Re: [U-Boot] [PATCH v3] NAND: add support for reading ONFI page table

2011-02-25 Thread Florian Fainelli
Hello Scott,

(sorry for the lag in answering)

On Tuesday 15 February 2011 00:46:07 Scott Wood wrote:
 On Mon, 14 Feb 2011 16:48:01 +0100
 
 Florian Fainelli flor...@openwrt.org wrote:
  From: Florian Fainelli flor...@openwrt.org
  
  This patch adds support for reading an ONFI page parameter from a NAND
  device supporting it. If this is the case, struct nand_chip onfi_version
  member contains the supported ONFI version, 0 otherwise.
  
  This allows NAND drivers past nand_scan_ident to set the best timings for
  the NAND chip.
  
  Signed-off-by: Florian Fainelli flor...@openwrt.org
  ---
  Patch against your 'next' branch
 
 The 'next' branch is old, since I haven't pushed anything to it yet this
 cycle.  Base it on Wolfgang's 'next'.
 
  Changes since v1:
  - ifdef out ONFI detection code around CONFIG_SYS_NAND_ONFI_DETECTION
  - removed bogus comment
  - fixed busw variable usage
  - move non-ONFI detection code to its own function
  - fixed stylistic issues spotted by Scott
  
  Changes since v2:
  - reduce lenght of some lines down to 80 columns
  - change chip-options consistently wrt to ONFI detected or not
  - removed extra spaces
  
  diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
  index 5239c1f..7becb99 100644
  --- a/drivers/mtd/nand/nand_base.c
  +++ b/drivers/mtd/nand/nand_base.c
  @@ -2409,15 +2409,137 @@ static void nand_set_defaults(struct nand_chip
  *chip, int busw)
  
  chip-controller = chip-hwcontrol;
   
   }
  
  +#ifdef CONFIG_SYS_NAND_ONFI_DETECTION
  +static u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
  +{
  +   int i;
  +
  +   while (len--) {
  +   crc ^= *p++  8;
  +   for (i = 0; i  8; i++)
  +   crc = (crc  1) ^ ((crc  0x8000) ? 0x8005 : 0);
  +   }
  +
  +   return crc;
  +}
 
 Is this different from what's in lib/crc16.c (other than appearing to have
 made a different speed/size tradeoff)?

Yes it is a different version of the CRC16 function.

 
  +#define ONFI_CRC_BASE  0x4F4E
 
 Is this ONFI-specific, or standard for crc16?
 
  +
  +/*
  + * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0
  otherwise + */
  +static int nand_flash_detect_onfi(struct mtd_info *mtd,
  +   struct nand_chip *chip,
  +   int *busw)
  +{
 
 [snip]
 
  +   chip-options = ~NAND_CHIPOPTIONS_MSK;
  +   chip-options |= NAND_NO_READRDY  NAND_CHIPOPTIONS_MSK;
 
 Won't this get overwritten by this later?

It will, thanks for spotting.
--
Florian
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v3] NAND: add support for reading ONFI page table

2011-02-14 Thread Florian Fainelli
From: Florian Fainelli flor...@openwrt.org

This patch adds support for reading an ONFI page parameter from a NAND
device supporting it. If this is the case, struct nand_chip onfi_version
member contains the supported ONFI version, 0 otherwise.

This allows NAND drivers past nand_scan_ident to set the best timings for the
NAND chip.

Signed-off-by: Florian Fainelli flor...@openwrt.org
---
Patch against your 'next' branch

Changes since v1:
- ifdef out ONFI detection code around CONFIG_SYS_NAND_ONFI_DETECTION
- removed bogus comment
- fixed busw variable usage
- move non-ONFI detection code to its own function
- fixed stylistic issues spotted by Scott

Changes since v2:
- reduce lenght of some lines down to 80 columns
- change chip-options consistently wrt to ONFI detected or not
- removed extra spaces

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5239c1f..7becb99 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2409,15 +2409,137 @@ static void nand_set_defaults(struct nand_chip *chip, 
int busw)
chip-controller = chip-hwcontrol;
 }

