diff options
author | Lennert Buytenhek <buytenh@wantstofly.org> | 2006-03-20 12:10:14 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2006-03-21 17:06:12 -0500 |
commit | a8e19667a42d752f3eca6eaa17aa5d6f93066dfe (patch) | |
tree | 7bf3b7eb8ac3fb6c18b3a8c33a88d6d2158f45e4 | |
parent | e7736d47a11a771ba87314be563b2cb6b8d11d14 (diff) |
[ARM] 3371/1: ep93xx: gpio support
Patch from Lennert Buytenhek
Add support for setting the direction of and getting/setting the
value of the 64 GPIO lines.
Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/mach-ep93xx/core.c | 68 | ||||
-rw-r--r-- | include/asm-arm/arch-ep93xx/ep93xx-regs.h | 1 | ||||
-rw-r--r-- | include/asm-arm/arch-ep93xx/gpio.h | 107 |
3 files changed, 176 insertions, 0 deletions
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c index f831f74dc8cc..7d3e79990fad 100644 --- a/arch/arm/mach-ep93xx/core.c +++ b/arch/arm/mach-ep93xx/core.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <asm/mach/map.h> | 45 | #include <asm/mach/map.h> |
46 | #include <asm/mach/time.h> | 46 | #include <asm/mach/time.h> |
47 | #include <asm/mach/irq.h> | 47 | #include <asm/mach/irq.h> |
48 | #include <asm/arch/gpio.h> | ||
48 | 49 | ||
49 | #include <asm/hardware/vic.h> | 50 | #include <asm/hardware/vic.h> |
50 | 51 | ||
@@ -147,6 +148,73 @@ struct sys_timer ep93xx_timer = { | |||
147 | 148 | ||
148 | 149 | ||
149 | /************************************************************************* | 150 | /************************************************************************* |
151 | * GPIO handling for EP93xx | ||
152 | *************************************************************************/ | ||
153 | static unsigned char data_register_offset[8] = { | ||
154 | 0x00, 0x04, 0x08, 0x0c, 0x20, 0x30, 0x38, 0x40, | ||
155 | }; | ||
156 | |||
157 | static unsigned char data_direction_register_offset[8] = { | ||
158 | 0x10, 0x14, 0x18, 0x1c, 0x24, 0x34, 0x3c, 0x44, | ||
159 | }; | ||
160 | |||
161 | void gpio_line_config(int line, int direction) | ||
162 | { | ||
163 | unsigned int data_direction_register; | ||
164 | unsigned long flags; | ||
165 | unsigned char v; | ||
166 | |||
167 | data_direction_register = | ||
168 | EP93XX_GPIO_REG(data_direction_register_offset[line >> 3]); | ||
169 | |||
170 | local_irq_save(flags); | ||
171 | if (direction == GPIO_OUT) { | ||
172 | v = __raw_readb(data_direction_register); | ||
173 | v |= 1 << (line & 7); | ||
174 | __raw_writeb(v, data_direction_register); | ||
175 | } else if (direction == GPIO_IN) { | ||
176 | v = __raw_readb(data_direction_register); | ||
177 | v &= ~(1 << (line & 7)); | ||
178 | __raw_writeb(v, data_direction_register); | ||
179 | } | ||
180 | local_irq_restore(flags); | ||
181 | } | ||
182 | EXPORT_SYMBOL(gpio_line_config); | ||
183 | |||
184 | int gpio_line_get(int line) | ||
185 | { | ||
186 | unsigned int data_register; | ||
187 | |||
188 | data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); | ||
189 | |||
190 | return !!(__raw_readb(data_register) & (1 << (line & 7))); | ||
191 | } | ||
192 | EXPORT_SYMBOL(gpio_line_get); | ||
193 | |||
194 | void gpio_line_set(int line, int value) | ||
195 | { | ||
196 | unsigned int data_register; | ||
197 | unsigned long flags; | ||
198 | unsigned char v; | ||
199 | |||
200 | data_register = EP93XX_GPIO_REG(data_register_offset[line >> 3]); | ||
201 | |||
202 | local_irq_save(flags); | ||
203 | if (value == EP93XX_GPIO_HIGH) { | ||
204 | v = __raw_readb(data_register); | ||
205 | v |= 1 << (line & 7); | ||
206 | __raw_writeb(v, data_register); | ||
207 | } else if (value == EP93XX_GPIO_LOW) { | ||
208 | v = __raw_readb(data_register); | ||
209 | v &= ~(1 << (line & 7)); | ||
210 | __raw_writeb(v, data_register); | ||
211 | } | ||
212 | local_irq_restore(flags); | ||
213 | } | ||
214 | EXPORT_SYMBOL(gpio_line_set); | ||
215 | |||
216 | |||
217 | /************************************************************************* | ||
150 | * EP93xx IRQ handling | 218 | * EP93xx IRQ handling |
151 | *************************************************************************/ | 219 | *************************************************************************/ |
152 | void __init ep93xx_init_irq(void) | 220 | void __init ep93xx_init_irq(void) |
diff --git a/include/asm-arm/arch-ep93xx/ep93xx-regs.h b/include/asm-arm/arch-ep93xx/ep93xx-regs.h index 693f23886e85..c1efacc83b75 100644 --- a/include/asm-arm/arch-ep93xx/ep93xx-regs.h +++ b/include/asm-arm/arch-ep93xx/ep93xx-regs.h | |||
@@ -71,6 +71,7 @@ | |||
71 | #define EP93XX_SECURITY_BASE (EP93XX_APB_VIRT_BASE + 0x00030000) | 71 | #define EP93XX_SECURITY_BASE (EP93XX_APB_VIRT_BASE + 0x00030000) |
72 | 72 | ||
73 | #define EP93XX_GPIO_BASE (EP93XX_APB_VIRT_BASE + 0x00040000) | 73 | #define EP93XX_GPIO_BASE (EP93XX_APB_VIRT_BASE + 0x00040000) |
74 | #define EP93XX_GPIO_REG(x) (EP93XX_GPIO_BASE + (x)) | ||
74 | 75 | ||
75 | #define EP93XX_AAC_BASE (EP93XX_APB_VIRT_BASE + 0x00080000) | 76 | #define EP93XX_AAC_BASE (EP93XX_APB_VIRT_BASE + 0x00080000) |
76 | 77 | ||
diff --git a/include/asm-arm/arch-ep93xx/gpio.h b/include/asm-arm/arch-ep93xx/gpio.h new file mode 100644 index 000000000000..1ee14a14cba0 --- /dev/null +++ b/include/asm-arm/arch-ep93xx/gpio.h | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * linux/include/asm-arm/arch-ep93xx/gpio.h | ||
3 | */ | ||
4 | |||
5 | #ifndef __ASM_ARCH_GPIO_H | ||
6 | #define __ASM_ARCH_GPIO_H | ||
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 | |||
14 | extern void gpio_line_config(int line, int direction); | ||
15 | extern int gpio_line_get(int line); | ||
16 | extern void gpio_line_set(int line, int value); | ||
17 | |||
18 | /* GPIO port A. */ | ||
19 | #define EP93XX_GPIO_LINE_A(x) ((x) + 0) | ||
20 | #define EP93XX_GPIO_LINE_EGPIO0 EP93XX_GPIO_LINE_A(0) | ||
21 | #define EP93XX_GPIO_LINE_EGPIO1 EP93XX_GPIO_LINE_A(1) | ||
22 | #define EP93XX_GPIO_LINE_EGPIO2 EP93XX_GPIO_LINE_A(2) | ||
23 | #define EP93XX_GPIO_LINE_EGPIO3 EP93XX_GPIO_LINE_A(3) | ||
24 | #define EP93XX_GPIO_LINE_EGPIO4 EP93XX_GPIO_LINE_A(4) | ||
25 | #define EP93XX_GPIO_LINE_EGPIO5 EP93XX_GPIO_LINE_A(5) | ||
26 | #define EP93XX_GPIO_LINE_EGPIO6 EP93XX_GPIO_LINE_A(6) | ||
27 | #define EP93XX_GPIO_LINE_EGPIO7 EP93XX_GPIO_LINE_A(7) | ||
28 | |||
29 | /* GPIO port B. */ | ||
30 | #define EP93XX_GPIO_LINE_B(x) ((x) + 8) | ||
31 | #define EP93XX_GPIO_LINE_EGPIO8 EP93XX_GPIO_LINE_B(0) | ||
32 | #define EP93XX_GPIO_LINE_EGPIO9 EP93XX_GPIO_LINE_B(1) | ||
33 | #define EP93XX_GPIO_LINE_EGPIO10 EP93XX_GPIO_LINE_B(2) | ||
34 | #define EP93XX_GPIO_LINE_EGPIO11 EP93XX_GPIO_LINE_B(3) | ||
35 | #define EP93XX_GPIO_LINE_EGPIO12 EP93XX_GPIO_LINE_B(4) | ||
36 | #define EP93XX_GPIO_LINE_EGPIO13 EP93XX_GPIO_LINE_B(5) | ||
37 | #define EP93XX_GPIO_LINE_EGPIO14 EP93XX_GPIO_LINE_B(6) | ||
38 | #define EP93XX_GPIO_LINE_EGPIO15 EP93XX_GPIO_LINE_B(7) | ||
39 | |||
40 | /* GPIO port C. */ | ||
41 | #define EP93XX_GPIO_LINE_C(x) ((x) + 16) | ||
42 | #define EP93XX_GPIO_LINE_ROW0 EP93XX_GPIO_LINE_C(0) | ||
43 | #define EP93XX_GPIO_LINE_ROW1 EP93XX_GPIO_LINE_C(1) | ||
44 | #define EP93XX_GPIO_LINE_ROW2 EP93XX_GPIO_LINE_C(2) | ||
45 | #define EP93XX_GPIO_LINE_ROW3 EP93XX_GPIO_LINE_C(3) | ||
46 | #define EP93XX_GPIO_LINE_ROW4 EP93XX_GPIO_LINE_C(4) | ||
47 | #define EP93XX_GPIO_LINE_ROW5 EP93XX_GPIO_LINE_C(5) | ||
48 | #define EP93XX_GPIO_LINE_ROW6 EP93XX_GPIO_LINE_C(6) | ||
49 | #define EP93XX_GPIO_LINE_ROW7 EP93XX_GPIO_LINE_C(7) | ||
50 | |||
51 | /* GPIO port D. */ | ||
52 | #define EP93XX_GPIO_LINE_D(x) ((x) + 24) | ||
53 | #define EP93XX_GPIO_LINE_COL0 EP93XX_GPIO_LINE_D(0) | ||
54 | #define EP93XX_GPIO_LINE_COL1 EP93XX_GPIO_LINE_D(1) | ||
55 | #define EP93XX_GPIO_LINE_COL2 EP93XX_GPIO_LINE_D(2) | ||
56 | #define EP93XX_GPIO_LINE_COL3 EP93XX_GPIO_LINE_D(3) | ||
57 | #define EP93XX_GPIO_LINE_COL4 EP93XX_GPIO_LINE_D(4) | ||
58 | #define EP93XX_GPIO_LINE_COL5 EP93XX_GPIO_LINE_D(5) | ||
59 | #define EP93XX_GPIO_LINE_COL6 EP93XX_GPIO_LINE_D(6) | ||
60 | #define EP93XX_GPIO_LINE_COL7 EP93XX_GPIO_LINE_D(7) | ||
61 | |||
62 | /* GPIO port E. */ | ||
63 | #define EP93XX_GPIO_LINE_E(x) ((x) + 32) | ||
64 | #define EP93XX_GPIO_LINE_GRLED EP93XX_GPIO_LINE_E(0) | ||
65 | #define EP93XX_GPIO_LINE_RDLED EP93XX_GPIO_LINE_E(1) | ||
66 | #define EP93XX_GPIO_LINE_DIORn EP93XX_GPIO_LINE_E(2) | ||
67 | #define EP93XX_GPIO_LINE_IDECS1n EP93XX_GPIO_LINE_E(3) | ||
68 | #define EP93XX_GPIO_LINE_IDECS2n EP93XX_GPIO_LINE_E(4) | ||
69 | #define EP93XX_GPIO_LINE_IDEDA0 EP93XX_GPIO_LINE_E(5) | ||
70 | #define EP93XX_GPIO_LINE_IDEDA1 EP93XX_GPIO_LINE_E(6) | ||
71 | #define EP93XX_GPIO_LINE_IDEDA2 EP93XX_GPIO_LINE_E(7) | ||
72 | |||
73 | /* GPIO port F. */ | ||
74 | #define EP93XX_GPIO_LINE_F(x) ((x) + 40) | ||
75 | #define EP93XX_GPIO_LINE_WP EP93XX_GPIO_LINE_F(0) | ||
76 | #define EP93XX_GPIO_LINE_MCCD1 EP93XX_GPIO_LINE_F(1) | ||
77 | #define EP93XX_GPIO_LINE_MCCD2 EP93XX_GPIO_LINE_F(2) | ||
78 | #define EP93XX_GPIO_LINE_MCBVD1 EP93XX_GPIO_LINE_F(3) | ||
79 | #define EP93XX_GPIO_LINE_MCBVD2 EP93XX_GPIO_LINE_F(4) | ||
80 | #define EP93XX_GPIO_LINE_VS1 EP93XX_GPIO_LINE_F(5) | ||
81 | #define EP93XX_GPIO_LINE_READY EP93XX_GPIO_LINE_F(6) | ||
82 | #define EP93XX_GPIO_LINE_VS2 EP93XX_GPIO_LINE_F(7) | ||
83 | |||
84 | /* GPIO port G. */ | ||
85 | #define EP93XX_GPIO_LINE_G(x) ((x) + 48) | ||
86 | #define EP93XX_GPIO_LINE_EECLK EP93XX_GPIO_LINE_G(0) | ||
87 | #define EP93XX_GPIO_LINE_EEDAT EP93XX_GPIO_LINE_G(1) | ||
88 | #define EP93XX_GPIO_LINE_SLA0 EP93XX_GPIO_LINE_G(2) | ||
89 | #define EP93XX_GPIO_LINE_SLA1 EP93XX_GPIO_LINE_G(3) | ||
90 | #define EP93XX_GPIO_LINE_DD12 EP93XX_GPIO_LINE_G(4) | ||
91 | #define EP93XX_GPIO_LINE_DD13 EP93XX_GPIO_LINE_G(5) | ||
92 | #define EP93XX_GPIO_LINE_DD14 EP93XX_GPIO_LINE_G(6) | ||
93 | #define EP93XX_GPIO_LINE_DD15 EP93XX_GPIO_LINE_G(7) | ||
94 | |||
95 | /* GPIO port H. */ | ||
96 | #define EP93XX_GPIO_LINE_H(x) ((x) + 56) | ||
97 | #define EP93XX_GPIO_LINE_DD0 EP93XX_GPIO_LINE_H(0) | ||
98 | #define EP93XX_GPIO_LINE_DD1 EP93XX_GPIO_LINE_H(1) | ||
99 | #define EP93XX_GPIO_LINE_DD2 EP93XX_GPIO_LINE_H(2) | ||
100 | #define EP93XX_GPIO_LINE_DD3 EP93XX_GPIO_LINE_H(3) | ||
101 | #define EP93XX_GPIO_LINE_DD4 EP93XX_GPIO_LINE_H(4) | ||
102 | #define EP93XX_GPIO_LINE_DD5 EP93XX_GPIO_LINE_H(5) | ||
103 | #define EP93XX_GPIO_LINE_DD6 EP93XX_GPIO_LINE_H(6) | ||
104 | #define EP93XX_GPIO_LINE_DD7 EP93XX_GPIO_LINE_H(7) | ||
105 | |||
106 | |||
107 | #endif | ||