All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle
@ 2015-03-24 20:56 NeilBrown
  2015-03-24 20:56 ` [PATCH 2/4] mmc/core: add pm_runtime tracking to mmc_host devices NeilBrown
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: NeilBrown @ 2015-03-24 20:56 UTC (permalink / raw)
  To: Ulf Hansson, Adrian Hunter; +Cc: linux-mmc

This is a proof-of-concept hack to demonstrate what I was
trying to describe earlier.
The last patch, in particular, takes some very ugly short-cuts
which I would never dream of proposing for upstream inclusion.

It seems to work, but I haven't tested thoroughly.  I may not even be
doing what I think it is doing...

Comments?

Thanks,
NeilBrown
---

NeilBrown (4):
      mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
      mmc/core: add pm_runtime tracking to mmc_host devices.
      mmc/sdio: keep device awake when interrupts expected in 4bit mode
      mmc/host: use runtime_pm to switch to 1-bit mode


 drivers/mmc/core/core.c |    5 +++
 drivers/mmc/core/host.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/mmc/core/sdio.c |   41 +++++++++++--------------
 3 files changed, 100 insertions(+), 24 deletions(-)

--
Signature


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
  2015-03-24 20:56 [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle NeilBrown
  2015-03-24 20:56 ` [PATCH 2/4] mmc/core: add pm_runtime tracking to mmc_host devices NeilBrown
@ 2015-03-24 20:56 ` NeilBrown
  2015-03-24 21:18   ` Ulf Hansson
  2015-03-24 20:56 ` [PATCH 3/4] mmc/sdio: keep device awake when interrupts expected in 4bit mode NeilBrown
  2015-03-24 20:56 ` [PATCH 4/4] mmc/host: use runtime_pm to switch to 1-bit mode NeilBrown
  3 siblings, 1 reply; 9+ messages in thread
From: NeilBrown @ 2015-03-24 20:56 UTC (permalink / raw)
  To: Ulf Hansson, Adrian Hunter; +Cc: Tony Lindgren, linux-mmc

From: NeilBrown <neilb@suse.de>

Every call to sdio_enable_4bit_bus is followed (on success) but a call
to mmc_set_bus_width().

To simplify the code, include those calls directly in
sdio_enable_4bit_bus().

Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mmc/core/sdio.c |   32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ce6cc47206b0..5bc6c7dbbd60 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
 	int err;
 
 	if (card->type == MMC_TYPE_SDIO)
-		return sdio_enable_wide(card);
-
-	if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
-		(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
+		err = sdio_enable_wide(card);
+	else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
+		 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
 		err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
 		if (err)
 			return err;
+		err = sdio_enable_wide(card);
+		if (err <= 0)
+			mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
 	} else
 		return 0;
 
-	err = sdio_enable_wide(card);
-	if (err <= 0)
-		mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
+	if (err > 0) {
+		mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
+		err = 0;
+	}
 
 	return err;
 }
@@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
 	/*
 	 * Switch to wider bus (if supported).
 	 */
-	if (card->host->caps & MMC_CAP_4_BIT_DATA) {
+	if (card->host->caps & MMC_CAP_4_BIT_DATA)
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0) {
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
-	}
 
 	/* Set the driver strength for the card */
 	sdio_select_driver_type(card);
@@ -803,9 +801,7 @@ try_again:
 		 * Switch to wider bus (if supported).
 		 */
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0)
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-		else if (err)
+		if (err)
 			goto remove;
 	}
 finish:
@@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
 	} else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
 		/* We may have switched to 1-bit mode during suspend */
 		err = sdio_enable_4bit_bus(host->card);
