blob: c67a581c772e873514c7fd15ddfecad476f6240c [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>
Jitao Shif2c259c2021-06-03 13:51:29 +08009#include <edid.h>
10#include <framebuffer_info.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080011#include <gpio.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080012#include <soc/bl31.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080013#include <soc/ddp.h>
Ryan Chuangda63f092021-06-23 09:47:37 +080014#include <soc/dpm.h>
Jitao Shif2c259c2021-06-03 13:51:29 +080015#include <soc/dptx.h>
Wenbin Mei24c63552021-02-24 15:17:41 +080016#include <soc/gpio.h>
17#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>
Wenbin Mei24c63552021-02-24 15:17:41 +080023
Yidi Lin7c06dd92021-04-08 09:55:11 +080024#include "gpio.h"
25
Jitao Shif2c259c2021-06-03 13:51:29 +080026/* GPIO to schematics names */
27#define GPIO_AP_EDP_BKLTEN GPIO(DGI_D5)
28#define GPIO_BL_PWM_1V8 GPIO(DISP_PWM0)
29#define GPIO_EDP_HPD_1V8 GPIO(GPIO_07)
30#define GPIO_EN_PP3300_DISP_X GPIO(I2SO1_D2)
31
Yu-Ping Wu7b7250d2022-07-19 17:43:29 +080032bool mainboard_needs_pcie_init(void)
33{
34 uint32_t sku;
35
36 if (!CONFIG(BOARD_GOOGLE_DOJO))
37 return false;
38
39 sku = sku_id();
40 switch (sku) {
41 case 0:
42 case 1:
43 case 4:
44 case 5:
45 return false;
46 case 2:
47 case 3:
48 case 6:
49 case 7:
50 return true;
51 default:
52 /* For example CROS_SKU_UNPROVISIONED */
53 printk(BIOS_WARNING, "Unexpected sku %#x; assuming PCIe", sku);
54 return true;
55 }
56}
57
Jitao Shif2c259c2021-06-03 13:51:29 +080058/* Set up backlight control pins as output pin and power-off by default */
59static void configure_panel_backlight(void)
60{
61 gpio_output(GPIO_AP_EDP_BKLTEN, 0);
62 gpio_output(GPIO_BL_PWM_1V8, 0);
63}
64
65static void power_on_panel(void)
66{
67 /* Default power sequence for most panels. */
68 gpio_set_pull(GPIO_EDP_HPD_1V8, GPIO_PULL_ENABLE, GPIO_PULL_UP);
69 gpio_set_mode(GPIO_EDP_HPD_1V8, 2);
70 gpio_output(GPIO_EN_PP3300_DISP_X, 1);
71}
72
73static bool configure_display(void)
74{
75 struct edid edid;
76 struct fb_info *info;
77 const char *name;
78
79 printk(BIOS_INFO, "%s: Starting display initialization\n", __func__);
80
81 mtcmos_display_power_on();
82 mtcmos_protect_display_bus();
83 configure_panel_backlight();
84 power_on_panel();
85
86 mtk_ddp_init();
87 mdelay(200);
88
89 if (mtk_edp_init(&edid) < 0) {
90 printk(BIOS_ERR, "%s: Failed to initialize eDP\n", __func__);
91 return false;
92 }
93 name = edid.ascii_string;
94 if (name[0] == '\0')
95 name = "unknown name";
96 printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__,
97 edid.manufacturer_name, name, edid.mode.ha, edid.mode.va,
98 edid.mode.refresh);
99
100 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
101
102 mtk_ddp_mode_set(&edid);
103 info = fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0);
104 if (info)
105 fb_set_orientation(info, LB_FB_ORIENTATION_NORMAL);
106
107 return true;
108}
109
Trevor Wu812df722022-03-22 13:09:13 +0800110static void configure_i2s(void)
111{
112 /* Audio PWR */
113 mtcmos_audio_power_on();
114 mtcmos_protect_audio_bus();
115
116 /* SoC I2S */
117 gpio_set_mode(GPIO(GPIO_02), PAD_GPIO_02_FUNC_TDMIN_LRCK);
118 gpio_set_mode(GPIO(GPIO_03), PAD_GPIO_03_FUNC_TDMIN_BCK);
119 gpio_set_mode(GPIO(I2SO2_D0), PAD_I2SO2_D0_FUNC_I2SO2_D0);
120}
121
122static void configure_audio(void)
123{
124 if (CONFIG(CHERRY_USE_RT1011) || CONFIG(CHERRY_USE_MAX98390))
125 mtk_i2c_bus_init(I2C2, I2C_SPEED_FAST);
126
127 if (CONFIG(CHERRY_USE_MAX98390))
128 configure_i2s();
129}
130
Wenbin Mei24c63552021-02-24 15:17:41 +0800131static void mainboard_init(struct device *dev)
132{
Jitao Shif2c259c2021-06-03 13:51:29 +0800133 if (display_init_required())
134 configure_display();
135 else
136 printk(BIOS_INFO, "%s: Skipped display initialization\n", __func__);
137
Rex-BC Chen15486f42021-11-12 18:28:18 +0800138 mtk_msdc_configure_emmc(true);
139 mtk_msdc_configure_sdcard();
Yuchen Huang144237f2021-03-01 14:39:33 +0800140 setup_usb_host();
Yidi Lin7c06dd92021-04-08 09:55:11 +0800141
Trevor Wu812df722022-03-22 13:09:13 +0800142 configure_audio();
Trevor Wu1d194322021-08-17 15:58:11 +0800143
Ryan Chuangda63f092021-06-23 09:47:37 +0800144 if (dpm_init())
145 printk(BIOS_ERR, "dpm init failed, DVFS may not work\n");
146
Rex-BC Chen9e3e0f52021-06-03 11:41:07 +0800147 if (spm_init())
148 printk(BIOS_ERR, "spm init failed, system suspend may not work\n");
149
Hung-Te Lina01f8bc2022-09-06 14:32:05 +0800150 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
151 register_reset_to_bl31(GPIO_RESET.id, true);
Wenbin Mei24c63552021-02-24 15:17:41 +0800152}
153
154static void mainboard_enable(struct device *dev)
155{
156 dev->ops->init = &mainboard_init;
157}
158
159struct chip_operations mainboard_ops = {
160 .name = CONFIG_MAINBOARD_PART_NUMBER,
161 .enable_dev = mainboard_enable,
162};