@@ -50,8 +50,6 @@ struct mvsd_host {
50
50
struct timer_list timer ;
51
51
struct mmc_host * mmc ;
52
52
struct device * dev ;
53
- struct resource * res ;
54
- int irq ;
55
53
struct clk * clk ;
56
54
int gpio_card_detect ;
57
55
int gpio_write_protect ;
@@ -718,10 +716,6 @@ static int __init mvsd_probe(struct platform_device *pdev)
718
716
if (!r || irq < 0 || !mvsd_data )
719
717
return - ENXIO ;
720
718
721
- r = request_mem_region (r -> start , SZ_1K , DRIVER_NAME );
722
- if (!r )
723
- return - EBUSY ;
724
-
725
719
mmc = mmc_alloc_host (sizeof (struct mvsd_host ), & pdev -> dev );
726
720
if (!mmc ) {
727
721
ret = - ENOMEM ;
@@ -731,8 +725,8 @@ static int __init mvsd_probe(struct platform_device *pdev)
731
725
host = mmc_priv (mmc );
732
726
host -> mmc = mmc ;
733
727
host -> dev = & pdev -> dev ;
734
- host -> res = r ;
735
728
host -> base_clock = mvsd_data -> clock / 2 ;
729
+ host -> clk = ERR_PTR (- EINVAL );
736
730
737
731
mmc -> ops = & mvsd_ops ;
738
732
@@ -752,7 +746,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
752
746
753
747
spin_lock_init (& host -> lock );
754
748
755
- host -> base = ioremap ( r -> start , SZ_4K );
749
+ host -> base = devm_request_and_ioremap ( & pdev -> dev , r );
756
750
if (!host -> base ) {
757
751
ret = - ENOMEM ;
758
752
goto out ;
@@ -765,44 +759,45 @@ static int __init mvsd_probe(struct platform_device *pdev)
765
759
766
760
mvsd_power_down (host );
767
761
768
- ret = request_irq ( irq , mvsd_irq , 0 , DRIVER_NAME , host );
762
+ ret = devm_request_irq ( & pdev -> dev , irq , mvsd_irq , 0 , DRIVER_NAME , host );
769
763
if (ret ) {
770
764
pr_err ("%s: cannot assign irq %d\n" , DRIVER_NAME , irq );
771
765
goto out ;
772
- } else
773
- host -> irq = irq ;
766
+ }
774
767
775
768
/* Not all platforms can gate the clock, so it is not
776
769
an error if the clock does not exists. */
777
- host -> clk = clk_get (& pdev -> dev , NULL );
778
- if (!IS_ERR (host -> clk )) {
770
+ host -> clk = devm_clk_get (& pdev -> dev , NULL );
771
+ if (!IS_ERR (host -> clk ))
779
772
clk_prepare_enable (host -> clk );
780
- }
781
773
782
774
if (mvsd_data -> gpio_card_detect ) {
783
- ret = gpio_request (mvsd_data -> gpio_card_detect ,
784
- DRIVER_NAME " cd" );
775
+ ret = devm_gpio_request_one (& pdev -> dev ,
776
+ mvsd_data -> gpio_card_detect ,
777
+ GPIOF_IN , DRIVER_NAME " cd" );
785
778
if (ret == 0 ) {
786
- gpio_direction_input (mvsd_data -> gpio_card_detect );
787
779
irq = gpio_to_irq (mvsd_data -> gpio_card_detect );
788
- ret = request_irq (irq , mvsd_card_detect_irq ,
789
- IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING ,
790
- DRIVER_NAME " cd" , host );
780
+ ret = devm_request_irq (& pdev -> dev , irq ,
781
+ mvsd_card_detect_irq ,
782
+ IRQ_TYPE_EDGE_RISING |
783
+ IRQ_TYPE_EDGE_FALLING ,
784
+ DRIVER_NAME " cd" , host );
791
785
if (ret == 0 )
792
786
host -> gpio_card_detect =
793
787
mvsd_data -> gpio_card_detect ;
794
788
else
795
- gpio_free (mvsd_data -> gpio_card_detect );
789
+ devm_gpio_free (& pdev -> dev ,
790
+ mvsd_data -> gpio_card_detect );
796
791
}
797
792
}
798
793
if (!host -> gpio_card_detect )
799
794
mmc -> caps |= MMC_CAP_NEEDS_POLL ;
800
795
801
796
if (mvsd_data -> gpio_write_protect ) {
802
- ret = gpio_request (mvsd_data -> gpio_write_protect ,
803
- DRIVER_NAME " wp" );
797
+ ret = devm_gpio_request_one (& pdev -> dev ,
798
+ mvsd_data -> gpio_write_protect ,
799
+ GPIOF_IN , DRIVER_NAME " wp" );
804
800
if (ret == 0 ) {
805
- gpio_direction_input (mvsd_data -> gpio_write_protect );
806
801
host -> gpio_write_protect =
807
802
mvsd_data -> gpio_write_protect ;
808
803
}
@@ -824,26 +819,11 @@ static int __init mvsd_probe(struct platform_device *pdev)
824
819
return 0 ;
825
820
826
821
out :
827
- if (host ) {
828
- if (host -> irq )
829
- free_irq (host -> irq , host );
830
- if (host -> gpio_card_detect ) {
831
- free_irq (gpio_to_irq (host -> gpio_card_detect ), host );
832
- gpio_free (host -> gpio_card_detect );
833
- }
834
- if (host -> gpio_write_protect )
835
- gpio_free (host -> gpio_write_protect );
836
- if (host -> base )
837
- iounmap (host -> base );
838
- }
839
- if (r )
840
- release_resource (r );
841
- if (mmc )
842
- if (!IS_ERR_OR_NULL (host -> clk )) {
822
+ if (mmc ) {
823
+ if (!IS_ERR (host -> clk ))
843
824
clk_disable_unprepare (host -> clk );
844
- clk_put (host -> clk );
845
- }
846
825
mmc_free_host (mmc );
826
+ }
847
827
848
828
return ret ;
849
829
}
@@ -852,28 +832,16 @@ static int __exit mvsd_remove(struct platform_device *pdev)
852
832
{
853
833
struct mmc_host * mmc = platform_get_drvdata (pdev );
854
834
855
- if (mmc ) {
856
- struct mvsd_host * host = mmc_priv (mmc );
835
+ struct mvsd_host * host = mmc_priv (mmc );
857
836
858
- if (host -> gpio_card_detect ) {
859
- free_irq (gpio_to_irq (host -> gpio_card_detect ), host );
860
- gpio_free (host -> gpio_card_detect );
861
- }
862
- mmc_remove_host (mmc );
863
- free_irq (host -> irq , host );
864
- if (host -> gpio_write_protect )
865
- gpio_free (host -> gpio_write_protect );
866
- del_timer_sync (& host -> timer );
867
- mvsd_power_down (host );
868
- iounmap (host -> base );
869
- release_resource (host -> res );
837
+ mmc_remove_host (mmc );
838
+ del_timer_sync (& host -> timer );
839
+ mvsd_power_down (host );
840
+
841
+ if (!IS_ERR (host -> clk ))
842
+ clk_disable_unprepare (host -> clk );
843
+ mmc_free_host (mmc );
870
844
871
- if (!IS_ERR (host -> clk )) {
872
- clk_disable_unprepare (host -> clk );
873
- clk_put (host -> clk );
874
- }
875
- mmc_free_host (mmc );
876
- }
877
845
platform_set_drvdata (pdev , NULL );
878
846
return 0 ;
879
847
}
0 commit comments