Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 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 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/cache.h> |
| 21 | #include <arch/io.h> |
| 22 | #include <boot/coreboot_tables.h> |
| 23 | #include <console/console.h> |
| 24 | #include <delay.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/i2c.h> |
| 27 | #include <edid.h> |
| 28 | #include <gpio.h> |
| 29 | #include <soc/grf.h> |
| 30 | #include <soc/soc.h> |
| 31 | #include <soc/pmu.h> |
| 32 | #include <soc/clock.h> |
| 33 | #include <soc/rk808.h> |
| 34 | #include <soc/spi.h> |
| 35 | #include <soc/i2c.h> |
| 36 | #include <symbols.h> |
| 37 | #include <vbe.h> |
| 38 | |
| 39 | #include "board.h" |
| 40 | |
| 41 | static void configure_usb(void) |
| 42 | { |
| 43 | gpio_output(GPIO(0, B, 3), 1); /* HOST1_PWR_EN */ |
| 44 | gpio_output(GPIO(0, B, 4), 1); /* USBOTG_PWREN_H */ |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void configure_sdmmc(void) |
| 48 | { |
| 49 | writel(IOMUX_SDMMC0, &rk3288_grf->iomux_sdmmc0); |
| 50 | |
| 51 | /* use sdmmc0 io, disable JTAG function */ |
| 52 | writel(RK_CLRBITS(1 << 12), &rk3288_grf->soc_con0); |
| 53 | |
Julius Werner | 0353c9f | 2014-11-06 12:51:24 -0800 | [diff] [blame^] | 54 | rk808_configure_ldo(PMIC_BUS, 4, 3300); /* VCCIO_SD */ |
| 55 | rk808_configure_ldo(PMIC_BUS, 5, 3300); /* VCC33_SD */ |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 56 | |
| 57 | gpio_input(GPIO(7, A, 5)); /* SD_DET */ |
| 58 | } |
| 59 | |
| 60 | static void configure_emmc(void) |
| 61 | { |
| 62 | writel(IOMUX_EMMCDATA, &rk3288_grf->iomux_emmcdata); |
| 63 | writel(IOMUX_EMMCPWREN, &rk3288_grf->iomux_emmcpwren); |
| 64 | writel(IOMUX_EMMCCMD, &rk3288_grf->iomux_emmccmd); |
| 65 | |
Doug Anderson | f3d5736 | 2014-10-28 14:09:47 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Use a pullup instead of a drive since the output is 3.3V and |
| 68 | * really should be 1.8V (oops). The external pulldown will help |
| 69 | * bring the voltage down if we only drive with a pullup here. |
| 70 | */ |
| 71 | gpio_input_pullup(GPIO(7, B, 4)); /* EMMC_RST_L */ |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static void configure_codec(void) |
| 75 | { |
| 76 | writel(IOMUX_I2C2, &rk3288_grf->iomux_i2c2); /* CODEC I2C */ |
| 77 | i2c_init(2, 400000); /* CODEC I2C */ |
| 78 | |
| 79 | writel(IOMUX_I2S, &rk3288_grf->iomux_i2s); |
| 80 | writel(IOMUX_I2SCLK, &rk3288_grf->iomux_i2sclk); |
| 81 | |
Julius Werner | 0353c9f | 2014-11-06 12:51:24 -0800 | [diff] [blame^] | 82 | rk808_configure_ldo(PMIC_BUS, 6, 1800); /* VCC18_CODEC */ |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 83 | |
| 84 | /* AUDIO IO domain 1.8V voltage selection */ |
| 85 | writel(RK_SETBITS(1 << 6), &rk3288_grf->io_vsel); |
| 86 | rkclk_configure_i2s(12288000); |
| 87 | } |
| 88 | |
| 89 | static void configure_lcd(void) |
| 90 | { |
| 91 | writel(IOMUX_LCDC, &rk3288_grf->iomux_lcdc); |
| 92 | |
Julius Werner | 0353c9f | 2014-11-06 12:51:24 -0800 | [diff] [blame^] | 93 | rk808_configure_switch(PMIC_BUS, 2, 1); /* VCC18_LCD */ |
| 94 | rk808_configure_ldo(PMIC_BUS, 7, 3300); /* VCC10_LCD_PWREN_H */ |
| 95 | rk808_configure_switch(PMIC_BUS, 1, 1); /* VCC33_LCD */ |
Katie Roberts-Hoffman | b262c72 | 2014-10-23 19:14:30 -0700 | [diff] [blame] | 96 | |
| 97 | gpio_output(GPIO(7, A, 0), 0); /* LCDC_BL */ |
| 98 | gpio_output(GPIO(7, A, 2), 1); /* BL_EN */ |
| 99 | } |
| 100 | |
| 101 | static void mainboard_init(device_t dev) |
| 102 | { |
| 103 | setbits_le32(&rk3288_pmu->iomux_i2c0scl, IOMUX_I2C0SCL); /* PMIC I2C */ |
| 104 | setbits_le32(&rk3288_pmu->iomux_i2c0sda, IOMUX_I2C0SDA); /* PMIC I2C */ |
| 105 | i2c_init(0, 400000); /* PMIC I2C */ |
| 106 | |
| 107 | gpio_output(GPIO_RESET, 0); |
| 108 | |
| 109 | configure_usb(); |
| 110 | configure_sdmmc(); |
| 111 | configure_emmc(); |
| 112 | configure_codec(); |
| 113 | configure_lcd(); |
| 114 | } |
| 115 | |
| 116 | static void mainboard_enable(device_t dev) |
| 117 | { |
| 118 | dev->ops->init = &mainboard_init; |
| 119 | } |
| 120 | |
| 121 | struct chip_operations mainboard_ops = { |
| 122 | .enable_dev = mainboard_enable, |
| 123 | }; |
| 124 | |
| 125 | void lb_board(struct lb_header *header) |
| 126 | { |
| 127 | struct lb_range *dma; |
| 128 | |
| 129 | dma = (struct lb_range *)lb_new_record(header); |
| 130 | dma->tag = LB_TAB_DMA; |
| 131 | dma->size = sizeof(*dma); |
| 132 | dma->range_start = (uintptr_t)_dma_coherent; |
| 133 | dma->range_size = _dma_coherent_size; |
| 134 | } |