]>
Commit | Line | Data |
---|---|---|
fe1b4db0 IC |
1 | /* |
2 | * (C) Copyright 2007-2012 | |
3 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> | |
4 | * Tom Cubie <tangliang@allwinnertech.com> | |
5 | * | |
6 | * SPDX-License-Identifier: GPL-2.0+ | |
7 | */ | |
8 | ||
9 | #ifndef _SUNXI_GPIO_H | |
10 | #define _SUNXI_GPIO_H | |
11 | ||
12 | #include <linux/types.h> | |
e373aad3 | 13 | #include <asm/arch/cpu.h> |
fe1b4db0 IC |
14 | |
15 | /* | |
16 | * sunxi has 9 banks of gpio, they are: | |
17 | * PA0 - PA17 | PB0 - PB23 | PC0 - PC24 | |
18 | * PD0 - PD27 | PE0 - PE31 | PF0 - PF5 | |
19 | * PG0 - PG9 | PH0 - PH27 | PI0 - PI12 | |
20 | */ | |
21 | ||
22 | #define SUNXI_GPIO_A 0 | |
23 | #define SUNXI_GPIO_B 1 | |
24 | #define SUNXI_GPIO_C 2 | |
25 | #define SUNXI_GPIO_D 3 | |
26 | #define SUNXI_GPIO_E 4 | |
27 | #define SUNXI_GPIO_F 5 | |
28 | #define SUNXI_GPIO_G 6 | |
29 | #define SUNXI_GPIO_H 7 | |
30 | #define SUNXI_GPIO_I 8 | |
e373aad3 HG |
31 | |
32 | /* | |
33 | * This defines the number of GPIO banks for the _main_ GPIO controller. | |
34 | * You should fix up the padding in struct sunxi_gpio_reg below if you | |
35 | * change this. | |
36 | */ | |
fe1b4db0 IC |
37 | #define SUNXI_GPIO_BANKS 9 |
38 | ||
e373aad3 HG |
39 | /* |
40 | * sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO) | |
41 | * at a different register offset. | |
42 | * | |
43 | * sun6i has 2 banks: | |
44 | * PL0 - PL8 | PM0 - PM7 | |
45 | * | |
46 | * sun8i has 1 bank: | |
47 | * PL0 - PL11 | |
d35488c7 HG |
48 | * |
49 | * sun9i has 3 banks: | |
50 | * PL0 - PL9 | PM0 - PM15 | PN0 - PN1 | |
e373aad3 HG |
51 | */ |
52 | #define SUNXI_GPIO_L 11 | |
53 | #define SUNXI_GPIO_M 12 | |
d35488c7 | 54 | #define SUNXI_GPIO_N 13 |
e373aad3 | 55 | |
fe1b4db0 IC |
56 | struct sunxi_gpio { |
57 | u32 cfg[4]; | |
58 | u32 dat; | |
59 | u32 drv[2]; | |
60 | u32 pull[2]; | |
61 | }; | |
62 | ||
63 | /* gpio interrupt control */ | |
64 | struct sunxi_gpio_int { | |
65 | u32 cfg[3]; | |
66 | u32 ctl; | |
67 | u32 sta; | |
68 | u32 deb; /* interrupt debounce */ | |
69 | }; | |
70 | ||
71 | struct sunxi_gpio_reg { | |
72 | struct sunxi_gpio gpio_bank[SUNXI_GPIO_BANKS]; | |
73 | u8 res[0xbc]; | |
74 | struct sunxi_gpio_int gpio_int; | |
75 | }; | |
76 | ||
e373aad3 HG |
77 | #define BANK_TO_GPIO(bank) (((bank) < SUNXI_GPIO_L) ? \ |
78 | &((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank] : \ | |
79 | &((struct sunxi_gpio_reg *)SUNXI_R_PIO_BASE)->gpio_bank[(bank) - SUNXI_GPIO_L]) | |
fe1b4db0 IC |
80 | |
81 | #define GPIO_BANK(pin) ((pin) >> 5) | |
82 | #define GPIO_NUM(pin) ((pin) & 0x1f) | |
83 | ||
84 | #define GPIO_CFG_INDEX(pin) (((pin) & 0x1f) >> 3) | |
85 | #define GPIO_CFG_OFFSET(pin) ((((pin) & 0x1f) & 0x7) << 2) | |
86 | ||
991963bc | 87 | #define GPIO_DRV_INDEX(pin) (((pin) & 0x1f) >> 4) |
fe1b4db0 IC |
88 | #define GPIO_DRV_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1) |
89 | ||
90 | #define GPIO_PULL_INDEX(pin) (((pin) & 0x1f) >> 4) | |
91 | #define GPIO_PULL_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1) | |
92 | ||
93 | /* GPIO bank sizes */ | |
94 | #define SUNXI_GPIO_A_NR 32 | |
95 | #define SUNXI_GPIO_B_NR 32 | |
96 | #define SUNXI_GPIO_C_NR 32 | |
97 | #define SUNXI_GPIO_D_NR 32 | |
98 | #define SUNXI_GPIO_E_NR 32 | |
99 | #define SUNXI_GPIO_F_NR 32 | |
100 | #define SUNXI_GPIO_G_NR 32 | |
101 | #define SUNXI_GPIO_H_NR 32 | |
102 | #define SUNXI_GPIO_I_NR 32 | |
e373aad3 HG |
103 | #define SUNXI_GPIO_L_NR 32 |
104 | #define SUNXI_GPIO_M_NR 32 | |
fe1b4db0 IC |
105 | |
106 | #define SUNXI_GPIO_NEXT(__gpio) \ | |
107 | ((__gpio##_START) + (__gpio##_NR) + 0) | |
108 | ||
109 | enum sunxi_gpio_number { | |
110 | SUNXI_GPIO_A_START = 0, | |
111 | SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A), | |
112 | SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B), | |
113 | SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C), | |
114 | SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D), | |
115 | SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E), | |
116 | SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F), | |
117 | SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G), | |
118 | SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H), | |
e373aad3 HG |
119 | SUNXI_GPIO_L_START = 352, |
120 | SUNXI_GPIO_M_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_L), | |
d35488c7 | 121 | SUNXI_GPIO_N_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_M), |
6c727e09 | 122 | SUNXI_GPIO_AXP0_START = 1024, |
fe1b4db0 IC |
123 | }; |
124 | ||
125 | /* SUNXI GPIO number definitions */ | |
126 | #define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr)) | |
127 | #define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr)) | |
128 | #define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr)) | |
129 | #define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr)) | |
130 | #define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr)) | |
131 | #define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr)) | |
132 | #define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr)) | |
133 | #define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr)) | |
134 | #define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr)) | |
e373aad3 HG |
135 | #define SUNXI_GPL(_nr) (SUNXI_GPIO_L_START + (_nr)) |
136 | #define SUNXI_GPM(_nr) (SUNXI_GPIO_M_START + (_nr)) | |
d35488c7 | 137 | #define SUNXI_GPN(_nr) (SUNXI_GPIO_N_START + (_nr)) |
fe1b4db0 | 138 | |
6c727e09 HG |
139 | #define SUNXI_GPAXP0(_nr) (SUNXI_GPIO_AXP0_START + (_nr)) |
140 | ||
fe1b4db0 IC |
141 | /* GPIO pin function config */ |
142 | #define SUNXI_GPIO_INPUT 0 | |
143 | #define SUNXI_GPIO_OUTPUT 1 | |
19e99fb4 | 144 | #define SUNXI_GPIO_DISABLE 7 |
fe1b4db0 | 145 | |
487b3277 PK |
146 | #define SUNXI_GPA_EMAC 2 |
147 | #define SUN6I_GPA_GMAC 2 | |
148 | #define SUN7I_GPA_GMAC 5 | |
8deacca9 PK |
149 | #define SUN6I_GPA_SDC2 5 |
150 | #define SUN6I_GPA_SDC3 4 | |
1c27b7dc | 151 | #define SUN8I_H3_GPA_UART0 2 |
1d736fd3 NG |
152 | #define SUN8I_H3_H5_GPA_TWI0 2 |
153 | #define SUN8I_H3_H5_GPA_TWI1 3 | |
fe1b4db0 | 154 | |
421c98d7 | 155 | #define SUN4I_GPB_PWM 2 |
6c739c5d PK |
156 | #define SUN4I_GPB_TWI0 2 |
157 | #define SUN4I_GPB_TWI1 2 | |
158 | #define SUN5I_GPB_TWI1 2 | |
159 | #define SUN4I_GPB_TWI2 2 | |
160 | #define SUN5I_GPB_TWI2 2 | |
487b3277 PK |
161 | #define SUN4I_GPB_UART0 2 |
162 | #define SUN5I_GPB_UART0 2 | |
5cd83b11 | 163 | #define SUN8I_GPB_UART2 2 |
e506889c | 164 | #define SUN8I_A33_GPB_UART0 3 |
d5a3357f | 165 | #define SUN8I_A83T_GPB_UART0 2 |
c199489f | 166 | #define SUN8I_V3S_GPB_UART0 3 |
d96ebc46 | 167 | #define SUN50I_GPB_UART0 4 |
fe1b4db0 | 168 | |
ad008299 | 169 | #define SUNXI_GPC_NAND 2 |
19e99fb4 | 170 | #define SUNXI_GPC_SPI0 3 |
487b3277 | 171 | #define SUNXI_GPC_SDC2 3 |
8deacca9 | 172 | #define SUN6I_GPC_SDC3 4 |
19e99fb4 | 173 | #define SUN50I_GPC_SPI0 4 |
fe1b4db0 | 174 | |
8deacca9 | 175 | #define SUN8I_GPD_SDC1 3 |
487b3277 PK |
176 | #define SUNXI_GPD_LCD0 2 |
177 | #define SUNXI_GPD_LVDS0 3 | |
fe1b4db0 | 178 | |
8deacca9 | 179 | #define SUN5I_GPE_SDC2 3 |
6c739c5d | 180 | #define SUN8I_GPE_TWI2 3 |
8deacca9 | 181 | |
487b3277 PK |
182 | #define SUNXI_GPF_SDC0 2 |
183 | #define SUNXI_GPF_UART0 4 | |
184 | #define SUN8I_GPF_UART0 3 | |
fe1b4db0 | 185 | |
8deacca9 | 186 | #define SUN4I_GPG_SDC1 4 |
487b3277 | 187 | #define SUN5I_GPG_SDC1 2 |
8deacca9 PK |
188 | #define SUN6I_GPG_SDC1 2 |
189 | #define SUN8I_GPG_SDC1 2 | |
6c739c5d | 190 | #define SUN6I_GPG_TWI3 2 |
487b3277 | 191 | #define SUN5I_GPG_UART1 4 |
2dae800f | 192 | |
421c98d7 HG |
193 | #define SUN6I_GPH_PWM 2 |
194 | #define SUN8I_GPH_PWM 2 | |
8deacca9 | 195 | #define SUN4I_GPH_SDC1 5 |
6c739c5d PK |
196 | #define SUN6I_GPH_TWI0 2 |
197 | #define SUN8I_GPH_TWI0 2 | |
198 | #define SUN6I_GPH_TWI1 2 | |
199 | #define SUN8I_GPH_TWI1 2 | |
200 | #define SUN6I_GPH_TWI2 2 | |
487b3277 | 201 | #define SUN6I_GPH_UART0 2 |
1871a8ca | 202 | #define SUN9I_GPH_UART0 2 |
fe1b4db0 | 203 | |
8deacca9 | 204 | #define SUNXI_GPI_SDC3 2 |
6c739c5d PK |
205 | #define SUN7I_GPI_TWI3 3 |
206 | #define SUN7I_GPI_TWI4 3 | |
fe1b4db0 | 207 | |
ce881076 HG |
208 | #define SUN6I_GPL0_R_P2WI_SCK 3 |
209 | #define SUN6I_GPL1_R_P2WI_SDA 3 | |
3b10e6eb | 210 | |
487b3277 | 211 | #define SUN8I_GPL_R_RSB 2 |
9d082687 JW |
212 | #define SUN8I_H3_GPL_R_TWI 2 |
213 | #define SUN8I_A23_GPL_R_TWI 3 | |
487b3277 | 214 | #define SUN8I_GPL_R_UART 2 |
c757a50b | 215 | |
487b3277 | 216 | #define SUN9I_GPN_R_RSB 3 |
d35488c7 | 217 | |
fe1b4db0 IC |
218 | /* GPIO pin pull-up/down config */ |
219 | #define SUNXI_GPIO_PULL_DISABLE 0 | |
220 | #define SUNXI_GPIO_PULL_UP 1 | |
221 | #define SUNXI_GPIO_PULL_DOWN 2 | |
222 | ||
f7c7ab63 | 223 | /* Virtual AXP0 GPIOs */ |
f9b7a04b HG |
224 | #define SUNXI_GPIO_AXP0_PREFIX "AXP0-" |
225 | #define SUNXI_GPIO_AXP0_VBUS_DETECT 4 | |
226 | #define SUNXI_GPIO_AXP0_VBUS_ENABLE 5 | |
227 | #define SUNXI_GPIO_AXP0_GPIO_COUNT 6 | |
f7c7ab63 | 228 | |
bf38891a SG |
229 | void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val); |
230 | void sunxi_gpio_set_cfgpin(u32 pin, u32 val); | |
231 | int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset); | |
fe1b4db0 IC |
232 | int sunxi_gpio_get_cfgpin(u32 pin); |
233 | int sunxi_gpio_set_drv(u32 pin, u32 val); | |
234 | int sunxi_gpio_set_pull(u32 pin, u32 val); | |
8deacca9 | 235 | int sunxi_name_to_gpio_bank(const char *name); |
abce2c62 IC |
236 | int sunxi_name_to_gpio(const char *name); |
237 | #define name_to_gpio(name) sunxi_name_to_gpio(name) | |
fe1b4db0 | 238 | |
2fcf033d HG |
239 | #if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO |
240 | int axp_gpio_init(void); | |
241 | #else | |
242 | static inline int axp_gpio_init(void) { return 0; } | |
243 | #endif | |
244 | ||
fe1b4db0 | 245 | #endif /* _SUNXI_GPIO_H */ |