blob: 5a02914e1b0dcd23f95c50da1886cc1abafed6d9 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080013#include <asm/io.h>
Kever Yang60b270e2019-07-22 19:59:17 +080014#include <asm/arch-rockchip/bootrom.h>
Kever Yang0f9e3382019-07-22 20:02:08 +080015#include <asm/arch-rockchip/clock.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080016#include <asm/arch-rockchip/grf_rk3188.h>
17#include <asm/arch-rockchip/hardware.h>
Simon Glass0034d962021-08-07 07:24:01 -060018#include <dm/ofnode.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070019#include <linux/err.h>
Kever Yang0a2a5e12019-03-29 09:09:01 +080020
Kever Yang8fd60192019-07-22 19:59:14 +080021#define GRF_BASE 0x20008000
22
Kever Yang60b270e2019-07-22 19:59:17 +080023const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
Levin Du27df5072019-10-17 15:22:38 +080024 [BROM_BOOTSOURCE_EMMC] = "/dwmmc@1021c000",
25 [BROM_BOOTSOURCE_SD] = "/dwmmc@10214000",
Kever Yang60b270e2019-07-22 19:59:17 +080026};
27
Kever Yang0a2a5e12019-03-29 09:09:01 +080028#ifdef CONFIG_DEBUG_UART_BOARD_INIT
29void board_debug_uart_init(void)
30{
31 /* Enable early UART on the RK3188 */
Kever Yang0a2a5e12019-03-29 09:09:01 +080032 struct rk3188_grf * const grf = (void *)GRF_BASE;
33 enum {
34 GPIO1B1_SHIFT = 2,
35 GPIO1B1_MASK = 3,
36 GPIO1B1_GPIO = 0,
37 GPIO1B1_UART2_SOUT,
38 GPIO1B1_JTAG_TDO,
39
40 GPIO1B0_SHIFT = 0,
41 GPIO1B0_MASK = 3,
42 GPIO1B0_GPIO = 0,
43 GPIO1B0_UART2_SIN,
44 GPIO1B0_JTAG_TDI,
45 };
46
47 rk_clrsetreg(&grf->gpio1b_iomux,
48 GPIO1B1_MASK << GPIO1B1_SHIFT |
49 GPIO1B0_MASK << GPIO1B0_SHIFT,
50 GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
51 GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
52}
53#endif
Kever Yang8fd60192019-07-22 19:59:14 +080054
Kever Yang0f9e3382019-07-22 20:02:08 +080055#ifdef CONFIG_SPL_BUILD
Kever Yang8fd60192019-07-22 19:59:14 +080056int arch_cpu_init(void)
57{
Kever Yang0f9e3382019-07-22 20:02:08 +080058 struct rk3188_grf *grf;
Kever Yang8fd60192019-07-22 19:59:14 +080059
Kever Yang0f9e3382019-07-22 20:02:08 +080060 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
61 if (IS_ERR(grf)) {
62 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
63 return 0;
64 }
65#ifdef CONFIG_ROCKCHIP_USB_UART
Kever Yang8fd60192019-07-22 19:59:14 +080066 rk_clrsetreg(&grf->uoc0_con[0],
67 SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK,
68 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT |
69 1 << COMMON_ON_N_SHIFT);
70 rk_clrsetreg(&grf->uoc0_con[2],
71 SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT);
72 rk_clrsetreg(&grf->uoc0_con[3],
73 OPMODE_MASK | XCVRSELECT_MASK |
74 TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK,
75 OPMODE_NODRIVING << OPMODE_SHIFT |
76 XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT |
77 1 << TERMSEL_FULLSPEED_SHIFT |
78 1 << SUSPENDN_SHIFT);
79 rk_clrsetreg(&grf->uoc0_con[0],
80 BYPASSSEL_MASK | BYPASSDMEN_MASK,
81 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT);
82#endif
Alexander Kochetkov1baa6e22020-06-22 16:19:25 +030083 return 0;
84}
85#endif
86
87__weak int rk3188_board_late_init(void)
88{
89 return 0;
90}
91
92int rk_board_late_init(void)
93{
94 struct rk3188_grf *grf;
95
96 grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
97 if (IS_ERR(grf)) {
98 pr_err("grf syscon returned %ld\n", PTR_ERR(grf));
99 return 0;
100 }
Kever Yang0f9e3382019-07-22 20:02:08 +0800101
102 /* enable noc remap to mimic legacy loaders */
103 rk_clrsetreg(&grf->soc_con0,
104 NOC_REMAP_MASK << NOC_REMAP_SHIFT,
105 NOC_REMAP_MASK << NOC_REMAP_SHIFT);
106
Alexander Kochetkov1baa6e22020-06-22 16:19:25 +0300107 return rk3188_board_late_init();
Kever Yang8fd60192019-07-22 19:59:14 +0800108}
Kever Yang96bf25a2019-07-22 19:59:16 +0800109
110#ifdef CONFIG_SPL_BUILD
111static int setup_led(void)
112{
113#ifdef CONFIG_SPL_LED
114 struct udevice *dev;
115 char *led_name;
116 int ret;
117
Simon Glass0034d962021-08-07 07:24:01 -0600118 led_name = ofnode_conf_read_str("u-boot,boot-led");
Kever Yang96bf25a2019-07-22 19:59:16 +0800119 if (!led_name)
120 return 0;
121 ret = led_get_by_label(led_name, &dev);
122 if (ret) {
123 debug("%s: get=%d\n", __func__, ret);
124 return ret;
125 }
Kever Yang2ce12152020-08-20 17:31:16 +0800126 ret = led_set_state(dev, LEDST_ON);
Kever Yang96bf25a2019-07-22 19:59:16 +0800127 if (ret)
128 return ret;
129#endif
130
131 return 0;
132}
133
134void spl_board_init(void)
135{
136 int ret;
137
138 ret = setup_led();
139 if (ret) {
140 debug("LED ret=%d\n", ret);
141 hang();
142 }
143}
144#endif