Skip to content

Commit c8be24c

Browse files
lyakhcjb
authored andcommitted
mmc: tmio_mmc: support the generic MMC GPIO card hotplug helper
If the platform specifies the TMIO_MMC_HAS_COLD_CD flag, use the generic MMC GPIO card hotplug helper. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 2b1ac5c commit c8be24c

3 files changed

Lines changed: 50 additions & 48 deletions

File tree

‎drivers/mmc/host/tmio_mmc.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ struct tmio_mmc_host {
5353
void (*set_pwr)(struct platform_device *host, int state);
5454
void (*set_clk_div)(struct platform_device *host, int state);
5555

56-
int pm_error;
57-
/* recognise system-wide suspend in runtime PM methods */
58-
bool pm_global;
59-
6056
/* pio related stuff */
6157
struct scatterlist *sg_ptr;
6258
struct scatterlist *sg_orig;

‎drivers/mmc/host/tmio_mmc_pio.c‎

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
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);
9901002
void 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
}
10171031
EXPORT_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
}
10331045
EXPORT_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
}
10561058
EXPORT_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
}
10851078
EXPORT_SYMBOL(tmio_mmc_host_runtime_resume);

‎include/linux/mfd/tmio.h‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifndef MFD_TMIO_H
22
#define MFD_TMIO_H
33

4+
#include <linux/device.h>
45
#include <linux/fb.h>
56
#include <linux/io.h>
7+
#include <linux/jiffies.h>
68
#include <linux/platform_device.h>
79
#include <linux/pm_runtime.h>
810

@@ -64,15 +66,21 @@
6466
#define TMIO_MMC_SDIO_IRQ (1 << 2)
6567
/*
6668
* 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+
* down, using a GPIO IRQ, in which case they have to fill in cd_irq, cd_gpio,
70+
* and cd_flags fields of struct tmio_mmc_data.
6971
*/
7072
#define TMIO_MMC_HAS_COLD_CD (1 << 3)
7173
/*
7274
* Some controllers require waiting for the SD bus to become
7375
* idle before writing to some registers.
7476
*/
7577
#define TMIO_MMC_HAS_IDLE_WAIT (1 << 4)
78+
/*
79+
* A GPIO is used for card hotplug detection. We need an extra flag for this,
80+
* because 0 is a valid GPIO number too, and requiring users to specify
81+
* cd_gpio < 0 to disable GPIO hotplug would break backwards compatibility.
82+
*/
83+
#define TMIO_MMC_USE_GPIO_CD (1 << 5)
7684

7785
int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base);
7886
int tmio_core_mmc_resume(void __iomem *cnf, int shift, unsigned long base);
@@ -98,18 +106,23 @@ struct tmio_mmc_data {
98106
struct tmio_mmc_dma *dma;
99107
struct device *dev;
100108
bool power;
109+
unsigned int cd_gpio;
101110
void (*set_pwr)(struct platform_device *host, int state);
102111
void (*set_clk_div)(struct platform_device *host, int state);
103112
int (*get_cd)(struct platform_device *host);
104113
int (*write16_hook)(struct tmio_mmc_host *host, int addr);
105114
};
106115

116+
/*
117+
* This function is deprecated and will be removed soon. Please, convert your
118+
* platform to use drivers/mmc/core/cd-gpio.c
119+
*/
120+
#include <linux/mmc/host.h>
107121
static inline void tmio_mmc_cd_wakeup(struct tmio_mmc_data *pdata)
108122
{
109-
if (pdata && !pdata->power) {
110-
pdata->power = true;
111-
pm_runtime_get(pdata->dev);
112-
}
123+
if (pdata)
124+
mmc_detect_change(dev_get_drvdata(pdata->dev),
125+
msecs_to_jiffies(100));
113126
}
114127

115128
/*

0 commit comments

Comments
 (0)