1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
7 #include <debug_uart.h>
17 #include <asm/arch-rockchip/bootrom.h>
18 #include <asm/arch-rockchip/clock.h>
19 #include <asm/arch-rockchip/hardware.h>
20 #include <asm/arch-rockchip/periph.h>
21 #include <asm/arch-rockchip/pmu_rk3288.h>
22 #include <asm/arch-rockchip/sdram.h>
23 #include <asm/arch-rockchip/sdram_common.h>
24 #include <asm/arch-rockchip/sys_proto.h>
25 #include <asm/arch-rockchip/timer.h>
29 #include <power/regulator.h>
30 #include <power/rk8xx_pmic.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_ofnode(offset_to_ofnode(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));
71 #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
72 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
73 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
74 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY)
75 return BOOT_DEVICE_SPI;
77 return BOOT_DEVICE_MMC1;
80 #if !defined(CONFIG_SPL_OF_PLATDATA)
81 static int phycore_init(void)
86 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
90 #if defined(CONFIG_SPL_POWER_SUPPORT)
91 /* Increase USB input current to 2A */
92 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
96 /* Close charger when USB lower then 3.26V */
97 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
106 __weak int arch_cpu_init(void)
111 void board_init_f(ulong dummy)
116 #ifdef CONFIG_DEBUG_UART
118 * Debug UART can be used from here if required:
123 * printascii("string");
126 debug("\nspl:debug uart enabled in %s\n", __func__);
128 ret = spl_early_init();
130 debug("spl_early_init() failed: %d\n", ret);
134 rockchip_timer_init();
137 ret = rockchip_get_clk(&dev);
139 debug("CLK init failed: %d\n", ret);
143 #if !defined(CONFIG_SPL_OF_PLATDATA)
144 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
145 ret = phycore_init();
147 debug("Failed to set up phycore power settings: %d\n",
154 #if !defined(CONFIG_SUPPORT_TPL)
155 debug("\nspl:init dram\n");
156 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
158 debug("DRAM init failed: %d\n", ret);
163 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
164 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
168 static int setup_led(void)
170 #ifdef CONFIG_SPL_LED
175 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
178 ret = led_get_by_label(led_name, &dev);
180 debug("%s: get=%d\n", __func__, ret);
183 ret = led_set_on(dev, 1);
191 void spl_board_init(void)
197 debug("LED ret=%d\n", ret);
201 preloader_console_init();
202 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
203 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
208 #ifdef CONFIG_SPL_OS_BOOT
210 #define PMU_BASE 0xff730000
211 int dram_init_banksize(void)
213 struct rk3288_pmu *const pmu = (void *)PMU_BASE;
214 size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]);
216 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
217 gd->bd->bi_dram[0].size = size;