blob: 0b55e7faf7838dd5046b9d8283efa38602982b52 [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
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -070017#include <boardid.h>
Lin Huangb497b482016-03-31 18:44:13 +080018#include <delay.h>
huang lina6dbfb52016-03-02 18:38:40 +080019#include <device/device.h>
Lin Huangb497b482016-03-31 18:44:13 +080020#include <device/i2c.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070021#include <gpio.h>
Lin Huang5a4be8a2016-05-17 15:45:53 +080022#include <soc/bl31_plat_params.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070023#include <soc/clock.h>
Lin Huangb497b482016-03-31 18:44:13 +080024#include <soc/display.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070025#include <soc/grf.h>
Lin Huangb497b482016-03-31 18:44:13 +080026#include <soc/i2c.h>
Liangfeng Wu76655cb2016-05-26 16:06:58 +080027#include <soc/usb.h>
Simon Glassbc679bc2016-06-19 16:09:21 -060028#include <vendorcode/google/chromeos/chromeos.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070029
Vadim Bendebury993dbe12016-05-22 15:53:37 -070030#include "board.h"
31
Brian Norrise06a1b82016-09-21 18:16:54 -070032/*
33 * Wifi's PDN/RST line is pulled down by its (unpowered) voltage rails, but
34 * this reset pin is pulled up by default. Let's drive it low as early as we
35 * can.
36 */
37static void deassert_wifi_power(void)
38{
39 gpio_output(GPIO(1, B, 3), 0); /* Assert WLAN_MODULE_RST# */
40}
41
Lin Huang2f7ed8d2016-04-08 18:56:20 +080042static void configure_emmc(void)
43{
44 /* Host controller does not support programmable clock generator.
45 * If we don't do this setting, when we use phy to control the
46 * emmc clock(when clock exceed 50MHz), it will get wrong clock.
47 *
48 * Refer to TRM V0.3 Part 1 Chapter 15 PAGE 782 for this register.
49 * Please search "_CON11[7:0]" to locate register description.
50 */
51 write32(&rk3399_grf->emmccore_con[11], RK_CLRSETBITS(0xff, 0));
52
53 rkclk_configure_emmc();
54}
55
Lin Huangc9fea5c2016-08-30 15:34:42 -070056static void register_apio_suspend(void)
57{
58 static struct bl31_apio_param param_apio = {
59 .h = {
60 .type = PARAM_SUSPEND_APIO,
61 },
62 .apio = {
63 .apio1 = 1,
64 .apio2 = 1,
65 .apio3 = 1,
66 .apio4 = 1,
67 .apio5 = 1,
68 },
69 };
70 register_bl31_param(&param_apio.h);
71}
72
Lin Huang7d8ccfb2016-08-22 17:35:40 -070073static void register_gpio_suspend(void)
74{
75 /*
76 * These three GPIO params are used to shut down the 1.5V, 1.8V and
77 * 3.3V power rails, which need to be shut down ordered by voltage,
78 * with highest voltage first.
79 * Since register_bl31() appends to the front of the list, we need to
80 * register them backwards, with 1.5V coming first.
81 */
82 static struct bl31_gpio_param param_p15_en = {
83 .h = {
84 .type = PARAM_SUSPEND_GPIO,
85 },
86 .gpio = {
87 .polarity = BL31_GPIO_LEVEL_LOW,
88 },
89 };
90 param_p15_en.gpio.index = GET_GPIO_NUM(GPIO_P15V_EN);
91 register_bl31_param(&param_p15_en.h);
92
93 static struct bl31_gpio_param param_p18_audio_en = {
94 .h = {
95 .type = PARAM_SUSPEND_GPIO,
96 },
97 .gpio = {
98 .polarity = BL31_GPIO_LEVEL_LOW,
99 },
100 };
101 param_p18_audio_en.gpio.index = GET_GPIO_NUM(GPIO_P18V_AUDIO_PWREN);
102 register_bl31_param(&param_p18_audio_en.h);
103
104 static struct bl31_gpio_param param_p30_en = {
105 .h = {
106 .type = PARAM_SUSPEND_GPIO,
107 },
108 .gpio = {
109 .polarity = BL31_GPIO_LEVEL_LOW,
110 },
111 };
112 param_p30_en.gpio.index = GET_GPIO_NUM(GPIO_P30V_EN);
113 register_bl31_param(&param_p30_en.h);
114}
115
Lin Huang5a4be8a2016-05-17 15:45:53 +0800116static void register_reset_to_bl31(void)
117{
118 static struct bl31_gpio_param param_reset = {
119 .h = {
120 .type = PARAM_RESET,
121 },
122 .gpio = {
123 .polarity = 1,
124 },
125 };
126
127 /* gru/kevin reset pin: gpio0b3 */
128 param_reset.gpio.index = GET_GPIO_NUM(GPIO_RESET),
129
130 register_bl31_param(&param_reset.h);
131}
132
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800133static void register_poweroff_to_bl31(void)
134{
135 static struct bl31_gpio_param param_poweroff = {
136 .h = {
137 .type = PARAM_POWEROFF,
138 },
139 .gpio = {
140 .polarity = 1,
141 },
142 };
143
144 /*
145 * gru/kevin power off pin: gpio1a6,
146 * reuse with tsadc int pin, so iomux need set back to
147 * gpio in BL31 and depthcharge before you setting this gpio
148 */
149 param_poweroff.gpio.index = GET_GPIO_NUM(GPIO_POWEROFF),
150
151 register_bl31_param(&param_poweroff.h);
152}
153
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700154static void configure_sdmmc(void)
155{
156 gpio_output(GPIO(4, D, 5), 1); /* SDMMC_PWR_EN */
157 gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */
Vadim Bendebury2832c412016-05-11 15:03:44 +0800158
159 /* SDMMC_DET_L is different on Kevin board revision 0. */
160 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_KEVIN) && (board_id() == 0))
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -0700161 gpio_input(GPIO(4, D, 2));
Vadim Bendebury2832c412016-05-11 15:03:44 +0800162 else
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -0700163 gpio_input(GPIO(4, D, 0));
Vadim Bendebury2832c412016-05-11 15:03:44 +0800164
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700165 gpio_output(GPIO(2, D, 4), 0); /* Keep the max voltage */
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -0700166
Julius Werner7feb86b2016-09-02 11:25:56 -0700167 gpio_input(GPIO(4, B, 0)); /* SDMMC0_D0 remove pull-up */
168 gpio_input(GPIO(4, B, 1)); /* SDMMC0_D1 remove pull-up */
169 gpio_input(GPIO(4, B, 2)); /* SDMMC0_D2 remove pull-up */
170 gpio_input(GPIO(4, B, 3)); /* SDMMC0_D3 remove pull-up */
171 gpio_input(GPIO(4, B, 4)); /* SDMMC0_CLK remove pull-down */
172 gpio_input(GPIO(4, B, 5)); /* SDMMC0_CMD remove pull-up */
173
Vadim Bendeburyad6ee022016-05-12 16:54:00 +0800174 write32(&rk3399_grf->gpio2_p[2][1], RK_CLRSETBITS(0xfff, 0));
175
176 /*
177 * Set all outputs' drive strength to 8 mA. Group 4 bank B driver
178 * strength requires three bits per pin. Value of 2 written in that
179 * three bit field means '8 mA', as deduced from the kernel code.
180 *
181 * Thus the six pins involved in SDMMC interface require 18 bits to
182 * configure drive strength, but each 32 bit register provides only 16
183 * bits for this setting, this covers 5 pins fully and one bit from
184 * the 6th pin. Two more bits spill over to the next register. This is
185 * described on page 378 of rk3399 TRM Version 0.3 Part 1.
186 */
187 write32(&rk3399_grf->gpio4b_e01,
188 RK_CLRSETBITS(0xffff,
189 (2 << 0) | (2 << 3) |
190 (2 << 6) | (2 << 9) | (2 << 12)));
191 write32(&rk3399_grf->gpio4b_e2, RK_CLRSETBITS(3, 1));
192
193 /* And now set the multiplexor to enable SDMMC0. */
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700194 write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC);
195}
huang lina6dbfb52016-03-02 18:38:40 +0800196
Xing Zheng96fbc312016-05-19 11:39:20 +0800197static void configure_codec(void)
198{
Julius Werner7feb86b2016-09-02 11:25:56 -0700199 gpio_input(GPIO(3, D, 0)); /* I2S0_SCLK remove pull-up */
200 gpio_input(GPIO(3, D, 1)); /* I2S0_RX remove pull-up */
201 gpio_input(GPIO(3, D, 2)); /* I2S0_TX remove pull-up */
202 gpio_input(GPIO(3, D, 3)); /* I2S0_SDI0 remove pull-up */
203 gpio_input(GPIO(3, D, 4)); /* I2S0_SDI1 remove pull-up */
204 /* GPIO3_D5 (I2S0_SDI2SDO2) not connected */
205 gpio_input(GPIO(3, D, 6)); /* I2S0_SDO1 remove pull-up */
206 gpio_input(GPIO(3, D, 7)); /* I2S0_SDO0 remove pull-up */
207 gpio_input(GPIO(4, A, 0)); /* I2S0_MCLK remove pull-up */
208
Xing Zheng96fbc312016-05-19 11:39:20 +0800209 write32(&rk3399_grf->iomux_i2s0, IOMUX_I2S0);
210 write32(&rk3399_grf->iomux_i2sclk, IOMUX_I2SCLK);
211
212 /* AUDIO IO domain 1.8V voltage selection */
213 write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 1));
214
215 /* CPU1_P1.8V_AUDIO_PWREN for P1.8_AUDIO */
216 gpio_output(GPIO(0, A, 2), 1);
217
218 /* set CPU1_SPK_PA_EN output */
219 gpio_output(GPIO(1, A, 2), 0);
220
221 rkclk_configure_i2s(12288000);
222}
223
Lin Huangb497b482016-03-31 18:44:13 +0800224static void configure_display(void)
225{
226 /* set pinmux for edp HPD*/
227 gpio_input_pulldown(GPIO(4, C, 7));
228 write32(&rk3399_grf->iomux_edp_hotplug, IOMUX_EDP_HOTPLUG);
229
230 gpio_output(GPIO(4, D, 3), 1); /* CPU3_EDP_VDDEN for P3.3V_DISP */
231}
232
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800233static void setup_usb(void)
234{
Julius Werner1c8491c2016-08-15 17:58:05 -0700235 /* A few magic PHY tuning values that improve eye diagram amplitude
236 * and make it extra sure we get reliable communication in firmware. */
237 /* Set max ODT compensation voltage and current tuning reference. */
238 write32(&rk3399_grf->usbphy0_ctrl[3], 0x0fff02e3);
239 write32(&rk3399_grf->usbphy1_ctrl[3], 0x0fff02e3);
240 /* Set max pre-emphasis level, only on Kevin PHY0. */
241 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_KEVIN))
242 write32(&rk3399_grf->usbphy0_ctrl[12], 0xffff00a7);
243
Julius Werner785ff1b2016-08-03 19:18:39 -0700244 setup_usb_otg0();
245 setup_usb_otg1();
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800246}
247
huang lina6dbfb52016-03-02 18:38:40 +0800248static void mainboard_init(device_t dev)
249{
Brian Norrise06a1b82016-09-21 18:16:54 -0700250 deassert_wifi_power();
Vadim Bendebury1e80ab32016-03-28 00:44:54 -0700251 configure_sdmmc();
Lin Huang2f7ed8d2016-04-08 18:56:20 +0800252 configure_emmc();
Xing Zheng96fbc312016-05-19 11:39:20 +0800253 configure_codec();
Lin Huangb497b482016-03-31 18:44:13 +0800254 configure_display();
Liangfeng Wu76655cb2016-05-26 16:06:58 +0800255 setup_usb();
Lin Huang5a4be8a2016-05-17 15:45:53 +0800256 register_reset_to_bl31();
Lin Huang9a5c4fe2016-05-19 11:11:23 +0800257 register_poweroff_to_bl31();
Lin Huang7d8ccfb2016-08-22 17:35:40 -0700258 register_gpio_suspend();
Lin Huangc9fea5c2016-08-30 15:34:42 -0700259 register_apio_suspend();
Lin Huangb497b482016-03-31 18:44:13 +0800260}
261
262static void enable_backlight_booster(void)
263{
264 const struct {
265 uint8_t reg;
266 uint8_t value;
267 } i2c_writes[] = {
268 {1, 0x84},
269 {1, 0x85},
270 {0, 0x26}
271 };
272 int i;
273 const int booster_i2c_port = 0;
274 uint8_t i2c_buf[2];
275 struct i2c_seg i2c_command = { .read = 0, .chip = 0x2c,
276 .buf = i2c_buf, .len = sizeof(i2c_buf)
277 };
278
279 /*
280 * This function is called on Gru right after BL_EN is asserted. It
281 * takes time for the switcher chip to come online, let's wait a bit
282 * to let the voltage settle, so that the chip can be accessed.
283 */
284 udelay(1000);
285
Julius Werner7feb86b2016-09-02 11:25:56 -0700286 gpio_input(GPIO(1, B, 7)); /* I2C0_SDA remove pull_up */
287 gpio_input(GPIO(1, C, 0)); /* I2C0_SCL remove pull_up */
288
289 i2c_init(0, 100*KHz);
290
Lin Huangb497b482016-03-31 18:44:13 +0800291 write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA);
292 write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL);
Lin Huangb497b482016-03-31 18:44:13 +0800293
294 for (i = 0; i < ARRAY_SIZE(i2c_writes); i++) {
295 i2c_buf[0] = i2c_writes[i].reg;
296 i2c_buf[1] = i2c_writes[i].value;
297 i2c_transfer(booster_i2c_port, &i2c_command, 1);
298 }
299}
300
301void mainboard_power_on_backlight(void)
302{
303 gpio_output(GPIO(1, C, 1), 1); /* BL_EN */
304
Julius Werner5e6771b2016-07-29 16:15:04 -0700305 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_GRU) && board_id() == 0)
Lin Huangb497b482016-03-31 18:44:13 +0800306 enable_backlight_booster();
huang lina6dbfb52016-03-02 18:38:40 +0800307}
308
309static void mainboard_enable(device_t dev)
310{
311 dev->ops->init = &mainboard_init;
312}
313
314struct chip_operations mainboard_ops = {
315 .name = CONFIG_MAINBOARD_PART_NUMBER,
316 .enable_dev = mainboard_enable,
317};