1 // SPDX-License-Identifier: GPL-2.0+
3 *Copyright (c) 2018 Rockchip Electronics Co., Ltd
7 #include <asm/arch/grf_rk3308.h>
8 #include <asm/arch-rockchip/hardware.h>
10 #include <debug_uart.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 #include <asm/armv8/mmu.h>
15 static struct mm_region rk3308_mem_map[] = {
20 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
26 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
28 PTE_BLOCK_PXN | PTE_BLOCK_UXN
35 struct mm_region *mem_map = rk3308_mem_map;
37 #define GRF_BASE 0xff000000
38 #define SGRF_BASE 0xff2b0000
42 GPIO1C7_MASK = GENMASK(11, 8),
50 GPIO1C6_MASK = GENMASK(7, 4),
58 GPIO4D3_MASK = GENMASK(7, 6),
64 GPIO4D2_MASK = GENMASK(5, 4),
69 UART2_IO_SEL_SHIFT = 2,
70 UART2_IO_SEL_MASK = GENMASK(3, 2),
75 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,
80 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,
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,
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,
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,
106 I2C3_IOFUNC_SRC_CTRL_SHIFT = 10,
107 I2C3_IOFUNC_SRC_CTRL_MASK = BIT(10),
108 I2C3_IOFUNC_SRC_CTRL_SEL_PLUS = 1,
110 GPIO2A3_SEL_SRC_CTRL_SHIFT = 7,
111 GPIO2A3_SEL_SRC_CTRL_MASK = BIT(7),
112 GPIO2A3_SEL_SRC_CTRL_SEL_PLUS = 1,
114 GPIO2A2_SEL_SRC_CTRL_SHIFT = 3,
115 GPIO2A2_SEL_SRC_CTRL_MASK = BIT(3),
116 GPIO2A2_SEL_SRC_CTRL_SEL_PLUS = 1,
120 IOVSEL3_CTRL_SHIFT = 8,
121 IOVSEL3_CTRL_MASK = BIT(8),
122 VCCIO3_SEL_BY_GPIO = 0,
123 VCCIO3_SEL_BY_IOVSEL3,
126 IOVSEL3_MASK = BIT(3),
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
141 int rk_board_init(void)
143 static struct rk3308_grf * const grf = (void *)GRF_BASE;
147 ret = gpio_request(GPIO0_A4, "gpio0_a4");
149 printf("request for gpio0_a4 failed:%d\n", ret);
153 gpio_direction_input(GPIO0_A4);
155 if (gpio_get_value(GPIO0_A4))
156 val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT |
157 VCCIO3_1V8 << IOVSEL3_SHIFT;
159 val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT |
160 VCCIO3_3V3 << IOVSEL3_SHIFT;
161 rk_clrsetreg(&grf->soc_con0, IOVSEL3_CTRL_MASK | IOVSEL3_MASK, val);
167 #if defined(CONFIG_DEBUG_UART)
168 __weak void board_debug_uart_init(void)
170 static struct rk3308_grf * const grf = (void *)GRF_BASE;
172 /* Enable early UART2 channel m1 on the rk3308 */
173 rk_clrsetreg(&grf->soc_con5, UART2_IO_SEL_MASK,
174 UART2_IO_SEL_M1 << UART2_IO_SEL_SHIFT);
175 rk_clrsetreg(&grf->gpio4d_iomux,
176 GPIO4D3_MASK | GPIO4D2_MASK,
177 GPIO4D2_UART2_RX_M1 << GPIO4D2_SHIFT |
178 GPIO4D3_UART2_TX_M1 << GPIO4D3_SHIFT);
182 #if defined(CONFIG_SPL_BUILD)
183 int arch_cpu_init(void)
185 static struct rk3308_sgrf * const sgrf = (void *)SGRF_BASE;
186 static struct rk3308_grf * const grf = (void *)GRF_BASE;
188 /* Set CRYPTO SDMMC EMMC NAND SFC USB master bus to be secure access */
189 rk_clrreg(&sgrf->con_secure0, 0x2b83);
192 * Enable plus options to use more pinctrl functions, including
193 * GPIO2A2_PLUS, GPIO2A3_PLUS and I2C3_MULTI_SRC_PLUS.
195 rk_clrsetreg(&grf->soc_con13,
196 I2C3_IOFUNC_SRC_CTRL_MASK | GPIO2A3_SEL_SRC_CTRL_MASK |
197 GPIO2A2_SEL_SRC_CTRL_MASK,
198 I2C3_IOFUNC_SRC_CTRL_SEL_PLUS << I2C3_IOFUNC_SRC_CTRL_SHIFT |
199 GPIO2A3_SEL_SRC_CTRL_SEL_PLUS << GPIO2A3_SEL_SRC_CTRL_SHIFT |
200 GPIO2A2_SEL_SRC_CTRL_SEL_PLUS << GPIO2A2_SEL_SRC_CTRL_SHIFT);
202 /* Plus options about GPIO3B2_PLUS, GPIO3B3_PLUS and GPIO2C0_PLUS. */
203 rk_clrsetreg(&grf->soc_con15,
204 GPIO2C0_SEL_SRC_CTRL_MASK | GPIO3B3_SEL_SRC_CTRL_MASK |
205 GPIO3B2_SEL_SRC_CTRL_MASK,
206 GPIO2C0_SEL_SRC_CTRL_SEL_PLUS << GPIO2C0_SEL_SRC_CTRL_SHIFT |
207 GPIO3B3_SEL_SRC_CTRL_SEL_PLUS << GPIO3B3_SEL_SRC_CTRL_SHIFT |
208 GPIO3B2_SEL_SRC_CTRL_SEL_PLUS << GPIO3B2_SEL_SRC_CTRL_SHIFT);