aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/otg/mv_otg.c
diff options
context:
space:
mode:
authorChao Xie <chao.xie@marvell.com>2013-01-24 01:38:28 -0500
committerFelipe Balbi <balbi@ti.com>2013-01-24 14:11:34 -0500
commitfb3dfe13d0cc7e76c9d4a73a72f17f80f63590a7 (patch)
tree53cccf0e50cde65a34257832a2db1ccfc73d958a /drivers/usb/otg/mv_otg.c
parent6a6f05f09772dfe2fa0a5a3ec6b786f4a40e7e54 (diff)
usb: otg: mv_otg: use devm_xxx for probe
use devm_xxx for otg driver probe. So we do need care about the resources release in driver remove or failure handling in driver probe. Signed-off-by: Chao Xie <chao.xie@marvell.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/otg/mv_otg.c')
-rw-r--r--drivers/usb/otg/mv_otg.c82
1 files changed, 22 insertions, 60 deletions
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c
index 1dd57504186d..fe1b56a31947 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/otg/mv_otg.c
@@ -662,18 +662,9 @@ static struct attribute_group inputs_attr_group = {
662int mv_otg_remove(struct platform_device *pdev) 662int mv_otg_remove(struct platform_device *pdev)
663{ 663{
664 struct mv_otg *mvotg = platform_get_drvdata(pdev); 664 struct mv_otg *mvotg = platform_get_drvdata(pdev);
665 int clk_i;
666 665
667 sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); 666 sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group);
668 667
669 if (mvotg->irq)
670 free_irq(mvotg->irq, mvotg);
671
672 if (mvotg->pdata->vbus)
673 free_irq(mvotg->pdata->vbus->irq, mvotg);
674 if (mvotg->pdata->id)
675 free_irq(mvotg->pdata->id->irq, mvotg);
676
677 if (mvotg->qwork) { 668 if (mvotg->qwork) {
678 flush_workqueue(mvotg->qwork); 669 flush_workqueue(mvotg->qwork);
679 destroy_workqueue(mvotg->qwork); 670 destroy_workqueue(mvotg->qwork);
@@ -681,21 +672,9 @@ int mv_otg_remove(struct platform_device *pdev)
681 672
682 mv_otg_disable(mvotg); 673 mv_otg_disable(mvotg);
683 674
684 if (mvotg->cap_regs)
685 iounmap(mvotg->cap_regs);
686
687 if (mvotg->phy_regs)
688 iounmap(mvotg->phy_regs);
689
690 for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++)
691 clk_put(mvotg->clk[clk_i]);
692
693 usb_remove_phy(&mvotg->phy); 675 usb_remove_phy(&mvotg->phy);
694 platform_set_drvdata(pdev, NULL); 676 platform_set_drvdata(pdev, NULL);
695 677
696 kfree(mvotg->phy.otg);
697 kfree(mvotg);
698
699 return 0; 678 return 0;
700} 679}
701 680
@@ -714,17 +693,15 @@ static int mv_otg_probe(struct platform_device *pdev)
714 } 693 }
715 694
716 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 695 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum;
717 mvotg = kzalloc(size, GFP_KERNEL); 696 mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
718 if (!mvotg) { 697 if (!mvotg) {
719 dev_err(&pdev->dev, "failed to allocate memory!\n"); 698 dev_err(&pdev->dev, "failed to allocate memory!\n");
720 return -ENOMEM; 699 return -ENOMEM;
721 } 700 }
722 701
723 otg = kzalloc(sizeof *otg, GFP_KERNEL); 702 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
724 if (!otg) { 703 if (!otg)
725 kfree(mvotg);
726 return -ENOMEM; 704 return -ENOMEM;
727 }
728 705
729 platform_set_drvdata(pdev, mvotg); 706 platform_set_drvdata(pdev, mvotg);
730 707
@@ -733,18 +710,18 @@ static int mv_otg_probe(struct platform_device *pdev)
733 710
734 mvotg->clknum = pdata->clknum; 711 mvotg->clknum = pdata->clknum;
735 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 712 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) {
736 mvotg->clk[clk_i] = clk_get(&pdev->dev, pdata->clkname[clk_i]); 713 mvotg->clk[clk_i] = devm_clk_get(&pdev->dev,
714 pdata->clkname[clk_i]);
737 if (IS_ERR(mvotg->clk[clk_i])) { 715 if (IS_ERR(mvotg->clk[clk_i])) {
738 retval = PTR_ERR(mvotg->clk[clk_i]); 716 retval = PTR_ERR(mvotg->clk[clk_i]);
739 goto err_put_clk; 717 return retval;
740 } 718 }
741 } 719 }
742 720
743 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 721 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
744 if (!mvotg->qwork) { 722 if (!mvotg->qwork) {
745 dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n"); 723 dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n");
746 retval = -ENOMEM; 724 return -ENOMEM;
747 goto err_put_clk;
748 } 725 }
749 726
750 INIT_DELAYED_WORK(&mvotg->work, mv_otg_work); 727 INIT_DELAYED_WORK(&mvotg->work, mv_otg_work);
@@ -772,7 +749,7 @@ static int mv_otg_probe(struct platform_device *pdev)
772 goto err_destroy_workqueue; 749 goto err_destroy_workqueue;
773 } 750 }
774 751
775 mvotg->phy_regs = ioremap(r->start, resource_size(r)); 752 mvotg->phy_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
776 if (mvotg->phy_regs == NULL) { 753 if (mvotg->phy_regs == NULL) {
777 dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 754 dev_err(&pdev->dev, "failed to map phy I/O memory\n");
778 retval = -EFAULT; 755 retval = -EFAULT;
@@ -784,21 +761,21 @@ static int mv_otg_probe(struct platform_device *pdev)
784 if (r == NULL) { 761 if (r == NULL) {
785 dev_err(&pdev->dev, "no I/O memory resource defined\n"); 762 dev_err(&pdev->dev, "no I/O memory resource defined\n");
786 retval = -ENODEV; 763 retval = -ENODEV;
787 goto err_unmap_phyreg; 764 goto err_destroy_workqueue;
788 } 765 }
789 766
790 mvotg->cap_regs = ioremap(r->start, resource_size(r)); 767 mvotg->cap_regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
791 if (mvotg->cap_regs == NULL) { 768 if (mvotg->cap_regs == NULL) {
792 dev_err(&pdev->dev, "failed to map I/O memory\n"); 769 dev_err(&pdev->dev, "failed to map I/O memory\n");
793 retval = -EFAULT; 770 retval = -EFAULT;
794 goto err_unmap_phyreg; 771 goto err_destroy_workqueue;
795 } 772 }
796 773
797 /* we will acces controller register, so enable the udc controller */ 774 /* we will acces controller register, so enable the udc controller */
798 retval = mv_otg_enable_internal(mvotg); 775 retval = mv_otg_enable_internal(mvotg);
799 if (retval) { 776 if (retval) {
800 dev_err(&pdev->dev, "mv otg enable error %d\n", retval); 777 dev_err(&pdev->dev, "mv otg enable error %d\n", retval);
801 goto err_unmap_capreg; 778 goto err_destroy_workqueue;
802 } 779 }
803 780
804 mvotg->op_regs = 781 mvotg->op_regs =
@@ -806,9 +783,9 @@ static int mv_otg_probe(struct platform_device *pdev)
806 + (readl(mvotg->cap_regs) & CAPLENGTH_MASK)); 783 + (readl(mvotg->cap_regs) & CAPLENGTH_MASK));
807 784
808 if (pdata->id) { 785 if (pdata->id) {
809 retval = request_threaded_irq(pdata->id->irq, NULL, 786 retval = devm_request_threaded_irq(&pdev->dev, pdata->id->irq,
810 mv_otg_inputs_irq, 787 NULL, mv_otg_inputs_irq,
811 IRQF_ONESHOT, "id", mvotg); 788 IRQF_ONESHOT, "id", mvotg);
812 if (retval) { 789 if (retval) {
813 dev_info(&pdev->dev, 790 dev_info(&pdev->dev,
814 "Failed to request irq for ID\n"); 791 "Failed to request irq for ID\n");
@@ -818,9 +795,9 @@ static int mv_otg_probe(struct platform_device *pdev)
818 795
819 if (pdata->vbus) { 796 if (pdata->vbus) {
820 mvotg->clock_gating = 1; 797 mvotg->clock_gating = 1;
821 retval = request_threaded_irq(pdata->vbus->irq, NULL, 798 retval = devm_request_threaded_irq(&pdev->dev, pdata->vbus->irq,
822 mv_otg_inputs_irq, 799 NULL, mv_otg_inputs_irq,
823 IRQF_ONESHOT, "vbus", mvotg); 800 IRQF_ONESHOT, "vbus", mvotg);
824 if (retval) { 801 if (retval) {
825 dev_info(&pdev->dev, 802 dev_info(&pdev->dev,
826 "Failed to request irq for VBUS, " 803 "Failed to request irq for VBUS, "
@@ -844,7 +821,7 @@ static int mv_otg_probe(struct platform_device *pdev)
844 } 821 }
845 822
846 mvotg->irq = r->start; 823 mvotg->irq = r->start;
847 if (request_irq(mvotg->irq, mv_otg_irq, IRQF_SHARED, 824 if (devm_request_irq(&pdev->dev, mvotg->irq, mv_otg_irq, IRQF_SHARED,
848 driver_name, mvotg)) { 825 driver_name, mvotg)) {
849 dev_err(&pdev->dev, "Request irq %d for OTG failed\n", 826 dev_err(&pdev->dev, "Request irq %d for OTG failed\n",
850 mvotg->irq); 827 mvotg->irq);
@@ -857,14 +834,14 @@ static int mv_otg_probe(struct platform_device *pdev)
857 if (retval < 0) { 834 if (retval < 0) {
858 dev_err(&pdev->dev, "can't register transceiver, %d\n", 835 dev_err(&pdev->dev, "can't register transceiver, %d\n",
859 retval); 836 retval);
860 goto err_free_irq; 837 goto err_disable_clk;
861 } 838 }
862 839
863 retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group); 840 retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group);
864 if (retval < 0) { 841 if (retval < 0) {
865 dev_dbg(&pdev->dev, 842 dev_dbg(&pdev->dev,
866 "Can't register sysfs attr group: %d\n", retval); 843 "Can't register sysfs attr group: %d\n", retval);
867 goto err_set_transceiver; 844 goto err_remove_phy;
868 } 845 }
869 846
870 spin_lock_init(&mvotg->wq_lock); 847 spin_lock_init(&mvotg->wq_lock);
@@ -879,30 +856,15 @@ static int mv_otg_probe(struct platform_device *pdev)
879 856
880 return 0; 857 return 0;
881 858
882err_set_transceiver: 859err_remove_phy:
883 usb_remove_phy(&mvotg->phy); 860 usb_remove_phy(&mvotg->phy);
884err_free_irq:
885 free_irq(mvotg->irq, mvotg);
886err_disable_clk: 861err_disable_clk:
887 if (pdata->vbus)
888 free_irq(pdata->vbus->irq, mvotg);
889 if (pdata->id)
890 free_irq(pdata->id->irq, mvotg);
891 mv_otg_disable_internal(mvotg); 862 mv_otg_disable_internal(mvotg);
892err_unmap_capreg:
893 iounmap(mvotg->cap_regs);
894err_unmap_phyreg:
895 iounmap(mvotg->phy_regs);
896err_destroy_workqueue: 863err_destroy_workqueue:
897 flush_workqueue(mvotg->qwork); 864 flush_workqueue(mvotg->qwork);
898 destroy_workqueue(mvotg->qwork); 865 destroy_workqueue(mvotg->qwork);
899err_put_clk:
900 for (clk_i--; clk_i >= 0; clk_i--)
901 clk_put(mvotg->clk[clk_i]);
902 866
903 platform_set_drvdata(pdev, NULL); 867 platform_set_drvdata(pdev, NULL);
904 kfree(otg);
905 kfree(mvotg);
906 868
907 return retval; 869 return retval;
908} 870}