···11-/*22- * Written by Philipp Zabel <philipp.zabel@gmail.com>33- *44- * This program is free software; you can redistribute it and/or modify55- * it under the terms of the GNU General Public License as published by66- * the Free Software Foundation; either version 2 of the License, or77- * (at your option) any later version.88- *99- * This program is distributed in the hope that it will be useful,1010- * but WITHOUT ANY WARRANTY; without even the implied warranty of1111- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212- * GNU General Public License for more details.1313- *1414- * You should have received a copy of the GNU General Public License1515- * along with this program; if not, write to the Free Software1616- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA1717- *1818- */1919-#ifndef __MACH_PXA_GPIO_PXA_H2020-#define __MACH_PXA_GPIO_PXA_H2121-2222-#include <mach/irqs.h>2323-#include <mach/hardware.h>2424-2525-#define GPIO_REGS_VIRT io_p2v(0x40E00000)2626-2727-#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))2828-#define GPIO_REG(x) (*(volatile u32 *)(GPIO_REGS_VIRT + (x)))2929-3030-/* GPIO Pin Level Registers */3131-#define GPLR0 GPIO_REG(BANK_OFF(0) + 0x00)3232-#define GPLR1 GPIO_REG(BANK_OFF(1) + 0x00)3333-#define GPLR2 GPIO_REG(BANK_OFF(2) + 0x00)3434-#define GPLR3 GPIO_REG(BANK_OFF(3) + 0x00)3535-3636-/* GPIO Pin Direction Registers */3737-#define GPDR0 GPIO_REG(BANK_OFF(0) + 0x0c)3838-#define GPDR1 GPIO_REG(BANK_OFF(1) + 0x0c)3939-#define GPDR2 GPIO_REG(BANK_OFF(2) + 0x0c)4040-#define GPDR3 GPIO_REG(BANK_OFF(3) + 0x0c)4141-4242-/* GPIO Pin Output Set Registers */4343-#define GPSR0 GPIO_REG(BANK_OFF(0) + 0x18)4444-#define GPSR1 GPIO_REG(BANK_OFF(1) + 0x18)4545-#define GPSR2 GPIO_REG(BANK_OFF(2) + 0x18)4646-#define GPSR3 GPIO_REG(BANK_OFF(3) + 0x18)4747-4848-/* GPIO Pin Output Clear Registers */4949-#define GPCR0 GPIO_REG(BANK_OFF(0) + 0x24)5050-#define GPCR1 GPIO_REG(BANK_OFF(1) + 0x24)5151-#define GPCR2 GPIO_REG(BANK_OFF(2) + 0x24)5252-#define GPCR3 GPIO_REG(BANK_OFF(3) + 0x24)5353-5454-/* GPIO Rising Edge Detect Registers */5555-#define GRER0 GPIO_REG(BANK_OFF(0) + 0x30)5656-#define GRER1 GPIO_REG(BANK_OFF(1) + 0x30)5757-#define GRER2 GPIO_REG(BANK_OFF(2) + 0x30)5858-#define GRER3 GPIO_REG(BANK_OFF(3) + 0x30)5959-6060-/* GPIO Falling Edge Detect Registers */6161-#define GFER0 GPIO_REG(BANK_OFF(0) + 0x3c)6262-#define GFER1 GPIO_REG(BANK_OFF(1) + 0x3c)6363-#define GFER2 GPIO_REG(BANK_OFF(2) + 0x3c)6464-#define GFER3 GPIO_REG(BANK_OFF(3) + 0x3c)6565-6666-/* GPIO Edge Detect Status Registers */6767-#define GEDR0 GPIO_REG(BANK_OFF(0) + 0x48)6868-#define GEDR1 GPIO_REG(BANK_OFF(1) + 0x48)6969-#define GEDR2 GPIO_REG(BANK_OFF(2) + 0x48)7070-#define GEDR3 GPIO_REG(BANK_OFF(3) + 0x48)7171-7272-/* GPIO Alternate Function Select Registers */7373-#define GAFR0_L GPIO_REG(0x0054)7474-#define GAFR0_U GPIO_REG(0x0058)7575-#define GAFR1_L GPIO_REG(0x005C)7676-#define GAFR1_U GPIO_REG(0x0060)7777-#define GAFR2_L GPIO_REG(0x0064)7878-#define GAFR2_U GPIO_REG(0x0068)7979-#define GAFR3_L GPIO_REG(0x006C)8080-#define GAFR3_U GPIO_REG(0x0070)8181-8282-/* More handy macros. The argument is a literal GPIO number. */8383-8484-#define GPIO_bit(x) (1 << ((x) & 0x1f))8585-8686-#define GPLR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x00)8787-#define GPDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x0c)8888-#define GPSR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x18)8989-#define GPCR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x24)9090-#define GRER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x30)9191-#define GFER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x3c)9292-#define GEDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x48)9393-#define GAFR(x) GPIO_REG(0x54 + (((x) & 0x70) >> 2))9494-9595-9696-#define gpio_to_bank(gpio) ((gpio) >> 5)9797-9898-#ifdef CONFIG_CPU_PXA26x9999-/* GPIO86/87/88/89 on PXA26x have their direction bits in GPDR2 inverted,100100- * as well as their Alternate Function value being '1' for GPIO in GAFRx.101101- */102102-static inline int __gpio_is_inverted(unsigned gpio)103103-{104104- return cpu_is_pxa25x() && gpio > 85;105105-}106106-#else107107-static inline int __gpio_is_inverted(unsigned gpio) { return 0; }108108-#endif109109-110110-/*111111- * On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate112112- * function of a GPIO, and GPDRx cannot be altered once configured. It113113- * is attributed as "occupied" here (I know this terminology isn't114114- * accurate, you are welcome to propose a better one :-)115115- */116116-static inline int __gpio_is_occupied(unsigned gpio)117117-{118118- if (cpu_is_pxa27x() || cpu_is_pxa25x()) {119119- int af = (GAFR(gpio) >> ((gpio & 0xf) * 2)) & 0x3;120120- int dir = GPDR(gpio) & GPIO_bit(gpio);121121-122122- if (__gpio_is_inverted(gpio))123123- return af != 1 || dir == 0;124124- else125125- return af != 0 || dir != 0;126126- } else127127- return GPDR(gpio) & GPIO_bit(gpio);128128-}129129-130130-#include <plat/gpio-pxa.h>131131-#endif /* __MACH_PXA_GPIO_PXA_H */
+3-2
arch/arm/mach-pxa/include/mach/gpio.h
···2525#define __ASM_ARCH_PXA_GPIO_H26262727#include <asm-generic/gpio.h>2828-/* The defines for the driver are needed for the accelerated accessors */2929-#include "gpio-pxa.h"2828+2929+#include <mach/irqs.h>3030+#include <mach/hardware.h>30313132#endif
-2
arch/arm/mach-pxa/include/mach/idp.h
···131131#define PCC_VS2 (1 << 1)132132#define PCC_VS1 (1 << 0)133133134134-#define PCC_DETECT(x) (GPLR(7 + (x)) & GPIO_bit(7 + (x)))135135-136134/* A listing of interrupts used by external hardware devices */137135138136#define TOUCH_PANEL_IRQ PXA_GPIO_TO_IRQ(5)
···11-#ifndef __PLAT_PXA_GPIO_H22-#define __PLAT_PXA_GPIO_H33-44-struct irq_data;55-66-/*77- * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with88- * one set of registers. The register offsets are organized below:99- *1010- * GPLR GPDR GPSR GPCR GRER GFER GEDR1111- * BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x00481212- * BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C1313- * BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x00501414- *1515- * BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x01481616- * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C1717- * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x01501818- *1919- * NOTE:2020- * BANK 3 is only available on PXA27x and later processors.2121- * BANK 4 and 5 are only available on PXA9352222- */2323-2424-#define GPIO_BANK(n) (GPIO_REGS_VIRT + BANK_OFF(n))2525-2626-#define GPLR_OFFSET 0x002727-#define GPDR_OFFSET 0x0C2828-#define GPSR_OFFSET 0x182929-#define GPCR_OFFSET 0x243030-#define GRER_OFFSET 0x303131-#define GFER_OFFSET 0x3C3232-#define GEDR_OFFSET 0x483333-3434-/* NOTE: some PXAs have fewer on-chip GPIOs (like PXA255, with 85).3535- * Those cases currently cause holes in the GPIO number space, the3636- * actual number of the last GPIO is recorded by 'pxa_last_gpio'.3737- */3838-extern int pxa_last_gpio;3939-4040-typedef int (*set_wake_t)(struct irq_data *d, unsigned int on);4141-4242-extern void pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn);4343-extern int pxa_irq_to_gpio(int irq);4444-4545-#endif /* __PLAT_PXA_GPIO_H */
+6
drivers/gpio/Kconfig
···141141 help142142 Say yes here to support the PrimeCell PL061 GPIO device143143144144+config GPIO_PXA145145+ bool "PXA GPIO support"146146+ depends on ARCH_PXA || ARCH_MMP147147+ help148148+ Say yes here to support the PXA GPIO device149149+144150config GPIO_XILINX145151 bool "Xilinx GPIO support"146152 depends on PPC_OF || MICROBLAZE
···1212 * published by the Free Software Foundation.1313 */1414#include <linux/gpio.h>1515+#include <linux/gpio-pxa.h>1516#include <linux/init.h>1617#include <linux/irq.h>1718#include <linux/io.h>1919+#include <linux/platform_device.h>1820#include <linux/syscore_ops.h>1921#include <linux/slab.h>20222121-#include <mach/gpio-pxa.h>2323+/*2424+ * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with2525+ * one set of registers. The register offsets are organized below:2626+ *2727+ * GPLR GPDR GPSR GPCR GRER GFER GEDR2828+ * BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x00482929+ * BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C3030+ * BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x00503131+ *3232+ * BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x01483333+ * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C3434+ * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x01503535+ *3636+ * NOTE:3737+ * BANK 3 is only available on PXA27x and later processors.3838+ * BANK 4 and 5 are only available on PXA9353939+ */4040+4141+#define GPLR_OFFSET 0x004242+#define GPDR_OFFSET 0x0C4343+#define GPSR_OFFSET 0x184444+#define GPCR_OFFSET 0x244545+#define GRER_OFFSET 0x304646+#define GFER_OFFSET 0x3C4747+#define GEDR_OFFSET 0x484848+#define GAFR_OFFSET 0x544949+5050+#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))22512352int pxa_last_gpio;2453···8152static DEFINE_SPINLOCK(gpio_lock);8253static struct pxa_gpio_chip *pxa_gpio_chips;8354static int gpio_type;5555+static void __iomem *gpio_reg_base;84568557#define for_each_gpio_chip(i, c) \8658 for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++)···10474static inline int gpio_is_mmp_type(int type)10575{10676 return (type & MMP_GPIO) != 0;7777+}7878+7979+/* GPIO86/87/88/89 on PXA26x have their direction bits in PXA_GPDR(2 inverted,8080+ * as well as their Alternate Function value being '1' for GPIO in GAFRx.8181+ */8282+static inline int __gpio_is_inverted(int gpio)8383+{8484+ if ((gpio_type == PXA26X_GPIO) && (gpio > 85))8585+ return 1;8686+ return 0;8787+}8888+8989+/*9090+ * On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate9191+ * function of a GPIO, and GPDRx cannot be altered once configured. It9292+ * is attributed as "occupied" here (I know this terminology isn't9393+ * accurate, you are welcome to propose a better one :-)9494+ */9595+static inline int __gpio_is_occupied(unsigned gpio)9696+{9797+ struct pxa_gpio_chip *pxachip;9898+ void __iomem *base;9999+ unsigned long gafr = 0, gpdr = 0;100100+ int ret, af = 0, dir = 0;101101+102102+ pxachip = gpio_to_pxachip(gpio);103103+ base = gpio_chip_base(&pxachip->chip);104104+ gpdr = readl_relaxed(base + GPDR_OFFSET);105105+106106+ switch (gpio_type) {107107+ case PXA25X_GPIO:108108+ case PXA26X_GPIO:109109+ case PXA27X_GPIO:110110+ gafr = readl_relaxed(base + GAFR_OFFSET);111111+ af = (gafr >> ((gpio & 0xf) * 2)) & 0x3;112112+ dir = gpdr & GPIO_bit(gpio);113113+114114+ if (__gpio_is_inverted(gpio))115115+ ret = (af != 1) || (dir == 0);116116+ else117117+ ret = (af != 0) || (dir != 0);118118+ break;119119+ default:120120+ ret = gpdr & GPIO_bit(gpio);121121+ break;122122+ }123123+ return ret;107124}108125109126#ifdef CONFIG_ARCH_PXA···264187 (value ? GPSR_OFFSET : GPCR_OFFSET));265188}266189267267-static int __init pxa_init_gpio_chip(int gpio_end)190190+static int __devinit pxa_init_gpio_chip(int gpio_end)268191{269192 int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1;270193 struct pxa_gpio_chip *chips;···279202 struct gpio_chip *c = &chips[i].chip;280203281204 sprintf(chips[i].label, "gpio-%d", i);282282- chips[i].regbase = GPIO_BANK(i);205205+ chips[i].regbase = gpio_reg_base + BANK_OFF(i);283206284207 c->base = gpio;285208 c->label = chips[i].label;···461384 return count;462385}463386464464-void __init pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn)387387+static int __devinit pxa_gpio_probe(struct platform_device *pdev)465388{466389 struct pxa_gpio_chip *c;390390+ struct resource *res;467391 int gpio, irq;392392+ int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;468393469394 pxa_last_gpio = pxa_gpio_nums();470395 if (!pxa_last_gpio)471471- return;396396+ return -EINVAL;397397+398398+ irq0 = platform_get_irq_byname(pdev, "gpio0");399399+ irq1 = platform_get_irq_byname(pdev, "gpio1");400400+ irq_mux = platform_get_irq_byname(pdev, "gpio_mux");401401+ if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0)402402+ || (irq_mux <= 0))403403+ return -EINVAL;404404+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);405405+ if (!res)406406+ return -EINVAL;407407+ gpio_reg_base = ioremap(res->start, resource_size(res));408408+ if (!gpio_reg_base)409409+ return -EINVAL;410410+411411+ if (irq0 > 0)412412+ gpio_offset = 2;472413473414 /* Initialize GPIO chips */474474- pxa_init_gpio_chip(end);415415+ pxa_init_gpio_chip(pxa_last_gpio);475416476417 /* clear all GPIO edge detects */477418 for_each_gpio_chip(gpio, c) {···512417 irq_set_chained_handler(IRQ_GPIO1, pxa_gpio_demux_handler);513418#endif514419515515- for (irq = gpio_to_irq(start); irq <= gpio_to_irq(end); irq++) {420420+ for (irq = gpio_to_irq(gpio_offset);421421+ irq <= gpio_to_irq(pxa_last_gpio); irq++) {516422 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,517423 handle_edge_irq);518424 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);519425 }520426521521- /* Install handler for GPIO>=2 edge detect interrupts */522522- irq_set_chained_handler(mux_irq, pxa_gpio_demux_handler);523523- pxa_muxed_gpio_chip.irq_set_wake = fn;427427+ irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);428428+ return 0;524429}430430+431431+static struct platform_driver pxa_gpio_driver = {432432+ .probe = pxa_gpio_probe,433433+ .driver = {434434+ .name = "pxa-gpio",435435+ },436436+};437437+438438+static int __init pxa_gpio_init(void)439439+{440440+ return platform_driver_register(&pxa_gpio_driver);441441+}442442+postcore_initcall(pxa_gpio_init);525443526444#ifdef CONFIG_PM527445static int pxa_gpio_suspend(void)···578470 .suspend = pxa_gpio_suspend,579471 .resume = pxa_gpio_resume,580472};473473+474474+static int __init pxa_gpio_sysinit(void)475475+{476476+ register_syscore_ops(&pxa_gpio_syscore_ops);477477+ return 0;478478+}479479+postcore_initcall(pxa_gpio_sysinit);
+16
include/linux/gpio-pxa.h
···11+#ifndef __GPIO_PXA_H22+#define __GPIO_PXA_H33+44+#define GPIO_bit(x) (1 << ((x) & 0x1f))55+66+#define gpio_to_bank(gpio) ((gpio) >> 5)77+88+/* NOTE: some PXAs have fewer on-chip GPIOs (like PXA255, with 85).99+ * Those cases currently cause holes in the GPIO number space, the1010+ * actual number of the last GPIO is recorded by 'pxa_last_gpio'.1111+ */1212+extern int pxa_last_gpio;1313+1414+extern int pxa_irq_to_gpio(int irq);1515+1616+#endif /* __GPIO_PXA_H */