blob: 74771d3a0b04f33a08d2d4c46f20d115c589ec70 [file] [log] [blame]
Heiko Stübner0b3c26a2017-02-18 19:46:38 +01001/*
2 * (C) Copyright 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
Heiko Stübnerba188bb2017-03-20 12:40:33 +01007#include <clk.h>
Heiko Stübner0b3c26a2017-02-18 19:46:38 +01008#include <common.h>
9#include <debug_uart.h>
10#include <dm.h>
11#include <fdtdec.h>
12#include <led.h>
13#include <malloc.h>
14#include <ram.h>
15#include <spl.h>
16#include <asm/gpio.h>
17#include <asm/io.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_rk3188.h>
23#include <asm/arch/sdram.h>
24#include <asm/arch/timer.h>
25#include <dm/pinctrl.h>
26#include <dm/root.h>
27#include <dm/test.h>
28#include <dm/util.h>
29#include <power/regulator.h>
30#include <syscon.h>
31
32DECLARE_GLOBAL_DATA_PTR;
33
34u32 spl_boot_device(void)
35{
36#if !CONFIG_IS_ENABLED(OF_PLATDATA)
37 const void *blob = gd->fdt_blob;
38 struct udevice *dev;
39 const char *bootdev;
40 int node;
41 int ret;
42
43 bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
44 debug("Boot device %s\n", bootdev);
45 if (!bootdev)
46 goto fallback;
47
48 node = fdt_path_offset(blob, bootdev);
49 if (node < 0) {
50 debug("node=%d\n", node);
51 goto fallback;
52 }
53 ret = device_get_global_by_of_offset(node, &dev);
54 if (ret) {
55 debug("device at node %s/%d not found: %d\n", bootdev, node,
56 ret);
57 goto fallback;
58 }
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;
63 case UCLASS_MMC:
64 return BOOT_DEVICE_MMC1;
65 default:
66 debug("Booting from device uclass '%s' not supported\n",
67 dev_get_uclass_name(dev));
68 }
69
70fallback:
71#endif
72 return BOOT_DEVICE_MMC1;
73}
74
Heiko Stübnerba188bb2017-03-20 12:40:33 +010075static int setup_arm_clock(void)
76{
77 struct udevice *dev;
78 struct clk clk;
79 int ret;
80
81 ret = rockchip_get_clk(&dev);
82 if (ret)
83 return ret;
84
85 clk.id = CLK_ARM;
86 ret = clk_request(dev, &clk);
87 if (ret < 0)
88 return ret;
89
90 ret = clk_set_rate(&clk, 600000000);
91
92 clk_free(&clk);
93 return ret;
94}
95
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010096void board_init_f(ulong dummy)
97{
98 struct udevice *pinctrl, *dev;
Heiko Stübner0b3c26a2017-02-18 19:46:38 +010099 int ret;
100
101 /* Example code showing how to enable the debug UART on RK3188 */
102#ifdef EARLY_UART
103#include <asm/arch/grf_rk3188.h>
104 /* Enable early UART on the RK3188 */
105#define GRF_BASE 0x20008000
106 struct rk3188_grf * const grf = (void *)GRF_BASE;
107
108 rk_clrsetreg(&grf->gpio1b_iomux,
109 GPIO1B1_MASK << GPIO1B1_SHIFT |
110 GPIO1B0_MASK << GPIO1B0_SHIFT,
111 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
112 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
113 /*
114 * Debug UART can be used from here if required:
115 *
116 * debug_uart_init();
117 * printch('a');
118 * printhex8(0x1234);
119 * printascii("string");
120 */
121 debug_uart_init();
122 printch('s');
123 printch('p');
124 printch('l');
125 printch('\n');
126#endif
127
Kever Yange603a3d2017-03-20 14:47:16 +0800128 ret = spl_early_init();
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100129 if (ret) {
Kever Yange603a3d2017-03-20 14:47:16 +0800130 debug("spl_early_init() failed: %d\n", ret);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100131 hang();
132 }
133
134 rockchip_timer_init();
135
136 ret = rockchip_get_clk(&dev);
137 if (ret) {
138 debug("CLK init failed: %d\n", ret);
139 return;
140 }
141
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100142 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
143 if (ret) {
144 debug("Pinctrl init failed: %d\n", ret);
145 return;
146 }
147
148 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
149 if (ret) {
150 debug("DRAM init failed: %d\n", ret);
151 return;
152 }
153
Heiko Stübnerba188bb2017-03-20 12:40:33 +0100154 setup_arm_clock();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200155#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200156 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100157#endif
158}
159
160static int setup_led(void)
161{
162#ifdef CONFIG_SPL_LED
163 struct udevice *dev;
164 char *led_name;
165 int ret;
166
167 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
168 if (!led_name)
169 return 0;
170 ret = led_get_by_label(led_name, &dev);
171 if (ret) {
172 debug("%s: get=%d\n", __func__, ret);
173 return ret;
174 }
175 ret = led_set_on(dev, 1);
176 if (ret)
177 return ret;
178#endif
179
180 return 0;
181}
182
183void spl_board_init(void)
184{
185 struct udevice *pinctrl;
186 int ret;
187
188 ret = setup_led();
189 if (ret) {
190 debug("LED ret=%d\n", ret);
191 hang();
192 }
193
194 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
195 if (ret) {
196 debug("%s: Cannot find pinctrl device\n", __func__);
197 goto err;
198 }
199
200#ifdef CONFIG_SPL_MMC_SUPPORT
201 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
202 if (ret) {
203 debug("%s: Failed to set up SD card\n", __func__);
204 goto err;
205 }
206#endif
207
208 /* Enable debug UART */
209 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
210 if (ret) {
211 debug("%s: Failed to set up console UART\n", __func__);
212 goto err;
213 }
214
215 preloader_console_init();
Philipp Tomsich798370f2017-06-29 11:21:15 +0200216#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
Philipp Tomsich7234c732017-10-10 16:21:16 +0200217 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübner0b3c26a2017-02-18 19:46:38 +0100218#endif
219 return;
220
221err:
222 printf("spl_board_init: Error %d\n", ret);
223
224 /* No way to report error here */
225 hang();
226}