blob: 6f88638d15698bc7621fd489298ce2f155b6498d [file] [log] [blame]
Andy Yanb5e16302019-11-14 11:21:12 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 *Copyright (c) 2018 Rockchip Electronics Co., Ltd
4 */
Simon Glass97589732020-05-10 11:40:02 -06005#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -07006#include <malloc.h>
John Keeping1cfd0802022-07-14 15:18:37 +01007#include <asm/arch-rockchip/bootrom.h>
Jonas Karlman0333e3b2024-04-08 18:14:11 +00008#include <asm/arch-rockchip/grf_rk3308.h>
Andy Yanb5e16302019-11-14 11:21:12 +08009#include <asm/arch-rockchip/hardware.h>
10#include <asm/gpio.h>
11#include <debug_uart.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
Andy Yanb5e16302019-11-14 11:21:12 +080013
Andy Yanb5e16302019-11-14 11:21:12 +080014#include <asm/armv8/mmu.h>
15static struct mm_region rk3308_mem_map[] = {
16 {
17 .virt = 0x0UL,
18 .phys = 0x0UL,
19 .size = 0xff000000UL,
20 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
21 PTE_BLOCK_INNER_SHARE
22 }, {
23 .virt = 0xff000000UL,
24 .phys = 0xff000000UL,
25 .size = 0x01000000UL,
26 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
27 PTE_BLOCK_NON_SHARE |
28 PTE_BLOCK_PXN | PTE_BLOCK_UXN
29 }, {
30 /* List terminator */
31 0,
32 }
33};
34
35struct mm_region *mem_map = rk3308_mem_map;
36
37#define GRF_BASE 0xff000000
38#define SGRF_BASE 0xff2b0000
39
40enum {
41 GPIO1C7_SHIFT = 8,
42 GPIO1C7_MASK = GENMASK(11, 8),
43 GPIO1C7_GPIO = 0,
44 GPIO1C7_UART1_RTSN,
45 GPIO1C7_UART2_TX_M0,
46 GPIO1C7_SPI2_MOSI,
47 GPIO1C7_JTAG_TMS,
48
49 GPIO1C6_SHIFT = 4,
50 GPIO1C6_MASK = GENMASK(7, 4),
51 GPIO1C6_GPIO = 0,
52 GPIO1C6_UART1_CTSN,
53 GPIO1C6_UART2_RX_M0,
54 GPIO1C6_SPI2_MISO,
55 GPIO1C6_JTAG_TCLK,
56
57 GPIO4D3_SHIFT = 6,
58 GPIO4D3_MASK = GENMASK(7, 6),
59 GPIO4D3_GPIO = 0,
60 GPIO4D3_SDMMC_D3,
61 GPIO4D3_UART2_TX_M1,
62
63 GPIO4D2_SHIFT = 4,
64 GPIO4D2_MASK = GENMASK(5, 4),
65 GPIO4D2_GPIO = 0,
66 GPIO4D2_SDMMC_D2,
67 GPIO4D2_UART2_RX_M1,
68
69 UART2_IO_SEL_SHIFT = 2,
70 UART2_IO_SEL_MASK = GENMASK(3, 2),
71 UART2_IO_SEL_M0 = 0,
72 UART2_IO_SEL_M1,
73 UART2_IO_SEL_USB,
74
David Wu770258b2019-12-03 19:02:50 +080075 GPIO2C0_SEL_SRC_CTRL_SHIFT = 11,
76 GPIO2C0_SEL_SRC_CTRL_MASK = BIT(11),
77 GPIO2C0_SEL_SRC_CTRL_IOMUX = 0,
78 GPIO2C0_SEL_SRC_CTRL_SEL_PLUS,
79
Andy Yanb5e16302019-11-14 11:21:12 +080080 GPIO3B3_SEL_SRC_CTRL_SHIFT = 7,
81 GPIO3B3_SEL_SRC_CTRL_MASK = BIT(7),
82 GPIO3B3_SEL_SRC_CTRL_IOMUX = 0,
83 GPIO3B3_SEL_SRC_CTRL_SEL_PLUS,
84
85 GPIO3B3_SEL_PLUS_SHIFT = 4,
86 GPIO3B3_SEL_PLUS_MASK = GENMASK(6, 4),
87 GPIO3B3_SEL_PLUS_GPIO3_B3 = 0,
88 GPIO3B3_SEL_PLUS_FLASH_ALE,
89 GPIO3B3_SEL_PLUS_EMMC_PWREN,
90 GPIO3B3_SEL_PLUS_SPI1_CLK,
91 GPIO3B3_SEL_PLUS_LCDC_D23_M1,
92
93 GPIO3B2_SEL_SRC_CTRL_SHIFT = 3,
94 GPIO3B2_SEL_SRC_CTRL_MASK = BIT(3),
95 GPIO3B2_SEL_SRC_CTRL_IOMUX = 0,
96 GPIO3B2_SEL_SRC_CTRL_SEL_PLUS,
97
98 GPIO3B2_SEL_PLUS_SHIFT = 0,
99 GPIO3B2_SEL_PLUS_MASK = GENMASK(2, 0),
100 GPIO3B2_SEL_PLUS_GPIO3_B2 = 0,
101 GPIO3B2_SEL_PLUS_FLASH_RDN,
102 GPIO3B2_SEL_PLUS_EMMC_RSTN,
103 GPIO3B2_SEL_PLUS_SPI1_MISO,
104 GPIO3B2_SEL_PLUS_LCDC_D22_M1,
David Wu770258b2019-12-03 19:02:50 +0800105
106 I2C3_IOFUNC_SRC_CTRL_SHIFT = 10,
107 I2C3_IOFUNC_SRC_CTRL_MASK = BIT(10),
108 I2C3_IOFUNC_SRC_CTRL_SEL_PLUS = 1,
109
110 GPIO2A3_SEL_SRC_CTRL_SHIFT = 7,
111 GPIO2A3_SEL_SRC_CTRL_MASK = BIT(7),
112 GPIO2A3_SEL_SRC_CTRL_SEL_PLUS = 1,
113
114 GPIO2A2_SEL_SRC_CTRL_SHIFT = 3,
115 GPIO2A2_SEL_SRC_CTRL_MASK = BIT(3),
116 GPIO2A2_SEL_SRC_CTRL_SEL_PLUS = 1,
Andy Yanb5e16302019-11-14 11:21:12 +0800117};
118
119enum {
120 IOVSEL3_CTRL_SHIFT = 8,
121 IOVSEL3_CTRL_MASK = BIT(8),
122 VCCIO3_SEL_BY_GPIO = 0,
123 VCCIO3_SEL_BY_IOVSEL3,
124
125 IOVSEL3_SHIFT = 3,
126 IOVSEL3_MASK = BIT(3),
127 VCCIO3_3V3 = 0,
128 VCCIO3_1V8,
129};
130
131/*
132 * The voltage of VCCIO3(which is the voltage domain of emmc/flash/sfc
133 * interface) can indicated by GPIO0_A4 or io_vsel3. The SOC defaults
134 * use GPIO0_A4 to indicate power supply voltage for VCCIO3 by hardware,
135 * then we can switch to io_vsel3 after system power on, and release GPIO0_A4
136 * for other usage.
137 */
138
139#define GPIO0_A4 4
140
John Keeping1cfd0802022-07-14 15:18:37 +0100141const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
142 [BROM_BOOTSOURCE_EMMC] = "/mmc@ff490000",
Jonas Karlman746a77e2024-03-22 20:50:22 +0000143 [BROM_BOOTSOURCE_SPINOR] = "/spi@ff4c0000/flash@0",
John Keeping1cfd0802022-07-14 15:18:37 +0100144 [BROM_BOOTSOURCE_SD] = "/mmc@ff480000",
145};
146
Andy Yanb5e16302019-11-14 11:21:12 +0800147int rk_board_init(void)
148{
149 static struct rk3308_grf * const grf = (void *)GRF_BASE;
150 u32 val;
151 int ret;
152
153 ret = gpio_request(GPIO0_A4, "gpio0_a4");
154 if (ret < 0) {
155 printf("request for gpio0_a4 failed:%d\n", ret);
156 return 0;
157 }
158
159 gpio_direction_input(GPIO0_A4);
160
161 if (gpio_get_value(GPIO0_A4))
162 val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT |
163 VCCIO3_1V8 << IOVSEL3_SHIFT;
164 else
165 val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT |
166 VCCIO3_3V3 << IOVSEL3_SHIFT;
167 rk_clrsetreg(&grf->soc_con0, IOVSEL3_CTRL_MASK | IOVSEL3_MASK, val);
168
169 gpio_free(GPIO0_A4);
170 return 0;
171}
172
Pegorer Massimoe54d4fa2023-07-15 10:19:28 +0000173#ifdef CONFIG_DEBUG_UART_BOARD_INIT
Andy Yanb5e16302019-11-14 11:21:12 +0800174__weak void board_debug_uart_init(void)
175{
176 static struct rk3308_grf * const grf = (void *)GRF_BASE;
177
178 /* Enable early UART2 channel m1 on the rk3308 */
179 rk_clrsetreg(&grf->soc_con5, UART2_IO_SEL_MASK,
180 UART2_IO_SEL_M1 << UART2_IO_SEL_SHIFT);
181 rk_clrsetreg(&grf->gpio4d_iomux,
182 GPIO4D3_MASK | GPIO4D2_MASK,
183 GPIO4D2_UART2_RX_M1 << GPIO4D2_SHIFT |
184 GPIO4D3_UART2_TX_M1 << GPIO4D3_SHIFT);
185}
186#endif
187
188#if defined(CONFIG_SPL_BUILD)
189int arch_cpu_init(void)
190{
191 static struct rk3308_sgrf * const sgrf = (void *)SGRF_BASE;
David Wu770258b2019-12-03 19:02:50 +0800192 static struct rk3308_grf * const grf = (void *)GRF_BASE;
Andy Yanb5e16302019-11-14 11:21:12 +0800193
194 /* Set CRYPTO SDMMC EMMC NAND SFC USB master bus to be secure access */
195 rk_clrreg(&sgrf->con_secure0, 0x2b83);
196
David Wu770258b2019-12-03 19:02:50 +0800197 /*
198 * Enable plus options to use more pinctrl functions, including
199 * GPIO2A2_PLUS, GPIO2A3_PLUS and I2C3_MULTI_SRC_PLUS.
200 */
201 rk_clrsetreg(&grf->soc_con13,
202 I2C3_IOFUNC_SRC_CTRL_MASK | GPIO2A3_SEL_SRC_CTRL_MASK |
203 GPIO2A2_SEL_SRC_CTRL_MASK,
204 I2C3_IOFUNC_SRC_CTRL_SEL_PLUS << I2C3_IOFUNC_SRC_CTRL_SHIFT |
205 GPIO2A3_SEL_SRC_CTRL_SEL_PLUS << GPIO2A3_SEL_SRC_CTRL_SHIFT |
206 GPIO2A2_SEL_SRC_CTRL_SEL_PLUS << GPIO2A2_SEL_SRC_CTRL_SHIFT);
207
208 /* Plus options about GPIO3B2_PLUS, GPIO3B3_PLUS and GPIO2C0_PLUS. */
209 rk_clrsetreg(&grf->soc_con15,
210 GPIO2C0_SEL_SRC_CTRL_MASK | GPIO3B3_SEL_SRC_CTRL_MASK |
211 GPIO3B2_SEL_SRC_CTRL_MASK,
212 GPIO2C0_SEL_SRC_CTRL_SEL_PLUS << GPIO2C0_SEL_SRC_CTRL_SHIFT |
213 GPIO3B3_SEL_SRC_CTRL_SEL_PLUS << GPIO3B3_SEL_SRC_CTRL_SHIFT |
214 GPIO3B2_SEL_SRC_CTRL_SEL_PLUS << GPIO3B2_SEL_SRC_CTRL_SHIFT);
215
Andy Yanb5e16302019-11-14 11:21:12 +0800216 return 0;
217}
218#endif