blob: 77b9b36d3577c6e835652dc6217f5d230d02c75e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Stübnerdf9041e2017-02-18 19:46:38 +01002/*
3 * (C) Copyright 2015 Google, Inc
Heiko Stübnerdf9041e2017-02-18 19:46:38 +01004 */
5
Heiko Stübnerf4f57c52017-03-20 12:40:33 +01006#include <clk.h>
Heiko Stübnerdf9041e2017-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 Glassc35f8e52019-01-21 14:53:31 -070015#include <syscon.h>
Heiko Stübnerdf9041e2017-02-18 19:46:38 +010016#include <asm/gpio.h>
17#include <asm/io.h>
Kever Yang15f09a12019-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>
25#include <asm/arch-rockchip/timer.h>
Heiko Stübnerdf9041e2017-02-18 19:46:38 +010026#include <dm/pinctrl.h>
27#include <dm/root.h>
28#include <dm/test.h>
29#include <dm/util.h>
30#include <power/regulator.h>
Heiko Stübnerdf9041e2017-02-18 19:46:38 +010031
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 }
Jean-Jacques Hiblot7ec91812018-08-09 16:17:44 +020053 ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev);
Heiko Stübnerdf9041e2017-02-18 19:46:38 +010054 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übnerf4f57c52017-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
Kever Yang17e5f3a2018-11-29 10:07:38 +080096void board_init_f(ulong dummy)
97{
David Wuc0b163e2019-01-02 20:50:58 +080098 struct udevice *dev;
Kever Yang17e5f3a2018-11-29 10:07:38 +080099 int ret;
100
Kever Yang86d0eca2019-03-29 09:09:01 +0800101#ifdef CONFIG_DEBUG_UART
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100102 /*
103 * Debug UART can be used from here if required:
104 *
105 * debug_uart_init();
106 * printch('a');
107 * printhex8(0x1234);
108 * printascii("string");
109 */
110 debug_uart_init();
David Wuc0b163e2019-01-02 20:50:58 +0800111 printascii("U-Boot SPL board init");
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100112#endif
113
Heiko Stuebner5b5ca4c2018-10-08 13:01:56 +0200114#ifdef CONFIG_ROCKCHIP_USB_UART
115 rk_clrsetreg(&grf->uoc0_con[0],
116 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
117 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
118 1 << COMMON_ON_N_SHIFT);
119 rk_clrsetreg(&grf->uoc0_con[2],
120 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
121 rk_clrsetreg(&grf->uoc0_con[3],
122 OPMODE_MASK | XCVRSELECT_MASK |
123 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
124 OPMODE_NODRIVING << OPMODE_SHIFT |
125 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
126 1 << TERMSEL_FULLSPEED_SHIFT |
127 1 << SUSPENDN_SHIFT);
128 rk_clrsetreg(&grf->uoc0_con[0],
129 BYPASSSEL_MASK | BYPASSDMEN_MASK,
130 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
131#endif
132
Kever Yang232cf962017-03-20 14:47:16 +0800133 ret = spl_early_init();
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100134 if (ret) {
Kever Yang232cf962017-03-20 14:47:16 +0800135 debug("spl_early_init() failed: %d\n", ret);
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100136 hang();
137 }
138
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100139 ret = rockchip_get_clk(&dev);
140 if (ret) {
141 debug("CLK init failed: %d\n", ret);
142 return;
143 }
144
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100145 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
146 if (ret) {
147 debug("DRAM init failed: %d\n", ret);
148 return;
149 }
150
Heiko Stübnerf4f57c52017-03-20 12:40:33 +0100151 setup_arm_clock();
Philipp Tomsichee14d292017-06-29 11:21:15 +0200152#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
Philipp Tomsichb82bd1f2017-10-10 16:21:16 +0200153 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100154#endif
155}
156
157static int setup_led(void)
158{
159#ifdef CONFIG_SPL_LED
160 struct udevice *dev;
161 char *led_name;
162 int ret;
163
164 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
165 if (!led_name)
166 return 0;
167 ret = led_get_by_label(led_name, &dev);
168 if (ret) {
169 debug("%s: get=%d\n", __func__, ret);
170 return ret;
171 }
172 ret = led_set_on(dev, 1);
173 if (ret)
174 return ret;
175#endif
176
177 return 0;
178}
179
180void spl_board_init(void)
181{
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100182 int ret;
183
184 ret = setup_led();
185 if (ret) {
186 debug("LED ret=%d\n", ret);
187 hang();
188 }
189
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100190 preloader_console_init();
Philipp Tomsichee14d292017-06-29 11:21:15 +0200191#if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
Philipp Tomsichb82bd1f2017-10-10 16:21:16 +0200192 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100193#endif
194 return;
Heiko Stübnerdf9041e2017-02-18 19:46:38 +0100195}