Skip to contentSkip to conversation

mmc: sdhci-pci: Enable card detect wake for Intel BYT-related SD card host controllers

PATCH Superseded Adrian Hunter 2 participants 9 messages Apr 19, 2017 – Jun 13, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Adrian Hunter

author maintainer
#0 lore raw

cover mmc: sdhci-pci: Enable card detect wake for Intel BYT-related SD card host controllers

Hi

Here are 2 small patches to enable card detect wake for Intel BYT-related SD card host controllers.

Adrian Hunter (2):
mmc: slot-gpio: Add support to enable irq wake on cd_irq
mmc: sdhci-pci: Enable card detect wake for Intel BYT-related SD card host controllers

 drivers/mmc/core/core.c           |  5 ++++-
 drivers/mmc/core/slot-gpio.c      | 12 ++++++++++++
 drivers/mmc/host/sdhci-pci-core.c |  3 +++
 drivers/mmc/host/sdhci-pci.h      |  1 +
 include/linux/mmc/host.h          |  1 +
 include/linux/mmc/slot-gpio.h     |  1 +
 6 files changed, 22 insertions(+), 1 deletion(-)

Regards
Adrian

author maintainer
#1 lore raw

PATCH 1/2 mmc: slot-gpio: Add support to enable irq wake on cd_irq

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
 	host->removed = 1;
 	spin_unlock_irqrestore(&host->lock, flags);
 #endif
-	if (host->slot.cd_irq >= 0)
+	if (host->slot.cd_irq >= 0) {
+		if (host->slot.cd_wake_enabled)
+			disable_irq_wake(host->slot.cd_irq);
 		disable_irq(host->slot.cd_irq);
+	}
 
 	host->rescan_disable = 1;
 	cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +12 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
 	struct gpio_desc *cd_gpio;
 	bool override_ro_active_level;
 	bool override_cd_active_level;
+	bool cd_wake;
 	irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
 	char *ro_label;
 	char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+	struct mmc_gpio *ctx = host->slot.handler_priv;
+
+	if (ctx && ctx->cd_gpio)
+		ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
 	struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
 	if (irq < 0)
 		host->caps |= MMC_CAP_NEEDS_POLL;
+	else if (ctx->cd_wake && !enable_irq_wake(irq))
+		host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
 	int cd_irq;
+	bool cd_wake_enabled;
 	void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -0
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
 			 irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

Quoted 4 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Any comments on this?

Quoted 85 lines
---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
 	host->removed = 1;
 	spin_unlock_irqrestore(&host->lock, flags);
 #endif
-	if (host->slot.cd_irq >= 0)
+	if (host->slot.cd_irq >= 0) {
+		if (host->slot.cd_wake_enabled)
+			disable_irq_wake(host->slot.cd_irq);
 		disable_irq(host->slot.cd_irq);
+	}
 
 	host->rescan_disable = 1;
 	cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +12 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
 	struct gpio_desc *cd_gpio;
 	bool override_ro_active_level;
 	bool override_cd_active_level;
+	bool cd_wake;
 	irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
 	char *ro_label;
 	char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+	struct mmc_gpio *ctx = host->slot.handler_priv;
+
+	if (ctx && ctx->cd_gpio)
+		ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
 	struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
 	if (irq < 0)
 		host->caps |= MMC_CAP_NEEDS_POLL;
+	else if (ctx->cd_wake && !enable_irq_wake(irq))
+		host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
 	int cd_irq;
+	bool cd_wake_enabled;
 	void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -0
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
 			 irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
#3 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

Quoted 7 lines · Adrian Hunter
Quoted 4 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Any comments on this?

Not yet. I need some more thinking about this.

However, at first glance it seems very reasonable to make the core to help with cd wakeup irqs.

Related topic: I have a plan of avoiding the mmc_pm_notify() to punt a work at resume, in case the host has enabled cd wakeup irqs. The reason is that we are sometimes resuming removable cards, just to find out that those are still there. I would be interesting to know how $subject change can help with this as well. I intend to keep this in mind while I review this, just so you know. :-)

Kind regards
Uffe

Quoted 87 lines
Quoted 86 lines
---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
      host->removed = 1;
      spin_unlock_irqrestore(&host->lock, flags);
 #endif
-     if (host->slot.cd_irq >= 0)
+     if (host->slot.cd_irq >= 0) {
+             if (host->slot.cd_wake_enabled)
+                     disable_irq_wake(host->slot.cd_irq);
              disable_irq(host->slot.cd_irq);
+     }
 
      host->rescan_disable = 1;
      cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +12 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
      struct gpio_desc *cd_gpio;
      bool override_ro_active_level;
      bool override_cd_active_level;
+     bool cd_wake;
      irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
      char *ro_label;
      char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+     struct mmc_gpio *ctx = host->slot.handler_priv;
+
+     if (ctx && ctx->cd_gpio)
+             ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
      struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
      if (irq < 0)
              host->caps |= MMC_CAP_NEEDS_POLL;
