blob: 9efba47affc55c246137e8fe77338e02043ac4f2 [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
Kever Yangbd8532e2019-07-22 19:59:15 +080033void board_return_to_bootrom(void)
34{
35 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
36}
37
Simon Glass2cffe662015-08-30 16:55:38 -060038u32 spl_boot_device(void)
39{
Simon Glass26158ef2016-07-04 11:58:32 -060040#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass2cffe662015-08-30 16:55:38 -060041 const void *blob = gd->fdt_blob;
42 struct udevice *dev;
43 const char *bootdev;
44 int node;
45 int ret;
46
47 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
48 debug("Boot device %s\n", bootdev);
49 if (!bootdev)
50 goto fallback;
51
52 node = fdt_path_offset(blob, bootdev);
53 if (node < 0) {
54 debug("node=%d\n", node);
55 goto fallback;
56 }
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +020057 ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev);
Simon Glass2cffe662015-08-30 16:55:38 -060058 if (ret) {
59 debug("device at node %s/%d not found: %d\n", bootdev, node,
60 ret);
61 goto fallback;
62 }
63 debug("Found device %s\n", dev->name);
64 switch (device_get_uclass_id(dev)) {
65 case UCLASS_SPI_FLASH:
66 return BOOT_DEVICE_SPI;
67 case UCLASS_MMC:
68 return BOOT_DEVICE_MMC1;
69 default:
70 debug("Booting from device uclass '%s' not supported\n",
71 dev_get_uclass_name(dev));
72 }
73
74fallback:
Simon Glassbf8d7bf2016-11-13 14:22:16 -070075#elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
Simon Glasse51b2e72016-11-13 14:24:54 -070076 defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
Marty E. Plummer27086982019-01-05 20:12:08 -060077 defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \
78 defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY)
Simon Glass6f9087c2016-11-13 14:21:57 -070079 return BOOT_DEVICE_SPI;
Simon Glass26158ef2016-07-04 11:58:32 -060080#endif
Simon Glass2cffe662015-08-30 16:55:38 -060081 return BOOT_DEVICE_MMC1;
82}
83
Wadim Egorov6ee2d012017-06-19 12:36:40 +020084#if !defined(CONFIG_SPL_OF_PLATDATA)
85static int phycore_init(void)
86{
87 struct udevice *pmic;
88 int ret;
89
90 ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
91 if (ret)
92 return ret;
93
94#if defined(CONFIG_SPL_POWER_SUPPORT)
95 /* Increase USB input current to 2A */
96 ret = rk818_spl_configure_usb_input_current(pmic, 2000);
97 if (ret)
98 return ret;
99
100 /* Close charger when USB lower then 3.26V */
101 ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
102 if (ret)
103 return ret;
104#endif
105
106 return 0;
107}
108#endif
109
Kever Yanga3eff932019-07-09 21:58:43 +0800110__weak int arch_cpu_init(void)
111{
112 return 0;
113}
114
Kever Yang243fca72019-07-09 22:00:26 +0800115#define TIMER_LOAD_COUNT_L 0x00
116#define TIMER_LOAD_COUNT_H 0x04
117#define TIMER_CONTROL_REG 0x10
118#define TIMER_EN 0x1
119#define TIMER_FMODE BIT(0)
120#define TIMER_RMODE BIT(1)
121
122void rockchip_stimer_init(void)
123{
124 /* If Timer already enabled, don't re-init it */
125 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
126
127 if (reg & TIMER_EN)
128 return;
129
130 asm volatile("mcr p15, 0, %0, c14, c0, 0"
131 : : "r"(COUNTER_FREQUENCY));
132
133 writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG);
134 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE);
135 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4);
136 writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE +
137 TIMER_CONTROL_REG);
138}
139
Simon Glass2cffe662015-08-30 16:55:38 -0600140void board_init_f(ulong dummy)
141{
Simon Glass2cffe662015-08-30 16:55:38 -0600142 struct udevice *dev;
143 int ret;
144
Kever Yangabfed9b2019-03-29 09:09:04 +0800145#ifdef CONFIG_DEBUG_UART
Simon Glass2cffe662015-08-30 16:55:38 -0600146 /*
147 * Debug UART can be used from here if required:
148 *
149 * debug_uart_init();
150 * printch('a');
151 * printhex8(0x1234);
152 * printascii("string");
153 */
154 debug_uart_init();
Eddie Cai9d62e822017-04-18 19:17:27 +0800155 debug("\nspl:debug uart enabled in %s\n", __func__);
Kever Yangabfed9b2019-03-29 09:09:04 +0800156#endif
Eddie Cai3e2b61c2017-03-15 08:43:29 -0600157 ret = spl_early_init();
Simon Glass2cffe662015-08-30 16:55:38 -0600158 if (ret) {
Eddie Cai3e2b61c2017-03-15 08:43:29 -0600159 debug("spl_early_init() failed: %d\n", ret);
Simon Glass2cffe662015-08-30 16:55:38 -0600160 hang();
161 }
162
Kever Yang243fca72019-07-09 22:00:26 +0800163 /* Init secure timer */
164 rockchip_stimer_init();
165 /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */
166 timer_init();
167
Kever Yanga3eff932019-07-09 21:58:43 +0800168 arch_cpu_init();
Simon Glass2cffe662015-08-30 16:55:38 -0600169
Simon Glassae8fe412016-07-17 15:23:17 -0600170 ret = rockchip_get_clk(&dev);
Simon Glass2cffe662015-08-30 16:55:38 -0600171 if (ret) {
172 debug("CLK init failed: %d\n", ret);
173 return;
174 }
175
Wadim Egorov6ee2d012017-06-19 12:36:40 +0200176#if !defined(CONFIG_SPL_OF_PLATDATA)
177 if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
178 ret = phycore_init();
179 if (ret) {
180 debug("Failed to set up phycore power settings: %d\n",
181 ret);
182 return;
183 }
184 }
185#endif
186
Jagan Teki387fd4b2017-09-27 23:03:12 +0530187#if !defined(CONFIG_SUPPORT_TPL)
Eddie Cai9d62e822017-04-18 19:17:27 +0800188 debug("\nspl:init dram\n");
Simon Glass2cffe662015-08-30 16:55:38 -0600189 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
190 if (ret) {
191 debug("DRAM init failed: %d\n", ret);
192 return;
193 }
Jagan Teki387fd4b2017-09-27 23:03:12 +0530194#endif
Simon Glass2cffe662015-08-30 16:55:38 -0600195}
196
197static int setup_led(void)
198{
199#ifdef CONFIG_SPL_LED
200 struct udevice *dev;
201 char *led_name;
202 int ret;
203
204 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
205 if (!led_name)
206 return 0;
207 ret = led_get_by_label(led_name, &dev);
208 if (ret) {
209 debug("%s: get=%d\n", __func__, ret);
210 return ret;
211 }
212 ret = led_set_on(dev, 1);
213 if (ret)
214 return ret;
215#endif
216
217 return 0;
218}
219
220void spl_board_init(void)
221{
Simon Glass2cffe662015-08-30 16:55:38 -0600222 int ret;
223
224 ret = setup_led();
Simon Glass2cffe662015-08-30 16:55:38 -0600225 if (ret) {
226 debug("LED ret=%d\n", ret);
227 hang();
228 }
229
Simon Glass2cffe662015-08-30 16:55:38 -0600230 preloader_console_init();
Kever Yangbd8532e2019-07-22 19:59:15 +0800231
Simon Glass2cffe662015-08-30 16:55:38 -0600232 return;
Simon Glass2cffe662015-08-30 16:55:38 -0600233}
Jagan Teki536e4d32017-09-27 23:03:14 +0530234
235#ifdef CONFIG_SPL_OS_BOOT
236
237#define PMU_BASE 0xff730000
238int dram_init_banksize(void)
239{
240 struct rk3288_pmu *const pmu = (void *)PMU_BASE;
241 size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]);
242
243 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
244 gd->bd->bi_dram[0].size = size;
245
246 return 0;
247}
248#endif