-		if (err > 0) {
-			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
 	}
 
 	if (!err && host->sdio_irqs) {



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] mmc/core: add pm_runtime tracking to mmc_host devices.
  2015-03-24 20:56 [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle NeilBrown
@ 2015-03-24 20:56 ` NeilBrown
  2015-03-24 20:56 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2015-03-24 20:56 UTC (permalink / raw)
  To: Ulf Hansson, Adrian Hunter; +Cc: linux-mmc

Enable runtime pm for mmc_host devices, and take a
reference while the host is claimed.

Use an autosuspend timeout so that the device isn't
put to sleep until we have been idle for a while.

Set the parent to ignore children, so the PM status of
the host does not affect the controller at all.

This functionality will be used in a future patch to allow
commands to be sent to the device when the host is idle.

Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mmc/core/core.c |    5 +++++
 drivers/mmc/core/host.c |   23 +++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 23f10f72e5f3..ca475a5c8d94 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -900,6 +900,7 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 
 	might_sleep();
 
+	pm_runtime_get_sync(&host->class_dev);
 	add_wait_queue(&host->wq, &wait);
 	spin_lock_irqsave(&host->lock, flags);
 	while (1) {
@@ -922,6 +923,8 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 	remove_wait_queue(&host->wq, &wait);
 	if (host->ops->enable && !stop && host->claim_cnt == 1)
 		host->ops->enable(host);
+	if (stop)
+		pm_runtime_put(&host->class_dev);
 	return stop;
 }
 
@@ -953,6 +956,8 @@ void mmc_release_host(struct mmc_host *host)
 		spin_unlock_irqrestore(&host->lock, flags);
 		wake_up(&host->wq);
 	}
+	pm_runtime_mark_last_busy(&host->class_dev);
+	pm_runtime_put_autosuspend(&host->class_dev);
 }
 EXPORT_SYMBOL(mmc_release_host);
 
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 8be0df758e68..c205c4531b44 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -22,6 +22,7 @@
 #include <linux/leds.h>
 #include <linux/slab.h>
 #include <linux/suspend.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -490,6 +491,11 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 	host->class_dev.parent = dev;
 	host->class_dev.class = &mmc_host_class;
 	device_initialize(&host->class_dev);
+	if (dev)
+		/*
+		 * The device can sleep even when host is claimed.
+		 */
+		pm_suspend_ignore_children(dev, true);
 
 	if (mmc_gpio_alloc(host)) {
 		put_device(&host->class_dev);
@@ -532,15 +538,25 @@ EXPORT_SYMBOL(mmc_alloc_host);
 int mmc_add_host(struct mmc_host *host)
 {
 	int err;
+	struct device *dev = &host->class_dev;
 
 	WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
 		!host->ops->enable_sdio_irq);
 
-	err = device_add(&host->class_dev);
+	err = device_add(dev);
 	if (err)
 		return err;
+	pm_runtime_enable(dev);
+	/*
+	 * The host should be able to suspend while the attached card
+	 * stays awake.
+	 */
+	pm_suspend_ignore_children(dev, true);
+	pm_runtime_get_sync(dev);
+	pm_runtime_set_autosuspend_delay(dev, 100);
+	pm_runtime_use_autosuspend(dev);
 
-	led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
+	led_trigger_register_simple(dev_name(dev), &host->led);
 
 #ifdef CONFIG_DEBUG_FS
 	mmc_add_host_debugfs(host);
@@ -550,6 +566,9 @@ int mmc_add_host(struct mmc_host *host)
 	mmc_start_host(host);
 	register_pm_notifier(&host->pm_notify);
 
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+
 	return 0;
 }
 



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] mmc/sdio: keep device awake when interrupts expected in 4bit mode
  2015-03-24 20:56 [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle NeilBrown
  2015-03-24 20:56 ` [PATCH 2/4] mmc/core: add pm_runtime tracking to mmc_host devices NeilBrown
  2015-03-24 20:56 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
@ 2015-03-24 20:56 ` NeilBrown
  2015-03-24 20:56 ` [PATCH 4/4] mmc/host: use runtime_pm to switch to 1-bit mode NeilBrown
  3 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2015-03-24 20:56 UTC (permalink / raw)
  To: Ulf Hansson, Adrian Hunter; +Cc: linux-mmc

In 4-bit mode, SDIO interrupts are only reliable if clocks
are maintained.
So get an extra reference when that is the case.

Signed-off-by: NeilBrown  <neil@brown.name>
---
 drivers/mmc/core/sdio.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 5bc6c7dbbd60..f432b11677bd 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -227,6 +227,9 @@ static int sdio_enable_wide(struct mmc_card *card)
 	if (ret)
 		return ret;
 
+	/* Interrupts only work in 4bit mode if clocks stay on */
+	if (card->host->caps & MMC_CAP_SDIO_IRQ)
+		pm_runtime_get(card->host->parent);
 	return 1;
 }
 
