Skip to content

Commit 7311bef

Browse files
lyakhcjb
authored andcommitted
mmc: tmio: runtime suspend the controller, where possible
The TMIO MMC controller cannot be powered off to save power, when no card is plugged in, because then it will not be able to detect a new card-insertion event. On some implementations, however, it is possible to switch to using another source to detect card insertion. This patch adds support for such implementations. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent d6a1f86 commit 7311bef

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

‎drivers/mmc/host/tmio_mmc.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,7 @@ int tmio_mmc_host_resume(struct device *dev);
131131
#define tmio_mmc_host_resume NULL
132132
#endif
133133

134+
int tmio_mmc_host_runtime_suspend(struct device *dev);
135+
int tmio_mmc_host_runtime_resume(struct device *dev);
136+
134137
#endif

‎drivers/mmc/host/tmio_mmc_pio.c‎

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
746746
static 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
}
950975
EXPORT_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+
9851037
MODULE_LICENSE("GPL v2");

‎include/linux/mfd/tmio.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/fb.h>
55
#include <linux/io.h>
66
#include <linux/platform_device.h>
7+
#include <linux/pm_runtime.h>
78

89
#define tmio_ioread8(addr) readb(addr)
910
#define tmio_ioread16(addr) readw(addr)
@@ -61,6 +62,12 @@
6162
* Some controllers can support SDIO IRQ signalling.
6263
*/
6364
#define TMIO_MMC_SDIO_IRQ (1 << 2)
65+
/*
66+
* Some platforms can detect card insertion events with controller powered
67+
* down, in which case they have to call tmio_mmc_cd_wakeup() to power up the
68+
* controller and report the event to the driver.
69+
*/
70+
#define TMIO_MMC_HAS_COLD_CD (1 << 3)
6471

6572
int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base);
6673
int tmio_core_mmc_resume(void __iomem *cnf, int shift, unsigned long base);
@@ -82,11 +89,21 @@ struct tmio_mmc_data {
8289
unsigned long flags;
8390
u32 ocr_mask; /* available voltages */
8491
struct tmio_mmc_dma *dma;
92+
struct device *dev;
93+
bool power;
8594
void (*set_pwr)(struct platform_device *host, int state);
8695
void (*set_clk_div)(struct platform_device *host, int state);
8796
int (*get_cd)(struct platform_device *host);
8897
};
8998

99+
static inline void tmio_mmc_cd_wakeup(struct tmio_mmc_data *pdata)
100+
{
101+
if (pdata && !pdata->power) {
102+
pdata->power = true;
103+
pm_runtime_get(pdata->dev);
104+
}
105+
}
106+
90107
/*
91108
* data for the NAND controller
92109
*/

0 commit comments

Comments
 (0)