linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: change mmc_delay() to use usleep_range()
@ 2012-01-13 15:09 Dmitry Antipov
  2012-01-13 21:38 ` Aaro Koskinen
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2012-01-13 15:09 UTC (permalink / raw)
  To: Chris Ball; +Cc: patches, linux-mmc, linux-kernel, Dmitry Antipov

Use the usleep_range() to simplify mmc_delay() and give some more
accuracy to it - but with an exception of mmc_card_sleepawake():
since sleep/awake timeout varies in a wide range, different
delay methods should be used.

Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>
---
 drivers/mmc/core/core.h    |    8 ++------
 drivers/mmc/core/mmc_ops.c |   12 +++++++++---
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 14664f1..a77851e 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -47,12 +47,8 @@ void mmc_power_off(struct mmc_host *host);
 
 static inline void mmc_delay(unsigned int ms)
 {
-	if (ms < 1000 / HZ) {
-		cond_resched();
-		mdelay(ms);
-	} else {
-		msleep(ms);
-	}
+	unsigned long us = ms * USEC_PER_MSEC;
+	usleep_range(us, us + 1000);
 }
 
 void mmc_rescan(struct work_struct *work);
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 4d41fa9..38d53ac 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -82,9 +82,15 @@ int mmc_card_sleepawake(struct mmc_host *host, int sleep)
 	 * SEND_STATUS command to poll the status because that command (and most
 	 * others) is invalid while the card sleeps.
 	 */
-	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
-		mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000));
-
+	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) {
+		/* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms
+		   range. Round it up to 1us and use an appropriate delay method. */
+		unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10);
+		if (us < 10)
+			udelay(us);
+		else
+			usleep_range(us, us + 100);
+	}
 	if (!sleep)
 		err = mmc_select_card(card);
 
-- 
1.7.7.5


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

* Re: [PATCH] mmc: change mmc_delay() to use usleep_range()
  2012-01-13 15:09 Dmitry Antipov
@ 2012-01-13 21:38 ` Aaro Koskinen
  0 siblings, 0 replies; 5+ messages in thread
From: Aaro Koskinen @ 2012-01-13 21:38 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Chris Ball, patches, linux-mmc, linux-kernel

Hi,

On Fri, 13 Jan 2012, Dmitry Antipov wrote:
> Use the usleep_range() to simplify mmc_delay() and give some more
> accuracy to it - but with an exception of mmc_card_sleepawake():
> since sleep/awake timeout varies in a wide range, different
> delay methods should be used.
>
> Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>

[...]

> +	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) {
> +		/* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms
> +		   range. Round it up to 1us and use an appropriate delay method. */
> +		unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10);
> +		if (us < 10)
> +			udelay(us);
> +		else
> +			usleep_range(us, us + 100);
> +	}

I think this part of the patch is over-engineered. What difference
does it make in practice if you round it up to a bigger value so that
usleep_range() makes always sense? The S/A timeout defines the max time
the transition can take, it's not wrong to wait a bit longer. Also note
that udelay() is not accurate so you need to add some margin anyway.

A.

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

* [PATCH] mmc: change mmc_delay() to use usleep_range()
@ 2012-01-16  6:43 Dmitry Antipov
  2012-01-17  7:29 ` Adrian Hunter
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2012-01-16  6:43 UTC (permalink / raw)
  To: Chris Ball; +Cc: patches, linux-mmc, linux-kernel, Dmitry Antipov

Use the usleep_range() to simplify mmc_delay() and give some more
accuracy to it - but with an exception of mmc_card_sleepawake():
for the hosts with very small (<100us) sleep/awake timeout, it's
value is rounded up to 100us so usleep_range() always makes sense.
---
 drivers/mmc/core/core.h    |    8 ++------
 drivers/mmc/core/mmc_ops.c |    9 ++++++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 3bdafbc..fbd2cba 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -48,12 +48,8 @@ void mmc_power_off(struct mmc_host *host);
 
 static inline void mmc_delay(unsigned int ms)
 {
-	if (ms < 1000 / HZ) {
-		cond_resched();
-		mdelay(ms);
-	} else {
-		msleep(ms);
-	}
+	unsigned long us = ms * USEC_PER_MSEC;
+	usleep_range(us, us + 1000);
 }
 
 void mmc_rescan(struct work_struct *work);
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 4d41fa9..457443a 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -82,9 +82,12 @@ int mmc_card_sleepawake(struct mmc_host *host, int sleep)
 	 * SEND_STATUS command to poll the status because that command (and most
 	 * others) is invalid while the card sleeps.
 	 */
-	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
-		mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000));
-
+	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) {
+		/* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms
+		   range, which is rounded it up to 100us here. */
+		unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 1000);
+		usleep_range(us, us + 100);
+	}
 	if (!sleep)
 		err = mmc_select_card(card);
 
-- 
1.7.7.5


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

* Re: [PATCH] mmc: change mmc_delay() to use usleep_range()
  2012-01-16  6:43 [PATCH] mmc: change mmc_delay() to use usleep_range() Dmitry Antipov
@ 2012-01-17  7:29 ` Adrian Hunter
  2012-01-17  7:46   ` Adrian Hunter
  0 siblings, 1 reply; 5+ messages in thread
From: Adrian Hunter @ 2012-01-17  7:29 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Chris Ball, patches, linux-mmc, linux-kernel

On 16/01/12 08:43, Dmitry Antipov wrote:
> Use the usleep_range() to simplify mmc_delay() and give some more
> accuracy to it - but with an exception of mmc_card_sleepawake():
> for the hosts with very small (<100us) sleep/awake timeout, it's
> value is rounded up to 100us so usleep_range() always makes sense.
> ---
>  drivers/mmc/core/core.h    |    8 ++------
>  drivers/mmc/core/mmc_ops.c |    9 ++++++---
>  2 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
> index 3bdafbc..fbd2cba 100644
> --- a/drivers/mmc/core/core.h
> +++ b/drivers/mmc/core/core.h
> @@ -48,12 +48,8 @@ void mmc_power_off(struct mmc_host *host);
>  
>  static inline void mmc_delay(unsigned int ms)
>  {
> -	if (ms < 1000 / HZ) {
> -		cond_resched();
> -		mdelay(ms);
> -	} else {
> -		msleep(ms);
> -	}
> +	unsigned long us = ms * USEC_PER_MSEC;
> +	usleep_range(us, us + 1000);
>  }
>  
>  void mmc_rescan(struct work_struct *work);
> diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
> index 4d41fa9..457443a 100644
> --- a/drivers/mmc/core/mmc_ops.c
> +++ b/drivers/mmc/core/mmc_ops.c
> @@ -82,9 +82,12 @@ int mmc_card_sleepawake(struct mmc_host *host, int sleep)
>  	 * SEND_STATUS command to poll the status because that command (and most
>  	 * others) is invalid while the card sleeps.
>  	 */
> -	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
> -		mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000));
> -
> +	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) {
> +		/* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms
> +		   range, which is rounded it up to 100us here. */
> +		unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 1000);

The divisor has changed from 10000 to 1000 but the change is from ms to us,
so it ought to be 3 zeros different - unless it is a bug fix (which should
be a separate patch)?


> +		usleep_range(us, us + 100);
> +	}
>  	if (!sleep)
>  		err = mmc_select_card(card);
>  

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

* Re: [PATCH] mmc: change mmc_delay() to use usleep_range()
  2012-01-17  7:29 ` Adrian Hunter
