blob: 61d410d780e4ddf26c1383e8baf6732763e3fd5c [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>
Kever Yang0f9e3382019-07-22 20:02:08 +08008#include <syscon.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +08009#include <asm/io.h>
Kever Yang60b270e2019-07-22 19:59:17 +080010#include <asm/arch-rockchip/bootrom.h>
Kever Yang0f9e3382019-07-22 20:02:08 +080011#include <asm/arch-rockchip/clock.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080012#include <asm/arch-rockchip/grf_rk3188.h>
13#include <asm/arch-rockchip/hardware.h>
14
Kever Yang8fd60192019-07-22 19:59:14 +080015#define GRF_BASE 0x20008000
16
Kever Yang60b270e2019-07-22 19:59:17 +080017const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Levin Du27df5072019-10-17 15:22:38 +080018 [BROM_BOOTSOURCE_EMMC] = "/dwmmc@1021c000",
19 [BROM_BOOTSOURCE_SD] = "/dwmmc@10214000",
Kever Yang60b270e2019-07-22 19:59:17 +080020};
21
Kever Yang0a2a5e12019-03-29 09:09:01 +080022#ifdef CONFIG_DEBUG_UART_BOARD_INIT
23void board_debug_uart_init(void)
24{
25 /* Enable early UART on the RK3188 */
Kever Yang0a2a5e12019-03-29 09:09:01 +080026 struct rk3188_grf * const grf = (void *)GRF_BASE;
27 enum {
28 GPIO1B1_SHIFT = 2,
29 GPIO1B1_MASK = 3,
30 GPIO1B1_GPIO = 0,
31 GPIO1B1_UART2_SOUT,
32 GPIO1B1_JTAG_TDO,
33
34 GPIO1B0_SHIFT = 0,
35 GPIO1B0_MASK = 3,
36 GPIO1B0_GPIO = 0,
37 GPIO1B0_UART2_SIN,
38 GPIO1B0_JTAG_TDI,
39 };
40
41 rk_clrsetreg(&grf->gpio1b_iomux,
42 GPIO1B1_MASK << GPIO1B1_SHIFT |
43 GPIO1B0_MASK << GPIO1B0_SHIFT,
44 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
45 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
46}
47#endif
Kever Yang8fd60192019-07-22 19:59:14 +080048
Kever Yang0f9e3382019-07-22 20:02:08 +080049#ifdef CONFIG_SPL_BUILD
Kever Yang8fd60192019-07-22 19:59:14 +080050int arch_cpu_init(void)
51{
Kever Yang0f9e3382019-07-22 20:02:08 +080052 struct rk3188_grf *grf;
Kever Yang8fd60192019-07-22 19:59:14 +080053
Kever Yang0f9e3382019-07-22 20:02:08 +080054 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
55 if (IS_ERR(grf)) {
56 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
57 return 0;
58 }
59#ifdef CONFIG_ROCKCHIP_USB_UART
Kever Yang8fd60192019-07-22 19:59:14 +080060 rk_clrsetreg(&grf->uoc0_con[0],
61 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
62 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
63 1 << COMMON_ON_N_SHIFT);
64 rk_clrsetreg(&grf->uoc0_con[2],
65 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
66 rk_clrsetreg(&grf->uoc0_con[3],
67 OPMODE_MASK | XCVRSELECT_MASK |
68 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
69 OPMODE_NODRIVING << OPMODE_SHIFT |
70 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
71 1 << TERMSEL_FULLSPEED_SHIFT |
72 1 << SUSPENDN_SHIFT);
73 rk_clrsetreg(&grf->uoc0_con[0],
74 BYPASSSEL_MASK | BYPASSDMEN_MASK,
75 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
76#endif
Kever Yang0f9e3382019-07-22 20:02:08 +080077
78 /* enable noc remap to mimic legacy loaders */
79 rk_clrsetreg(&grf->soc_con0,
80 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
81 NOC_REMAP_MASK << NOC_REMAP_SHIFT);
82
Kever Yang8fd60192019-07-22 19:59:14 +080083 return 0;
84}
Kever Yang0f9e3382019-07-22 20:02:08 +080085#endif
Kever Yang96bf25a2019-07-22 19:59:16 +080086
87#ifdef CONFIG_SPL_BUILD
88static int setup_led(void)
89{
90#ifdef CONFIG_SPL_LED
91 struct udevice *dev;
92 char *led_name;
93 int ret;
94
95 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
96 if (!led_name)
97 return 0;
98 ret = led_get_by_label(led_name, &dev);
99 if (ret) {
100 debug("%s: get=%d\n", __func__, ret);
101 return ret;
102 }
103 ret = led_set_on(dev, 1);
104 if (ret)
105 return ret;
106#endif
107
108 return 0;
109}
110
111void spl_board_init(void)
112{
113 int ret;
114
115 ret = setup_led();
116 if (ret) {
117 debug("LED ret=%d\n", ret);
118 hang();
119 }
120}
121#endif