aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c56
1 files changed, 15 insertions, 41 deletions
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index c47d11493b97..ddc9970fd724 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -611,42 +611,25 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = {
611 .master_xfer = sh_mobile_i2c_xfer, 611 .master_xfer = sh_mobile_i2c_xfer,
612}; 612};
613 613
614static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook) 614static int sh_mobile_i2c_hook_irqs(struct platform_device *dev)
615{ 615{
616 struct resource *res; 616 struct resource *res;
617 int ret = -ENXIO; 617 resource_size_t n;
618 int n, k = 0; 618 int k = 0, ret;
619 619
620 while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) { 620 while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
621 for (n = res->start; hook && n <= res->end; n++) { 621 for (n = res->start; n <= res->end; n++) {
622 if (request_irq(n, sh_mobile_i2c_isr, 0, 622 ret = devm_request_irq(&dev->dev, n, sh_mobile_i2c_isr,
623 dev_name(&dev->dev), dev)) { 623 0, dev_name(&dev->dev), dev);
624 for (n--; n >= res->start; n--) 624 if (ret) {
625 free_irq(n, dev); 625 dev_err(&dev->dev, "cannot request IRQ %pa\n", &n);
626 626 return ret;
627 goto rollback;
628 } 627 }
629 } 628 }
630 k++; 629 k++;
631 } 630 }
632 631
633 if (hook) 632 return k > 0 ? 0 : -ENOENT;
634 return k > 0 ? 0 : -ENOENT;
635
636 ret = 0;
637
638 rollback:
639 k--;
640
641 while (k >= 0) {
642 res = platform_get_resource(dev, IORESOURCE_IRQ, k);
643 for (n = res->start; n <= res->end; n++)
644 free_irq(n, dev);
645
646 k--;
647 }
648
649 return ret;
650} 633}
651 634
652static int sh_mobile_i2c_probe(struct platform_device *dev) 635static int sh_mobile_i2c_probe(struct platform_device *dev)
@@ -668,11 +651,9 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
668 return PTR_ERR(pd->clk); 651 return PTR_ERR(pd->clk);
669 } 652 }
670 653
671 ret = sh_mobile_i2c_hook_irqs(dev, 1); 654 ret = sh_mobile_i2c_hook_irqs(dev);
672 if (ret) { 655 if (ret)
673 dev_err(&dev->dev, "cannot request IRQ\n");
674 return ret; 656 return ret;
675 }
676 657
677 pd->dev = &dev->dev; 658 pd->dev = &dev->dev;
678 platform_set_drvdata(dev, pd); 659 platform_set_drvdata(dev, pd);
@@ -680,10 +661,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
680 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 661 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
681 662
682 pd->reg = devm_ioremap_resource(&dev->dev, res); 663 pd->reg = devm_ioremap_resource(&dev->dev, res);
683 if (IS_ERR(pd->reg)) { 664 if (IS_ERR(pd->reg))
684 ret = PTR_ERR(pd->reg); 665 return PTR_ERR(pd->reg);
685 goto err_irq;
686 }
687 666
688 /* Use platform data bus speed or STANDARD_MODE */ 667 /* Use platform data bus speed or STANDARD_MODE */
689 ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); 668 ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed);
@@ -735,7 +714,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
735 ret = i2c_add_numbered_adapter(adap); 714 ret = i2c_add_numbered_adapter(adap);
736 if (ret < 0) { 715 if (ret < 0) {
737 dev_err(&dev->dev, "cannot add numbered adapter\n"); 716 dev_err(&dev->dev, "cannot add numbered adapter\n");
738 goto err_irq; 717 return ret;
739 } 718 }
740 719
741 dev_info(&dev->dev, 720 dev_info(&dev->dev,
@@ -743,10 +722,6 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
743 adap->nr, pd->bus_speed, pd->iccl, pd->icch); 722 adap->nr, pd->bus_speed, pd->iccl, pd->icch);
744 723
745 return 0; 724 return 0;
746
747 err_irq:
748 sh_mobile_i2c_hook_irqs(dev, 0);
749 return ret;
750} 725}
751 726
752static int sh_mobile_i2c_remove(struct platform_device *dev) 727static int sh_mobile_i2c_remove(struct platform_device *dev)
@@ -754,7 +729,6 @@ static int sh_mobile_i2c_remove(struct platform_device *dev)
754 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev); 729 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
755 730
756 i2c_del_adapter(&pd->adap); 731 i2c_del_adapter(&pd->adap);
757 sh_mobile_i2c_hook_irqs(dev, 0);
758 pm_runtime_disable(&dev->dev); 732 pm_runtime_disable(&dev->dev);
759 return 0; 733 return 0;
760} 734}