| 1 |
|
| 2 |
|
| 3 |
#include <bootmode.h> |
| 4 |
#include <device/device.h> |
| 5 |
#include <device/mmio.h> |
| 6 |
#include <fw_config.h> |
| 7 |
#include <gpio.h> |
| 8 |
#include <soc/bl31.h> |
| 9 |
#include <soc/display.h> |
| 10 |
#include <soc/dpm_v2.h> |
| 11 |
#include <soc/i2c.h> |
| 12 |
#include <soc/msdc.h> |
| 13 |
#include <soc/mt6359p.h> |
| 14 |
#include <soc/mtcmos.h> |
| 15 |
#include <soc/spm_common.h> |
| 16 |
#include <soc/storage.h> |
| 17 |
#include <soc/usb.h> |
| 18 |
|
| 19 |
#include "gpio.h" |
| 20 |
#include "panel.h" |
| 21 |
#include "storage.h" |
| 22 |
|
| 23 |
#define AFE_SE_SECURE_CON1 (AUDIO_BASE + 0x5634) |
| 24 |
|
| 25 |
static void configure_rt9123_rt1019(void) |
| 26 |
{ |
| 27 |
|
| 28 |
gpio_set_mode(GPIO_I2S_SPKR_BCK, GPIO_FUNC(DMIC0_DAT0, I2SOUT1_BCK)); |
| 29 |
gpio_set_mode(GPIO_I2S_SPKR_LRCK, GPIO_FUNC(DMIC1_CLK, I2SOUT1_LRCK)); |
| 30 |
gpio_set_mode(GPIO_I2S_SPKR_DO, GPIO_FUNC(DMIC1_DAT0, I2SOUT1_DO)); |
| 31 |
|
| 32 |
printk(BIOS_INFO, "%s: AMP configuration done\n", __func__); |
| 33 |
} |
| 34 |
|
| 35 |
static void configure_alc5645(void) |
| 36 |
{ |
| 37 |
|
| 38 |
gpio_set_mode(GPIO_I2S_HP_MCK, GPIO_FUNC(I2SOUT0_MCK, I2SOUT0_MCK)); |
| 39 |
gpio_set_mode(GPIO_I2S_HP_BCK, GPIO_FUNC(I2SOUT0_BCK, I2SOUT0_BCK)); |
| 40 |
gpio_set_mode(GPIO_I2S_HP_LRCK, GPIO_FUNC(I2SOUT0_LRCK, I2SOUT0_LRCK)); |
| 41 |
gpio_set_mode(GPIO_I2S_HP_DO, GPIO_FUNC(I2SOUT0_DO, I2SOUT0_DO)); |
| 42 |
|
| 43 |
|
| 44 |
mtk_i2c_bus_init(I2C2, I2C_SPEED_STANDARD); |
| 45 |
|
| 46 |
printk(BIOS_INFO, "%s: AMP configuration done\n", __func__); |
| 47 |
} |
| 48 |
|
| 49 |
static void configure_audio(void) |
| 50 |
{ |
| 51 |
mtcmos_audio_power_on(); |
| 52 |
mtcmos_protect_audio_bus(); |
| 53 |
|
| 54 |
|
| 55 |
write32p(AFE_SE_SECURE_CON1, 0x0); |
| 56 |
|
| 57 |
if (fw_config_probe(FW_CONFIG(AUDIO_AMP, AMP_RT9123)) || |
| 58 |
fw_config_probe(FW_CONFIG(AUDIO_AMP, AMP_RT1019))) |
| 59 |
configure_rt9123_rt1019(); |
| 60 |
else if (fw_config_probe(FW_CONFIG(AUDIO_AMP, AMP_ALC5645))) |
| 61 |
configure_alc5645(); |
| 62 |
else |
| 63 |
printk(BIOS_WARNING, "Unknown amp\n"); |
| 64 |
} |
| 65 |
|
| 66 |
static void power_on_fpmcu(void) |
| 67 |
{ |
| 68 |
|
| 69 |
gpio_output(GPIO_EN_PWR_FP, 1); |
| 70 |
gpio_output(GPIO_FP_RST_1V8_S3_L, 1); |
| 71 |
} |
| 72 |
|
| 73 |
enum mtk_storage_type mainboard_get_storage_type(void) |
| 74 |
{ |
| 75 |
uint32_t index = storage_id(); |
| 76 |
|
| 77 |
switch (index) { |
| 78 |
case 0: |
| 79 |
return STORAGE_UFS_31; |
| 80 |
case 1: |
| 81 |
return STORAGE_UFS_22; |
| 82 |
case 2: |
| 83 |
return STORAGE_EMMC; |
| 84 |
default: |
| 85 |
printk(BIOS_WARNING, "unsupported storage id %u\n", index); |
| 86 |
} |
| 87 |
return STORAGE_UNKNOWN; |
| 88 |
} |
| 89 |
|
| 90 |
static void mainboard_init(struct device *dev) |
| 91 |
{ |
| 92 |
mt6359p_init_pmif_arb(); |
| 93 |
|
| 94 |
if (mainboard_get_storage_type() == STORAGE_EMMC) { |
| 95 |
mtk_msdc_configure_emmc(true); |
| 96 |
mtcmos_ufs_power_off(); |
| 97 |
} |
| 98 |
|
| 99 |
dpm_init(); |
| 100 |
setup_usb_host(); |
| 101 |
setup_usb_secondary_host(); |
| 102 |
spm_init(); |
| 103 |
power_on_fpmcu(); |
| 104 |
configure_audio(); |
| 105 |
|
| 106 |
if (CONFIG(SKYWALKER_SDCARD_INIT)) |
| 107 |
mtk_msdc_configure_sdcard(); |
| 108 |
|
| 109 |
if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 110 |
register_reset_to_bl31(GPIO_AP_EC_WARM_RST_REQ.id, true); |
| 111 |
|
| 112 |
if (display_init_required()) { |
| 113 |
if (mtk_display_init() < 0) |
| 114 |
printk(BIOS_ERR, "%s: Failed to init display\n", __func__); |
| 115 |
} else { |
| 116 |
printk(BIOS_INFO, "%s: Skipping display init; disabling secure mode\n", |
| 117 |
__func__); |
| 118 |
mtcmos_display_power_on(); |
| 119 |
mtcmos_protect_display_bus(); |
| 120 |
mtk_display_disable_secure_mode(); |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
static void mainboard_enable(struct device *dev) |
| 126 |
{ |
| 127 |
dev->ops->init = &mainboard_init; |
| 128 |
} |
| 129 |
|
| 130 |
struct chip_operations mainboard_ops = { |
| 131 |
.name = CONFIG_MAINBOARD_PART_NUMBER, |
| 132 |
.enable_dev = mainboard_enable, |
| 133 |
}; |