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