2 * (C) Copyright 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <debug_uart.h>
18 #include <asm/arch/bootrom.h>
19 #include <asm/arch/clock.h>
20 #include <asm/arch/hardware.h>
21 #include <asm/arch/periph.h>
22 #include <asm/arch/pmu_rk3188.h>
23 #include <asm/arch/sdram.h>
24 #include <asm/arch/timer.h>
25 #include <dm/pinctrl.h>
29 #include <power/regulator.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 u32 spl_boot_device(void)
36 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
37 const void *blob = gd->fdt_blob;
43 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
44 debug("Boot device %s\n", bootdev);
48 node = fdt_path_offset(blob, bootdev);
50 debug("node=%d\n", node);
53 ret = device_get_global_by_of_offset(node, &dev);
55 debug("device at node %s/%d not found: %d\n", bootdev, node,
59 debug("Found device %s\n", dev->name);
60 switch (device_get_uclass_id(dev)) {
61 case UCLASS_SPI_FLASH:
62 return BOOT_DEVICE_SPI;
64 return BOOT_DEVICE_MMC1;
66 debug("Booting from device uclass '%s' not supported\n",
67 dev_get_uclass_name(dev));
72 return BOOT_DEVICE_MMC1;
75 u32 spl_boot_mode(const u32 boot_device)
77 return MMCSD_MODE_RAW;
80 static int setup_arm_clock(void)
86 ret = rockchip_get_clk(&dev);
91 ret = clk_request(dev, &clk);
95 ret = clk_set_rate(&clk, 600000000);
101 void board_init_f(ulong dummy)
103 struct udevice *pinctrl, *dev;
106 /* Example code showing how to enable the debug UART on RK3188 */
108 #include <asm/arch/grf_rk3188.h>
109 /* Enable early UART on the RK3188 */
110 #define GRF_BASE 0x20008000
111 struct rk3188_grf * const grf = (void *)GRF_BASE;
113 rk_clrsetreg(&grf->gpio1b_iomux,
114 GPIO1B1_MASK << GPIO1B1_SHIFT |
115 GPIO1B0_MASK << GPIO1B0_SHIFT,
116 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
117 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
119 * Debug UART can be used from here if required:
124 * printascii("string");
133 ret = spl_early_init();
135 debug("spl_early_init() failed: %d\n", ret);
139 rockchip_timer_init();
141 ret = rockchip_get_clk(&dev);
143 debug("CLK init failed: %d\n", ret);
147 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
149 debug("Pinctrl init failed: %d\n", ret);
153 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
155 debug("DRAM init failed: %d\n", ret);
160 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
161 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
165 static int setup_led(void)
167 #ifdef CONFIG_SPL_LED
172 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
175 ret = led_get_by_label(led_name, &dev);
177 debug("%s: get=%d\n", __func__, ret);
180 ret = led_set_on(dev, 1);
188 void spl_board_init(void)
190 struct udevice *pinctrl;
195 debug("LED ret=%d\n", ret);
199 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
201 debug("%s: Cannot find pinctrl device\n", __func__);
205 #ifdef CONFIG_SPL_MMC_SUPPORT
206 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
208 debug("%s: Failed to set up SD card\n", __func__);
213 /* Enable debug UART */
214 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
216 debug("%s: Failed to set up console UART\n", __func__);
220 preloader_console_init();
221 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
222 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
227 printf("spl_board_init: Error %d\n", ret);
229 /* No way to report error here */