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> |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 18 | #include <device/device.h> |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 19 | #include <gpio.h> |
| 20 | #include <soc/clock.h> |
| 21 | #include <soc/grf.h> |
| 22 | |
| 23 | static void configure_sdmmc(void) |
| 24 | { |
| 25 | gpio_output(GPIO(4, D, 5), 1); /* SDMMC_PWR_EN */ |
| 26 | gpio_output(GPIO(2, A, 2), 1); /* SDMMC_SDIO_PWR_EN */ |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 27 | |
| 28 | /* SDMMC_DET_L is different on Kevin board revision 0. */ |
| 29 | if (IS_ENABLED(CONFIG_BOARD_GOOGLE_KEVIN) && (board_id() == 0)) |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 30 | gpio_input(GPIO(4, D, 2)); |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 31 | else |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 32 | gpio_input(GPIO(4, D, 0)); |
Vadim Bendebury | 2832c41 | 2016-05-11 15:03:44 +0800 | [diff] [blame] | 33 | |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 34 | gpio_output(GPIO(2, D, 4), 0); /* Keep the max voltage */ |
Vadim Bendebury | 8e8a00c | 2016-04-22 12:25:07 -0700 | [diff] [blame] | 35 | |
Vadim Bendebury | ad6ee02 | 2016-05-12 16:54:00 +0800 | [diff] [blame^] | 36 | /* |
| 37 | * The SD card on this board is connected to port SDMMC0, which is |
| 38 | * multiplexed with GPIO4B pins 0..5. |
| 39 | * |
| 40 | * Disable all pullups on these pins. For pullup configuration |
| 41 | * register layout stacks banks 2 through 4 together, hence [2] means |
| 42 | * group 4, [1] means bank B. This register is described on page 342 |
| 43 | * of section 1 of the TRM. |
| 44 | * |
| 45 | * Each GPIO pin's pull config takes two bits, writing zero to the |
| 46 | * field disables pull ups/downs, as described on page 342 of rk3399 |
| 47 | * TRM Version 0.3 Part 1. |
| 48 | */ |
| 49 | write32(&rk3399_grf->gpio2_p[2][1], RK_CLRSETBITS(0xfff, 0)); |
| 50 | |
| 51 | /* |
| 52 | * Set all outputs' drive strength to 8 mA. Group 4 bank B driver |
| 53 | * strength requires three bits per pin. Value of 2 written in that |
| 54 | * three bit field means '8 mA', as deduced from the kernel code. |
| 55 | * |
| 56 | * Thus the six pins involved in SDMMC interface require 18 bits to |
| 57 | * configure drive strength, but each 32 bit register provides only 16 |
| 58 | * bits for this setting, this covers 5 pins fully and one bit from |
| 59 | * the 6th pin. Two more bits spill over to the next register. This is |
| 60 | * described on page 378 of rk3399 TRM Version 0.3 Part 1. |
| 61 | */ |
| 62 | write32(&rk3399_grf->gpio4b_e01, |
| 63 | RK_CLRSETBITS(0xffff, |
| 64 | (2 << 0) | (2 << 3) | |
| 65 | (2 << 6) | (2 << 9) | (2 << 12))); |
| 66 | write32(&rk3399_grf->gpio4b_e2, RK_CLRSETBITS(3, 1)); |
| 67 | |
| 68 | /* And now set the multiplexor to enable SDMMC0. */ |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 69 | write32(&rk3399_grf->iomux_sdmmc, IOMUX_SDMMC); |
| 70 | } |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 71 | |
| 72 | static void mainboard_init(device_t dev) |
| 73 | { |
Vadim Bendebury | 1e80ab3 | 2016-03-28 00:44:54 -0700 | [diff] [blame] | 74 | configure_sdmmc(); |
huang lin | a6dbfb5 | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void mainboard_enable(device_t dev) |
| 78 | { |
| 79 | dev->ops->init = &mainboard_init; |
| 80 | } |
| 81 | |
| 82 | struct chip_operations mainboard_ops = { |
| 83 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 84 | .enable_dev = mainboard_enable, |
| 85 | }; |