blob: db3742c039703e68c2e1883f9937b47f7475bf05 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Ian Campbellb2765ec2014-05-05 11:52:24 +01002/*
3 * (C) Copyright 2007-2012
4 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
5 * Tom Cubie <tangliang@allwinnertech.com>
Andre Przywara82d307c2022-09-06 10:36:38 +01006 *
7 * Definitions that are shared between the Allwinner pinctrl and GPIO drivers,
8 * also used by some non-DM SPL code directly.
Ian Campbellb2765ec2014-05-05 11:52:24 +01009 */
10
11#ifndef _SUNXI_GPIO_H
12#define _SUNXI_GPIO_H
13
14#include <linux/types.h>
Andre Przywara1191f382022-09-06 11:50:54 +010015
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
Andre Przywara068962b2022-10-05 17:54:19 +010022#elif defined(CONFIG_SUNXI_GEN_NCAT2)
23#define SUNXI_PIO_BASE 0x02000000
24#define SUNXI_R_PIO_BASE 0x07022000
Andre Przywara1191f382022-09-06 11:50:54 +010025#else
26#define SUNXI_PIO_BASE 0x01c20800
27#define SUNXI_R_PIO_BASE 0x01f02c00
28#endif
Ian Campbellb2765ec2014-05-05 11:52:24 +010029
30/*
31 * sunxi has 9 banks of gpio, they are:
32 * PA0 - PA17 | PB0 - PB23 | PC0 - PC24
33 * PD0 - PD27 | PE0 - PE31 | PF0 - PF5
34 * PG0 - PG9 | PH0 - PH27 | PI0 - PI12
35 */
36
37#define SUNXI_GPIO_A 0
38#define SUNXI_GPIO_B 1
39#define SUNXI_GPIO_C 2
40#define SUNXI_GPIO_D 3
41#define SUNXI_GPIO_E 4
42#define SUNXI_GPIO_F 5
43#define SUNXI_GPIO_G 6
44#define SUNXI_GPIO_H 7
45#define SUNXI_GPIO_I 8
Hans de Goede0ee72682014-10-22 16:47:45 +080046
47/*
Hans de Goede0ee72682014-10-22 16:47:45 +080048 * sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO)
49 * at a different register offset.
50 *
51 * sun6i has 2 banks:
52 * PL0 - PL8 | PM0 - PM7
53 *
54 * sun8i has 1 bank:
55 * PL0 - PL11
Hans de Goede8760c912015-01-26 16:46:43 +010056 *
57 * sun9i has 3 banks:
58 * PL0 - PL9 | PM0 - PM15 | PN0 - PN1
Hans de Goede0ee72682014-10-22 16:47:45 +080059 */
60#define SUNXI_GPIO_L 11
61#define SUNXI_GPIO_M 12
Hans de Goede8760c912015-01-26 16:46:43 +010062#define SUNXI_GPIO_N 13
Hans de Goede0ee72682014-10-22 16:47:45 +080063
Icenowy Zheng112c8862019-04-24 13:44:12 +080064#define SUN50I_H6_GPIO_POW_MOD_SEL 0x340
65#define SUN50I_H6_GPIO_POW_MOD_VAL 0x348
66
Samuel Hollande93ea432021-09-11 16:50:49 -050067#define SUNXI_GPIOS_PER_BANK 32
Ian Campbellb2765ec2014-05-05 11:52:24 +010068
69#define SUNXI_GPIO_NEXT(__gpio) \
Samuel Hollande93ea432021-09-11 16:50:49 -050070 ((__gpio##_START) + SUNXI_GPIOS_PER_BANK)
Ian Campbellb2765ec2014-05-05 11:52:24 +010071
72enum sunxi_gpio_number {
73 SUNXI_GPIO_A_START = 0,
74 SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A),
75 SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B),
76 SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C),
77 SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D),
78 SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E),
79 SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F),
80 SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G),
81 SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H),
Hans de Goede0ee72682014-10-22 16:47:45 +080082 SUNXI_GPIO_L_START = 352,
83 SUNXI_GPIO_M_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_L),
Hans de Goede8760c912015-01-26 16:46:43 +010084 SUNXI_GPIO_N_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_M),
Hans de Goede1fc9c4a2014-12-24 19:34:38 +010085 SUNXI_GPIO_AXP0_START = 1024,
Ian Campbellb2765ec2014-05-05 11:52:24 +010086};
87
88/* SUNXI GPIO number definitions */
89#define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr))
90#define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr))
91#define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr))
92#define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr))
93#define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr))
94#define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr))
95#define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr))
96#define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr))
97#define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr))
Hans de Goede0ee72682014-10-22 16:47:45 +080098#define SUNXI_GPL(_nr) (SUNXI_GPIO_L_START + (_nr))
99#define SUNXI_GPM(_nr) (SUNXI_GPIO_M_START + (_nr))
Hans de Goede8760c912015-01-26 16:46:43 +0100100#define SUNXI_GPN(_nr) (SUNXI_GPIO_N_START + (_nr))
Ian Campbellb2765ec2014-05-05 11:52:24 +0100101
Hans de Goede1fc9c4a2014-12-24 19:34:38 +0100102#define SUNXI_GPAXP0(_nr) (SUNXI_GPIO_AXP0_START + (_nr))
103
Ian Campbellb2765ec2014-05-05 11:52:24 +0100104/* GPIO pin function config */
105#define SUNXI_GPIO_INPUT 0
106#define SUNXI_GPIO_OUTPUT 1
107
Jens Kuskef9770722015-11-17 15:12:58 +0100108#define SUN8I_H3_GPA_UART0 2
Angelo Dureghello47263bd2021-10-09 14:18:59 +0200109#define SUN8I_H3_GPA_UART2 2
Ian Campbellb2765ec2014-05-05 11:52:24 +0100110
Hans de Goede663ae652016-08-19 15:25:41 +0200111#define SUN4I_GPB_PWM 2
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200112#define SUN4I_GPB_TWI0 2
113#define SUN4I_GPB_TWI1 2
114#define SUN5I_GPB_TWI1 2
Icenowy Zheng365951a2020-10-26 22:19:34 +0800115#define SUN8I_V3S_GPB_TWI0 2
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100116#define SUN4I_GPB_UART0 2
117#define SUN5I_GPB_UART0 2
Laurent Itti20dfe002015-05-05 17:02:00 -0700118#define SUN8I_GPB_UART2 2
Chen-Yu Tsai28b71922015-06-23 19:57:25 +0800119#define SUN8I_A33_GPB_UART0 3
vishnupatekar133bfbe2015-11-29 01:07:20 +0800120#define SUN8I_A83T_GPB_UART0 2
Icenowy Zheng52e61882017-04-08 15:30:12 +0800121#define SUN8I_V3S_GPB_UART0 3
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200122#define SUN50I_GPB_UART0 4
Ian Campbellb2765ec2014-05-05 11:52:24 +0100123
Karol Gugala7bea8932015-07-23 14:33:01 +0200124#define SUNXI_GPC_NAND 2
Siarhei Siamashka6f3ea202016-06-07 14:28:34 +0300125#define SUNXI_GPC_SPI0 3
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100126#define SUNXI_GPC_SDC2 3
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100127#define SUN6I_GPC_SDC3 4
Siarhei Siamashka6f3ea202016-06-07 14:28:34 +0300128#define SUN50I_GPC_SPI0 4
Jesse Taubeea3cbc62022-02-11 19:32:34 -0500129#define SUNIV_GPC_SPI0 2
Ian Campbellb2765ec2014-05-05 11:52:24 +0100130
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100131#define SUNXI_GPD_LCD0 2
132#define SUNXI_GPD_LVDS0 3
Ian Campbellb2765ec2014-05-05 11:52:24 +0100133
Icenowy Zheng015051d2022-01-29 10:23:03 -0500134#define SUNIV_GPE_UART0 5
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100135
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100136#define SUNXI_GPF_SDC0 2
137#define SUNXI_GPF_UART0 4
138#define SUN8I_GPF_UART0 3
Ian Campbellb2765ec2014-05-05 11:52:24 +0100139
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100140#define SUN4I_GPG_SDC1 4
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100141#define SUN5I_GPG_SDC1 2
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100142#define SUN6I_GPG_SDC1 2
143#define SUN8I_GPG_SDC1 2
Tobias Schramm6892a562021-02-15 00:19:58 +0100144#define SUN8I_GPG_UART1 2
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100145#define SUN5I_GPG_UART1 4
Hans de Goede7e68a1b2014-12-21 16:28:32 +0100146
Hans de Goede663ae652016-08-19 15:25:41 +0200147#define SUN6I_GPH_PWM 2
148#define SUN8I_GPH_PWM 2
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100149#define SUN4I_GPH_SDC1 5
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200150#define SUN6I_GPH_TWI0 2
151#define SUN8I_GPH_TWI0 2
Stefan Mavrodievcabe9922019-01-08 12:04:30 +0200152#define SUN50I_GPH_TWI0 2
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200153#define SUN6I_GPH_TWI1 2
154#define SUN8I_GPH_TWI1 2
Stefan Mavrodievcabe9922019-01-08 12:04:30 +0200155#define SUN50I_GPH_TWI1 2
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100156#define SUN6I_GPH_UART0 2
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100157#define SUN9I_GPH_UART0 2
Icenowy Zhenga78bb072018-07-21 16:20:28 +0800158#define SUN50I_H6_GPH_UART0 2
Jernej Skrabec30efb9d2021-01-11 21:11:41 +0100159#define SUN50I_H616_GPH_UART0 2
Ian Campbellb2765ec2014-05-05 11:52:24 +0100160
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100161#define SUNXI_GPI_SDC3 2
Ian Campbellb2765ec2014-05-05 11:52:24 +0100162
Hans de Goede7c590382014-12-13 10:25:14 +0100163#define SUN6I_GPL0_R_P2WI_SCK 3
164#define SUN6I_GPL1_R_P2WI_SDA 3
Oliver Schinagl4f9a0082013-07-25 14:07:42 +0200165
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100166#define SUN8I_GPL_R_RSB 2
Jelle van der Waa8d3d7c12016-01-14 14:06:26 +0100167#define SUN8I_H3_GPL_R_TWI 2
168#define SUN8I_A23_GPL_R_TWI 3
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100169#define SUN8I_GPL_R_UART 2
Vasily Khoruzhick6f4c3442018-11-05 20:24:30 -0800170#define SUN50I_GPL_R_TWI 2
Jernej Skrabec7de8eb02021-01-11 21:11:42 +0100171#define SUN50I_H616_GPL_R_TWI 3
Chen-Yu Tsai6ee63882014-10-22 16:47:47 +0800172
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100173#define SUN9I_GPN_R_RSB 3
Hans de Goede8760c912015-01-26 16:46:43 +0100174
Andre Przywaraf6ad5102022-09-06 12:12:50 +0100175#ifdef CONFIG_SUNXI_NEW_PINCTRL
176 #define SUNXI_PINCTRL_BANK_SIZE 0x30
177 #define SUNXI_GPIO_DISABLE 0xf
178#else
179 #define SUNXI_PINCTRL_BANK_SIZE 0x24
180 #define SUNXI_GPIO_DISABLE 0x7
181#endif
182
Ian Campbellb2765ec2014-05-05 11:52:24 +0100183/* GPIO pin pull-up/down config */
184#define SUNXI_GPIO_PULL_DISABLE 0
185#define SUNXI_GPIO_PULL_UP 1
186#define SUNXI_GPIO_PULL_DOWN 2
187
Paul Kocialkowski6604a132015-03-22 18:07:09 +0100188/* Virtual AXP0 GPIOs */
Hans de Goede08607d12015-04-22 11:31:22 +0200189#define SUNXI_GPIO_AXP0_PREFIX "AXP0-"
Hans de Goede08607d12015-04-22 11:31:22 +0200190#define SUNXI_GPIO_AXP0_VBUS_ENABLE 5
191#define SUNXI_GPIO_AXP0_GPIO_COUNT 6
Paul Kocialkowski6604a132015-03-22 18:07:09 +0100192
Samuel Hollande3095022021-08-12 20:09:43 -0500193struct sunxi_gpio_plat {
Andre Przywara841ebfb32022-09-05 18:12:39 +0100194 void *regs;
Samuel Hollande3095022021-08-12 20:09:43 -0500195 char bank_name[3];
196};
197
Andre Przywara82d307c2022-09-06 10:36:38 +0100198/* prototypes for the non-DM GPIO/pinctrl functions, used in the SPL */
Andre Przywara841ebfb32022-09-05 18:12:39 +0100199void sunxi_gpio_set_cfgbank(void *bank_base, int pin_offset, u32 val);
Simon Glassd8624532014-10-30 20:25:47 -0600200void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
Andre Przywara841ebfb32022-09-05 18:12:39 +0100201int sunxi_gpio_get_cfgbank(void *bank_base, int pin_offset);
Ian Campbellb2765ec2014-05-05 11:52:24 +0100202int sunxi_gpio_get_cfgpin(u32 pin);
Samuel Holland41abadc2021-10-20 23:52:54 -0500203void sunxi_gpio_set_drv(u32 pin, u32 val);
Andre Przywara841ebfb32022-09-05 18:12:39 +0100204void sunxi_gpio_set_drv_bank(void *bank_base, u32 pin_offset, u32 val);
Samuel Holland41abadc2021-10-20 23:52:54 -0500205void sunxi_gpio_set_pull(u32 pin, u32 val);
Andre Przywara841ebfb32022-09-05 18:12:39 +0100206void sunxi_gpio_set_pull_bank(void *bank_base, int pin_offset, u32 val);
Ian Campbellaf471472014-06-05 19:00:15 +0100207int sunxi_name_to_gpio(const char *name);
Ian Campbellb2765ec2014-05-05 11:52:24 +0100208
Hans de Goede3ae1d132015-04-25 17:25:14 +0200209#if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
210int axp_gpio_init(void);
211#else
212static inline int axp_gpio_init(void) { return 0; }
213#endif
214
Ian Campbellb2765ec2014-05-05 11:52:24 +0100215#endif /* _SUNXI_GPIO_H */