blob: c3efe0d7a95a9cbc35110729271dede68dae7ea7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Stübner0b3c26a2017-02-18 19:46:38 +01002/*
3 * (C) Copyright 2015 Google, Inc
Heiko Stübner0b3c26a2017-02-18 19:46:38 +01004 */
5
Heiko Stübnerba188bb2017-03-20 12:40:33 +01006#include <clk.h>
Heiko Stübner0b3c26a2017-02-18 19:46:38 +01007#include <common.h>
8#include <debug_uart.h>
9#include <dm.h>
10#include <fdtdec.h>
11#include <led.h>
12#include <malloc.h>
13#include <ram.h>
14#include <spl.h>
Simon Glassf473eba2019-01-21 14:53:31 -070015#include <syscon.h>
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010016#include <asm/gpio.h>
17#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080018#include <asm/arch-rockchip/bootrom.h>
19#include <asm/arch-rockchip/clock.h>
20#include <asm/arch-rockchip/grf_rk3188.h>
21#include <asm/arch-rockchip/hardware.h>
22#include <asm/arch-rockchip/periph.h>
23#include <asm/arch-rockchip/pmu_rk3188.h>
24#include <asm/arch-rockchip/sdram.h>
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010025#include <dm/root.h>
26#include <dm/test.h>
27#include <dm/util.h>
28#include <power/regulator.h>
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010029
30DECLARE_GLOBAL_DATA_PTR;
31
32u32 spl_boot_device(void)
33{
34#if !CONFIG_IS_ENABLED(OF_PLATDATA)
35 const void *blob = gd->fdt_blob;
36 struct udevice *dev;
37 const char *bootdev;
38 int node;
39 int ret;
40
41 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
42 debug("Boot device %s\n", bootdev);
43 if (!bootdev)
44 goto fallback;
45
46 node = fdt_path_offset(blob, bootdev);
47 if (node < 0) {
48 debug("node=%d\n", node);
49 goto fallback;
50 }
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +020051 ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010052 if (ret) {
53 debug("device at node %s/%d not found: %d\n", bootdev, node,
54 ret);
55 goto fallback;
56 }
57 debug("Found device %s\n", dev->name);
58 switch (device_get_uclass_id(dev)) {
59 case UCLASS_SPI_FLASH:
60 return BOOT_DEVICE_SPI;
61 case UCLASS_MMC:
62 return BOOT_DEVICE_MMC1;
63 default:
64 debug("Booting from device uclass '%s' not supported\n",
65 dev_get_uclass_name(dev));
66 }
67
68fallback:
69#endif
70 return BOOT_DEVICE_MMC1;
71}
72
Heiko Stübnerba188bb2017-03-20 12:40:33 +010073static int setup_arm_clock(void)
74{
75 struct udevice *dev;
76 struct clk clk;
77 int ret;
78
79 ret = rockchip_get_clk(&dev);
80 if (ret)
81 return ret;
82
83 clk.id = CLK_ARM;
84 ret = clk_request(dev, &clk);
85 if (ret < 0)
86 return ret;
87
88 ret = clk_set_rate(&clk, 600000000);
89
90 clk_free(&clk);
91 return ret;
92}
93
Kever Yangd2af98b2018-11-29 10:07:38 +080094void board_init_f(ulong dummy)
95{
David Wucee4c822019-01-02 20:50:58 +080096 struct udevice *dev;
Kever Yangd2af98b2018-11-29 10:07:38 +080097 int ret;
98
Kever Yang0a2a5e12019-03-29 09:09:01 +080099#ifdef CONFIG_DEBUG_UART
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100100 /*
101 * Debug UART can be used from here if required:
102 *
103 * debug_uart_init();
104 * printch('a');
105 * printhex8(0x1234);
106 * printascii("string");
107 */
108 debug_uart_init();
David Wucee4c822019-01-02 20:50:58 +0800109 printascii("U-Boot SPL board init");
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100110#endif
111
Heiko Stuebner9cc8feb2018-10-08 13:01:56 +0200112#ifdef CONFIG_ROCKCHIP_USB_UART
113 rk_clrsetreg(&grf->uoc0_con[0],
114 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
115 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
116 1 << COMMON_ON_N_SHIFT);
117 rk_clrsetreg(&grf->uoc0_con[2],
118 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
119 rk_clrsetreg(&grf->uoc0_con[3],
120 OPMODE_MASK | XCVRSELECT_MASK |
121 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
122 OPMODE_NODRIVING << OPMODE_SHIFT |
123 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
124 1 << TERMSEL_FULLSPEED_SHIFT |
125 1 << SUSPENDN_SHIFT);
126 rk_clrsetreg(&grf->uoc0_con[0],
127 BYPASSSEL_MASK | BYPASSDMEN_MASK,
128 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
129#endif
130
Kever Yange603a3d2017-03-20 14:47:16 +0800131 ret = spl_early_init();
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100132 if (ret) {
Kever Yange603a3d2017-03-20 14:47:16 +0800133 debug("spl_early_init() failed: %d\n", ret);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100134 hang();
135 }
136
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100137 ret = rockchip_get_clk(&dev);
138 if (ret) {
139 debug("CLK init failed: %d\n", ret);
140 return;
141 }
142
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100143 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
144 if (ret) {
145 debug("DRAM init failed: %d\n", ret);
146 return;
147 }
148
Heiko Stübnerba188bb2017-03-20 12:40:33 +0100149 setup_arm_clock();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200150#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200151 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100152#endif
153}
154
155static int setup_led(void)
156{
157#ifdef CONFIG_SPL_LED
158 struct udevice *dev;
159 char *led_name;
160 int ret;
161
162 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
163 if (!led_name)
164 return 0;
165 ret = led_get_by_label(led_name, &dev);
166 if (ret) {
167 debug("%s: get=%d\n", __func__, ret);
168 return ret;
169 }
170 ret = led_set_on(dev, 1);
171 if (ret)
172 return ret;
173#endif
174
175 return 0;
176}
177
178void spl_board_init(void)
179{
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100180 int ret;
181
182 ret = setup_led();
183 if (ret) {
184 debug("LED ret=%d\n", ret);
185 hang();
186 }
187
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100188 preloader_console_init();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200189#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200190 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100191#endif
192 return;
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100193}