public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] nand_wait_ready() timeout scaling
@ 2008-04-30 19:22 Andrew E. Mileski
  2008-04-30 19:46 ` Andrew E. Mileski
  2008-07-14 20:32 ` Andrew E. Mileski
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew E. Mileski @ 2008-04-30 19:22 UTC (permalink / raw)
  To: linux-mtd

The nand_wait_ready() timeout was hardcoded to 2 jiffies, which does not
scale with the system timer frequency.  Using a guess of a 250 Hz system
timer frequency, I believe the timeout was meant to be 8 ms.  This patch
sets an 8 ms timeout that scales with the system timer frequency.

Tested with a 1000 Hz system timer frequency and with a device requiring
at least a 3 ms timeout.

Signed-off-by: Andrew E. Mileski <andrewm@isoar.ca>
--

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ba1bdf7..ef7e1c1 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -415,13 +415,13 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
 }
 
 /*
- * Wait for the ready pin, after a command
- * The timeout is catched later.
+ * Wait 8 ms for the ready pin, after a command
+ * The timeout is caught later.
  */
 void nand_wait_ready(struct mtd_info *mtd)
 {
 	struct nand_chip *chip = mtd->priv;
-	unsigned long timeo = jiffies + 2;
+	unsigned long timeo = jiffies + (HZ * 8) / 1000;
 
 	led_trigger_event(nand_led_trigger, LED_FULL);
 	/* wait until command is processed or timeout occures */

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

* Re: [PATCH] nand_wait_ready() timeout scaling
  2008-04-30 19:22 [PATCH] nand_wait_ready() timeout scaling Andrew E. Mileski
@ 2008-04-30 19:46 ` Andrew E. Mileski
  2008-04-30 20:19   ` Trent Piepho
  2008-07-14 20:32 ` Andrew E. Mileski
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew E. Mileski @ 2008-04-30 19:46 UTC (permalink / raw)
  To: linux-mtd

Andrew E. Mileski wrote:
> The nand_wait_ready() timeout was hardcoded to 2 jiffies, which does not
> scale with the system timer frequency.  Using a guess of a 250 Hz system
> timer frequency, I believe the timeout was meant to be 8 ms.  This patch
> sets an 8 ms timeout that scales with the system timer frequency.
> 
> Tested with a 1000 Hz system timer frequency and with a device requiring
> at least a 3 ms timeout.

Just realized that 100 Hz systems would have a problem with this patch
since (100 * 8) / 1000 = 0.  Guess the simple solution is to make the 
timeout 10 ms.

-- 
Andrew E. Mileski

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

* Re: [PATCH] nand_wait_ready() timeout scaling
  2008-04-30 19:46 ` Andrew E. Mileski
@ 2008-04-30 20:19   ` Trent Piepho
  2008-04-30 20:55     ` Andrew E. Mileski
  0 siblings, 1 reply; 5+ messages in thread
From: Trent Piepho @ 2008-04-30 20:19 UTC (permalink / raw)
  To: Andrew E. Mileski; +Cc: linux-mtd

On Wed, 30 Apr 2008, Andrew E. Mileski wrote:
> Andrew E. Mileski wrote:
>> The nand_wait_ready() timeout was hardcoded to 2 jiffies, which does not
>> scale with the system timer frequency.  Using a guess of a 250 Hz system
>> timer frequency, I believe the timeout was meant to be 8 ms.  This patch
>> sets an 8 ms timeout that scales with the system timer frequency.
>>
>> Tested with a 1000 Hz system timer frequency and with a device requiring
>> at least a 3 ms timeout.
>
> Just realized that 100 Hz systems would have a problem with this patch
> since (100 * 8) / 1000 = 0.  Guess the simple solution is to make the
> timeout 10 ms.

msecs_to_jiffies() is what you want to use.

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

* Re: [PATCH] nand_wait_ready() timeout scaling
  2008-04-30 20:19   ` Trent Piepho
@ 2008-04-30 20:55     ` Andrew E. Mileski
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew E. Mileski @ 2008-04-30 20:55 UTC (permalink / raw)
  To: linux-mtd

Trent Piepho wrote:
> Andrew E. Mileski wrote:
>> Just realized that 100 Hz systems would have a problem with this patch
>> since (100 * 8) / 1000 = 0.  Guess the simple solution is to make the
>> timeout 10 ms.
> 
> msecs_to_jiffies() is what you want to use.

Thanks.  Guess all similar calculations in nand_base.c file should be 
changed to that too.

-- 
Andrew E. Mileski

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

* Re: [PATCH] nand_wait_ready() timeout scaling
  2008-04-30 19:22 [PATCH] nand_wait_ready() timeout scaling Andrew E. Mileski
  2008-04-30 19:46 ` Andrew E. Mileski
@ 2008-07-14 20:32 ` Andrew E. Mileski
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew E. Mileski @ 2008-07-14 20:32 UTC (permalink / raw)
  To: linux-mtd

Andrew E. Mileski wrote:
> The nand_wait_ready() timeout was hardcoded to 2 jiffies, which does not
> scale with the system timer frequency.  Using a guess of a 250 Hz system
> timer frequency, I believe the timeout was meant to be 8 ms.

Just a heads-up for those similarly banging their heads trying to get
NAND to work for them, that I think I've also found 2 instances of a
bug:  not waiting tWB before calling nand_wait_ready() in nand_base.c

   nand_do_read_ops()
   nand_do_read_oob()

I almost think the ndelay(tWB) should be in nand_wait_ready(), but I'm
still playing with it.

-- 
Andrew E. Mileski

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

end of thread, other threads:[~2008-07-14 20:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-30 19:22 [PATCH] nand_wait_ready() timeout scaling Andrew E. Mileski
2008-04-30 19:46 ` Andrew E. Mileski
2008-04-30 20:19   ` Trent Piepho
2008-04-30 20:55     ` Andrew E. Mileski
2008-07-14 20:32 ` Andrew E. Mileski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox