2018-05-07 05:58:06 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2014-05-05 18:52:24 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2007-2012
|
|
|
|
* Allwinner Technology Co., Ltd. <www.allwinnertech.com>
|
|
|
|
* Tom Cubie <tangliang@allwinnertech.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SUNXI_GPIO_H
|
|
|
|
#define _SUNXI_GPIO_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
2014-10-22 16:47:45 +08:00
|
|
|
#include <asm/arch/cpu.h>
|
2014-05-05 18:52:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sunxi has 9 banks of gpio, they are:
|
|
|
|
* PA0 - PA17 | PB0 - PB23 | PC0 - PC24
|
|
|
|
* PD0 - PD27 | PE0 - PE31 | PF0 - PF5
|
|
|
|
* PG0 - PG9 | PH0 - PH27 | PI0 - PI12
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SUNXI_GPIO_A 0
|
|
|
|
#define SUNXI_GPIO_B 1
|
|
|
|
#define SUNXI_GPIO_C 2
|
|
|
|
#define SUNXI_GPIO_D 3
|
|
|
|
#define SUNXI_GPIO_E 4
|
|
|
|
#define SUNXI_GPIO_F 5
|
|
|
|
#define SUNXI_GPIO_G 6
|
|
|
|
#define SUNXI_GPIO_H 7
|
|
|
|
#define SUNXI_GPIO_I 8
|
2014-10-22 16:47:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This defines the number of GPIO banks for the _main_ GPIO controller.
|
|
|
|
* You should fix up the padding in struct sunxi_gpio_reg below if you
|
|
|
|
* change this.
|
|
|
|
*/
|
2014-05-05 18:52:24 +08:00
|
|
|
#define SUNXI_GPIO_BANKS 9
|
|
|
|
|
2014-10-22 16:47:45 +08:00
|
|
|
/*
|
|
|
|
* sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO)
|
|
|
|
* at a different register offset.
|
|
|
|
*
|
|
|
|
* sun6i has 2 banks:
|
|
|
|
* PL0 - PL8 | PM0 - PM7
|
|
|
|
*
|
|
|
|
* sun8i has 1 bank:
|
|
|
|
* PL0 - PL11
|
2015-01-26 23:46:43 +08:00
|
|
|
*
|
|
|
|
* sun9i has 3 banks:
|
|
|
|
* PL0 - PL9 | PM0 - PM15 | PN0 - PN1
|
2014-10-22 16:47:45 +08:00
|
|
|
*/
|
|
|
|
#define SUNXI_GPIO_L 11
|
|
|
|
#define SUNXI_GPIO_M 12
|
2015-01-26 23:46:43 +08:00
|
|
|
#define SUNXI_GPIO_N 13
|
2014-10-22 16:47:45 +08:00
|
|
|
|
2014-05-05 18:52:24 +08:00
|
|
|
struct sunxi_gpio {
|
|
|
|
u32 cfg[4];
|
|
|
|
u32 dat;
|
|
|
|
u32 drv[2];
|
|
|
|
u32 pull[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* gpio interrupt control */
|
|
|
|
struct sunxi_gpio_int {
|
|
|
|
u32 cfg[3];
|
|
|
|
u32 ctl;
|
|
|
|
u32 sta;
|
|
|
|
u32 deb; /* interrupt debounce */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sunxi_gpio_reg {
|
|
|
|
struct sunxi_gpio gpio_bank[SUNXI_GPIO_BANKS];
|
|
|
|
u8 res[0xbc];
|
|
|
|
struct sunxi_gpio_int gpio_int;
|
|
|
|
};
|
|
|
|
|
2019-04-24 13:44:12 +08:00
|
|
|
#define SUN50I_H6_GPIO_POW_MOD_SEL 0x340
|
|
|
|
#define SUN50I_H6_GPIO_POW_MOD_VAL 0x348
|
|
|
|
|
2014-10-22 16:47:45 +08:00
|
|
|
#define BANK_TO_GPIO(bank) (((bank) < SUNXI_GPIO_L) ? \
|
|
|
|
&((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank] : \
|
|
|
|
&((struct sunxi_gpio_reg *)SUNXI_R_PIO_BASE)->gpio_bank[(bank) - SUNXI_GPIO_L])
|
2014-05-05 18:52:24 +08:00
|
|
|
|
|
|
|
#define GPIO_BANK(pin) ((pin) >> 5)
|
|
|
|
#define GPIO_NUM(pin) ((pin) & 0x1f)
|
|
|
|
|
|
|
|
#define GPIO_CFG_INDEX(pin) (((pin) & 0x1f) >> 3)
|
|
|
|
#define GPIO_CFG_OFFSET(pin) ((((pin) & 0x1f) & 0x7) << 2)
|
|
|
|
|
2015-03-23 01:07:08 +08:00
|
|
|
#define GPIO_DRV_INDEX(pin) (((pin) & 0x1f) >> 4)
|
2014-05-05 18:52:24 +08:00
|
|
|
#define GPIO_DRV_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1)
|
|
|
|
|
|
|
|
#define GPIO_PULL_INDEX(pin) (((pin) & 0x1f) >> 4)
|
|
|
|
#define GPIO_PULL_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1)
|
|
|
|
|
|
|
|
/* GPIO bank sizes */
|
2021-09-12 05:50:49 +08:00
|
|
|
#define SUNXI_GPIOS_PER_BANK 32
|
2014-05-05 18:52:24 +08:00
|
|
|
|
|
|
|
#define SUNXI_GPIO_NEXT(__gpio) \
|
2021-09-12 05:50:49 +08:00
|
|
|
((__gpio##_START) + SUNXI_GPIOS_PER_BANK)
|
2014-05-05 18:52:24 +08:00
|
|
|
|
|
|
|
enum sunxi_gpio_number {
|
|
|
|
SUNXI_GPIO_A_START = 0,
|
|
|
|
SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A),
|
|
|
|
SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B),
|
|
|
|
SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C),
|
|
|
|
SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D),
|
|
|
|
SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E),
|
|
|
|
SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F),
|
|
|
|
SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G),
|
|
|
|
SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H),
|
2014-10-22 16:47:45 +08:00
|
|
|
SUNXI_GPIO_L_START = 352,
|
|
|
|
SUNXI_GPIO_M_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_L),
|
2015-01-26 23:46:43 +08:00
|
|
|
SUNXI_GPIO_N_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_M),
|
2014-12-25 02:34:38 +08:00
|
|
|
SUNXI_GPIO_AXP0_START = 1024,
|
2014-05-05 18:52:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* SUNXI GPIO number definitions */
|
|
|
|
#define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr))
|
|
|
|
#define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr))
|
|
|
|
#define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr))
|
|
|
|
#define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr))
|
|
|
|
#define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr))
|
|
|
|
#define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr))
|
|
|
|
#define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr))
|
|
|
|
#define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr))
|
|
|
|
#define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr))
|
2014-10-22 16:47:45 +08:00
|
|
|
#define SUNXI_GPL(_nr) (SUNXI_GPIO_L_START + (_nr))
|
|
|
|
#define SUNXI_GPM(_nr) (SUNXI_GPIO_M_START + (_nr))
|
2015-01-26 23:46:43 +08:00
|
|
|
#define SUNXI_GPN(_nr) (SUNXI_GPIO_N_START + (_nr))
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2014-12-25 02:34:38 +08:00
|
|
|
#define SUNXI_GPAXP0(_nr) (SUNXI_GPIO_AXP0_START + (_nr))
|
|
|
|
|
2014-05-05 18:52:24 +08:00
|
|
|
/* GPIO pin function config */
|
|
|
|
#define SUNXI_GPIO_INPUT 0
|
|
|
|
#define SUNXI_GPIO_OUTPUT 1
|
2016-06-07 19:28:34 +08:00
|
|
|
#define SUNXI_GPIO_DISABLE 7
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-11-17 22:12:58 +08:00
|
|
|
#define SUN8I_H3_GPA_UART0 2
|
2021-10-09 20:18:59 +08:00
|
|
|
#define SUN8I_H3_GPA_UART2 2
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2016-08-19 21:25:41 +08:00
|
|
|
#define SUN4I_GPB_PWM 2
|
2015-04-11 05:09:52 +08:00
|
|
|
#define SUN4I_GPB_TWI0 2
|
|
|
|
#define SUN4I_GPB_TWI1 2
|
|
|
|
#define SUN5I_GPB_TWI1 2
|
2020-10-26 22:19:34 +08:00
|
|
|
#define SUN8I_V3S_GPB_TWI0 2
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN4I_GPB_UART0 2
|
|
|
|
#define SUN5I_GPB_UART0 2
|
2015-05-06 08:02:00 +08:00
|
|
|
#define SUN8I_GPB_UART2 2
|
2015-06-23 19:57:25 +08:00
|
|
|
#define SUN8I_A33_GPB_UART0 3
|
2015-11-29 01:07:20 +08:00
|
|
|
#define SUN8I_A83T_GPB_UART0 2
|
2017-04-08 15:30:12 +08:00
|
|
|
#define SUN8I_V3S_GPB_UART0 3
|
2016-03-29 23:29:10 +08:00
|
|
|
#define SUN50I_GPB_UART0 4
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-07-23 20:33:01 +08:00
|
|
|
#define SUNXI_GPC_NAND 2
|
2016-06-07 19:28:34 +08:00
|
|
|
#define SUNXI_GPC_SPI0 3
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUNXI_GPC_SDC2 3
|
2015-03-23 01:12:23 +08:00
|
|
|
#define SUN6I_GPC_SDC3 4
|
2016-06-07 19:28:34 +08:00
|
|
|
#define SUN50I_GPC_SPI0 4
|
2022-02-12 08:32:34 +08:00
|
|
|
#define SUNIV_GPC_SPI0 2
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUNXI_GPD_LCD0 2
|
|
|
|
#define SUNXI_GPD_LVDS0 3
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2022-01-29 23:23:03 +08:00
|
|
|
#define SUNIV_GPE_UART0 5
|
2015-03-23 01:12:23 +08:00
|
|
|
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUNXI_GPF_SDC0 2
|
|
|
|
#define SUNXI_GPF_UART0 4
|
|
|
|
#define SUN8I_GPF_UART0 3
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-03-23 01:12:23 +08:00
|
|
|
#define SUN4I_GPG_SDC1 4
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN5I_GPG_SDC1 2
|
2015-03-23 01:12:23 +08:00
|
|
|
#define SUN6I_GPG_SDC1 2
|
|
|
|
#define SUN8I_GPG_SDC1 2
|
2021-02-15 07:19:58 +08:00
|
|
|
#define SUN8I_GPG_UART1 2
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN5I_GPG_UART1 4
|
2014-12-21 23:28:32 +08:00
|
|
|
|
2016-08-19 21:25:41 +08:00
|
|
|
#define SUN6I_GPH_PWM 2
|
|
|
|
#define SUN8I_GPH_PWM 2
|
2015-03-23 01:12:23 +08:00
|
|
|
#define SUN4I_GPH_SDC1 5
|
2015-04-11 05:09:52 +08:00
|
|
|
#define SUN6I_GPH_TWI0 2
|
|
|
|
#define SUN8I_GPH_TWI0 2
|
2019-01-08 18:04:30 +08:00
|
|
|
#define SUN50I_GPH_TWI0 2
|
2015-04-11 05:09:52 +08:00
|
|
|
#define SUN6I_GPH_TWI1 2
|
|
|
|
#define SUN8I_GPH_TWI1 2
|
2019-01-08 18:04:30 +08:00
|
|
|
#define SUN50I_GPH_TWI1 2
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN6I_GPH_UART0 2
|
2015-01-14 02:25:06 +08:00
|
|
|
#define SUN9I_GPH_UART0 2
|
2018-07-21 16:20:28 +08:00
|
|
|
#define SUN50I_H6_GPH_UART0 2
|
2021-01-12 04:11:41 +08:00
|
|
|
#define SUN50I_H616_GPH_UART0 2
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-03-23 01:12:23 +08:00
|
|
|
#define SUNXI_GPI_SDC3 2
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2014-12-13 17:25:14 +08:00
|
|
|
#define SUN6I_GPL0_R_P2WI_SCK 3
|
|
|
|
#define SUN6I_GPL1_R_P2WI_SDA 3
|
2013-07-25 20:07:42 +08:00
|
|
|
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN8I_GPL_R_RSB 2
|
2016-01-14 21:06:26 +08:00
|
|
|
#define SUN8I_H3_GPL_R_TWI 2
|
|
|
|
#define SUN8I_A23_GPL_R_TWI 3
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN8I_GPL_R_UART 2
|
2018-11-06 12:24:30 +08:00
|
|
|
#define SUN50I_GPL_R_TWI 2
|
2021-01-12 04:11:42 +08:00
|
|
|
#define SUN50I_H616_GPL_R_TWI 3
|
2014-10-22 16:47:47 +08:00
|
|
|
|
2015-03-23 01:12:22 +08:00
|
|
|
#define SUN9I_GPN_R_RSB 3
|
2015-01-26 23:46:43 +08:00
|
|
|
|
2014-05-05 18:52:24 +08:00
|
|
|
/* GPIO pin pull-up/down config */
|
|
|
|
#define SUNXI_GPIO_PULL_DISABLE 0
|
|
|
|
#define SUNXI_GPIO_PULL_UP 1
|
|
|
|
#define SUNXI_GPIO_PULL_DOWN 2
|
|
|
|
|
2015-03-23 01:07:09 +08:00
|
|
|
/* Virtual AXP0 GPIOs */
|
2015-04-22 17:31:22 +08:00
|
|
|
#define SUNXI_GPIO_AXP0_PREFIX "AXP0-"
|
|
|
|
#define SUNXI_GPIO_AXP0_VBUS_ENABLE 5
|
|
|
|
#define SUNXI_GPIO_AXP0_GPIO_COUNT 6
|
2015-03-23 01:07:09 +08:00
|
|
|
|
2021-08-13 09:09:43 +08:00
|
|
|
struct sunxi_gpio_plat {
|
|
|
|
struct sunxi_gpio *regs;
|
|
|
|
char bank_name[3];
|
|
|
|
};
|
|
|
|
|
2014-10-31 10:25:47 +08:00
|
|
|
void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
|
|
|
|
void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
|
|
|
|
int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset);
|
2014-05-05 18:52:24 +08:00
|
|
|
int sunxi_gpio_get_cfgpin(u32 pin);
|
2021-10-21 12:52:54 +08:00
|
|
|
void sunxi_gpio_set_drv(u32 pin, u32 val);
|
2021-10-21 12:52:55 +08:00
|
|
|
void sunxi_gpio_set_drv_bank(struct sunxi_gpio *pio, u32 bank_offset, u32 val);
|
2021-10-21 12:52:54 +08:00
|
|
|
void sunxi_gpio_set_pull(u32 pin, u32 val);
|
2021-10-21 12:52:55 +08:00
|
|
|
void sunxi_gpio_set_pull_bank(struct sunxi_gpio *pio, int bank_offset, u32 val);
|
2014-06-06 02:00:15 +08:00
|
|
|
int sunxi_name_to_gpio(const char *name);
|
2014-05-05 18:52:24 +08:00
|
|
|
|
2015-04-25 23:25:14 +08:00
|
|
|
#if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
|
|
|
|
int axp_gpio_init(void);
|
|
|
|
#else
|
|
|
|
static inline int axp_gpio_init(void) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 18:52:24 +08:00
|
|
|
#endif /* _SUNXI_GPIO_H */
|