blob: 22f8150d5e9e974604b4e23c4911610a7e97ebd8 [file] [log] [blame]
Angel Pons11ba3532020-04-05 13:21:58 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Tristan Shiehbb684e02018-06-19 16:07:54 +08002
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +08003#include <assert.h>
Hung-Te Lin2c307a02019-02-20 14:31:23 +08004#include <boardid.h>
5#include <bootmode.h>
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +08006#include <cbfs.h>
Hung-Te Lin2c307a02019-02-20 14:31:23 +08007#include <console/console.h>
8#include <delay.h>
Tristan Shiehbb684e02018-06-19 16:07:54 +08009#include <device/device.h>
Hung-Te Lin7fc22812020-07-24 08:49:41 +080010#include <ec/google/chromeec/ec.h>
Hung-Te Lin2c307a02019-02-20 14:31:23 +080011#include <edid.h>
Patrick Rudolph73192882020-02-19 12:10:51 +010012#include <framebuffer_info.h>
Hung-Te Lin2c307a02019-02-20 14:31:23 +080013#include <gpio.h>
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020014#include <identity.h>
Hung-Te Lina01f8bc2022-09-06 14:32:05 +080015#include <soc/bl31.h>
Hung-Te Lin2c307a02019-02-20 14:31:23 +080016#include <soc/ddp.h>
17#include <soc/dsi.h>
Tristan Shiehbb684e02018-06-19 16:07:54 +080018#include <soc/mmu_operations.h>
Jiaxin Yu30bc9f42019-04-23 20:45:50 +080019#include <soc/mtcmos.h>
Dawei Chien2422f8c2019-05-30 11:55:10 +080020#include <soc/spm.h>
Tristan Shieh71ae5822018-09-26 14:33:54 +080021#include <soc/usb.h>
Elyes Haouasbdd03c22024-05-27 11:20:07 +020022#include <stdio.h>
Tristan Shiehbb684e02018-06-19 16:07:54 +080023
Tristan Shieh4d990ab2019-02-25 17:14:14 +080024#include "gpio.h"
Hung-Te Lin2c307a02019-02-20 14:31:23 +080025#include "panel.h"
26
Tristan Shieh8db79c12018-09-07 17:26:21 +080027static void configure_emmc(void)
28{
29 const gpio_t emmc_pin[] = {
30 GPIO(MSDC0_DAT0), GPIO(MSDC0_DAT1),
31 GPIO(MSDC0_DAT2), GPIO(MSDC0_DAT3),
32 GPIO(MSDC0_DAT4), GPIO(MSDC0_DAT5),
33 GPIO(MSDC0_DAT6), GPIO(MSDC0_DAT7),
34 GPIO(MSDC0_CMD), GPIO(MSDC0_RSTB),
35 };
36
37 for (size_t i = 0; i < ARRAY_SIZE(emmc_pin); i++)
38 gpio_set_pull(emmc_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP);
39}
40
Tristan Shieh71ae5822018-09-26 14:33:54 +080041static void configure_usb(void)
42{
43 setup_usb_host();
44}
45
Jiaxin Yu30bc9f42019-04-23 20:45:50 +080046static void configure_audio(void)
47{
48 /* Audio PWR*/
49 mtcmos_audio_power_on();
50
51 /* SoC I2S */
52 gpio_set_mode(GPIO(CAM_RST0), PAD_CAM_RST0_FUNC_I2S2_LRCK);
53 gpio_set_mode(GPIO(CAM_PDN1), PAD_CAM_PDN1_FUNC_I2S2_BCK);
54 gpio_set_mode(GPIO(CAM_PDN0), PAD_CAM_PDN0_FUNC_I2S2_MCK);
55 gpio_set_mode(GPIO(EINT3), PAD_EINT3_FUNC_I2S3_DO);
56}
Hung-Te Lin2c307a02019-02-20 14:31:23 +080057
Hung-Te Lin7fc22812020-07-24 08:49:41 +080058static void configure_ec(void)
59{
60 /* EC may need SKU ID to identify if it is clamshell or convertible. */
61 if (CONFIG(BOARD_GOOGLE_JACUZZI_COMMON))
62 google_chromeec_set_sku_id(sku_id());
63}
64
Hung-Te Lin2c307a02019-02-20 14:31:23 +080065/* Default implementation for boards without panels defined yet. */
66struct panel_description __weak *get_panel_description(int panel_id)
67{
68 printk(BIOS_ERR, "%s: ERROR: No panels defined for board: %s.\n",
Kyösti Mälkkib78e4622022-12-15 22:12:29 +020069 __func__, mainboard_part_number);
Hung-Te Lin2c307a02019-02-20 14:31:23 +080070 return NULL;
71}
72
73/* Set up backlight control pins as output pin and power-off by default */
74static void configure_panel_backlight(void)
75{
76 gpio_output(GPIO(PERIPHERAL_EN13), 0);
77 gpio_output(GPIO(DISP_PWM), 0);
78}
79
80static void power_on_panel(struct panel_description *panel)
81{
82 if (panel->power_on) {
83 panel->power_on();
84 return;
85 }
86
87 /* Default power sequence for most panels. */
88 gpio_output(GPIO_LCM_RST_1V8, 0);
89 gpio_output(GPIO_PPVARP_LCD_EN, 1);
90 gpio_output(GPIO_PPVARN_LCD_EN, 1);
91 gpio_output(GPIO_PP1800_LCM_EN, 1);
92 gpio_output(GPIO_PP3300_LCM_EN, 1);
Tao Xiaf3c0a012020-11-11 15:32:46 +080093 mdelay(15);
Hung-Te Lin2c307a02019-02-20 14:31:23 +080094 gpio_output(GPIO_LCM_RST_1V8, 1);
95 mdelay(6);
96}
97
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +080098struct panel_description *get_panel_from_cbfs(struct panel_description *desc)
99{
100 /* The CBFS name will be panel-{MANUFACTURER}-${PANEL_NAME},
101 * where MANUFACTURER is 3 characters and PANEL_NAME is usually
102 * 13 characters.
103 */
104 char cbfs_name[64];
105 static union {
106 u8 raw[4 * 1024]; /* Most panels only need < 2K. */
107 struct panel_serializable_data s;
108 } buffer;
109
110 if (!desc->name)
111 return NULL;
112
113 snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name);
Julius Werner834b3ec2020-03-04 16:52:08 -0800114 if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer)))
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +0800115 desc->s = &buffer.s;
116 else
117 printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name);
118
119 return desc->s ? desc : NULL;
120}
121
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800122static struct panel_description *get_active_panel(void)
123{
124 /* TODO(hungte) Create a dedicated panel_id() in board_id.c */
xuxinxiong3ced5282021-03-26 22:53:35 +0800125 int panel_id = sku_id() >> 4 & 0x0F;
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800126
127 struct panel_description *panel = get_panel_description(panel_id);
128 if (!panel) {
129 printk(BIOS_ERR, "%s: Panel %d is not supported.\n",
130 __func__, panel_id);
131 return NULL;
132 }
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +0800133 assert(panel->s);
134
135 const struct edid *edid = &panel->s->edid;
136 const char *name = edid->ascii_string;
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800137 if (name[0] == '\0')
138 name = "unknown name";
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +0800139 printk(BIOS_INFO, "%s: Found ID %d: '%s %s' %dx%d@%dHz\n", __func__,
140 panel_id, edid->manufacturer_name, name, edid->mode.ha,
141 edid->mode.va, edid->mode.refresh);
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800142 return panel;
143}
144
145static bool configure_display(void)
146{
147 struct panel_description *panel = get_active_panel();
148 if (!panel)
149 return false;
150
151 mtcmos_display_power_on();
152 mtcmos_protect_display_bus();
153 configure_panel_backlight();
154 power_on_panel(panel);
155
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +0800156 struct edid *edid = &panel->s->edid;
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800157 edid_set_framebuffer_bits_per_pixel(edid, 32, 0);
158 mtk_ddp_init();
159 u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO |
160 MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
161 MIPI_DSI_MODE_LPM);
Paul Ma6d500a22020-05-08 13:16:04 +0800162 if (CONFIG(DRIVER_ANALOGIX_ANX7625))
Jitao Shib9239312021-03-04 21:52:24 +0800163 mipi_dsi_flags |= MIPI_DSI_MODE_EOT_PACKET |
164 MIPI_DSI_MODE_LINE_END;
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800165 if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, edid,
Hung-Te Lin9ede2ff2019-08-15 09:43:55 +0800166 panel->s->init) < 0) {
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800167 printk(BIOS_ERR, "%s: Failed in DSI init.\n", __func__);
168 return false;
169 }
Jitao Shib32e4d62020-09-25 10:36:29 +0800170
171 if (panel->post_power_on)
172 panel->post_power_on();
173
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800174 mtk_ddp_mode_set(edid);
Patrick Rudolph8b56c8c2020-02-19 12:57:00 +0100175 struct fb_info *info = fb_new_framebuffer_info_from_edid(edid, 0);
Patrick Rudolph73192882020-02-19 12:10:51 +0100176 if (info)
Julius Werner1f84b2c2021-09-01 16:27:58 -0700177 fb_set_orientation(info, panel->orientation);
Patrick Rudolph73192882020-02-19 12:10:51 +0100178
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800179 return true;
180}
181
Tristan Shiehbb684e02018-06-19 16:07:54 +0800182static void mainboard_init(struct device *dev)
183{
Hung-Te Lin2c307a02019-02-20 14:31:23 +0800184 if (display_init_required()) {
185 printk(BIOS_INFO, "%s: Starting display init.\n", __func__);
186 if (!configure_display())
187 printk(BIOS_ERR, "%s: Failed to init display.\n",
188 __func__);
189 } else {
190 printk(BIOS_INFO, "%s: Skipped display init.\n", __func__);
191 }
192
Tristan Shieh8db79c12018-09-07 17:26:21 +0800193 configure_emmc();
Tristan Shieh71ae5822018-09-26 14:33:54 +0800194 configure_usb();
Jiaxin Yu30bc9f42019-04-23 20:45:50 +0800195 configure_audio();
Hung-Te Lin7fc22812020-07-24 08:49:41 +0800196 configure_ec();
Dawei Chien2422f8c2019-05-30 11:55:10 +0800197 if (spm_init())
198 printk(BIOS_ERR,
199 "SPM initialization failed, suspend/resume may fail.\n");
Tristan Shieh4d990ab2019-02-25 17:14:14 +0800200
Hung-Te Lina01f8bc2022-09-06 14:32:05 +0800201 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
202 register_reset_to_bl31(GPIO_RESET.id, true);
Tristan Shiehbb684e02018-06-19 16:07:54 +0800203}
204
205static void mainboard_enable(struct device *dev)
206{
207 dev->ops->init = &mainboard_init;
208}
209
210struct chip_operations mainboard_ops = {
Tristan Shiehbb684e02018-06-19 16:07:54 +0800211 .enable_dev = mainboard_enable,
212};