3434#include <linux/io.h>
3535#include <linux/irq.h>
3636#include <linux/mfd/tmio.h>
37+ #include <linux/mmc/cd-gpio.h>
3738#include <linux/mmc/host.h>
3839#include <linux/mmc/tmio.h>
3940#include <linux/module.h>
@@ -791,8 +792,10 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
791792 spin_unlock_irqrestore (& host -> lock , flags );
792793
793794 /*
794- * pdata->power == false only if COLD_CD is available, otherwise only
795- * in short time intervals during probing or resuming
795+ * pdata->power toggles between false and true in both cases - either
796+ * or not the controller can be runtime-suspended during inactivity.
797+ * But if the controller has to be kept on, the runtime-pm usage_count
798+ * is kept positive, so no suspending actually takes place.
796799 */
797800 if (ios -> power_mode == MMC_POWER_ON && ios -> clock ) {
798801 if (!pdata -> power ) {
@@ -916,7 +919,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
916919 else
917920 mmc -> ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34 ;
918921
919- _host -> native_hotplug = !(pdata -> flags & TMIO_MMC_HAS_COLD_CD ||
922+ _host -> native_hotplug = !(pdata -> flags & TMIO_MMC_USE_GPIO_CD ||
920923 mmc -> caps & MMC_CAP_NEEDS_POLL ||
921924 mmc -> caps & MMC_CAP_NONREMOVABLE );
922925
@@ -933,8 +936,9 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
933936 * 3) a worker thread polls the sdhi - indicated by MMC_CAP_NEEDS_POLL
934937 * 4) the medium is non-removable - indicated by MMC_CAP_NONREMOVABLE
935938 *
936- * While we increment the rtpm counter for all scenarios when the mmc
937- * core activates us by calling an appropriate set_ios(), we must
939+ * While we increment the runtime PM counter for all scenarios when
940+ * the mmc core activates us by calling an appropriate set_ios(), we
941+ * must additionally ensure that in case 2) the tmio mmc hardware stays
938942 * additionally ensure that in case 2) the tmio mmc hardware stays
939943 * powered on during runtime for the card detection to work.
940944 */
@@ -973,6 +977,14 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
973977
974978 tmio_mmc_enable_mmc_irqs (_host , irq_mask );
975979
980+ if (pdata -> flags & TMIO_MMC_USE_GPIO_CD ) {
981+ ret = mmc_cd_gpio_request (mmc , pdata -> cd_gpio );
982+ if (ret < 0 ) {
983+ tmio_mmc_host_remove (_host );
984+ return ret ;
985+ }
986+ }
987+
976988 * host = _host ;
977989
978990 return 0 ;
@@ -990,20 +1002,22 @@ EXPORT_SYMBOL(tmio_mmc_host_probe);
9901002void tmio_mmc_host_remove (struct tmio_mmc_host * host )
9911003{
9921004 struct platform_device * pdev = host -> pdev ;
1005+ struct tmio_mmc_data * pdata = host -> pdata ;
1006+ struct mmc_host * mmc = host -> mmc ;
1007+
1008+ if (pdata -> flags & TMIO_MMC_USE_GPIO_CD )
1009+ /*
1010+ * This means we can miss a card-eject, but this is anyway
1011+ * possible, because of delayed processing of hotplug events.
1012+ */
1013+ mmc_cd_gpio_free (mmc );
9931014
994- /*
995- * We don't have to manipulate pdata->power here: if there is a card in
996- * the slot, the runtime PM is active and our .runtime_resume() will not
997- * be run. If there is no card in the slot and the platform can suspend
998- * the controller, the runtime PM is suspended and pdata->power == false,
999- * so, our .runtime_resume() will not try to detect a card in the slot.
1000- */
10011015 if (!host -> native_hotplug )
10021016 pm_runtime_get_sync (& pdev -> dev );
10031017
10041018 dev_pm_qos_hide_latency_limit (& pdev -> dev );
10051019
1006- mmc_remove_host (host -> mmc );
1020+ mmc_remove_host (mmc );
10071021 cancel_work_sync (& host -> done );
10081022 cancel_delayed_work_sync (& host -> delayed_reset_work );
10091023 tmio_mmc_release_dma (host );
@@ -1012,7 +1026,7 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
10121026 pm_runtime_disable (& pdev -> dev );
10131027
10141028 iounmap (host -> ctl );
1015- mmc_free_host (host -> mmc );
1029+ mmc_free_host (mmc );
10161030}
10171031EXPORT_SYMBOL (tmio_mmc_host_remove );
10181032
@@ -1026,8 +1040,6 @@ int tmio_mmc_host_suspend(struct device *dev)
10261040 if (!ret )
10271041 tmio_mmc_disable_mmc_irqs (host , TMIO_MASK_ALL );
10281042
1029- host -> pm_error = pm_runtime_put_sync (dev );
1030-
10311043 return ret ;
10321044}
10331045EXPORT_SYMBOL (tmio_mmc_host_suspend );
@@ -1037,20 +1049,10 @@ int tmio_mmc_host_resume(struct device *dev)
10371049 struct mmc_host * mmc = dev_get_drvdata (dev );
10381050 struct tmio_mmc_host * host = mmc_priv (mmc );
10391051
1040- /* The MMC core will perform the complete set up */
1041- host -> pdata -> power = false;
1042-
1043- host -> pm_global = true;
1044- if (!host -> pm_error )
1045- pm_runtime_get_sync (dev );
1046-
1047- if (host -> pm_global ) {
1048- /* Runtime PM resume callback didn't run */
1049- tmio_mmc_reset (host );
1050- tmio_mmc_enable_dma (host , true);
1051- host -> pm_global = false;
1052- }
1052+ tmio_mmc_reset (host );
1053+ tmio_mmc_enable_dma (host , true);
10531054
1055+ /* The MMC core will perform the complete set up */
10541056 return mmc_resume_host (mmc );
10551057}
10561058EXPORT_SYMBOL (tmio_mmc_host_resume );
@@ -1067,19 +1069,10 @@ int tmio_mmc_host_runtime_resume(struct device *dev)
10671069{
10681070 struct mmc_host * mmc = dev_get_drvdata (dev );
10691071 struct tmio_mmc_host * host = mmc_priv (mmc );
1070- struct tmio_mmc_data * pdata = host -> pdata ;
10711072
10721073 tmio_mmc_reset (host );
10731074 tmio_mmc_enable_dma (host , true);
10741075
1075- if (pdata -> power ) {
1076- /* Only entered after a card-insert interrupt */
1077- if (!mmc -> card )
1078- tmio_mmc_set_ios (mmc , & mmc -> ios );
1079- mmc_detect_change (mmc , msecs_to_jiffies (100 ));
1080- }
1081- host -> pm_global = false;
1082-
10831076 return 0 ;
10841077}
10851078EXPORT_SYMBOL (tmio_mmc_host_runtime_resume );
0 commit comments