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