blob: 0e78f62a8754c8042bfc59f70d51f5e275170a4a [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>
6#include <delay.h>
7#include <device/device.h>
8#include <device/mmio.h>
Yu-Ping Wu514277f2022-08-09 15:54:05 +08009#include <ec/google/chromeec/ec.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080010#include <gpio.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080011#include <soc/bl31.h>
Yidi Linc4e14c22024-01-09 11:50:27 +080012#include <soc/display.h>
Ryan Chuangda63f092021-06-23 09:47:37 +080013#include <soc/dpm.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080014#include <soc/i2c.h>
Wenbin Meica33b74a2021-08-04 10:53:27 +080015#include <soc/msdc.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080016#include <soc/mtcmos.h>
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080017#include <soc/pcie.h>
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +080018#include <soc/spm.h>
Yuchen Huang144237f2021-03-01 14:39:33 +080019#include <soc/usb.h>
Yu-Ping Wu514277f2022-08-09 15:54:05 +080020#include <types.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080021
Yidi Lin7c06dd92021-04-08 09:55:11 +080022#include "gpio.h"
23
Jitao Shif2c259c2021-06-03 13:51:29 +080024/* GPIO to schematics names */
25#define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5)
26#define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0)
27#define GPIO_EDP_HPD_1V8 GPIO(GPIO_07)
28#define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2)
29
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080030bool mainboard_needs_pcie_init(void)
31{
Yu-Ping Wu514277f2022-08-09 15:54:05 +080032 uint32_t sku = sku_id();
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080033
Yu-Ping Wu514277f2022-08-09 15:54:05 +080034 if (sku == CROS_SKU_UNKNOWN) {
35 printk(BIOS_WARNING, "Unknown SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080036 return true;
Yu-Ping Wu514277f2022-08-09 15:54:05 +080037 } else if (sku == CROS_SKU_UNPROVISIONED) {
38 printk(BIOS_WARNING, "Unprovisioned SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080039 return true;
40 }
Yu-Ping Wu514277f2022-08-09 15:54:05 +080041
42 /*
43 * All cherry boards share the same SKU encoding. Therefore there is no need to check
44 * the board here.
45 * - BIT(1): NVMe (PCIe)
46 * - BIT(3): UFS (which takes precedence over BIT(1))
47 */
48 if (sku & BIT(3))
49 return false;
50 if (sku & BIT(1))
51 return true;
52
53 /* Otherwise, eMMC */
54 return false;
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080055}
56
Jitao Shif2c259c2021-06-03 13:51:29 +080057/* Set up backlight control pins as output pin and power-off by default */
Yidi Linc4e14c22024-01-09 11:50:27 +080058static void configure_backlight(void)
Jitao Shif2c259c2021-06-03 13:51:29 +080059{
60 gpio_output(GPIO_AP_EDP_BKLTEN, 0);
61 gpio_output(GPIO_BL_PWM_1V8, 0);
62}
63
64static void power_on_panel(void)
65{
66 /* Default power sequence for most panels. */
67 gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP);
68 gpio_set_mode(GPIO_EDP_HPD_1V8, 2);
69 gpio_output(GPIO_EN_PP3300_DISP_X, 1);
70}
71
Yidi Linc4e14c22024-01-09 11:50:27 +080072static struct panel_description panel = {
73 .configure_backlight = configure_backlight,
74 .power_on = power_on_panel,
75 .disp_path = DISP_PATH_EDP,
76 .orientation = LB_FB_ORIENTATION_NORMAL,
77};
78
79struct panel_description *get_active_panel(void)
Jitao Shif2c259c2021-06-03 13:51:29 +080080{
Yidi Linc4e14c22024-01-09 11:50:27 +080081 return &panel;
Jitao Shif2c259c2021-06-03 13:51:29 +080082}
83
Trevor Wu812df722022-03-22 13:09:13 +080084static void configure_i2s(void)
85{
86 /* Audio PWR */
87 mtcmos_audio_power_on();
88 mtcmos_protect_audio_bus();
89
90 /* SoC I2S */
91 gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK);
92 gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK);
93 gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0);
94}
95
96static void configure_audio(void)
97{
98 if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390))
99 mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST);
100
101 if (CONFIG(CHERRY_USE_MAX98390))
102 configure_i2s();
103}
104
Wenbin Mei24c63552021-02-24 15:17:41 +0800105static void mainboard_init(struct device *dev)
106{
Jitao Shif2c259c2021-06-03 13:51:29 +0800107 if (display_init_required())
Yidi Linc4e14c22024-01-09 11:50:27 +0800108 mtk_display_init();
Jitao Shif2c259c2021-06-03 13:51:29 +0800109 else
110 printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__);
111
Rex-BC Chen15486f42021-11-12 18:28:18 +0800112 mtk_msdc_configure_emmc(true);
113 mtk_msdc_configure_sdcard();
Yuchen Huang144237f2021-03-01 14:39:33 +0800114 setup_usb_host();
Yidi Lin7c06dd92021-04-08 09:55:11 +0800115
Trevor Wu812df722022-03-22 13:09:13 +0800116 configure_audio();
Trevor Wu1d194322021-08-17 15:58:11 +0800117
Ryan Chuangda63f092021-06-23 09:47:37 +0800118 if (dpm_init())
119 printk(BIOS_ERR, "dpm init failed, DVFS may not work\n");
120
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +0800121 if (spm_init())
122 printk(BIOS_ERR, "spm init failed, system suspend may not work\n");
123
Hung-Te Lina01f8bc2022-09-06 14:32:05 +0800124 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
125 register_reset_to_bl31(GPIO_RESET.id, true);
Wenbin Mei24c63552021-02-24 15:17:41 +0800126}
127
128static void mainboard_enable(struct device *dev)
129{
130 dev->ops->init = &mainboard_init;
131}
132
133struct chip_operations mainboard_ops = {
Wenbin Mei24c63552021-02-24 15:17:41 +0800134 .enable_dev = mainboard_enable,
135};