blob: c2e168192c2b3540937e4de29bcc9e45967e0ca9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass2cffe662015-08-30 16:55:38 -06002/*
3 * (C) Copyright 2015 Google, Inc
Simon Glass2cffe662015-08-30 16:55:38 -06004 */
5
6#include <common.h>
7#include <debug_uart.h>
8#include <dm.h>
9#include <fdtdec.h>
Wadim Egorov6ee2d012017-06-19 12:36:40 +020010#include <i2c.h>
Simon Glass2cffe662015-08-30 16:55:38 -060011#include <led.h>
12#include <malloc.h>
13#include <ram.h>
14#include <spl.h>
15#include <asm/gpio.h>
16#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080017#include <asm/arch-rockchip/bootrom.h>
18#include <asm/arch-rockchip/clock.h>
19#include <asm/arch-rockchip/hardware.h>
20#include <asm/arch-rockchip/periph.h>
21#include <asm/arch-rockchip/pmu_rk3288.h>
22#include <asm/arch-rockchip/sdram.h>
23#include <asm/arch-rockchip/sdram_common.h>
24#include <asm/arch-rockchip/sys_proto.h>
Simon Glass2cffe662015-08-30 16:55:38 -060025#include <dm/root.h>
26#include <dm/test.h>
27#include <dm/util.h>
28#include <power/regulator.h>
Wadim Egorov6ee2d012017-06-19 12:36:40 +020029#include <power/rk8xx_pmic.h>
Simon Glass2cffe662015-08-30 16:55:38 -060030
31DECLARE_GLOBAL_DATA_PTR;
32
33u32 spl_boot_device(void)
34{
Simon Glass26158ef2016-07-04 11:58:32 -060035#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass2cffe662015-08-30 16:55:38 -060036 const void *blob = gd->fdt_blob;
37 struct udevice *dev;
38 const char *bootdev;
39 int node;
40 int ret;
41
42 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
43 debug("Boot device %s\n", bootdev);
44 if (!bootdev)
45 goto fallback;
46
47 node = fdt_path_offset(blob, bootdev);
48 if (node < 0) {
49 debug("node=%d\n", node);
50 goto fallback;
51 }
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +020052 ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev);
Simon Glass2cffe662015-08-30 16:55:38 -060053 if (ret) {
54 debug("device at node %s/%d not found: %d\n", bootdev, node,
55 ret);
56 goto fallback;
57 }
58 debug("Found device %s\n", dev->name);
59 switch (device_get_uclass_id(dev)) {
60 case UCLASS_SPI_FLASH:
61 return BOOT_DEVICE_SPI;
62 case UCLASS_MMC:
63 return BOOT_DEVICE_MMC1;
64 default:
65 debug("Booting from device uclass '%s' not supported\n",
66 dev_get_uclass_name(dev));
67 }
68
69fallback:
Simon Glassbf8d7bf2016-11-13 14:22:16 -070070#elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
Simon Glasse51b2e72016-11-13 14:24:54 -070071 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Marty E. Plummer27086982019-01-05 20:12:08 -060072 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
73 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY)
Simon Glass6f9087c2016-11-13 14:21:57 -070074 return BOOT_DEVICE_SPI;
Simon Glass26158ef2016-07-04 11:58:32 -060075#endif
Simon Glass2cffe662015-08-30 16:55:38 -060076 return BOOT_DEVICE_MMC1;
77}
78
Wadim Egorov6ee2d012017-06-19 12:36:40 +020079#if !defined(CONFIG_SPL_OF_PLATDATA)
80static int phycore_init(void)
81{
82 struct udevice *pmic;
83 int ret;
84
85 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
86 if (ret)
87 return ret;
88
89#if defined(CONFIG_SPL_POWER_SUPPORT)
90 /* Increase USB input current to 2A */
91 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
92 if (ret)
93 return ret;
94
95 /* Close charger when USB lower then 3.26V */
96 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
97 if (ret)
98 return ret;
99#endif
100
101 return 0;
102}
103#endif
104
Kever Yanga3eff932019-07-09 21:58:43 +0800105__weak int arch_cpu_init(void)
106{
107 return 0;
108}
109
Kever Yang243fca72019-07-09 22:00:26 +0800110#define TIMER_LOAD_COUNT_L 0x00
111#define TIMER_LOAD_COUNT_H 0x04
112#define TIMER_CONTROL_REG 0x10
113#define TIMER_EN 0x1
114#define TIMER_FMODE BIT(0)
115#define TIMER_RMODE BIT(1)
116
117void rockchip_stimer_init(void)
118{
119 /* If Timer already enabled, don't re-init it */
120 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
121
122 if (reg & TIMER_EN)
123 return;
124
125 asm volatile("mcr p15, 0, %0, c14, c0, 0"
126 : : "r"(COUNTER_FREQUENCY));
127
128 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
129 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
130 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
131 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
132 TIMER_CONTROL_REG);
133}
134
Simon Glass2cffe662015-08-30 16:55:38 -0600135void board_init_f(ulong dummy)
136{
Simon Glass2cffe662015-08-30 16:55:38 -0600137 struct udevice *dev;
138 int ret;
139
Kever Yangabfed9b2019-03-29 09:09:04 +0800140#ifdef CONFIG_DEBUG_UART
Simon Glass2cffe662015-08-30 16:55:38 -0600141 /*
142 * Debug UART can be used from here if required:
143 *
144 * debug_uart_init();
145 * printch('a');
146 * printhex8(0x1234);
147 * printascii("string");
148 */
149 debug_uart_init();
Eddie Cai9d62e822017-04-18 19:17:27 +0800150 debug("\nspl:debug uart enabled in %s\n", __func__);
Kever Yangabfed9b2019-03-29 09:09:04 +0800151#endif
Eddie Cai3e2b61c2017-03-15 08:43:29 -0600152 ret = spl_early_init();
Simon Glass2cffe662015-08-30 16:55:38 -0600153 if (ret) {
Eddie Cai3e2b61c2017-03-15 08:43:29 -0600154 debug("spl_early_init() failed: %d\n", ret);
Simon Glass2cffe662015-08-30 16:55:38 -0600155 hang();
156 }
157
Kever Yang243fca72019-07-09 22:00:26 +0800158 /* Init secure timer */
159 rockchip_stimer_init();
160 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
161 timer_init();
162
Kever Yanga3eff932019-07-09 21:58:43 +0800163 arch_cpu_init();
Simon Glass2cffe662015-08-30 16:55:38 -0600164
Simon Glassae8fe412016-07-17 15:23:17 -0600165 ret = rockchip_get_clk(&dev);
Simon Glass2cffe662015-08-30 16:55:38 -0600166 if (ret) {
167 debug("CLK init failed: %d\n", ret);
168 return;
169 }
170
Wadim Egorov6ee2d012017-06-19 12:36:40 +0200171#if !defined(CONFIG_SPL_OF_PLATDATA)
172 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
173 ret = phycore_init();
174 if (ret) {
175 debug("Failed to set up phycore power settings: %d\n",
176 ret);
177 return;
178 }
179 }
180#endif
181
Jagan Teki387fd4b2017-09-27 23:03:12 +0530182#if !defined(CONFIG_SUPPORT_TPL)
Eddie Cai9d62e822017-04-18 19:17:27 +0800183 debug("\nspl:init dram\n");
Simon Glass2cffe662015-08-30 16:55:38 -0600184 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
185 if (ret) {
186 debug("DRAM init failed: %d\n", ret);
187 return;
188 }
Jagan Teki387fd4b2017-09-27 23:03:12 +0530189#endif
190
Philipp Tomsich798370f2017-06-29 11:21:15 +0200191#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200192 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Xu Ziyuan5401eb82016-07-12 19:09:49 +0800193#endif
Simon Glass2cffe662015-08-30 16:55:38 -0600194}
195
196static int setup_led(void)
197{
198#ifdef CONFIG_SPL_LED
199 struct udevice *dev;
200 char *led_name;
201 int ret;
202
203 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
204 if (!led_name)
205 return 0;
206 ret = led_get_by_label(led_name, &dev);
207 if (ret) {
208 debug("%s: get=%d\n", __func__, ret);
209 return ret;
210 }
211 ret = led_set_on(dev, 1);
212 if (ret)
213 return ret;
214#endif
215
216 return 0;
217}
218
219void spl_board_init(void)
220{
Simon Glass2cffe662015-08-30 16:55:38 -0600221 int ret;
222
223 ret = setup_led();
Simon Glass2cffe662015-08-30 16:55:38 -0600224 if (ret) {
225 debug("LED ret=%d\n", ret);
226 hang();
227 }
228
Simon Glass2cffe662015-08-30 16:55:38 -0600229 preloader_console_init();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200230#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200231 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Sandy Pattersona9e92ee2016-08-10 10:21:47 -0400232#endif
Simon Glass2cffe662015-08-30 16:55:38 -0600233 return;
Simon Glass2cffe662015-08-30 16:55:38 -0600234}
Jagan Teki536e4d32017-09-27 23:03:14 +0530235
236#ifdef CONFIG_SPL_OS_BOOT
237
238#define PMU_BASE 0xff730000
239int dram_init_banksize(void)
240{
241 struct rk3288_pmu *const pmu = (void *)PMU_BASE;
242 size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]);
243
244 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
245 gd->bd->bi_dram[0].size = size;
246
247 return 0;
248}
249#endif