]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/mach-rockchip/rk3288-board-spl.c
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/pmu_rk3288.h>
23 #include <asm/arch/sdram.h>
24 #include <asm/arch/sdram_common.h>
25 #include <asm/arch/sys_proto.h>
26 #include <asm/arch/timer.h>
27 #include <dm/pinctrl.h>
31 #include <power/regulator.h>
32 #include <power/rk8xx_pmic.h>
34 DECLARE_GLOBAL_DATA_PTR
;
36 u32
spl_boot_device(void)
38 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
39 const void *blob
= gd
->fdt_blob
;
45 bootdev
= fdtdec_get_config_string(blob
, "u-boot,boot0");
46 debug("Boot device %s\n", bootdev
);
50 node
= fdt_path_offset(blob
, bootdev
);
52 debug("node=%d\n", node
);
55 ret
= device_get_global_by_of_offset(node
, &dev
);
57 debug("device at node %s/%d not found: %d\n", bootdev
, node
,
61 debug("Found device %s\n", dev
->name
);
62 switch (device_get_uclass_id(dev
)) {
63 case UCLASS_SPI_FLASH
:
64 return BOOT_DEVICE_SPI
;
66 return BOOT_DEVICE_MMC1
;
68 debug("Booting from device uclass '%s' not supported\n",
69 dev_get_uclass_name(dev
));
73 #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
74 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
75 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
76 return BOOT_DEVICE_SPI
;
78 return BOOT_DEVICE_MMC1
;
81 #ifdef CONFIG_SPL_MMC_SUPPORT
82 static int configure_emmc(struct udevice
*pinctrl
)
84 #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
86 struct gpio_desc desc
;
89 pinctrl_request_noflags(pinctrl
, PERIPH_ID_EMMC
);
92 * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
93 * use the EMMC_PWREN setting.
95 ret
= dm_gpio_lookup_name("D9", &desc
);
97 debug("gpio ret=%d\n", ret
);
100 ret
= dm_gpio_request(&desc
, "emmc_pwren");
102 debug("gpio_request ret=%d\n", ret
);
105 ret
= dm_gpio_set_dir_flags(&desc
, GPIOD_IS_OUT
);
107 debug("gpio dir ret=%d\n", ret
);
110 ret
= dm_gpio_set_value(&desc
, 1);
112 debug("gpio value ret=%d\n", ret
);
120 #if !defined(CONFIG_SPL_OF_PLATDATA)
121 static int phycore_init(void)
123 struct udevice
*pmic
;
126 ret
= uclass_first_device_err(UCLASS_PMIC
, &pmic
);
130 #if defined(CONFIG_SPL_POWER_SUPPORT)
131 /* Increase USB input current to 2A */
132 ret
= rk818_spl_configure_usb_input_current(pmic
, 2000);
136 /* Close charger when USB lower then 3.26V */
137 ret
= rk818_spl_configure_usb_chrg_shutdown(pmic
, 3260000);
146 void board_init_f(ulong dummy
)
148 struct udevice
*pinctrl
;
152 /* Example code showing how to enable the debug UART on RK3288 */
153 #include <asm/arch/grf_rk3288.h>
154 /* Enable early UART on the RK3288 */
155 #define GRF_BASE 0xff770000
156 struct rk3288_grf
* const grf
= (void *)GRF_BASE
;
158 rk_clrsetreg(&grf
->gpio7ch_iomux
, GPIO7C7_MASK
<< GPIO7C7_SHIFT
|
159 GPIO7C6_MASK
<< GPIO7C6_SHIFT
,
160 GPIO7C7_UART2DBG_SOUT
<< GPIO7C7_SHIFT
|
161 GPIO7C6_UART2DBG_SIN
<< GPIO7C6_SHIFT
);
163 * Debug UART can be used from here if required:
168 * printascii("string");
171 debug("\nspl:debug uart enabled in %s\n", __func__
);
172 ret
= spl_early_init();
174 debug("spl_early_init() failed: %d\n", ret
);
178 rockchip_timer_init();
181 ret
= rockchip_get_clk(&dev
);
183 debug("CLK init failed: %d\n", ret
);
187 ret
= uclass_get_device(UCLASS_PINCTRL
, 0, &pinctrl
);
189 debug("Pinctrl init failed: %d\n", ret
);
193 #if !defined(CONFIG_SPL_OF_PLATDATA)
194 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
195 ret
= phycore_init();
197 debug("Failed to set up phycore power settings: %d\n",
204 #if !defined(CONFIG_SUPPORT_TPL)
205 debug("\nspl:init dram\n");
206 ret
= uclass_get_device(UCLASS_RAM
, 0, &dev
);
208 debug("DRAM init failed: %d\n", ret
);
213 #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
214 back_to_bootrom(BROM_BOOT_NEXTSTAGE
);
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)
281 back_to_bootrom(BROM_BOOT_NEXTSTAGE
);
285 printf("spl_board_init: Error %d\n", ret
);
287 /* No way to report error here */
291 #ifdef CONFIG_SPL_OS_BOOT
293 #define PMU_BASE 0xff730000
294 int dram_init_banksize(void)
296 struct rk3288_pmu
*const pmu
= (void *)PMU_BASE
;
297 size_t size
= rockchip_sdram_size((phys_addr_t
)&pmu
->sys_reg
[2]);
299 gd
->bd
->bi_dram
[0].start
= CONFIG_SYS_SDRAM_BASE
;
300 gd
->bd
->bi_dram
[0].size
= size
;