Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007-2012 |
| 4 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 5 | * Tom Cubie <tangliang@allwinnertech.com> |
Andre Przywara | 20b78c5 | 2022-09-06 10:36:38 +0100 | [diff] [blame] | 6 | * |
| 7 | * Definitions that are shared between the Allwinner pinctrl and GPIO drivers, |
| 8 | * also used by some non-DM SPL code directly. |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef _SUNXI_GPIO_H |
| 12 | #define _SUNXI_GPIO_H |
| 13 | |
| 14 | #include <linux/types.h> |
Andre Przywara | 1da48c9 | 2022-09-06 11:50:54 +0100 | [diff] [blame] | 15 | |
| 16 | #if defined(CONFIG_MACH_SUN9I) |
| 17 | #define SUNXI_PIO_BASE 0x06000800 |
| 18 | #define SUNXI_R_PIO_BASE 0x08002c00 |
| 19 | #elif defined(CONFIG_SUN50I_GEN_H6) |
| 20 | #define SUNXI_PIO_BASE 0x0300b000 |
| 21 | #define SUNXI_R_PIO_BASE 0x07022000 |
| 22 | #else |
| 23 | #define SUNXI_PIO_BASE 0x01c20800 |
| 24 | #define SUNXI_R_PIO_BASE 0x01f02c00 |
| 25 | #endif |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * sunxi has 9 banks of gpio, they are: |
| 29 | * PA0 - PA17 | PB0 - PB23 | PC0 - PC24 |
| 30 | * PD0 - PD27 | PE0 - PE31 | PF0 - PF5 |
| 31 | * PG0 - PG9 | PH0 - PH27 | PI0 - PI12 |
| 32 | */ |
| 33 | |
| 34 | #define SUNXI_GPIO_A 0 |
| 35 | #define SUNXI_GPIO_B 1 |
| 36 | #define SUNXI_GPIO_C 2 |
| 37 | #define SUNXI_GPIO_D 3 |
| 38 | #define SUNXI_GPIO_E 4 |
| 39 | #define SUNXI_GPIO_F 5 |
| 40 | #define SUNXI_GPIO_G 6 |
| 41 | #define SUNXI_GPIO_H 7 |
| 42 | #define SUNXI_GPIO_I 8 |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 43 | |
| 44 | /* |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 45 | * sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO) |
| 46 | * at a different register offset. |
| 47 | * |
| 48 | * sun6i has 2 banks: |
| 49 | * PL0 - PL8 | PM0 - PM7 |
| 50 | * |
| 51 | * sun8i has 1 bank: |
| 52 | * PL0 - PL11 |
Hans de Goede | d35488c | 2015-01-26 16:46:43 +0100 | [diff] [blame] | 53 | * |
| 54 | * sun9i has 3 banks: |
| 55 | * PL0 - PL9 | PM0 - PM15 | PN0 - PN1 |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 56 | */ |
| 57 | #define SUNXI_GPIO_L 11 |
| 58 | #define SUNXI_GPIO_M 12 |
Hans de Goede | d35488c | 2015-01-26 16:46:43 +0100 | [diff] [blame] | 59 | #define SUNXI_GPIO_N 13 |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 60 | |
Icenowy Zheng | 5f19c93 | 2019-04-24 13:44:12 +0800 | [diff] [blame] | 61 | #define SUN50I_H6_GPIO_POW_MOD_SEL 0x340 |
| 62 | #define SUN50I_H6_GPIO_POW_MOD_VAL 0x348 |
| 63 | |
Samuel Holland | 8fe8ff3 | 2021-09-11 16:50:49 -0500 | [diff] [blame] | 64 | #define SUNXI_GPIOS_PER_BANK 32 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 65 | |
| 66 | #define SUNXI_GPIO_NEXT(__gpio) \ |
Samuel Holland | 8fe8ff3 | 2021-09-11 16:50:49 -0500 | [diff] [blame] | 67 | ((__gpio##_START) + SUNXI_GPIOS_PER_BANK) |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 68 | |
| 69 | enum sunxi_gpio_number { |
| 70 | SUNXI_GPIO_A_START = 0, |
| 71 | SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A), |
| 72 | SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B), |
| 73 | SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C), |
| 74 | SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D), |
| 75 | SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E), |
| 76 | SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F), |
| 77 | SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G), |
| 78 | SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H), |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 79 | SUNXI_GPIO_L_START = 352, |
| 80 | SUNXI_GPIO_M_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_L), |
Hans de Goede | d35488c | 2015-01-26 16:46:43 +0100 | [diff] [blame] | 81 | SUNXI_GPIO_N_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_M), |
Hans de Goede | 6c727e0 | 2014-12-24 19:34:38 +0100 | [diff] [blame] | 82 | SUNXI_GPIO_AXP0_START = 1024, |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* SUNXI GPIO number definitions */ |
| 86 | #define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr)) |
| 87 | #define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr)) |
| 88 | #define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr)) |
| 89 | #define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr)) |
| 90 | #define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr)) |
| 91 | #define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr)) |
| 92 | #define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr)) |
| 93 | #define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr)) |
| 94 | #define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr)) |
Hans de Goede | e373aad | 2014-10-22 16:47:45 +0800 | [diff] [blame] | 95 | #define SUNXI_GPL(_nr) (SUNXI_GPIO_L_START + (_nr)) |
| 96 | #define SUNXI_GPM(_nr) (SUNXI_GPIO_M_START + (_nr)) |
Hans de Goede | d35488c | 2015-01-26 16:46:43 +0100 | [diff] [blame] | 97 | #define SUNXI_GPN(_nr) (SUNXI_GPIO_N_START + (_nr)) |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 98 | |
Hans de Goede | 6c727e0 | 2014-12-24 19:34:38 +0100 | [diff] [blame] | 99 | #define SUNXI_GPAXP0(_nr) (SUNXI_GPIO_AXP0_START + (_nr)) |
| 100 | |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 101 | /* GPIO pin function config */ |
| 102 | #define SUNXI_GPIO_INPUT 0 |
| 103 | #define SUNXI_GPIO_OUTPUT 1 |
| 104 | |
Jens Kuske | 1c27b7d | 2015-11-17 15:12:58 +0100 | [diff] [blame] | 105 | #define SUN8I_H3_GPA_UART0 2 |
Angelo Dureghello | 482c1cc | 2021-10-09 14:18:59 +0200 | [diff] [blame] | 106 | #define SUN8I_H3_GPA_UART2 2 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 107 | |
Hans de Goede | 421c98d | 2016-08-19 15:25:41 +0200 | [diff] [blame] | 108 | #define SUN4I_GPB_PWM 2 |
Paul Kocialkowski | 6c739c5 | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 109 | #define SUN4I_GPB_TWI0 2 |
| 110 | #define SUN4I_GPB_TWI1 2 |
| 111 | #define SUN5I_GPB_TWI1 2 |
Icenowy Zheng | 8c51c65 | 2020-10-26 22:19:34 +0800 | [diff] [blame] | 112 | #define SUN8I_V3S_GPB_TWI0 2 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 113 | #define SUN4I_GPB_UART0 2 |
| 114 | #define SUN5I_GPB_UART0 2 |
Laurent Itti | 5cd83b11 | 2015-05-05 17:02:00 -0700 | [diff] [blame] | 115 | #define SUN8I_GPB_UART2 2 |
Chen-Yu Tsai | e506889 | 2015-06-23 19:57:25 +0800 | [diff] [blame] | 116 | #define SUN8I_A33_GPB_UART0 3 |
vishnupatekar | d5a3357 | 2015-11-29 01:07:20 +0800 | [diff] [blame] | 117 | #define SUN8I_A83T_GPB_UART0 2 |
Icenowy Zheng | c199489 | 2017-04-08 15:30:12 +0800 | [diff] [blame] | 118 | #define SUN8I_V3S_GPB_UART0 3 |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 119 | #define SUN50I_GPB_UART0 4 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 120 | |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 121 | #define SUNXI_GPC_NAND 2 |
Siarhei Siamashka | 19e99fb | 2016-06-07 14:28:34 +0300 | [diff] [blame] | 122 | #define SUNXI_GPC_SPI0 3 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 123 | #define SUNXI_GPC_SDC2 3 |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 124 | #define SUN6I_GPC_SDC3 4 |
Siarhei Siamashka | 19e99fb | 2016-06-07 14:28:34 +0300 | [diff] [blame] | 125 | #define SUN50I_GPC_SPI0 4 |
Jesse Taube | 0dcdaff | 2022-02-11 19:32:34 -0500 | [diff] [blame] | 126 | #define SUNIV_GPC_SPI0 2 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 127 | |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 128 | #define SUNXI_GPD_LCD0 2 |
| 129 | #define SUNXI_GPD_LVDS0 3 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 130 | |
Icenowy Zheng | 5d35f0f | 2022-01-29 10:23:03 -0500 | [diff] [blame] | 131 | #define SUNIV_GPE_UART0 5 |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 132 | |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 133 | #define SUNXI_GPF_SDC0 2 |
| 134 | #define SUNXI_GPF_UART0 4 |
| 135 | #define SUN8I_GPF_UART0 3 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 136 | |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 137 | #define SUN4I_GPG_SDC1 4 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 138 | #define SUN5I_GPG_SDC1 2 |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 139 | #define SUN6I_GPG_SDC1 2 |
| 140 | #define SUN8I_GPG_SDC1 2 |
Tobias Schramm | 7f4e294 | 2021-02-15 00:19:58 +0100 | [diff] [blame] | 141 | #define SUN8I_GPG_UART1 2 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 142 | #define SUN5I_GPG_UART1 4 |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 143 | |
Hans de Goede | 421c98d | 2016-08-19 15:25:41 +0200 | [diff] [blame] | 144 | #define SUN6I_GPH_PWM 2 |
| 145 | #define SUN8I_GPH_PWM 2 |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 146 | #define SUN4I_GPH_SDC1 5 |
Paul Kocialkowski | 6c739c5 | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 147 | #define SUN6I_GPH_TWI0 2 |
| 148 | #define SUN8I_GPH_TWI0 2 |
Stefan Mavrodiev | da1ae59 | 2019-01-08 12:04:30 +0200 | [diff] [blame] | 149 | #define SUN50I_GPH_TWI0 2 |
Paul Kocialkowski | 6c739c5 | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 150 | #define SUN6I_GPH_TWI1 2 |
| 151 | #define SUN8I_GPH_TWI1 2 |
Stefan Mavrodiev | da1ae59 | 2019-01-08 12:04:30 +0200 | [diff] [blame] | 152 | #define SUN50I_GPH_TWI1 2 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 153 | #define SUN6I_GPH_UART0 2 |
Hans de Goede | 1871a8c | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 154 | #define SUN9I_GPH_UART0 2 |
Icenowy Zheng | 7f51a40 | 2018-07-21 16:20:28 +0800 | [diff] [blame] | 155 | #define SUN50I_H6_GPH_UART0 2 |
Jernej Skrabec | c13d98b | 2021-01-11 21:11:41 +0100 | [diff] [blame] | 156 | #define SUN50I_H616_GPH_UART0 2 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 157 | |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 158 | #define SUNXI_GPI_SDC3 2 |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 159 | |
Hans de Goede | ce88107 | 2014-12-13 10:25:14 +0100 | [diff] [blame] | 160 | #define SUN6I_GPL0_R_P2WI_SCK 3 |
| 161 | #define SUN6I_GPL1_R_P2WI_SDA 3 |
Oliver Schinagl | 3b10e6e | 2013-07-25 14:07:42 +0200 | [diff] [blame] | 162 | |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 163 | #define SUN8I_GPL_R_RSB 2 |
Jelle van der Waa | 9d08268 | 2016-01-14 14:06:26 +0100 | [diff] [blame] | 164 | #define SUN8I_H3_GPL_R_TWI 2 |
| 165 | #define SUN8I_A23_GPL_R_TWI 3 |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 166 | #define SUN8I_GPL_R_UART 2 |
Vasily Khoruzhick | 31a4ac4 | 2018-11-05 20:24:30 -0800 | [diff] [blame] | 167 | #define SUN50I_GPL_R_TWI 2 |
Jernej Skrabec | d0b07c1 | 2021-01-11 21:11:42 +0100 | [diff] [blame] | 168 | #define SUN50I_H616_GPL_R_TWI 3 |
Chen-Yu Tsai | c757a50 | 2014-10-22 16:47:47 +0800 | [diff] [blame] | 169 | |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 170 | #define SUN9I_GPN_R_RSB 3 |
Hans de Goede | d35488c | 2015-01-26 16:46:43 +0100 | [diff] [blame] | 171 | |
Andre Przywara | 452369c | 2022-09-06 12:12:50 +0100 | [diff] [blame^] | 172 | #ifdef CONFIG_SUNXI_NEW_PINCTRL |
| 173 | #define SUNXI_PINCTRL_BANK_SIZE 0x30 |
| 174 | #define SUNXI_GPIO_DISABLE 0xf |
| 175 | #else |
| 176 | #define SUNXI_PINCTRL_BANK_SIZE 0x24 |
| 177 | #define SUNXI_GPIO_DISABLE 0x7 |
| 178 | #endif |
| 179 | |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 180 | /* GPIO pin pull-up/down config */ |
| 181 | #define SUNXI_GPIO_PULL_DISABLE 0 |
| 182 | #define SUNXI_GPIO_PULL_UP 1 |
| 183 | #define SUNXI_GPIO_PULL_DOWN 2 |
| 184 | |
Paul Kocialkowski | f7c7ab6 | 2015-03-22 18:07:09 +0100 | [diff] [blame] | 185 | /* Virtual AXP0 GPIOs */ |
Hans de Goede | f9b7a04 | 2015-04-22 11:31:22 +0200 | [diff] [blame] | 186 | #define SUNXI_GPIO_AXP0_PREFIX "AXP0-" |
Hans de Goede | f9b7a04 | 2015-04-22 11:31:22 +0200 | [diff] [blame] | 187 | #define SUNXI_GPIO_AXP0_VBUS_ENABLE 5 |
| 188 | #define SUNXI_GPIO_AXP0_GPIO_COUNT 6 |
Paul Kocialkowski | f7c7ab6 | 2015-03-22 18:07:09 +0100 | [diff] [blame] | 189 | |
Samuel Holland | b799eab | 2021-08-12 20:09:43 -0500 | [diff] [blame] | 190 | struct sunxi_gpio_plat { |
Andre Przywara | 30097ee | 2022-09-05 18:12:39 +0100 | [diff] [blame] | 191 | void *regs; |
Samuel Holland | b799eab | 2021-08-12 20:09:43 -0500 | [diff] [blame] | 192 | char bank_name[3]; |
| 193 | }; |
| 194 | |
Andre Przywara | 20b78c5 | 2022-09-06 10:36:38 +0100 | [diff] [blame] | 195 | /* prototypes for the non-DM GPIO/pinctrl functions, used in the SPL */ |
Andre Przywara | 30097ee | 2022-09-05 18:12:39 +0100 | [diff] [blame] | 196 | void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val); |
Simon Glass | bf38891 | 2014-10-30 20:25:47 -0600 | [diff] [blame] | 197 | void sunxi_gpio_set_cfgpin(u32 pin, u32 val); |
Andre Przywara | 30097ee | 2022-09-05 18:12:39 +0100 | [diff] [blame] | 198 | int sunxi_gpio_get_cfgbank(void *bank_base, int pin_offset); |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 199 | int sunxi_gpio_get_cfgpin(u32 pin); |
Samuel Holland | ac5397a | 2021-10-20 23:52:54 -0500 | [diff] [blame] | 200 | void sunxi_gpio_set_drv(u32 pin, u32 val); |
Andre Przywara | 30097ee | 2022-09-05 18:12:39 +0100 | [diff] [blame] | 201 | void sunxi_gpio_set_drv_bank(void *bank_base, u32 pin_offset, u32 val); |
Samuel Holland | ac5397a | 2021-10-20 23:52:54 -0500 | [diff] [blame] | 202 | void sunxi_gpio_set_pull(u32 pin, u32 val); |
Andre Przywara | 30097ee | 2022-09-05 18:12:39 +0100 | [diff] [blame] | 203 | void sunxi_gpio_set_pull_bank(void *bank_base, int pin_offset, u32 val); |
Ian Campbell | abce2c6 | 2014-06-05 19:00:15 +0100 | [diff] [blame] | 204 | int sunxi_name_to_gpio(const char *name); |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 205 | |
Hans de Goede | 2fcf033 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 206 | #if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO |
| 207 | int axp_gpio_init(void); |
| 208 | #else |
| 209 | static inline int axp_gpio_init(void) { return 0; } |
| 210 | #endif |
| 211 | |
Ian Campbell | fe1b4db | 2014-05-05 11:52:24 +0100 | [diff] [blame] | 212 | #endif /* _SUNXI_GPIO_H */ |