aboutsummaryrefslogtreecommitdiffstats
path: root/arch/cris/arch-v10
diff options
context:
space:
mode:
authorJesper Nilsson <jesper.nilsson@axis.com>2008-02-06 08:52:40 -0500
committerJesper Nilsson <jesper.nilsson@axis.com>2008-02-08 05:16:45 -0500
commitad433f2368c37a64d119a997a0530cc28b9a5566 (patch)
tree6bd274f8e7fdc867e393bd145b3cee4cf923a674 /arch/cris/arch-v10
parent5efa1d1c940f07e79469e20db2b7a73c44180e82 (diff)
CRIS v10: Cleanup of drivers/gpio.c
- Change parameters of gpio_write (const char * buf -> const char __user *buf) - Don't initialize static variables to zero. - Remove useless casts from void. - Change name of interrupt routine (gpio_pa_interrupt -> gpio_interrupt) - Use kzmalloc instead of allocating memory and zeroing it manually. - Correct casts for copy_to_user and copy_from_user to (void __user *) - Make file_operations gpio_fops static. - Make ioif_watcher static, not used outside this file.
Diffstat (limited to 'arch/cris/arch-v10')
-rw-r--r--arch/cris/arch-v10/drivers/gpio.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/arch/cris/arch-v10/drivers/gpio.c b/arch/cris/arch-v10/drivers/gpio.c
index 26ae11be208d..68a998bd1069 100644
--- a/arch/cris/arch-v10/drivers/gpio.c
+++ b/arch/cris/arch-v10/drivers/gpio.c
@@ -46,9 +46,9 @@ static wait_queue_head_t *gpio_wq;
46#endif 46#endif
47 47
48static int gpio_ioctl(struct inode *inode, struct file *file, 48static int gpio_ioctl(struct inode *inode, struct file *file,
49 unsigned int cmd, unsigned long arg); 49 unsigned int cmd, unsigned long arg);
50static ssize_t gpio_write(struct file * file, const char * buf, size_t count, 50static ssize_t gpio_write(struct file *file, const char __user *buf,
51 loff_t *off); 51 size_t count, loff_t *off);
52static int gpio_open(struct inode *inode, struct file *filp); 52static int gpio_open(struct inode *inode, struct file *filp);
53static int gpio_release(struct inode *inode, struct file *filp); 53static int gpio_release(struct inode *inode, struct file *filp);
54static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait); 54static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait);
@@ -74,10 +74,10 @@ struct gpio_private {
74 74
75/* linked list of alarms to check for */ 75/* linked list of alarms to check for */
76 76
77static struct gpio_private *alarmlist = 0; 77static struct gpio_private *alarmlist;
78 78
79static int gpio_some_alarms = 0; /* Set if someone uses alarm */ 79static int gpio_some_alarms; /* Set if someone uses alarm */
80static unsigned long gpio_pa_irq_enabled_mask = 0; 80static unsigned long gpio_pa_irq_enabled_mask;
81 81
82static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */ 82static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */
83 83
@@ -145,7 +145,7 @@ static unsigned long dir_g_shadow; /* 1=output */
145static unsigned int gpio_poll(struct file *file, poll_table *wait) 145static unsigned int gpio_poll(struct file *file, poll_table *wait)
146{ 146{
147 unsigned int mask = 0; 147 unsigned int mask = 0;
148 struct gpio_private *priv = (struct gpio_private *)file->private_data; 148 struct gpio_private *priv = file->private_data;
149 unsigned long data; 149 unsigned long data;
150 unsigned long flags; 150 unsigned long flags;
151 151
@@ -222,7 +222,7 @@ gpio_poll_timer_interrupt(int irq, void *dev_id)
222} 222}
223 223
224static irqreturn_t 224static irqreturn_t
225gpio_pa_interrupt(int irq, void *dev_id) 225gpio_interrupt(int irq, void *dev_id)
226{ 226{
227 unsigned long tmp; 227 unsigned long tmp;
228 unsigned long flags; 228 unsigned long flags;
@@ -272,10 +272,10 @@ static void gpio_write_byte(struct gpio_private *priv, unsigned char data)
272 gpio_write_bit(priv, data, i); 272 gpio_write_bit(priv, data, i);
273} 273}
274 274
275static ssize_t gpio_write(struct file * file, const char * buf, size_t count, 275static ssize_t gpio_write(struct file *file, const char __user *buf,
276 loff_t *off) 276 size_t count, loff_t *off)
277{ 277{
278 struct gpio_private *priv = (struct gpio_private *)file->private_data; 278 struct gpio_private *priv = file->private_data;
279 unsigned long flags; 279 unsigned long flags;
280 ssize_t retval = count; 280 ssize_t retval = count;
281 281
@@ -318,13 +318,11 @@ gpio_open(struct inode *inode, struct file *filp)
318 if (p > GPIO_MINOR_LAST) 318 if (p > GPIO_MINOR_LAST)
319 return -EINVAL; 319 return -EINVAL;
320 320
321 priv = kmalloc(sizeof(struct gpio_private), GFP_KERNEL); 321 priv = kzalloc(sizeof(struct gpio_private), GFP_KERNEL);
322 322
323 if (!priv) 323 if (!priv)
324 return -ENOMEM; 324 return -ENOMEM;
325 325
326 memset(priv, 0, sizeof(*priv));
327
328 priv->minor = p; 326 priv->minor = p;
329 327
330 /* initialize the io/alarm struct */ 328 /* initialize the io/alarm struct */
@@ -351,7 +349,7 @@ gpio_open(struct inode *inode, struct file *filp)
351 priv->data_mask = 0; 349 priv->data_mask = 0;
352 init_waitqueue_head(&priv->alarm_wq); 350 init_waitqueue_head(&priv->alarm_wq);
353 351
354 filp->private_data = (void *)priv; 352 filp->private_data = priv;
355 353
356 /* link it into our alarmlist */ 354 /* link it into our alarmlist */
357 spin_lock_irqsave(&gpio_lock, flags); 355 spin_lock_irqsave(&gpio_lock, flags);
@@ -372,7 +370,7 @@ gpio_release(struct inode *inode, struct file *filp)
372 spin_lock_irqsave(&gpio_lock, flags); 370 spin_lock_irqsave(&gpio_lock, flags);
373 371
374 p = alarmlist; 372 p = alarmlist;
375 todel = (struct gpio_private *)filp->private_data; 373 todel = filp->private_data;
376 374
377 /* unlink from alarmlist and free the private structure */ 375 /* unlink from alarmlist and free the private structure */
378 376
@@ -511,7 +509,7 @@ gpio_ioctl(struct inode *inode, struct file *file,
511 unsigned long val; 509 unsigned long val;
512 int ret = 0; 510 int ret = 0;
513 511
514 struct gpio_private *priv = (struct gpio_private *)file->private_data; 512 struct gpio_private *priv = file->private_data;
515 if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE) 513 if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE)
516 return -EINVAL; 514 return -EINVAL;
517 515
@@ -633,7 +631,7 @@ gpio_ioctl(struct inode *inode, struct file *file,
633 } else if (priv->minor == GPIO_MINOR_G) { 631 } else if (priv->minor == GPIO_MINOR_G) {
634 val = *R_PORT_G_DATA; 632 val = *R_PORT_G_DATA;
635 } 633 }
636 if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 634 if (copy_to_user((void __user *)arg, &val, sizeof(val)))
637 ret = -EFAULT; 635 ret = -EFAULT;
638 break; 636 break;
639 case IO_READ_OUTBITS: 637 case IO_READ_OUTBITS:
@@ -643,32 +641,32 @@ gpio_ioctl(struct inode *inode, struct file *file,
643 } else if (priv->minor == GPIO_MINOR_G) { 641 } else if (priv->minor == GPIO_MINOR_G) {
644 val = port_g_data_shadow; 642 val = port_g_data_shadow;
645 } 643 }
646 if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 644 if (copy_to_user((void __user *)arg, &val, sizeof(val)))
647 ret = -EFAULT; 645 ret = -EFAULT;
648 break; 646 break;
649 case IO_SETGET_INPUT: 647 case IO_SETGET_INPUT:
650 /* bits set in *arg is set to input, 648 /* bits set in *arg is set to input,
651 * *arg updated with current input pins. 649 * *arg updated with current input pins.
652 */ 650 */
653 if (copy_from_user(&val, (unsigned long*)arg, sizeof(val))) 651 if (copy_from_user(&val, (void __user *)arg, sizeof(val)))
654 { 652 {
655 ret = -EFAULT; 653 ret = -EFAULT;
656 break; 654 break;
657 } 655 }
658 val = setget_input(priv, val); 656 val = setget_input(priv, val);
659 if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 657 if (copy_to_user((void __user *)arg, &val, sizeof(val)))
660 ret = -EFAULT; 658 ret = -EFAULT;
661 break; 659 break;
662 case IO_SETGET_OUTPUT: 660 case IO_SETGET_OUTPUT:
663 /* bits set in *arg is set to output, 661 /* bits set in *arg is set to output,
664 * *arg updated with current output pins. 662 * *arg updated with current output pins.
665 */ 663 */
666 if (copy_from_user(&val, (unsigned long *)arg, sizeof(val))) { 664 if (copy_from_user(&val, (void __user *)arg, sizeof(val))) {
667 ret = -EFAULT; 665 ret = -EFAULT;
668 break; 666 break;
669 } 667 }
670 val = setget_output(priv, val); 668 val = setget_output(priv, val);
671 if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 669 if (copy_to_user((void __user *)arg, &val, sizeof(val)))
672 ret = -EFAULT; 670 ret = -EFAULT;
673 break; 671 break;
674 default: 672 default:
@@ -711,7 +709,7 @@ gpio_leds_ioctl(unsigned int cmd, unsigned long arg)
711 return 0; 709 return 0;
712} 710}
713 711
714const struct file_operations gpio_fops = { 712static const struct file_operations gpio_fops = {
715 .owner = THIS_MODULE, 713 .owner = THIS_MODULE,
716 .poll = gpio_poll, 714 .poll = gpio_poll,
717 .ioctl = gpio_ioctl, 715 .ioctl = gpio_ioctl,
@@ -720,10 +718,10 @@ const struct file_operations gpio_fops = {
720 .release = gpio_release, 718 .release = gpio_release,
721}; 719};
722 720
723void ioif_watcher(const unsigned int gpio_in_available, 721static void ioif_watcher(const unsigned int gpio_in_available,
724 const unsigned int gpio_out_available, 722 const unsigned int gpio_out_available,
725 const unsigned char pa_available, 723 const unsigned char pa_available,
726 const unsigned char pb_available) 724 const unsigned char pb_available)
727{ 725{
728 unsigned long int flags; 726 unsigned long int flags;
729 727
@@ -770,8 +768,7 @@ void ioif_watcher(const unsigned int gpio_in_available,
770 768
771/* main driver initialization routine, called from mem.c */ 769/* main driver initialization routine, called from mem.c */
772 770
773static __init int 771static int __init gpio_init(void)
774gpio_init(void)
775{ 772{
776 int res; 773 int res;
777#if defined (CONFIG_ETRAX_CSP0_LEDS) 774#if defined (CONFIG_ETRAX_CSP0_LEDS)
@@ -817,7 +814,7 @@ gpio_init(void)
817 printk(KERN_CRIT "err: timer0 irq for gpio\n"); 814 printk(KERN_CRIT "err: timer0 irq for gpio\n");
818 return res; 815 return res;
819 } 816 }
820 res = request_irq(PA_IRQ_NBR, gpio_pa_interrupt, 817 res = request_irq(PA_IRQ_NBR, gpio_interrupt,
821 IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name); 818 IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name);
822 if (res) 819 if (res)
823 printk(KERN_CRIT "err: PA irq for gpio\n"); 820 printk(KERN_CRIT "err: PA irq for gpio\n");
@@ -826,5 +823,5 @@ gpio_init(void)
826} 823}
827 824
828/* this makes sure that gpio_init is called during kernel boot */ 825/* this makes sure that gpio_init is called during kernel boot */
829
830module_init(gpio_init); 826module_init(gpio_init);
827