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 <dm/pinctrl.h>
25 #include <power/regulator.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 u32 spl_boot_device(void)
31 const void *blob = gd->fdt_blob;
37 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
38 debug("Boot device %s\n", bootdev);
42 node = fdt_path_offset(blob, bootdev);
44 debug("node=%d\n", node);
47 ret = device_get_global_by_of_offset(node, &dev);
49 debug("device at node %s/%d not found: %d\n", bootdev, node,
53 debug("Found device %s\n", dev->name);
54 switch (device_get_uclass_id(dev)) {
55 case UCLASS_SPI_FLASH:
56 return BOOT_DEVICE_SPI;
58 return BOOT_DEVICE_MMC1;
60 debug("Booting from device uclass '%s' not supported\n",
61 dev_get_uclass_name(dev));
65 return BOOT_DEVICE_MMC1;
68 u32 spl_boot_mode(void)
70 return MMCSD_MODE_RAW;
73 /* read L2 control register (L2CTLR) */
74 static inline uint32_t read_l2ctlr(void)
78 asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
83 /* write L2 control register (L2CTLR) */
84 static inline void write_l2ctlr(uint32_t val)
87 * Note: L2CTLR can only be written when the L2 memory system
88 * is idle, ie before the MMU is enabled.
90 asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory");
94 static void configure_l2ctlr(void)
98 l2ctlr = read_l2ctlr();
99 l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */
102 * Data RAM write latency: 2 cycles
103 * Data RAM read latency: 2 cycles
104 * Data RAM setup latency: 1 cycle
105 * Tag RAM write latency: 1 cycle
106 * Tag RAM read latency: 1 cycle
107 * Tag RAM setup latency: 1 cycle
109 l2ctlr |= (1 << 3 | 1 << 0);
110 write_l2ctlr(l2ctlr);
113 struct rk3288_timer {
114 u32 timer_load_count0;
115 u32 timer_load_count1;
116 u32 timer_curr_value0;
117 u32 timer_curr_value1;
119 u32 timer_int_status;
122 void init_timer(void)
124 struct rk3288_timer * const timer7_ptr = (void *)TIMER7_BASE;
126 writel(0xffffffff, &timer7_ptr->timer_load_count0);
127 writel(0xffffffff, &timer7_ptr->timer_load_count1);
128 writel(1, &timer7_ptr->timer_ctrl_reg);
131 static int configure_emmc(struct udevice *pinctrl)
133 struct gpio_desc desc;
136 pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
139 * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
140 * use the EMMC_PWREN setting.
142 ret = dm_gpio_lookup_name("D9", &desc);
144 debug("gpio ret=%d\n", ret);
147 ret = dm_gpio_request(&desc, "emmc_pwren");
149 debug("gpio_request ret=%d\n", ret);
152 ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
154 debug("gpio dir ret=%d\n", ret);
157 ret = dm_gpio_set_value(&desc, 1);
159 debug("gpio value ret=%d\n", ret);
166 void board_init_f(ulong dummy)
168 struct udevice *pinctrl;
172 /* Example code showing how to enable the debug UART on RK3288 */
174 #include <asm/arch/grf_rk3288.h>
175 /* Enable early UART on the RK3288 */
176 #define GRF_BASE 0xff770000
177 struct rk3288_grf * const grf = (void *)GRF_BASE;
179 rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
180 GPIO7C6_MASK << GPIO7C6_SHIFT,
181 GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
182 GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
184 * Debug UART can be used from here if required:
189 * printascii("string");
196 debug("spl_init() failed: %d\n", ret);
203 ret = uclass_get_device(UCLASS_CLK, 0, &dev);
205 debug("CLK init failed: %d\n", ret);
209 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
211 debug("Pinctrl init failed: %d\n", ret);
215 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
217 debug("DRAM init failed: %d\n", ret);
222 * Now that DRAM is initialized setup base pointer for simple malloc
225 gd->malloc_base = CONFIG_SPL_STACK_R_ADDR;
229 static int setup_led(void)
231 #ifdef CONFIG_SPL_LED
236 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
239 ret = led_get_by_label(led_name, &dev);
241 debug("%s: get=%d\n", __func__, ret);
244 ret = led_set_on(dev, 1);
252 void spl_board_init(void)
254 struct udevice *pinctrl;
260 debug("LED ret=%d\n", ret);
264 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
266 debug("%s: Cannot find pinctrl device\n", __func__);
269 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
271 debug("%s: Failed to set up SD card\n", __func__);
274 ret = configure_emmc(pinctrl);
276 debug("%s: Failed to set up eMMC\n", __func__);
280 /* Enable debug UART */
281 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
283 debug("%s: Failed to set up console UART\n", __func__);
287 preloader_console_init();
290 printf("spl_board_init: Error %d\n", ret);
292 /* No way to report error here */