1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
8 #include <debug_uart.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>
28 #include <power/regulator.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 u32 spl_boot_device(void)
35 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
36 const void *blob = gd->fdt_blob;
42 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
43 debug("Boot device %s\n", bootdev);
47 node = fdt_path_offset(blob, bootdev);
49 debug("node=%d\n", node);
52 ret = device_get_global_by_of_offset(node, &dev);
54 debug("device at node %s/%d not found: %d\n", bootdev, node,
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;
63 return BOOT_DEVICE_MMC1;
65 debug("Booting from device uclass '%s' not supported\n",
66 dev_get_uclass_name(dev));
71 return BOOT_DEVICE_MMC1;
74 static int setup_arm_clock(void)
80 ret = rockchip_get_clk(&dev);
85 ret = clk_request(dev, &clk);
89 ret = clk_set_rate(&clk, 600000000);
95 void board_init_f(ulong dummy)
97 struct udevice *pinctrl, *dev;
100 /* Example code showing how to enable the debug UART on RK3188 */
102 #include <asm/arch/grf_rk3188.h>
103 /* Enable early UART on the RK3188 */
104 #define GRF_BASE 0x20008000
105 struct rk3188_grf * const grf = (void *)GRF_BASE;
107 rk_clrsetreg(&grf->gpio1b_iomux,
108 GPIO1B1_MASK << GPIO1B1_SHIFT |
109 GPIO1B0_MASK << GPIO1B0_SHIFT,
110 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
111 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
113 * Debug UART can be used from here if required:
118 * printascii("string");
127 ret = spl_early_init();
129 debug("spl_early_init() failed: %d\n", ret);
133 ret = rockchip_get_clk(&dev);
135 debug("CLK init failed: %d\n", ret);
139 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
141 debug("Pinctrl init failed: %d\n", ret);
145 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
147 debug("DRAM init failed: %d\n", ret);
152 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
153 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
157 static int setup_led(void)
159 #ifdef CONFIG_SPL_LED
164 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
167 ret = led_get_by_label(led_name, &dev);
169 debug("%s: get=%d\n", __func__, ret);
172 ret = led_set_on(dev, 1);
180 void spl_board_init(void)
182 struct udevice *pinctrl;
187 debug("LED ret=%d\n", ret);
191 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
193 debug("%s: Cannot find pinctrl device\n", __func__);
197 #ifdef CONFIG_SPL_MMC_SUPPORT
198 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
200 debug("%s: Failed to set up SD card\n", __func__);
205 /* Enable debug UART */
206 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
208 debug("%s: Failed to set up console UART\n", __func__);
212 preloader_console_init();
213 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
214 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
219 printf("spl_board_init: Error %d\n", ret);
221 /* No way to report error here */