diff options
| author | Philipp Zabel <philipp.zabel@gmail.com> | 2008-02-05 01:28:22 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:13 -0500 |
| commit | 1c44f5f16fee880b294f8068354bfb9dddf1349b (patch) | |
| tree | dd9815cf7a38af7d4abc55eb707574ceedd8a912 | |
| parent | 7c2db759ece63fd166cf0849b7b271589fa1b754 (diff) | |
gpiolib support for the PXA architecture
This adds gpiolib support for the PXA architecture:
- move all GPIO API functions from generic.c into gpio.c
- convert the gpio_get/set_value macros into inline functions
This makes it easier to hook up GPIOs provided by external chips like
ASICs and CPLDs.
Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Eric Miao <eric.miao@marvell.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: Ben Gardner <bgardner@wabtec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Minor ARM fixup from David Brownell folded into this ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | arch/arm/Kconfig | 1 | ||||
| -rw-r--r-- | arch/arm/mach-pxa/Makefile | 3 | ||||
| -rw-r--r-- | arch/arm/mach-pxa/generic.c | 93 | ||||
| -rw-r--r-- | arch/arm/mach-pxa/generic.h | 1 | ||||
| -rw-r--r-- | arch/arm/mach-pxa/gpio.c | 197 | ||||
| -rw-r--r-- | arch/arm/mach-pxa/irq.c | 2 | ||||
| -rw-r--r-- | include/asm-arm/arch-pxa/gpio.h | 48 | ||||
| -rw-r--r-- | include/asm-arm/arch-pxa/pxa-regs.h | 13 |
8 files changed, 236 insertions, 122 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index a322f58cdc90..e19e7744e366 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
| @@ -385,6 +385,7 @@ config ARCH_PXA | |||
| 385 | depends on MMU | 385 | depends on MMU |
| 386 | select ARCH_MTD_XIP | 386 | select ARCH_MTD_XIP |
| 387 | select GENERIC_GPIO | 387 | select GENERIC_GPIO |
| 388 | select HAVE_GPIO_LIB | ||
| 388 | select GENERIC_TIME | 389 | select GENERIC_TIME |
| 389 | select GENERIC_CLOCKEVENTS | 390 | select GENERIC_CLOCKEVENTS |
| 390 | select TICK_ONESHOT | 391 | select TICK_ONESHOT |
diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile index 8604938bd948..6e0c4f5b5ae6 100644 --- a/arch/arm/mach-pxa/Makefile +++ b/arch/arm/mach-pxa/Makefile | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | # Common support (must be linked before board specific support) | 5 | # Common support (must be linked before board specific support) |
| 6 | obj-y += clock.o devices.o generic.o irq.o dma.o time.o | 6 | obj-y += clock.o devices.o generic.o irq.o dma.o \ |
| 7 | time.o gpio.o | ||
| 7 | obj-$(CONFIG_PXA25x) += pxa25x.o | 8 | obj-$(CONFIG_PXA25x) += pxa25x.o |
| 8 | obj-$(CONFIG_PXA27x) += pxa27x.o | 9 | obj-$(CONFIG_PXA27x) += pxa27x.o |
| 9 | obj-$(CONFIG_PXA3xx) += pxa3xx.o mfp.o smemc.o | 10 | obj-$(CONFIG_PXA3xx) += pxa3xx.o mfp.o smemc.o |
diff --git a/arch/arm/mach-pxa/generic.c b/arch/arm/mach-pxa/generic.c index 76970598f550..80721c610d41 100644 --- a/arch/arm/mach-pxa/generic.c +++ b/arch/arm/mach-pxa/generic.c | |||
| @@ -32,7 +32,6 @@ | |||
| 32 | #include <asm/mach/map.h> | 32 | #include <asm/mach/map.h> |
| 33 | 33 | ||
| 34 | #include <asm/arch/pxa-regs.h> | 34 | #include <asm/arch/pxa-regs.h> |
| 35 | #include <asm/arch/gpio.h> | ||
| 36 | 35 | ||
| 37 | #include "generic.h" | 36 | #include "generic.h" |
| 38 | 37 | ||
| @@ -67,97 +66,6 @@ unsigned int get_memclk_frequency_10khz(void) | |||
| 67 | EXPORT_SYMBOL(get_memclk_frequency_10khz); | 66 | EXPORT_SYMBOL(get_memclk_frequency_10khz); |
| 68 | 67 | ||
| 69 | /* | 68 | /* |
| 70 | * Handy function to set GPIO alternate functions | ||
| 71 | */ | ||
| 72 | int pxa_last_gpio; | ||
| 73 | |||
| 74 | int pxa_gpio_mode(int gpio_mode) | ||
| 75 | { | ||
| 76 | unsigned long flags; | ||
| 77 | int gpio = gpio_mode & GPIO_MD_MASK_NR; | ||
| 78 | int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8; | ||
| 79 | int gafr; | ||
| 80 | |||
| 81 | if (gpio > pxa_last_gpio) | ||
| 82 | return -EINVAL; | ||
| 83 | |||
| 84 | local_irq_save(flags); | ||
| 85 | if (gpio_mode & GPIO_DFLT_LOW) | ||
| 86 | GPCR(gpio) = GPIO_bit(gpio); | ||
| 87 | else if (gpio_mode & GPIO_DFLT_HIGH) | ||
| 88 | GPSR(gpio) = GPIO_bit(gpio); | ||
| 89 | if (gpio_mode & GPIO_MD_MASK_DIR) | ||
| 90 | GPDR(gpio) |= GPIO_bit(gpio); | ||
| 91 | else | ||
| 92 | GPDR(gpio) &= ~GPIO_bit(gpio); | ||
| 93 | gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); | ||
| 94 | GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); | ||
| 95 | local_irq_restore(flags); | ||
| 96 | |||
| 97 | return 0; | ||
| 98 | } | ||
| 99 | |||
| 100 | EXPORT_SYMBOL(pxa_gpio_mode); | ||
| 101 | |||
| 102 | int gpio_direction_input(unsigned gpio) | ||
| 103 | { | ||
| 104 | unsigned long flags; | ||
| 105 | u32 mask; | ||
| 106 | |||
| 107 | if (gpio > pxa_last_gpio) | ||
| 108 | return -EINVAL; | ||
| 109 | |||
| 110 | mask = GPIO_bit(gpio); | ||
| 111 | local_irq_save(flags); | ||
| 112 | GPDR(gpio) &= ~mask; | ||
| 113 | local_irq_restore(flags); | ||
| 114 | |||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | EXPORT_SYMBOL(gpio_direction_input); | ||
| 118 | |||
| 119 | int gpio_direction_output(unsigned gpio, int value) | ||
| 120 | { | ||
| 121 | unsigned long flags; | ||
| 122 | u32 mask; | ||
| 123 | |||
| 124 | if (gpio > pxa_last_gpio) | ||
| 125 | return -EINVAL; | ||
| 126 | |||
| 127 | mask = GPIO_bit(gpio); | ||
| 128 | local_irq_save(flags); | ||
| 129 | if (value) | ||
| 130 | GPSR(gpio) = mask; | ||
| 131 | else | ||
| 132 | GPCR(gpio) = mask; | ||
| 133 | GPDR(gpio) |= mask; | ||
| 134 | local_irq_restore(flags); | ||
| 135 | |||
| 136 | return 0; | ||
| 137 | } | ||
| 138 | EXPORT_SYMBOL(gpio_direction_output); | ||
| 139 | |||
| 140 | /* | ||
| 141 | * Return GPIO level | ||
| 142 | */ | ||
| 143 | int pxa_gpio_get_value(unsigned gpio) | ||
| 144 | { | ||
| 145 | return __gpio_get_value(gpio); | ||
| 146 | } | ||
| 147 | |||
| 148 | EXPORT_SYMBOL(pxa_gpio_get_value); | ||
| 149 | |||
| 150 | /* | ||
| 151 | * Set output GPIO level | ||
| 152 | */ | ||
| 153 | void pxa_gpio_set_value(unsigned gpio, int value) | ||
| 154 | { | ||
| 155 | __gpio_set_value(gpio, value); | ||
| 156 | } | ||
| 157 | |||
| 158 | EXPORT_SYMBOL(pxa_gpio_set_value); | ||
| 159 | |||
| 160 | /* | ||
| 161 | * Routine to safely enable or disable a clock in the CKEN | 69 | * Routine to safely enable or disable a clock in the CKEN |
| 162 | */ | 70 | */ |
| 163 | void __pxa_set_cken(int clock, int enable) | 71 | void __pxa_set_cken(int clock, int enable) |
| @@ -172,7 +80,6 @@ void __pxa_set_cken(int clock, int enable) | |||
| 172 | 80 | ||
| 173 | local_irq_restore(flags); | 81 | local_irq_restore(flags); |
| 174 | } | 82 | } |
| 175 | |||
| 176 | EXPORT_SYMBOL(__pxa_set_cken); | 83 | EXPORT_SYMBOL(__pxa_set_cken); |
| 177 | 84 | ||
| 178 | /* | 85 | /* |
diff --git a/arch/arm/mach-pxa/generic.h b/arch/arm/mach-pxa/generic.h index 1a16ad3ecee6..b3d10b0e52a0 100644 --- a/arch/arm/mach-pxa/generic.h +++ b/arch/arm/mach-pxa/generic.h | |||
| @@ -16,6 +16,7 @@ extern void __init pxa_init_irq_low(void); | |||
| 16 | extern void __init pxa_init_irq_high(void); | 16 | extern void __init pxa_init_irq_high(void); |
| 17 | extern void __init pxa_init_irq_gpio(int gpio_nr); | 17 | extern void __init pxa_init_irq_gpio(int gpio_nr); |
| 18 | extern void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int)); | 18 | extern void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int)); |
| 19 | extern void __init pxa_init_gpio(int gpio_nr); | ||
| 19 | extern void __init pxa25x_init_irq(void); | 20 | extern void __init pxa25x_init_irq(void); |
| 20 | extern void __init pxa27x_init_irq(void); | 21 | extern void __init pxa27x_init_irq(void); |
| 21 | extern void __init pxa3xx_init_irq(void); | 22 | extern void __init pxa3xx_init_irq(void); |
diff --git a/arch/arm/mach-pxa/gpio.c b/arch/arm/mach-pxa/gpio.c new file mode 100644 index 000000000000..8638dd7dd076 --- /dev/null +++ b/arch/arm/mach-pxa/gpio.c | |||
| @@ -0,0 +1,197 @@ | |||
| 1 | /* | ||
| 2 | * linux/arch/arm/mach-pxa/gpio.c | ||
| 3 | * | ||
| 4 | * Generic PXA GPIO handling | ||
| 5 | * | ||
| 6 | * Author: Nicolas Pitre | ||
| 7 | * Created: Jun 15, 2001 | ||
| 8 | * Copyright: MontaVista Software Inc. | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License version 2 as | ||
| 12 | * published by the Free Software Foundation. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | |||
| 18 | #include <asm/gpio.h> | ||
| 19 | #include <asm/hardware.h> | ||
| 20 | #include <asm/io.h> | ||
| 21 | #include <asm/arch/pxa-regs.h> | ||
| 22 | |||
| 23 | #include "generic.h" | ||
| 24 | |||
| 25 | |||
| 26 | struct pxa_gpio_chip { | ||