@@ -283,6 +286,8 @@ static int sdio_disable_wide(struct mmc_card *card)
 		return ret;
 
 	mmc_set_bus_width(card->host, MMC_BUS_WIDTH_1);
+	if (card->host->caps & MMC_CAP_SDIO_IRQ)
+		pm_runtime_put(card->host->parent);
 
 	return 0;
 }



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] mmc/host: use runtime_pm to switch to 1-bit mode
  2015-03-24 20:56 [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle NeilBrown
                   ` (2 preceding siblings ...)
  2015-03-24 20:56 ` [PATCH 3/4] mmc/sdio: keep device awake when interrupts expected in 4bit mode NeilBrown
@ 2015-03-24 20:56 ` NeilBrown
  3 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2015-03-24 20:56 UTC (permalink / raw)
  To: Ulf Hansson, Adrian Hunter; +Cc: linux-mmc

sdio card needs to switch to 1-bit more before the
device can go to sleep.  So when the host has been unclaimed
for a while, do that using runtime_pm.

Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mmc/core/host.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/sdio.c |    4 ++-
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index c205c4531b44..866df1858e6e 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -47,9 +47,64 @@ static void mmc_host_classdev_release(struct device *dev)
 	kfree(host);
 }
 
+int sdio_disable_wide(struct mmc_card *card);
+
+static int mmc_host_runtime_suspend(struct device *dev)
+{
+	/* If SDIO card is in 4bit mode, we need to
+	 * switch it to 1-bit mode so that it can
+	 * go to sleep.
+	 */
+	struct mmc_host *host = cls_dev_to_mmc_host(dev);
+	if (host->card && host->card->type == MMC_TYPE_SDIO &&
+		host->ios.bus_width == 4) {
+		/* The host cannot be claimed while suspending,
+		 * so we are safe
+		 */
+		BUG_ON(host->claimed);
+		host->claimed = 1;
+		host->claim_cnt = 1;
+		host->claimer = current;
+		sdio_disable_wide(host->card);
+		host->claimed = 0;
+		host->claim_cnt = 0;
+		host->claimer = NULL;
+		host->unused = 1;
+	}
+	return 0;
+}
+
+int sdio_enable_wide(struct mmc_card *card);
+static int mmc_host_runtime_resume(struct device *dev)
+{
+	struct mmc_host *host = cls_dev_to_mmc_host(dev);
+	if (host->card && host->card->type == MMC_TYPE_SDIO &&
+		host->unused) {
+		/* The host cannot be claimed while suspending,
+		 * so we are safe
+		 */
+		BUG_ON(host->claimed);
+		host->claimed = 1;
+		host->claim_cnt = 1;
+		host->claimer = current;
+		sdio_enable_wide(host->card);
+		host->claimed = 0;
+		host->claim_cnt = 0;
+		host->claimer = NULL;
+		host->unused = 0;
+	}
+	return 0;
+}
+
+static struct dev_pm_ops mmc_host_dev_pm_ops = {
+	.runtime_suspend= mmc_host_runtime_suspend,
+	.runtime_resume	= mmc_host_runtime_resume,
+};
+
 static struct class mmc_host_class = {
 	.name		= "mmc_host",
 	.dev_release	= mmc_host_classdev_release,
+	.pm		= &mmc_host_dev_pm_ops,
 };
 
 int mmc_register_host_class(void)
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index f432b11677bd..b4713be32fb9 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -200,7 +200,7 @@ out:
 	return ret;
 }
 
-static int sdio_enable_wide(struct mmc_card *card)
+int sdio_enable_wide(struct mmc_card *card)
 {
 	int ret;
 	u8 ctrl;
@@ -260,7 +260,7 @@ static int sdio_disable_cd(struct mmc_card *card)
  * Devices that remain active during a system suspend are
  * put back into 1-bit mode.
  */
-static int sdio_disable_wide(struct mmc_card *card)
+int sdio_disable_wide(struct mmc_card *card)
 {
 	int ret;
 	u8 ctrl;



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
  2015-03-24 20:56 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
@ 2015-03-24 21:18   ` Ulf Hansson
  0 siblings, 0 replies; 9+ messages in thread
From: Ulf Hansson @ 2015-03-24 21:18 UTC (permalink / raw)
  To: NeilBrown; +Cc: Adrian Hunter, Tony Lindgren, linux-mmc

On 24 March 2015 at 21:56, NeilBrown <neil@brown.name> wrote:
> From: NeilBrown <neilb@suse.de>
>
> Every call to sdio_enable_4bit_bus is followed (on success) but a call
> to mmc_set_bus_width().
>
> To simplify the code, include those calls directly in
> sdio_enable_4bit_bus().
>
> Tested-by: Tony Lindgren <tony@atomide.com>
> Signed-off-by: NeilBrown <neil@brown.name>

This one is already applied. Thanks!

Kind regards
Uffe

> ---
>  drivers/mmc/core/sdio.c |   32 ++++++++++++--------------------
>  1 file changed, 12 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
> index ce6cc47206b0..5bc6c7dbbd60 100644
> --- a/drivers/mmc/core/sdio.c
> +++ b/drivers/mmc/core/sdio.c
> @@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
>         int err;
>
>         if (card->type == MMC_TYPE_SDIO)
> -               return sdio_enable_wide(card);
> -
> -       if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
> -               (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
> +               err = sdio_enable_wide(card);
> +       else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
> +                (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
>                 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
>                 if (err)
>                         return err;
> +               err = sdio_enable_wide(card);
> +               if (err <= 0)
> +                       mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
>         } else
>                 return 0;
>
> -       err = sdio_enable_wide(card);
> -       if (err <= 0)
> -               mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
> +       if (err > 0) {
> +               mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> +               err = 0;
> +       }
>
>         return err;
>  }
> @@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
>         /*
>          * Switch to wider bus (if supported).
>          */
> -       if (card->host->caps & MMC_CAP_4_BIT_DATA) {
> +       if (card->host->caps & MMC_CAP_4_BIT_DATA)
>                 err = sdio_enable_4bit_bus(card);
> -               if (err > 0) {
> -                       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> -                       err = 0;
> -               }
> -       }
>
>         /* Set the driver strength for the card */
>         sdio_select_driver_type(card);
> @@ -803,9 +801,7 @@ try_again:
>                  * Switch to wider bus (if supported).
>                  */
>                 err = sdio_enable_4bit_bus(card);
> -               if (err > 0)
> -                       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> -               else if (err)
> +               if (err)
>                         goto remove;
>         }
>  finish:
> @@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
>         } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
>                 /* We may have switched to 1-bit mode during suspend */
>                 err = sdio_enable_4bit_bus(host->card);
> -               if (err > 0) {
> -                       mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
> -                       err = 0;
> -               }
>         }
>
>         if (!err && host->sdio_irqs) {
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
  2015-02-24  2:42 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
@ 2015-03-23  9:34   ` Ulf Hansson
  0 siblings, 0 replies; 9+ messages in thread
From: Ulf Hansson @ 2015-03-23  9:34 UTC (permalink / raw)
  To: NeilBrown
  Cc: Tony Lindgren, Andreas Fenkart, linux-mmc, lkml, GTA04 owners,
	NeilBrown, linux-omap

On 24 February 2015 at 03:42, NeilBrown <neilb@suse.de> wrote:
> Every call to sdio_enable_4bit_bus is followed (on success) but a call

/s /but / by

> to mmc_set_bus_width().
>
> To simplify the code, include those calls directly in
> sdio_enable_4bit_bus().
>
> Signed-off-by: NeilBrown <neil@brown.name>

Nice cleanup! Applied for next with the above minor change.

Kind regards
Uffe

> ---
>  drivers/mmc/core/sdio.c |   32 ++++++++++++--------------------
>  1 file changed, 12 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
> index ce6cc47206b0..5bc6c7dbbd60 100644
> --- a/drivers/mmc/core/sdio.c
> +++ b/drivers/mmc/core/sdio.c
> @@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
>         int err;
>
>         if (card->type == MMC_TYPE_SDIO)
> -               return sdio_enable_wide(card);
> -
> -       if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
> -               (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
> +               err = sdio_enable_wide(card);
> +       else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
> +                (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
>                 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
>                 if (err)
>                         return err;
> +               err = sdio_enable_wide(card);
> +               if (err <= 0)
> +                       mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
>         } else
>                 return 0;
>
> -       err = sdio_enable_wide(card);
> -       if (err <= 0)
> -               mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
> +       if (err > 0) {
> +               mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> +               err = 0;
> +       }
>
>         return err;
>  }
> @@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
>         /*
>          * Switch to wider bus (if supported).
>          */
> -       if (card->host->caps & MMC_CAP_4_BIT_DATA) {
> +       if (card->host->caps & MMC_CAP_4_BIT_DATA)
>                 err = sdio_enable_4bit_bus(card);
> -               if (err > 0) {
> -                       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> -                       err = 0;
> -               }
> -       }
>
>         /* Set the driver strength for the card */
>         sdio_select_driver_type(card);
> @@ -803,9 +801,7 @@ try_again:
>                  * Switch to wider bus (if supported).
>                  */
>                 err = sdio_enable_4bit_bus(card);
> -               if (err > 0)
> -                       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
> -               else if (err)
> +               if (err)
>                         goto remove;
>         }
>  finish:
> @@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
>         } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
>                 /* We may have switched to 1-bit mode during suspend */
>                 err = sdio_enable_4bit_bus(host->card);
> -               if (err > 0) {
> -                       mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
> -                       err = 0;
> -               }
>         }
>
>         if (!err && host->sdio_irqs) {
>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
  2015-02-24  2:42 [PATCH 0/4] Switch to 1-bit mode SDIO before disabling clocks NeilBrown
@ 2015-02-24  2:42 ` NeilBrown
  2015-03-23  9:34   ` Ulf Hansson
  0 siblings, 1 reply; 9+ messages in thread
From: NeilBrown @ 2015-02-24  2:42 UTC (permalink / raw)
  To: Tony Lindgren, Ulf Hansson
  Cc: Andreas Fenkart, linux-mmc, lkml, GTA04 owners, NeilBrown, linux-omap

Every call to sdio_enable_4bit_bus is followed (on success) but a call
to mmc_set_bus_width().

To simplify the code, include those calls directly in
sdio_enable_4bit_bus().

Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mmc/core/sdio.c |   32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ce6cc47206b0..5bc6c7dbbd60 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
 	int err;
 
 	if (card->type == MMC_TYPE_SDIO)
-		return sdio_enable_wide(card);
-
-	if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
-		(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
+		err = sdio_enable_wide(card);
+	else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
+		 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
 		err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
 		if (err)
 			return err;
+		err = sdio_enable_wide(card);
+		if (err <= 0)
+			mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
 	} else
 		return 0;
 
-	err = sdio_enable_wide(card);
-	if (err <= 0)
-		mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
+	if (err > 0) {
+		mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
+		err = 0;
+	}
 
 	return err;
 }
@@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
 	/*
 	 * Switch to wider bus (if supported).
 	 */
-	if (card->host->caps & MMC_CAP_4_BIT_DATA) {
+	if (card->host->caps & MMC_CAP_4_BIT_DATA)
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0) {
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
-	}
 
 	/* Set the driver strength for the card */
 	sdio_select_driver_type(card);
@@ -803,9 +801,7 @@ try_again:
 		 * Switch to wider bus (if supported).
 		 */
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0)
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-		else if (err)
+		if (err)
 			goto remove;
 	}
 finish:
@@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
 	} else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
 		/* We may have switched to 1-bit mode during suspend */
 		err = sdio_enable_4bit_bus(host->card);
-		if (err > 0) {
-			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
 	}
 
 	if (!err && host->sdio_irqs) {



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus.
  2015-01-30 19:05 [PATCH-v2 0/4] mmc: switch to 1-bit mode which stopping clocks NeilBrown
@ 2015-01-30 19:05 ` NeilBrown
  0 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2015-01-30 19:05 UTC (permalink / raw)
  To: Tony Lindgren, Ulf Hansson
  Cc: Andreas Fenkart, linux-mmc, linux-kernel, GTA04 owners,
	NeilBrown, linux-omap

Every call to sdio_enable_4bit_bus is followed (on success) but a call
to mmc_set_bus_width().

To simplify the code, include those calls directly in
sdio_enable_4bit_bus().

Signed-off-by: NeilBrown <neil@brown.name>
---
 drivers/mmc/core/sdio.c |   32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ce6cc47206b0..5bc6c7dbbd60 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -293,19 +293,22 @@ static int sdio_enable_4bit_bus(struct mmc_card *card)
 	int err;
 
 	if (card->type == MMC_TYPE_SDIO)
-		return sdio_enable_wide(card);
-
-	if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
-		(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
+		err = sdio_enable_wide(card);
+	else if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
+		 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
 		err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
 		if (err)
 			return err;
+		err = sdio_enable_wide(card);
+		if (err <= 0)
+			mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
 	} else
 		return 0;
 
-	err = sdio_enable_wide(card);
-	if (err <= 0)
-		mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
+	if (err > 0) {
+		mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
+		err = 0;
+	}
 
 	return err;
 }
