blob: 101d7cd477990b6d8b8e97cc2373633a254c2c5c [file] [log] [blame]
huang lina6dbfb52016-03-02 18:38:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Rockchip Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
philipchen21b08522017-04-27 18:25:11 -070017#include <assert.h>
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -070018#include <boardid.h>
Julius Wernerc49782c2016-11-21 20:14:18 -080019#include <console/console.h>
Lin Huangb497b482016-03-31 18:44:13 +080020#include <delay.h>
huang lina6dbfb52016-03-02 18:38:40 +080021#include <device/device.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +020022#include <device/i2c_simple.h>
Julius Wernerc49782c2016-11-21 20:14:18 -080023#include <ec/google/chromeec/ec.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070024#include <gpio.h>
Lin Huang5a4be8a2016-05-17 15:45:53 +080025#include <soc/bl31_plat_params.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070026#include <soc/clock.h>
Lin Huangb497b482016-03-31 18:44:13 +080027#include <soc/display.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070028#include <soc/grf.h>
Lin Huangadd76662017-11-23 08:50:03 +080029#include <soc/mipi.h>
Lin Huangb497b482016-03-31 18:44:13 +080030#include <soc/i2c.h>
Liangfeng Wu76655cb2016-05-26 16:06:58 +080031#include <soc/usb.h>
Lin Huangadd76662017-11-23 08:50:03 +080032#include <string.h>
Simon Glassbc679bc2016-06-19 16:09:21 -060033#include <vendorcode/google/chromeos/chromeos.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070034
Vadim Bendebury993dbe12016-05-22 15:53:37 -070035#include "board.h"
36
Brian Norrise06a1b82016-09-21 18:16:54 -070037/*
Caesar Wang212a0262017-05-24 18:02:25 +080038 * We have to drive the stronger pull-up within 1 second of powering up the
Ege Mihmanli75b15432017-11-15 17:19:58 -080039 * touchpad to prevent its firmware from falling into recovery. Not on
40 * Scarlet-based boards.
Caesar Wang212a0262017-05-24 18:02:25 +080041 */
42static void configure_touchpad(void)
43{
Julius Werner6486e782017-07-14 14:30:29 -070044 gpio_output(GPIO_TP_RST_L, 1); /* TP's I2C pull-up rail */
Caesar Wang212a0262017-05-24 18:02:25 +080045}
46
47/*
Brian Norrise06a1b82016-09-21 18:16:54 -070048 * Wifi's PDN/RST line is pulled down by its (unpowered) voltage rails, but
49 * this reset pin is pulled up by default. Let's drive it low as early as we
Philip Chena0618202017-08-23 18:02:25 -070050 * can. This only applies to boards with Marvell 8997 WiFi.
Brian Norrise06a1b82016-09-21 18:16:54 -070051 */
Julius Werner6486e782017-07-14 14:30:29 -070052static void assert_wifi_reset(void)
Brian Norrise06a1b82016-09-21 18:16:54 -070053{
Julius Werner6486e782017-07-14 14:30:29 -070054 gpio_output(GPIO_WLAN_RST_L, 0); /* Assert WLAN_MODULE_RST# */
Brian Norrise06a1b82016-09-21 18:16:54 -070055}
56
Lin Huang2f7ed8d2016-04-08 18:56:20 +080057static void configure_emmc(void)
58{
59 /* Host controller does not support programmable clock generator.
60 * If we don't do this setting, when we use phy to control the
61 * emmc clock(when clock exceed 50MHz), it will get wrong clock.
62 *
63 * Refer to TRM V0.3 Part 1 Chapter 15 PAGE 782 for this register.
64 * Please search "_CON11[7:0]" to locate register description.
65 */
66 write32(&rk3399_grf->emmccore_con[11], RK_CLRSETBITS(0xff, 0));
67
68 rkclk_configure_emmc();
69}
70
Lin Huangc9fea5c2016-08-30 15:34:42 -070071static void register_apio_suspend(void)
72{
73 static struct bl31_apio_param param_apio = {
74 .h = {
75 .type = PARAM_SUSPEND_APIO,
76 },
77 .apio = {
78 .apio1 = 1,
79 .apio2 = 1,
80 .apio3 = 1,
81 .apio4 = 1,
82 .apio5 = 1,
83 },
84 };
85 register_bl31_param(&param_apio.h);
86}
87
Lin Huang7d8ccfb2016-08-22 17:35:40 -070088static void register_gpio_suspend(void)
89{
90 /*
91 * These three GPIO params are used to shut down the 1.5V, 1.8V and
92 * 3.3V power rails, which need to be shut down ordered by voltage,
93 * with highest voltage first.
94 * Since register_bl31() appends to the front of the list, we need to
95 * register them backwards, with 1.5V coming first.
Ege Mihmanli75b15432017-11-15 17:19:58 -080096 * 1.5V and 1.8V are EC-controlled on Scarlet derivatives,
97 * so we skip them.
Lin Huang7d8ccfb2016-08-22 17:35:40 -070098 */
Ege Mihmanli75b15432017-11-15 17:19:58 -080099 if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) {
Julius Werner2be64042017-09-01 14:27:46 -0700100 static struct bl31_gpio_param param_p15_en = {
101 .h = { .type = PARAM_SUSPEND_GPIO },
102 .gpio = { .polarity = BL31_GPIO_LEVEL_LOW },
103 };
104 param_p15_en.gpio.index = GPIO_P15V_EN.raw;
105 register_bl31_param(&param_p15_en.h);
Lin Huang7d8ccfb2016-08-22 17:35:40 -0700106
Julius Werner2be64042017-09-01 14:27:46 -0700107 static struct bl31_gpio_param param_p18_audio_en = {
108 .h = { .type = PARAM_SUSPEND_GPIO },
109 .gpio = { .polarity = BL31_GPIO_LEVEL_LOW },
110 };
111 param_p18_audio_en.gpio.index = GPIO_P18V_AUDIO_PWREN.raw;
112 register_bl31_param(&param_p18_audio_en.h);
113 }
Lin Huang7d8ccfb2016-08-22 17:35:40 -0700114
115 static struct bl31_gpio_param param_p30_en = {
Julius Werner2be64042017-09-01 14:27:46 -0700116 .h = { .type = PARAM_SUSPEND_GPIO },
117 .gpio = { .polarity = BL31_GPIO_LEVEL_LOW },
Lin Huang7d8ccfb2016-08-22 17:35:40 -0700118 };
Julius Werner4ed8b302017-07-14 14:25:39 -0700119 param_p30_en.gpio.index = GPIO_P30V_EN.raw;
Lin Huang7d8ccfb2016-08-22 17:35:40 -0700120 register_bl31_param(&param_p30_en.h);
121}
122
Lin Huang5a4be8a2016-05-17 15:45:53 +0800123static void register_reset_to_bl31(void)
124{
125 static struct bl31_gpio_param param_reset = {
126 .h = {
127 .type = PARAM_RESET,
128 },
129 .gpio = {
130 .polarity = 1,
131 },
132 };
133
134 /* gru/kevin reset pin: gpio0b3 */
Julius Werner4ed8b302017-07-14 14:25:39 -0700135 param_reset.gpio.index = GPIO_RESET.raw,
Lin Huang5a4be8a2016-05-17 15:45:53 +0800136
137 register_bl31_param(&param_reset.h);
138}
139
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800140static void register_poweroff_to_bl31(void)
141{
142 static struct bl31_gpio_param param_poweroff = {
143 .h = {
144 .type = PARAM_POWEROFF,
145 },
146 .gpio = {
147 .polarity = 1,
148 },
149 };
150
151 /*
152 * gru/kevin power off pin: gpio1a6,
153 * reuse with tsadc int pin, so iomux need set back to
154 * gpio in BL31 and depthcharge before you setting this gpio
155 */
Julius Werner4ed8b302017-07-14 14:25:39 -0700156 param_poweroff.gpio.index = GPIO_POWEROFF.raw,
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800157
158 register_bl31_param(&param_poweroff.h);
159}
160
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700161static void configure_sdmmc(void)
162{
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700163 gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */
Vadim Bendebury2832c412016-05-11 15:03:44 +0800164
Lin Huanga2c5b2f2017-07-25 09:50:10 +0800165 /* set SDMMC_DET_L pin */
Ege Mihmanli75b15432017-11-15 17:19:58 -0800166 if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
Lin Huanga2c5b2f2017-07-25 09:50:10 +0800167 /*
168 * do not have external pull up, so need to
169 * set this pin internal pull up
170 */
171 gpio_input_pullup(GPIO(1, B, 3));
Vadim Bendebury2832c412016-05-11 15:03:44 +0800172 else
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -0700173 gpio_input(GPIO(4, D, 0));
Vadim Bendebury2832c412016-05-11 15:03:44 +0800174
Lin Huanga2c5b2f2017-07-25 09:50:10 +0800175 /*
176 * Keep sd card io domain 3v
Ege Mihmanli75b15432017-11-15 17:19:58 -0800177 * In Scarlet derivatives, this GPIO set to high will get 3v,
Lin Huanga2c5b2f2017-07-25 09:50:10 +0800178 * With other board variants setting this GPIO low results in 3V.
179 */
Ege Mihmanli75b15432017-11-15 17:19:58 -0800180 if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
Lin Huanga2c5b2f2017-07-25 09:50:10 +0800181 gpio_output(GPIO(2, D, 4), 1);
182 else
183 gpio_output(GPIO(2, D, 4), 0);
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -0700184
Julius Werner7feb86b2016-09-02 11:25:56 -0700185 gpio_input(GPIO(4, B, 0)); /* SDMMC0_D0 remove pull-up */
186 gpio_input(GPIO(4, B, 1)); /* SDMMC0_D1 remove pull-up */
187 gpio_input(GPIO(4, B, 2)); /* SDMMC0_D2 remove pull-up */
188 gpio_input(GPIO(4, B, 3)); /* SDMMC0_D3 remove pull-up */
189 gpio_input(GPIO(4, B, 4)); /* SDMMC0_CLK remove pull-down */
190 gpio_input(GPIO(4, B, 5)); /* SDMMC0_CMD remove pull-up */
191
Vadim Bendeburyad6ee022016-05-12 16:54:00 +0800192 write32(&rk3399_grf->gpio2_p[2][1], RK_CLRSETBITS(0xfff, 0));
193
194 /*
195 * Set all outputs' drive strength to 8 mA. Group 4 bank B driver
196 * strength requires three bits per pin. Value of 2 written in that
197 * three bit field means '8 mA', as deduced from the kernel code.
198 *
199 * Thus the six pins involved in SDMMC interface require 18 bits to
200 * configure drive strength, but each 32 bit register provides only 16
201 * bits for this setting, this covers 5 pins fully and one bit from
202 * the 6th pin. Two more bits spill over to the next register. This is
203 * described on page 378 of rk3399 TRM Version 0.3 Part 1.
204 */
205 write32(&rk3399_grf->gpio4b_e01,
206 RK_CLRSETBITS(0xffff,
207 (2 << 0) | (2 << 3) |
208 (2 << 6) | (2 << 9) | (2 << 12)));
209 write32(&rk3399_grf->gpio4b_e2, RK_CLRSETBITS(3, 1));
210
211 /* And now set the multiplexor to enable SDMMC0. */
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700212 write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC);
213}
huang lina6dbfb52016-03-02 18:38:40 +0800214
Xing Zheng96fbc312016-05-19 11:39:20 +0800215static void configure_codec(void)
216{
Julius Werner7feb86b2016-09-02 11:25:56 -0700217 gpio_input(GPIO(3, D, 0)); /* I2S0_SCLK remove pull-up */
218 gpio_input(GPIO(3, D, 1)); /* I2S0_RX remove pull-up */
219 gpio_input(GPIO(3, D, 2)); /* I2S0_TX remove pull-up */
220 gpio_input(GPIO(3, D, 3)); /* I2S0_SDI0 remove pull-up */
Julius Werner5598db22017-12-08 16:42:59 -0800221 /* GPIOs 3_D4 - 3_D6 not used for I2S and are SKU ID pins on Scarlet. */
Julius Werner7feb86b2016-09-02 11:25:56 -0700222 gpio_input(GPIO(3, D, 7)); /* I2S0_SDO0 remove pull-up */
223 gpio_input(GPIO(4, A, 0)); /* I2S0_MCLK remove pull-up */
224
Julius Werner5598db22017-12-08 16:42:59 -0800225 write32(&rk3399_grf->iomux_i2s0, IOMUX_I2S0_SD0);
Xing Zheng96fbc312016-05-19 11:39:20 +0800226 write32(&rk3399_grf->iomux_i2sclk, IOMUX_I2SCLK);
227
Ege Mihmanli75b15432017-11-15 17:19:58 -0800228 if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
Julius Werner1ab8c012017-11-03 15:23:09 -0700229 gpio_output(GPIO_P18V_AUDIO_PWREN, 1);
230 gpio_output(GPIO_SPK_PA_EN, 0);
Xing Zheng96fbc312016-05-19 11:39:20 +0800231
232 rkclk_configure_i2s(12288000);
233}
234
Lin Huangb497b482016-03-31 18:44:13 +0800235static void configure_display(void)
236{
Ege Mihmanlibeb04682017-11-20 11:54:02 -0800237 /*
238 * Rainier is Scarlet-derived, but uses EDP so use board-specific
239 * config rather than baseboard.
240 */
241 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_SCARLET)) {
Julius Werner6486e782017-07-14 14:30:29 -0700242 gpio_output(GPIO(4, D, 1), 0); /* DISPLAY_RST_L */
243 gpio_output(GPIO(4, D, 3), 1); /* PPVARP_LCD */
244 mdelay(10);
245 gpio_output(GPIO(4, D, 4), 1); /* PPVARN_LCD */
246 mdelay(20 + 2); /* add 2ms for bias rise time */
247 gpio_output(GPIO(4, D, 1), 1); /* DISPLAY_RST_L */
248 mdelay(30);
249 } else {
250 /* set pinmux for edp HPD */
251 gpio_input_pulldown(GPIO(4, C, 7));
252 write32(&rk3399_grf->iomux_edp_hotplug, IOMUX_EDP_HOTPLUG);
Lin Huangb497b482016-03-31 18:44:13 +0800253
Julius Werner6486e782017-07-14 14:30:29 -0700254 gpio_output(GPIO(4, D, 3), 1); /* P3.3V_DISP */
255 }
Lin Huangb497b482016-03-31 18:44:13 +0800256}
257
Julius Wernerc49782c2016-11-21 20:14:18 -0800258static void usb_power_cycle(int port)
259{
260 if (google_chromeec_set_usb_pd_role(port, USB_PD_CTRL_ROLE_FORCE_SINK))
261 printk(BIOS_ERR, "ERROR: Cannot force USB%d PD sink\n", port);
262
263 mdelay(10); /* Make sure USB stick is fully depowered. */
264
265 if (google_chromeec_set_usb_pd_role(port, USB_PD_CTRL_ROLE_TOGGLE_ON))
266 printk(BIOS_ERR, "ERROR: Cannot restore USB%d PD mode\n", port);
267}
268
philipchen21b08522017-04-27 18:25:11 -0700269static void setup_usb(int port)
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800270{
philipchen21b08522017-04-27 18:25:11 -0700271 /* Must be PHY0 or PHY1. */
272 assert(port == 0 || port == 1);
273
William wu605a87c2017-01-09 19:02:39 +0800274 /*
275 * A few magic PHY tuning values that improve eye diagram amplitude
276 * and make it extra sure we get reliable communication in firmware
277 * Set max ODT compensation voltage and current tuning reference.
278 */
philipchen21b08522017-04-27 18:25:11 -0700279 write32(&rk3399_grf->usbphy_ctrl[port][3], RK_CLRSETBITS(0xfff, 0x2e3));
William wu9f470b12016-11-10 19:34:45 +0800280
Caesar Wang9e588002017-02-10 11:16:13 +0800281 /* Set max pre-emphasis level on PHY0 and PHY1. */
philipchen21b08522017-04-27 18:25:11 -0700282 write32(&rk3399_grf->usbphy_ctrl[port][12],
Caesar Wang9e588002017-02-10 11:16:13 +0800283 RK_CLRSETBITS(0xffff, 0xa7));
William wu9f470b12016-11-10 19:34:45 +0800284
Caesar Wang9e588002017-02-10 11:16:13 +0800285 /*
William wuebbdd282017-01-23 20:54:22 +0800286 * 1. Disable the pre-emphasize in eop state and chirp
Caesar Wang9e588002017-02-10 11:16:13 +0800287 * state to avoid mis-trigger the disconnect detection
288 * and also avoid high-speed handshake fail for PHY0
289 * and PHY1 consist of otg-port and host-port.
William wuebbdd282017-01-23 20:54:22 +0800290 *
291 * 2. Configure PHY0 and PHY1 otg-ports squelch detection
292 * threshold to 125mV (default is 150mV).
Caesar Wang9e588002017-02-10 11:16:13 +0800293 */
philipchen21b08522017-04-27 18:25:11 -0700294 write32(&rk3399_grf->usbphy_ctrl[port][0],
William wuebbdd282017-01-23 20:54:22 +0800295 RK_CLRSETBITS(7 << 13 | 3 << 0, 6 << 13));
philipchen21b08522017-04-27 18:25:11 -0700296 write32(&rk3399_grf->usbphy_ctrl[port][13], RK_CLRBITS(3 << 0));
William wu9f470b12016-11-10 19:34:45 +0800297
Caesar Wang9e588002017-02-10 11:16:13 +0800298 /*
299 * ODT auto compensation bypass, and set max driver
300 * strength only for PHY0 and PHY1 otg-port.
301 */
philipchen21b08522017-04-27 18:25:11 -0700302 write32(&rk3399_grf->usbphy_ctrl[port][2],
Caesar Wang9e588002017-02-10 11:16:13 +0800303 RK_CLRSETBITS(0x7e << 4, 0x60 << 4));
William wu9f470b12016-11-10 19:34:45 +0800304
Caesar Wang9e588002017-02-10 11:16:13 +0800305 /*
306 * ODT auto refresh bypass, and set the max bias current
307 * tuning reference only for PHY0 and PHY1 otg-port.
308 */
philipchen21b08522017-04-27 18:25:11 -0700309 write32(&rk3399_grf->usbphy_ctrl[port][3],
Caesar Wang9e588002017-02-10 11:16:13 +0800310 RK_CLRSETBITS(0x21c, 1 << 4));
William wu605a87c2017-01-09 19:02:39 +0800311
Caesar Wang9e588002017-02-10 11:16:13 +0800312 /*
313 * ODT auto compensation bypass, and set default driver
314 * strength only for PHY0 and PHY1 host-port.
315 */
philipchen21b08522017-04-27 18:25:11 -0700316 write32(&rk3399_grf->usbphy_ctrl[port][15], RK_SETBITS(1 << 10));
William wu605a87c2017-01-09 19:02:39 +0800317
Caesar Wang9e588002017-02-10 11:16:13 +0800318 /* ODT auto refresh bypass only for PHY0 and PHY1 host-port. */
philipchen21b08522017-04-27 18:25:11 -0700319 write32(&rk3399_grf->usbphy_ctrl[port][16], RK_CLRBITS(1 << 9));
Julius Werner1c8491c2016-08-15 17:58:05 -0700320
philipchen21b08522017-04-27 18:25:11 -0700321 if (port == 0)
322 setup_usb_otg0();
323 else
324 setup_usb_otg1();
Julius Wernerc49782c2016-11-21 20:14:18 -0800325
326 /*
327 * Need to power-cycle USB ports for use in firmware, since some devices
328 * can't fall back to USB 2.0 after they saw SuperSpeed terminations.
329 * This takes about a dozen milliseconds, so only do it in boot modes
330 * that have firmware UI (which one could select USB boot from).
331 */
philipchen21b08522017-04-27 18:25:11 -0700332 if (display_init_required())
333 usb_power_cycle(port);
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800334}
335
huang lina6dbfb52016-03-02 18:38:40 +0800336static void mainboard_init(device_t dev)
337{
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700338 configure_sdmmc();
Lin Huang2f7ed8d2016-04-08 18:56:20 +0800339 configure_emmc();
Xing Zheng96fbc312016-05-19 11:39:20 +0800340 configure_codec();
Julius Werner6486e782017-07-14 14:30:29 -0700341 if (display_init_required())
342 configure_display();
philipchen21b08522017-04-27 18:25:11 -0700343 setup_usb(0);
Philip Chena0618202017-08-23 18:02:25 -0700344 if (IS_ENABLED(CONFIG_GRU_HAS_WLAN_RESET))
345 assert_wifi_reset();
Ege Mihmanli75b15432017-11-15 17:19:58 -0800346 if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) {
Julius Werner6486e782017-07-14 14:30:29 -0700347 configure_touchpad(); /* Scarlet: works differently */
348 setup_usb(1); /* Scarlet: only one USB port */
Julius Werner6486e782017-07-14 14:30:29 -0700349 }
Julius Werner2be64042017-09-01 14:27:46 -0700350 register_gpio_suspend();
Lin Huang5a4be8a2016-05-17 15:45:53 +0800351 register_reset_to_bl31();
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800352 register_poweroff_to_bl31();
Lin Huangc9fea5c2016-08-30 15:34:42 -0700353 register_apio_suspend();
Lin Huangb497b482016-03-31 18:44:13 +0800354}
355
Philip Chena304b692017-04-06 10:17:08 -0700356static void prepare_backlight_i2c(void)
Lin Huangb497b482016-03-31 18:44:13 +0800357{
Julius Werner7feb86b2016-09-02 11:25:56 -0700358 gpio_input(GPIO(1, B, 7)); /* I2C0_SDA remove pull_up */
359 gpio_input(GPIO(1, C, 0)); /* I2C0_SCL remove pull_up */
360
361 i2c_init(0, 100*KHz);
362
Lin Huangb497b482016-03-31 18:44:13 +0800363 write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA);
364 write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL);
Lin Huangb497b482016-03-31 18:44:13 +0800365}
366
367void mainboard_power_on_backlight(void)
368{
Lin Huang18617bf2017-11-20 14:57:22 +0800369 gpio_output(GPIO_BL_EN, 1); /* BL_EN */
370
371 /* Configure as output GPIO, to be toggled by payload. */
372 if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
373 gpio_output(GPIO_BACKLIGHT, 0);
Lin Huangb497b482016-03-31 18:44:13 +0800374
Philip Chena304b692017-04-06 10:17:08 -0700375 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_GRU))
376 prepare_backlight_i2c();
huang lina6dbfb52016-03-02 18:38:40 +0800377}
378
Lin Huangadd76662017-11-23 08:50:03 +0800379static struct panel_init_command kd097d04_init_commands[] = {
380 /* voltage setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800381 MIPI_INIT_CMD(0xB0, 0x00),
382 MIPI_INIT_CMD(0xB2, 0x02),
383 MIPI_INIT_CMD(0xB3, 0x11),
384 MIPI_INIT_CMD(0xB4, 0x00),
385 MIPI_INIT_CMD(0xB6, 0x80),
Lin Huangadd76662017-11-23 08:50:03 +0800386 /* VCOM disable */
Lin Huang0499ce92018-01-17 14:24:14 +0800387 MIPI_INIT_CMD(0xB8, 0x80),
388 MIPI_INIT_CMD(0xBA, 0x43),
Lin Huangadd76662017-11-23 08:50:03 +0800389 /* VCOM setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800390 MIPI_INIT_CMD(0xBB, 0x53),
Lin Huangadd76662017-11-23 08:50:03 +0800391 /* VSP setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800392 MIPI_INIT_CMD(0xBC, 0x0A),
Lin Huangadd76662017-11-23 08:50:03 +0800393 /* VSN setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800394 MIPI_INIT_CMD(0xBD, 0x4A),
Lin Huangadd76662017-11-23 08:50:03 +0800395 /* VGH setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800396 MIPI_INIT_CMD(0xBE, 0x2F),
Lin Huangadd76662017-11-23 08:50:03 +0800397 /* VGL setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800398 MIPI_INIT_CMD(0xBF, 0x1A),
399 MIPI_INIT_CMD(0xF0, 0x39),
400 MIPI_INIT_CMD(0xF1, 0x21),
Lin Huangadd76662017-11-23 08:50:03 +0800401 /* Gamma setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800402 MIPI_INIT_CMD(0xB0, 0x02),
403 MIPI_INIT_CMD(0xC0, 0x00),
404 MIPI_INIT_CMD(0xC1, 0x01),
405 MIPI_INIT_CMD(0xC2, 0x0B),
406 MIPI_INIT_CMD(0xC3, 0x15),
407 MIPI_INIT_CMD(0xC4, 0x22),
408 MIPI_INIT_CMD(0xC5, 0x11),
409 MIPI_INIT_CMD(0xC6, 0x15),
410 MIPI_INIT_CMD(0xC7, 0x19),
411 MIPI_INIT_CMD(0xC8, 0x1A),
412 MIPI_INIT_CMD(0xC9, 0x16),
413 MIPI_INIT_CMD(0xCA, 0x18),
414 MIPI_INIT_CMD(0xCB, 0x13),
415 MIPI_INIT_CMD(0xCC, 0x18),
416 MIPI_INIT_CMD(0xCD, 0x13),
417 MIPI_INIT_CMD(0xCE, 0x1C),
418 MIPI_INIT_CMD(0xCF, 0x19),
419 MIPI_INIT_CMD(0xD0, 0x21),
420 MIPI_INIT_CMD(0xD1, 0x2C),
421 MIPI_INIT_CMD(0xD2, 0x2F),
422 MIPI_INIT_CMD(0xD3, 0x30),
423 MIPI_INIT_CMD(0xD4, 0x19),
424 MIPI_INIT_CMD(0xD5, 0x1F),
425 MIPI_INIT_CMD(0xD6, 0x00),
426 MIPI_INIT_CMD(0xD7, 0x01),
427 MIPI_INIT_CMD(0xD8, 0x0B),
428 MIPI_INIT_CMD(0xD9, 0x15),
429 MIPI_INIT_CMD(0xDA, 0x22),
430 MIPI_INIT_CMD(0xDB, 0x11),
431 MIPI_INIT_CMD(0xDC, 0x15),
432 MIPI_INIT_CMD(0xDD, 0x19),
433 MIPI_INIT_CMD(0xDE, 0x1A),
434 MIPI_INIT_CMD(0xDF, 0x16),
435 MIPI_INIT_CMD(0xE0, 0x18),
436 MIPI_INIT_CMD(0xE1, 0x13),
437 MIPI_INIT_CMD(0xE2, 0x18),
438 MIPI_INIT_CMD(0xE3, 0x13),
439 MIPI_INIT_CMD(0xE4, 0x1C),
440 MIPI_INIT_CMD(0xE5, 0x19),
441 MIPI_INIT_CMD(0xE6, 0x21),
442 MIPI_INIT_CMD(0xE7, 0x2C),
443 MIPI_INIT_CMD(0xE8, 0x2F),
444 MIPI_INIT_CMD(0xE9, 0x30),
445 MIPI_INIT_CMD(0xEA, 0x19),
446 MIPI_INIT_CMD(0xEB, 0x1F),
Lin Huangadd76662017-11-23 08:50:03 +0800447 /* GOA MUX setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800448 MIPI_INIT_CMD(0xB0, 0x01),
449 MIPI_INIT_CMD(0xC0, 0x10),
450 MIPI_INIT_CMD(0xC1, 0x0F),
451 MIPI_INIT_CMD(0xC2, 0x0E),
452 MIPI_INIT_CMD(0xC3, 0x0D),
453 MIPI_INIT_CMD(0xC4, 0x0C),
454 MIPI_INIT_CMD(0xC5, 0x0B),
455 MIPI_INIT_CMD(0xC6, 0x0A),
456 MIPI_INIT_CMD(0xC7, 0x09),
457 MIPI_INIT_CMD(0xC8, 0x08),
458 MIPI_INIT_CMD(0xC9, 0x07),
459 MIPI_INIT_CMD(0xCA, 0x06),
460 MIPI_INIT_CMD(0xCB, 0x05),
461 MIPI_INIT_CMD(0xCC, 0x00),
462 MIPI_INIT_CMD(0xCD, 0x01),
463 MIPI_INIT_CMD(0xCE, 0x02),
464 MIPI_INIT_CMD(0xCF, 0x03),
465 MIPI_INIT_CMD(0xD0, 0x04),
466 MIPI_INIT_CMD(0xD6, 0x10),
467 MIPI_INIT_CMD(0xD7, 0x0F),
468 MIPI_INIT_CMD(0xD8, 0x0E),
469 MIPI_INIT_CMD(0xD9, 0x0D),
470 MIPI_INIT_CMD(0xDA, 0x0C),
471 MIPI_INIT_CMD(0xDB, 0x0B),
472 MIPI_INIT_CMD(0xDC, 0x0A),
473 MIPI_INIT_CMD(0xDD, 0x09),
474 MIPI_INIT_CMD(0xDE, 0x08),
475 MIPI_INIT_CMD(0xDF, 0x07),
476 MIPI_INIT_CMD(0xE0, 0x06),
477 MIPI_INIT_CMD(0xE1, 0x05),
478 MIPI_INIT_CMD(0xE2, 0x00),
479 MIPI_INIT_CMD(0xE3, 0x01),
480 MIPI_INIT_CMD(0xE4, 0x02),
481 MIPI_INIT_CMD(0xE5, 0x03),
482 MIPI_INIT_CMD(0xE6, 0x04),
483 MIPI_INIT_CMD(0xE7, 0x00),
484 MIPI_INIT_CMD(0xEC, 0xC0),
Lin Huangadd76662017-11-23 08:50:03 +0800485 /* GOA timing setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800486 MIPI_INIT_CMD(0xB0, 0x03),
487 MIPI_INIT_CMD(0xC0, 0x01),
488 MIPI_INIT_CMD(0xC2, 0x6F),
489 MIPI_INIT_CMD(0xC3, 0x6F),
490 MIPI_INIT_CMD(0xC5, 0x36),
491 MIPI_INIT_CMD(0xC8, 0x08),
492 MIPI_INIT_CMD(0xC9, 0x04),
493 MIPI_INIT_CMD(0xCA, 0x41),
494 MIPI_INIT_CMD(0xCC, 0x43),
495 MIPI_INIT_CMD(0xCF, 0x60),
496 MIPI_INIT_CMD(0xD2, 0x04),
497 MIPI_INIT_CMD(0xD3, 0x04),
498 MIPI_INIT_CMD(0xD4, 0x03),
499 MIPI_INIT_CMD(0xD5, 0x02),
500 MIPI_INIT_CMD(0xD6, 0x01),
501 MIPI_INIT_CMD(0xD7, 0x00),
502 MIPI_INIT_CMD(0xDB, 0x01),
503 MIPI_INIT_CMD(0xDE, 0x36),
504 MIPI_INIT_CMD(0xE6, 0x6F),
505 MIPI_INIT_CMD(0xE7, 0x6F),
Lin Huangadd76662017-11-23 08:50:03 +0800506 /* GOE setting */
Lin Huang0499ce92018-01-17 14:24:14 +0800507 MIPI_INIT_CMD(0xB0, 0x06),
508 MIPI_INIT_CMD(0xB8, 0xA5),
509 MIPI_INIT_CMD(0xC0, 0xA5),
510 MIPI_INIT_CMD(0xD5, 0x3F),
511 {},
Lin Huangadd76662017-11-23 08:50:03 +0800512};
513
514const struct mipi_panel_data kd097d04_panel = {
515 .mipi_num = 2,
516 .format = MIPI_DSI_FMT_RGB888,
517 .lanes = 8,
518 .display_on_udelay = 120000,
519 .video_mode_udelay = 5000,
520 .init_cmd = kd097d04_init_commands,
Lin Huangadd76662017-11-23 08:50:03 +0800521};
522
523static const struct edid_mode kd097d04_edid_mode = {
524 .name = "1536x2048@60Hz",
Lin Huangab21ab92017-12-06 10:18:10 +0800525 .pixel_clock = 216000,
Lin Huangadd76662017-11-23 08:50:03 +0800526 .refresh = 60,
527 .ha = 1536,
Lin Huangab21ab92017-12-06 10:18:10 +0800528 .hbl = 186,
529 .hso = 81,
Lin Huangadd76662017-11-23 08:50:03 +0800530 .hspw = 24,
531 .va = 2048,
Lin Huangab21ab92017-12-06 10:18:10 +0800532 .vbl = 42,
Lin Huangadd76662017-11-23 08:50:03 +0800533 .vso = 17,
534 .vspw = 2,
535};
536
Lin Huang318a03a2017-12-08 10:31:46 +0800537const struct mipi_panel_data inx097pfg_panel = {
538 .mipi_num = 2,
539 .format = MIPI_DSI_FMT_RGB888,
540 .lanes = 8,
541 .display_on_udelay = 120000,
542 .video_mode_udelay = 5000,
543};
544
545static const struct edid_mode inx097pfg_edid_mode = {
546 .name = "1536x2048@60Hz",
547 .pixel_clock = 220000,
548 .refresh = 60,
549 .ha = 1536,
550 .hbl = 224,
551 .hso = 100,
552 .hspw = 24,
553 .va = 2048,
554 .vbl = 38,
555 .vso = 18,
556 .vspw = 2,
557};
558
Lin Huangadd76662017-11-23 08:50:03 +0800559const struct mipi_panel_data *mainboard_get_mipi_mode
560 (struct edid_mode *edid_mode)
Lin Huang25fb09b2017-11-22 09:40:50 +0800561{
Lin Huang318a03a2017-12-08 10:31:46 +0800562 switch (sku_id()) {
563 case 0:
564 case 2:
565 case 4:
566 case 6:
567 memcpy(edid_mode, &inx097pfg_edid_mode,
568 sizeof(struct edid_mode));
569 return &inx097pfg_panel;
570 case 1:
571 case 3:
572 case 5:
573 case 7:
574 default:
575 memcpy(edid_mode, &kd097d04_edid_mode,
576 sizeof(struct edid_mode));
577 return &kd097d04_panel;
578 }
Lin Huang25fb09b2017-11-22 09:40:50 +0800579}
580
huang lina6dbfb52016-03-02 18:38:40 +0800581static void mainboard_enable(device_t dev)
582{
583 dev->ops->init = &mainboard_init;
584}
585
586struct chip_operations mainboard_ops = {
587 .name = CONFIG_MAINBOARD_PART_NUMBER,
588 .enable_dev = mainboard_enable,
589};