Heiko Stübner | df9041e | 2017-02-18 19:46:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2015 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <debug_uart.h> |
| 9 | #include <dm.h> |
| 10 | #include <fdtdec.h> |
| 11 | #include <led.h> |
| 12 | #include <malloc.h> |
| 13 | #include <ram.h> |
| 14 | #include <spl.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/bootrom.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/arch/hardware.h> |
| 20 | #include <asm/arch/periph.h> |
| 21 | #include <asm/arch/pmu_rk3188.h> |
| 22 | #include <asm/arch/sdram.h> |
| 23 | #include <asm/arch/timer.h> |
| 24 | #include <dm/pinctrl.h> |
| 25 | #include <dm/root.h> |
| 26 | #include <dm/test.h> |
| 27 | #include <dm/util.h> |
| 28 | #include <power/regulator.h> |
| 29 | #include <syscon.h> |
| 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | u32 spl_boot_device(void) |
| 34 | { |
| 35 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 36 | const void *blob = gd->fdt_blob; |
| 37 | struct udevice *dev; |
| 38 | const char *bootdev; |
| 39 | int node; |
| 40 | int ret; |
| 41 | |
| 42 | bootdev = fdtdec_get_config_string(blob, "u-boot,boot0"); |
| 43 | debug("Boot device %s\n", bootdev); |
| 44 | if (!bootdev) |
| 45 | goto fallback; |
| 46 | |
| 47 | node = fdt_path_offset(blob, bootdev); |
| 48 | if (node < 0) { |
| 49 | debug("node=%d\n", node); |
| 50 | goto fallback; |
| 51 | } |
| 52 | ret = device_get_global_by_of_offset(node, &dev); |
| 53 | if (ret) { |
| 54 | debug("device at node %s/%d not found: %d\n", bootdev, node, |
| 55 | ret); |
| 56 | goto fallback; |
| 57 | } |
| 58 | debug("Found device %s\n", dev->name); |
| 59 | switch (device_get_uclass_id(dev)) { |
| 60 | case UCLASS_SPI_FLASH: |
| 61 | return BOOT_DEVICE_SPI; |
| 62 | case UCLASS_MMC: |
| 63 | return BOOT_DEVICE_MMC1; |
| 64 | default: |
| 65 | debug("Booting from device uclass '%s' not supported\n", |
| 66 | dev_get_uclass_name(dev)); |
| 67 | } |
| 68 | |
| 69 | fallback: |
| 70 | #endif |
| 71 | return BOOT_DEVICE_MMC1; |
| 72 | } |
| 73 | |
| 74 | u32 spl_boot_mode(const u32 boot_device) |
| 75 | { |
| 76 | return MMCSD_MODE_RAW; |
| 77 | } |
| 78 | |
| 79 | void board_init_f(ulong dummy) |
| 80 | { |
| 81 | struct udevice *pinctrl, *dev; |
| 82 | struct rk3188_pmu *pmu; |
| 83 | int ret; |
| 84 | |
| 85 | /* Example code showing how to enable the debug UART on RK3188 */ |
| 86 | #ifdef EARLY_UART |
| 87 | #include <asm/arch/grf_rk3188.h> |
| 88 | /* Enable early UART on the RK3188 */ |
| 89 | #define GRF_BASE 0x20008000 |
| 90 | struct rk3188_grf * const grf = (void *)GRF_BASE; |
| 91 | |
| 92 | rk_clrsetreg(&grf->gpio1b_iomux, |
| 93 | GPIO1B1_MASK << GPIO1B1_SHIFT | |
| 94 | GPIO1B0_MASK << GPIO1B0_SHIFT, |
| 95 | GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | |
| 96 | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); |
| 97 | /* |
| 98 | * Debug UART can be used from here if required: |
| 99 | * |
| 100 | * debug_uart_init(); |
| 101 | * printch('a'); |
| 102 | * printhex8(0x1234); |
| 103 | * printascii("string"); |
| 104 | */ |
| 105 | debug_uart_init(); |
| 106 | printch('s'); |
| 107 | printch('p'); |
| 108 | printch('l'); |
| 109 | printch('\n'); |
| 110 | #endif |
| 111 | |
| 112 | ret = spl_init(); |
| 113 | if (ret) { |
| 114 | debug("spl_init() failed: %d\n", ret); |
| 115 | hang(); |
| 116 | } |
| 117 | |
| 118 | rockchip_timer_init(); |
| 119 | |
| 120 | ret = rockchip_get_clk(&dev); |
| 121 | if (ret) { |
| 122 | debug("CLK init failed: %d\n", ret); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Recover the bootrom's stackpointer. |
| 128 | * For whatever reason needs to run after rockchip_get_clk. |
| 129 | */ |
| 130 | pmu = syscon_get_first_range(ROCKCHIP_SYSCON_PMU); |
| 131 | if (IS_ERR(pmu)) |
| 132 | error("pmu syscon returned %ld\n", PTR_ERR(pmu)); |
| 133 | SAVE_SP_ADDR = readl(&pmu->sys_reg[2]); |
| 134 | |
| 135 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); |
| 136 | if (ret) { |
| 137 | debug("Pinctrl init failed: %d\n", ret); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 142 | if (ret) { |
| 143 | debug("DRAM init failed: %d\n", ret); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | #if defined(CONFIG_ROCKCHIP_SPL_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) |
| 148 | back_to_bootrom(); |
| 149 | #endif |
| 150 | } |
| 151 | |
| 152 | static int setup_led(void) |
| 153 | { |
| 154 | #ifdef CONFIG_SPL_LED |
| 155 | struct udevice *dev; |
| 156 | char *led_name; |
| 157 | int ret; |
| 158 | |
| 159 | led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); |
| 160 | if (!led_name) |
| 161 | return 0; |
| 162 | ret = led_get_by_label(led_name, &dev); |
| 163 | if (ret) { |
| 164 | debug("%s: get=%d\n", __func__, ret); |
| 165 | return ret; |
| 166 | } |
| 167 | ret = led_set_on(dev, 1); |
| 168 | if (ret) |
| 169 | return ret; |
| 170 | #endif |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | void spl_board_init(void) |
| 176 | { |
| 177 | struct udevice *pinctrl; |
| 178 | int ret; |
| 179 | |
| 180 | ret = setup_led(); |
| 181 | if (ret) { |
| 182 | debug("LED ret=%d\n", ret); |
| 183 | hang(); |
| 184 | } |
| 185 | |
| 186 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); |
| 187 | if (ret) { |
| 188 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 189 | goto err; |
| 190 | } |
| 191 | |
| 192 | #ifdef CONFIG_SPL_MMC_SUPPORT |
| 193 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD); |
| 194 | if (ret) { |
| 195 | debug("%s: Failed to set up SD card\n", __func__); |
| 196 | goto err; |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | /* Enable debug UART */ |
| 201 | ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG); |
| 202 | if (ret) { |
| 203 | debug("%s: Failed to set up console UART\n", __func__); |
| 204 | goto err; |
| 205 | } |
| 206 | |
| 207 | preloader_console_init(); |
| 208 | #ifdef CONFIG_ROCKCHIP_SPL_BACK_TO_BROM |
| 209 | back_to_bootrom(); |
| 210 | #endif |
| 211 | return; |
| 212 | |
| 213 | err: |
| 214 | printf("spl_board_init: Error %d\n", ret); |
| 215 | |
| 216 | /* No way to report error here */ |
| 217 | hang(); |
| 218 | } |