linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremie Samuel <jeremie.samuel.ext@parrot.com>
To: Chris Ball <cjb@laptop.org>
Cc: linux-mmc@vger.kernel.org,
	"Grégor Boirie" <gregor.boirie@parrot.com>,
	"Matthieu Castet" <matthieu.castet@parrot.com>,
	"Jeremie Samuel" <jeremie.samuel.ext@parrot.com>
Subject: [PATCH v2 5/8] sdhci: Delay led blinking
Date: Mon, 21 Oct 2013 17:25:54 +0200	[thread overview]
Message-ID: <1382369157-16129-6-git-send-email-jeremie.samuel.ext@parrot.com> (raw)
In-Reply-To: <1382369157-16129-1-git-send-email-jeremie.samuel.ext@parrot.com>

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(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 0bb892c..be91ca1 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -280,8 +280,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)
@@ -289,8 +295,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
@@ -298,19 +310,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
 
@@ -1338,9 +1342,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
@@ -2172,15 +2174,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)
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index 05cd76c..3bb6ad6 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -115,6 +115,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 */
-- 
1.7.10.4


  parent reply	other threads:[~2013-10-21 15:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 15:25 [PATCH v2 0/8] sdhci: Move real work out of an atomic context Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 1/8] sdhci: Turn timeout timer into delayed work Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 2/8] sdhci: Turn tuning " Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 3/8] sdhci: Use work structs instead of tasklets Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 4/8] sdhci: Use threaded IRQ handler Jeremie Samuel
2013-10-30 19:30   ` Olof Johansson
2013-10-21 15:25 ` Jeremie Samuel [this message]
2013-10-21 15:25 ` [PATCH v2 6/8] sdhci: Turn host->lock into a mutex Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 7/8] sdhci: Get rid of mdelay()s where it is safe and makes sense Jeremie Samuel
2013-10-21 15:25 ` [PATCH v2 8/8] sdhci: Use jiffies instead of a timeout counter Jeremie Samuel
2013-10-21 15:31 ` [PATCH v2 0/8] sdhci: Move real work out of an atomic context Chris Ball
2013-10-21 15:52   ` Jeremie Samuel
2013-10-21 20:02 ` Chris Ball

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1382369157-16129-6-git-send-email-jeremie.samuel.ext@parrot.com \
    --to=jeremie.samuel.ext@parrot.com \
    --cc=cjb@laptop.org \
    --cc=gregor.boirie@parrot.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=matthieu.castet@parrot.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).