aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorPramod Gurav <pramod.gurav@smartplayin.com>2014-10-08 14:19:43 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-22 13:50:10 -0400
commit38c3807252085f97e1359400c8bf1312da3168c6 (patch)
treee6dfa61211f149076ef83e21b41c2568b10a72a6 /drivers/input/keyboard
parent254af0a3c7fe1959b0a865660f2f2004e023ddc3 (diff)
Input: pxa27x_keypad - switch to using managed resources
This change switches ithe driver to use devm_* APIs to allocate resources. This helps to simplify failure path in probe function and module unloading and does away with remove function. Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c84
1 files changed, 20 insertions, 64 deletions
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index a15063bea700..e08fc0ae913d 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -741,37 +741,27 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
741 return -ENXIO; 741 return -ENXIO;
742 } 742 }
743 743
744 keypad = kzalloc(sizeof(struct pxa27x_keypad), GFP_KERNEL); 744 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad),
745 input_dev = input_allocate_device(); 745 GFP_KERNEL);
746 if (!keypad || !input_dev) { 746 if (!keypad)
747 dev_err(&pdev->dev, "failed to allocate memory\n"); 747 return -ENOMEM;
748 error = -ENOMEM; 748
749 goto failed_free; 749 input_dev = devm_input_allocate_device(&pdev->dev);
750 } 750 if (!input_dev)
751 return -ENOMEM;
751 752
752 keypad->pdata = pdata; 753 keypad->pdata = pdata;
753 keypad->input_dev = input_dev; 754 keypad->input_dev = input_dev;
754 keypad->irq = irq; 755 keypad->irq = irq;
755 756
756 res = request_mem_region(res->start, resource_size(res), pdev->name); 757 keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res);
757 if (res == NULL) { 758 if (IS_ERR(keypad->mmio_base))
758 dev_err(&pdev->dev, "failed to request I/O memory\n"); 759 return PTR_ERR(keypad->mmio_base);
759 error = -EBUSY;
760 goto failed_free;
761 }
762
763 keypad->mmio_base = ioremap(res->start, resource_size(res));
764 if (keypad->mmio_base == NULL) {
765 dev_err(&pdev->dev, "failed to remap I/O memory\n");
766 error = -ENXIO;
767 goto failed_free_mem;
768 }
769 760
770 keypad->clk = clk_get(&pdev->dev, NULL); 761 keypad->clk = devm_clk_get(&pdev->dev, NULL);
771 if (IS_ERR(keypad->clk)) { 762 if (IS_ERR(keypad->clk)) {
772 dev_err(&pdev->dev, "failed to get keypad clock\n"); 763 dev_err(&pdev->dev, "failed to get keypad clock\n");
773 error = PTR_ERR(keypad->clk); 764 return PTR_ERR(keypad->clk);
774 goto failed_free_io;
775 } 765 }
776 766
777 input_dev->name = pdev->name; 767 input_dev->name = pdev->name;
@@ -802,7 +792,7 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
802 } 792 }
803 if (error) { 793 if (error) {
804 dev_err(&pdev->dev, "failed to build keycode\n"); 794 dev_err(&pdev->dev, "failed to build keycode\n");
805 goto failed_put_clk; 795 return error;
806 } 796 }
807 797
808 keypad->row_shift = get_count_order(pdata->matrix_key_cols); 798 keypad->row_shift = get_count_order(pdata->matrix_key_cols);
@@ -812,61 +802,26 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
812 input_dev->evbit[0] |= BIT_MASK(EV_REL); 802 input_dev->evbit[0] |= BIT_MASK(EV_REL);
813 } 803 }
814 804
815 error = request_irq(irq, pxa27x_keypad_irq_handler, 0, 805 error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler,
816 pdev->name, keypad); 806 0, pdev->name, keypad);
817 if (error) { 807 if (error) {
818 dev_err(&pdev->dev, "failed to request IRQ\n"); 808 dev_err(&pdev->dev, "failed to request IRQ\n");
819 goto failed_put_clk; 809 return error;
820 } 810 }
821 811
822 /* Register the input device */ 812 /* Register the input device */
823 error = input_register_device(input_dev); 813 error = input_register_device(input_dev);
824 if (error) { 814 if (error) {
825 dev_err(&pdev->dev, "failed to register input device\n"); 815 dev_err(&pdev->dev, "failed to register input device\n");
826 goto failed_free_irq; 816 return error;
827 } 817 }
828 818
829 platform_set_drvdata(pdev, keypad); 819 platform_set_drvdata(pdev, keypad);
830 device_init_wakeup(&pdev->dev, 1); 820 device_init_wakeup(&pdev->dev, 1);
831 821
832 return 0; 822 return 0;
833
834failed_free_irq:
835 free_irq(irq, keypad);
836failed_put_clk:
837 clk_put(keypad->clk);
838failed_free_io:
839 iounmap(keypad->mmio_base);
840failed_free_mem:
841 release_mem_region(res->start, resource_size(res));
842failed_free:
843 input_free_device(input_dev);
844 kfree(keypad);
845 return error;
846} 823}
847 824
848static int pxa27x_keypad_remove(struct platform_device *pdev)
849{
850 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev);
851 struct resource *res;
852
853 free_irq(keypad->irq, keypad);
854 clk_put(keypad->clk);
855
856 input_unregister_device(keypad->input_dev);
857 iounmap(keypad->mmio_base);
858
859 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
860 release_mem_region(res->start, resource_size(res));
861
862 kfree(keypad);
863
864 return 0;
865}
866
867/* work with hotplug and coldplug */
868MODULE_ALIAS("platform:pxa27x-keypad");
869
870#ifdef CONFIG_OF 825#ifdef CONFIG_OF
871static const struct of_device_id pxa27x_keypad_dt_match[] = { 826static const struct of_device_id pxa27x_keypad_dt_match[] = {
872 { .compatible = "marvell,pxa27x-keypad" }, 827 { .compatible = "marvell,pxa27x-keypad" },
@@ -877,7 +832,6 @@ MODULE_DEVICE_TABLE(of, pxa27x_keypad_dt_match);
877 832
878static struct platform_driver pxa27x_keypad_driver = { 833static struct platform_driver pxa27x_keypad_driver = {
879 .probe = pxa27x_keypad_probe, 834 .probe = pxa27x_keypad_probe,
880 .remove = pxa27x_keypad_remove,
881 .driver = { 835 .driver = {
882 .name = "pxa27x-keypad", 836 .name = "pxa27x-keypad",
883 .of_match_table = of_match_ptr(pxa27x_keypad_dt_match), 837 .of_match_table = of_match_ptr(pxa27x_keypad_dt_match),
@@ -889,3 +843,5 @@ module_platform_driver(pxa27x_keypad_driver);
889 843
890MODULE_DESCRIPTION("PXA27x Keypad Controller Driver"); 844MODULE_DESCRIPTION("PXA27x Keypad Controller Driver");
891MODULE_LICENSE("GPL"); 845MODULE_LICENSE("GPL");
846/* work with hotplug and coldplug */
847MODULE_ALIAS("platform:pxa27x-keypad");