blob: d3162d3447e03d69851a9904c889e0793a802a7c [file] [log] [blame]
Jagan Teki8967dea2023-01-30 20:27:45 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2021 Rockchip Electronics Co., Ltd
4 * Copyright (c) 2022 Edgeble AI Technologies Pvt. Ltd.
5 */
6
Jagan Teki8967dea2023-01-30 20:27:45 +05307#include <spl.h>
8#include <asm/armv8/mmu.h>
Jonas Karlmanafe8635f2023-03-14 00:38:30 +00009#include <asm/arch-rockchip/bootrom.h>
Quentin Schulz95b568f2024-03-11 13:01:54 +010010#include <asm/arch-rockchip/grf_rk3588.h>
Jagan Teki8967dea2023-01-30 20:27:45 +053011#include <asm/arch-rockchip/hardware.h>
12#include <asm/arch-rockchip/ioc_rk3588.h>
13
Jagan Teki8967dea2023-01-30 20:27:45 +053014#define FIREWALL_DDR_BASE 0xfe030000
15#define FW_DDR_MST5_REG 0x54
16#define FW_DDR_MST13_REG 0x74
17#define FW_DDR_MST21_REG 0x94
18#define FW_DDR_MST26_REG 0xa8
19#define FW_DDR_MST27_REG 0xac
20#define FIREWALL_SYSMEM_BASE 0xfe038000
21#define FW_SYSM_MST5_REG 0x54
22#define FW_SYSM_MST13_REG 0x74
23#define FW_SYSM_MST21_REG 0x94
24#define FW_SYSM_MST26_REG 0xa8
25#define FW_SYSM_MST27_REG 0xac
26
Jagan Teki8967dea2023-01-30 20:27:45 +053027#define BUS_IOC_GPIO2A_IOMUX_SEL_L 0x40
28#define BUS_IOC_GPIO2B_IOMUX_SEL_L 0x48
29#define BUS_IOC_GPIO2D_IOMUX_SEL_L 0x58
30#define BUS_IOC_GPIO2D_IOMUX_SEL_H 0x5c
31#define BUS_IOC_GPIO3A_IOMUX_SEL_L 0x60
32
Quentin Schulz95b568f2024-03-11 13:01:54 +010033#define SYS_GRF_FORCE_JTAG BIT(14)
34
Jonas Karlmana1b1fd12023-11-17 23:24:34 +000035/**
36 * Boot-device identifiers used by the BROM on RK3588 when device is booted
37 * from SPI flash. IOMUX used for SPI flash affect the value used by the BROM
38 * and not the type of SPI flash used.
39 */
40enum {
41 BROM_BOOTSOURCE_FSPI_M0 = 3,
42 BROM_BOOTSOURCE_FSPI_M1 = 4,
43 BROM_BOOTSOURCE_FSPI_M2 = 6,
44};
45
Jonas Karlmanafe8635f2023-03-14 00:38:30 +000046const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
47 [BROM_BOOTSOURCE_EMMC] = "/mmc@fe2e0000",
Jonas Karlmana1b1fd12023-11-17 23:24:34 +000048 [BROM_BOOTSOURCE_FSPI_M0] = "/spi@fe2b0000/flash@0",
49 [BROM_BOOTSOURCE_FSPI_M1] = "/spi@fe2b0000/flash@0",
50 [BROM_BOOTSOURCE_FSPI_M2] = "/spi@fe2b0000/flash@0",
Jonas Karlmanafe8635f2023-03-14 00:38:30 +000051 [BROM_BOOTSOURCE_SD] = "/mmc@fe2c0000",
52};
53
Jagan Teki8967dea2023-01-30 20:27:45 +053054static struct mm_region rk3588_mem_map[] = {
55 {
56 .virt = 0x0UL,
57 .phys = 0x0UL,
58 .size = 0xf0000000UL,
59 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
60 PTE_BLOCK_INNER_SHARE
61 }, {
62 .virt = 0xf0000000UL,
63 .phys = 0xf0000000UL,
64 .size = 0x10000000UL,
65 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
66 PTE_BLOCK_NON_SHARE |
67 PTE_BLOCK_PXN | PTE_BLOCK_UXN
68 }, {
69 .virt = 0x900000000,
70 .phys = 0x900000000,
71 .size = 0x150000000,
72 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
73 PTE_BLOCK_NON_SHARE |
74 PTE_BLOCK_PXN | PTE_BLOCK_UXN
75 }, {
76 /* List terminator */
77 0,
78 }
79};
80
81struct mm_region *mem_map = rk3588_mem_map;
82
83/* GPIO0B_IOMUX_SEL_H */
84enum {
85 GPIO0B5_SHIFT = 4,
86 GPIO0B5_MASK = GENMASK(7, 4),
87 GPIO0B5_REFER = 8,
88 GPIO0B5_UART2_TX_M0 = 10,
89
90 GPIO0B6_SHIFT = 8,
91 GPIO0B6_MASK = GENMASK(11, 8),
92 GPIO0B6_REFER = 8,
93 GPIO0B6_UART2_RX_M0 = 10,
94};
95
96void board_debug_uart_init(void)
97{
98 __maybe_unused static struct rk3588_bus_ioc * const bus_ioc = (void *)BUS_IOC_BASE;
99 static struct rk3588_pmu2_ioc * const pmu2_ioc = (void *)PMU2_IOC_BASE;
100
101 /* Refer to BUS_IOC */
102 rk_clrsetreg(&pmu2_ioc->gpio0b_iomux_sel_h,
103 GPIO0B6_MASK | GPIO0B5_MASK,
104 GPIO0B6_REFER << GPIO0B6_SHIFT |
105 GPIO0B5_REFER << GPIO0B5_SHIFT);
106
107 /* UART2_M0 Switch iomux */
108 rk_clrsetreg(&bus_ioc->gpio0b_iomux_sel_h,
109 GPIO0B6_MASK | GPIO0B5_MASK,
110 GPIO0B6_UART2_RX_M0 << GPIO0B6_SHIFT |
111 GPIO0B5_UART2_TX_M0 << GPIO0B5_SHIFT);
112}
113
114#ifdef CONFIG_SPL_BUILD
115void rockchip_stimer_init(void)
116{
117 /* If Timer already enabled, don't re-init it */
118 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + 0x4);
119
120 if (reg & 0x1)
121 return;
122
123 asm volatile("msr CNTFRQ_EL0, %0" : : "r" (CONFIG_COUNTER_FREQUENCY));
124 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 0x14);
125 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 0x18);
126 writel(0x1, CONFIG_ROCKCHIP_STIMER_BASE + 0x4);
127}
128#endif
129
130#ifndef CONFIG_TPL_BUILD
131int arch_cpu_init(void)
132{
133#ifdef CONFIG_SPL_BUILD
Quentin Schulz95b568f2024-03-11 13:01:54 +0100134#ifdef CONFIG_ROCKCHIP_DISABLE_FORCE_JTAG
135 static struct rk3588_sysgrf * const sys_grf = (void *)SYS_GRF_BASE;
136#endif
Jagan Teki8967dea2023-01-30 20:27:45 +0530137 int secure_reg;
138
139 /* Set the SDMMC eMMC crypto_ns FSPI access secure area */
140 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST5_REG);
141 secure_reg &= 0xffff;
142 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST5_REG);
143 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST13_REG);
144 secure_reg &= 0xffff;
145 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST13_REG);
146 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST21_REG);
147 secure_reg &= 0xffff;
148 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST21_REG);
149 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST26_REG);
150 secure_reg &= 0xffff;
151 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST26_REG);
152 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST27_REG);
153 secure_reg &= 0xffff0000;
154 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST27_REG);
155
156 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST5_REG);
157 secure_reg &= 0xffff;
158 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST5_REG);
159 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST13_REG);
160 secure_reg &= 0xffff;
161 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST13_REG);
162 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST21_REG);
163 secure_reg &= 0xffff;
164 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST21_REG);
165 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST26_REG);
166 secure_reg &= 0xffff;
167 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST26_REG);
168 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST27_REG);
169 secure_reg &= 0xffff0000;
170 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST27_REG);
Quentin Schulz95b568f2024-03-11 13:01:54 +0100171
172#ifdef CONFIG_ROCKCHIP_DISABLE_FORCE_JTAG
173 /* Disable JTAG exposed on SDMMC */
174 rk_clrreg(&sys_grf->soc_con[6], SYS_GRF_FORCE_JTAG);
175#endif
Jagan Teki8967dea2023-01-30 20:27:45 +0530176#endif
177
178 return 0;
179}
180#endif