@@ -746,6 +746,7 @@ static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
746746static void tmio_mmc_set_ios (struct mmc_host * mmc , struct mmc_ios * ios )
747747{
748748 struct tmio_mmc_host * host = mmc_priv (mmc );
749+ struct tmio_mmc_data * pdata = host -> pdata ;
749750 unsigned long flags ;
750751
751752 spin_lock_irqsave (& host -> lock , flags );
@@ -775,13 +776,24 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
775776
776777 /* Power sequence - OFF -> UP -> ON */
777778 if (ios -> power_mode == MMC_POWER_UP ) {
779+ if ((pdata -> flags & TMIO_MMC_HAS_COLD_CD ) && !pdata -> power ) {
780+ pm_runtime_get_sync (& host -> pdev -> dev );
781+ pdata -> power = true;
782+ }
778783 /* power up SD bus */
779784 if (host -> set_pwr )
780785 host -> set_pwr (host -> pdev , 1 );
781786 } else if (ios -> power_mode == MMC_POWER_OFF || !ios -> clock ) {
782787 /* power down SD bus */
783- if (ios -> power_mode == MMC_POWER_OFF && host -> set_pwr )
784- host -> set_pwr (host -> pdev , 0 );
788+ if (ios -> power_mode == MMC_POWER_OFF ) {
789+ if (host -> set_pwr )
790+ host -> set_pwr (host -> pdev , 0 );
791+ if ((pdata -> flags & TMIO_MMC_HAS_COLD_CD ) &&
792+ pdata -> power ) {
793+ pdata -> power = false;
794+ pm_runtime_put (& host -> pdev -> dev );
795+ }
796+ }
785797 tmio_mmc_clk_stop (host );
786798 } else {
787799 /* start bus clock */
@@ -853,6 +865,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
853865 if (!mmc )
854866 return - ENOMEM ;
855867
868+ pdata -> dev = & pdev -> dev ;
856869 _host = mmc_priv (mmc );
857870 _host -> pdata = pdata ;
858871 _host -> mmc = mmc ;
@@ -886,6 +899,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
886899 else
887900 mmc -> ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34 ;
888901
902+ pdata -> power = false;
889903 pm_runtime_enable (& pdev -> dev );
890904 ret = pm_runtime_resume (& pdev -> dev );
891905 if (ret < 0 )
@@ -907,7 +921,8 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
907921 tmio_mmc_request_dma (_host , pdata );
908922
909923 /* We have to keep the device powered for its card detection to work */
910- pm_runtime_get_noresume (& pdev -> dev );
924+ if (!(pdata -> flags & TMIO_MMC_HAS_COLD_CD ))
925+ pm_runtime_get_noresume (& pdev -> dev );
911926
912927 mmc_add_host (mmc );
913928
@@ -937,15 +952,25 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
937952{
938953 struct platform_device * pdev = host -> pdev ;
939954
955+ /*
956+ * We don't have to manipulate pdata->power here: if there is a card in
957+ * the slot, the runtime PM is active and our .runtime_resume() will not
958+ * be run. If there is no card in the slot and the platform can suspend
959+ * the controller, the runtime PM is suspended and pdata->power == false,
960+ * so, our .runtime_resume() will not try to detect a card in the slot.
961+ */
962+ if (host -> pdata -> flags & TMIO_MMC_HAS_COLD_CD )
963+ pm_runtime_get_sync (& pdev -> dev );
964+
940965 mmc_remove_host (host -> mmc );
941966 cancel_delayed_work_sync (& host -> delayed_reset_work );
942967 tmio_mmc_release_dma (host );
943- iounmap (host -> ctl );
944- mmc_free_host (host -> mmc );
945968
946- /* Compensate for pm_runtime_get_sync() in probe() above */
947969 pm_runtime_put_sync (& pdev -> dev );
948970 pm_runtime_disable (& pdev -> dev );
971+
972+ iounmap (host -> ctl );
973+ mmc_free_host (host -> mmc );
949974}
950975EXPORT_SYMBOL (tmio_mmc_host_remove );
951976
@@ -970,6 +995,9 @@ int tmio_mmc_host_resume(struct device *dev)
970995 struct mmc_host * mmc = dev_get_drvdata (dev );
971996 struct tmio_mmc_host * host = mmc_priv (mmc );
972997
998+ /* The MMC core will perform the complete set up */
999+ host -> pdata -> power = false;
1000+
9731001 if (!host -> pm_error )
9741002 pm_runtime_get_sync (dev );
9751003
@@ -982,4 +1010,28 @@ EXPORT_SYMBOL(tmio_mmc_host_resume);
9821010
9831011#endif /* CONFIG_PM */
9841012
1013+ int tmio_mmc_host_runtime_suspend (struct device * dev )
1014+ {
1015+ return 0 ;
1016+ }
1017+ EXPORT_SYMBOL (tmio_mmc_host_runtime_suspend );
1018+
1019+ int tmio_mmc_host_runtime_resume (struct device * dev )
1020+ {
1021+ struct mmc_host * mmc = dev_get_drvdata (dev );
1022+ struct tmio_mmc_host * host = mmc_priv (mmc );
1023+ struct tmio_mmc_data * pdata = host -> pdata ;
1024+
1025+ tmio_mmc_reset (host );
1026+
1027+ if (pdata -> power ) {
1028+ /* Only entered after a card-insert interrupt */
1029+ tmio_mmc_set_ios (mmc , & mmc -> ios );
1030+ mmc_detect_change (mmc , msecs_to_jiffies (100 ));
1031+ }
1032+
1033+ return 0 ;
1034+ }
1035+ EXPORT_SYMBOL (tmio_mmc_host_runtime_resume );
1036+
9851037MODULE_LICENSE ("GPL v2" );
0 commit comments