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