blob: 0641e6af0f74b87f4bfa725cc1f5a9139e6cd9e8 [file] [log] [blame]
Heiko Stuebnerfc367852019-07-16 22:18:21 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2017 Rockchip Electronics Co., Ltd
4 */
5#include <common.h>
6#include <clk.h>
7#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Heiko Stuebnerfc367852019-07-16 22:18:21 +02009#include <asm/armv8/mmu.h>
10#include <asm/io.h>
11#include <asm/arch-rockchip/grf_px30.h>
12#include <asm/arch-rockchip/hardware.h>
13#include <asm/arch-rockchip/uart.h>
14#include <asm/arch-rockchip/clock.h>
15#include <asm/arch-rockchip/cru_px30.h>
16#include <dt-bindings/clock/px30-cru.h>
17
18static struct mm_region px30_mem_map[] = {
19 {
20 .virt = 0x0UL,
21 .phys = 0x0UL,
22 .size = 0xff000000UL,
23 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
24 PTE_BLOCK_INNER_SHARE
25 }, {
26 .virt = 0xff000000UL,
27 .phys = 0xff000000UL,
28 .size = 0x01000000UL,
29 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
30 PTE_BLOCK_NON_SHARE |
31 PTE_BLOCK_PXN | PTE_BLOCK_UXN
32 }, {
33 /* List terminator */
34 0,
35 }
36};
37
38struct mm_region *mem_map = px30_mem_map;
39
40#define PMU_PWRDN_CON 0xff000018
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +010041#define PMUGRF_BASE 0xff010000
Heiko Stuebnerfc367852019-07-16 22:18:21 +020042#define GRF_BASE 0xff140000
43#define CRU_BASE 0xff2b0000
Quentin Schulz58751752022-09-15 12:12:47 +020044#define PMUCRU_BASE 0xff2bc000
Heiko Stuebnerfc367852019-07-16 22:18:21 +020045#define VIDEO_PHY_BASE 0xff2e0000
46#define SERVICE_CORE_ADDR 0xff508000
47#define DDR_FW_BASE 0xff534000
48
49#define FW_DDR_CON 0x40
50
51#define QOS_PRIORITY 0x08
52
53#define QOS_PRIORITY_LEVEL(h, l) ((((h) & 3) << 8) | ((l) & 3))
54
Chris Morgan0f412e42021-08-05 16:26:39 +080055/* GRF_GPIO1AL_IOMUX */
56enum {
57 GPIO1A3_SHIFT = 12,
58 GPIO1A3_MASK = 0xf << GPIO1A3_SHIFT,
59 GPIO1A3_GPIO = 0,
60 GPIO1A3_FLASH_D3,
61 GPIO1A3_EMMC_D3,
62 GPIO1A3_SFC_SIO3,
63
64 GPIO1A2_SHIFT = 8,
65 GPIO1A2_MASK = 0xf << GPIO1A2_SHIFT,
66 GPIO1A2_GPIO = 0,
67 GPIO1A2_FLASH_D2,
68 GPIO1A2_EMMC_D2,
69 GPIO1A2_SFC_SIO2,
70
71 GPIO1A1_SHIFT = 4,
72 GPIO1A1_MASK = 0xf << GPIO1A1_SHIFT,
73 GPIO1A1_GPIO = 0,
74 GPIO1A1_FLASH_D1,
75 GPIO1A1_EMMC_D1,
76 GPIO1A1_SFC_SIO1,
77
78 GPIO1A0_SHIFT = 0,
79 GPIO1A0_MASK = 0xf << GPIO1A0_SHIFT,
80 GPIO1A0_GPIO = 0,
81 GPIO1A0_FLASH_D0,
82 GPIO1A0_EMMC_D0,
83 GPIO1A0_SFC_SIO0,
84};
85
86/* GRF_GPIO1AH_IOMUX */
87enum {
88 GPIO1A4_SHIFT = 0,
89 GPIO1A4_MASK = 0xf << GPIO1A4_SHIFT,
90 GPIO1A4_GPIO = 0,
91 GPIO1A4_FLASH_D4,
92 GPIO1A4_EMMC_D4,
93 GPIO1A4_SFC_CSN0,
94};
95
96/* GRF_GPIO1BL_IOMUX */
97enum {
98 GPIO1B1_SHIFT = 4,
99 GPIO1B1_MASK = 0xf << GPIO1B1_SHIFT,
100 GPIO1B1_GPIO = 0,
101 GPIO1B1_FLASH_RDY,
102 GPIO1B1_EMMC_CLKOUT,
103 GPIO1B1_SFC_CLK,
104};
105
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +0100106/* GRF_GPIO1BH_IOMUX */
107enum {
108 GPIO1B7_SHIFT = 12,
109 GPIO1B7_MASK = 0xf << GPIO1B7_SHIFT,
110 GPIO1B7_GPIO = 0,
111 GPIO1B7_FLASH_RDN,
112 GPIO1B7_UART3_RXM1,
113 GPIO1B7_SPI0_CLK,
114
115 GPIO1B6_SHIFT = 8,
116 GPIO1B6_MASK = 0xf << GPIO1B6_SHIFT,
117 GPIO1B6_GPIO = 0,
118 GPIO1B6_FLASH_CS1,
119 GPIO1B6_UART3_TXM1,
120 GPIO1B6_SPI0_CSN,
121};
122
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200123/* GRF_GPIO1CL_IOMUX */
124enum {
125 GPIO1C1_SHIFT = 4,
126 GPIO1C1_MASK = 0xf << GPIO1C1_SHIFT,
127 GPIO1C1_GPIO = 0,
128 GPIO1C1_UART1_TX,
129
130 GPIO1C0_SHIFT = 0,
131 GPIO1C0_MASK = 0xf << GPIO1C0_SHIFT,
132 GPIO1C0_GPIO = 0,
133 GPIO1C0_UART1_RX,
134};
135
136/* GRF_GPIO1DL_IOMUX */
137enum {
138 GPIO1D3_SHIFT = 12,
139 GPIO1D3_MASK = 0xf << GPIO1D3_SHIFT,
140 GPIO1D3_GPIO = 0,
141 GPIO1D3_SDMMC_D1,
142 GPIO1D3_UART2_RXM0,
143
144 GPIO1D2_SHIFT = 8,
145 GPIO1D2_MASK = 0xf << GPIO1D2_SHIFT,
146 GPIO1D2_GPIO = 0,
147 GPIO1D2_SDMMC_D0,
148 GPIO1D2_UART2_TXM0,
149};
150
151/* GRF_GPIO1DH_IOMUX */
152enum {
153 GPIO1D7_SHIFT = 12,
154 GPIO1D7_MASK = 0xf << GPIO1D7_SHIFT,
155 GPIO1D7_GPIO = 0,
156 GPIO1D7_SDMMC_CMD,
157
158 GPIO1D6_SHIFT = 8,
159 GPIO1D6_MASK = 0xf << GPIO1D6_SHIFT,
160 GPIO1D6_GPIO = 0,
161 GPIO1D6_SDMMC_CLK,
162
163 GPIO1D5_SHIFT = 4,
164 GPIO1D5_MASK = 0xf << GPIO1D5_SHIFT,
165 GPIO1D5_GPIO = 0,
166 GPIO1D5_SDMMC_D3,
167
168 GPIO1D4_SHIFT = 0,
169 GPIO1D4_MASK = 0xf << GPIO1D4_SHIFT,
170 GPIO1D4_GPIO = 0,
171 GPIO1D4_SDMMC_D2,
172};
173
174/* GRF_GPIO2BH_IOMUX */
175enum {
176 GPIO2B6_SHIFT = 8,
177 GPIO2B6_MASK = 0xf << GPIO2B6_SHIFT,
178 GPIO2B6_GPIO = 0,
179 GPIO2B6_CIF_D1M0,
180 GPIO2B6_UART2_RXM1,
181
182 GPIO2B4_SHIFT = 0,
183 GPIO2B4_MASK = 0xf << GPIO2B4_SHIFT,
184 GPIO2B4_GPIO = 0,
185 GPIO2B4_CIF_D0M0,
186 GPIO2B4_UART2_TXM1,
187};
188
189/* GRF_GPIO3AL_IOMUX */
190enum {
191 GPIO3A2_SHIFT = 8,
192 GPIO3A2_MASK = 0xf << GPIO3A2_SHIFT,
193 GPIO3A2_GPIO = 0,
194 GPIO3A2_UART5_TX = 4,
195
196 GPIO3A1_SHIFT = 4,
197 GPIO3A1_MASK = 0xf << GPIO3A1_SHIFT,
198 GPIO3A1_GPIO = 0,
199 GPIO3A1_UART5_RX = 4,
200};
201
Quentin Schulz58751752022-09-15 12:12:47 +0200202/* PMUGRF_GPIO0BL_IOMUX */
203enum {
204 GPIO0B3_SHIFT = 6,
205 GPIO0B3_MASK = 0x3 << GPIO0B3_SHIFT,
206 GPIO0B3_GPIO = 0,
207 GPIO0B3_UART0_RX,
208 GPIO0B3_PMU_DEBUG1,
209
210 GPIO0B2_SHIFT = 4,
211 GPIO0B2_MASK = 0x3 << GPIO0B2_SHIFT,
212 GPIO0B2_GPIO = 0,
213 GPIO0B2_UART0_TX,
214 GPIO0B2_PMU_DEBUG0,
215};
216
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +0100217/* PMUGRF_GPIO0CL_IOMUX */
218enum {
219 GPIO0C1_SHIFT = 2,
220 GPIO0C1_MASK = 0x3 << GPIO0C1_SHIFT,
221 GPIO0C1_GPIO = 0,
222 GPIO0C1_PWM_3,
223 GPIO0C1_UART3_RXM0,
224 GPIO0C1_PMU_DEBUG4,
225
226 GPIO0C0_SHIFT = 0,
227 GPIO0C0_MASK = 0x3 << GPIO0C0_SHIFT,
228 GPIO0C0_GPIO = 0,
229 GPIO0C0_PWM_1,
230 GPIO0C0_UART3_TXM0,
231 GPIO0C0_PMU_DEBUG3,
232};
233
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200234int arch_cpu_init(void)
235{
236 static struct px30_grf * const grf = (void *)GRF_BASE;
237 u32 __maybe_unused val;
238
239#ifdef CONFIG_SPL_BUILD
240 /* We do some SoC one time setting here. */
241 /* Disable the ddr secure region setting to make it non-secure */
242 writel(0x0, DDR_FW_BASE + FW_DDR_CON);
243
244 /* Set cpu qos priority */
245 writel(QOS_PRIORITY_LEVEL(1, 1), SERVICE_CORE_ADDR + QOS_PRIORITY);
246
247#if !defined(CONFIG_DEBUG_UART_BOARD_INIT) || \
248 (CONFIG_DEBUG_UART_BASE != 0xff160000) || \
249 (CONFIG_DEBUG_UART_CHANNEL != 0)
250 /* fix sdmmc pinmux if not using uart2-channel0 as debug uart */
251 rk_clrsetreg(&grf->gpio1dl_iomux,
252 GPIO1D3_MASK | GPIO1D2_MASK,
253 GPIO1D3_SDMMC_D1 << GPIO1D3_SHIFT |
254 GPIO1D2_SDMMC_D0 << GPIO1D2_SHIFT);
255 rk_clrsetreg(&grf->gpio1dh_iomux,
256 GPIO1D7_MASK | GPIO1D6_MASK | GPIO1D5_MASK | GPIO1D4_MASK,
257 GPIO1D7_SDMMC_CMD << GPIO1D7_SHIFT |
258 GPIO1D6_SDMMC_CLK << GPIO1D6_SHIFT |
259 GPIO1D5_SDMMC_D3 << GPIO1D5_SHIFT |
260 GPIO1D4_SDMMC_D2 << GPIO1D4_SHIFT);
261#endif
262
Chris Morgan0f412e42021-08-05 16:26:39 +0800263#ifdef CONFIG_ROCKCHIP_SFC
264 rk_clrsetreg(&grf->gpio1al_iomux,
265 GPIO1A3_MASK | GPIO1A2_MASK | GPIO1A1_MASK | GPIO1A0_MASK,
266 GPIO1A3_SFC_SIO3 << GPIO1A3_SHIFT |
267 GPIO1A2_SFC_SIO2 << GPIO1A2_SHIFT |
268 GPIO1A1_SFC_SIO1 << GPIO1A1_SHIFT |
269 GPIO1A0_SFC_SIO0 << GPIO1A0_SHIFT);
270 rk_clrsetreg(&grf->gpio1ah_iomux, GPIO1A4_MASK,
271 GPIO1A4_SFC_CSN0 << GPIO1A4_SHIFT);
272 rk_clrsetreg(&grf->gpio1bl_iomux, GPIO1B1_MASK,
273 GPIO1B1_SFC_CLK << GPIO1B1_SHIFT);
274#endif
275
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200276#endif
277
278 /* Enable PD_VO (default disable at reset) */
279 rk_clrreg(PMU_PWRDN_CON, 1 << 13);
280
281 /* Disable video phy bandgap by default */
282 writel(0x82, VIDEO_PHY_BASE + 0x0000);
283 writel(0x05, VIDEO_PHY_BASE + 0x03ac);
284
285 /* Clear the force_jtag */
286 rk_clrreg(&grf->cpu_con[1], 1 << 7);
287
288 return 0;
289}
290
291#ifdef CONFIG_DEBUG_UART_BOARD_INIT
292void board_debug_uart_init(void)
293{
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +0100294#if defined(CONFIG_DEBUG_UART_BASE) && \
Quentin Schulz58751752022-09-15 12:12:47 +0200295 (((CONFIG_DEBUG_UART_BASE == 0xff168000) && \
296 (CONFIG_DEBUG_UART_CHANNEL != 1)) || \
297 CONFIG_DEBUG_UART_BASE == 0xff030000)
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +0100298 static struct px30_pmugrf * const pmugrf = (void *)PMUGRF_BASE;
299#endif
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200300 static struct px30_grf * const grf = (void *)GRF_BASE;
301 static struct px30_cru * const cru = (void *)CRU_BASE;
Quentin Schulz58751752022-09-15 12:12:47 +0200302#if defined(CONFIG_DEBUG_UART_BASE) && CONFIG_DEBUG_UART_BASE == 0xff030000
303 static struct px30_pmucru * const pmucru = (void *)PMUCRU_BASE;
304#endif
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200305
306#if defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff158000)
307 /* uart_sel_clk default select 24MHz */
308 rk_clrsetreg(&cru->clksel_con[34],
309 UART1_PLL_SEL_MASK | UART1_DIV_CON_MASK,
310 UART1_PLL_SEL_24M << UART1_PLL_SEL_SHIFT | 0);
311 rk_clrsetreg(&cru->clksel_con[35],
312 UART1_CLK_SEL_MASK,
313 UART1_CLK_SEL_UART1 << UART1_CLK_SEL_SHIFT);
314
315 rk_clrsetreg(&grf->gpio1cl_iomux,
316 GPIO1C1_MASK | GPIO1C0_MASK,
317 GPIO1C1_UART1_TX << GPIO1C1_SHIFT |
318 GPIO1C0_UART1_RX << GPIO1C0_SHIFT);
Paul Kocialkowski4a7180d2019-11-28 15:27:52 +0100319#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff168000)
320 /* GRF_IOFUNC_CON0 */
321 enum {
322 CON_IOMUX_UART3SEL_SHIFT = 9,
323 CON_IOMUX_UART3SEL_MASK = 1 << CON_IOMUX_UART3SEL_SHIFT,
324 CON_IOMUX_UART3SEL_M0 = 0,
325 CON_IOMUX_UART3SEL_M1,
326 };
327
328 /* uart_sel_clk default select 24MHz */
329 rk_clrsetreg(&cru->clksel_con[40],
330 UART3_PLL_SEL_MASK | UART3_DIV_CON_MASK,
331 UART3_PLL_SEL_24M << UART3_PLL_SEL_SHIFT | 0);
332 rk_clrsetreg(&cru->clksel_con[41],
333 UART3_CLK_SEL_MASK,
334 UART3_CLK_SEL_UART3 << UART3_CLK_SEL_SHIFT);
335
336#if (CONFIG_DEBUG_UART_CHANNEL == 1)
337 rk_clrsetreg(&grf->iofunc_con0,
338 CON_IOMUX_UART3SEL_MASK,
339 CON_IOMUX_UART3SEL_M1 << CON_IOMUX_UART3SEL_SHIFT);
340
341 rk_clrsetreg(&grf->gpio1bh_iomux,
342 GPIO1B7_MASK | GPIO1B6_MASK,
343 GPIO1B7_UART3_RXM1 << GPIO1B7_SHIFT |
344 GPIO1B6_UART3_TXM1 << GPIO1B6_SHIFT);
345#else
346 rk_clrsetreg(&grf->iofunc_con0,
347 CON_IOMUX_UART3SEL_MASK,
348 CON_IOMUX_UART3SEL_M0 << CON_IOMUX_UART3SEL_SHIFT);
349
350 rk_clrsetreg(&pmugrf->gpio0cl_iomux,
351 GPIO0C1_MASK | GPIO0C0_MASK,
352 GPIO0C1_UART3_RXM0 << GPIO0C1_SHIFT |
353 GPIO0C0_UART3_TXM0 << GPIO0C0_SHIFT);
354#endif /* CONFIG_DEBUG_UART_CHANNEL == 1 */
355
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200356#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff178000)
357 /* uart_sel_clk default select 24MHz */
358 rk_clrsetreg(&cru->clksel_con[46],
359 UART5_PLL_SEL_MASK | UART5_DIV_CON_MASK,
360 UART5_PLL_SEL_24M << UART5_PLL_SEL_SHIFT | 0);
361 rk_clrsetreg(&cru->clksel_con[47],
362 UART5_CLK_SEL_MASK,
363 UART5_CLK_SEL_UART5 << UART5_CLK_SEL_SHIFT);
364
365 rk_clrsetreg(&grf->gpio3al_iomux,
366 GPIO3A2_MASK | GPIO3A1_MASK,
367 GPIO3A2_UART5_TX << GPIO3A2_SHIFT |
368 GPIO3A1_UART5_RX << GPIO3A1_SHIFT);
Quentin Schulz58751752022-09-15 12:12:47 +0200369#elif defined(CONFIG_DEBUG_UART_BASE) && (CONFIG_DEBUG_UART_BASE == 0xff030000)
370 /* uart_sel_clk default select 24MHz */
371 rk_clrsetreg(&pmucru->pmu_clksel_con[3],
372 UART0_PLL_SEL_MASK | UART0_DIV_CON_MASK,
373 UART0_PLL_SEL_24M << UART0_PLL_SEL_SHIFT | 0);
374 rk_clrsetreg(&pmucru->pmu_clksel_con[4],
375 UART0_CLK_SEL_MASK,
376 UART0_CLK_SEL_UART0 << UART0_CLK_SEL_SHIFT);
377
378 rk_clrsetreg(&pmugrf->gpio0bl_iomux,
379 GPIO0B3_MASK | GPIO0B2_MASK,
380 GPIO0B3_UART0_RX << GPIO0B3_SHIFT |
381 GPIO0B2_UART0_TX << GPIO0B2_SHIFT);
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200382#else
383 /* GRF_IOFUNC_CON0 */
384 enum {
385 CON_IOMUX_UART2SEL_SHIFT = 10,
386 CON_IOMUX_UART2SEL_MASK = 3 << CON_IOMUX_UART2SEL_SHIFT,
387 CON_IOMUX_UART2SEL_M0 = 0,
388 CON_IOMUX_UART2SEL_M1,
389 CON_IOMUX_UART2SEL_USBPHY,
390 };
391
392 /* uart_sel_clk default select 24MHz */
393 rk_clrsetreg(&cru->clksel_con[37],
394 UART2_PLL_SEL_MASK | UART2_DIV_CON_MASK,
395 UART2_PLL_SEL_24M << UART2_PLL_SEL_SHIFT | 0);
396 rk_clrsetreg(&cru->clksel_con[38],
397 UART2_CLK_SEL_MASK,
398 UART2_CLK_SEL_UART2 << UART2_CLK_SEL_SHIFT);
399
Paul Kocialkowski7250b232019-11-28 15:27:51 +0100400#if (CONFIG_DEBUG_UART_CHANNEL == 1)
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200401 /* Enable early UART2 */
402 rk_clrsetreg(&grf->iofunc_con0,
403 CON_IOMUX_UART2SEL_MASK,
404 CON_IOMUX_UART2SEL_M1 << CON_IOMUX_UART2SEL_SHIFT);
405
406 rk_clrsetreg(&grf->gpio2bh_iomux,
407 GPIO2B6_MASK | GPIO2B4_MASK,
408 GPIO2B6_UART2_RXM1 << GPIO2B6_SHIFT |
409 GPIO2B4_UART2_TXM1 << GPIO2B4_SHIFT);
410#else
411 rk_clrsetreg(&grf->iofunc_con0,
412 CON_IOMUX_UART2SEL_MASK,
413 CON_IOMUX_UART2SEL_M0 << CON_IOMUX_UART2SEL_SHIFT);
414
415 rk_clrsetreg(&grf->gpio1dl_iomux,
416 GPIO1D3_MASK | GPIO1D2_MASK,
417 GPIO1D3_UART2_RXM0 << GPIO1D3_SHIFT |
418 GPIO1D2_UART2_TXM0 << GPIO1D2_SHIFT);
Paul Kocialkowski7250b232019-11-28 15:27:51 +0100419#endif /* CONFIG_DEBUG_UART_CHANNEL == 1 */
Heiko Stuebnerfc367852019-07-16 22:18:21 +0200420
421#endif /* CONFIG_DEBUG_UART_BASE && CONFIG_DEBUG_UART_BASE == ... */
422}
423#endif /* CONFIG_DEBUG_UART_BOARD_INIT */