Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | *Copyright (c) 2018 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 6 | #include <init.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 7 | #include <malloc.h> |
John Keeping | 1cfd080 | 2022-07-14 15:18:37 +0100 | [diff] [blame] | 8 | #include <asm/arch-rockchip/bootrom.h> |
Jonas Karlman | 0333e3b | 2024-04-08 18:14:11 +0000 | [diff] [blame^] | 9 | #include <asm/arch-rockchip/grf_rk3308.h> |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 10 | #include <asm/arch-rockchip/hardware.h> |
| 11 | #include <asm/gpio.h> |
| 12 | #include <debug_uart.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 14 | |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 15 | #include <asm/armv8/mmu.h> |
| 16 | static struct mm_region rk3308_mem_map[] = { |
| 17 | { |
| 18 | .virt = 0x0UL, |
| 19 | .phys = 0x0UL, |
| 20 | .size = 0xff000000UL, |
| 21 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 22 | PTE_BLOCK_INNER_SHARE |
| 23 | }, { |
| 24 | .virt = 0xff000000UL, |
| 25 | .phys = 0xff000000UL, |
| 26 | .size = 0x01000000UL, |
| 27 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 28 | PTE_BLOCK_NON_SHARE | |
| 29 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 30 | }, { |
| 31 | /* List terminator */ |
| 32 | 0, |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | struct mm_region *mem_map = rk3308_mem_map; |
| 37 | |
| 38 | #define GRF_BASE 0xff000000 |
| 39 | #define SGRF_BASE 0xff2b0000 |
| 40 | |
| 41 | enum { |
| 42 | GPIO1C7_SHIFT = 8, |
| 43 | GPIO1C7_MASK = GENMASK(11, 8), |
| 44 | GPIO1C7_GPIO = 0, |
| 45 | GPIO1C7_UART1_RTSN, |
| 46 | GPIO1C7_UART2_TX_M0, |
| 47 | GPIO1C7_SPI2_MOSI, |
| 48 | GPIO1C7_JTAG_TMS, |
| 49 | |
| 50 | GPIO1C6_SHIFT = 4, |
| 51 | GPIO1C6_MASK = GENMASK(7, 4), |
| 52 | GPIO1C6_GPIO = 0, |
| 53 | GPIO1C6_UART1_CTSN, |
| 54 | GPIO1C6_UART2_RX_M0, |
| 55 | GPIO1C6_SPI2_MISO, |
| 56 | GPIO1C6_JTAG_TCLK, |
| 57 | |
| 58 | GPIO4D3_SHIFT = 6, |
| 59 | GPIO4D3_MASK = GENMASK(7, 6), |
| 60 | GPIO4D3_GPIO = 0, |
| 61 | GPIO4D3_SDMMC_D3, |
| 62 | GPIO4D3_UART2_TX_M1, |
| 63 | |
| 64 | GPIO4D2_SHIFT = 4, |
| 65 | GPIO4D2_MASK = GENMASK(5, 4), |
| 66 | GPIO4D2_GPIO = 0, |
| 67 | GPIO4D2_SDMMC_D2, |
| 68 | GPIO4D2_UART2_RX_M1, |
| 69 | |
| 70 | UART2_IO_SEL_SHIFT = 2, |
| 71 | UART2_IO_SEL_MASK = GENMASK(3, 2), |
| 72 | UART2_IO_SEL_M0 = 0, |
| 73 | UART2_IO_SEL_M1, |
| 74 | UART2_IO_SEL_USB, |
| 75 | |
David Wu | 770258b | 2019-12-03 19:02:50 +0800 | [diff] [blame] | 76 | GPIO2C0_SEL_SRC_CTRL_SHIFT = 11, |
| 77 | GPIO2C0_SEL_SRC_CTRL_MASK = BIT(11), |
| 78 | GPIO2C0_SEL_SRC_CTRL_IOMUX = 0, |
| 79 | GPIO2C0_SEL_SRC_CTRL_SEL_PLUS, |
| 80 | |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 81 | GPIO3B3_SEL_SRC_CTRL_SHIFT = 7, |
| 82 | GPIO3B3_SEL_SRC_CTRL_MASK = BIT(7), |
| 83 | GPIO3B3_SEL_SRC_CTRL_IOMUX = 0, |
| 84 | GPIO3B3_SEL_SRC_CTRL_SEL_PLUS, |
| 85 | |
| 86 | GPIO3B3_SEL_PLUS_SHIFT = 4, |
| 87 | GPIO3B3_SEL_PLUS_MASK = GENMASK(6, 4), |
| 88 | GPIO3B3_SEL_PLUS_GPIO3_B3 = 0, |
| 89 | GPIO3B3_SEL_PLUS_FLASH_ALE, |
| 90 | GPIO3B3_SEL_PLUS_EMMC_PWREN, |
| 91 | GPIO3B3_SEL_PLUS_SPI1_CLK, |
| 92 | GPIO3B3_SEL_PLUS_LCDC_D23_M1, |
| 93 | |
| 94 | GPIO3B2_SEL_SRC_CTRL_SHIFT = 3, |
| 95 | GPIO3B2_SEL_SRC_CTRL_MASK = BIT(3), |
| 96 | GPIO3B2_SEL_SRC_CTRL_IOMUX = 0, |
| 97 | GPIO3B2_SEL_SRC_CTRL_SEL_PLUS, |
| 98 | |
| 99 | GPIO3B2_SEL_PLUS_SHIFT = 0, |
| 100 | GPIO3B2_SEL_PLUS_MASK = GENMASK(2, 0), |
| 101 | GPIO3B2_SEL_PLUS_GPIO3_B2 = 0, |
| 102 | GPIO3B2_SEL_PLUS_FLASH_RDN, |
| 103 | GPIO3B2_SEL_PLUS_EMMC_RSTN, |
| 104 | GPIO3B2_SEL_PLUS_SPI1_MISO, |
| 105 | GPIO3B2_SEL_PLUS_LCDC_D22_M1, |
David Wu | 770258b | 2019-12-03 19:02:50 +0800 | [diff] [blame] | 106 | |
| 107 | I2C3_IOFUNC_SRC_CTRL_SHIFT = 10, |
| 108 | I2C3_IOFUNC_SRC_CTRL_MASK = BIT(10), |
| 109 | I2C3_IOFUNC_SRC_CTRL_SEL_PLUS = 1, |
| 110 | |
| 111 | GPIO2A3_SEL_SRC_CTRL_SHIFT = 7, |
| 112 | GPIO2A3_SEL_SRC_CTRL_MASK = BIT(7), |
| 113 | GPIO2A3_SEL_SRC_CTRL_SEL_PLUS = 1, |
| 114 | |
| 115 | GPIO2A2_SEL_SRC_CTRL_SHIFT = 3, |
| 116 | GPIO2A2_SEL_SRC_CTRL_MASK = BIT(3), |
| 117 | GPIO2A2_SEL_SRC_CTRL_SEL_PLUS = 1, |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | enum { |
| 121 | IOVSEL3_CTRL_SHIFT = 8, |
| 122 | IOVSEL3_CTRL_MASK = BIT(8), |
| 123 | VCCIO3_SEL_BY_GPIO = 0, |
| 124 | VCCIO3_SEL_BY_IOVSEL3, |
| 125 | |
| 126 | IOVSEL3_SHIFT = 3, |
| 127 | IOVSEL3_MASK = BIT(3), |
| 128 | VCCIO3_3V3 = 0, |
| 129 | VCCIO3_1V8, |
| 130 | }; |
| 131 | |
| 132 | /* |
| 133 | * The voltage of VCCIO3(which is the voltage domain of emmc/flash/sfc |
| 134 | * interface) can indicated by GPIO0_A4 or io_vsel3. The SOC defaults |
| 135 | * use GPIO0_A4 to indicate power supply voltage for VCCIO3 by hardware, |
| 136 | * then we can switch to io_vsel3 after system power on, and release GPIO0_A4 |
| 137 | * for other usage. |
| 138 | */ |
| 139 | |
| 140 | #define GPIO0_A4 4 |
| 141 | |
John Keeping | 1cfd080 | 2022-07-14 15:18:37 +0100 | [diff] [blame] | 142 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 143 | [BROM_BOOTSOURCE_EMMC] = "/mmc@ff490000", |
Jonas Karlman | 746a77e | 2024-03-22 20:50:22 +0000 | [diff] [blame] | 144 | [BROM_BOOTSOURCE_SPINOR] = "/spi@ff4c0000/flash@0", |
John Keeping | 1cfd080 | 2022-07-14 15:18:37 +0100 | [diff] [blame] | 145 | [BROM_BOOTSOURCE_SD] = "/mmc@ff480000", |
| 146 | }; |
| 147 | |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 148 | int rk_board_init(void) |
| 149 | { |
| 150 | static struct rk3308_grf * const grf = (void *)GRF_BASE; |
| 151 | u32 val; |
| 152 | int ret; |
| 153 | |
| 154 | ret = gpio_request(GPIO0_A4, "gpio0_a4"); |
| 155 | if (ret < 0) { |
| 156 | printf("request for gpio0_a4 failed:%d\n", ret); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | gpio_direction_input(GPIO0_A4); |
| 161 | |
| 162 | if (gpio_get_value(GPIO0_A4)) |
| 163 | val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT | |
| 164 | VCCIO3_1V8 << IOVSEL3_SHIFT; |
| 165 | else |
| 166 | val = VCCIO3_SEL_BY_IOVSEL3 << IOVSEL3_CTRL_SHIFT | |
| 167 | VCCIO3_3V3 << IOVSEL3_SHIFT; |
| 168 | rk_clrsetreg(&grf->soc_con0, IOVSEL3_CTRL_MASK | IOVSEL3_MASK, val); |
| 169 | |
| 170 | gpio_free(GPIO0_A4); |
| 171 | return 0; |
| 172 | } |
| 173 | |
Pegorer Massimo | e54d4fa | 2023-07-15 10:19:28 +0000 | [diff] [blame] | 174 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 175 | __weak void board_debug_uart_init(void) |
| 176 | { |
| 177 | static struct rk3308_grf * const grf = (void *)GRF_BASE; |
| 178 | |
| 179 | /* Enable early UART2 channel m1 on the rk3308 */ |
| 180 | rk_clrsetreg(&grf->soc_con5, UART2_IO_SEL_MASK, |
| 181 | UART2_IO_SEL_M1 << UART2_IO_SEL_SHIFT); |
| 182 | rk_clrsetreg(&grf->gpio4d_iomux, |
| 183 | GPIO4D3_MASK | GPIO4D2_MASK, |
| 184 | GPIO4D2_UART2_RX_M1 << GPIO4D2_SHIFT | |
| 185 | GPIO4D3_UART2_TX_M1 << GPIO4D3_SHIFT); |
| 186 | } |
| 187 | #endif |
| 188 | |
| 189 | #if defined(CONFIG_SPL_BUILD) |
| 190 | int arch_cpu_init(void) |
| 191 | { |
| 192 | static struct rk3308_sgrf * const sgrf = (void *)SGRF_BASE; |
David Wu | 770258b | 2019-12-03 19:02:50 +0800 | [diff] [blame] | 193 | static struct rk3308_grf * const grf = (void *)GRF_BASE; |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 194 | |
| 195 | /* Set CRYPTO SDMMC EMMC NAND SFC USB master bus to be secure access */ |
| 196 | rk_clrreg(&sgrf->con_secure0, 0x2b83); |
| 197 | |
David Wu | 770258b | 2019-12-03 19:02:50 +0800 | [diff] [blame] | 198 | /* |
| 199 | * Enable plus options to use more pinctrl functions, including |
| 200 | * GPIO2A2_PLUS, GPIO2A3_PLUS and I2C3_MULTI_SRC_PLUS. |
| 201 | */ |
| 202 | rk_clrsetreg(&grf->soc_con13, |
| 203 | I2C3_IOFUNC_SRC_CTRL_MASK | GPIO2A3_SEL_SRC_CTRL_MASK | |
| 204 | GPIO2A2_SEL_SRC_CTRL_MASK, |
| 205 | I2C3_IOFUNC_SRC_CTRL_SEL_PLUS << I2C3_IOFUNC_SRC_CTRL_SHIFT | |
| 206 | GPIO2A3_SEL_SRC_CTRL_SEL_PLUS << GPIO2A3_SEL_SRC_CTRL_SHIFT | |
| 207 | GPIO2A2_SEL_SRC_CTRL_SEL_PLUS << GPIO2A2_SEL_SRC_CTRL_SHIFT); |
| 208 | |
| 209 | /* Plus options about GPIO3B2_PLUS, GPIO3B3_PLUS and GPIO2C0_PLUS. */ |
| 210 | rk_clrsetreg(&grf->soc_con15, |
| 211 | GPIO2C0_SEL_SRC_CTRL_MASK | GPIO3B3_SEL_SRC_CTRL_MASK | |
| 212 | GPIO3B2_SEL_SRC_CTRL_MASK, |
| 213 | GPIO2C0_SEL_SRC_CTRL_SEL_PLUS << GPIO2C0_SEL_SRC_CTRL_SHIFT | |
| 214 | GPIO3B3_SEL_SRC_CTRL_SEL_PLUS << GPIO3B3_SEL_SRC_CTRL_SHIFT | |
| 215 | GPIO3B2_SEL_SRC_CTRL_SEL_PLUS << GPIO3B2_SEL_SRC_CTRL_SHIFT); |
| 216 | |
Andy Yan | b5e1630 | 2019-11-14 11:21:12 +0800 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | #endif |