blob: c1593ca999ffae363105d74aa50c5d97e83e54fd [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>
Jitao Shif2c259c2021-06-03 13:51:29 +080010#include <edid.h>
11#include <framebuffer_info.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080012#include <gpio.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080013#include <soc/bl31.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080014#include <soc/ddp.h>
Ryan Chuangda63f092021-06-23 09:47:37 +080015#include <soc/dpm.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080016#include <soc/dptx.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080017#include <soc/i2c.h>
Wenbin Meica33b74a2021-08-04 10:53:27 +080018#include <soc/msdc.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080019#include <soc/mtcmos.h>
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080020#include <soc/pcie.h>
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +080021#include <soc/spm.h>
Yuchen Huang144237f2021-03-01 14:39:33 +080022#include <soc/usb.h>
Yu-Ping Wu514277f2022-08-09 15:54:05 +080023#include <types.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080024
Yidi Lin7c06dd92021-04-08 09:55:11 +080025#include "gpio.h"
26
Jitao Shif2c259c2021-06-03 13:51:29 +080027/* GPIO to schematics names */
28#define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5)
29#define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0)
30#define GPIO_EDP_HPD_1V8 GPIO(GPIO_07)
31#define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2)
32
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080033bool mainboard_needs_pcie_init(void)
34{
Yu-Ping Wu514277f2022-08-09 15:54:05 +080035 uint32_t sku = sku_id();
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080036
Yu-Ping Wu514277f2022-08-09 15:54:05 +080037 if (sku == CROS_SKU_UNKNOWN) {
38 printk(BIOS_WARNING, "Unknown SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080039 return true;
Yu-Ping Wu514277f2022-08-09 15:54:05 +080040 } else if (sku == CROS_SKU_UNPROVISIONED) {
41 printk(BIOS_WARNING, "Unprovisioned SKU (%#x); assuming PCIe", sku);
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080042 return true;
43 }
Yu-Ping Wu514277f2022-08-09 15:54:05 +080044
45 /*
46 * All cherry boards share the same SKU encoding. Therefore there is no need to check
47 * the board here.
48 * - BIT(1): NVMe (PCIe)
49 * - BIT(3): UFS (which takes precedence over BIT(1))
50 */
51 if (sku & BIT(3))
52 return false;
53 if (sku & BIT(1))
54 return true;
55
56 /* Otherwise, eMMC */
57 return false;
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080058}
59
Jitao Shif2c259c2021-06-03 13:51:29 +080060/* Set up backlight control pins as output pin and power-off by default */
61static void configure_panel_backlight(void)
62{
63 gpio_output(GPIO_AP_EDP_BKLTEN, 0);
64 gpio_output(GPIO_BL_PWM_1V8, 0);
65}
66
67static void power_on_panel(void)
68{
69 /* Default power sequence for most panels. */
70 gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP);
71 gpio_set_mode(GPIO_EDP_HPD_1V8, 2);
72 gpio_output(GPIO_EN_PP3300_DISP_X, 1);
73}
74
75static bool configure_display(void)
76{
77 struct edid edid;
78 struct fb_info *info;
79 const char *name;
80
81 printk(BIOS_INFO, "%s: Starting display initialization\n", __func__);
82
83 mtcmos_display_power_on();
84 mtcmos_protect_display_bus();
85 configure_panel_backlight();
86 power_on_panel();
87
88 mtk_ddp_init();
89 mdelay(200);
90
91 if (mtk_edp_init(&edid) < 0) {
92 printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__);
93 return false;
94 }
95 name = edid.ascii_string;
96 if (name[0] == '\0')
97 name = "unknown name";
98 printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__,
99 edid.manufacturer_name, name, edid.mode.ha, edid.mode.va,
100 edid.mode.refresh);
101
102 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
103
104 mtk_ddp_mode_set(&edid);
105 info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0);
106 if (info)
107 fb_set_orientation(info, LB_FB_ORIENTATION_NORMAL);
108
109 return true;
110}
111
Trevor Wu812df722022-03-22 13:09:13 +0800112static void configure_i2s(void)
113{
114 /* Audio PWR */
115 mtcmos_audio_power_on();
116 mtcmos_protect_audio_bus();
117
118 /* SoC I2S */
119 gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK);
120 gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK);
121 gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0);
122}
123
124static void configure_audio(void)
125{
126 if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390))
127 mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST);
128
129 if (CONFIG(CHERRY_USE_MAX98390))
130 configure_i2s();
131}
132
Wenbin Mei24c63552021-02-24 15:17:41 +0800133static void mainboard_init(struct device *dev)
134{
Jitao Shif2c259c2021-06-03 13:51:29 +0800135 if (display_init_required())
136 configure_display();
137 else
138 printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__);
139
Rex-BC Chen15486f42021-11-12 18:28:18 +0800140 mtk_msdc_configure_emmc(true);
141 mtk_msdc_configure_sdcard();
Yuchen Huang144237f2021-03-01 14:39:33 +0800142 setup_usb_host();
Yidi Lin7c06dd92021-04-08 09:55:11 +0800143
Trevor Wu812df722022-03-22 13:09:13 +0800144 configure_audio();
Trevor Wu1d194322021-08-17 15:58:11 +0800145
Ryan Chuangda63f092021-06-23 09:47:37 +0800146 if (dpm_init())
147 printk(BIOS_ERR, "dpm init failed, DVFS may not work\n");
148
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +0800149 if (spm_init())
150 printk(BIOS_ERR, "spm init failed, system suspend may not work\n");
151
Hung-Te Lina01f8bc2022-09-06 14:32:05 +0800152 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
153 register_reset_to_bl31(GPIO_RESET.id, true);
Wenbin Mei24c63552021-02-24 15:17:41 +0800154}
155
156static void mainboard_enable(struct device *dev)
157{
158 dev->ops->init = &mainboard_init;
159}
160
161struct chip_operations mainboard_ops = {
Wenbin Mei24c63552021-02-24 15:17:41 +0800162 .enable_dev = mainboard_enable,
163};