blob: 6d2b4f4759d2ef5da3280ca5a12b2e7e0515c610 [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>
huang lina6dbfb52016-03-02 18:38:40 +080018#include <device/device.h>
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070019#include <gpio.h>
20#include <soc/clock.h>
21#include <soc/grf.h>
22
Lin Huang2f7ed8d2016-04-08 18:56:20 +080023static void configure_emmc(void)
24{
25 /* Host controller does not support programmable clock generator.
26 * If we don't do this setting, when we use phy to control the
27 * emmc clock(when clock exceed 50MHz), it will get wrong clock.
28 *
29 * Refer to TRM V0.3 Part 1 Chapter 15 PAGE 782 for this register.
30 * Please search "_CON11[7:0]" to locate register description.
31 */
32 write32(&rk3399_grf->emmccore_con[11], RK_CLRSETBITS(0xff, 0));
33
34 rkclk_configure_emmc();
35}
36
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070037static void configure_sdmmc(void)
38{
39 gpio_output(GPIO(4, D, 5), 1); /* SDMMC_PWR_EN */
40 gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */
Vadim Bendebury2832c412016-05-11 15:03:44 +080041
42 /* SDMMC_DET_L is different on Kevin board revision 0. */
43 if (IS_ENABLED(CONFIG_BOARD_GOOGLE_KEVIN) && (board_id() == 0))
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -070044 gpio_input(GPIO(4, D, 2));
Vadim Bendebury2832c412016-05-11 15:03:44 +080045 else
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -070046 gpio_input(GPIO(4, D, 0));
Vadim Bendebury2832c412016-05-11 15:03:44 +080047
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070048 gpio_output(GPIO(2, D, 4), 0); /* Keep the max voltage */
Vadim Bendebury8e8a00c2016-04-22 12:25:07 -070049
Vadim Bendeburyad6ee022016-05-12 16:54:00 +080050 /*
51 * The SD card on this board is connected to port SDMMC0, which is
52 * multiplexed with GPIO4B pins 0..5.
53 *
54 * Disable all pullups on these pins. For pullup configuration
55 * register layout stacks banks 2 through 4 together, hence [2] means
56 * group 4, [1] means bank B. This register is described on page 342
57 * of section 1 of the TRM.
58 *
59 * Each GPIO pin's pull config takes two bits, writing zero to the
60 * field disables pull ups/downs, as described on page 342 of rk3399
61 * TRM Version 0.3 Part 1.
62 */
63 write32(&rk3399_grf->gpio2_p[2][1], RK_CLRSETBITS(0xfff, 0));
64
65 /*
66 * Set all outputs' drive strength to 8 mA. Group 4 bank B driver
67 * strength requires three bits per pin. Value of 2 written in that
68 * three bit field means '8 mA', as deduced from the kernel code.
69 *
70 * Thus the six pins involved in SDMMC interface require 18 bits to
71 * configure drive strength, but each 32 bit register provides only 16
72 * bits for this setting, this covers 5 pins fully and one bit from
73 * the 6th pin. Two more bits spill over to the next register. This is
74 * described on page 378 of rk3399 TRM Version 0.3 Part 1.
75 */
76 write32(&rk3399_grf->gpio4b_e01,
77 RK_CLRSETBITS(0xffff,
78 (2 << 0) | (2 << 3) |
79 (2 << 6) | (2 << 9) | (2 << 12)));
80 write32(&rk3399_grf->gpio4b_e2, RK_CLRSETBITS(3, 1));
81
82 /* And now set the multiplexor to enable SDMMC0. */
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070083 write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC);
84}
huang lina6dbfb52016-03-02 18:38:40 +080085
86static void mainboard_init(device_t dev)
87{
Vadim Bendebury1e80ab32016-03-28 00:44:54 -070088 configure_sdmmc();
Lin Huang2f7ed8d2016-04-08 18:56:20 +080089 configure_emmc();
huang lina6dbfb52016-03-02 18:38:40 +080090}
91
92static void mainboard_enable(device_t dev)
93{
94 dev->ops->init = &mainboard_init;
95}
96
97struct chip_operations mainboard_ops = {
98 .name = CONFIG_MAINBOARD_PART_NUMBER,
99 .enable_dev = mainboard_enable,
100};