linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] spi: Fix "not ready" timeout after write in at25.
@ 2009-07-03  7:10 Sebastian Heutling
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Heutling @ 2009-07-03  7:10 UTC (permalink / raw)
  To: david-b-yBeKhBN/0LDR7s880joybQ
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sebastian Heutling

Under certain circumstances msleep(1) within the loop, which waits
for the EEPROM to be finished, might take longer than the timeout.
On the next loop the status register might now return to be ready
and therefore the loop finishes. The following check now tests if
a timeout occurred and if so returns an error although the device
reported to have finished.
This fix replaces testing the occurrence of the timeout by testing
the "not ready" bit in the status register.
The patch is against 2.6.29.2.

Signed-off-by: Sebastian Heutling <heutling-U9zb0o/1OQCELgA04lAiVw@public.gmane.org> 

---
 drivers/misc/eeprom/at25.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 290dbe9..ea83604 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -160,6 +160,7 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
 	bounce[0] = AT25_WRITE;
 	mutex_lock(&at25->lock);
 	do {
+		int	sr;
 		unsigned long	timeout, retries;
 		unsigned	segment;
 		unsigned	offset = (unsigned) off;
@@ -205,7 +206,6 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
 		timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
 		retries = 0;
 		do {
-			int	sr;
 
 			sr = spi_w8r8(at25->spi, AT25_RDSR);
 			if (sr < 0 || (sr & AT25_SR_nRDY)) {
@@ -219,7 +219,7 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
 				break;
 		} while (retries++ < 3 || time_before_eq(jiffies, timeout));
 
-		if (time_after(jiffies, timeout)) {
+		if ((sr < 0) || (sr & AT25_SR_nRDY)) {
 			dev_err(&at25->spi->dev,
 				"write %d bytes offset %d, "
 				"timeout after %u msecs\n",
-- 
1.6.3.2


------------------------------------------------------------------------------

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

* Re: [PATCH 1/1] spi: Fix "not ready" timeout after write in at25
       [not found] ` <4A2CE07F.2060302-U9zb0o/1OQCELgA04lAiVw@public.gmane.org>
@ 2009-07-03  1:48   ` David Brownell
  0 siblings, 0 replies; 3+ messages in thread
From: David Brownell @ 2009-07-03  1:48 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sebastian Heutling

On Monday 08 June 2009, Sebastian Heutling wrote:
> Under certain circumstances msleep(1) within the loop, which waits
> for the EEPROM to be finished, might take longer than the timeout.
> On the next loop the status register might return to be ready and 
> therefore the loop finishes. The following check now tests if
> a timeout occurred and if so returns an error although the device
> reported to be finished.
> This fix replaces testing the occurrence of the timeout by testing
> the "not ready" bit in the status register.
> The patch is against 2.6.29.2.

This got badly mangled by your mailer.  Care to re-send?

> 
> Signed-off-by: Sebastian Heutling <heutling-U9zb0o/1OQCELgA04lAiVw@public.gmane.org>
> 
> ---
>   drivers/misc/eeprom/at25.c |    4 ++--
>   1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
> index 290dbe9..ea83604 100644
> --- a/drivers/misc/eeprom/at25.c
> +++ b/drivers/misc/eeprom/at25.c
> @@ -160,6 +160,7 @@ at25_ee_write(struct at25_data *at25, char *buf, 
> loff_t off, size_t count)
>   	bounce[0] = AT25_WRITE;
>   	mutex_lock(&at25->lock);
>   	do {
> +		int	sr;
>   		unsigned long	timeout, retries;
>   		unsigned	segment;
>   		unsigned	offset = (unsigned) off;
> @@ -205,7 +206,6 @@ at25_ee_write(struct at25_data *at25, char *buf, 
> loff_t off, size_t count)
>   		timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
>   		retries = 0;
>   		do {
> -			int	sr;
>    			sr = spi_w8r8(at25->spi, AT25_RDSR);
>   			if (sr < 0 || (sr & AT25_SR_nRDY)) {
> @@ -219,7 +219,7 @@ at25_ee_write(struct at25_data *at25, char *buf, 
> loff_t off, size_t count)
>   				break;
>   		} while (retries++ < 3 || time_before_eq(jiffies, timeout));
>   -		if (time_after(jiffies, timeout)) {
> +		if ((sr < 0) || (sr & AT25_SR_nRDY)) {
>   			dev_err(&at25->spi->dev,
>   				"write %d bytes offset %d, "
>   				"timeout after %u msecs\n",
> -- 
> 1.6.3.2

------------------------------------------------------------------------------

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

* [PATCH 1/1] spi: Fix "not ready" timeout after write in at25
@ 2009-06-08  9:57 Sebastian Heutling
       [not found] ` <4A2CE07F.2060302-U9zb0o/1OQCELgA04lAiVw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Heutling @ 2009-06-08  9:57 UTC (permalink / raw)
  To: dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Under certain circumstances msleep(1) within the loop, which waits
for the EEPROM to be finished, might take longer than the timeout.
On the next loop the status register might return to be ready and 
therefore the loop finishes. The following check now tests if
a timeout occurred and if so returns an error although the device
reported to be finished.
This fix replaces testing the occurrence of the timeout by testing
the "not ready" bit in the status register.
The patch is against 2.6.29.2.

Signed-off-by: Sebastian Heutling <heutling-U9zb0o/1OQCELgA04lAiVw@public.gmane.org>

---
  drivers/misc/eeprom/at25.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 290dbe9..ea83604 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -160,6 +160,7 @@ at25_ee_write(struct at25_data *at25, char *buf, 
loff_t off, size_t count)
  	bounce[0] = AT25_WRITE;
  	mutex_lock(&at25->lock);
  	do {
+		int	sr;
  		unsigned long	timeout, retries;
  		unsigned	segment;
  		unsigned	offset = (unsigned) off;
@@ -205,7 +206,6 @@ at25_ee_write(struct at25_data *at25, char *buf, 
loff_t off, size_t count)
  		timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
  		retries = 0;
  		do {
-			int	sr;
   			sr = spi_w8r8(at25->spi, AT25_RDSR);
  			if (sr < 0 || (sr & AT25_SR_nRDY)) {
@@ -219,7 +219,7 @@ at25_ee_write(struct at25_data *at25, char *buf, 
loff_t off, size_t count)
  				break;
  		} while (retries++ < 3 || time_before_eq(jiffies, timeout));
  -		if (time_after(jiffies, timeout)) {
+		if ((sr < 0) || (sr & AT25_SR_nRDY)) {
  			dev_err(&at25->spi->dev,
  				"write %d bytes offset %d, "
  				"timeout after %u msecs\n",
-- 
1.6.3.2


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get

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

end of thread, other threads:[~2009-07-03  7:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-03  7:10 [PATCH 1/1] spi: Fix "not ready" timeout after write in at25 Sebastian Heutling
  -- strict thread matches above, loose matches on Subject: below --
2009-06-08  9:57 Sebastian Heutling
     [not found] ` <4A2CE07F.2060302-U9zb0o/1OQCELgA04lAiVw@public.gmane.org>
2009-07-03  1:48   ` David Brownell

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