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