blob: 19638c97f69d7b33c9a3d4014e59daa591fccf53 [file] [log] [blame]
Wenbin Mei24c63552021-02-24 15:17:41 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +08003#include <boardid.h>
Wenbin Mei24c63552021-02-24 15:17:41 +08004#include <bootmode.h>
5#include <console/console.h>
Wenbin Mei24c63552021-02-24 15:17:41 +08006#include <device/device.h>
7#include <device/mmio.h>
Yu-Ping Wu514277f2022-08-09 15:54:05 +08008#include <ec/google/chromeec/ec.h>
Wenbin Mei24c63552021-02-24 15:17:41 +08009#include <gpio.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080010#include <soc/bl31.h>
Yidi Linc4e14c22024-01-09 11:50:27 +080011#include <soc/display.h>
Ryan Chuangda63f092021-06-23 09:47:37 +080012#include <soc/dpm.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080013#include <soc/i2c.h>
Wenbin Meica33b74a2021-08-04 10:53:27 +080014#include <soc/msdc.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080015#include <soc/mtcmos.h>
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080016#include <soc/pcie.h>
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +080017#include <soc/spm.h>
Yuchen Huang144237f2021-03-01 14:39:33 +080018#include <soc/usb.h>
Yu-Ping Wu514277f2022-08-09 15:54:05 +080019#include <types.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080020
Yidi Lin7c06dd92021-04-08 09:55:11 +080021#include "gpio.h"
22
Jitao Shif2c259c2021-06-03 13:51:29 +080023/* GPIO to schematics names */
24#define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5)
25#define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0)
26#define GPIO_EDP_HPD_1V8 GPIO(GPIO_07)
27#define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2)
28
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080029bool mainboard_needs_pcie_init(void)
30{
Yu-Ping Wu514277f2022-08-09 15:54:05 +080031 uint32_t sku = sku_id();
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080032
Yu-Ping Wu514277f2022-08-09 15:54:05 +080033 if (sku == CROS_SKU_UNKNOWN) {
34 printk(BIOS_WARNING, "Unknown SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080035 return true;
Yu-Ping Wu514277f2022-08-09 15:54:05 +080036 } else if (sku == CROS_SKU_UNPROVISIONED) {
37 printk(BIOS_WARNING, "Unprovisioned SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080038 return true;
39 }
Yu-Ping Wu514277f2022-08-09 15:54:05 +080040
41 /*
42 * All cherry boards share the same SKU encoding. Therefore there is no need to check
43 * the board here.
44 * - BIT(1): NVMe (PCIe)
45 * - BIT(3): UFS (which takes precedence over BIT(1))
46 */
47 if (sku & BIT(3))
48 return false;
49 if (sku & BIT(1))
50 return true;
51
52 /* Otherwise, eMMC */
53 return false;
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080054}
55
Jitao Shif2c259c2021-06-03 13:51:29 +080056/* Set up backlight control pins as output pin and power-off by default */
Yidi Linc4e14c22024-01-09 11:50:27 +080057static void configure_backlight(void)
Jitao Shif2c259c2021-06-03 13:51:29 +080058{
59 gpio_output(GPIO_AP_EDP_BKLTEN, 0);
60 gpio_output(GPIO_BL_PWM_1V8, 0);
61}
62
63static void power_on_panel(void)
64{
65 /* Default power sequence for most panels. */
66 gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP);
67 gpio_set_mode(GPIO_EDP_HPD_1V8, 2);
68 gpio_output(GPIO_EN_PP3300_DISP_X, 1);
69}
70
Yidi Linc4e14c22024-01-09 11:50:27 +080071static struct panel_description panel = {
72 .configure_backlight = configure_backlight,
73 .power_on = power_on_panel,
74 .disp_path = DISP_PATH_EDP,
75 .orientation = LB_FB_ORIENTATION_NORMAL,
76};
77
78struct panel_description *get_active_panel(void)
Jitao Shif2c259c2021-06-03 13:51:29 +080079{
Yidi Linc4e14c22024-01-09 11:50:27 +080080 return &panel;
Jitao Shif2c259c2021-06-03 13:51:29 +080081}
82
Trevor Wu812df722022-03-22 13:09:13 +080083static void configure_i2s(void)
84{
85 /* Audio PWR */
86 mtcmos_audio_power_on();
87 mtcmos_protect_audio_bus();
88
89 /* SoC I2S */
90 gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK);
91 gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK);
92 gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0);
93}
94
95static void configure_audio(void)
96{
97 if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390))
98 mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST);
99
100 if (CONFIG(CHERRY_USE_MAX98390))
101 configure_i2s();
102}
103
Wenbin Mei24c63552021-02-24 15:17:41 +0800104static void mainboard_init(struct device *dev)
105{
Jitao Shif2c259c2021-06-03 13:51:29 +0800106 if (display_init_required())
Yidi Linc4e14c22024-01-09 11:50:27 +0800107 mtk_display_init();
Jitao Shif2c259c2021-06-03 13:51:29 +0800108 else
109 printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__);
110
Rex-BC Chen15486f42021-11-12 18:28:18 +0800111 mtk_msdc_configure_emmc(true);
112 mtk_msdc_configure_sdcard();
Yuchen Huang144237f2021-03-01 14:39:33 +0800113 setup_usb_host();
Yidi Lin7c06dd92021-04-08 09:55:11 +0800114
Trevor Wu812df722022-03-22 13:09:13 +0800115 configure_audio();
Trevor Wu1d194322021-08-17 15:58:11 +0800116
Ryan Chuangda63f092021-06-23 09:47:37 +0800117 if (dpm_init())
118 printk(BIOS_ERR, "dpm init failed, DVFS may not work\n");
119
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +0800120 if (spm_init())
121 printk(BIOS_ERR, "spm init failed, system suspend may not work\n");
122
Hung-Te Lina01f8bc2022-09-06 14:32:05 +0800123 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
124 register_reset_to_bl31(GPIO_RESET.id, true);
Wenbin Mei24c63552021-02-24 15:17:41 +0800125}
126
127static void mainboard_enable(struct device *dev)
128{
129 dev->ops->init = &mainboard_init;
130}
131
132struct chip_operations mainboard_ops = {
Wenbin Mei24c63552021-02-24 15:17:41 +0800133 .enable_dev = mainboard_enable,
134};