Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

David Brownell and committed by
Linus Torvalds
a31c4eea 3c729f1e

+94 -2
+48
arch/arm/mach-at91rm9200/gpio.c
··· 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 86 * mux the pin to the "A" internal peripheral role. 69 87 */ 70 88 int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup) ··· 196 178 return 0; 197 179 } 198 180 EXPORT_SYMBOL(at91_set_multi_drive); 181 + 182 + /*--------------------------------------------------------------------------*/ 183 + 184 + /* new-style GPIO calls; these expect at91_set_GPIO_periph to have been 185 + * called, and maybe at91_set_multi_drive() for putout pins. 186 + */ 187 + 188 + int gpio_direction_input(unsigned pin) 189 + { 190 + void __iomem *pio = pin_to_controller(pin); 191 + unsigned mask = pin_to_mask(pin); 192 + 193 + if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) 194 + return -EINVAL; 195 + __raw_writel(mask, pio + PIO_OER); 196 + return 0; 197 + } 198 + EXPORT_SYMBOL(gpio_direction_input); 199 + 200 + int gpio_direction_output(unsigned pin) 201 + { 202 + void __iomem *pio = pin_to_controller(pin); 203 + unsigned mask = pin_to_mask(pin); 204 + 205 + if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) 206 + return -EINVAL; 207 + __raw_writel(mask, pio + PIO_OER); 208 + return 0; 209 + } 210 + EXPORT_SYMBOL(gpio_direction_output); 199 211 200 212 /*--------------------------------------------------------------------------*/ 201 213
+46 -2
include/asm-arm/arch-at91rm9200/gpio.h
··· 179 179 180 180 #ifndef __ASSEMBLY__ 181 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 183 extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup); 183 184 extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup); 184 185 extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup); ··· 194 193 /* callable only from core power-management code */ 195 194 extern void at91_gpio_suspend(void); 196 195 extern void at91_gpio_resume(void); 197 - #endif 196 + 197 + /*-------------------------------------------------------------------------*/ 198 + 199 + /* wrappers for "new style" GPIO calls. the old AT91-specfic ones should 200 + * eventually be removed (along with this errno.h inclusion), and the 201 + * gpio request/free calls should probably be implemented. 202 + */ 203 + 204 + #include <asm/errno.h> 205 + 206 + static inline int gpio_request(unsigned gpio, const char *label) 207 + { 208 + return 0; 209 + } 210 + 211 + static inline void gpio_free(unsigned gpio) 212 + { 213 + } 214 + 215 + extern int gpio_direction_input(unsigned gpio); 216 + extern int gpio_direction_output(unsigned gpio); 217 + 218 + static inline int gpio_get_value(unsigned gpio) 219 + { 220 + return at91_get_gpio_value(gpio); 221 + } 222 + 223 + static inline void gpio_set_value(unsigned gpio, int value) 224 + { 225 + at91_set_gpio_value(gpio, value); 226 + } 227 + 228 + #include <asm-generic/gpio.h> /* cansleep wrappers */ 229 + 230 + static inline int gpio_to_irq(unsigned gpio) 231 + { 232 + return gpio; 233 + } 234 + 235 + static inline int irq_to_gpio(unsigned irq) 236 + { 237 + return irq; 238 + } 239 + 240 + #endif /* __ASSEMBLY__ */ 198 241 199 242 #endif 200 -