+     else if (ctx->cd_wake && !enable_irq_wake(irq))
+             host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
      int cd_irq;
+     bool cd_wake_enabled;
      void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -0
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
                       irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
author maintainer
#4 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

Quoted 10 lines · Ulf Hansson
Quoted 7 lines · Adrian Hunter
Quoted 4 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Any comments on this?

Not yet. I need some more thinking about this.

How is the thinking going ;-)

Quoted 102 lines

However, at first glance it seems very reasonable to make the core to help with cd wakeup irqs.

Related topic: I have a plan of avoiding the mmc_pm_notify() to punt a work at resume, in case the host has enabled cd wakeup irqs. The reason is that we are sometimes resuming removable cards, just to find out that those are still there. I would be interesting to know how $subject change can help with this as well. I intend to keep this in mind while I review this, just so you know. :-)

Kind regards
Uffe

Quoted 87 lines
Quoted 86 lines
---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
      host->removed = 1;
      spin_unlock_irqrestore(&host->lock, flags);
 #endif
-     if (host->slot.cd_irq >= 0)
+     if (host->slot.cd_irq >= 0) {
+             if (host->slot.cd_wake_enabled)
+                     disable_irq_wake(host->slot.cd_irq);
              disable_irq(host->slot.cd_irq);
+     }
 
      host->rescan_disable = 1;
      cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +12 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
      struct gpio_desc *cd_gpio;
      bool override_ro_active_level;
      bool override_cd_active_level;
+     bool cd_wake;
      irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
      char *ro_label;
      char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+     struct mmc_gpio *ctx = host->slot.handler_priv;
+
+     if (ctx && ctx->cd_gpio)
+             ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
      struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
      if (irq < 0)
              host->caps |= MMC_CAP_NEEDS_POLL;
+     else if (ctx->cd_wake && !enable_irq_wake(irq))
+             host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
      int cd_irq;
+     bool cd_wake_enabled;
      void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -0
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
                       irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
#5 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

Quoted 6 lines · Adrian Hunter
Quoted 5 lines · Ulf Hansson
Quoted 4 lines · Adrian Hunter
Quoted 3 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Any comments on this?

Not yet. I need some more thinking about this.

How is the thinking going ;-)

To many things at the moment. Anyway, to me this is material for 4.13. I will get back to it as soon as I can.

Kind regards
Uffe

Quoted 104 lines
Quoted 103 lines

However, at first glance it seems very reasonable to make the core to help with cd wakeup irqs.

Related topic: I have a plan of avoiding the mmc_pm_notify() to punt a work at resume, in case the host has enabled cd wakeup irqs. The reason is that we are sometimes resuming removable cards, just to find out that those are still there. I would be interesting to know how $subject change can help with this as well. I intend to keep this in mind while I review this, just so you know. :-)

Kind regards
Uffe

Quoted 87 lines
Quoted 86 lines
---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
      host->removed = 1;
      spin_unlock_irqrestore(&host->lock, flags);
 #endif
-     if (host->slot.cd_irq >= 0)
+     if (host->slot.cd_irq >= 0) {
+             if (host->slot.cd_wake_enabled)
+                     disable_irq_wake(host->slot.cd_irq);
              disable_irq(host->slot.cd_irq);
+     }
 
      host->rescan_disable = 1;
      cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +12 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
      struct gpio_desc *cd_gpio;
      bool override_ro_active_level;
      bool override_cd_active_level;
+     bool cd_wake;
      irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
      char *ro_label;
      char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+     struct mmc_gpio *ctx = host->slot.handler_priv;
+
+     if (ctx && ctx->cd_gpio)
+             ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
      struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
      if (irq < 0)
              host->caps |= MMC_CAP_NEEDS_POLL;
+     else if (ctx->cd_wake && !enable_irq_wake(irq))
+             host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
      int cd_irq;
+     bool cd_wake_enabled;
      void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -0
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
                       irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
author maintainer
#6 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

Quoted 9 lines · Ulf Hansson
Quoted 8 lines · Adrian Hunter
Quoted 7 lines · Ulf Hansson
Quoted 6 lines · Adrian Hunter
Quoted 4 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Any comments on this?

Not yet. I need some more thinking about this.

How is the thinking going ;-)

To many things at the moment. Anyway, to me this is material for 4.13. I will get back to it as soon as I can.

Any update on this?

#7 lore raw

Re: [PATCH 1/2] mmc: slot-gpio: Add support to enable irq wake on cd_irq

In reply to Adrian Hunter
Quoted 2 lines · Adrian Hunter

Add mmc_gpio_cd_enable_wake() to allow drivers to enable irq wake on the card detect irq.

Adrian, again apologize for the delay. As stated earlier, this is a very good idea. See some more comments below.

Quoted 40 lines
---
 drivers/mmc/core/core.c       |  5 ++++-
 drivers/mmc/core/slot-gpio.c  | 12 ++++++++++++
 include/linux/mmc/host.h      |  1 +
 include/linux/mmc/slot-gpio.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/mmc/core/core.c +4 -1
