diff options
author | David Brownell <david-b@pacbell.net> | 2007-02-12 03:53:13 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-02-12 12:48:34 -0500 |
commit | a31c4eea2127ee52b5c7c1befada4664963ad030 (patch) | |
tree | dc459f1ddba26772c9faa26ac8cdef0c41afd300 | |
parent | 3c729f1ecd23b86a2d6b211d646f57f9da8dfeb1 (diff) |
[PATCH] AT91 GPIO wrappers
This is a first cut at making the AT91 code use the generic GPIO calls.
Note that the original AT91 GPIO calls merged the "mux pin as GPIO" and "set
GPIO direction" functionality into one API call, contrary to what's specified
as a cross-platform portable model. So this involved a few non-inlinable
functions.
[akpm@osdl.org: cleanups]
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/arm/mach-at91rm9200/gpio.c | 48 | ||||
-rw-r--r-- | include/asm-arm/arch-at91rm9200/gpio.h | 48 |
2 files changed, 94 insertions, 2 deletions
diff --git a/arch/arm/mach-at91rm9200/gpio.c b/arch/arm/mach-at91rm9200/gpio.c index af22659c8a28..15eb5b6b29f2 100644 --- a/arch/arm/mach-at91rm9200/gpio.c +++ b/arch/arm/mach-at91rm9200/gpio.c | |||
@@ -65,6 +65,24 @@ static inline unsigned pin_to_mask(unsigned pin) | |||
65 | 65 | ||
66 | 66 | ||
67 | /* | 67 | /* |
68 | * mux the pin to the "GPIO" peripheral role. | ||
69 | */ | ||
70 | int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup) | ||
71 | { | ||
72 | void __iomem *pio = pin_to_controller(pin); | ||
73 | unsigned mask = pin_to_mask(pin); | ||
74 | |||
75 | if (!pio) | ||
76 | return -EINVAL; | ||
77 | __raw_writel(mask, pio + PIO_IDR); | ||
78 | __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); | ||
79 | __raw_writel(mask, pio + PIO_PER); | ||
80 | return 0; | ||
81 | } | ||
82 | EXPORT_SYMBOL(at91_set_GPIO_periph); | ||
83 | |||
84 | |||
85 | /* | ||
68 | * mux the pin to the "A" internal peripheral role. | 86 | * mux the pin to the "A" internal peripheral role. |
69 | */ | 87 | */ |
70 | int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup) | 88 | int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup) |
@@ -181,6 +199,36 @@ EXPORT_SYMBOL(at91_set_multi_drive); | |||
181 | 199 | ||
182 | /*--------------------------------------------------------------------------*/ | 200 | /*--------------------------------------------------------------------------*/ |
183 | 201 | ||
202 | /* new-style GPIO calls; these expect at91_set_GPIO_periph to have been | ||
203 | * called, and maybe at91_set_multi_drive() for putout pins. | ||
204 | */ | ||
205 | |||
206 | int gpio_direction_input(unsigned pin) | ||
207 | { | ||
208 | void __iomem *pio = pin_to_controller(pin); | ||
209 | unsigned mask = pin_to_mask(pin); | ||
210 | |||
211 | if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) | ||
212 | return -EINVAL; | ||
213 | __raw_writel(mask, pio + PIO_OER); | ||
214 | return 0; | ||
215 | } | ||
216 | EXPORT_SYMBOL(gpio_direction_input); | ||
217 | |||
218 | int gpio_direction_output(unsigned pin) | ||
219 | { | ||
220 | void __iomem *pio = pin_to_controller(pin); | ||
221 | unsigned mask = pin_to_mask(pin); | ||
222 | |||
223 | if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) | ||
224 | return -EINVAL; | ||
225 | __raw_writel(mask, pio + PIO_OER); | ||
226 | return 0; | ||
227 | } | ||
228 | EXPORT_SYMBOL(gpio_direction_output); | ||
229 | |||
230 | /*--------------------------------------------------------------------------*/ | ||
231 | |||
184 | /* | 232 | /* |
185 | * assuming the pin is muxed as a gpio output, set its value. | 233 | * assuming the pin is muxed as a gpio output, set its value. |
186 | */ | 234 | */ |
diff --git a/include/asm-arm/arch-at91rm9200/gpio.h b/include/asm-arm/arch-at91rm9200/gpio.h index a011d27876a2..e09d6528fadf 100644 --- a/include/asm-arm/arch-at91rm9200/gpio.h +++ b/include/asm-arm/arch-at91rm9200/gpio.h | |||
@@ -179,6 +179,7 @@ | |||
179 | 179 | ||
180 | #ifndef __ASSEMBLY__ | 180 | #ifndef __ASSEMBLY__ |
181 | /* setup setup routines, called from board init or driver probe() */ | 181 | /* setup setup routines, called from board init or driver probe() */ |
182 | extern int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup); | ||
182 | extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup); | 183 | extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup); |
183 | extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup); | 184 | extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup); |
184 | extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup); | 185 | extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup); |
@@ -193,7 +194,50 @@ extern int at91_get_gpio_value(unsigned pin); | |||
193 | /* callable only from core power-management code */ | 194 | /* callable only from core power-management code */ |
194 | extern void at91_gpio_suspend(void); | 195 | extern void at91_gpio_suspend(void); |
195 | extern void at91_gpio_resume(void); | 196 | extern void at91_gpio_resume(void); |
196 | #endif | ||
197 | 197 | ||
198 | #endif | 198 | /*-------------------------------------------------------------------------*/ |
199 | |||
200 | /* wrappers for "new style" GPIO calls. the old AT91-specfic ones should | ||
201 | * eventually be removed (along with this errno.h inclusion), and the | ||
202 | * gpio request/free calls should probably be implemented. | ||
203 | */ | ||
204 | |||
205 | #include <asm/errno.h> | ||
206 | |||
207 | static inline int gpio_request(unsigned gpio, const char *label) | ||
208 | { | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static inline void gpio_free(unsigned gpio) | ||
213 | { | ||
214 | } | ||
215 | |||
216 | extern int gpio_direction_input(unsigned gpio); | ||
217 | extern int gpio_direction_output(unsigned gpio); | ||
199 | 218 | ||
219 | static inline int gpio_get_value(unsigned gpio) | ||
220 | { | ||
221 | return at91_get_gpio_value(gpio); | ||
222 | } | ||
223 | |||
224 | static inline void gpio_set_value(unsigned gpio, int value) | ||
225 | { | ||
226 | at91_set_gpio_value(gpio, value); | ||
227 | } | ||
228 | |||
229 | #include <asm-generic/gpio.h> /* cansleep wrappers */ | ||
230 | |||
231 | static inline int gpio_to_irq(unsigned gpio) | ||
232 | { | ||
233 | return gpio; | ||
234 | } | ||
235 | |||
236 | static inline int irq_to_gpio(unsigned irq) | ||
237 | { | ||
238 | return irq; | ||
239 | } | ||
240 | |||
241 | #endif /* __ASSEMBLY__ */ | ||
242 | |||
243 | #endif | ||