diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2013-01-25 11:59:28 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-01-28 05:17:04 -0500 |
commit | b42748c970d1865685749960cb23f08e259a9f86 (patch) | |
tree | 659149c3fd8b2f7a3c4a3694e13a43f8fade265f /drivers/gpio | |
parent | 0e8f2fdacf1d44651aa7e57063c76142d1f4988b (diff) |
gpio: pca953x: use managed resources
Using the devm_* managed resources the pca driver can be simplified
and cut down on boilerplate code.
[gcl: fixed a inccorect reference to a removed label, "goto fail_out"
became "return ret"]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpio-pca953x.c | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 1dc99062eb14..24059462c87f 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c | |||
@@ -560,7 +560,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
560 | } | 560 | } |
561 | ret = pca953x_read_regs(chip, offset, chip->irq_stat); | 561 | ret = pca953x_read_regs(chip, offset, chip->irq_stat); |
562 | if (ret) | 562 | if (ret) |
563 | goto out_failed; | 563 | return ret; |
564 | 564 | ||
565 | /* | 565 | /* |
566 | * There is no way to know which GPIO line generated the | 566 | * There is no way to know which GPIO line generated the |
@@ -579,7 +579,8 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
579 | if (!chip->domain) | 579 | if (!chip->domain) |
580 | return -ENODEV; | 580 | return -ENODEV; |
581 | 581 | ||
582 | ret = request_threaded_irq(client->irq, | 582 | ret = devm_request_threaded_irq(&client->dev, |
583 | client->irq, | ||
583 | NULL, | 584 | NULL, |
584 | pca953x_irq_handler, | 585 | pca953x_irq_handler, |
585 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, | 586 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
@@ -596,12 +597,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
596 | return 0; | 597 | return 0; |
597 | } | 598 | } |
598 | 599 | ||
599 | static void pca953x_irq_teardown(struct pca953x_chip *chip) | ||
600 | { | ||
601 | if (chip->irq_base != -1) { | ||
602 | free_irq(chip->client->irq, chip); | ||
603 | } | ||
604 | } | ||
605 | #else /* CONFIG_GPIO_PCA953X_IRQ */ | 600 | #else /* CONFIG_GPIO_PCA953X_IRQ */ |
606 | static int pca953x_irq_setup(struct pca953x_chip *chip, | 601 | static int pca953x_irq_setup(struct pca953x_chip *chip, |
607 | const struct i2c_device_id *id, | 602 | const struct i2c_device_id *id, |
@@ -614,10 +609,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, | |||
614 | 609 | ||
615 | return 0; | 610 | return 0; |
616 | } | 611 | } |
617 | |||
618 | static void pca953x_irq_teardown(struct pca953x_chip *chip) | ||
619 | { | ||
620 | } | ||
621 | #endif | 612 | #endif |
622 | 613 | ||
623 | /* | 614 | /* |
@@ -736,7 +727,8 @@ static int pca953x_probe(struct i2c_client *client, | |||
736 | int ret; | 727 | int ret; |
737 | u32 invert = 0; | 728 | u32 invert = 0; |
738 | 729 | ||
739 | chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); | 730 | chip = devm_kzalloc(&client->dev, |
731 | sizeof(struct pca953x_chip), GFP_KERNEL); | ||
740 | if (chip == NULL) | 732 | if (chip == NULL) |
741 | return -ENOMEM; | 733 | return -ENOMEM; |
742 | 734 | ||
@@ -771,15 +763,15 @@ static int pca953x_probe(struct i2c_client *client, | |||
771 | else | 763 | else |
772 | ret = device_pca957x_init(chip, invert); | 764 | ret = device_pca957x_init(chip, invert); |
773 | if (ret) | 765 | if (ret) |
774 | goto out_failed; | 766 | return ret; |
775 | 767 | ||
776 | ret = pca953x_irq_setup(chip, id, irq_base); | 768 | ret = pca953x_irq_setup(chip, id, irq_base); |
777 | if (ret) | 769 | if (ret) |
778 | goto out_failed; | 770 | return ret; |
779 | 771 | ||
780 | ret = gpiochip_add(&chip->gpio_chip); | 772 | ret = gpiochip_add(&chip->gpio_chip); |
781 | if (ret) | 773 | if (ret) |
782 | goto out_failed_irq; | 774 | return ret; |
783 | 775 | ||
784 | if (pdata && pdata->setup) { | 776 | if (pdata && pdata->setup) { |
785 | ret = pdata->setup(client, chip->gpio_chip.base, | 777 | ret = pdata->setup(client, chip->gpio_chip.base, |
@@ -790,12 +782,6 @@ static int pca953x_probe(struct i2c_client *client, | |||
790 | 782 | ||
791 | i2c_set_clientdata(client, chip); | 783 | i2c_set_clientdata(client, chip); |
792 | return 0; | 784 | return 0; |
793 | |||
794 | out_failed_irq: | ||
795 | pca953x_irq_teardown(chip); | ||
796 | out_failed: | ||
797 | kfree(chip); | ||
798 | return ret; | ||
799 | } | 785 | } |
800 | 786 | ||
801 | static int pca953x_remove(struct i2c_client *client) | 787 | static int pca953x_remove(struct i2c_client *client) |
@@ -821,8 +807,6 @@ static int pca953x_remove(struct i2c_client *client) | |||
821 | return ret; | 807 | return ret; |
822 | } | 808 | } |
823 | 809 | ||
824 | pca953x_irq_teardown(chip); | ||
825 | kfree(chip); | ||
826 | return 0; | 810 | return 0; |
827 | } | 811 | } |
828 | 812 | ||