blob: d83c486e5a0beeaba62a78237e948ec2a898bbf5 [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 */
221 gpio_input(GPIO(3, D, 4)); /* I2S0_SDI1 remove pull-up */
222 /* GPIO3_D5 (I2S0_SDI2SDO2) not connected */
223 gpio_input(GPIO(3, D, 6)); /* I2S0_SDO1 remove pull-up */
224 gpio_input(GPIO(3, D, 7)); /* I2S0_SDO0 remove pull-up */
225 gpio_input(GPIO(4, A, 0)); /* I2S0_MCLK remove pull-up */
226
Xing Zheng96fbc312016-05-19 11:39:20 +0800227 write32(&rk3399_grf->iomux_i2s0, IOMUX_I2S0);
228 write32(&rk3399_grf->iomux_i2sclk, IOMUX_I2SCLK);
229
230 /* AUDIO IO domain 1.8V voltage selection */
231 write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 1));
232
Ege Mihmanli75b15432017-11-15 17:19:58 -0800233 if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
Julius Werner1ab8c012017-11-03 15:23:09 -0700234 gpio_output(GPIO_P18V_AUDIO_PWREN, 1);
235 gpio_output(GPIO_SPK_PA_EN, 0);
Xing Zheng96fbc312016-05-19 11:39:20 +0800236
237 rkclk_configure_i2s(12288000);
238}
239
Lin Huangb497b482016-03-31 18:44:13 +0800240static void configure_display(void)
241{
Ege Mihmanlibeb04682017-11-20 11:54:02 -0800242 /*
243 * Rainier is Scarlet-derived, but uses EDP so use board-specific
244 * config rather than baseboard.
245 */
246 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_SCARLET)) {
Julius Werner6486e782017-07-14 14:30:29 -0700247 gpio_output(GPIO(4, D, 1), 0); /* DISPLAY_RST_L */
248 gpio_output(GPIO(4, D, 3), 1); /* PPVARP_LCD */
249 mdelay(10);
250 gpio_output(GPIO(4, D, 4), 1); /* PPVARN_LCD */
251 mdelay(20 + 2); /* add 2ms for bias rise time */
252 gpio_output(GPIO(4, D, 1), 1); /* DISPLAY_RST_L */
253 mdelay(30);
254 } else {
255 /* set pinmux for edp HPD */
256 gpio_input_pulldown(GPIO(4, C, 7));
257 write32(&rk3399_grf->iomux_edp_hotplug, IOMUX_EDP_HOTPLUG);
Lin Huangb497b482016-03-31 18:44:13 +0800258
Julius Werner6486e782017-07-14 14:30:29 -0700259 gpio_output(GPIO(4, D, 3), 1); /* P3.3V_DISP */
260 }
Lin Huangb497b482016-03-31 18:44:13 +0800261}
262
Julius Wernerc49782c2016-11-21 20:14:18 -0800263static void usb_power_cycle(int port)
264{
265 if (google_chromeec_set_usb_pd_role(port, USB_PD_CTRL_ROLE_FORCE_SINK))
266 printk(BIOS_ERR, "ERROR: Cannot force USB%d PD sink\n", port);
267
268 mdelay(10); /* Make sure USB stick is fully depowered. */
269
270 if (google_chromeec_set_usb_pd_role(port, USB_PD_CTRL_ROLE_TOGGLE_ON))
271 printk(BIOS_ERR, "ERROR: Cannot restore USB%d PD mode\n", port);
272}
273
philipchen21b08522017-04-27 18:25:11 -0700274static void setup_usb(int port)
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800275{
philipchen21b08522017-04-27 18:25:11 -0700276 /* Must be PHY0 or PHY1. */
277 assert(port == 0 || port == 1);
278
William wu605a87c2017-01-09 19:02:39 +0800279 /*
280 * A few magic PHY tuning values that improve eye diagram amplitude
281 * and make it extra sure we get reliable communication in firmware
282 * Set max ODT compensation voltage and current tuning reference.
283 */
philipchen21b08522017-04-27 18:25:11 -0700284 write32(&rk3399_grf->usbphy_ctrl[port][3], RK_CLRSETBITS(0xfff, 0x2e3));
William wu9f470b12016-11-10 19:34:45 +0800285
Caesar Wang9e588002017-02-10 11:16:13 +0800286 /* Set max pre-emphasis level on PHY0 and PHY1. */
philipchen21b08522017-04-27 18:25:11 -0700287 write32(&rk3399_grf->usbphy_ctrl[port][12],
Caesar Wang9e588002017-02-10 11:16:13 +0800288 RK_CLRSETBITS(0xffff, 0xa7));
William wu9f470b12016-11-10 19:34:45 +0800289
Caesar Wang9e588002017-02-10 11:16:13 +0800290 /*
William wuebbdd282017-01-23 20:54:22 +0800291 * 1. Disable the pre-emphasize in eop state and chirp
Caesar Wang9e588002017-02-10 11:16:13 +0800292 * state to avoid mis-trigger the disconnect detection
293 * and also avoid high-speed handshake fail for PHY0
294 * and PHY1 consist of otg-port and host-port.
William wuebbdd282017-01-23 20:54:22 +0800295 *
296 * 2. Configure PHY0 and PHY1 otg-ports squelch detection
297 * threshold to 125mV (default is 150mV).
Caesar Wang9e588002017-02-10 11:16:13 +0800298 */
philipchen21b08522017-04-27 18:25:11 -0700299 write32(&rk3399_grf->usbphy_ctrl[port][0],
William wuebbdd282017-01-23 20:54:22 +0800300 RK_CLRSETBITS(7 << 13 | 3 << 0, 6 << 13));
philipchen21b08522017-04-27 18:25:11 -0700301 write32(&rk3399_grf->usbphy_ctrl[port][13], RK_CLRBITS(3 << 0));
William wu9f470b12016-11-10 19:34:45 +0800302
Caesar Wang9e588002017-02-10 11:16:13 +0800303 /*
304 * ODT auto compensation bypass, and set max driver
305 * strength only for PHY0 and PHY1 otg-port.
306 */
philipchen21b08522017-04-27 18:25:11 -0700307 write32(&rk3399_grf->usbphy_ctrl[port][2],
Caesar Wang9e588002017-02-10 11:16:13 +0800308 RK_CLRSETBITS(0x7e << 4, 0x60 << 4));
William wu9f470b12016-11-10 19:34:45 +0800309
Caesar Wang9e588002017-02-10 11:16:13 +0800310 /*
311 * ODT auto refresh bypass, and set the max bias current
312 * tuning reference only for PHY0 and PHY1 otg-port.
313 */
philipchen21b08522017-04-27 18:25:11 -0700314 write32(&rk3399_grf->usbphy_ctrl[port][3],
Caesar Wang9e588002017-02-10 11:16:13 +0800315 RK_CLRSETBITS(0x21c, 1 << 4));
William wu605a87c2017-01-09 19:02:39 +0800316
Caesar Wang9e588002017-02-10 11:16:13 +0800317 /*
318 * ODT auto compensation bypass, and set default driver
319 * strength only for PHY0 and PHY1 host-port.
320 */
philipchen21b08522017-04-27 18:25:11 -0700321 write32(&rk3399_grf->usbphy_ctrl[port][15], RK_SETBITS(1 << 10));
William wu605a87c2017-01-09 19:02:39 +0800322
Caesar Wang9e588002017-02-10 11:16:13 +0800323 /* ODT auto refresh bypass only for PHY0 and PHY1 host-port. */
philipchen21b08522017-04-27 18:25:11 -0700324 write32(&rk3399_grf->usbphy_ctrl[port][16], RK_CLRBITS(1 << 9));
Julius Werner1c8491c2016-08-15 17:58:05 -0700325
philipchen21b08522017-04-27 18:25:11 -0700326 if (port == 0)
327 setup_usb_otg0();
328 else
329 setup_usb_otg1();
Julius Wernerc49782c2016-11-21 20:14:18 -0800330
331 /*
332 * Need to power-cycle USB ports for use in firmware, since some devices
333 * can't fall back to USB 2.0 after they saw SuperSpeed terminations.
334 * This takes about a dozen milliseconds, so only do it in boot modes
335 * that have firmware UI (which one could select USB boot from).
336 */
philipchen21b08522017-04-27 18:25:11 -0700337 if (display_init_required())
338 usb_power_cycle(port);
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800339}
340
huang lina6dbfb52016-03-02 18:38:40 +0800341static void mainboard_init(device_t dev)
342{
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700343 configure_sdmmc();
Lin Huang2f7ed8d2016-04-08 18:56:20 +0800344 configure_emmc();
Xing Zheng96fbc312016-05-19 11:39:20 +0800345 configure_codec();
Julius Werner6486e782017-07-14 14:30:29 -0700346 if (display_init_required())
347 configure_display();
philipchen21b08522017-04-27 18:25:11 -0700348 setup_usb(0);
Philip Chena0618202017-08-23 18:02:25 -0700349 if (IS_ENABLED(CONFIG_GRU_HAS_WLAN_RESET))
350 assert_wifi_reset();
Ege Mihmanli75b15432017-11-15 17:19:58 -0800351 if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) {
Julius Werner6486e782017-07-14 14:30:29 -0700352 configure_touchpad(); /* Scarlet: works differently */
353 setup_usb(1); /* Scarlet: only one USB port */
Julius Werner6486e782017-07-14 14:30:29 -0700354 }
Julius Werner2be64042017-09-01 14:27:46 -0700355 register_gpio_suspend();
Lin Huang5a4be8a2016-05-17 15:45:53 +0800356 register_reset_to_bl31();
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800357 register_poweroff_to_bl31();
Lin Huangc9fea5c2016-08-30 15:34:42 -0700358 register_apio_suspend();
Lin Huangb497b482016-03-31 18:44:13 +0800359}
360
Philip Chena304b692017-04-06 10:17:08 -0700361static void prepare_backlight_i2c(void)
Lin Huangb497b482016-03-31 18:44:13 +0800362{
Julius Werner7feb86b2016-09-02 11:25:56 -0700363 gpio_input(GPIO(1, B, 7)); /* I2C0_SDA remove pull_up */
364 gpio_input(GPIO(1, C, 0)); /* I2C0_SCL remove pull_up */
365
366 i2c_init(0, 100*KHz);
367
Lin Huangb497b482016-03-31 18:44:13 +0800368 write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA);
369 write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL);
Lin Huangb497b482016-03-31 18:44:13 +0800370}
371
372void mainboard_power_on_backlight(void)
373{
Lin Huang18617bf2017-11-20 14:57:22 +0800374 gpio_output(GPIO_BL_EN, 1); /* BL_EN */
375
376 /* Configure as output GPIO, to be toggled by payload. */
377 if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET))
378 gpio_output(GPIO_BACKLIGHT, 0);
Lin Huangb497b482016-03-31 18:44:13 +0800379
Philip Chena304b692017-04-06 10:17:08 -0700380 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_GRU))
381 prepare_backlight_i2c();
huang lina6dbfb52016-03-02 18:38:40 +0800382}
383
Lin Huangadd76662017-11-23 08:50:03 +0800384static struct panel_init_command kd097d04_init_commands[] = {
385 /* voltage setting */
386 { 0xB0, 0x00 },
387 { 0xB2, 0x02 },
388 { 0xB3, 0x11 },
389 { 0xB4, 0x00 },
390 { 0xB6, 0x80 },
391 /* VCOM disable */
392 { 0xB8, 0x80 },
393 { 0xBA, 0x43 },
394 /* VCOM setting */
395 { 0xBB, 0x53 },
396 /* VSP setting */
397 { 0xBC, 0x0A },
398 /* VSN setting */
399 { 0xBD, 0x4A },
400 /* VGH setting */
401 { 0xBE, 0x2F },
402 /* VGL setting */
403 { 0xBF, 0x1A },
404 { 0xF0, 0x39 },
405 { 0xF1, 0x21 },
406 /* Gamma setting */
407 { 0xB0, 0x02 },
408 { 0xC0, 0x00 },
409 { 0xC1, 0x01 },
410 { 0xC2, 0x0B },
411 { 0xC3, 0x15 },
412 { 0xC4, 0x22 },
413 { 0xC5, 0x11 },
414 { 0xC6, 0x15 },
415 { 0xC7, 0x19 },
416 { 0xC8, 0x1A },
417 { 0xC9, 0x16 },
418 { 0xCA, 0x18 },
419 { 0xCB, 0x13 },
420 { 0xCC, 0x18 },
421 { 0xCD, 0x13 },
422 { 0xCE, 0x1C },
423 { 0xCF, 0x19 },
424 { 0xD0, 0x21 },
425 { 0xD1, 0x2C },
426 { 0xD2, 0x2F },
427 { 0xD3, 0x30 },
428 { 0xD4, 0x19 },
429 { 0xD5, 0x1F },
430 { 0xD6, 0x00 },
431 { 0xD7, 0x01 },
432 { 0xD8, 0x0B },
433 { 0xD9, 0x15 },
434 { 0xDA, 0x22 },
435 { 0xDB, 0x11 },
436 { 0xDC, 0x15 },
437 { 0xDD, 0x19 },
438 { 0xDE, 0x1A },
439 { 0xDF, 0x16 },
440 { 0xE0, 0x18 },
441 { 0xE1, 0x13 },
442 { 0xE2, 0x18 },
443 { 0xE3, 0x13 },
444 { 0xE4, 0x1C },
445 { 0xE5, 0x19 },
446 { 0xE6, 0x21 },
447 { 0xE7, 0x2C },
448 { 0xE8, 0x2F },
449 { 0xE9, 0x30 },
450 { 0xEA, 0x19 },
451 { 0xEB, 0x1F },
452 /* GOA MUX setting */
453 { 0xB0, 0x01 },
454 { 0xC0, 0x10 },
455 { 0xC1, 0x0F },
456 { 0xC2, 0x0E },
457 { 0xC3, 0x0D },
458 { 0xC4, 0x0C },
459 { 0xC5, 0x0B },
460 { 0xC6, 0x0A },
461 { 0xC7, 0x09 },
462 { 0xC8, 0x08 },
463 { 0xC9, 0x07 },
464 { 0xCA, 0x06 },
465 { 0xCB, 0x05 },
466 { 0xCC, 0x00 },
467 { 0xCD, 0x01 },
468 { 0xCE, 0x02 },
469 { 0xCF, 0x03 },
470 { 0xD0, 0x04 },
471 { 0xD6, 0x10 },
472 { 0xD7, 0x0F },
473 { 0xD8, 0x0E },
474 { 0xD9, 0x0D },
475 { 0xDA, 0x0C },
476 { 0xDB, 0x0B },
477 { 0xDC, 0x0A },
478 { 0xDD, 0x09 },
479 { 0xDE, 0x08 },
480 { 0xDF, 0x07 },
481 { 0xE0, 0x06 },
482 { 0xE1, 0x05 },
483 { 0xE2, 0x00 },
484 { 0xE3, 0x01 },
485 { 0xE4, 0x02 },
486 { 0xE5, 0x03 },
487 { 0xE6, 0x04 },
488 { 0xE7, 0x00 },
489 { 0xEC, 0xC0 },
490 /* GOA timing setting */
491 { 0xB0, 0x03 },
492 { 0xC0, 0x01 },
493 { 0xC2, 0x6F },
494 { 0xC3, 0x6F },
495 { 0xC5, 0x36 },
496 { 0xC8, 0x08 },
497 { 0xC9, 0x04 },
498 { 0xCA, 0x41 },
499 { 0xCC, 0x43 },
500 { 0xCF, 0x60 },
501 { 0xD2, 0x04 },
502 { 0xD3, 0x04 },
503 { 0xD4, 0x03 },
504 { 0xD5, 0x02 },
505 { 0xD6, 0x01 },
506 { 0xD7, 0x00 },
507 { 0xDB, 0x01 },
508 { 0xDE, 0x36 },
509 { 0xE6, 0x6F },
510 { 0xE7, 0x6F },
511 /* GOE setting */
512 { 0xB0, 0x06 },
513 { 0xB8, 0xA5 },
514 { 0xC0, 0xA5 },
515 { 0xD5, 0x3F },
516};
517
518const struct mipi_panel_data kd097d04_panel = {
519 .mipi_num = 2,
520 .format = MIPI_DSI_FMT_RGB888,
521 .lanes = 8,
522 .display_on_udelay = 120000,
523 .video_mode_udelay = 5000,
524 .init_cmd = kd097d04_init_commands,
525 .num_init_commands = ARRAY_SIZE(kd097d04_init_commands)
526};
527
528static const struct edid_mode kd097d04_edid_mode = {
529 .name = "1536x2048@60Hz",
530 .pixel_clock = 213000,
531 .refresh = 60,
532 .ha = 1536,
533 .hbl = 164,
534 .hso = 70,
535 .hspw = 24,
536 .va = 2048,
537 .vbl = 44,
538 .vso = 17,
539 .vspw = 2,
540};
541
542const struct mipi_panel_data *mainboard_get_mipi_mode
543 (struct edid_mode *edid_mode)
Lin Huang25fb09b2017-11-22 09:40:50 +0800544{
Lin Huangadd76662017-11-23 08:50:03 +0800545 memcpy(edid_mode, &kd097d04_edid_mode, sizeof(struct edid_mode));
546
547 return &kd097d04_panel;
Lin Huang25fb09b2017-11-22 09:40:50 +0800548}
549
huang lina6dbfb52016-03-02 18:38:40 +0800550static void mainboard_enable(device_t dev)
551{
552 dev->ops->init = &mainboard_init;
553}
554
555struct chip_operations mainboard_ops = {
556 .name = CONFIG_MAINBOARD_PART_NUMBER,
557 .enable_dev = mainboard_enable,
558};