blob: c807221f33f153ac153bdbd82b401def565186d8 [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>
Kever Yange2f8ba82020-08-20 17:31:16 +08009#include <led.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Kever Yangc14fe2a2019-07-22 20:02:08 +080011#include <syscon.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080013#include <asm/io.h>
Kever Yang3b3c6232019-07-22 19:59:17 +080014#include <asm/arch-rockchip/bootrom.h>
Kever Yangc14fe2a2019-07-22 20:02:08 +080015#include <asm/arch-rockchip/clock.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080016#include <asm/arch-rockchip/grf_rk3188.h>
17#include <asm/arch-rockchip/hardware.h>
Simon Glass7de8bd02021-08-07 07:24:01 -060018#include <dm/ofnode.h>
Simon Glass61b29b82020-02-03 07:36:15 -070019#include <linux/err.h>
Simon Glass1e94b462023-09-14 18:21:46 -060020#include <linux/printk.h>
Kever Yang86d0eca2019-03-29 09:09:01 +080021
Kever Yang4dd4fc32019-07-22 19:59:14 +080022#define GRF_BASE 0x20008000
23
Kever Yang3b3c6232019-07-22 19:59:17 +080024const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Johan Jonker5859bb22022-04-15 23:21:43 +020025 [BROM_BOOTSOURCE_EMMC] = "/mmc@1021c000",
26 [BROM_BOOTSOURCE_SD] = "/mmc@10214000",
Kever Yang3b3c6232019-07-22 19:59:17 +080027};
28
Kever Yang86d0eca2019-03-29 09:09:01 +080029#ifdef CONFIG_DEBUG_UART_BOARD_INIT
30void board_debug_uart_init(void)
31{
32 /* Enable early UART on the RK3188 */
Kever Yang86d0eca2019-03-29 09:09:01 +080033 struct rk3188_grf * const grf = (void *)GRF_BASE;
34 enum {
35 GPIO1B1_SHIFT = 2,
36 GPIO1B1_MASK = 3,
37 GPIO1B1_GPIO = 0,
38 GPIO1B1_UART2_SOUT,
39 GPIO1B1_JTAG_TDO,
40
41 GPIO1B0_SHIFT = 0,
42 GPIO1B0_MASK = 3,
43 GPIO1B0_GPIO = 0,
44 GPIO1B0_UART2_SIN,
45 GPIO1B0_JTAG_TDI,
46 };
47
48 rk_clrsetreg(&grf->gpio1b_iomux,
49 GPIO1B1_MASK << GPIO1B1_SHIFT |
50 GPIO1B0_MASK << GPIO1B0_SHIFT,
51 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
52 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
53}
54#endif
Kever Yang4dd4fc32019-07-22 19:59:14 +080055
Kever Yangc14fe2a2019-07-22 20:02:08 +080056#ifdef CONFIG_SPL_BUILD
Kever Yang4dd4fc32019-07-22 19:59:14 +080057int arch_cpu_init(void)
58{
Kever Yangc14fe2a2019-07-22 20:02:08 +080059 struct rk3188_grf *grf;
Kever Yang4dd4fc32019-07-22 19:59:14 +080060
Kever Yangc14fe2a2019-07-22 20:02:08 +080061 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
62 if (IS_ERR(grf)) {
63 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
64 return 0;
65 }
66#ifdef CONFIG_ROCKCHIP_USB_UART
Kever Yang4dd4fc32019-07-22 19:59:14 +080067 rk_clrsetreg(&grf->uoc0_con[0],
68 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
69 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
70 1 << COMMON_ON_N_SHIFT);
71 rk_clrsetreg(&grf->uoc0_con[2],
72 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
73 rk_clrsetreg(&grf->uoc0_con[3],
74 OPMODE_MASK | XCVRSELECT_MASK |
75 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
76 OPMODE_NODRIVING << OPMODE_SHIFT |
77 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
78 1 << TERMSEL_FULLSPEED_SHIFT |
79 1 << SUSPENDN_SHIFT);
80 rk_clrsetreg(&grf->uoc0_con[0],
81 BYPASSSEL_MASK | BYPASSDMEN_MASK,
82 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
83#endif
Alexander Kochetkova2b1cff2020-06-22 16:19:25 +030084 return 0;
85}
86#endif
87
88__weak int rk3188_board_late_init(void)
89{
90 return 0;
91}
92
93int rk_board_late_init(void)
94{
95 struct rk3188_grf *grf;
96
97 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
98 if (IS_ERR(grf)) {
99 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
100 return 0;
101 }
Kever Yangc14fe2a2019-07-22 20:02:08 +0800102
103 /* enable noc remap to mimic legacy loaders */
104 rk_clrsetreg(&grf->soc_con0,
105 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
106 NOC_REMAP_MASK << NOC_REMAP_SHIFT);
107
Alexander Kochetkova2b1cff2020-06-22 16:19:25 +0300108 return rk3188_board_late_init();
Kever Yang4dd4fc32019-07-22 19:59:14 +0800109}
Kever Yang9323ffa2019-07-22 19:59:16 +0800110
111#ifdef CONFIG_SPL_BUILD
112static int setup_led(void)
113{
114#ifdef CONFIG_SPL_LED
115 struct udevice *dev;
116 char *led_name;
117 int ret;
118
Simon Glass7de8bd02021-08-07 07:24:01 -0600119 led_name = ofnode_conf_read_str("u-boot,boot-led");
Kever Yang9323ffa2019-07-22 19:59:16 +0800120 if (!led_name)
121 return 0;
122 ret = led_get_by_label(led_name, &dev);
123 if (ret) {
124 debug("%s: get=%d\n", __func__, ret);
125 return ret;
126 }
Kever Yange2f8ba82020-08-20 17:31:16 +0800127 ret = led_set_state(dev, LEDST_ON);
Kever Yang9323ffa2019-07-22 19:59:16 +0800128 if (ret)
129 return ret;
130#endif
131
132 return 0;
133}
134
135void spl_board_init(void)
136{
137 int ret;
138
139 ret = setup_led();
140 if (ret) {
141 debug("LED ret=%d\n", ret);
142 hang();
143 }
144}
145#endif