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 const void *blob = gd->fdt_blob;
38 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
39 debug("Boot device %s\n", bootdev);
43 node = fdt_path_offset(blob, bootdev);
45 debug("node=%d\n", node);
48 ret = device_get_global_by_of_offset(node, &dev);
50 debug("device at node %s/%d not found: %d\n", bootdev, node,
54 debug("Found device %s\n", dev->name);
55 switch (device_get_uclass_id(dev)) {
56 case UCLASS_SPI_FLASH:
57 return BOOT_DEVICE_SPI;
59 return BOOT_DEVICE_MMC1;
61 debug("Booting from device uclass '%s' not supported\n",
62 dev_get_uclass_name(dev));
66 return BOOT_DEVICE_MMC1;
69 u32 spl_boot_mode(void)
71 return MMCSD_MODE_RAW;
74 /* read L2 control register (L2CTLR) */
75 static inline uint32_t read_l2ctlr(void)
79 asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
84 /* write L2 control register (L2CTLR) */
85 static inline void write_l2ctlr(uint32_t val)
88 * Note: L2CTLR can only be written when the L2 memory system
89 * is idle, ie before the MMU is enabled.
91 asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory");
95 static void configure_l2ctlr(void)
99 l2ctlr = read_l2ctlr();
100 l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */
103 * Data RAM write latency: 2 cycles
104 * Data RAM read latency: 2 cycles
105 * Data RAM setup latency: 1 cycle
106 * Tag RAM write latency: 1 cycle
107 * Tag RAM read latency: 1 cycle
108 * Tag RAM setup latency: 1 cycle
110 l2ctlr |= (1 << 3 | 1 << 0);
111 write_l2ctlr(l2ctlr);
114 static int configure_emmc(struct udevice *pinctrl)
116 struct gpio_desc desc;
119 pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
123 * use the EMMC_PWREN setting.
125 ret = dm_gpio_lookup_name("D9", &desc);
127 debug("gpio ret=%d\n", ret);
130 ret = dm_gpio_request(&desc, "emmc_pwren");
132 debug("gpio_request ret=%d\n", ret);
135 ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
137 debug("gpio dir ret=%d\n", ret);
140 ret = dm_gpio_set_value(&desc, 1);
142 debug("gpio value ret=%d\n", ret);
149 void board_init_f(ulong dummy)
151 struct udevice *pinctrl;
155 /* Example code showing how to enable the debug UART on RK3288 */
157 #include <asm/arch/grf_rk3288.h>
158 /* Enable early UART on the RK3288 */
159 #define GRF_BASE 0xff770000
160 struct rk3288_grf * const grf = (void *)GRF_BASE;
162 rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
163 GPIO7C6_MASK << GPIO7C6_SHIFT,
164 GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
165 GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
167 * Debug UART can be used from here if required:
172 * printascii("string");
179 debug("spl_init() failed: %d\n", ret);
183 rockchip_timer_init();
186 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
188 debug("CLK init failed: %d\n", ret);
192 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
194 debug("Pinctrl init failed: %d\n", ret);
198 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
200 debug("DRAM init failed: %d\n", ret);
205 static int setup_led(void)
207 #ifdef CONFIG_SPL_LED
212 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
215 ret = led_get_by_label(led_name, &dev);
217 debug("%s: get=%d\n", __func__, ret);
220 ret = led_set_on(dev, 1);
228 void spl_board_init(void)
230 struct udevice *pinctrl;
236 debug("LED ret=%d\n", ret);
240 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
242 debug("%s: Cannot find pinctrl device\n", __func__);
245 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
247 debug("%s: Failed to set up SD card\n", __func__);
250 ret = configure_emmc(pinctrl);
252 debug("%s: Failed to set up eMMC\n", __func__);
256 /* Enable debug UART */
257 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
259 debug("%s: Failed to set up console UART\n", __func__);
263 preloader_console_init();
266 printf("spl_board_init: Error %d\n", ret);
268 /* No way to report error here */