2 * (C) Copyright 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
8 #include <debug_uart.h>
18 #include <asm/arch/bootrom.h>
19 #include <asm/arch/clock.h>
20 #include <asm/arch/hardware.h>
21 #include <asm/arch/periph.h>
22 #include <asm/arch/sdram.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/arch/timer.h>
25 #include <dm/pinctrl.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_of_offset(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 return BOOT_DEVICE_SPI;
76 return BOOT_DEVICE_MMC1;
79 u32 spl_boot_mode(const u32 boot_device)
81 return MMCSD_MODE_RAW;
84 #ifdef CONFIG_SPL_MMC_SUPPORT
85 static int configure_emmc(struct udevice *pinctrl)
87 #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
89 struct gpio_desc desc;
92 pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
95 * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
96 * use the EMMC_PWREN setting.
98 ret = dm_gpio_lookup_name("D9", &desc);
100 debug("gpio ret=%d\n", ret);
103 ret = dm_gpio_request(&desc, "emmc_pwren");
105 debug("gpio_request ret=%d\n", ret);
108 ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
110 debug("gpio dir ret=%d\n", ret);
113 ret = dm_gpio_set_value(&desc, 1);
115 debug("gpio value ret=%d\n", ret);
123 #if !defined(CONFIG_SPL_OF_PLATDATA)
124 static int phycore_init(void)
126 struct udevice *pmic;
129 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
133 #if defined(CONFIG_SPL_POWER_SUPPORT)
134 /* Increase USB input current to 2A */
135 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
139 /* Close charger when USB lower then 3.26V */
140 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
149 void board_init_f(ulong dummy)
151 struct udevice *pinctrl;
155 /* Example code showing how to enable the debug UART on RK3288 */
156 #include <asm/arch/grf_rk3288.h>
157 /* Enable early UART on the RK3288 */
158 #define GRF_BASE 0xff770000
159 struct rk3288_grf * const grf = (void *)GRF_BASE;
161 rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
162 GPIO7C6_MASK << GPIO7C6_SHIFT,
163 GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
164 GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
166 * Debug UART can be used from here if required:
171 * printascii("string");
174 debug("\nspl:debug uart enabled in %s\n", __func__);
175 ret = spl_early_init();
177 debug("spl_early_init() failed: %d\n", ret);
181 rockchip_timer_init();
184 ret = rockchip_get_clk(&dev);
186 debug("CLK init failed: %d\n", ret);
190 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
192 debug("Pinctrl init failed: %d\n", ret);
196 #if !defined(CONFIG_SPL_OF_PLATDATA)
197 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
198 ret = phycore_init();
200 debug("Failed to set up phycore power settings: %d\n",
207 debug("\nspl:init dram\n");
208 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
210 debug("DRAM init failed: %d\n", ret);
213 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
218 static int setup_led(void)
220 #ifdef CONFIG_SPL_LED
225 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
228 ret = led_get_by_label(led_name, &dev);
230 debug("%s: get=%d\n", __func__, ret);
233 ret = led_set_on(dev, 1);
241 void spl_board_init(void)
243 struct udevice *pinctrl;
249 debug("LED ret=%d\n", ret);
253 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
255 debug("%s: Cannot find pinctrl device\n", __func__);
259 #ifdef CONFIG_SPL_MMC_SUPPORT
260 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
262 debug("%s: Failed to set up SD card\n", __func__);
265 ret = configure_emmc(pinctrl);
267 debug("%s: Failed to set up eMMC\n", __func__);
272 /* Enable debug UART */
273 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
275 debug("%s: Failed to set up console UART\n", __func__);
279 preloader_console_init();
280 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
285 printf("spl_board_init: Error %d\n", ret);
287 /* No way to report error here */