blob: 18e67b5ca9b22af3a727cdc74194a6b8a8088b5d [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
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 Karlmanafe8635f2023-03-14 00:38:30 +000040const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
41 [BROM_BOOTSOURCE_EMMC] = "/mmc@fe2e0000",
42 [BROM_BOOTSOURCE_SPINOR] = "/spi@fe2b0000/flash@0",
43 [BROM_BOOTSOURCE_SD] = "/mmc@fe2c0000",
44};
45
Jagan Teki8967dea2023-01-30 20:27:45 +053046static struct mm_region rk3588_mem_map[] = {
47 {
48 .virt = 0x0UL,
49 .phys = 0x0UL,
50 .size = 0xf0000000UL,
51 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
52 PTE_BLOCK_INNER_SHARE
53 }, {
54 .virt = 0xf0000000UL,
55 .phys = 0xf0000000UL,
56 .size = 0x10000000UL,
57 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
58 PTE_BLOCK_NON_SHARE |
59 PTE_BLOCK_PXN | PTE_BLOCK_UXN
60 }, {
61 .virt = 0x900000000,
62 .phys = 0x900000000,
63 .size = 0x150000000,
64 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
65 PTE_BLOCK_NON_SHARE |
66 PTE_BLOCK_PXN | PTE_BLOCK_UXN
67 }, {
68 /* List terminator */
69 0,
70 }
71};
72
73struct mm_region *mem_map = rk3588_mem_map;
74
75/* GPIO0B_IOMUX_SEL_H */
76enum {
77 GPIO0B5_SHIFT = 4,
78 GPIO0B5_MASK = GENMASK(7, 4),
79 GPIO0B5_REFER = 8,
80 GPIO0B5_UART2_TX_M0 = 10,
81
82 GPIO0B6_SHIFT = 8,
83 GPIO0B6_MASK = GENMASK(11, 8),
84 GPIO0B6_REFER = 8,
85 GPIO0B6_UART2_RX_M0 = 10,
86};
87
88void board_debug_uart_init(void)
89{
90 __maybe_unused static struct rk3588_bus_ioc * const bus_ioc = (void *)BUS_IOC_BASE;
91 static struct rk3588_pmu2_ioc * const pmu2_ioc = (void *)PMU2_IOC_BASE;
92
93 /* Refer to BUS_IOC */
94 rk_clrsetreg(&pmu2_ioc->gpio0b_iomux_sel_h,
95 GPIO0B6_MASK | GPIO0B5_MASK,
96 GPIO0B6_REFER << GPIO0B6_SHIFT |
97 GPIO0B5_REFER << GPIO0B5_SHIFT);
98
99 /* UART2_M0 Switch iomux */
100 rk_clrsetreg(&bus_ioc->gpio0b_iomux_sel_h,
101 GPIO0B6_MASK | GPIO0B5_MASK,
102 GPIO0B6_UART2_RX_M0 << GPIO0B6_SHIFT |
103 GPIO0B5_UART2_TX_M0 << GPIO0B5_SHIFT);
104}
105
106#ifdef CONFIG_SPL_BUILD
107void rockchip_stimer_init(void)
108{
109 /* If Timer already enabled, don't re-init it */
110 u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + 0x4);
111
112 if (reg & 0x1)
113 return;
114
115 asm volatile("msr CNTFRQ_EL0, %0" : : "r" (CONFIG_COUNTER_FREQUENCY));
116 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 0x14);
117 writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 0x18);
118 writel(0x1, CONFIG_ROCKCHIP_STIMER_BASE + 0x4);
119}
120#endif
121
122#ifndef CONFIG_TPL_BUILD
123int arch_cpu_init(void)
124{
125#ifdef CONFIG_SPL_BUILD
126 int secure_reg;
127
128 /* Set the SDMMC eMMC crypto_ns FSPI access secure area */
129 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST5_REG);
130 secure_reg &= 0xffff;
131 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST5_REG);
132 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST13_REG);
133 secure_reg &= 0xffff;
134 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST13_REG);
135 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST21_REG);
136 secure_reg &= 0xffff;
137 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST21_REG);
138 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST26_REG);
139 secure_reg &= 0xffff;
140 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST26_REG);
141 secure_reg = readl(FIREWALL_DDR_BASE + FW_DDR_MST27_REG);
142 secure_reg &= 0xffff0000;
143 writel(secure_reg, FIREWALL_DDR_BASE + FW_DDR_MST27_REG);
144
145 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST5_REG);
146 secure_reg &= 0xffff;
147 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST5_REG);
148 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST13_REG);
149 secure_reg &= 0xffff;
150 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST13_REG);
151 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST21_REG);
152 secure_reg &= 0xffff;
153 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST21_REG);
154 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST26_REG);
155 secure_reg &= 0xffff;
156 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST26_REG);
157 secure_reg = readl(FIREWALL_SYSMEM_BASE + FW_SYSM_MST27_REG);
158 secure_reg &= 0xffff0000;
159 writel(secure_reg, FIREWALL_SYSMEM_BASE + FW_SYSM_MST27_REG);
160#endif
161
162 return 0;
163}
164#endif