Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Rockchip Electronics Co., Ltd |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 6 | #include <init.h> |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 7 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 8 | #include <asm/arch-rockchip/hardware.h> |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 9 | #include <asm/arch-rockchip/grf_rk3328.h> |
| 10 | #include <asm/arch-rockchip/uart.h> |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 11 | #include <asm/armv8/mmu.h> |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 12 | |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 13 | #define CRU_BASE 0xFF440000 |
| 14 | #define GRF_BASE 0xFF100000 |
| 15 | #define UART2_BASE 0xFF130000 |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 16 | #define FW_DDR_CON_REG 0xFF7C0040 |
Jonas Karlman | cac3311 | 2024-01-07 18:18:33 +0000 | [diff] [blame] | 17 | #define EFUSE_NS_BASE 0xFF260000 |
| 18 | |
| 19 | #define EFUSE_MOD 0x0000 |
| 20 | #define EFUSE_INT_CON 0x0014 |
| 21 | #define EFUSE_T_CSB_P 0x0028 |
| 22 | #define EFUSE_T_PGENB_P 0x002C |
| 23 | #define EFUSE_T_LOAD_P 0x0030 |
| 24 | #define EFUSE_T_ADDR_P 0x0034 |
| 25 | #define EFUSE_T_STROBE_P 0x0038 |
| 26 | #define EFUSE_T_CSB_R 0x003C |
| 27 | #define EFUSE_T_PGENB_R 0x0040 |
| 28 | #define EFUSE_T_LOAD_R 0x0044 |
| 29 | #define EFUSE_T_ADDR_R 0x0048 |
| 30 | #define EFUSE_T_STROBE_R 0x004C |
| 31 | |
| 32 | #define EFUSE_USER_MODE 0x1 |
| 33 | #define EFUSE_TIMING(s, l) (((s) << 16) | (l)) |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 34 | |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 35 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
Johan Jonker | f05aa9d | 2022-04-15 23:21:43 +0200 | [diff] [blame] | 36 | [BROM_BOOTSOURCE_EMMC] = "/mmc@ff520000", |
Jonas Karlman | e4b50e0 | 2024-02-17 00:22:39 +0000 | [diff] [blame] | 37 | [BROM_BOOTSOURCE_SPINOR] = "/spi@ff190000/flash@0", |
Johan Jonker | f05aa9d | 2022-04-15 23:21:43 +0200 | [diff] [blame] | 38 | [BROM_BOOTSOURCE_SD] = "/mmc@ff500000", |
Kever Yang | b04029e | 2019-07-22 19:59:33 +0800 | [diff] [blame] | 39 | }; |
| 40 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 41 | static struct mm_region rk3328_mem_map[] = { |
| 42 | { |
| 43 | .virt = 0x0UL, |
| 44 | .phys = 0x0UL, |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 45 | .size = 0xff000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 46 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 47 | PTE_BLOCK_INNER_SHARE |
| 48 | }, { |
Kever Yang | 6cd0cab | 2017-06-13 21:00:12 +0800 | [diff] [blame] | 49 | .virt = 0xff000000UL, |
| 50 | .phys = 0xff000000UL, |
| 51 | .size = 0x1000000UL, |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 52 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 53 | PTE_BLOCK_NON_SHARE | |
| 54 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 55 | }, { |
| 56 | /* List terminator */ |
| 57 | 0, |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | struct mm_region *mem_map = rk3328_mem_map; |
| 62 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 63 | int arch_cpu_init(void) |
| 64 | { |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 65 | #ifdef CONFIG_SPL_BUILD |
Jonas Karlman | cac3311 | 2024-01-07 18:18:33 +0000 | [diff] [blame] | 66 | u32 reg; |
| 67 | |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 68 | /* We do some SoC one time setting here. */ |
| 69 | |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 70 | /* Disable the ddr secure region setting to make it non-secure */ |
| 71 | rk_setreg(FW_DDR_CON_REG, 0x200); |
Jonas Karlman | cac3311 | 2024-01-07 18:18:33 +0000 | [diff] [blame] | 72 | |
| 73 | /* Use efuse auto mode */ |
| 74 | reg = readl(EFUSE_NS_BASE + EFUSE_MOD); |
| 75 | writel(reg & ~EFUSE_USER_MODE, EFUSE_NS_BASE + EFUSE_MOD); |
| 76 | |
| 77 | /* Enable efuse finish and auto access err interrupt */ |
| 78 | writel(0x07, EFUSE_NS_BASE + EFUSE_INT_CON); |
| 79 | |
| 80 | /* Set efuse timing control */ |
| 81 | writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_CSB_P); |
| 82 | writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_PGENB_P); |
| 83 | writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_LOAD_P); |
| 84 | writel(EFUSE_TIMING(1, 241), EFUSE_NS_BASE + EFUSE_T_ADDR_P); |
| 85 | writel(EFUSE_TIMING(2, 240), EFUSE_NS_BASE + EFUSE_T_STROBE_P); |
| 86 | writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_CSB_R); |
| 87 | writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_PGENB_R); |
| 88 | writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_LOAD_R); |
| 89 | writel(EFUSE_TIMING(1, 4), EFUSE_NS_BASE + EFUSE_T_ADDR_R); |
| 90 | writel(EFUSE_TIMING(2, 3), EFUSE_NS_BASE + EFUSE_T_STROBE_R); |
Kever Yang | a18a645 | 2019-07-29 12:18:18 +0300 | [diff] [blame] | 91 | #endif |
Kever Yang | ec02b3c | 2017-02-23 15:37:51 +0800 | [diff] [blame] | 92 | return 0; |
| 93 | } |
Kever Yang | 5a9a2aa | 2019-07-22 20:01:58 +0800 | [diff] [blame] | 94 | |
| 95 | void board_debug_uart_init(void) |
| 96 | { |
| 97 | struct rk3328_grf_regs * const grf = (void *)GRF_BASE; |
| 98 | struct rk_uart * const uart = (void *)UART2_BASE; |
| 99 | enum{ |
| 100 | GPIO2A0_SEL_SHIFT = 0, |
| 101 | GPIO2A0_SEL_MASK = 3 << GPIO2A0_SEL_SHIFT, |
| 102 | GPIO2A0_UART2_TX_M1 = 1, |
| 103 | |
| 104 | GPIO2A1_SEL_SHIFT = 2, |
| 105 | GPIO2A1_SEL_MASK = 3 << GPIO2A1_SEL_SHIFT, |
| 106 | GPIO2A1_UART2_RX_M1 = 1, |
| 107 | }; |
| 108 | enum { |
| 109 | IOMUX_SEL_UART2_SHIFT = 0, |
| 110 | IOMUX_SEL_UART2_MASK = 3 << IOMUX_SEL_UART2_SHIFT, |
| 111 | IOMUX_SEL_UART2_M0 = 0, |
| 112 | IOMUX_SEL_UART2_M1, |
| 113 | }; |
| 114 | |
| 115 | /* uart_sel_clk default select 24MHz */ |
| 116 | writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148); |
| 117 | |
| 118 | /* init uart baud rate 1500000 */ |
| 119 | writel(0x83, &uart->lcr); |
| 120 | writel(0x1, &uart->rbr); |
| 121 | writel(0x3, &uart->lcr); |
| 122 | |
| 123 | /* Enable early UART2 */ |
| 124 | rk_clrsetreg(&grf->com_iomux, |
| 125 | IOMUX_SEL_UART2_MASK, |
| 126 | IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT); |
| 127 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 128 | GPIO2A0_SEL_MASK, |
| 129 | GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT); |
| 130 | rk_clrsetreg(&grf->gpio2a_iomux, |
| 131 | GPIO2A1_SEL_MASK, |
| 132 | GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT); |
| 133 | |
| 134 | /* enable FIFO */ |
| 135 | writel(0x1, &uart->sfe); |
| 136 | } |