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