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

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] GPIO API: PXA wrapper cleanup

Based on the discussion last december (http://lkml.org/lkml/2006/12/20/242),
this patch:

- moves the PXA_LAST_GPIO check into pxa_gpio_mode
- fixes comment and includes in gpio.h
- replaces the gpio_set/get_value macros with inline
functions and adds a non-inline version to avoid
code explosion when gpio is not a constant.

Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Nicolas Pitre <nico@cam.org>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Philipp Zabel and committed by
Linus Torvalds
3deac046 5d4675a8

+63 -19
+27 -1
arch/arm/mach-pxa/generic.c
··· 36 36 #include <asm/mach/map.h> 37 37 38 38 #include <asm/arch/pxa-regs.h> 39 + #include <asm/arch/gpio.h> 39 40 #include <asm/arch/udc.h> 40 41 #include <asm/arch/pxafb.h> 41 42 #include <asm/arch/mmc.h> ··· 107 106 * Handy function to set GPIO alternate functions 108 107 */ 109 108 110 - void pxa_gpio_mode(int gpio_mode) 109 + int pxa_gpio_mode(int gpio_mode) 111 110 { 112 111 unsigned long flags; 113 112 int gpio = gpio_mode & GPIO_MD_MASK_NR; 114 113 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8; 115 114 int gafr; 115 + 116 + if (gpio > PXA_LAST_GPIO) 117 + return -EINVAL; 116 118 117 119 local_irq_save(flags); 118 120 if (gpio_mode & GPIO_DFLT_LOW) ··· 129 125 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); 130 126 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); 131 127 local_irq_restore(flags); 128 + 129 + return 0; 132 130 } 133 131 134 132 EXPORT_SYMBOL(pxa_gpio_mode); 133 + 134 + /* 135 + * Return GPIO level 136 + */ 137 + int pxa_gpio_get_value(unsigned gpio) 138 + { 139 + return __gpio_get_value(gpio); 140 + } 141 + 142 + EXPORT_SYMBOL(pxa_gpio_get_value); 143 + 144 + /* 145 + * Set output GPIO level 146 + */ 147 + void pxa_gpio_set_value(unsigned gpio, int value) 148 + { 149 + __gpio_set_value(gpio, value); 150 + } 151 + 152 + EXPORT_SYMBOL(pxa_gpio_set_value); 135 153 136 154 /* 137 155 * Routine to safely enable or disable a clock in the CKEN
+25 -17
include/asm-arm/arch-pxa/gpio.h
··· 25 25 #define __ASM_ARCH_PXA_GPIO_H 26 26 27 27 #include <asm/arch/pxa-regs.h> 28 - #include <asm/arch/irqs.h> 29 - #include <asm/arch/hardware.h> 30 - 31 - #include <asm/errno.h> 28 + #include <asm/irq.h> 29 + #include <asm/hardware.h> 32 30 33 31 static inline int gpio_request(unsigned gpio, const char *label) 34 32 { ··· 40 42 41 43 static inline int gpio_direction_input(unsigned gpio) 42 44 { 43 - if (gpio > PXA_LAST_GPIO) 44 - return -EINVAL; 45 - pxa_gpio_mode(gpio | GPIO_IN); 45 + return pxa_gpio_mode(gpio | GPIO_IN); 46 46 } 47 47 48 48 static inline int gpio_direction_output(unsigned gpio) 49 49 { 50 - if (gpio > PXA_LAST_GPIO) 51 - return -EINVAL; 52 - pxa_gpio_mode(gpio | GPIO_OUT); 50 + return pxa_gpio_mode(gpio | GPIO_OUT); 53 51 } 54 52 55 - /* REVISIT these macros are correct, but suffer code explosion 56 - * for non-constant parameters. Provide out-line versions too. 57 - */ 58 - #define gpio_get_value(gpio) \ 59 - (GPLR(gpio) & GPIO_bit(gpio)) 53 + static inline int __gpio_get_value(unsigned gpio) 54 + { 55 + return GPLR(gpio) & GPIO_bit(gpio); 56 + } 60 57 61 - #define gpio_set_value(gpio,value) \ 62 - ((value) ? (GPSR(gpio) = GPIO_bit(gpio)):(GPCR(gpio) = GPIO_bit(gpio))) 58 + #define gpio_get_value(gpio) \ 59 + (__builtin_constant_p(gpio) ? \ 60 + __gpio_get_value(gpio) : \ 61 + pxa_gpio_get_value(gpio)) 62 + 63 + static inline void __gpio_set_value(unsigned gpio, int value) 64 + { 65 + if (value) 66 + GPSR(gpio) = GPIO_bit(gpio); 67 + else 68 + GPCR(gpio) = GPIO_bit(gpio); 69 + } 70 + 71 + #define gpio_set_value(gpio,value) \ 72 + (__builtin_constant_p(gpio) ? \ 73 + __gpio_set_value(gpio, value) : \ 74 + pxa_gpio_set_value(gpio, value)) 63 75 64 76 #include <asm-generic/gpio.h> /* cansleep wrappers */ 65 77
+11 -1
include/asm-arm/arch-pxa/hardware.h
··· 65 65 /* 66 66 * Handy routine to set GPIO alternate functions 67 67 */ 68 - extern void pxa_gpio_mode( int gpio_mode ); 68 + extern int pxa_gpio_mode( int gpio_mode ); 69 + 70 + /* 71 + * Return GPIO level, nonzero means high, zero is low 72 + */ 73 + extern int pxa_gpio_get_value(unsigned gpio); 74 + 75 + /* 76 + * Set output GPIO level 77 + */ 78 + extern void pxa_gpio_set_value(unsigned gpio, int value); 69 79 70 80 /* 71 81 * Routine to enable or disable CKEN