diff options
author | Jesper Nilsson <jesper.nilsson@axis.com> | 2008-02-08 11:00:25 -0500 |
---|---|---|
committer | Jesper Nilsson <jesper.nilsson@axis.com> | 2008-02-08 11:00:25 -0500 |
commit | 69b06c15e7e24d2b17ec8f89a7f3ae9fa55f5667 (patch) | |
tree | dd8c6e72c31e8d2f33ce4fa77e3e9f1f3d37bb8e /arch/cris/arch-v32 | |
parent | a34d24425e9c133e875a26c0bbc91783cf485b93 (diff) |
CRIS v32: Change drivers/i2c.c locking.
- Change spin_lock + local_irq_save into spin_lock_irqsave
- Change spin_unlock + local_irq_restore into spin_unlock_irqrestore
- Return ENOTTY if ioctl is not recognized as a cris ioctl.
- Make init functions static.
Diffstat (limited to 'arch/cris/arch-v32')
-rw-r--r-- | arch/cris/arch-v32/drivers/i2c.c | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/arch/cris/arch-v32/drivers/i2c.c b/arch/cris/arch-v32/drivers/i2c.c index 4eda3236792a..c2fb7a5c1396 100644 --- a/arch/cris/arch-v32/drivers/i2c.c +++ b/arch/cris/arch-v32/drivers/i2c.c | |||
@@ -395,14 +395,10 @@ i2c_write(unsigned char theSlave, void *data, size_t nbytes) | |||
395 | unsigned char value; | 395 | unsigned char value; |
396 | unsigned long flags; | 396 | unsigned long flags; |
397 | 397 | ||
398 | spin_lock(&i2c_lock); | 398 | spin_lock_irqsave(&i2c_lock, flags); |
399 | 399 | ||
400 | do { | 400 | do { |
401 | error = 0; | 401 | error = 0; |
402 | /* | ||
403 | * we don't like to be interrupted | ||
404 | */ | ||
405 | local_irq_save(flags); | ||
406 | 402 | ||
407 | i2c_start(); | 403 | i2c_start(); |
408 | /* | 404 | /* |
@@ -430,16 +426,12 @@ i2c_write(unsigned char theSlave, void *data, size_t nbytes) | |||
430 | * end byte stream | 426 | * end byte stream |
431 | */ | 427 | */ |
432 | i2c_stop(); | 428 | i2c_stop(); |
433 | /* | ||
434 | * enable interrupt again | ||
435 | */ | ||
436 | local_irq_restore(flags); | ||
437 | 429 | ||
438 | } while (error && cntr--); | 430 | } while (error && cntr--); |
439 | 431 | ||
440 | i2c_delay(CLOCK_LOW_TIME); | 432 | i2c_delay(CLOCK_LOW_TIME); |
441 | 433 | ||
442 | spin_unlock(&i2c_lock); | 434 | spin_unlock_irqrestore(&i2c_lock, flags); |
443 | 435 | ||
444 | return -error; | 436 | return -error; |
445 | } | 437 | } |
@@ -459,16 +451,12 @@ i2c_read(unsigned char theSlave, void *data, size_t nbytes) | |||
459 | int error, cntr = 3; | 451 | int error, cntr = 3; |
460 | unsigned long flags; | 452 | unsigned long flags; |
461 | 453 | ||
462 | spin_lock(&i2c_lock); | 454 | spin_lock_irqsave(&i2c_lock, flags); |
463 | 455 | ||
464 | do { | 456 | do { |
465 | error = 0; | 457 | error = 0; |
466 | memset(data, 0, nbytes); | 458 | memset(data, 0, nbytes); |
467 | /* | 459 | /* |
468 | * we don't like to be interrupted | ||
469 | */ | ||
470 | local_irq_save(flags); | ||
471 | /* | ||
472 | * generate start condition | 460 | * generate start condition |
473 | */ | 461 | */ |
474 | i2c_start(); | 462 | i2c_start(); |
@@ -500,13 +488,9 @@ i2c_read(unsigned char theSlave, void *data, size_t nbytes) | |||
500 | * end sequence | 488 | * end sequence |
501 | */ | 489 | */ |
502 | i2c_stop(); | 490 | i2c_stop(); |
503 | /* | ||
504 | * enable interrupt again | ||
505 | */ | ||
506 | local_irq_restore(flags); | ||
507 | } while (error && cntr--); | 491 | } while (error && cntr--); |
508 | 492 | ||
509 | spin_unlock(&i2c_lock); | 493 | spin_unlock_irqrestore(&i2c_lock, flags); |
510 | 494 | ||
511 | return -error; | 495 | return -error; |
512 | } | 496 | } |
@@ -525,14 +509,10 @@ i2c_writereg(unsigned char theSlave, unsigned char theReg, | |||
525 | int error, cntr = 3; | 509 | int error, cntr = 3; |
526 | unsigned long flags; | 510 | unsigned long flags; |
527 | 511 | ||
528 | spin_lock(&i2c_lock); | 512 | spin_lock_irqsave(&i2c_lock, flags); |
529 | 513 | ||
530 | do { | 514 | do { |
531 | error = 0; | 515 | error = 0; |
532 | /* | ||
533 | * we don't like to be interrupted | ||
534 | */ | ||
535 | local_irq_save(flags); | ||
536 | 516 | ||
537 | i2c_start(); | 517 | i2c_start(); |
538 | /* | 518 | /* |
@@ -567,15 +547,11 @@ i2c_writereg(unsigned char theSlave, unsigned char theReg, | |||
567 | * end byte stream | 547 | * end byte stream |
568 | */ | 548 | */ |
569 | i2c_stop(); | 549 | i2c_stop(); |
570 | /* | ||
571 | * enable interrupt again | ||
572 | */ | ||
573 | local_irq_restore(flags); | ||
574 | } while(error && cntr--); | 550 | } while(error && cntr--); |
575 | 551 | ||
576 | i2c_delay(CLOCK_LOW_TIME); | 552 | i2c_delay(CLOCK_LOW_TIME); |
577 | 553 | ||
578 | spin_unlock(&i2c_lock); | 554 | spin_unlock_irqrestore(&i2c_lock, flags); |
579 | 555 | ||
580 | return -error; | 556 | return -error; |
581 | } | 557 | } |
@@ -594,15 +570,11 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg) | |||
594 | int error, cntr = 3; | 570 | int error, cntr = 3; |
595 | unsigned long flags; | 571 | unsigned long flags; |
596 | 572 | ||
597 | spin_lock(&i2c_lock); | 573 | spin_lock_irqsave(&i2c_lock, flags); |
598 | 574 | ||
599 | do { | 575 | do { |
600 | error = 0; | 576 | error = 0; |
601 | /* | 577 | /* |
602 | * we don't like to be interrupted | ||
603 | */ | ||
604 | local_irq_save(flags); | ||
605 | /* | ||
606 | * generate start condition | 578 | * generate start condition |
607 | */ | 579 | */ |
608 | i2c_start(); | 580 | i2c_start(); |
@@ -653,14 +625,10 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg) | |||
653 | * end sequence | 625 | * end sequence |
654 | */ | 626 | */ |
655 | i2c_stop(); | 627 | i2c_stop(); |
656 | /* | ||
657 | * enable interrupt again | ||
658 | */ | ||
659 | local_irq_restore(flags); | ||
660 | 628 | ||
661 | } while(error && cntr--); | 629 | } while(error && cntr--); |
662 | 630 | ||
663 | spin_unlock(&i2c_lock); | 631 | spin_unlock_irqrestore(&i2c_lock, flags); |
664 | 632 | ||
665 | return b; | 633 | return b; |
666 | } | 634 | } |
@@ -685,7 +653,7 @@ i2c_ioctl(struct inode *inode, struct file *file, | |||
685 | unsigned int cmd, unsigned long arg) | 653 | unsigned int cmd, unsigned long arg) |
686 | { | 654 | { |
687 | if(_IOC_TYPE(cmd) != ETRAXI2C_IOCTYPE) { | 655 | if(_IOC_TYPE(cmd) != ETRAXI2C_IOCTYPE) { |
688 | return -EINVAL; | 656 | return -ENOTTY; |
689 | } | 657 | } |
690 | 658 | ||
691 | switch (_IOC_NR(cmd)) { | 659 | switch (_IOC_NR(cmd)) { |
@@ -725,8 +693,7 @@ static const struct file_operations i2c_fops = { | |||
725 | .release = i2c_release, | 693 | .release = i2c_release, |
726 | }; | 694 | }; |
727 | 695 | ||
728 | int __init | 696 | static int __init i2c_init(void) |
729 | i2c_init(void) | ||
730 | { | 697 | { |
731 | static int res; | 698 | static int res; |
732 | static int first = 1; | 699 | static int first = 1; |
@@ -750,10 +717,8 @@ i2c_init(void) | |||
750 | } | 717 | } |
751 | 718 | ||
752 | 719 | ||
753 | int __init | 720 | static int __init i2c_register(void) |
754 | i2c_register(void) | ||
755 | { | 721 | { |
756 | |||
757 | int res; | 722 | int res; |
758 | 723 | ||
759 | res = i2c_init(); | 724 | res = i2c_init(); |
@@ -763,7 +728,7 @@ i2c_register(void) | |||
763 | /* register char device */ | 728 | /* register char device */ |
764 | 729 | ||
765 | res = register_chrdev(I2C_MAJOR, i2c_name, &i2c_fops); | 730 | res = register_chrdev(I2C_MAJOR, i2c_name, &i2c_fops); |
766 | if(res < 0) { | 731 | if (res < 0) { |
767 | printk(KERN_ERR "i2c: couldn't get a major number.\n"); | 732 | printk(KERN_ERR "i2c: couldn't get a major number.\n"); |
768 | return res; | 733 | return res; |
769 | } | 734 | } |
@@ -773,9 +738,7 @@ i2c_register(void) | |||
773 | 738 | ||
774 | return 0; | 739 | return 0; |
775 | } | 740 | } |
776 | |||
777 | /* this makes sure that i2c_init is called during boot */ | 741 | /* this makes sure that i2c_init is called during boot */ |
778 | |||
779 | module_init(i2c_register); | 742 | module_init(i2c_register); |
780 | 743 | ||
781 | /****************** END OF FILE i2c.c ********************************/ | 744 | /****************** END OF FILE i2c.c ********************************/ |