2 * (C) Copyright 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <debug_uart.h>
17 #include <asm/arch/clock.h>
18 #include <asm/arch/hardware.h>
19 #include <asm/arch/periph.h>
20 #include <asm/arch/sdram.h>
21 #include <asm/arch/timer.h>
22 #include <dm/pinctrl.h>
26 #include <power/regulator.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 u32 spl_boot_device(void)
32 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
33 const void *blob = gd->fdt_blob;
39 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
40 debug("Boot device %s\n", bootdev);
44 node = fdt_path_offset(blob, bootdev);
46 debug("node=%d\n", node);
49 ret = device_get_global_by_of_offset(node, &dev);
51 debug("device at node %s/%d not found: %d\n", bootdev, node,
55 debug("Found device %s\n", dev->name);
56 switch (device_get_uclass_id(dev)) {
57 case UCLASS_SPI_FLASH:
58 return BOOT_DEVICE_SPI;
60 return BOOT_DEVICE_MMC1;
62 debug("Booting from device uclass '%s' not supported\n",
63 dev_get_uclass_name(dev));
67 #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
68 return BOOT_DEVICE_SPI;
70 return BOOT_DEVICE_MMC1;
73 u32 spl_boot_mode(const u32 boot_device)
75 return MMCSD_MODE_RAW;
78 /* read L2 control register (L2CTLR) */
79 static inline uint32_t read_l2ctlr(void)
83 asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
88 /* write L2 control register (L2CTLR) */
89 static inline void write_l2ctlr(uint32_t val)
92 * Note: L2CTLR can only be written when the L2 memory system
93 * is idle, ie before the MMU is enabled.
95 asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory");
99 static void configure_l2ctlr(void)
103 l2ctlr = read_l2ctlr();
104 l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */
107 * Data RAM write latency: 2 cycles
108 * Data RAM read latency: 2 cycles
109 * Data RAM setup latency: 1 cycle
110 * Tag RAM write latency: 1 cycle
111 * Tag RAM read latency: 1 cycle
112 * Tag RAM setup latency: 1 cycle
114 l2ctlr |= (1 << 3 | 1 << 0);
115 write_l2ctlr(l2ctlr);
118 #ifdef CONFIG_SPL_MMC_SUPPORT
119 static int configure_emmc(struct udevice *pinctrl)
121 #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
123 struct gpio_desc desc;
126 pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
129 * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
130 * use the EMMC_PWREN setting.
132 ret = dm_gpio_lookup_name("D9", &desc);
134 debug("gpio ret=%d\n", ret);
137 ret = dm_gpio_request(&desc, "emmc_pwren");
139 debug("gpio_request ret=%d\n", ret);
142 ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
144 debug("gpio dir ret=%d\n", ret);
147 ret = dm_gpio_set_value(&desc, 1);
149 debug("gpio value ret=%d\n", ret);
156 extern void back_to_bootrom(void);
157 void board_init_f(ulong dummy)
159 struct udevice *pinctrl;
163 /* Example code showing how to enable the debug UART on RK3288 */
165 #include <asm/arch/grf_rk3288.h>
166 /* Enable early UART on the RK3288 */
167 #define GRF_BASE 0xff770000
168 struct rk3288_grf * const grf = (void *)GRF_BASE;
170 rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
171 GPIO7C6_MASK << GPIO7C6_SHIFT,
172 GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
173 GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
175 * Debug UART can be used from here if required:
180 * printascii("string");
187 debug("spl_init() failed: %d\n", ret);
191 rockchip_timer_init();
194 ret = rockchip_get_clk(&dev);
196 debug("CLK init failed: %d\n", ret);
200 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
202 debug("Pinctrl init failed: %d\n", ret);
206 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
208 debug("DRAM init failed: %d\n", ret);
211 #if defined(CONFIG_ROCKCHIP_SPL_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
216 static int setup_led(void)
218 #ifdef CONFIG_SPL_LED
223 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
226 ret = led_get_by_label(led_name, &dev);
228 debug("%s: get=%d\n", __func__, ret);
231 ret = led_set_on(dev, 1);
239 void spl_board_init(void)
241 struct udevice *pinctrl;
247 debug("LED ret=%d\n", ret);
251 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
253 debug("%s: Cannot find pinctrl device\n", __func__);
257 #ifdef CONFIG_SPL_MMC_SUPPORT
258 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
260 debug("%s: Failed to set up SD card\n", __func__);
263 ret = configure_emmc(pinctrl);
265 debug("%s: Failed to set up eMMC\n", __func__);
270 /* Enable debug UART */
271 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
273 debug("%s: Failed to set up console UART\n", __func__);
277 preloader_console_init();
278 #ifdef CONFIG_ROCKCHIP_SPL_BACK_TO_BROM
283 printf("spl_board_init: Error %d\n", ret);
285 /* No way to report error here */