blob: 222953ab94add37b0d091d3a1bdb0fce15296478 [file] [log] [blame]
Kever Yang0a2a5e12019-03-29 09:09:01 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4 */
5#include <common.h>
Kever Yang0f9e3382019-07-22 20:02:08 +08006#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07007#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Kever Yang2ce12152020-08-20 17:31:16 +08009#include <led.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Kever Yang0f9e3382019-07-22 20:02:08 +080011#include <syscon.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080012#include <asm/io.h>
Kever Yang60b270e2019-07-22 19:59:17 +080013#include <asm/arch-rockchip/bootrom.h>
Kever Yang0f9e3382019-07-22 20:02:08 +080014#include <asm/arch-rockchip/clock.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080015#include <asm/arch-rockchip/grf_rk3188.h>
16#include <asm/arch-rockchip/hardware.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070017#include <linux/err.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080018
Kever Yang8fd60192019-07-22 19:59:14 +080019#define GRF_BASE 0x20008000
20
Kever Yang60b270e2019-07-22 19:59:17 +080021const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Levin Du27df5072019-10-17 15:22:38 +080022 [BROM_BOOTSOURCE_EMMC] = "/dwmmc@1021c000",
23 [BROM_BOOTSOURCE_SD] = "/dwmmc@10214000",
Kever Yang60b270e2019-07-22 19:59:17 +080024};
25
Kever Yang0a2a5e12019-03-29 09:09:01 +080026#ifdef CONFIG_DEBUG_UART_BOARD_INIT
27void board_debug_uart_init(void)
28{
29 /* Enable early UART on the RK3188 */
Kever Yang0a2a5e12019-03-29 09:09:01 +080030 struct rk3188_grf * const grf = (void *)GRF_BASE;
31 enum {
32 GPIO1B1_SHIFT = 2,
33 GPIO1B1_MASK = 3,
34 GPIO1B1_GPIO = 0,
35 GPIO1B1_UART2_SOUT,
36 GPIO1B1_JTAG_TDO,
37
38 GPIO1B0_SHIFT = 0,
39 GPIO1B0_MASK = 3,
40 GPIO1B0_GPIO = 0,
41 GPIO1B0_UART2_SIN,
42 GPIO1B0_JTAG_TDI,
43 };
44
45 rk_clrsetreg(&grf->gpio1b_iomux,
46 GPIO1B1_MASK << GPIO1B1_SHIFT |
47 GPIO1B0_MASK << GPIO1B0_SHIFT,
48 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
49 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
50}
51#endif
Kever Yang8fd60192019-07-22 19:59:14 +080052
Kever Yang0f9e3382019-07-22 20:02:08 +080053#ifdef CONFIG_SPL_BUILD
Kever Yang8fd60192019-07-22 19:59:14 +080054int arch_cpu_init(void)
55{
Kever Yang0f9e3382019-07-22 20:02:08 +080056 struct rk3188_grf *grf;
Kever Yang8fd60192019-07-22 19:59:14 +080057
Kever Yang0f9e3382019-07-22 20:02:08 +080058 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
59 if (IS_ERR(grf)) {
60 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
61 return 0;
62 }
63#ifdef CONFIG_ROCKCHIP_USB_UART
Kever Yang8fd60192019-07-22 19:59:14 +080064 rk_clrsetreg(&grf->uoc0_con[0],
65 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
66 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
67 1 << COMMON_ON_N_SHIFT);
68 rk_clrsetreg(&grf->uoc0_con[2],
69 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
70 rk_clrsetreg(&grf->uoc0_con[3],
71 OPMODE_MASK | XCVRSELECT_MASK |
72 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
73 OPMODE_NODRIVING << OPMODE_SHIFT |
74 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
75 1 << TERMSEL_FULLSPEED_SHIFT |
76 1 << SUSPENDN_SHIFT);
77 rk_clrsetreg(&grf->uoc0_con[0],
78 BYPASSSEL_MASK | BYPASSDMEN_MASK,
79 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
80#endif
Alexander Kochetkov1baa6e22020-06-22 16:19:25 +030081 return 0;
82}
83#endif
84
85__weak int rk3188_board_late_init(void)
86{
87 return 0;
88}
89
90int rk_board_late_init(void)
91{
92 struct rk3188_grf *grf;
93
94 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
95 if (IS_ERR(grf)) {
96 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
97 return 0;
98 }
Kever Yang0f9e3382019-07-22 20:02:08 +080099
100 /* enable noc remap to mimic legacy loaders */
101 rk_clrsetreg(&grf->soc_con0,
102 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
103 NOC_REMAP_MASK << NOC_REMAP_SHIFT);
104
Alexander Kochetkov1baa6e22020-06-22 16:19:25 +0300105 return rk3188_board_late_init();
Kever Yang8fd60192019-07-22 19:59:14 +0800106}
Kever Yang96bf25a2019-07-22 19:59:16 +0800107
108#ifdef CONFIG_SPL_BUILD
Kever Yang2ce12152020-08-20 17:31:16 +0800109DECLARE_GLOBAL_DATA_PTR;
Kever Yang96bf25a2019-07-22 19:59:16 +0800110static int setup_led(void)
111{
112#ifdef CONFIG_SPL_LED
113 struct udevice *dev;
114 char *led_name;
115 int ret;
116
117 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
118 if (!led_name)
119 return 0;
120 ret = led_get_by_label(led_name, &dev);
121 if (ret) {
122 debug("%s: get=%d\n", __func__, ret);
123 return ret;
124 }
Kever Yang2ce12152020-08-20 17:31:16 +0800125 ret = led_set_state(dev, LEDST_ON);
Kever Yang96bf25a2019-07-22 19:59:16 +0800126 if (ret)
127 return ret;
128#endif
129
130 return 0;
131}
132
133void spl_board_init(void)
134{
135 int ret;
136
137 ret = setup_led();
138 if (ret) {
139 debug("LED ret=%d\n", ret);
140 hang();
141 }
142}
143#endif