@@ -547,13 +550,8 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
 	/*
 	 * Switch to wider bus (if supported).
 	 */
-	if (card->host->caps & MMC_CAP_4_BIT_DATA) {
+	if (card->host->caps & MMC_CAP_4_BIT_DATA)
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0) {
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
-	}
 
 	/* Set the driver strength for the card */
 	sdio_select_driver_type(card);
@@ -803,9 +801,7 @@ try_again:
 		 * Switch to wider bus (if supported).
 		 */
 		err = sdio_enable_4bit_bus(card);
-		if (err > 0)
-			mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
-		else if (err)
+		if (err)
 			goto remove;
 	}
 finish:
@@ -983,10 +979,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
 	} else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
 		/* We may have switched to 1-bit mode during suspend */
 		err = sdio_enable_4bit_bus(host->card);
-		if (err > 0) {
-			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
-			err = 0;
-		}
 	}
 
 	if (!err && host->sdio_irqs) {



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-03-24 21:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-24 20:56 [PATCH/RFC 0/4] Use runtime-pm to switch sdio to 1-bit when idle NeilBrown
2015-03-24 20:56 ` [PATCH 2/4] mmc/core: add pm_runtime tracking to mmc_host devices NeilBrown
2015-03-24 20:56 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
2015-03-24 21:18   ` Ulf Hansson
2015-03-24 20:56 ` [PATCH 3/4] mmc/sdio: keep device awake when interrupts expected in 4bit mode NeilBrown
2015-03-24 20:56 ` [PATCH 4/4] mmc/host: use runtime_pm to switch to 1-bit mode NeilBrown
  -- strict thread matches above, loose matches on Subject: below --
2015-02-24  2:42 [PATCH 0/4] Switch to 1-bit mode SDIO before disabling clocks NeilBrown
2015-02-24  2:42 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown
2015-03-23  9:34   ` Ulf Hansson
2015-01-30 19:05 [PATCH-v2 0/4] mmc: switch to 1-bit mode which stopping clocks NeilBrown
2015-01-30 19:05 ` [PATCH 1/4] mmc: core: fold mmc_set_bus_width calls into sdio_enable_4bit_bus NeilBrown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.