diff options
Diffstat (limited to 'arch/cris/arch-v10/drivers/gpio.c')
-rw-r--r-- | arch/cris/arch-v10/drivers/gpio.c | 634 |
1 files changed, 250 insertions, 384 deletions
diff --git a/arch/cris/arch-v10/drivers/gpio.c b/arch/cris/arch-v10/drivers/gpio.c index 0d347a705835..68a998bd1069 100644 --- a/arch/cris/arch-v10/drivers/gpio.c +++ b/arch/cris/arch-v10/drivers/gpio.c | |||
@@ -1,138 +1,11 @@ | |||
1 | /* $Id: gpio.c,v 1.17 2005/06/19 17:06:46 starvik Exp $ | 1 | /* |
2 | * | ||
3 | * Etrax general port I/O device | 2 | * Etrax general port I/O device |
4 | * | 3 | * |
5 | * Copyright (c) 1999, 2000, 2001, 2002 Axis Communications AB | 4 | * Copyright (c) 1999-2007 Axis Communications AB |
6 | * | 5 | * |
7 | * Authors: Bjorn Wesen (initial version) | 6 | * Authors: Bjorn Wesen (initial version) |
8 | * Ola Knutsson (LED handling) | 7 | * Ola Knutsson (LED handling) |
9 | * Johan Adolfsson (read/set directions, write, port G) | 8 | * Johan Adolfsson (read/set directions, write, port G) |
10 | * | ||
11 | * $Log: gpio.c,v $ | ||
12 | * Revision 1.17 2005/06/19 17:06:46 starvik | ||
13 | * Merge of Linux 2.6.12. | ||
14 | * | ||
15 | * Revision 1.16 2005/03/07 13:02:29 starvik | ||
16 | * Protect driver global states with spinlock | ||
17 | * | ||
18 | * Revision 1.15 2005/01/05 06:08:55 starvik | ||
19 | * No need to do local_irq_disable after local_irq_save. | ||
20 | * | ||
21 | * Revision 1.14 2004/12/13 12:21:52 starvik | ||
22 | * Added I/O and DMA allocators from Linux 2.4 | ||
23 | * | ||
24 | * Revision 1.12 2004/08/24 07:19:59 starvik | ||
25 | * Whitespace cleanup | ||
26 | * | ||
27 | * Revision 1.11 2004/05/14 07:58:03 starvik | ||
28 | * Merge of changes from 2.4 | ||
29 | * | ||
30 | * Revision 1.9 2003/09/11 07:29:48 starvik | ||
31 | * Merge of Linux 2.6.0-test5 | ||
32 | * | ||
33 | * Revision 1.8 2003/07/04 08:27:37 starvik | ||
34 | * Merge of Linux 2.5.74 | ||
35 | * | ||
36 | * Revision 1.7 2003/01/10 07:44:07 starvik | ||
37 | * init_ioremap is now called by kernel before drivers are initialized | ||
38 | * | ||
39 | * Revision 1.6 2002/12/11 13:13:57 starvik | ||
40 | * Added arch/ to v10 specific includes | ||
41 | * Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer) | ||
42 | * | ||
43 | * Revision 1.5 2002/11/20 11:56:11 starvik | ||
44 | * Merge of Linux 2.5.48 | ||
45 | * | ||
46 | * Revision 1.4 2002/11/18 10:10:05 starvik | ||
47 | * Linux 2.5 port of latest gpio.c from Linux 2.4 | ||
48 | * | ||
49 | * Revision 1.20 2002/10/16 21:16:24 johana | ||
50 | * Added support for PA high level interrupt. | ||
51 | * That gives 2ms response time with iodtest for high levels and 2-12 ms | ||
52 | * response time on low levels if the check is not made in | ||
53 | * process.c:cpu_idle() as well. | ||
54 | * | ||
55 | * Revision 1.19 2002/10/14 18:27:33 johana | ||
56 | * Implemented alarm handling so select() now works. | ||
57 | * Latency is around 6-9 ms with a etrax_gpio_wake_up_check() in | ||
58 | * cpu_idle(). | ||
59 | * Otherwise I get 15-18 ms (same as doing the poll in userspace - | ||
60 | * but less overhead). | ||
61 | * TODO? Perhaps we should add the check in IMMEDIATE_BH (or whatever it | ||
62 | * is in 2.4) as well? | ||
63 | * TODO? Perhaps call request_irq()/free_irq() only when needed? | ||
64 | * Increased version to 2.5 | ||
65 | * | ||
66 | * Revision 1.18 2002/10/11 15:02:00 johana | ||
67 | * Mask inverted 8 bit value in setget_input(). | ||
68 | * | ||
69 | * Revision 1.17 2002/06/17 15:53:01 johana | ||
70 | * Added IO_READ_INBITS, IO_READ_OUTBITS, IO_SETGET_INPUT and IO_SETGET_OUTPUT | ||
71 | * that take a pointer as argument and thus can handle 32 bit ports (G) | ||
72 | * correctly. | ||
73 | * These should be used instead of IO_READBITS, IO_SETINPUT and IO_SETOUTPUT. | ||
74 | * (especially if Port G bit 31 is used) | ||
75 | * | ||
76 | * Revision 1.16 2002/06/17 09:59:51 johana | ||
77 | * Returning 32 bit values in the ioctl return value doesn't work if bit | ||
78 | * 31 is set (could happen for port G), so mask it of with 0x7FFFFFFF. | ||
79 | * A new set of ioctl's will be added. | ||
80 | * | ||
81 | * Revision 1.15 2002/05/06 13:19:13 johana | ||
82 | * IO_SETINPUT returns mask with bit set = inputs for PA and PB as well. | ||
83 | * | ||
84 | * Revision 1.14 2002/04/12 12:01:53 johana | ||
85 | * Use global r_port_g_data_shadow. | ||
86 | * Moved gpio_init_port_g() closer to gpio_init() and marked it __init. | ||
87 | * | ||
88 | * Revision 1.13 2002/04/10 12:03:55 johana | ||
89 | * Added support for port G /dev/gpiog (minor 3). | ||
90 | * Changed indentation on switch cases. | ||
91 | * Fixed other spaces to tabs. | ||
92 | * | ||
93 | * Revision 1.12 2001/11/12 19:42:15 pkj | ||
94 | * * Corrected return values from gpio_leds_ioctl(). | ||
95 | * * Fixed compiler warnings. | ||
96 | * | ||
97 | * Revision 1.11 2001/10/30 14:39:12 johana | ||
98 | * Added D() around gpio_write printk. | ||
99 | * | ||
100 | * Revision 1.10 2001/10/25 10:24:42 johana | ||
101 | * Added IO_CFG_WRITE_MODE ioctl and write method that can do fast | ||
102 | * bittoggling in the kernel. (This speeds up programming an FPGA with 450kB | ||
103 | * from ~60 seconds to 4 seconds). | ||
104 | * Added save_flags/cli/restore_flags in ioctl. | ||
105 | * | ||
106 | * Revision 1.9 2001/05/04 14:16:07 matsfg | ||
107 | * Corrected spelling error | ||
108 | * | ||
109 | * Revision 1.8 2001/04/27 13:55:26 matsfg | ||
110 | * Moved initioremap. | ||
111 | * Turns off all LEDS on init. | ||
112 | * Added support for shutdown and powerbutton. | ||
113 | * | ||
114 | * Revision 1.7 2001/04/04 13:30:08 matsfg | ||
115 | * Added bitset and bitclear for leds. Calls init_ioremap to set up memmapping | ||
116 | * | ||
117 | * Revision 1.6 2001/03/26 16:03:06 bjornw | ||
118 | * Needs linux/config.h | ||
119 | * | ||
120 | * Revision 1.5 2001/03/26 14:22:03 bjornw | ||
121 | * Namechange of some config options | ||
122 | * | ||
123 | * Revision 1.4 2001/02/27 13:52:48 bjornw | ||
124 | * malloc.h -> slab.h | ||
125 | * | ||
126 | * Revision 1.3 2001/01/24 15:06:48 bjornw | ||
127 | * gpio_wq correct type | ||
128 | * | ||
129 | * Revision 1.2 2001/01/18 16:07:30 bjornw | ||
130 | * 2.4 port | ||
131 | * | ||
132 | * Revision 1.1 2001/01/18 15:55:16 bjornw | ||
133 | * Verbatim copy of etraxgpio.c from elinux 2.0 added | ||
134 | * | ||
135 | * | ||
136 | */ | 9 | */ |
137 | 10 | ||
138 | 11 | ||
@@ -165,7 +38,7 @@ static int dp_cnt; | |||
165 | #else | 38 | #else |
166 | #define DP(x) | 39 | #define DP(x) |
167 | #endif | 40 | #endif |
168 | 41 | ||
169 | static char gpio_name[] = "etrax gpio"; | 42 | static char gpio_name[] = "etrax gpio"; |
170 | 43 | ||
171 | #if 0 | 44 | #if 0 |
@@ -173,9 +46,9 @@ static wait_queue_head_t *gpio_wq; | |||
173 | #endif | 46 | #endif |
174 | 47 | ||
175 | static int gpio_ioctl(struct inode *inode, struct file *file, | 48 | static int gpio_ioctl(struct inode *inode, struct file *file, |
176 | unsigned int cmd, unsigned long arg); | 49 | unsigned int cmd, unsigned long arg); |
177 | static ssize_t gpio_write(struct file * file, const char * buf, size_t count, | 50 | static ssize_t gpio_write(struct file *file, const char __user *buf, |
178 | loff_t *off); | 51 | size_t count, loff_t *off); |
179 | static int gpio_open(struct inode *inode, struct file *filp); | 52 | static int gpio_open(struct inode *inode, struct file *filp); |
180 | static int gpio_release(struct inode *inode, struct file *filp); | 53 | static int gpio_release(struct inode *inode, struct file *filp); |
181 | static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait); | 54 | static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait); |
@@ -201,22 +74,22 @@ struct gpio_private { | |||
201 | 74 | ||
202 | /* linked list of alarms to check for */ | 75 | /* linked list of alarms to check for */ |
203 | 76 | ||
204 | static struct gpio_private *alarmlist = 0; | 77 | static struct gpio_private *alarmlist; |
205 | 78 | ||
206 | static int gpio_some_alarms = 0; /* Set if someone uses alarm */ | 79 | static int gpio_some_alarms; /* Set if someone uses alarm */ |
207 | static unsigned long gpio_pa_irq_enabled_mask = 0; | 80 | static unsigned long gpio_pa_irq_enabled_mask; |
208 | 81 | ||
209 | static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */ | 82 | static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */ |
210 | 83 | ||
211 | /* Port A and B use 8 bit access, but Port G is 32 bit */ | 84 | /* Port A and B use 8 bit access, but Port G is 32 bit */ |
212 | #define NUM_PORTS (GPIO_MINOR_B+1) | 85 | #define NUM_PORTS (GPIO_MINOR_B+1) |
213 | 86 | ||
214 | static volatile unsigned char *ports[NUM_PORTS] = { | 87 | static volatile unsigned char *ports[NUM_PORTS] = { |
215 | R_PORT_PA_DATA, | 88 | R_PORT_PA_DATA, |
216 | R_PORT_PB_DATA, | 89 | R_PORT_PB_DATA, |
217 | }; | 90 | }; |
218 | static volatile unsigned char *shads[NUM_PORTS] = { | 91 | static volatile unsigned char *shads[NUM_PORTS] = { |
219 | &port_pa_data_shadow, | 92 | &port_pa_data_shadow, |
220 | &port_pb_data_shadow | 93 | &port_pb_data_shadow |
221 | }; | 94 | }; |
222 | 95 | ||
@@ -236,29 +109,29 @@ static volatile unsigned char *shads[NUM_PORTS] = { | |||
236 | #endif | 109 | #endif |
237 | 110 | ||
238 | 111 | ||
239 | static unsigned char changeable_dir[NUM_PORTS] = { | 112 | static unsigned char changeable_dir[NUM_PORTS] = { |
240 | CONFIG_ETRAX_PA_CHANGEABLE_DIR, | 113 | CONFIG_ETRAX_PA_CHANGEABLE_DIR, |
241 | CONFIG_ETRAX_PB_CHANGEABLE_DIR | 114 | CONFIG_ETRAX_PB_CHANGEABLE_DIR |
242 | }; | 115 | }; |
243 | static unsigned char changeable_bits[NUM_PORTS] = { | 116 | static unsigned char changeable_bits[NUM_PORTS] = { |
244 | CONFIG_ETRAX_PA_CHANGEABLE_BITS, | 117 | CONFIG_ETRAX_PA_CHANGEABLE_BITS, |
245 | CONFIG_ETRAX_PB_CHANGEABLE_BITS | 118 | CONFIG_ETRAX_PB_CHANGEABLE_BITS |
246 | }; | 119 | }; |
247 | 120 | ||
248 | static volatile unsigned char *dir[NUM_PORTS] = { | 121 | static volatile unsigned char *dir[NUM_PORTS] = { |
249 | R_PORT_PA_DIR, | 122 | R_PORT_PA_DIR, |
250 | R_PORT_PB_DIR | 123 | R_PORT_PB_DIR |
251 | }; | 124 | }; |
252 | 125 | ||
253 | static volatile unsigned char *dir_shadow[NUM_PORTS] = { | 126 | static volatile unsigned char *dir_shadow[NUM_PORTS] = { |
254 | &port_pa_dir_shadow, | 127 | &port_pa_dir_shadow, |
255 | &port_pb_dir_shadow | 128 | &port_pb_dir_shadow |
256 | }; | 129 | }; |
257 | 130 | ||
258 | /* All bits in port g that can change dir. */ | 131 | /* All bits in port g that can change dir. */ |
259 | static const unsigned long int changeable_dir_g_mask = 0x01FFFF01; | 132 | static const unsigned long int changeable_dir_g_mask = 0x01FFFF01; |
260 | 133 | ||
261 | /* Port G is 32 bit, handle it special, some bits are both inputs | 134 | /* Port G is 32 bit, handle it special, some bits are both inputs |
262 | and outputs at the same time, only some of the bits can change direction | 135 | and outputs at the same time, only some of the bits can change direction |
263 | and some of them in groups of 8 bit. */ | 136 | and some of them in groups of 8 bit. */ |
264 | static unsigned long changeable_dir_g; | 137 | static unsigned long changeable_dir_g; |
@@ -269,18 +142,17 @@ static unsigned long dir_g_shadow; /* 1=output */ | |||
269 | #define USE_PORTS(priv) ((priv)->minor <= GPIO_MINOR_B) | 142 | #define USE_PORTS(priv) ((priv)->minor <= GPIO_MINOR_B) |
270 | 143 | ||
271 | 144 | ||
272 | 145 | static unsigned int gpio_poll(struct file *file, poll_table *wait) | |
273 | static unsigned int | ||
274 | gpio_poll(struct file *file, | ||
275 | poll_table *wait) | ||
276 | { | 146 | { |
277 | unsigned int mask = 0; | 147 | unsigned int mask = 0; |
278 | struct gpio_private *priv = (struct gpio_private *)file->private_data; | 148 | struct gpio_private *priv = file->private_data; |
279 | unsigned long data; | 149 | unsigned long data; |
280 | spin_lock(&gpio_lock); | 150 | unsigned long flags; |
151 | |||
152 | spin_lock_irqsave(&gpio_lock, flags); | ||
153 | |||
281 | poll_wait(file, &priv->alarm_wq, wait); | 154 | poll_wait(file, &priv->alarm_wq, wait); |
282 | if (priv->minor == GPIO_MINOR_A) { | 155 | if (priv->minor == GPIO_MINOR_A) { |
283 | unsigned long flags; | ||
284 | unsigned long tmp; | 156 | unsigned long tmp; |
285 | data = *R_PORT_PA_DATA; | 157 | data = *R_PORT_PA_DATA; |
286 | /* PA has support for high level interrupt - | 158 | /* PA has support for high level interrupt - |
@@ -288,27 +160,25 @@ gpio_poll(struct file *file, | |||
288 | */ | 160 | */ |
289 | tmp = ~data & priv->highalarm & 0xFF; | 161 | tmp = ~data & priv->highalarm & 0xFF; |
290 | tmp = (tmp << R_IRQ_MASK1_SET__pa0__BITNR); | 162 | tmp = (tmp << R_IRQ_MASK1_SET__pa0__BITNR); |
291 | local_irq_save(flags); | 163 | |
292 | gpio_pa_irq_enabled_mask |= tmp; | 164 | gpio_pa_irq_enabled_mask |= tmp; |
293 | *R_IRQ_MASK1_SET = tmp; | 165 | *R_IRQ_MASK1_SET = tmp; |
294 | local_irq_restore(flags); | ||
295 | |||
296 | } else if (priv->minor == GPIO_MINOR_B) | 166 | } else if (priv->minor == GPIO_MINOR_B) |
297 | data = *R_PORT_PB_DATA; | 167 | data = *R_PORT_PB_DATA; |
298 | else if (priv->minor == GPIO_MINOR_G) | 168 | else if (priv->minor == GPIO_MINOR_G) |
299 | data = *R_PORT_G_DATA; | 169 | data = *R_PORT_G_DATA; |
300 | else { | 170 | else { |
301 | spin_unlock(&gpio_lock); | 171 | mask = 0; |
302 | return 0; | 172 | goto out; |
303 | } | 173 | } |
304 | 174 | ||
305 | if ((data & priv->highalarm) || | 175 | if ((data & priv->highalarm) || |
306 | (~data & priv->lowalarm)) { | 176 | (~data & priv->lowalarm)) { |
307 | mask = POLLIN|POLLRDNORM; | 177 | mask = POLLIN|POLLRDNORM; |
308 | } | 178 | } |
309 | 179 | ||
310 | spin_unlock(&gpio_lock); | 180 | out: |
311 | 181 | spin_unlock_irqrestore(&gpio_lock, flags); | |
312 | DP(printk("gpio_poll ready: mask 0x%08X\n", mask)); | 182 | DP(printk("gpio_poll ready: mask 0x%08X\n", mask)); |
313 | 183 | ||
314 | return mask; | 184 | return mask; |
@@ -316,16 +186,19 @@ gpio_poll(struct file *file, | |||
316 | 186 | ||
317 | int etrax_gpio_wake_up_check(void) | 187 | int etrax_gpio_wake_up_check(void) |
318 | { | 188 | { |
319 | struct gpio_private *priv = alarmlist; | 189 | struct gpio_private *priv; |
320 | unsigned long data = 0; | 190 | unsigned long data = 0; |
321 | int ret = 0; | 191 | int ret = 0; |
322 | spin_lock(&gpio_lock); | 192 | unsigned long flags; |
193 | |||
194 | spin_lock_irqsave(&gpio_lock, flags); | ||
195 | priv = alarmlist; | ||
323 | while (priv) { | 196 | while (priv) { |
324 | if (USE_PORTS(priv)) { | 197 | if (USE_PORTS(priv)) |
325 | data = *priv->port; | 198 | data = *priv->port; |
326 | } else if (priv->minor == GPIO_MINOR_G) { | 199 | else if (priv->minor == GPIO_MINOR_G) |
327 | data = *R_PORT_G_DATA; | 200 | data = *R_PORT_G_DATA; |
328 | } | 201 | |
329 | if ((data & priv->highalarm) || | 202 | if ((data & priv->highalarm) || |
330 | (~data & priv->lowalarm)) { | 203 | (~data & priv->lowalarm)) { |
331 | DP(printk("etrax_gpio_wake_up_check %i\n",priv->minor)); | 204 | DP(printk("etrax_gpio_wake_up_check %i\n",priv->minor)); |
@@ -334,12 +207,12 @@ int etrax_gpio_wake_up_check(void) | |||
334 | } | 207 | } |
335 | priv = priv->next; | 208 | priv = priv->next; |
336 | } | 209 | } |
337 | spin_unlock(&gpio_lock); | 210 | spin_unlock_irqrestore(&gpio_lock, flags); |
338 | return ret; | 211 | return ret; |
339 | } | 212 | } |
340 | 213 | ||
341 | static irqreturn_t | 214 | static irqreturn_t |
342 | gpio_poll_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) | 215 | gpio_poll_timer_interrupt(int irq, void *dev_id) |
343 | { | 216 | { |
344 | if (gpio_some_alarms) { | 217 | if (gpio_some_alarms) { |
345 | etrax_gpio_wake_up_check(); | 218 | etrax_gpio_wake_up_check(); |
@@ -349,10 +222,13 @@ gpio_poll_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) | |||
349 | } | 222 | } |
350 | 223 | ||
351 | static irqreturn_t | 224 | static irqreturn_t |
352 | gpio_pa_interrupt(int irq, void *dev_id, struct pt_regs *regs) | 225 | gpio_interrupt(int irq, void *dev_id) |
353 | { | 226 | { |
354 | unsigned long tmp; | 227 | unsigned long tmp; |
355 | spin_lock(&gpio_lock); | 228 | unsigned long flags; |
229 | |||
230 | spin_lock_irqsave(&gpio_lock, flags); | ||
231 | |||
356 | /* Find what PA interrupts are active */ | 232 | /* Find what PA interrupts are active */ |
357 | tmp = (*R_IRQ_READ1); | 233 | tmp = (*R_IRQ_READ1); |
358 | 234 | ||
@@ -363,75 +239,70 @@ gpio_pa_interrupt(int irq, void *dev_id, struct pt_regs *regs) | |||
363 | *R_IRQ_MASK1_CLR = tmp; | 239 | *R_IRQ_MASK1_CLR = tmp; |
364 | gpio_pa_irq_enabled_mask &= ~tmp; | 240 | gpio_pa_irq_enabled_mask &= ~tmp; |
365 | 241 | ||
366 | spin_unlock(&gpio_lock); | 242 | spin_unlock_irqrestore(&gpio_lock, flags); |
367 | 243 | ||
368 | if (gpio_some_alarms) { | 244 | if (gpio_some_alarms) |
369 | return IRQ_RETVAL(etrax_gpio_wake_up_check()); | 245 | return IRQ_RETVAL(etrax_gpio_wake_up_check()); |
370 | } | 246 | |
371 | return IRQ_NONE; | 247 | return IRQ_NONE; |
372 | } | 248 | } |
373 | 249 | ||
250 | static void gpio_write_bit(struct gpio_private *priv, | ||
251 | unsigned char data, int bit) | ||
252 | { | ||
253 | *priv->port = *priv->shadow &= ~(priv->clk_mask); | ||
254 | if (data & 1 << bit) | ||
255 | *priv->port = *priv->shadow |= priv->data_mask; | ||
256 | else | ||
257 | *priv->port = *priv->shadow &= ~(priv->data_mask); | ||
258 | |||
259 | /* For FPGA: min 5.0ns (DCC) before CCLK high */ | ||
260 | *priv->port = *priv->shadow |= priv->clk_mask; | ||
261 | } | ||
374 | 262 | ||
375 | static ssize_t gpio_write(struct file * file, const char * buf, size_t count, | 263 | static void gpio_write_byte(struct gpio_private *priv, unsigned char data) |
376 | loff_t *off) | ||
377 | { | 264 | { |
378 | struct gpio_private *priv = (struct gpio_private *)file->private_data; | 265 | int i; |
379 | unsigned char data, clk_mask, data_mask, write_msb; | ||
380 | unsigned long flags; | ||
381 | 266 | ||
382 | spin_lock(&gpio_lock); | 267 | if (priv->write_msb) |
268 | for (i = 7; i >= 0; i--) | ||
269 | gpio_write_bit(priv, data, i); | ||
270 | else | ||
271 | for (i = 0; i <= 7; i++) | ||
272 | gpio_write_bit(priv, data, i); | ||
273 | } | ||
383 | 274 | ||
275 | static ssize_t gpio_write(struct file *file, const char __user *buf, | ||
276 | size_t count, loff_t *off) | ||
277 | { | ||
278 | struct gpio_private *priv = file->private_data; | ||
279 | unsigned long flags; | ||
384 | ssize_t retval = count; | 280 | ssize_t retval = count; |
385 | if (priv->minor !=GPIO_MINOR_A && priv->minor != GPIO_MINOR_B) { | 281 | |
386 | retval = -EFAULT; | 282 | if (priv->minor != GPIO_MINOR_A && priv->minor != GPIO_MINOR_B) |
387 | goto out; | 283 | return -EFAULT; |
388 | } | 284 | |
389 | 285 | if (!access_ok(VERIFY_READ, buf, count)) | |
390 | if (!access_ok(VERIFY_READ, buf, count)) { | 286 | return -EFAULT; |
391 | retval = -EFAULT; | 287 | |
392 | goto out; | 288 | spin_lock_irqsave(&gpio_lock, flags); |
393 | } | 289 | |
394 | clk_mask = priv->clk_mask; | ||
395 | data_mask = priv->data_mask; | ||
396 | /* It must have been configured using the IO_CFG_WRITE_MODE */ | 290 | /* It must have been configured using the IO_CFG_WRITE_MODE */ |
397 | /* Perhaps a better error code? */ | 291 | /* Perhaps a better error code? */ |
398 | if (clk_mask == 0 || data_mask == 0) { | 292 | if (priv->clk_mask == 0 || priv->data_mask == 0) { |
399 | retval = -EPERM; | 293 | retval = -EPERM; |
400 | goto out; | 294 | goto out; |
401 | } | 295 | } |
402 | write_msb = priv->write_msb; | 296 | |
403 | D(printk("gpio_write: %lu to data 0x%02X clk 0x%02X msb: %i\n",count, data_mask, clk_mask, write_msb)); | 297 | D(printk(KERN_DEBUG "gpio_write: %02X to data 0x%02X " |
404 | while (count--) { | 298 | "clk 0x%02X msb: %i\n", |
405 | int i; | 299 | count, priv->data_mask, priv->clk_mask, priv->write_msb)); |
406 | data = *buf++; | 300 | |
407 | if (priv->write_msb) { | 301 | while (count--) |
408 | for (i = 7; i >= 0;i--) { | 302 | gpio_write_byte(priv, *buf++); |
409 | local_irq_save(flags); | 303 | |
410 | *priv->port = *priv->shadow &= ~clk_mask; | ||
411 | if (data & 1<<i) | ||
412 | *priv->port = *priv->shadow |= data_mask; | ||
413 | else | ||
414 | *priv->port = *priv->shadow &= ~data_mask; | ||
415 | /* For FPGA: min 5.0ns (DCC) before CCLK high */ | ||
416 | *priv->port = *priv->shadow |= clk_mask; | ||
417 | local_irq_restore(flags); | ||
418 | } | ||
419 | } else { | ||
420 | for (i = 0; i <= 7;i++) { | ||
421 | local_irq_save(flags); | ||
422 | *priv->port = *priv->shadow &= ~clk_mask; | ||
423 | if (data & 1<<i) | ||
424 | *priv->port = *priv->shadow |= data_mask; | ||
425 | else | ||
426 | *priv->port = *priv->shadow &= ~data_mask; | ||
427 | /* For FPGA: min 5.0ns (DCC) before CCLK high */ | ||
428 | *priv->port = *priv->shadow |= clk_mask; | ||
429 | local_irq_restore(flags); | ||
430 | } | ||
431 | } | ||
432 | } | ||
433 | out: | 304 | out: |
434 | spin_unlock(&gpio_lock); | 305 | spin_unlock_irqrestore(&gpio_lock, flags); |
435 | return retval; | 306 | return retval; |
436 | } | 307 | } |
437 | 308 | ||
@@ -442,22 +313,20 @@ gpio_open(struct inode *inode, struct file *filp) | |||
442 | { | 313 | { |
443 | struct gpio_private *priv; | 314 | struct gpio_private *priv; |
444 | int p = iminor(inode); | 315 | int p = iminor(inode); |
316 | unsigned long flags; | ||
445 | 317 | ||
446 | if (p > GPIO_MINOR_LAST) | 318 | if (p > GPIO_MINOR_LAST) |
447 | return -EINVAL; | 319 | return -EINVAL; |
448 | 320 | ||
449 | priv = kmalloc(sizeof(struct gpio_private), | 321 | priv = kzalloc(sizeof(struct gpio_private), GFP_KERNEL); |
450 | GFP_KERNEL); | ||
451 | 322 | ||
452 | if (!priv) | 323 | if (!priv) |
453 | return -ENOMEM; | 324 | return -ENOMEM; |
454 | 325 | ||
455 | priv->minor = p; | 326 | priv->minor = p; |
456 | 327 | ||
457 | /* initialize the io/alarm struct and link it into our alarmlist */ | 328 | /* initialize the io/alarm struct */ |
458 | 329 | ||
459 | priv->next = alarmlist; | ||
460 | alarmlist = priv; | ||
461 | if (USE_PORTS(priv)) { /* A and B */ | 330 | if (USE_PORTS(priv)) { /* A and B */ |
462 | priv->port = ports[p]; | 331 | priv->port = ports[p]; |
463 | priv->shadow = shads[p]; | 332 | priv->shadow = shads[p]; |
@@ -480,7 +349,13 @@ gpio_open(struct inode *inode, struct file *filp) | |||
480 | priv->data_mask = 0; | 349 | priv->data_mask = 0; |
481 | init_waitqueue_head(&priv->alarm_wq); | 350 | init_waitqueue_head(&priv->alarm_wq); |
482 | 351 | ||
483 | filp->private_data = (void *)priv; | 352 | filp->private_data = priv; |
353 | |||
354 | /* link it into our alarmlist */ | ||
355 | spin_lock_irqsave(&gpio_lock, flags); | ||
356 | priv->next = alarmlist; | ||
357 | alarmlist = priv; | ||
358 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
484 | 359 | ||
485 | return 0; | 360 | return 0; |
486 | } | 361 | } |
@@ -490,11 +365,12 @@ gpio_release(struct inode *inode, struct file *filp) | |||
490 | { | 365 | { |
491 | struct gpio_private *p; | 366 | struct gpio_private *p; |
492 | struct gpio_private *todel; | 367 | struct gpio_private *todel; |
368 | unsigned long flags; | ||
493 | 369 | ||
494 | spin_lock(&gpio_lock); | 370 | spin_lock_irqsave(&gpio_lock, flags); |
495 | 371 | ||
496 | p = alarmlist; | 372 | p = alarmlist; |
497 | todel = (struct gpio_private *)filp->private_data; | 373 | todel = filp->private_data; |
498 | 374 | ||
499 | /* unlink from alarmlist and free the private structure */ | 375 | /* unlink from alarmlist and free the private structure */ |
500 | 376 | ||
@@ -512,123 +388,114 @@ gpio_release(struct inode *inode, struct file *filp) | |||
512 | while (p) { | 388 | while (p) { |
513 | if (p->highalarm | p->lowalarm) { | 389 | if (p->highalarm | p->lowalarm) { |
514 | gpio_some_alarms = 1; | 390 | gpio_some_alarms = 1; |
515 | spin_unlock(&gpio_lock); | 391 | goto out; |
516 | return 0; | ||
517 | } | 392 | } |
518 | p = p->next; | 393 | p = p->next; |
519 | } | 394 | } |
520 | gpio_some_alarms = 0; | 395 | gpio_some_alarms = 0; |
521 | spin_unlock(&gpio_lock); | 396 | out: |
397 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
522 | return 0; | 398 | return 0; |
523 | } | 399 | } |
524 | 400 | ||
525 | /* Main device API. ioctl's to read/set/clear bits, as well as to | 401 | /* Main device API. ioctl's to read/set/clear bits, as well as to |
526 | * set alarms to wait for using a subsequent select(). | 402 | * set alarms to wait for using a subsequent select(). |
527 | */ | 403 | */ |
528 | |||
529 | unsigned long inline setget_input(struct gpio_private *priv, unsigned long arg) | 404 | unsigned long inline setget_input(struct gpio_private *priv, unsigned long arg) |
530 | { | 405 | { |
531 | /* Set direction 0=unchanged 1=input, | 406 | /* Set direction 0=unchanged 1=input, |
532 | * return mask with 1=input | 407 | * return mask with 1=input */ |
533 | */ | ||
534 | unsigned long flags; | ||
535 | if (USE_PORTS(priv)) { | 408 | if (USE_PORTS(priv)) { |
536 | local_irq_save(flags); | 409 | *priv->dir = *priv->dir_shadow &= |
537 | *priv->dir = *priv->dir_shadow &= | ||
538 | ~((unsigned char)arg & priv->changeable_dir); | 410 | ~((unsigned char)arg & priv->changeable_dir); |
539 | local_irq_restore(flags); | ||
540 | return ~(*priv->dir_shadow) & 0xFF; /* Only 8 bits */ | 411 | return ~(*priv->dir_shadow) & 0xFF; /* Only 8 bits */ |
541 | } else if (priv->minor == GPIO_MINOR_G) { | 412 | } |
542 | /* We must fiddle with R_GEN_CONFIG to change dir */ | 413 | |
543 | local_irq_save(flags); | 414 | if (priv->minor != GPIO_MINOR_G) |
544 | if (((arg & dir_g_in_bits) != arg) && | 415 | return 0; |
545 | (arg & changeable_dir_g)) { | 416 | |
546 | arg &= changeable_dir_g; | 417 | /* We must fiddle with R_GEN_CONFIG to change dir */ |
547 | /* Clear bits in genconfig to set to input */ | 418 | if (((arg & dir_g_in_bits) != arg) && |
548 | if (arg & (1<<0)) { | 419 | (arg & changeable_dir_g)) { |
549 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG,g0dir); | 420 | arg &= changeable_dir_g; |
550 | dir_g_in_bits |= (1<<0); | 421 | /* Clear bits in genconfig to set to input */ |
551 | dir_g_out_bits &= ~(1<<0); | 422 | if (arg & (1<<0)) { |
552 | } | 423 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g0dir); |
553 | if ((arg & 0x0000FF00) == 0x0000FF00) { | 424 | dir_g_in_bits |= (1<<0); |
554 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG,g8_15dir); | 425 | dir_g_out_bits &= ~(1<<0); |
555 | dir_g_in_bits |= 0x0000FF00; | ||
556 | dir_g_out_bits &= ~0x0000FF00; | ||
557 | } | ||
558 | if ((arg & 0x00FF0000) == 0x00FF0000) { | ||
559 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG,g16_23dir); | ||
560 | dir_g_in_bits |= 0x00FF0000; | ||
561 | dir_g_out_bits &= ~0x00FF0000; | ||
562 | } | ||
563 | if (arg & (1<<24)) { | ||
564 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG,g24dir); | ||
565 | dir_g_in_bits |= (1<<24); | ||
566 | dir_g_out_bits &= ~(1<<24); | ||
567 | } | ||
568 | D(printk(KERN_INFO "gpio: SETINPUT on port G set " | ||
569 | "genconfig to 0x%08lX " | ||
570 | "in_bits: 0x%08lX " | ||
571 | "out_bits: 0x%08lX\n", | ||
572 | (unsigned long)genconfig_shadow, | ||
573 | dir_g_in_bits, dir_g_out_bits)); | ||
574 | *R_GEN_CONFIG = genconfig_shadow; | ||
575 | /* Must be a >120 ns delay before writing this again */ | ||
576 | |||
577 | } | 426 | } |
578 | local_irq_restore(flags); | 427 | if ((arg & 0x0000FF00) == 0x0000FF00) { |
579 | return dir_g_in_bits; | 428 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g8_15dir); |
429 | dir_g_in_bits |= 0x0000FF00; | ||
430 | dir_g_out_bits &= ~0x0000FF00; | ||
431 | } | ||
432 | if ((arg & 0x00FF0000) == 0x00FF0000) { | ||
433 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g16_23dir); | ||
434 | dir_g_in_bits |= 0x00FF0000; | ||
435 | dir_g_out_bits &= ~0x00FF0000; | ||
436 | } | ||
437 | if (arg & (1<<24)) { | ||
438 | genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, g24dir); | ||
439 | dir_g_in_bits |= (1<<24); | ||
440 | dir_g_out_bits &= ~(1<<24); | ||
441 | } | ||
442 | D(printk(KERN_DEBUG "gpio: SETINPUT on port G set " | ||
443 | "genconfig to 0x%08lX " | ||
444 | "in_bits: 0x%08lX " | ||
445 | "out_bits: 0x%08lX\n", | ||
446 | (unsigned long)genconfig_shadow, | ||
447 | dir_g_in_bits, dir_g_out_bits)); | ||
448 | *R_GEN_CONFIG = genconfig_shadow; | ||
449 | /* Must be a >120 ns delay before writing this again */ | ||
450 | |||
580 | } | 451 | } |
581 | return 0; | 452 | return dir_g_in_bits; |
582 | } /* setget_input */ | 453 | } /* setget_input */ |
583 | 454 | ||
584 | unsigned long inline setget_output(struct gpio_private *priv, unsigned long arg) | 455 | unsigned long inline setget_output(struct gpio_private *priv, unsigned long arg) |
585 | { | 456 | { |
586 | unsigned long flags; | ||
587 | if (USE_PORTS(priv)) { | 457 | if (USE_PORTS(priv)) { |
588 | local_irq_save(flags); | 458 | *priv->dir = *priv->dir_shadow |= |
589 | *priv->dir = *priv->dir_shadow |= | 459 | ((unsigned char)arg & priv->changeable_dir); |
590 | ((unsigned char)arg & priv->changeable_dir); | ||
591 | local_irq_restore(flags); | ||
592 | return *priv->dir_shadow; | 460 | return *priv->dir_shadow; |
593 | } else if (priv->minor == GPIO_MINOR_G) { | 461 | } |
594 | /* We must fiddle with R_GEN_CONFIG to change dir */ | 462 | if (priv->minor != GPIO_MINOR_G) |
595 | local_irq_save(flags); | 463 | return 0; |
596 | if (((arg & dir_g_out_bits) != arg) && | 464 | |
597 | (arg & changeable_dir_g)) { | 465 | /* We must fiddle with R_GEN_CONFIG to change dir */ |
598 | /* Set bits in genconfig to set to output */ | 466 | if (((arg & dir_g_out_bits) != arg) && |
599 | if (arg & (1<<0)) { | 467 | (arg & changeable_dir_g)) { |
600 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG,g0dir); | 468 | /* Set bits in genconfig to set to output */ |
601 | dir_g_out_bits |= (1<<0); | 469 | if (arg & (1<<0)) { |
602 | dir_g_in_bits &= ~(1<<0); | 470 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g0dir); |
603 | } | 471 | dir_g_out_bits |= (1<<0); |
604 | if ((arg & 0x0000FF00) == 0x0000FF00) { | 472 | dir_g_in_bits &= ~(1<<0); |
605 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG,g8_15dir); | ||
606 | dir_g_out_bits |= 0x0000FF00; | ||
607 | dir_g_in_bits &= ~0x0000FF00; | ||
608 | } | ||
609 | if ((arg & 0x00FF0000) == 0x00FF0000) { | ||
610 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG,g16_23dir); | ||
611 | dir_g_out_bits |= 0x00FF0000; | ||
612 | dir_g_in_bits &= ~0x00FF0000; | ||
613 | } | ||
614 | if (arg & (1<<24)) { | ||
615 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG,g24dir); | ||
616 | dir_g_out_bits |= (1<<24); | ||
617 | dir_g_in_bits &= ~(1<<24); | ||
618 | } | ||
619 | D(printk(KERN_INFO "gpio: SETOUTPUT on port G set " | ||
620 | "genconfig to 0x%08lX " | ||
621 | "in_bits: 0x%08lX " | ||
622 | "out_bits: 0x%08lX\n", | ||
623 | (unsigned long)genconfig_shadow, | ||
624 | dir_g_in_bits, dir_g_out_bits)); | ||
625 | *R_GEN_CONFIG = genconfig_shadow; | ||
626 | /* Must be a >120 ns delay before writing this again */ | ||
627 | } | 473 | } |
628 | local_irq_restore(flags); | 474 | if ((arg & 0x0000FF00) == 0x0000FF00) { |
629 | return dir_g_out_bits & 0x7FFFFFFF; | 475 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g8_15dir); |
476 | dir_g_out_bits |= 0x0000FF00; | ||
477 | dir_g_in_bits &= ~0x0000FF00; | ||
478 | } | ||
479 | if ((arg & 0x00FF0000) == 0x00FF0000) { | ||
480 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g16_23dir); | ||
481 | dir_g_out_bits |= 0x00FF0000; | ||
482 | dir_g_in_bits &= ~0x00FF0000; | ||
483 | } | ||
484 | if (arg & (1<<24)) { | ||
485 | genconfig_shadow |= IO_MASK(R_GEN_CONFIG, g24dir); | ||
486 | dir_g_out_bits |= (1<<24); | ||
487 | dir_g_in_bits &= ~(1<<24); | ||
488 | } | ||
489 | D(printk(KERN_INFO "gpio: SETOUTPUT on port G set " | ||
490 | "genconfig to 0x%08lX " | ||
491 | "in_bits: 0x%08lX " | ||
492 | "out_bits: 0x%08lX\n", | ||
493 | (unsigned long)genconfig_shadow, | ||
494 | dir_g_in_bits, dir_g_out_bits)); | ||
495 | *R_GEN_CONFIG = genconfig_shadow; | ||
496 | /* Must be a >120 ns delay before writing this again */ | ||
630 | } | 497 | } |
631 | return 0; | 498 | return dir_g_out_bits & 0x7FFFFFFF; |
632 | } /* setget_output */ | 499 | } /* setget_output */ |
633 | 500 | ||
634 | static int | 501 | static int |
@@ -642,12 +509,11 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
642 | unsigned long val; | 509 | unsigned long val; |
643 | int ret = 0; | 510 | int ret = 0; |
644 | 511 | ||
645 | struct gpio_private *priv = (struct gpio_private *)file->private_data; | 512 | struct gpio_private *priv = file->private_data; |
646 | if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE) { | 513 | if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE) |
647 | return -EINVAL; | 514 | return -EINVAL; |
648 | } | ||
649 | 515 | ||
650 | spin_lock(&gpio_lock); | 516 | spin_lock_irqsave(&gpio_lock, flags); |
651 | 517 | ||
652 | switch (_IOC_NR(cmd)) { | 518 | switch (_IOC_NR(cmd)) { |
653 | case IO_READBITS: /* Use IO_READ_INBITS and IO_READ_OUTBITS instead */ | 519 | case IO_READBITS: /* Use IO_READ_INBITS and IO_READ_OUTBITS instead */ |
@@ -659,7 +525,6 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
659 | } | 525 | } |
660 | break; | 526 | break; |
661 | case IO_SETBITS: | 527 | case IO_SETBITS: |
662 | local_irq_save(flags); | ||
663 | // set changeable bits with a 1 in arg | 528 | // set changeable bits with a 1 in arg |
664 | if (USE_PORTS(priv)) { | 529 | if (USE_PORTS(priv)) { |
665 | *priv->port = *priv->shadow |= | 530 | *priv->port = *priv->shadow |= |
@@ -667,10 +532,8 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
667 | } else if (priv->minor == GPIO_MINOR_G) { | 532 | } else if (priv->minor == GPIO_MINOR_G) { |
668 | *R_PORT_G_DATA = port_g_data_shadow |= (arg & dir_g_out_bits); | 533 | *R_PORT_G_DATA = port_g_data_shadow |= (arg & dir_g_out_bits); |
669 | } | 534 | } |
670 | local_irq_restore(flags); | ||
671 | break; | 535 | break; |
672 | case IO_CLRBITS: | 536 | case IO_CLRBITS: |
673 | local_irq_save(flags); | ||
674 | // clear changeable bits with a 1 in arg | 537 | // clear changeable bits with a 1 in arg |
675 | if (USE_PORTS(priv)) { | 538 | if (USE_PORTS(priv)) { |
676 | *priv->port = *priv->shadow &= | 539 | *priv->port = *priv->shadow &= |
@@ -678,7 +541,6 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
678 | } else if (priv->minor == GPIO_MINOR_G) { | 541 | } else if (priv->minor == GPIO_MINOR_G) { |
679 | *R_PORT_G_DATA = port_g_data_shadow &= ~((unsigned long)arg & dir_g_out_bits); | 542 | *R_PORT_G_DATA = port_g_data_shadow &= ~((unsigned long)arg & dir_g_out_bits); |
680 | } | 543 | } |
681 | local_irq_restore(flags); | ||
682 | break; | 544 | break; |
683 | case IO_HIGHALARM: | 545 | case IO_HIGHALARM: |
684 | // set alarm when bits with 1 in arg go high | 546 | // set alarm when bits with 1 in arg go high |
@@ -698,6 +560,8 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
698 | /* Must update gpio_some_alarms */ | 560 | /* Must update gpio_some_alarms */ |
699 | struct gpio_private *p = alarmlist; | 561 | struct gpio_private *p = alarmlist; |
700 | int some_alarms; | 562 | int some_alarms; |
563 | spin_lock_irq(&gpio_lock); | ||
564 | p = alarmlist; | ||
701 | some_alarms = 0; | 565 | some_alarms = 0; |
702 | while (p) { | 566 | while (p) { |
703 | if (p->highalarm | p->lowalarm) { | 567 | if (p->highalarm | p->lowalarm) { |
@@ -707,6 +571,7 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
707 | p = p->next; | 571 | p = p->next; |
708 | } | 572 | } |
709 | gpio_some_alarms = some_alarms; | 573 | gpio_some_alarms = some_alarms; |
574 | spin_unlock_irq(&gpio_lock); | ||
710 | } | 575 | } |
711 | break; | 576 | break; |
712 | case IO_READDIR: /* Use IO_SETGET_INPUT/OUTPUT instead! */ | 577 | case IO_READDIR: /* Use IO_SETGET_INPUT/OUTPUT instead! */ |
@@ -766,7 +631,7 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
766 | } else if (priv->minor == GPIO_MINOR_G) { | 631 | } else if (priv->minor == GPIO_MINOR_G) { |
767 | val = *R_PORT_G_DATA; | 632 | val = *R_PORT_G_DATA; |
768 | } | 633 | } |
769 | if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) | 634 | if (copy_to_user((void __user *)arg, &val, sizeof(val))) |
770 | ret = -EFAULT; | 635 | ret = -EFAULT; |
771 | break; | 636 | break; |
772 | case IO_READ_OUTBITS: | 637 | case IO_READ_OUTBITS: |
@@ -776,33 +641,32 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
776 | } else if (priv->minor == GPIO_MINOR_G) { | 641 | } else if (priv->minor == GPIO_MINOR_G) { |
777 | val = port_g_data_shadow; | 642 | val = port_g_data_shadow; |
778 | } | 643 | } |
779 | if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) | 644 | if (copy_to_user((void __user *)arg, &val, sizeof(val))) |
780 | ret = -EFAULT; | 645 | ret = -EFAULT; |
781 | break; | 646 | break; |
782 | case IO_SETGET_INPUT: | 647 | case IO_SETGET_INPUT: |
783 | /* bits set in *arg is set to input, | 648 | /* bits set in *arg is set to input, |
784 | * *arg updated with current input pins. | 649 | * *arg updated with current input pins. |
785 | */ | 650 | */ |
786 | if (copy_from_user(&val, (unsigned long*)arg, sizeof(val))) | 651 | if (copy_from_user(&val, (void __user *)arg, sizeof(val))) |
787 | { | 652 | { |
788 | ret = -EFAULT; | 653 | ret = -EFAULT; |
789 | break; | 654 | break; |
790 | } | 655 | } |
791 | val = setget_input(priv, val); | 656 | val = setget_input(priv, val); |
792 | if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) | 657 | if (copy_to_user((void __user *)arg, &val, sizeof(val))) |
793 | ret = -EFAULT; | 658 | ret = -EFAULT; |
794 | break; | 659 | break; |
795 | case IO_SETGET_OUTPUT: | 660 | case IO_SETGET_OUTPUT: |
796 | /* bits set in *arg is set to output, | 661 | /* bits set in *arg is set to output, |
797 | * *arg updated with current output pins. | 662 | * *arg updated with current output pins. |
798 | */ | 663 | */ |
799 | if (copy_from_user(&val, (unsigned long*)arg, sizeof(val))) | 664 | if (copy_from_user(&val, (void __user *)arg, sizeof(val))) { |
800 | { | ||
801 | ret = -EFAULT; | 665 | ret = -EFAULT; |
802 | break; | 666 | break; |
803 | } | 667 | } |
804 | val = setget_output(priv, val); | 668 | val = setget_output(priv, val); |
805 | if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) | 669 | if (copy_to_user((void __user *)arg, &val, sizeof(val))) |
806 | ret = -EFAULT; | 670 | ret = -EFAULT; |
807 | break; | 671 | break; |
808 | default: | 672 | default: |
@@ -812,7 +676,7 @@ gpio_ioctl(struct inode *inode, struct file *file, | |||
812 | ret = -EINVAL; | 676 | ret = -EINVAL; |
813 | } /* switch */ | 677 | } /* switch */ |
814 | 678 | ||
815 | spin_unlock(&gpio_lock); | 679 | spin_unlock_irqrestore(&gpio_lock, flags); |
816 | return ret; | 680 | return ret; |
817 | } | 681 | } |
818 | 682 | ||
@@ -824,18 +688,18 @@ gpio_leds_ioctl(unsigned int cmd, unsigned long arg) | |||
824 | 688 | ||
825 | switch (_IOC_NR(cmd)) { | 689 | switch (_IOC_NR(cmd)) { |
826 | case IO_LEDACTIVE_SET: | 690 | case IO_LEDACTIVE_SET: |
827 | green = ((unsigned char) arg) & 1; | 691 | green = ((unsigned char)arg) & 1; |
828 | red = (((unsigned char) arg) >> 1) & 1; | 692 | red = (((unsigned char)arg) >> 1) & 1; |
829 | LED_ACTIVE_SET_G(green); | 693 | CRIS_LED_ACTIVE_SET_G(green); |
830 | LED_ACTIVE_SET_R(red); | 694 | CRIS_LED_ACTIVE_SET_R(red); |
831 | break; | 695 | break; |
832 | 696 | ||
833 | case IO_LED_SETBIT: | 697 | case IO_LED_SETBIT: |
834 | LED_BIT_SET(arg); | 698 | CRIS_LED_BIT_SET(arg); |
835 | break; | 699 | break; |
836 | 700 | ||
837 | case IO_LED_CLRBIT: | 701 | case IO_LED_CLRBIT: |
838 | LED_BIT_CLR(arg); | 702 | CRIS_LED_BIT_CLR(arg); |
839 | break; | 703 | break; |
840 | 704 | ||
841 | default: | 705 | default: |
@@ -845,7 +709,7 @@ gpio_leds_ioctl(unsigned int cmd, unsigned long arg) | |||
845 | return 0; | 709 | return 0; |
846 | } | 710 | } |
847 | 711 | ||
848 | const struct file_operations gpio_fops = { | 712 | static const struct file_operations gpio_fops = { |
849 | .owner = THIS_MODULE, | 713 | .owner = THIS_MODULE, |
850 | .poll = gpio_poll, | 714 | .poll = gpio_poll, |
851 | .ioctl = gpio_ioctl, | 715 | .ioctl = gpio_ioctl, |
@@ -854,16 +718,18 @@ const struct file_operations gpio_fops = { | |||
854 | .release = gpio_release, | 718 | .release = gpio_release, |
855 | }; | 719 | }; |
856 | 720 | ||
857 | 721 | static void ioif_watcher(const unsigned int gpio_in_available, | |
858 | void ioif_watcher(const unsigned int gpio_in_available, | 722 | const unsigned int gpio_out_available, |
859 | const unsigned int gpio_out_available, | 723 | const unsigned char pa_available, |
860 | const unsigned char pa_available, | 724 | const unsigned char pb_available) |
861 | const unsigned char pb_available) | ||
862 | { | 725 | { |
863 | unsigned long int flags; | 726 | unsigned long int flags; |
864 | D(printk("gpio.c: ioif_watcher called\n")); | 727 | |
865 | D(printk("gpio.c: G in: 0x%08x G out: 0x%08x PA: 0x%02x PB: 0x%02x\n", | 728 | D(printk(KERN_DEBUG "gpio.c: ioif_watcher called\n")); |
866 | gpio_in_available, gpio_out_available, pa_available, pb_available)); | 729 | D(printk(KERN_DEBUG "gpio.c: G in: 0x%08x G out: 0x%08x " |
730 | "PA: 0x%02x PB: 0x%02x\n", | ||
731 | gpio_in_available, gpio_out_available, | ||
732 | pa_available, pb_available)); | ||
867 | 733 | ||
868 | spin_lock_irqsave(&gpio_lock, flags); | 734 | spin_lock_irqsave(&gpio_lock, flags); |
869 | 735 | ||
@@ -872,7 +738,7 @@ void ioif_watcher(const unsigned int gpio_in_available, | |||
872 | 738 | ||
873 | /* Initialise the dir_g_shadow etc. depending on genconfig */ | 739 | /* Initialise the dir_g_shadow etc. depending on genconfig */ |
874 | /* 0=input 1=output */ | 740 | /* 0=input 1=output */ |
875 | if (genconfig_shadow & IO_STATE(R_GEN_CONFIG, g0dir, out)) | 741 | if (genconfig_shadow & IO_STATE(R_GEN_CONFIG, g0dir, out)) |
876 | dir_g_shadow |= (1 << 0); | 742 | dir_g_shadow |= (1 << 0); |
877 | if (genconfig_shadow & IO_STATE(R_GEN_CONFIG, g8_15dir, out)) | 743 | if (genconfig_shadow & IO_STATE(R_GEN_CONFIG, g8_15dir, out)) |
878 | dir_g_shadow |= 0x0000FF00; | 744 | dir_g_shadow |= 0x0000FF00; |
@@ -884,7 +750,8 @@ void ioif_watcher(const unsigned int gpio_in_available, | |||
884 | changeable_dir_g = changeable_dir_g_mask; | 750 | changeable_dir_g = changeable_dir_g_mask; |
885 | changeable_dir_g &= dir_g_out_bits; | 751 | changeable_dir_g &= dir_g_out_bits; |
886 | changeable_dir_g &= dir_g_in_bits; | 752 | changeable_dir_g &= dir_g_in_bits; |
887 | /* Correct the bits that can change direction */ | 753 | |
754 | /* Correct the bits that can change direction */ | ||
888 | dir_g_out_bits &= ~changeable_dir_g; | 755 | dir_g_out_bits &= ~changeable_dir_g; |
889 | dir_g_out_bits |= dir_g_shadow; | 756 | dir_g_out_bits |= dir_g_shadow; |
890 | dir_g_in_bits &= ~changeable_dir_g; | 757 | dir_g_in_bits &= ~changeable_dir_g; |
@@ -892,7 +759,8 @@ void ioif_watcher(const unsigned int gpio_in_available, | |||
892 | 759 | ||
893 | spin_unlock_irqrestore(&gpio_lock, flags); | 760 | spin_unlock_irqrestore(&gpio_lock, flags); |
894 | 761 | ||
895 | printk(KERN_INFO "GPIO port G: in_bits: 0x%08lX out_bits: 0x%08lX val: %08lX\n", | 762 | printk(KERN_INFO "GPIO port G: in_bits: 0x%08lX out_bits: 0x%08lX " |
763 | "val: %08lX\n", | ||
896 | dir_g_in_bits, dir_g_out_bits, (unsigned long)*R_PORT_G_DATA); | 764 | dir_g_in_bits, dir_g_out_bits, (unsigned long)*R_PORT_G_DATA); |
897 | printk(KERN_INFO "GPIO port G: dir: %08lX changeable: %08lX\n", | 765 | printk(KERN_INFO "GPIO port G: dir: %08lX changeable: %08lX\n", |
898 | dir_g_shadow, changeable_dir_g); | 766 | dir_g_shadow, changeable_dir_g); |
@@ -900,16 +768,12 @@ void ioif_watcher(const unsigned int gpio_in_available, | |||
900 | 768 | ||
901 | /* main driver initialization routine, called from mem.c */ | 769 | /* main driver initialization routine, called from mem.c */ |
902 | 770 | ||
903 | static __init int | 771 | static int __init gpio_init(void) |
904 | gpio_init(void) | ||
905 | { | 772 | { |
906 | int res; | 773 | int res; |
907 | #if defined (CONFIG_ETRAX_CSP0_LEDS) | 774 | #if defined (CONFIG_ETRAX_CSP0_LEDS) |
908 | int i; | 775 | int i; |
909 | #endif | 776 | #endif |
910 | printk("gpio init\n"); | ||
911 | |||
912 | /* do the formalities */ | ||
913 | 777 | ||
914 | res = register_chrdev(GPIO_MAJOR, gpio_name, &gpio_fops); | 778 | res = register_chrdev(GPIO_MAJOR, gpio_name, &gpio_fops); |
915 | if (res < 0) { | 779 | if (res < 0) { |
@@ -919,43 +783,45 @@ gpio_init(void) | |||
919 | 783 | ||
920 | /* Clear all leds */ | 784 | /* Clear all leds */ |
921 | #if defined (CONFIG_ETRAX_CSP0_LEDS) || defined (CONFIG_ETRAX_PA_LEDS) || defined (CONFIG_ETRAX_PB_LEDS) | 785 | #if defined (CONFIG_ETRAX_CSP0_LEDS) || defined (CONFIG_ETRAX_PA_LEDS) || defined (CONFIG_ETRAX_PB_LEDS) |
922 | LED_NETWORK_SET(0); | 786 | CRIS_LED_NETWORK_SET(0); |
923 | LED_ACTIVE_SET(0); | 787 | CRIS_LED_ACTIVE_SET(0); |
924 | LED_DISK_READ(0); | 788 | CRIS_LED_DISK_READ(0); |
925 | LED_DISK_WRITE(0); | 789 | CRIS_LED_DISK_WRITE(0); |
926 | 790 | ||
927 | #if defined (CONFIG_ETRAX_CSP0_LEDS) | 791 | #if defined (CONFIG_ETRAX_CSP0_LEDS) |
928 | for (i = 0; i < 32; i++) { | 792 | for (i = 0; i < 32; i++) |
929 | LED_BIT_SET(i); | 793 | CRIS_LED_BIT_SET(i); |
930 | } | ||
931 | #endif | 794 | #endif |
932 | 795 | ||
933 | #endif | 796 | #endif |
934 | /* The I/O interface allocation watcher will be called when | 797 | /* The I/O interface allocation watcher will be called when |
935 | * registering it. */ | 798 | * registering it. */ |
936 | if (cris_io_interface_register_watcher(ioif_watcher)){ | 799 | if (cris_io_interface_register_watcher(ioif_watcher)){ |
937 | printk(KERN_WARNING "gpio_init: Failed to install IO if allocator watcher\n"); | 800 | printk(KERN_WARNING "gpio_init: Failed to install IO " |
801 | "if allocator watcher\n"); | ||
938 | } | 802 | } |
939 | 803 | ||
940 | printk(KERN_INFO "ETRAX 100LX GPIO driver v2.5, (c) 2001, 2002, 2003, 2004 Axis Communications AB\n"); | 804 | printk(KERN_INFO "ETRAX 100LX GPIO driver v2.5, (c) 2001-2008 " |
805 | "Axis Communications AB\n"); | ||
941 | /* We call etrax_gpio_wake_up_check() from timer interrupt and | 806 | /* We call etrax_gpio_wake_up_check() from timer interrupt and |
942 | * from cpu_idle() in kernel/process.c | 807 | * from cpu_idle() in kernel/process.c |
943 | * The check in cpu_idle() reduces latency from ~15 ms to ~6 ms | 808 | * The check in cpu_idle() reduces latency from ~15 ms to ~6 ms |
944 | * in some tests. | 809 | * in some tests. |
945 | */ | 810 | */ |
946 | if (request_irq(TIMER0_IRQ_NBR, gpio_poll_timer_interrupt, | 811 | res = request_irq(TIMER0_IRQ_NBR, gpio_poll_timer_interrupt, |
947 | IRQF_SHARED | IRQF_DISABLED,"gpio poll", NULL)) { | 812 | IRQF_SHARED | IRQF_DISABLED, "gpio poll", gpio_name); |
813 | if (res) { | ||
948 | printk(KERN_CRIT "err: timer0 irq for gpio\n"); | 814 | printk(KERN_CRIT "err: timer0 irq for gpio\n"); |
815 | return res; | ||
949 | } | 816 | } |
950 | if (request_irq(PA_IRQ_NBR, gpio_pa_interrupt, | 817 | res = request_irq(PA_IRQ_NBR, gpio_interrupt, |
951 | IRQF_SHARED | IRQF_DISABLED,"gpio PA", NULL)) { | 818 | IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name); |
819 | if (res) | ||
952 | printk(KERN_CRIT "err: PA irq for gpio\n"); | 820 | printk(KERN_CRIT "err: PA irq for gpio\n"); |
953 | } | ||
954 | |||
955 | 821 | ||
956 | return res; | 822 | return res; |
957 | } | 823 | } |
958 | 824 | ||
959 | /* this makes sure that gpio_init is called during kernel boot */ | 825 | /* this makes sure that gpio_init is called during kernel boot */ |
960 | |||
961 | module_init(gpio_init); | 826 | module_init(gpio_init); |
827 | |||