@@ -269,8 +269,14 @@ static void sdhci_activate_led(struct sdhci_host *host)
u8 ctrl;
ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
- ctrl |= SDHCI_CTRL_LED;
- sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+#ifdef SDHCI_USE_LEDS_CLASS
+ if (host->brightness && !(ctrl & SDHCI_CTRL_LED)) {
+#else
+ if (!(ctrl & SDHCI_CTRL_LED)) {
+#endif
+ ctrl |= SDHCI_CTRL_LED;
+ sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+ }
}
static void sdhci_deactivate_led(struct sdhci_host *host)
@@ -278,8 +284,14 @@ static void sdhci_deactivate_led(struct sdhci_host *host)
u8 ctrl;
ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
- ctrl &= ~SDHCI_CTRL_LED;
- sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+#ifdef SDHCI_USE_LEDS_CLASS
+ if (!host->brightness && (ctrl & SDHCI_CTRL_LED)) {
+#else
+ if (ctrl & SDHCI_CTRL_LED) {
+#endif
+ ctrl &= ~SDHCI_CTRL_LED;
+ sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+ }
}
#ifdef SDHCI_USE_LEDS_CLASS
@@ -287,19 +299,11 @@ static void sdhci_led_control(struct led_classdev *led,
enum led_brightness brightness)
{
struct sdhci_host *host = container_of(led, struct sdhci_host, led);
- unsigned long flags;
-
- spin_lock_irqsave(&host->lock, flags);
if (host->runtime_suspended)
- goto out;
+ return;
- if (brightness == LED_OFF)
- sdhci_deactivate_led(host);
- else
- sdhci_activate_led(host);
-out:
- spin_unlock_irqrestore(&host->lock, flags);
+ host->brightness = brightness;
}
#endif
@@ -1321,9 +1325,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
WARN_ON(host->mrq != NULL);
-#ifndef SDHCI_USE_LEDS_CLASS
sdhci_activate_led(host);
-#endif
/*
* Ensure we don't send the STOP for non-SET_BLOCK_COUNTED
@@ -2145,15 +2147,15 @@ static void sdhci_finish_work(struct work_struct *wk)
host->cmd = NULL;
host->data = NULL;
-#ifndef SDHCI_USE_LEDS_CLASS
- sdhci_deactivate_led(host);
-#endif
-
mmiowb();
spin_unlock_irqrestore(&host->lock, flags);
mmc_request_done(host->mmc, mrq);
sdhci_runtime_pm_put(host);
+
+ spin_lock_irqsave(&host->lock, flags);
+ sdhci_deactivate_led(host);
+ spin_unlock_irqrestore(&host->lock, flags);
}
static void sdhci_timeout_work(struct work_struct *wk)
@@ -112,6 +112,7 @@ struct sdhci_host {
#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE)
struct led_classdev led; /* LED control */
char led_name[32];
+ enum led_brightness brightness;
#endif
spinlock_t lock; /* Mutex */
The function sdhci_led_control is called in an atomic context by the led_trigger driver. So, it is necessary to delay the activation or deactivation of the led. Signed-off-by: Jeremie Samuel <jeremie.samuel.ext@parrot.com> --- drivers/mmc/host/sdhci.c | 42 ++++++++++++++++++++++-------------------- include/linux/mmc/sdhci.h | 1 + 2 files changed, 23 insertions(+), 20 deletions(-)