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