blob: 69e72d7d13513c4cd0d3844ac3022718de6cf3b9 [file] [log] [blame]
Rex-BC Chen74a06292021-09-09 18:43:22 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
Rex-BC Chend05f2312021-12-17 14:39:30 +08003#include <bootmode.h>
Rex-BC Chenad5fda52021-11-10 20:44:12 +08004#include <console/console.h>
Rex-BC Chen74a06292021-09-09 18:43:22 +08005#include <device/device.h>
Rex-BC Chen1e9dfd92022-01-04 22:35:23 +08006#include <gpio.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +08007#include <soc/bl31.h>
wuyang5823f95e2023-11-02 09:33:01 +08008#include <soc/i2c.h>
Wenbin Mei966b5022021-10-19 21:21:31 +08009#include <soc/msdc.h>
Rex-BC Chenad5fda52021-11-10 20:44:12 +080010#include <soc/spm.h>
Rex-BC Chen2f9e5b92021-10-13 20:08:26 +080011#include <soc/usb.h>
Rex-BC Chen74a06292021-09-09 18:43:22 +080012
Rex-BC Chend05f2312021-12-17 14:39:30 +080013#include "display.h"
Rex-BC Chen64f13192021-11-18 12:55:01 +080014#include "gpio.h"
15
wuyang5823f95e2023-11-02 09:33:01 +080016static void configure_alc1019(void)
Rex-BC Chena8a9552d2022-01-04 11:07:22 +080017{
18 mtcmos_audio_power_on();
19
20 /* Set up I2S */
21 gpio_set_mode(GPIO(I2S2_MCK), PAD_I2S2_MCK_FUNC_I2S2_MCK);
22 gpio_set_mode(GPIO(I2S2_BCK), PAD_I2S2_BCK_FUNC_I2S2_BCK);
23 gpio_set_mode(GPIO(I2S2_LRCK), PAD_I2S2_LRCK_FUNC_I2S2_LRCK);
24 gpio_set_mode(GPIO(EINT4), PAD_EINT4_FUNC_I2S3_DO);
25}
26
wuyang5823f95e2023-11-02 09:33:01 +080027static void configure_alc5645(void)
28{
29 mtcmos_audio_power_on();
30
31 /* Set up I2S */
32 gpio_set_mode(GPIO(I2S1_MCK), PAD_I2S1_MCK_FUNC_I2S1_MCK);
33 gpio_set_mode(GPIO(I2S1_BCK), PAD_I2S1_BCK_FUNC_I2S1_BCK);
34 gpio_set_mode(GPIO(I2S1_LRCK), PAD_I2S1_LRCK_FUNC_I2S1_LRCK);
35 gpio_set_mode(GPIO(I2S1_DO), PAD_I2S1_DO_FUNC_I2S1_DO);
36
37 /* Init I2C bus timing register for audio codecs */
38 mtk_i2c_bus_init(I2C5, I2C_SPEED_STANDARD);
39}
40
Rex-BC Chen74a06292021-09-09 18:43:22 +080041static void mainboard_init(struct device *dev)
42{
Rex-BC Chen4ab77ad2021-10-26 13:17:43 +080043 mtk_msdc_configure_emmc(true);
Rex-BC Chenfca89d32021-11-19 10:47:12 +080044
45 if (CONFIG(SDCARD_INIT)) {
46 printk(BIOS_INFO, "SD card init\n");
Rex-BC Chen1e9dfd92022-01-04 22:35:23 +080047
48 /* External SD Card connected via USB */
49 gpio_output(GPIO_EN_PP3300_SDBRDG_X, 1);
Rex-BC Chenfca89d32021-11-19 10:47:12 +080050 }
51
Rex-BC Chen2f9e5b92021-10-13 20:08:26 +080052 setup_usb_host();
Rex-BC Chenad5fda52021-11-10 20:44:12 +080053
wuyang5823f95e2023-11-02 09:33:01 +080054 if (CONFIG(BOARD_GOOGLE_CHINCHOU))
55 configure_alc5645();
56 else
57 configure_alc1019();
Rex-BC Chena8a9552d2022-01-04 11:07:22 +080058
Rex-BC Chenad5fda52021-11-10 20:44:12 +080059 if (spm_init())
60 printk(BIOS_ERR, "spm init failed, system suspend may not work\n");
Rex-BC Chen64f13192021-11-18 12:55:01 +080061
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080062 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
63 register_reset_to_bl31(GPIO_RESET.id, true);
Rex-BC Chend05f2312021-12-17 14:39:30 +080064
65 if (display_init_required()) {
66 if (configure_display() < 0)
67 printk(BIOS_ERR, "%s: Failed to init display\n", __func__);
68 } else {
Ruihai Zhou266e6552023-07-03 20:10:28 +080069 if (CONFIG(BOARD_GOOGLE_STARYU_COMMON)) {
70 mtk_i2c_bus_init(PMIC_I2C_BUS, I2C_SPEED_FAST);
71 if (is_pmic_aw37503(PMIC_I2C_BUS)) {
72 printk(BIOS_DEBUG, "Initialize PMIC AW37503\n");
73 aw37503_init(PMIC_I2C_BUS);
74 }
75 }
Rex-BC Chend05f2312021-12-17 14:39:30 +080076 printk(BIOS_INFO, "%s: Skipped display init\n", __func__);
77 }
Rex-BC Chen74a06292021-09-09 18:43:22 +080078}
79
80static void mainboard_enable(struct device *dev)
81{
82 dev->ops->init = &mainboard_init;
83}
84
85struct chip_operations mainboard_ops = {
Rex-BC Chen74a06292021-09-09 18:43:22 +080086 .enable_dev = mainboard_enable,
87};