mmc: sdhci: support runtime PM for BYT SD cards
Adrian Hunter
maintainercover mmc: sdhci: support runtime PM for BYT SD cards
Hi
Here are 3 patches to support runtime PM for BYT SD cards
Please note that these patches are dependent upon 2 gpio patches that are in linux-next and linux-gpio but not the mmc tree. Those patches are:
author Mika Westerberg <[email protected]> 2013-04-03 10:56:54 (GMT) committer Linus Walleij <[email protected]> 2013-04-11 22:31:18 (GMT) commit 12028d2d216220618f76284af5f8ed510b11da55 (patch) gpiolib-acpi: introduce acpi_get_gpio_by_index() helper author Rafael J. Wysocki <[email protected]> 2013-04-09 13:57:25 (GMT) committer Linus Walleij <[email protected]> 2013-04-10 21:41:17 (GMT) commit 7fc7acb9a0b0ff3ffdf21818fe0735ebaf4fecb8 (patch) gpio / ACPI: Handle ACPI events in accordance with the spec
I think those patches are queued for 3.10.
Adrian Hunter (3):
mmc: sdhci: add ability to stay runtime-resumed if the card is powered up
mmc: sdhci-acpi: support runtime PM for ACPI HID 80860F14 SD cards
mmc: sdhci-pci: support runtime PM for BYT SD cards
drivers/mmc/host/sdhci-acpi.c | 64 ++++++++++++++++++++++++++++++++++++++++++- drivers/mmc/host/sdhci-pci.c | 2 ++ drivers/mmc/host/sdhci.c | 35 ++++++++++++++++++++++- include/linux/mmc/sdhci.h | 2 ++ 4 files changed, 101 insertions(+), 2 deletions(-)
Regards
Adrian Hunter
Adrian Hunter
maintainerPATCH 1/3 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.
--- drivers/mmc/host/sdhci.c | 35 ++++++++++++++++++++++++++++++++++- include/linux/mmc/sdhci.h | 2 ++ 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +34 -1
@@ -58,6 +58,8 @@ static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);#ifdef CONFIG_PM_RUNTIME static int sdhci_runtime_pm_get (struct sdhci_host *host);static int sdhci_runtime_pm_put (struct sdhci_host *host); +static void sdhci_runtime_pm_bus_on (struct sdhci_host *host); +static void sdhci_runtime_pm_bus_off (struct sdhci_host *host);#else static inline int sdhci_runtime_pm_get (struct sdhci_host *host) {
@@ -67,6 +69,12 @@ static inline int sdhci_runtime_pm_put(struct sdhci_host *host) {return 0 ; } +static void sdhci_runtime_pm_bus_on (struct sdhci_host *host) +{ +} +static void sdhci_runtime_pm_bus_off (struct sdhci_host *host) +{ +}#endif static void sdhci_dumpregs (struct sdhci_host *host)
@@ -192,8 +200,12 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)sdhci_writeb (host, mask,SDHCI_SOFTWARE_RESET ); -if (mask &SDHCI_RESET_ALL ) +if (mask &SDHCI_RESET_ALL ) { host->clock =0 ; +/* Reset-all turns off SD Bus Power */ +if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON ) +sdhci_runtime_pm_bus_off (host); + }/* Wait max 100 ms */ timeout =100 ;
@@ -1268,6 +1280,8 @@ static int sdhci_set_power(struct sdhci_host *host, unsigned short power)if (pwr ==0 ) {sdhci_writeb (host,0 ,SDHCI_POWER_CONTROL ); +if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON ) +sdhci_runtime_pm_bus_off (host);return 0 ; }
@@ -1289,6 +1303,9 @@ static int sdhci_set_power(struct sdhci_host *host, unsigned short power)sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL ); +if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON ) +sdhci_runtime_pm_bus_on (host); +/* * Some controllers need an extra 10ms delay of 10ms before they * can apply clock after applying power
@@ -2625,6 +2642,22 @@ static int sdhci_runtime_pm_put(struct sdhci_host *host)return pm_runtime_put_autosuspend (host->mmc->parent); } +static void sdhci_runtime_pm_bus_on (struct sdhci_host *host) +{ +if (host->runtime_suspended || host->bus_on) +return ; + host->bus_on = true; +pm_runtime_get_noresume (host->mmc->parent); +} + +static void sdhci_runtime_pm_bus_off (struct sdhci_host *host) +{ +if (host->runtime_suspended || !host->bus_on) +return ; + host->bus_on = false; +pm_runtime_put_noidle (host->mmc->parent); +} +int sdhci_runtime_suspend_host (struct sdhci_host *host) {unsigned long flags;
include/linux/mmc/sdhci.h +2 -0
@@ -95,6 +95,7 @@ struct sdhci_host {/* The system physically doesn't support 1.8v, even if the host does */ #define SDHCI_QUIRK2_NO_1_8_V (1<<2)#define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3) +#define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)int irq;/* Device IRQ */ void __iomem *ioaddr;/* Mapped address */
@@ -139,6 +140,7 @@ struct sdhci_host {u8 pwr;/* Current voltage */ bool runtime_suspended;/* Host is runtime suspended */ +bool bus_on;/* Bus power prevents runtime suspend */ struct mmc_request *mrq;/* Current request */ struct mmc_command *cmd;/* Current command */
Signature · 1 line
1.7.11.7
Adrian Hunter
maintainerPATCH 2/3 mmc: sdhci-acpi: support runtime PM for ACPI HID 80860F14 SD cards
In reply to Adrian HunterEnable runtime PM for ACPI HID 80860F14 SD cards, adding support for card detect GPIO.
--- drivers/mmc/host/sdhci-acpi.c | 64 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-acpi.c +63 -1
@@ -31,8 +31,10 @@#include <linux/bitops.h> #include <linux/types.h> #include <linux/err.h> +#include <linux/gpio.h> #include <linux/interrupt.h> #include <linux/acpi.h> +#include <linux/acpi_gpio.h> #include <linux/pm.h> #include <linux/pm_runtime.h>
@@ -101,6 +103,8 @@ static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { };static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { + .flags =SDHCI_ACPI_SD_CD |SDHCI_ACPI_RUNTIME_PM , + .quirks2 =SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON , };struct sdhci_acpi_uid_slot {
@@ -161,6 +165,57 @@ static const struct sdhci_acpi_slot *sdhci_acpi_get_slot(acpi_handle handle,return slot; } +#ifdef CONFIG_PM_RUNTIME + +static irqreturn_t sdhci_acpi_sd_cd (int irq,void *dev_id) +{ +mmc_detect_change (dev_id,msecs_to_jiffies (200 )); +return IRQ_HANDLED ; +} + +static int sdhci_acpi_add_own_cd (struct device *dev,int gpio, +struct mmc_host *mmc) +{ +unsigned long flags; +int err, irq; + +if (gpio <0 ) { + err = gpio; + goto out; + } + + err =devm_gpio_request_one (dev, gpio,GPIOF_DIR_IN ,"sd_cd" ); +if (err) + goto out; + + irq =gpio_to_irq (gpio); +if (irq <0 ) + goto out_free; + + flags =IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING ; + err =devm_request_irq (dev, irq, sdhci_acpi_sd_cd, flags,"sd_cd" , mmc); +if (err) + goto out_free; + +return 0 ; + +out_free: +devm_gpio_free (dev, gpio); +out: +dev_warn (dev,"failed to setup card detect wake up\n" ); +return err; +} + +#else + +static int sdhci_acpi_add_own_cd (struct device *dev,int gpio, +struct mmc_host *mmc) +{ +return 0 ; +} + +#endif +static int sdhci_acpi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -171,7 +226,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)struct resource *iomem;resource_size_t len;const char *hid; -int err; +int err, gpio;if (acpi_bus_get_device (handle, &device))return -ENODEV ;
@@ -196,6 +251,8 @@ static int sdhci_acpi_probe(struct platform_device *pdev)if (IS_ERR (host))return PTR_ERR (host); + gpio =acpi_get_gpio_by_index (dev,0 ,NULL ); + c =sdhci_priv (host); c->host = host; c->slot =sdhci_acpi_get_slot (handle, hid);
@@ -251,6 +308,11 @@ static int sdhci_acpi_probe(struct platform_device *pdev)if (err) goto err_free; +if (sdhci_acpi_flag (c,SDHCI_ACPI_SD_CD )) { +if (sdhci_acpi_add_own_cd (dev, gpio, host->mmc)) + c->use_runtime_pm = false; + } +if (c->use_runtime_pm) {pm_runtime_set_active (dev);pm_suspend_ignore_children (dev,1 );
Signature · 1 line
1.7.11.7
Adrian Hunter
maintainerPATCH 3/3 mmc: sdhci-pci: support runtime PM for BYT SD cards
In reply to Adrian HunterAdd support for runtime PM for BYT SD cards.
--- drivers/mmc/host/sdhci-pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-pci.c +2 -0
@@ -332,6 +332,8 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { };static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { + .quirks2 =SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON , + .allow_runtime_pm = true, };/* O2Micro extra registers */
Signature · 1 line
1.7.11.7
Quoted 16 lines · Adrian Hunter
Here are 3 patches to support runtime PM for BYT SD cards
Please note that these patches are dependent upon 2 gpio patches that are in linux-next and linux-gpio but not the mmc tree. Those patches are:
author Mika Westerberg <[email protected]> 2013-04-03 10:56:54 (GMT) committer Linus Walleij <[email protected]> 2013-04-11 22:31:18 (GMT) commit 12028d2d216220618f76284af5f8ed510b11da55 (patch) gpiolib-acpi: introduce acpi_get_gpio_by_index() helper author Rafael J. Wysocki <[email protected]> 2013-04-09 13:57:25 (GMT) committer Linus Walleij <[email protected]> 2013-04-10 21:41:17 (GMT) commit 7fc7acb9a0b0ff3ffdf21818fe0735ebaf4fecb8 (patch) gpio / ACPI: Handle ACPI events in accordance with the spec
Quoted 3 lines
I think those patches are queued for 3.10.
cc Linus Walleij <[email protected]>
No they are currently not, and will as it looks right now *not* be in v3.10 due to a screwup from my side, and that screwup walking the ladder to Torvalds where it exploded. So he's not pulling the GPIO tree this merge window.
So just sit back and synchronize this for v3.11 (surely they can be taken through the GPIO tree if Chris gives his ACK on them).
Yours,
Linus Walleij
Adrian Hunter
maintainerQuoted 22 lines · Linus Walleij
Quoted 16 lines · Adrian Hunter
Here are 3 patches to support runtime PM for BYT SD cards
Please note that these patches are dependent upon 2 gpio patches that are in linux-next and linux-gpio but not the mmc tree. Those patches are:
author Mika Westerberg <[email protected]> 2013-04-03 10:56:54 (GMT) committer Linus Walleij <[email protected]> 2013-04-11 22:31:18 (GMT) commit 12028d2d216220618f76284af5f8ed510b11da55 (patch) gpiolib-acpi: introduce acpi_get_gpio_by_index() helper author Rafael J. Wysocki <[email protected]> 2013-04-09 13:57:25 (GMT) committer Linus Walleij <[email protected]> 2013-04-10 21:41:17 (GMT) commit 7fc7acb9a0b0ff3ffdf21818fe0735ebaf4fecb8 (patch) gpio / ACPI: Handle ACPI events in accordance with the specQuoted 3 lines
I think those patches are queued for 3.10.
cc Linus Walleij <[email protected]>
Quoted 7 lines
No they are currently not, and will as it looks right now *not* be in v3.10 due to a screwup from my side, and that screwup walking the ladder to Torvalds where it exploded. So he's not pulling the GPIO tree this merge window.
So just sit back and synchronize this for v3.11 (surely they can be taken through the GPIO tree if Chris gives his ACK on them).
3.11 is fine, but one of the patches:
[PATCH 1/3] mmc: sdhci: add ability to stay runtime-resumed if the card is powered up
really should be in the mmc tree.
It would be simpler if the above 2 ACPI GPIO patches made it to 3.10 or went via the mmc tree. Adding Rafael in case he can still take them for 3.10.
Quoted 31 lines · Adrian Hunter
Quoted 22 lines · Linus Walleij
Quoted 16 lines · Adrian Hunter
Here are 3 patches to support runtime PM for BYT SD cards
Please note that these patches are dependent upon 2 gpio patches that are in linux-next and linux-gpio but not the mmc tree. Those patches are:
author Mika Westerberg <[email protected]> 2013-04-03 10:56:54 (GMT) committer Linus Walleij <[email protected]> 2013-04-11 22:31:18 (GMT) commit 12028d2d216220618f76284af5f8ed510b11da55 (patch) gpiolib-acpi: introduce acpi_get_gpio_by_index() helper author Rafael J. Wysocki <[email protected]> 2013-04-09 13:57:25 (GMT) committer Linus Walleij <[email protected]> 2013-04-10 21:41:17 (GMT) commit 7fc7acb9a0b0ff3ffdf21818fe0735ebaf4fecb8 (patch) gpio / ACPI: Handle ACPI events in accordance with the specQuoted 3 lines
I think those patches are queued for 3.10.
cc Linus Walleij <[email protected]>Quoted 7 lines
No they are currently not, and will as it looks right now *not* be in v3.10 due to a screwup from my side, and that screwup walking the ladder to Torvalds where it exploded. So he's not pulling the GPIO tree this merge window.
So just sit back and synchronize this for v3.11 (surely they can be taken through the GPIO tree if Chris gives his ACK on them).
Quoted 8 lines
3.11 is fine, but one of the patches:
[PATCH 1/3] mmc: sdhci: add ability to stay runtime-resumed if the card is powered up
really should be in the mmc tree.
It would be simpler if the above 2 ACPI GPIO patches made it to 3.10 or went via the mmc tree. Adding Rafael in case he can still take them for 3.10.
Looks like Linus pulled GPIO changes already. So they should be available for 3.10.
Quoted 7 lines · Mika
Quoted 2 lines · Adrian Hunter
It would be simpler if the above 2 ACPI GPIO patches made it to 3.10 or went via the mmc tree. Adding Rafael in case he can still take them for 3.10.
Looks like Linus pulled GPIO changes already. So they should be available for 3.10.
Yes it appears he (the other Linus) changed his mind, that's fine then...
Yours,
Linus Walleij
Hi Adrian,
Quoted 18 lines · Adrian Hunter
Hi
Here are 3 patches to support runtime PM for BYT SD cards
Please note that these patches are dependent upon 2 gpio patches that are in linux-next and linux-gpio but not the mmc tree. Those patches are:
author Mika Westerberg <[email protected]> 2013-04-03 10:56:54 (GMT) committer Linus Walleij <[email protected]> 2013-04-11 22:31:18 (GMT) commit 12028d2d216220618f76284af5f8ed510b11da55 (patch) gpiolib-acpi: introduce acpi_get_gpio_by_index() helper author Rafael J. Wysocki <[email protected]> 2013-04-09 13:57:25 (GMT) committer Linus Walleij <[email protected]> 2013-04-10 21:41:17 (GMT) commit 7fc7acb9a0b0ff3ffdf21818fe0735ebaf4fecb8 (patch) gpio / ACPI: Handle ACPI events in accordance with the spec
Quoted 1 line
I think those patches are queued for 3.10.
Thanks, I'll pushed these to mmc-next for 3.11 now.
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child