| 1 |
|
| 2 |
|
| 3 |
#include <bootmode.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <fw_config.h> |
| 7 |
#include <gpio.h> |
| 8 |
#include <soc/addressmap.h> |
| 9 |
#include <soc/bl31.h> |
| 10 |
#include <soc/display.h> |
| 11 |
#include <soc/dpm_v2.h> |
| 12 |
#include <soc/gpio_common.h> |
| 13 |
#include <soc/i2c.h> |
| 14 |
#include <soc/msdc.h> |
| 15 |
#include <soc/mt6373.h> |
| 16 |
#include <soc/pcie.h> |
| 17 |
#include <soc/spm_common.h> |
| 18 |
#include <soc/storage.h> |
| 19 |
#include <soc/usb.h> |
| 20 |
|
| 21 |
#include "gpio.h" |
| 22 |
#include "storage.h" |
| 23 |
|
| 24 |
#define AFE_SE_SECURE_CON1 (AUDIO_BASE + 0x5634) |
| 25 |
|
| 26 |
static void configure_tas2563(void) |
| 27 |
{ |
| 28 |
|
| 29 |
write32p(AFE_SE_SECURE_CON1, 0x0); |
| 30 |
|
| 31 |
|
| 32 |
gpio_set_mode(GPIO_I2SI4_BCK, GPIO_FUNC(I2SIN1_BCK, I2SIN4_BCK)); |
| 33 |
gpio_set_mode(GPIO_I2SI4_LRCK, GPIO_FUNC(I2SIN1_LRCK, I2SIN4_LRCK)); |
| 34 |
gpio_set_mode(GPIO_I2SO4_D0, GPIO_FUNC(I2SOUT1_DO, I2SOUT4_DATA0)); |
| 35 |
|
| 36 |
printk(BIOS_INFO, "%s: done\n", __func__); |
| 37 |
} |
| 38 |
|
| 39 |
static void configure_alc5645(void) |
| 40 |
{ |
| 41 |
|
| 42 |
write32p(AFE_SE_SECURE_CON1, 0x0); |
| 43 |
|
| 44 |
|
| 45 |
gpio_set_mode(GPIO_I2SI6_MCK, GPIO_FUNC(I2SIN0_MCK, I2S_MCK0)); |
| 46 |
gpio_set_mode(GPIO_I2SI6_BCK, GPIO_FUNC(I2SIN0_BCK, I2SIN6_0_BCK)); |
| 47 |
gpio_set_mode(GPIO_I2SI6_LRCK, GPIO_FUNC(I2SIN0_LRCK, I2SIN6_0_LRCK)); |
| 48 |
gpio_set_mode(GPIO_I2SO6_D0, GPIO_FUNC(I2SOUT0_DO, I2SOUT6_0_DO)); |
| 49 |
|
| 50 |
|
| 51 |
mtk_i2c_bus_init(I2C3, I2C_SPEED_STANDARD); |
| 52 |
|
| 53 |
printk(BIOS_INFO, "%s: done\n", __func__); |
| 54 |
} |
| 55 |
static void configure_audio(void) |
| 56 |
{ |
| 57 |
if (fw_config_probe(FW_CONFIG(AUDIO_AMP, AMP_TAS2563))) { |
| 58 |
mtk_i2c_bus_init(I2C3, I2C_SPEED_FAST); |
| 59 |
configure_tas2563(); |
| 60 |
} else if (fw_config_probe(FW_CONFIG(AUDIO_AMP, AMP_ALC5645))) { |
| 61 |
configure_alc5645(); |
| 62 |
} else { |
| 63 |
printk(BIOS_INFO, "Audio configure default amps NAU8318\n"); |
| 64 |
} |
| 65 |
|
| 66 |
printk(BIOS_INFO, "%s: done\n", __func__); |
| 67 |
} |
| 68 |
|
| 69 |
static void power_on_fpmcu(void) |
| 70 |
{ |
| 71 |
|
| 72 |
gpio_output(GPIO_EN_PWR_FP, 1); |
| 73 |
gpio_output(GPIO_FP_RST_1V8_S3_L, 1); |
| 74 |
} |
| 75 |
|
| 76 |
static void enable_display_power_rail(void) |
| 77 |
{ |
| 78 |
mt6373_init_pmif_arb(); |
| 79 |
mt6373_enable_vcn33_3(true); |
| 80 |
mt6373_set_vcn33_3_voltage(3300000); |
| 81 |
} |
| 82 |
|
| 83 |
enum mtk_storage_type mainboard_get_storage_type(void) |
| 84 |
{ |
| 85 |
uint32_t index = storage_id(); |
| 86 |
|
| 87 |
switch (index) { |
| 88 |
case 0: |
| 89 |
return STORAGE_UFS_40; |
| 90 |
case 1: |
| 91 |
return STORAGE_UFS_31; |
| 92 |
case 2: |
| 93 |
return STORAGE_UFS_40_HS; |
| 94 |
case 3: |
| 95 |
return STORAGE_NVME; |
| 96 |
default: |
| 97 |
printk(BIOS_WARNING, "unsupported storage id %u\n", index); |
| 98 |
} |
| 99 |
return STORAGE_UNKNOWN; |
| 100 |
} |
| 101 |
|
| 102 |
bool mainboard_needs_pcie_init(void) |
| 103 |
{ |
| 104 |
return mainboard_get_storage_type() == STORAGE_NVME; |
| 105 |
} |
| 106 |
|
| 107 |
static void mainboard_init(struct device *dev) |
| 108 |
{ |
| 109 |
if (display_init_required()) { |
| 110 |
enable_display_power_rail(); |
| 111 |
if (mtk_display_init() < 0) |
| 112 |
printk(BIOS_ERR, "%s: Failed to init display\n", __func__); |
| 113 |
} else { |
| 114 |
printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__); |
| 115 |
} |
| 116 |
|
| 117 |
setup_usb_host(); |
| 118 |
power_on_fpmcu(); |
| 119 |
configure_audio(); |
| 120 |
|
| 121 |
if (CONFIG(RAURU_SDCARD_INIT)) |
| 122 |
mtk_msdc_configure_sdcard(); |
| 123 |
|
| 124 |
if (dpm_init()) |
| 125 |
printk(BIOS_ERR, "dpm init failed, DVFS may not work\n"); |
| 126 |
|
| 127 |
if (spm_init()) |
| 128 |
printk(BIOS_ERR, "spm init failed, Suspend may not work\n"); |
| 129 |
|
| 130 |
if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 131 |
register_reset_to_bl31(GPIO_AP_EC_WARM_RST_REQ.id, true); |
| 132 |
} |
| 133 |
|
| 134 |
static void mainboard_enable(struct device *dev) |
| 135 |
{ |
| 136 |
dev->ops->init = &mainboard_init; |
| 137 |
} |
| 138 |
|
| 139 |
struct chip_operations mainboard_ops = { |
| 140 |
.name = CONFIG_MAINBOARD_PART_NUMBER, |
| 141 |
.enable_dev = mainboard_enable, |
| 142 |
}; |