1fe1b4db0SIan Campbell /* 2fe1b4db0SIan Campbell * (C) Copyright 2007-2012 3fe1b4db0SIan Campbell * Allwinner Technology Co., Ltd. <www.allwinnertech.com> 4fe1b4db0SIan Campbell * Tom Cubie <tangliang@allwinnertech.com> 5fe1b4db0SIan Campbell * 6fe1b4db0SIan Campbell * SPDX-License-Identifier: GPL-2.0+ 7fe1b4db0SIan Campbell */ 8fe1b4db0SIan Campbell 9fe1b4db0SIan Campbell #ifndef _SUNXI_GPIO_H 10fe1b4db0SIan Campbell #define _SUNXI_GPIO_H 11fe1b4db0SIan Campbell 12fe1b4db0SIan Campbell #include <linux/types.h> 13fe1b4db0SIan Campbell 14fe1b4db0SIan Campbell /* 15fe1b4db0SIan Campbell * sunxi has 9 banks of gpio, they are: 16fe1b4db0SIan Campbell * PA0 - PA17 | PB0 - PB23 | PC0 - PC24 17fe1b4db0SIan Campbell * PD0 - PD27 | PE0 - PE31 | PF0 - PF5 18fe1b4db0SIan Campbell * PG0 - PG9 | PH0 - PH27 | PI0 - PI12 19fe1b4db0SIan Campbell */ 20fe1b4db0SIan Campbell 21fe1b4db0SIan Campbell #define SUNXI_GPIO_A 0 22fe1b4db0SIan Campbell #define SUNXI_GPIO_B 1 23fe1b4db0SIan Campbell #define SUNXI_GPIO_C 2 24fe1b4db0SIan Campbell #define SUNXI_GPIO_D 3 25fe1b4db0SIan Campbell #define SUNXI_GPIO_E 4 26fe1b4db0SIan Campbell #define SUNXI_GPIO_F 5 27fe1b4db0SIan Campbell #define SUNXI_GPIO_G 6 28fe1b4db0SIan Campbell #define SUNXI_GPIO_H 7 29fe1b4db0SIan Campbell #define SUNXI_GPIO_I 8 30fe1b4db0SIan Campbell #define SUNXI_GPIO_BANKS 9 31fe1b4db0SIan Campbell 32fe1b4db0SIan Campbell struct sunxi_gpio { 33fe1b4db0SIan Campbell u32 cfg[4]; 34fe1b4db0SIan Campbell u32 dat; 35fe1b4db0SIan Campbell u32 drv[2]; 36fe1b4db0SIan Campbell u32 pull[2]; 37fe1b4db0SIan Campbell }; 38fe1b4db0SIan Campbell 39fe1b4db0SIan Campbell /* gpio interrupt control */ 40fe1b4db0SIan Campbell struct sunxi_gpio_int { 41fe1b4db0SIan Campbell u32 cfg[3]; 42fe1b4db0SIan Campbell u32 ctl; 43fe1b4db0SIan Campbell u32 sta; 44fe1b4db0SIan Campbell u32 deb; /* interrupt debounce */ 45fe1b4db0SIan Campbell }; 46fe1b4db0SIan Campbell 47fe1b4db0SIan Campbell struct sunxi_gpio_reg { 48fe1b4db0SIan Campbell struct sunxi_gpio gpio_bank[SUNXI_GPIO_BANKS]; 49fe1b4db0SIan Campbell u8 res[0xbc]; 50fe1b4db0SIan Campbell struct sunxi_gpio_int gpio_int; 51fe1b4db0SIan Campbell }; 52fe1b4db0SIan Campbell 53fe1b4db0SIan Campbell #define BANK_TO_GPIO(bank) \ 54fe1b4db0SIan Campbell &((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank] 55fe1b4db0SIan Campbell 56fe1b4db0SIan Campbell #define GPIO_BANK(pin) ((pin) >> 5) 57fe1b4db0SIan Campbell #define GPIO_NUM(pin) ((pin) & 0x1f) 58fe1b4db0SIan Campbell 59fe1b4db0SIan Campbell #define GPIO_CFG_INDEX(pin) (((pin) & 0x1f) >> 3) 60fe1b4db0SIan Campbell #define GPIO_CFG_OFFSET(pin) ((((pin) & 0x1f) & 0x7) << 2) 61fe1b4db0SIan Campbell 62fe1b4db0SIan Campbell #define GPIO_DRV_INDEX(pin) (((pin) & 0x1f) >> 4) 63fe1b4db0SIan Campbell #define GPIO_DRV_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1) 64fe1b4db0SIan Campbell 65fe1b4db0SIan Campbell #define GPIO_PULL_INDEX(pin) (((pin) & 0x1f) >> 4) 66fe1b4db0SIan Campbell #define GPIO_PULL_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1) 67fe1b4db0SIan Campbell 68fe1b4db0SIan Campbell /* GPIO bank sizes */ 69fe1b4db0SIan Campbell #define SUNXI_GPIO_A_NR 32 70fe1b4db0SIan Campbell #define SUNXI_GPIO_B_NR 32 71fe1b4db0SIan Campbell #define SUNXI_GPIO_C_NR 32 72fe1b4db0SIan Campbell #define SUNXI_GPIO_D_NR 32 73fe1b4db0SIan Campbell #define SUNXI_GPIO_E_NR 32 74fe1b4db0SIan Campbell #define SUNXI_GPIO_F_NR 32 75fe1b4db0SIan Campbell #define SUNXI_GPIO_G_NR 32 76fe1b4db0SIan Campbell #define SUNXI_GPIO_H_NR 32 77fe1b4db0SIan Campbell #define SUNXI_GPIO_I_NR 32 78fe1b4db0SIan Campbell 79fe1b4db0SIan Campbell #define SUNXI_GPIO_NEXT(__gpio) \ 80fe1b4db0SIan Campbell ((__gpio##_START) + (__gpio##_NR) + 0) 81fe1b4db0SIan Campbell 82fe1b4db0SIan Campbell enum sunxi_gpio_number { 83fe1b4db0SIan Campbell SUNXI_GPIO_A_START = 0, 84fe1b4db0SIan Campbell SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A), 85fe1b4db0SIan Campbell SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B), 86fe1b4db0SIan Campbell SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C), 87fe1b4db0SIan Campbell SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D), 88fe1b4db0SIan Campbell SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E), 89fe1b4db0SIan Campbell SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F), 90fe1b4db0SIan Campbell SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G), 91fe1b4db0SIan Campbell SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H), 92fe1b4db0SIan Campbell }; 93fe1b4db0SIan Campbell 94fe1b4db0SIan Campbell /* SUNXI GPIO number definitions */ 95fe1b4db0SIan Campbell #define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr)) 96fe1b4db0SIan Campbell #define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr)) 97fe1b4db0SIan Campbell #define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr)) 98fe1b4db0SIan Campbell #define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr)) 99fe1b4db0SIan Campbell #define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr)) 100fe1b4db0SIan Campbell #define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr)) 101fe1b4db0SIan Campbell #define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr)) 102fe1b4db0SIan Campbell #define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr)) 103fe1b4db0SIan Campbell #define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr)) 104fe1b4db0SIan Campbell 105fe1b4db0SIan Campbell /* GPIO pin function config */ 106fe1b4db0SIan Campbell #define SUNXI_GPIO_INPUT 0 107fe1b4db0SIan Campbell #define SUNXI_GPIO_OUTPUT 1 108fe1b4db0SIan Campbell 109fe1b4db0SIan Campbell #define SUNXI_GPA0_EMAC 2 110fe1b4db0SIan Campbell #define SUN7I_GPA0_GMAC 5 111fe1b4db0SIan Campbell 112fe1b4db0SIan Campbell #define SUNXI_GPB0_TWI0 2 113fe1b4db0SIan Campbell 114fe1b4db0SIan Campbell #define SUN4I_GPB22_UART0_TX 2 115fe1b4db0SIan Campbell #define SUN4I_GPB23_UART0_RX 2 116fe1b4db0SIan Campbell 117fe1b4db0SIan Campbell #define SUN5I_GPB19_UART0_TX 2 118fe1b4db0SIan Campbell #define SUN5I_GPB20_UART0_RX 2 119fe1b4db0SIan Campbell 120bbff84b3SHans de Goede #define SUN5I_GPG3_SDC1 2 121bbff84b3SHans de Goede 122fe1b4db0SIan Campbell #define SUN5I_GPG3_UART1_TX 4 123fe1b4db0SIan Campbell #define SUN5I_GPG4_UART1_RX 4 124fe1b4db0SIan Campbell 125fe1b4db0SIan Campbell #define SUNXI_GPC6_SDC2 3 126fe1b4db0SIan Campbell 127fe1b4db0SIan Campbell #define SUNXI_GPF0_SDC0 2 128fe1b4db0SIan Campbell 129fe1b4db0SIan Campbell #define SUNXI_GPF2_SDC0 2 130*7f87ad35SChen-Yu Tsai 131*7f87ad35SChen-Yu Tsai #ifdef CONFIG_SUN8I 132*7f87ad35SChen-Yu Tsai #define SUNXI_GPF2_UART0_TX 3 133*7f87ad35SChen-Yu Tsai #define SUNXI_GPF4_UART0_RX 3 134*7f87ad35SChen-Yu Tsai #else 135fe1b4db0SIan Campbell #define SUNXI_GPF2_UART0_TX 4 136fe1b4db0SIan Campbell #define SUNXI_GPF4_UART0_RX 4 137*7f87ad35SChen-Yu Tsai #endif 138fe1b4db0SIan Campbell 139fe1b4db0SIan Campbell #define SUN4I_GPG0_SDC1 4 140fe1b4db0SIan Campbell 141fe1b4db0SIan Campbell #define SUN4I_GPH22_SDC1 5 142fe1b4db0SIan Campbell 143ba1e40fdSChen-Yu Tsai #define SUN6I_GPH20_UART0_TX 2 144ba1e40fdSChen-Yu Tsai #define SUN6I_GPH21_UART0_RX 2 145ba1e40fdSChen-Yu Tsai 146fe1b4db0SIan Campbell #define SUN4I_GPI4_SDC3 2 147fe1b4db0SIan Campbell 148fe1b4db0SIan Campbell /* GPIO pin pull-up/down config */ 149fe1b4db0SIan Campbell #define SUNXI_GPIO_PULL_DISABLE 0 150fe1b4db0SIan Campbell #define SUNXI_GPIO_PULL_UP 1 151fe1b4db0SIan Campbell #define SUNXI_GPIO_PULL_DOWN 2 152fe1b4db0SIan Campbell 153fe1b4db0SIan Campbell int sunxi_gpio_set_cfgpin(u32 pin, u32 val); 154fe1b4db0SIan Campbell int sunxi_gpio_get_cfgpin(u32 pin); 155fe1b4db0SIan Campbell int sunxi_gpio_set_drv(u32 pin, u32 val); 156fe1b4db0SIan Campbell int sunxi_gpio_set_pull(u32 pin, u32 val); 157abce2c62SIan Campbell int sunxi_name_to_gpio(const char *name); 158abce2c62SIan Campbell #define name_to_gpio(name) sunxi_name_to_gpio(name) 159fe1b4db0SIan Campbell 160fe1b4db0SIan Campbell #endif /* _SUNXI_GPIO_H */ 161