blob: ef57dfd7619f691aa621c72fc8c3599b69eaccbb [file] [log] [blame]
Kever Yang86d0eca2019-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 Yangc14fe2a2019-07-22 20:02:08 +08006#include <dm.h>
Simon Glassdb41d652019-12-28 10:45:07 -07007#include <hang.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Kever Yangc14fe2a2019-07-22 20:02:08 +080010#include <syscon.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080011#include <asm/io.h>
Kever Yang3b3c6232019-07-22 19:59:17 +080012#include <asm/arch-rockchip/bootrom.h>
Kever Yangc14fe2a2019-07-22 20:02:08 +080013#include <asm/arch-rockchip/clock.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080014#include <asm/arch-rockchip/grf_rk3188.h>
15#include <asm/arch-rockchip/hardware.h>
Simon Glass61b29b82020-02-03 07:36:15 -070016#include <linux/err.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080017
Kever Yang4dd4fc32019-07-22 19:59:14 +080018#define GRF_BASE 0x20008000
19
Kever Yang3b3c6232019-07-22 19:59:17 +080020const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Levin Du2d86ab52019-10-17 15:22:38 +080021 [BROM_BOOTSOURCE_EMMC] = "/dwmmc@1021c000",
22 [BROM_BOOTSOURCE_SD] = "/dwmmc@10214000",
Kever Yang3b3c6232019-07-22 19:59:17 +080023};
24
Kever Yang86d0eca2019-03-29 09:09:01 +080025#ifdef CONFIG_DEBUG_UART_BOARD_INIT
26void board_debug_uart_init(void)
27{
28 /* Enable early UART on the RK3188 */
Kever Yang86d0eca2019-03-29 09:09:01 +080029 struct rk3188_grf * const grf = (void *)GRF_BASE;
30 enum {
31 GPIO1B1_SHIFT = 2,
32 GPIO1B1_MASK = 3,
33 GPIO1B1_GPIO = 0,
34 GPIO1B1_UART2_SOUT,
35 GPIO1B1_JTAG_TDO,
36
37 GPIO1B0_SHIFT = 0,
38 GPIO1B0_MASK = 3,
39 GPIO1B0_GPIO = 0,
40 GPIO1B0_UART2_SIN,
41 GPIO1B0_JTAG_TDI,
42 };
43
44 rk_clrsetreg(&grf->gpio1b_iomux,
45 GPIO1B1_MASK << GPIO1B1_SHIFT |
46 GPIO1B0_MASK << GPIO1B0_SHIFT,
47 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
48 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
49}
50#endif
Kever Yang4dd4fc32019-07-22 19:59:14 +080051
Kever Yangc14fe2a2019-07-22 20:02:08 +080052#ifdef CONFIG_SPL_BUILD
Kever Yang4dd4fc32019-07-22 19:59:14 +080053int arch_cpu_init(void)
54{
Kever Yangc14fe2a2019-07-22 20:02:08 +080055 struct rk3188_grf *grf;
Kever Yang4dd4fc32019-07-22 19:59:14 +080056
Kever Yangc14fe2a2019-07-22 20:02:08 +080057 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
58 if (IS_ERR(grf)) {
59 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
60 return 0;
61 }
62#ifdef CONFIG_ROCKCHIP_USB_UART
Kever Yang4dd4fc32019-07-22 19:59:14 +080063 rk_clrsetreg(&grf->uoc0_con[0],
64 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
65 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
66 1 << COMMON_ON_N_SHIFT);
67 rk_clrsetreg(&grf->uoc0_con[2],
68 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
69 rk_clrsetreg(&grf->uoc0_con[3],
70 OPMODE_MASK | XCVRSELECT_MASK |
71 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
72 OPMODE_NODRIVING << OPMODE_SHIFT |
73 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
74 1 << TERMSEL_FULLSPEED_SHIFT |
75 1 << SUSPENDN_SHIFT);
76 rk_clrsetreg(&grf->uoc0_con[0],
77 BYPASSSEL_MASK | BYPASSDMEN_MASK,
78 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
79#endif
Kever Yangc14fe2a2019-07-22 20:02:08 +080080
81 /* enable noc remap to mimic legacy loaders */
82 rk_clrsetreg(&grf->soc_con0,
83 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
84 NOC_REMAP_MASK << NOC_REMAP_SHIFT);
85
Kever Yang4dd4fc32019-07-22 19:59:14 +080086 return 0;
87}
Kever Yangc14fe2a2019-07-22 20:02:08 +080088#endif
Kever Yang9323ffa2019-07-22 19:59:16 +080089
90#ifdef CONFIG_SPL_BUILD
91static int setup_led(void)
92{
93#ifdef CONFIG_SPL_LED
94 struct udevice *dev;
95 char *led_name;
96 int ret;
97
98 led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
99 if (!led_name)
100 return 0;
101 ret = led_get_by_label(led_name, &dev);
102 if (ret) {
103 debug("%s: get=%d\n", __func__, ret);
104 return ret;
105 }
106 ret = led_set_on(dev, 1);
107 if (ret)
108 return ret;
109#endif
110
111 return 0;
112}
113
114void spl_board_init(void)
115{
116 int ret;
117
118 ret = setup_led();
119 if (ret) {
120 debug("LED ret=%d\n", ret);
121 hang();
122 }
123}
124#endif