index 0bb39795d484..6987976252ad 100644
@@ -2828,8 +2828,11 @@ void mmc_stop_host(struct mmc_host *host)
        host->removed = 1;
        spin_unlock_irqrestore(&host->lock, flags);
 #endif
-       if (host->slot.cd_irq >= 0)
+       if (host->slot.cd_irq >= 0) {
+               if (host->slot.cd_wake_enabled)
+                       disable_irq_wake(host->slot.cd_irq);
                disable_irq(host->slot.cd_irq);
+       }
 
        host->rescan_disable = 1;
        cancel_delayed_work_sync(&host->detect);
drivers/mmc/core/slot-gpio.c +1 -0
index a8450a8701e4..56e4edb9e63a 100644
@@ -25,6 +25,7 @@ struct mmc_gpio {
        struct gpio_desc *cd_gpio;
        bool override_ro_active_level;
        bool override_cd_active_level;
+       bool cd_wake;
        irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
        char *ro_label;
        char cd_label[0];
@@ -118,6 +119,15 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
 }

drivers/mmc/core/slot-gpio.c int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) · line 129

Quoted 10 lines
drivers/mmc/core/slot-gpio.c +8 -0
 EXPORT_SYMBOL(mmc_gpio_request_ro);
 
+void mmc_gpio_cd_enable_wake(struct mmc_host *host)
+{
+       struct mmc_gpio *ctx = host->slot.handler_priv;
+
+       if (ctx && ctx->cd_gpio)
+               ctx->cd_wake = true;
+}
+EXPORT_SYMBOL(mmc_gpio_cd_enable_wake);

I am wondering whether we really need a new slot API for this. Couldn't we just add new host caps for this and use that instead of the bool cd_awake?

The reason why I think that would make sense, is because it would simplify for mmc host drivers. Especially in the case of DT, as potentially we could deal with this from mmc_of_parse().

Quoted 37 lines
drivers/mmc/core/slot-gpio.c +3 -0
+
 void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 {
        struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -151,6 +161,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 
        if (irq < 0)
                host->caps |= MMC_CAP_NEEDS_POLL;
+       else if (ctx->cd_wake && !enable_irq_wake(irq))
+               host->slot.cd_wake_enabled = true;
 }
 EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
 
include/linux/mmc/host.h +1 -0
index 21385ac0c9b1..78c544e296cd 100644
@@ -184,6 +184,7 @@ struct mmc_async_req {
  */
 struct mmc_slot {
        int cd_irq;
+       bool cd_wake_enabled;
        void *handler_priv;
 };
 
include/linux/mmc/slot-gpio.h +1 -1
index 82f0d289f110..6af681d33a53 100644
@@ -33,5 +33,6 @@ void mmc_gpio_set_cd_isr(struct mmc_host *host,
                         irqreturn_t (*isr)(int irq, void *dev_id));
 void mmc_gpiod_request_cd_irq(struct mmc_host *host);
 bool mmc_can_gpio_cd(struct mmc_host *host);
+void mmc_gpio_cd_enable_wake(struct mmc_host *host);
 
 #endif
--
Quoted 2 lines

1.9.1

Otherwise this looks great to me!

One reason to the delay in review, was that I wanted to think about how this affects how mmc use device wakeups in general (device_may_wakeup()) during system suspend. In general userspace should be given the option to control whether device wakeups should be enabled or not (which driver then checks via calling device_may_wakeup()), however I don't think we need to give user space the option in this cases, as it's not really the device that wakes up the system, but a GPIO pin.

Kind regards
Uffe

author maintainer
#8 lore raw

PATCH 2/2 mmc: sdhci-pci: Enable card detect wake for Intel BYT-related SD card host controllers

In reply to Adrian Hunter

Enable card detect wake for Intel BYT-related SD card host controllers.

---
 drivers/mmc/host/sdhci-pci-core.c | 3 +++
 drivers/mmc/host/sdhci-pci.h      | 1 +
 2 files changed, 4 insertions(+)
drivers/mmc/host/sdhci-pci-core.c +3 -0
index 833072b8453e..57d6f50b73dc 100644
@@ -634,6 +634,7 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
 				 MMC_CAP_AGGRESSIVE_PM;
 	slot->cd_idx = 0;
 	slot->cd_override_level = true;
+	slot->cd_wake = true;
 	if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD ||
 	    slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD ||
 	    slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD ||
@@ -1989,6 +1990,8 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
 		if (ret) {
 			dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
 			slot->cd_idx = -1;
+		} else if (slot->cd_wake) {
+			mmc_gpio_cd_enable_wake(host->mmc);
 		}
 	}
 
drivers/mmc/host/sdhci-pci.h +1 -0
index 37766d20a600..6029fb314421 100644
@@ -91,6 +91,7 @@ struct sdhci_pci_slot {
 
 	int			cd_idx;
 	bool			cd_override_level;
+	bool			cd_wake;
 
 	void (*hw_reset)(struct sdhci_host *host);
 	unsigned long		private[0] ____cacheline_aligned;
Signature · 1 line
1.9.1