Path: blob/master/arch/arm/mach-pxa/include/mach/gpio.h
10820 views
/*1* arch/arm/mach-pxa/include/mach/gpio.h2*3* PXA GPIO wrappers for arch-neutral GPIO calls4*5* Written by Philipp Zabel <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20*21*/2223#ifndef __ASM_ARCH_PXA_GPIO_H24#define __ASM_ARCH_PXA_GPIO_H2526#include <mach/irqs.h>27#include <mach/hardware.h>28#include <asm-generic/gpio.h>2930#define GPIO_REGS_VIRT io_p2v(0x40E00000)3132#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))33#define GPIO_REG(x) (*(volatile u32 *)(GPIO_REGS_VIRT + (x)))3435/* GPIO Pin Level Registers */36#define GPLR0 GPIO_REG(BANK_OFF(0) + 0x00)37#define GPLR1 GPIO_REG(BANK_OFF(1) + 0x00)38#define GPLR2 GPIO_REG(BANK_OFF(2) + 0x00)39#define GPLR3 GPIO_REG(BANK_OFF(3) + 0x00)4041/* GPIO Pin Direction Registers */42#define GPDR0 GPIO_REG(BANK_OFF(0) + 0x0c)43#define GPDR1 GPIO_REG(BANK_OFF(1) + 0x0c)44#define GPDR2 GPIO_REG(BANK_OFF(2) + 0x0c)45#define GPDR3 GPIO_REG(BANK_OFF(3) + 0x0c)4647/* GPIO Pin Output Set Registers */48#define GPSR0 GPIO_REG(BANK_OFF(0) + 0x18)49#define GPSR1 GPIO_REG(BANK_OFF(1) + 0x18)50#define GPSR2 GPIO_REG(BANK_OFF(2) + 0x18)51#define GPSR3 GPIO_REG(BANK_OFF(3) + 0x18)5253/* GPIO Pin Output Clear Registers */54#define GPCR0 GPIO_REG(BANK_OFF(0) + 0x24)55#define GPCR1 GPIO_REG(BANK_OFF(1) + 0x24)56#define GPCR2 GPIO_REG(BANK_OFF(2) + 0x24)57#define GPCR3 GPIO_REG(BANK_OFF(3) + 0x24)5859/* GPIO Rising Edge Detect Registers */60#define GRER0 GPIO_REG(BANK_OFF(0) + 0x30)61#define GRER1 GPIO_REG(BANK_OFF(1) + 0x30)62#define GRER2 GPIO_REG(BANK_OFF(2) + 0x30)63#define GRER3 GPIO_REG(BANK_OFF(3) + 0x30)6465/* GPIO Falling Edge Detect Registers */66#define GFER0 GPIO_REG(BANK_OFF(0) + 0x3c)67#define GFER1 GPIO_REG(BANK_OFF(1) + 0x3c)68#define GFER2 GPIO_REG(BANK_OFF(2) + 0x3c)69#define GFER3 GPIO_REG(BANK_OFF(3) + 0x3c)7071/* GPIO Edge Detect Status Registers */72#define GEDR0 GPIO_REG(BANK_OFF(0) + 0x48)73#define GEDR1 GPIO_REG(BANK_OFF(1) + 0x48)74#define GEDR2 GPIO_REG(BANK_OFF(2) + 0x48)75#define GEDR3 GPIO_REG(BANK_OFF(3) + 0x48)7677/* GPIO Alternate Function Select Registers */78#define GAFR0_L GPIO_REG(0x0054)79#define GAFR0_U GPIO_REG(0x0058)80#define GAFR1_L GPIO_REG(0x005C)81#define GAFR1_U GPIO_REG(0x0060)82#define GAFR2_L GPIO_REG(0x0064)83#define GAFR2_U GPIO_REG(0x0068)84#define GAFR3_L GPIO_REG(0x006C)85#define GAFR3_U GPIO_REG(0x0070)8687/* More handy macros. The argument is a literal GPIO number. */8889#define GPIO_bit(x) (1 << ((x) & 0x1f))9091#define GPLR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x00)92#define GPDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x0c)93#define GPSR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x18)94#define GPCR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x24)95#define GRER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x30)96#define GFER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x3c)97#define GEDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x48)98#define GAFR(x) GPIO_REG(0x54 + (((x) & 0x70) >> 2))99100101#define NR_BUILTIN_GPIO PXA_GPIO_IRQ_NUM102103#define gpio_to_bank(gpio) ((gpio) >> 5)104#define gpio_to_irq(gpio) IRQ_GPIO(gpio)105106static inline int irq_to_gpio(unsigned int irq)107{108int gpio;109110if (irq == IRQ_GPIO0 || irq == IRQ_GPIO1)111return irq - IRQ_GPIO0;112113gpio = irq - PXA_GPIO_IRQ_BASE;114if (gpio >= 2 && gpio < NR_BUILTIN_GPIO)115return gpio;116117return -1;118}119120#ifdef CONFIG_CPU_PXA26x121/* GPIO86/87/88/89 on PXA26x have their direction bits in GPDR2 inverted,122* as well as their Alternate Function value being '1' for GPIO in GAFRx.123*/124static inline int __gpio_is_inverted(unsigned gpio)125{126return cpu_is_pxa25x() && gpio > 85;127}128#else129static inline int __gpio_is_inverted(unsigned gpio) { return 0; }130#endif131132/*133* On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate134* function of a GPIO, and GPDRx cannot be altered once configured. It135* is attributed as "occupied" here (I know this terminology isn't136* accurate, you are welcome to propose a better one :-)137*/138static inline int __gpio_is_occupied(unsigned gpio)139{140if (cpu_is_pxa27x() || cpu_is_pxa25x()) {141int af = (GAFR(gpio) >> ((gpio & 0xf) * 2)) & 0x3;142int dir = GPDR(gpio) & GPIO_bit(gpio);143144if (__gpio_is_inverted(gpio))145return af != 1 || dir == 0;146else147return af != 0 || dir != 0;148} else149return GPDR(gpio) & GPIO_bit(gpio);150}151152#include <plat/gpio.h>153#endif154155156