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 | |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 17 | #include <boardid.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 18 | #include <delay.h> |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 19 | #include <device/device.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 20 | #include <device/i2c.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 21 | #include <gpio.h> |
| 22 | #include <soc/clock.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 23 | #include <soc/display.h> |
Shunqian Zheng | 462e141 | 2016-05-02 10:27:30 +0800 | [diff] [blame] | 24 | #include <soc/emmc.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 25 | #include <soc/grf.h> |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 26 | #include <soc/i2c.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 27 | |
Vadim Bendebury | 993dbe1 | 2016-05-22 15:53:37 -0700 | [diff] [blame^] | 28 | #include "board.h" |
| 29 | |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 30 | static void configure_emmc(void) |
| 31 | { |
| 32 | /* Host controller does not support programmable clock generator. |
| 33 | * If we don't do this setting, when we use phy to control the |
| 34 | * emmc clock(when clock exceed 50MHz), it will get wrong clock. |
| 35 | * |
| 36 | * Refer to TRM V0.3 Part 1 Chapter 15 PAGE 782 for this register. |
| 37 | * Please search "_CON11[7:0]" to locate register description. |
| 38 | */ |
| 39 | write32(&rk3399_grf->emmccore_con[11], RK_CLRSETBITS(0xff, 0)); |
| 40 | |
| 41 | rkclk_configure_emmc(); |
Shunqian Zheng | 462e141 | 2016-05-02 10:27:30 +0800 | [diff] [blame] | 42 | |
| 43 | enable_emmc_clk(); |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 44 | } |
| 45 | |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 46 | static void configure_sdmmc(void) |
| 47 | { |
| 48 | gpio_output(GPIO(4, D, 5), 1); /* SDMMC_PWR_EN */ |
| 49 | gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */ |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 50 | |
| 51 | /* SDMMC_DET_L is different on Kevin board revision 0. */ |
| 52 | if (IS_ENABLED(CONFIG_BOARD_GOOGLE_KEVIN) && (board_id() == 0)) |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 53 | gpio_input(GPIO(4, D, 2)); |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 54 | else |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 55 | gpio_input(GPIO(4, D, 0)); |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 56 | |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 57 | gpio_output(GPIO(2, D, 4), 0); /* Keep the max voltage */ |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 58 | |
Vadim Bendebury | ad6ee02 | 2016-05-12 16:54:00 +0800 | [diff] [blame] | 59 | /* |
| 60 | * The SD card on this board is connected to port SDMMC0, which is |
| 61 | * multiplexed with GPIO4B pins 0..5. |
| 62 | * |
| 63 | * Disable all pullups on these pins. For pullup configuration |
| 64 | * register layout stacks banks 2 through 4 together, hence [2] means |
| 65 | * group 4, [1] means bank B. This register is described on page 342 |
| 66 | * of section 1 of the TRM. |
| 67 | * |
| 68 | * Each GPIO pin's pull config takes two bits, writing zero to the |
| 69 | * field disables pull ups/downs, as described on page 342 of rk3399 |
| 70 | * TRM Version 0.3 Part 1. |
| 71 | */ |
| 72 | write32(&rk3399_grf->gpio2_p[2][1], RK_CLRSETBITS(0xfff, 0)); |
| 73 | |
| 74 | /* |
| 75 | * Set all outputs' drive strength to 8 mA. Group 4 bank B driver |
| 76 | * strength requires three bits per pin. Value of 2 written in that |
| 77 | * three bit field means '8 mA', as deduced from the kernel code. |
| 78 | * |
| 79 | * Thus the six pins involved in SDMMC interface require 18 bits to |
| 80 | * configure drive strength, but each 32 bit register provides only 16 |
| 81 | * bits for this setting, this covers 5 pins fully and one bit from |
| 82 | * the 6th pin. Two more bits spill over to the next register. This is |
| 83 | * described on page 378 of rk3399 TRM Version 0.3 Part 1. |
| 84 | */ |
| 85 | write32(&rk3399_grf->gpio4b_e01, |
| 86 | RK_CLRSETBITS(0xffff, |
| 87 | (2 << 0) | (2 << 3) | |
| 88 | (2 << 6) | (2 << 9) | (2 << 12))); |
| 89 | write32(&rk3399_grf->gpio4b_e2, RK_CLRSETBITS(3, 1)); |
| 90 | |
| 91 | /* And now set the multiplexor to enable SDMMC0. */ |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 92 | write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC); |
| 93 | } |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 94 | |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 95 | static void configure_display(void) |
| 96 | { |
| 97 | /* set pinmux for edp HPD*/ |
| 98 | gpio_input_pulldown(GPIO(4, C, 7)); |
| 99 | write32(&rk3399_grf->iomux_edp_hotplug, IOMUX_EDP_HOTPLUG); |
| 100 | |
| 101 | gpio_output(GPIO(4, D, 3), 1); /* CPU3_EDP_VDDEN for P3.3V_DISP */ |
| 102 | } |
| 103 | |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 104 | static void mainboard_init(device_t dev) |
| 105 | { |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 106 | configure_sdmmc(); |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 107 | configure_emmc(); |
Lin Huang | b497b48 | 2016-03-31 18:44:13 +0800 | [diff] [blame] | 108 | configure_display(); |
| 109 | } |
| 110 | |
| 111 | static void enable_backlight_booster(void) |
| 112 | { |
| 113 | const struct { |
| 114 | uint8_t reg; |
| 115 | uint8_t value; |
| 116 | } i2c_writes[] = { |
| 117 | {1, 0x84}, |
| 118 | {1, 0x85}, |
| 119 | {0, 0x26} |
| 120 | }; |
| 121 | int i; |
| 122 | const int booster_i2c_port = 0; |
| 123 | uint8_t i2c_buf[2]; |
| 124 | struct i2c_seg i2c_command = { .read = 0, .chip = 0x2c, |
| 125 | .buf = i2c_buf, .len = sizeof(i2c_buf) |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * This function is called on Gru right after BL_EN is asserted. It |
| 130 | * takes time for the switcher chip to come online, let's wait a bit |
| 131 | * to let the voltage settle, so that the chip can be accessed. |
| 132 | */ |
| 133 | udelay(1000); |
| 134 | |
| 135 | /* Select pinmux for i2c0, which is the display backlight booster. */ |
| 136 | write32(&rk3399_pmugrf->iomux_i2c0_sda, IOMUX_I2C0_SDA); |
| 137 | write32(&rk3399_pmugrf->iomux_i2c0_scl, IOMUX_I2C0_SCL); |
| 138 | i2c_init(0, 100*KHz); |
| 139 | |
| 140 | for (i = 0; i < ARRAY_SIZE(i2c_writes); i++) { |
| 141 | i2c_buf[0] = i2c_writes[i].reg; |
| 142 | i2c_buf[1] = i2c_writes[i].value; |
| 143 | i2c_transfer(booster_i2c_port, &i2c_command, 1); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void mainboard_power_on_backlight(void) |
| 148 | { |
| 149 | gpio_output(GPIO(1, C, 1), 1); /* BL_EN */ |
| 150 | |
| 151 | if (IS_ENABLED(CONFIG_BOARD_GOOGLE_GRU)) |
| 152 | enable_backlight_booster(); |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static void mainboard_enable(device_t dev) |
| 156 | { |
| 157 | dev->ops->init = &mainboard_init; |
| 158 | } |
| 159 | |
| 160 | struct chip_operations mainboard_ops = { |
| 161 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 162 | .enable_dev = mainboard_enable, |
| 163 | }; |