huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 17 | #include <assert.h> |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 18 | #include <boardid.h> |
Julius Werner | c49782c | 2016-11-21 20:14:18 -0800 | [diff] [blame] | 19 | #include <console/console.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 20 | #include <delay.h> |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 21 | #include <device/device.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 22 | #include <device/i2c_simple.h> |
Julius Werner | c49782c | 2016-11-21 20:14:18 -0800 | [diff] [blame] | 23 | #include <ec/google/chromeec/ec.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 24 | #include <gpio.h> |
Lin Huang | 5a4be8a | 2016-05-17 15:45:53 +0800 | [diff] [blame] | 25 | #include <soc/bl31_plat_params.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 26 | #include <soc/clock.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 27 | #include <soc/display.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 28 | #include <soc/grf.h> |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 29 | #include <soc/mipi.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 30 | #include <soc/i2c.h> |
Liangfeng Wu | 76655cb | 2016-05-26 16:06:58 +0800 | [diff] [blame] | 31 | #include <soc/usb.h> |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 32 | #include <string.h> |
Simon Glass | bc679bc | 2016-06-19 16:09:21 -0600 | [diff] [blame] | 33 | #include <vendorcode/google/chromeos/chromeos.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 34 | |
Vadim Bendebury | 993dbe1 | 2016-05-22 15:53:37 -0700 | [diff] [blame] | 35 | #include "board.h" |
| 36 | |
Brian Norris | e06a1b8 | 2016-09-21 18:16:54 -0700 | [diff] [blame] | 37 | /* |
Caesar Wang | 212a026 | 2017-05-24 18:02:25 +0800 | [diff] [blame] | 38 | * We have to drive the stronger pull-up within 1 second of powering up the |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 39 | * touchpad to prevent its firmware from falling into recovery. Not on |
| 40 | * Scarlet-based boards. |
Caesar Wang | 212a026 | 2017-05-24 18:02:25 +0800 | [diff] [blame] | 41 | */ |
| 42 | static void configure_touchpad(void) |
| 43 | { |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 44 | gpio_output(GPIO_TP_RST_L, 1); /* TP's I2C pull-up rail */ |
Caesar Wang | 212a026 | 2017-05-24 18:02:25 +0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /* |
Brian Norris | e06a1b8 | 2016-09-21 18:16:54 -0700 | [diff] [blame] | 48 | * 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 Chen | a061820 | 2017-08-23 18:02:25 -0700 | [diff] [blame] | 50 | * can. This only applies to boards with Marvell 8997 WiFi. |
Brian Norris | e06a1b8 | 2016-09-21 18:16:54 -0700 | [diff] [blame] | 51 | */ |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 52 | static void assert_wifi_reset(void) |
Brian Norris | e06a1b8 | 2016-09-21 18:16:54 -0700 | [diff] [blame] | 53 | { |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 54 | gpio_output(GPIO_WLAN_RST_L, 0); /* Assert WLAN_MODULE_RST# */ |
Brian Norris | e06a1b8 | 2016-09-21 18:16:54 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 57 | static 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 Huang | c9fea5c | 2016-08-30 15:34:42 -0700 | [diff] [blame] | 71 | static 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(¶m_apio.h); |
| 86 | } |
| 87 | |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 88 | static 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 Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 96 | * 1.5V and 1.8V are EC-controlled on Scarlet derivatives, |
| 97 | * so we skip them. |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 98 | */ |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 99 | if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) { |
Julius Werner | 2be6404 | 2017-09-01 14:27:46 -0700 | [diff] [blame] | 100 | 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(¶m_p15_en.h); |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 106 | |
Julius Werner | 2be6404 | 2017-09-01 14:27:46 -0700 | [diff] [blame] | 107 | 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(¶m_p18_audio_en.h); |
| 113 | } |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 114 | |
| 115 | static struct bl31_gpio_param param_p30_en = { |
Julius Werner | 2be6404 | 2017-09-01 14:27:46 -0700 | [diff] [blame] | 116 | .h = { .type = PARAM_SUSPEND_GPIO }, |
| 117 | .gpio = { .polarity = BL31_GPIO_LEVEL_LOW }, |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 118 | }; |
Julius Werner | 4ed8b30 | 2017-07-14 14:25:39 -0700 | [diff] [blame] | 119 | param_p30_en.gpio.index = GPIO_P30V_EN.raw; |
Lin Huang | 7d8ccfb | 2016-08-22 17:35:40 -0700 | [diff] [blame] | 120 | register_bl31_param(¶m_p30_en.h); |
| 121 | } |
| 122 | |
Lin Huang | 5a4be8a | 2016-05-17 15:45:53 +0800 | [diff] [blame] | 123 | static 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 Werner | 4ed8b30 | 2017-07-14 14:25:39 -0700 | [diff] [blame] | 135 | param_reset.gpio.index = GPIO_RESET.raw, |
Lin Huang | 5a4be8a | 2016-05-17 15:45:53 +0800 | [diff] [blame] | 136 | |
| 137 | register_bl31_param(¶m_reset.h); |
| 138 | } |
| 139 | |
Lin Huang | 9a5c4fe | 2016-05-19 11:11:23 +0800 | [diff] [blame] | 140 | static 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 Werner | 4ed8b30 | 2017-07-14 14:25:39 -0700 | [diff] [blame] | 156 | param_poweroff.gpio.index = GPIO_POWEROFF.raw, |
Lin Huang | 9a5c4fe | 2016-05-19 11:11:23 +0800 | [diff] [blame] | 157 | |
| 158 | register_bl31_param(¶m_poweroff.h); |
| 159 | } |
| 160 | |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 161 | static void configure_sdmmc(void) |
| 162 | { |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 163 | gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */ |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 164 | |
Lin Huang | a2c5b2f | 2017-07-25 09:50:10 +0800 | [diff] [blame] | 165 | /* set SDMMC_DET_L pin */ |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 166 | if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) |
Lin Huang | a2c5b2f | 2017-07-25 09:50:10 +0800 | [diff] [blame] | 167 | /* |
| 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 Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 172 | else |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 173 | gpio_input(GPIO(4, D, 0)); |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 174 | |
Lin Huang | a2c5b2f | 2017-07-25 09:50:10 +0800 | [diff] [blame] | 175 | /* |
| 176 | * Keep sd card io domain 3v |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 177 | * In Scarlet derivatives, this GPIO set to high will get 3v, |
Lin Huang | a2c5b2f | 2017-07-25 09:50:10 +0800 | [diff] [blame] | 178 | * With other board variants setting this GPIO low results in 3V. |
| 179 | */ |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 180 | if (IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) |
Lin Huang | a2c5b2f | 2017-07-25 09:50:10 +0800 | [diff] [blame] | 181 | gpio_output(GPIO(2, D, 4), 1); |
| 182 | else |
| 183 | gpio_output(GPIO(2, D, 4), 0); |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 184 | |
Julius Werner | 7feb86b | 2016-09-02 11:25:56 -0700 | [diff] [blame] | 185 | 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 Bendebury | ad6ee02 | 2016-05-12 16:54:00 +0800 | [diff] [blame] | 192 | 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 Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 212 | write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC); |
| 213 | } |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 214 | |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 215 | static void configure_codec(void) |
| 216 | { |
Julius Werner | 7feb86b | 2016-09-02 11:25:56 -0700 | [diff] [blame] | 217 | 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 Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 227 | 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 Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 233 | if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) |
Julius Werner | 1ab8c01 | 2017-11-03 15:23:09 -0700 | [diff] [blame] | 234 | gpio_output(GPIO_P18V_AUDIO_PWREN, 1); |
| 235 | gpio_output(GPIO_SPK_PA_EN, 0); |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 236 | |
| 237 | rkclk_configure_i2s(12288000); |
| 238 | } |
| 239 | |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 240 | static void configure_display(void) |
| 241 | { |
Ege Mihmanli | beb0468 | 2017-11-20 11:54:02 -0800 | [diff] [blame] | 242 | /* |
| 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 Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 247 | 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 Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 258 | |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 259 | gpio_output(GPIO(4, D, 3), 1); /* P3.3V_DISP */ |
| 260 | } |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 261 | } |
| 262 | |
Julius Werner | c49782c | 2016-11-21 20:14:18 -0800 | [diff] [blame] | 263 | static 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 | |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 274 | static void setup_usb(int port) |
Liangfeng Wu | 76655cb | 2016-05-26 16:06:58 +0800 | [diff] [blame] | 275 | { |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 276 | /* Must be PHY0 or PHY1. */ |
| 277 | assert(port == 0 || port == 1); |
| 278 | |
William wu | 605a87c | 2017-01-09 19:02:39 +0800 | [diff] [blame] | 279 | /* |
| 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 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 284 | write32(&rk3399_grf->usbphy_ctrl[port][3], RK_CLRSETBITS(0xfff, 0x2e3)); |
William wu | 9f470b1 | 2016-11-10 19:34:45 +0800 | [diff] [blame] | 285 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 286 | /* Set max pre-emphasis level on PHY0 and PHY1. */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 287 | write32(&rk3399_grf->usbphy_ctrl[port][12], |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 288 | RK_CLRSETBITS(0xffff, 0xa7)); |
William wu | 9f470b1 | 2016-11-10 19:34:45 +0800 | [diff] [blame] | 289 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 290 | /* |
William wu | ebbdd28 | 2017-01-23 20:54:22 +0800 | [diff] [blame] | 291 | * 1. Disable the pre-emphasize in eop state and chirp |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 292 | * 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 wu | ebbdd28 | 2017-01-23 20:54:22 +0800 | [diff] [blame] | 295 | * |
| 296 | * 2. Configure PHY0 and PHY1 otg-ports squelch detection |
| 297 | * threshold to 125mV (default is 150mV). |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 298 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 299 | write32(&rk3399_grf->usbphy_ctrl[port][0], |
William wu | ebbdd28 | 2017-01-23 20:54:22 +0800 | [diff] [blame] | 300 | RK_CLRSETBITS(7 << 13 | 3 << 0, 6 << 13)); |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 301 | write32(&rk3399_grf->usbphy_ctrl[port][13], RK_CLRBITS(3 << 0)); |
William wu | 9f470b1 | 2016-11-10 19:34:45 +0800 | [diff] [blame] | 302 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 303 | /* |
| 304 | * ODT auto compensation bypass, and set max driver |
| 305 | * strength only for PHY0 and PHY1 otg-port. |
| 306 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 307 | write32(&rk3399_grf->usbphy_ctrl[port][2], |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 308 | RK_CLRSETBITS(0x7e << 4, 0x60 << 4)); |
William wu | 9f470b1 | 2016-11-10 19:34:45 +0800 | [diff] [blame] | 309 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 310 | /* |
| 311 | * ODT auto refresh bypass, and set the max bias current |
| 312 | * tuning reference only for PHY0 and PHY1 otg-port. |
| 313 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 314 | write32(&rk3399_grf->usbphy_ctrl[port][3], |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 315 | RK_CLRSETBITS(0x21c, 1 << 4)); |
William wu | 605a87c | 2017-01-09 19:02:39 +0800 | [diff] [blame] | 316 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 317 | /* |
| 318 | * ODT auto compensation bypass, and set default driver |
| 319 | * strength only for PHY0 and PHY1 host-port. |
| 320 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 321 | write32(&rk3399_grf->usbphy_ctrl[port][15], RK_SETBITS(1 << 10)); |
William wu | 605a87c | 2017-01-09 19:02:39 +0800 | [diff] [blame] | 322 | |
Caesar Wang | 9e58800 | 2017-02-10 11:16:13 +0800 | [diff] [blame] | 323 | /* ODT auto refresh bypass only for PHY0 and PHY1 host-port. */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 324 | write32(&rk3399_grf->usbphy_ctrl[port][16], RK_CLRBITS(1 << 9)); |
Julius Werner | 1c8491c | 2016-08-15 17:58:05 -0700 | [diff] [blame] | 325 | |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 326 | if (port == 0) |
| 327 | setup_usb_otg0(); |
| 328 | else |
| 329 | setup_usb_otg1(); |
Julius Werner | c49782c | 2016-11-21 20:14:18 -0800 | [diff] [blame] | 330 | |
| 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 | */ |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 337 | if (display_init_required()) |
| 338 | usb_power_cycle(port); |
Liangfeng Wu | 76655cb | 2016-05-26 16:06:58 +0800 | [diff] [blame] | 339 | } |
| 340 | |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 341 | static void mainboard_init(device_t dev) |
| 342 | { |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 343 | configure_sdmmc(); |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 344 | configure_emmc(); |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 345 | configure_codec(); |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 346 | if (display_init_required()) |
| 347 | configure_display(); |
philipchen | 21b0852 | 2017-04-27 18:25:11 -0700 | [diff] [blame] | 348 | setup_usb(0); |
Philip Chen | a061820 | 2017-08-23 18:02:25 -0700 | [diff] [blame] | 349 | if (IS_ENABLED(CONFIG_GRU_HAS_WLAN_RESET)) |
| 350 | assert_wifi_reset(); |
Ege Mihmanli | 75b1543 | 2017-11-15 17:19:58 -0800 | [diff] [blame] | 351 | if (!IS_ENABLED(CONFIG_GRU_BASEBOARD_SCARLET)) { |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 352 | configure_touchpad(); /* Scarlet: works differently */ |
| 353 | setup_usb(1); /* Scarlet: only one USB port */ |
Julius Werner | 6486e78 | 2017-07-14 14:30:29 -0700 | [diff] [blame] | 354 | } |
Julius Werner | 2be6404 | 2017-09-01 14:27:46 -0700 | [diff] [blame] | 355 | register_gpio_suspend(); |
Lin Huang | 5a4be8a | 2016-05-17 15:45:53 +0800 | [diff] [blame] | 356 | register_reset_to_bl31(); |
Lin Huang | 9a5c4fe | 2016-05-19 11:11:23 +0800 | [diff] [blame] | 357 | register_poweroff_to_bl31(); |
Lin Huang | c9fea5c | 2016-08-30 15:34:42 -0700 | [diff] [blame] | 358 | register_apio_suspend(); |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 359 | } |
| 360 | |
Philip Chen | a304b69 | 2017-04-06 10:17:08 -0700 | [diff] [blame] | 361 | static void prepare_backlight_i2c(void) |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 362 | { |
Julius Werner | 7feb86b | 2016-09-02 11:25:56 -0700 | [diff] [blame] | 363 | 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 Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 368 | write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA); |
| 369 | write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL); |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void mainboard_power_on_backlight(void) |
| 373 | { |
Lin Huang | 18617bf | 2017-11-20 14:57:22 +0800 | [diff] [blame] | 374 | 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 Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 379 | |
Philip Chen | a304b69 | 2017-04-06 10:17:08 -0700 | [diff] [blame] | 380 | if (IS_ENABLED(CONFIG_BOARD_GOOGLE_GRU)) |
| 381 | prepare_backlight_i2c(); |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 382 | } |
| 383 | |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 384 | static 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 | |
| 518 | const 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 | |
| 528 | static const struct edid_mode kd097d04_edid_mode = { |
| 529 | .name = "1536x2048@60Hz", |
Lin Huang | ab21ab9 | 2017-12-06 10:18:10 +0800 | [diff] [blame^] | 530 | .pixel_clock = 216000, |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 531 | .refresh = 60, |
| 532 | .ha = 1536, |
Lin Huang | ab21ab9 | 2017-12-06 10:18:10 +0800 | [diff] [blame^] | 533 | .hbl = 186, |
| 534 | .hso = 81, |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 535 | .hspw = 24, |
| 536 | .va = 2048, |
Lin Huang | ab21ab9 | 2017-12-06 10:18:10 +0800 | [diff] [blame^] | 537 | .vbl = 42, |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 538 | .vso = 17, |
| 539 | .vspw = 2, |
| 540 | }; |
| 541 | |
| 542 | const struct mipi_panel_data *mainboard_get_mipi_mode |
| 543 | (struct edid_mode *edid_mode) |
Lin Huang | 25fb09b | 2017-11-22 09:40:50 +0800 | [diff] [blame] | 544 | { |
Lin Huang | add7666 | 2017-11-23 08:50:03 +0800 | [diff] [blame] | 545 | memcpy(edid_mode, &kd097d04_edid_mode, sizeof(struct edid_mode)); |
| 546 | |
| 547 | return &kd097d04_panel; |
Lin Huang | 25fb09b | 2017-11-22 09:40:50 +0800 | [diff] [blame] | 548 | } |
| 549 | |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 550 | static void mainboard_enable(device_t dev) |
| 551 | { |
| 552 | dev->ops->init = &mainboard_init; |
| 553 | } |
| 554 | |
| 555 | struct chip_operations mainboard_ops = { |
| 556 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 557 | .enable_dev = mainboard_enable, |
| 558 | }; |