+#ifdef CONFIG_SYS_NAND_ONFI_DETECTION
+static u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
+{
+   int i;
+
+   while (len--) {
+   crc ^= *p++  8;
+   for (i = 0; i  8; i++)
+   crc = (crc  1) ^ ((crc  0x8000) ? 0x8005 : 0);
+   }
+
+   return crc;
+}
+
+/*
+ * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise
+ */
+static int nand_flash_detect_onfi(struct mtd_info *mtd,
+   struct nand_chip *chip,
+   int *busw)
+{
+   struct nand_onfi_params *p = chip-onfi_params;
+   int i;
+   int val;
+
+   chip-cmdfunc(mtd, NAND_CMD_READID, 0x20, -1);
+   if (chip-read_byte(mtd) != 'O' || chip-read_byte(mtd) != 'N' ||
+   chip-read_byte(mtd) != 'F' || chip-read_byte(mtd) != 'I')
+   return 0;
+
+   printk(KERN_INFO ONFI flash detected\n);
+   chip-cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
+   for (i = 0; i  3; i++) {
+   chip-read_buf(mtd, (uint8_t *)p, sizeof(*p));
+   if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) ==
+   le16_to_cpu(p-crc)) {
+   printk(KERN_INFO ONFI param page %d valid\n, i);
+   break;
+   }
+   }
+
+   if (i == 3)
+   return 0;
+
+   /* check version */
+   val = le16_to_cpu(p-revision);
+   if (val == 1 || val  (1  4)) {
+   printk(KERN_INFO %s: unsupported ONFI 
+   version: %d\n, __func__, val);
+   return 0;
+   }
+
+   if (val  (1  4))
+   chip-onfi_version = 22;
+   else if (val  (1  3))
+   chip-onfi_version = 21;
+   else if (val  (1  2))
+   chip-onfi_version = 20;
+   else
+   chip-onfi_version = 10;
+
+   if (!mtd-name)
+   mtd-name = p-model;
+
+   mtd-writesize = le32_to_cpu(p-byte_per_page);
+   mtd-erasesize = le32_to_cpu(p-pages_per_block) * mtd-writesize;
+   mtd-oobsize = le16_to_cpu(p-spare_bytes_per_page);
+   chip-chipsize = le32_to_cpu(p-blocks_per_lun) * mtd-erasesize;
+   *busw = 0;
+   if (le16_to_cpu(p-features)  1)
+   *busw = NAND_BUSWIDTH_16;
+
+   chip-options = ~NAND_CHIPOPTIONS_MSK;
+   chip-options |= NAND_NO_READRDY  NAND_CHIPOPTIONS_MSK;
+
+   return 1;
+}
+#else
+static inline int nand_flash_detect_onfi(struct mtd_info *mtd,
+   struct nand_chip *chip,
+   int *busw)
+{
+   return 0;
+}
+#endif
+
+static void nand_flash_detect_non_onfi(struct mtd_info *mtd,
+   struct nand_chip *chip,
+   const struct nand_flash_dev *type,
+   int *busw)
+{
+   /* Newer devices have all the information in additional id bytes */
+   if (!type-pagesize) {
+   int extid;
+   /* The 3rd id byte holds MLC / multichip data */
+   chip-cellinfo = chip-read_byte(mtd);
+   /* The 4th id byte is the important one */
+   extid = chip-read_byte(mtd);
+   /* Calc pagesize */
+   mtd-writesize = 1024  (extid  0x3);
+   extid = 2;
+   /* Calc oobsize */
+   mtd-oobsize = (8  (extid  0x01)) * (mtd-writesize  9);
+   extid = 2;
+   /* Calc blocksize. Blocksize is multiples of 64KiB */
+   mtd-erasesize = (64 * 1024)  (extid  0x03);
+   extid = 2;
+   /* Get buswidth information */
+   *busw = (extid  0x01) ? NAND_BUSWIDTH_16 : 0;
+
+   } else {
+  

Re: [U-Boot] [PATCH v3] NAND: add support for reading ONFI page table

2011-02-14 Thread Scott Wood
On Mon, 14 Feb 2011 16:48:01 +0100
Florian Fainelli flor...@openwrt.org wrote:

 From: Florian Fainelli flor...@openwrt.org
 
 This patch adds support for reading an ONFI page parameter from a NAND
 device supporting it. If this is the case, struct nand_chip onfi_version
 member contains the supported ONFI version, 0 otherwise.
 
 This allows NAND drivers past nand_scan_ident to set the best timings for the
 NAND chip.
 
 Signed-off-by: Florian Fainelli flor...@openwrt.org
 ---
 Patch against your 'next' branch

The 'next' branch is old, since I haven't pushed anything to it yet this
cycle.  Base it on Wolfgang's 'next'.

 Changes since v1:
 - ifdef out ONFI detection code around CONFIG_SYS_NAND_ONFI_DETECTION
 - removed bogus comment
 - fixed busw variable usage
 - move non-ONFI detection code to its own function
 - fixed stylistic issues spotted by Scott
 
 Changes since v2:
 - reduce lenght of some lines down to 80 columns
 - change chip-options consistently wrt to ONFI detected or not
 - removed extra spaces
 
 diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
 index 5239c1f..7becb99 100644
 --- a/drivers/mtd/nand/nand_base.c
 +++ b/drivers/mtd/nand/nand_base.c
 @@ -2409,15 +2409,137 @@ static void nand_set_defaults(struct nand_chip 
 *chip, int busw)
   chip-controller = chip-hwcontrol;
  }
 
 +#ifdef CONFIG_SYS_NAND_ONFI_DETECTION
 +static u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
 +{
 + int i;
 +
 + while (len--) {
 + crc ^= *p++  8;
 + for (i = 0; i  8; i++)
 + crc = (crc  1) ^ ((crc  0x8000) ? 0x8005 : 0);
 + }
 +
 + return crc;
 +}

Is this different from what's in lib/crc16.c (other than appearing to have
made a different speed/size tradeoff)?

 +#define ONFI_CRC_BASE0x4F4E

Is this ONFI-specific, or standard for crc16?

 +
 +/*
 + * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise
 + */
 +static int nand_flash_detect_onfi(struct mtd_info *mtd,
 + struct nand_chip *chip,
 + int *busw)
 +{
[snip]
 + chip-options = ~NAND_CHIPOPTIONS_MSK;
 + chip-options |= NAND_NO_READRDY  NAND_CHIPOPTIONS_MSK;

Won't this get overwritten by this later?

 + /* Get chip options, preserve non chip based options */
 + chip-options = ~NAND_CHIPOPTIONS_MSK;
 + chip-options |= type-options  NAND_CHIPOPTIONS_MSK;

-Scott

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v3] NAND: add support for reading ONFI page table

2011-02-14 Thread Wolfgang Denk
Dear Scott Wood,

In message 20110214174607.2b56d...@schlenkerla.am.freescale.net you wrote:
 
 The 'next' branch is old, since I haven't pushed anything to it yet this
 cycle.  Base it on Wolfgang's 'next'.

I don't have a next yet.  I will create it when -rc2 is out.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Plans break down. You cannot plan the future. Only presumptuous fools
plan. The wise man _steers_.- Terry Pratchett, _Making_Money_
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot