aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2007-11-26 12:41:02 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-01-26 09:37:31 -0500
commit4e9f9fd5148004b983b29e15de66918e71da56c0 (patch)
tree0299b61dd1cce80d529c3c4abcbc51159ae79369
parent9b73e76f3cf63379dcf45fcd4f112f5812418d0a (diff)
[ARM] 4668/1: ep93xx: implement new GPIO API
Implement new GPIO API for ep93xx platform as defined in Documentation/gpio.txt and provide transitional __deprecated wrappers for the previous gpio_line_* functions. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> Acked-by: Lennert Buytenhek <buytenh@wantstofly.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/Kconfig1
-rw-r--r--arch/arm/mach-ep93xx/core.c63
-rw-r--r--include/asm-arm/arch-ep93xx/gpio.h76
3 files changed, 111 insertions, 29 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a04f507e7f2c..97e58a1863c2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -217,6 +217,7 @@ config ARCH_EP93XX
217 bool "EP93xx-based" 217 bool "EP93xx-based"
218 select ARM_AMBA 218 select ARM_AMBA
219 select ARM_VIC 219 select ARM_VIC
220 select GENERIC_GPIO
220 help 221 help
221 This enables support for the Cirrus EP93xx series of CPUs. 222 This enables support for the Cirrus EP93xx series of CPUs.
222 223
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index 70b2c7801110..8a7340661377 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -188,7 +188,7 @@ static unsigned char data_direction_register_offset[8] = {
188 0x10, 0x14, 0x18, 0x1c, 0x24, 0x34, 0x3c, 0x44, 188 0x10, 0x14, 0x18, 0x1c, 0x24, 0x34, 0x3c, 0x44,
189}; 189};
190 190
191void gpio_line_config(int line, int direction) 191static void ep93xx_gpio_set_direction(unsigned line, int direction)
192{ 192{
193 unsigned int data_direction_register; 193 unsigned int data_direction_register;
194 unsigned long flags; 194 unsigned long flags;
@@ -219,39 +219,64 @@ void gpio_line_config(int line, int direction)
219 } 219 }
220 local_irq_restore(flags); 220 local_irq_restore(flags);
221} 221}
222
223void __deprecated gpio_line_config(int line, int direction)
224{
225 ep93xx_gpio_set_direction(line, direction);
226}
222EXPORT_SYMBOL(gpio_line_config); 227EXPORT_SYMBOL(gpio_line_config);
223 228
224int gpio_line_get(int line) 229int gpio_direction_input(unsigned gpio)
230{
231 if (gpio > EP93XX_GPIO_LINE_H(7))
232 return -EINVAL;
233
234 ep93xx_gpio_set_direction(gpio, GPIO_IN);
235
236 return 0;
237}
238EXPORT_SYMBOL(gpio_direction_input);
239
240int gpio_direction_output(unsigned gpio, int value)
241{
242 if (gpio > EP93XX_GPIO_LINE_H(7))
243 return -EINVAL;
244
245 gpio_set_value(gpio, value);
246 ep93xx_gpio_set_direction(gpio, GPIO_OUT);
247
248 return 0;
249}
250EXPORT_SYMBOL(gpio_direction_output);
251
252int gpio_get_value(unsigned gpio)
225{ 253{
226 unsigned int data_register; 254 unsigned int data_register;
227 255
228 data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); 256 data_register = EP93XX_GPIO_REG(data_register_offset[gpio >> 3]);
229 257
230 return !!(__raw_readb(data_register) & (1 << (line & 7))); 258 return !!(__raw_readb(data_register) & (1 << (gpio & 7)));
231} 259}
232EXPORT_SYMBOL(gpio_line_get); 260EXPORT_SYMBOL(gpio_get_value);
233 261
234void gpio_line_set(int line, int value) 262void gpio_set_value(unsigned gpio, int value)
235{ 263{
236 unsigned int data_register; 264 unsigned int data_register;
237 unsigned long flags; 265 unsigned long flags;
238 unsigned char v; 266 unsigned char v;
239 267
240 data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); 268 data_register = EP93XX_GPIO_REG(data_register_offset[gpio >> 3]);
241 269
242 local_irq_save(flags); 270 local_irq_save(flags);
243 if (value == EP93XX_GPIO_HIGH) { 271 v = __raw_readb(data_register);
244 v = __raw_readb(data_register); 272 if (value)
245 v |= 1 << (line & 7); 273 v |= 1 << (gpio & 7);
246 __raw_writeb(v, data_register); 274 else
247 } else if (value == EP93XX_GPIO_LOW) { 275 v &= ~(1 << (gpio & 7));
248 v = __raw_readb(data_register); 276 __raw_writeb(v, data_register);
249 v &= ~(1 << (line & 7));
250 __raw_writeb(v, data_register);
251 }
252 local_irq_restore(flags); 277 local_irq_restore(flags);
253} 278}
254EXPORT_SYMBOL(gpio_line_set); 279EXPORT_SYMBOL(gpio_set_value);
255 280
256 281
257/************************************************************************* 282/*************************************************************************
@@ -334,9 +359,9 @@ static int ep93xx_gpio_irq_type(unsigned int irq, unsigned int type)
334 359
335 line = irq - IRQ_EP93XX_GPIO(0); 360 line = irq - IRQ_EP93XX_GPIO(0);
336 if (line >= 0 && line < 16) { 361 if (line >= 0 && line < 16) {
337 gpio_line_config(line, GPIO_IN); 362 ep93xx_gpio_set_direction(line, GPIO_IN);
338 } else { 363 } else {
339 gpio_line_config(EP93XX_GPIO_LINE_F(line-16), GPIO_IN); 364 ep93xx_gpio_set_direction(EP93XX_GPIO_LINE_F(line-16), GPIO_IN);
340 } 365 }
341 366
342 port = line >> 3; 367 port = line >> 3;
diff --git a/include/asm-arm/arch-ep93xx/gpio.h b/include/asm-arm/arch-ep93xx/gpio.h
index 1ee14a14cba0..fc1e57db5fac 100644
--- a/include/asm-arm/arch-ep93xx/gpio.h
+++ b/include/asm-arm/arch-ep93xx/gpio.h
@@ -5,16 +5,6 @@
5#ifndef __ASM_ARCH_GPIO_H 5#ifndef __ASM_ARCH_GPIO_H
6#define __ASM_ARCH_GPIO_H 6#define __ASM_ARCH_GPIO_H
7 7
8#define GPIO_IN 0
9#define GPIO_OUT 1
10
11#define EP93XX_GPIO_LOW 0
12#define EP93XX_GPIO_HIGH 1
13
14extern void gpio_line_config(int line, int direction);
15extern int gpio_line_get(int line);
16extern void gpio_line_set(int line, int value);
17
18/* GPIO port A. */ 8/* GPIO port A. */
19#define EP93XX_GPIO_LINE_A(x) ((x) + 0) 9#define EP93XX_GPIO_LINE_A(x) ((x) + 0)
20#define EP93XX_GPIO_LINE_EGPIO0 EP93XX_GPIO_LINE_A(0) 10#define EP93XX_GPIO_LINE_EGPIO0 EP93XX_GPIO_LINE_A(0)
@@ -103,5 +93,71 @@ extern void gpio_line_set(int line, int value);
103#define EP93XX_GPIO_LINE_DD6 EP93XX_GPIO_LINE_H(6) 93#define EP93XX_GPIO_LINE_DD6 EP93XX_GPIO_LINE_H(6)
104#define EP93XX_GPIO_LINE_DD7 EP93XX_GPIO_LINE_H(7) 94#define EP93XX_GPIO_LINE_DD7 EP93XX_GPIO_LINE_H(7)
105 95
96/* new generic GPIO API - see Documentation/gpio.txt */
97
98static inline int gpio_request(unsigned gpio, const char *label)
99{
100 if (gpio > EP93XX_GPIO_LINE_H(7))
101 return -EINVAL;
102 return 0;
103}
104
105static inline void gpio_free(unsigned gpio)
106{
107}
108
109int gpio_direction_input(unsigned gpio);
110int gpio_direction_output(unsigned gpio, int value);
111int gpio_get_value(unsigned gpio);
112void gpio_set_value(unsigned gpio, int value);
113
114#include <asm-generic/gpio.h> /* cansleep wrappers */
115
116/*
117 * Map GPIO A0..A7 (0..7) to irq 64..71,
118 * B0..B7 (7..15) to irq 72..79, and
119 * F0..F7 (40..47) to irq 80..87.
120 */
121
122static inline int gpio_to_irq(unsigned gpio)
123{
124 if (gpio <= EP93XX_GPIO_LINE_EGPIO15)
125 return 64 + gpio;
126
127 if (gpio >= EP93XX_GPIO_LINE_F(0) && gpio <= EP93XX_GPIO_LINE_F(7))
128 return 80 + (gpio - EP93XX_GPIO_LINE_F(0));
129
130 return -EINVAL;
131}
132
133static inline int irq_to_gpio(unsigned irq)
134{
135 if (irq >= 64 && irq <= 79)
136 return irq - 64;
137
138 if (irq >= 80 && irq <= 87)
139 return (irq - 80) + EP93XX_GPIO_LINE_F(0);
140
141 return -EINVAL;
142}
143
144/* obsolete specific GPIO API */
145#define GPIO_IN 0
146#define GPIO_OUT 1
147
148#define EP93XX_GPIO_LOW 0
149#define EP93XX_GPIO_HIGH 1
150
151void __deprecated gpio_line_config(int line, int direction);
152
153static inline int __deprecated gpio_line_get(int line)
154{
155 return gpio_get_value(line);
156}
157
158static inline void __deprecated gpio_line_set(int line, int value)
159{
160 gpio_set_value(line, value);
161}
106 162
107#endif 163#endif