@ 2012-01-17  7:46   ` Adrian Hunter
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Hunter @ 2012-01-17  7:46 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Dmitry Antipov, Chris Ball, patches, linux-mmc, linux-kernel

On 17/01/12 09:29, Adrian Hunter wrote:
> On 16/01/12 08:43, Dmitry Antipov wrote:
>> Use the usleep_range() to simplify mmc_delay() and give some more
>> accuracy to it - but with an exception of mmc_card_sleepawake():
>> for the hosts with very small (<100us) sleep/awake timeout, it's
>> value is rounded up to 100us so usleep_range() always makes sense.
>> ---
>>  drivers/mmc/core/core.h    |    8 ++------
>>  drivers/mmc/core/mmc_ops.c |    9 ++++++---
>>  2 files changed, 8 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
>> index 3bdafbc..fbd2cba 100644
>> --- a/drivers/mmc/core/core.h
>> +++ b/drivers/mmc/core/core.h
>> @@ -48,12 +48,8 @@ void mmc_power_off(struct mmc_host *host);
>>  
>>  static inline void mmc_delay(unsigned int ms)
>>  {
>> -	if (ms < 1000 / HZ) {
>> -		cond_resched();
>> -		mdelay(ms);
>> -	} else {
>> -		msleep(ms);
>> -	}
>> +	unsigned long us = ms * USEC_PER_MSEC;

A blank line here would be nice

>> +	usleep_range(us, us + 1000);
>>  }
>>  
>>  void mmc_rescan(struct work_struct *work);
>> diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
>> index 4d41fa9..457443a 100644
>> --- a/drivers/mmc/core/mmc_ops.c
>> +++ b/drivers/mmc/core/mmc_ops.c
>> @@ -82,9 +82,12 @@ int mmc_card_sleepawake(struct mmc_host *host, int sleep)
>>  	 * SEND_STATUS command to poll the status because that command (and most
>>  	 * others) is invalid while the card sleeps.
>>  	 */
>> -	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY))
>> -		mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000));
>> -
>> +	if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) {
>> +		/* JEDEC MMCA 4.41 specifies the timeout value is in 200ns..838.86ms
>> +		   range, which is rounded it up to 100us here. */
>> +		unsigned long us = DIV_ROUND_UP(card->ext_csd.sa_timeout, 1000);
> 
> The divisor has changed from 10000 to 1000 but the change is from ms to us,
> so it ought to be 3 zeros different - unless it is a bug fix (which should
> be a separate patch)?
> 

In fact, why not just drop this part of the patch and leave it as mmc_delay?

>> +		usleep_range(us, us + 100);
>> +	}
>>  	if (!sleep)
>>  		err = mmc_select_card(card);
>>  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


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

end of thread, other threads:[~2012-01-17  7:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-16  6:43 [PATCH] mmc: change mmc_delay() to use usleep_range() Dmitry Antipov
2012-01-17  7:29 ` Adrian Hunter
2012-01-17  7:46   ` Adrian Hunter
  -- strict thread matches above, loose matches on Subject: below --
2012-01-13 15:09 Dmitry Antipov
2012-01-13 21:38 ` Aaro Koskinen

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