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