pxa3xx: fix ns2cycle equation

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed Aug 18 08:59:01 EDT 2010


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=93b352fce679945845664b56b0c3afbd655a7a12
Commit:     93b352fce679945845664b56b0c3afbd655a7a12
Parent:     da5cabf80e2433131bf0ed8993abc0f7ea618c73
Author:     Axel Lin <axel.lin at gmail.com>
AuthorDate: Mon Aug 16 16:09:09 2010 +0800
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Wed Aug 18 13:32:47 2010 +0100

    pxa3xx: fix ns2cycle equation
    
    Test on a PXA310 platform with Samsung K9F2G08X0B NAND flash,
    with tCH=5 and clk is 156MHz, ns2cycle(5, 156000000) returns -1.
    
    ns2cycle returns negtive value will break NDTR0_tXX macros.
    
    After checking the commit log, I found the problem is introduced by
    commit 5b0d4d7c8a67c5ba3d35e6ceb0c5530cc6846db7
    "[MTD] [NAND] pxa3xx: convert from ns to clock ticks more accurately"
    
    To get num of clock cycles, we use below equation:
    num of clock cycles = time (ns) / one clock cycle (ns) + 1
    We need to add 1 cycle here because integer division will truncate the result.
    It is possible the developers set the Min values in SPEC for timing settings.
    Thus the truncate may cause problem, and it is safe to add an extra cycle here.
    
    The various fields in NDTR{01} are in units of clock ticks minus one,
    thus we should subtract 1 cycle then.
    
    Thus the correct equation should be:
    num of clock cycles = time (ns) / one clock cycle (ns) + 1 - 1
                        = time (ns) / one clock cycle (ns)
    
    Signed-off-by: Axel Lin <axel.lin at gmail.com>
    Signed-off-by: Lei Wen <leiwen at marvell.com>
    Acked-by: Eric Miao <eric.y.miao at gmail.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
    Cc: stable at kernel.org
---
 drivers/mtd/nand/pxa3xx_nand.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index e02fa4f..4d89f37 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -363,7 +363,7 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
 #define tAR_NDTR1(r)	(((r) >> 0) & 0xf)
 
 /* convert nano-seconds to nand flash controller clock cycles */
-#define ns2cycle(ns, clk)	(int)(((ns) * (clk / 1000000) / 1000) - 1)
+#define ns2cycle(ns, clk)	(int)((ns) * (clk / 1000000) / 1000)
 
 /* convert nand flash controller clock cycles to nano-seconds */
 #define cycle2ns(c, clk)	((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))



More information about the linux-mtd-cvs mailing list