Jonas Karlman | 76f5d88 | 2025-04-07 22:46:52 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | // Copyright Contributors to the U-Boot project. |
| 3 | |
| 4 | #define LOG_CATEGORY LOGC_ARCH |
| 5 | |
| 6 | #include <dm.h> |
| 7 | #include <misc.h> |
| 8 | #include <asm/armv8/mmu.h> |
| 9 | #include <asm/arch-rockchip/bootrom.h> |
| 10 | #include <asm/arch-rockchip/hardware.h> |
| 11 | |
| 12 | #define FIREWALL_DDR_BASE 0xff2e0000 |
| 13 | #define FW_DDR_MST6_REG 0x58 |
| 14 | #define FW_DDR_MST7_REG 0x5c |
| 15 | #define FW_DDR_MST14_REG 0x78 |
| 16 | #define FW_DDR_MST16_REG 0x80 |
| 17 | |
| 18 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 19 | [BROM_BOOTSOURCE_EMMC] = "/soc/mmc@ffbf0000", |
| 20 | [BROM_BOOTSOURCE_SD] = "/soc/mmc@ffc30000", |
| 21 | }; |
| 22 | |
| 23 | static struct mm_region rk3528_mem_map[] = { |
| 24 | { |
| 25 | .virt = 0x0UL, |
| 26 | .phys = 0x0UL, |
| 27 | .size = 0xfc000000UL, |
| 28 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 29 | PTE_BLOCK_INNER_SHARE |
| 30 | }, { |
| 31 | .virt = 0xfc000000UL, |
| 32 | .phys = 0xfc000000UL, |
| 33 | .size = 0x04000000UL, |
| 34 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 35 | PTE_BLOCK_NON_SHARE | |
| 36 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 37 | }, { |
| 38 | /* List terminator */ |
| 39 | 0, |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | struct mm_region *mem_map = rk3528_mem_map; |
| 44 | |
| 45 | void board_debug_uart_init(void) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | int arch_cpu_init(void) |
| 50 | { |
| 51 | u32 val; |
| 52 | |
| 53 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) |
| 54 | return 0; |
| 55 | |
| 56 | /* Set the emmc to access ddr memory */ |
| 57 | val = readl(FIREWALL_DDR_BASE + FW_DDR_MST6_REG); |
| 58 | writel(val & 0x0000ffff, FIREWALL_DDR_BASE + FW_DDR_MST6_REG); |
| 59 | |
| 60 | /* Set the fspi to access ddr memory */ |
| 61 | val = readl(FIREWALL_DDR_BASE + FW_DDR_MST7_REG); |
| 62 | writel(val & 0xffff0000, FIREWALL_DDR_BASE + FW_DDR_MST7_REG); |
| 63 | |
| 64 | /* Set the sdmmc to access ddr memory */ |
| 65 | val = readl(FIREWALL_DDR_BASE + FW_DDR_MST14_REG); |
| 66 | writel(val & 0x0000ffff, FIREWALL_DDR_BASE + FW_DDR_MST14_REG); |
| 67 | |
| 68 | /* Set the usb to access ddr memory */ |
| 69 | val = readl(FIREWALL_DDR_BASE + FW_DDR_MST16_REG); |
| 70 | writel(val & 0xffff0000, FIREWALL_DDR_BASE + FW_DDR_MST16_REG); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | #define HP_TIMER_BASE CONFIG_ROCKCHIP_STIMER_BASE |
| 76 | #define HP_CTRL_REG 0x04 |
| 77 | #define TIMER_EN BIT(0) |
| 78 | #define HP_LOAD_COUNT0_REG 0x14 |
| 79 | #define HP_LOAD_COUNT1_REG 0x18 |
| 80 | |
| 81 | void rockchip_stimer_init(void) |
| 82 | { |
| 83 | u32 reg; |
| 84 | |
| 85 | if (!IS_ENABLED(CONFIG_XPL_BUILD)) |
| 86 | return; |
| 87 | |
| 88 | reg = readl(HP_TIMER_BASE + HP_CTRL_REG); |
| 89 | if (reg & TIMER_EN) |
| 90 | return; |
| 91 | |
| 92 | asm volatile("msr cntfrq_el0, %0" : : "r" (CONFIG_COUNTER_FREQUENCY)); |
| 93 | writel(0xffffffff, HP_TIMER_BASE + HP_LOAD_COUNT0_REG); |
| 94 | writel(0xffffffff, HP_TIMER_BASE + HP_LOAD_COUNT1_REG); |
| 95 | writel(TIMER_EN, HP_TIMER_BASE + HP_CTRL_REG); |
| 96 | } |
| 97 | |
| 98 | #define RK3528_OTP_CPU_CODE_OFFSET 0x02 |
| 99 | #define RK3528_OTP_CPU_CHIP_TYPE_OFFSET 0x28 |
| 100 | |
| 101 | int checkboard(void) |
| 102 | { |
| 103 | u8 cpu_code[2], chip_type; |
| 104 | struct udevice *dev; |
| 105 | char suffix[2]; |
| 106 | int ret; |
| 107 | |
| 108 | if (!IS_ENABLED(CONFIG_ROCKCHIP_OTP) || !CONFIG_IS_ENABLED(MISC)) |
| 109 | return 0; |
| 110 | |
| 111 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 112 | DM_DRIVER_GET(rockchip_otp), &dev); |
| 113 | if (ret) { |
| 114 | log_debug("Could not find otp device, ret=%d\n", ret); |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* cpu-code: SoC model, e.g. 0x35 0x28 */ |
| 119 | ret = misc_read(dev, RK3528_OTP_CPU_CODE_OFFSET, cpu_code, 2); |
| 120 | if (ret < 0) { |
| 121 | log_debug("Could not read cpu-code, ret=%d\n", ret); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | ret = misc_read(dev, RK3528_OTP_CPU_CHIP_TYPE_OFFSET, &chip_type, 1); |
| 126 | if (ret < 0) { |
| 127 | log_debug("Could not read chip type, ret=%d\n", ret); |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | suffix[0] = chip_type != 0x1 ? 'A' : '\0'; |
| 132 | suffix[1] = '\0'; |
| 133 | |
| 134 | printf("SoC: RK%02x%02x%s\n", cpu_code[0], cpu_code[1], suffix); |
| 135 | |
| 136 | return 0; |
| 137 | } |