Skip to content

Commit f0710a5

Browse files
ahunter6cjb
authored andcommitted
mmc: sdhci: add ability to stay runtime-resumed if the card is powered up
If card power is dependent on SD bus power then the host controller must not be runtime suspended while the card is powered up. Add the ability to stay runtime-resumed in that case and enable it with a new quirk SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent 113a87f commit f0710a5

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎drivers/mmc/host/sdhci.c‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
5858
#ifdef CONFIG_PM_RUNTIME
5959
static int sdhci_runtime_pm_get(struct sdhci_host *host);
6060
static int sdhci_runtime_pm_put(struct sdhci_host *host);
61+
static void sdhci_runtime_pm_bus_on(struct sdhci_host *host);
62+
static void sdhci_runtime_pm_bus_off(struct sdhci_host *host);
6163
#else
6264
static inline int sdhci_runtime_pm_get(struct sdhci_host *host)
6365
{
@@ -67,6 +69,12 @@ static inline int sdhci_runtime_pm_put(struct sdhci_host *host)
6769
{
6870
return 0;
6971
}
72+
static void sdhci_runtime_pm_bus_on(struct sdhci_host *host)
73+
{
74+
}
75+
static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
76+
{
77+
}
7078
#endif
7179

7280
static void sdhci_dumpregs(struct sdhci_host *host)
@@ -192,8 +200,12 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
192200

193201
sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
194202

195-
if (mask & SDHCI_RESET_ALL)
203+
if (mask & SDHCI_RESET_ALL) {
196204
host->clock = 0;
205+
/* Reset-all turns off SD Bus Power */
206+
if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON)
207+
sdhci_runtime_pm_bus_off(host);
208+
}
197209

198210
/* Wait max 100 ms */
199211
timeout = 100;
@@ -1268,6 +1280,8 @@ static int sdhci_set_power(struct sdhci_host *host, unsigned short power)
12681280

12691281
if (pwr == 0) {
12701282
sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
1283+
if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON)
1284+
sdhci_runtime_pm_bus_off(host);
12711285
return 0;
12721286
}
12731287

@@ -1289,6 +1303,9 @@ static int sdhci_set_power(struct sdhci_host *host, unsigned short power)
12891303

12901304
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
12911305

1306+
if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON)
1307+
sdhci_runtime_pm_bus_on(host);
1308+
12921309
/*
12931310
* Some controllers need an extra 10ms delay of 10ms before they
12941311
* can apply clock after applying power
@@ -2625,6 +2642,22 @@ static int sdhci_runtime_pm_put(struct sdhci_host *host)
26252642
return pm_runtime_put_autosuspend(host->mmc->parent);
26262643
}
26272644

2645+
static void sdhci_runtime_pm_bus_on(struct sdhci_host *host)
2646+
{
2647+
if (host->runtime_suspended || host->bus_on)
2648+
return;
2649+
host->bus_on = true;
2650+
pm_runtime_get_noresume(host->mmc->parent);
2651+
}
2652+
2653+
static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
2654+
{
2655+
if (host->runtime_suspended || !host->bus_on)
2656+
return;
2657+
host->bus_on = false;
2658+
pm_runtime_put_noidle(host->mmc->parent);
2659+
}
2660+
26282661
int sdhci_runtime_suspend_host(struct sdhci_host *host)
26292662
{
26302663
unsigned long flags;

‎include/linux/mmc/sdhci.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct sdhci_host {
9595
/* The system physically doesn't support 1.8v, even if the host does */
9696
#define SDHCI_QUIRK2_NO_1_8_V (1<<2)
9797
#define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3)
98+
#define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
9899

99100
int irq; /* Device IRQ */
100101
void __iomem *ioaddr; /* Mapped address */
@@ -139,6 +140,7 @@ struct sdhci_host {
139140
u8 pwr; /* Current voltage */
140141

141142
bool runtime_suspended; /* Host is runtime suspended */
143+
bool bus_on; /* Bus power prevents runtime suspend */
142144

143145
struct mmc_request *mrq; /* Current request */
144146
struct mmc_command *cmd; /* Current command */

0 commit comments

Comments
 (0)