Skip to contentSkip to conversation

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

PATCH Superseded Lei Wen 5 participants 10 messages Jan 3, 2011 – Jan 6, 2011

Subsystems (3)
lore
Share & tools
lore

Lei Wen

author
#0 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

This patch sync with newest mtd code in Linux on handling nand_scan_ident.

---
 drivers/mtd/nand/atmel_nand.c |    2 +-
 drivers/mtd/nand/nand_base.c  |   29 +++++++++++++++--------------
 drivers/mtd/nand/nand_ids.c   |    2 +-
 include/linux/mtd/nand.h      |    6 ++++--
 4 files changed, 21 insertions(+), 18 deletions(-)
drivers/mtd/nand/atmel_nand.c +1 -1
index d5eb54a..ab8bbb3 100644
@@ -296,7 +296,7 @@ int board_nand_init(struct nand_chip *nand)
 	mtd->priv = nand;
 
 	/* Detect NAND chips */
-	if (nand_scan_ident(mtd, 1)) {
+	if (nand_scan_ident(mtd, 1, NULL)) {
 		printk(KERN_WARNING "NAND Flash not found !\n");
 		return -ENXIO;
 	}
drivers/mtd/nand/nand_base.c +15 -14
index 5239c1f..39fcc94 100644
@@ -2414,10 +2414,10 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
  */
 static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 						  struct nand_chip *chip,
-						  int busw, int *maf_id)
+						  int busw, int *maf_id,
+						  struct nand_flash_dev *type)
 {
-	const struct nand_flash_dev *type = NULL;
-	int i, dev_id, maf_idx;
+	int dev_id, maf_idx;
 	int tmp_id, tmp_manf;
 
 	/* Select the device */
@@ -2456,15 +2456,14 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* Lookup the flash id */
-	for (i = 0; nand_flash_ids[i].name != NULL; i++) {
-		if (dev_id == nand_flash_ids[i].id) {
-			type =  &nand_flash_ids[i];
-			break;
-		}
-	}
+	if (!type)
+		type = nand_flash_ids;
+
+	for (; type->name != NULL; type++)
+		if (dev_id == type->id)
+                        break;
 
-	if (!type) {
+	if (!type->name) {
 		/* supress warning if there is no nand */
 		if (*maf_id != 0x00 && *maf_id != 0xff &&
 		    dev_id  != 0x00 && dev_id  != 0xff)
@@ -2580,13 +2579,15 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
  * nand_scan_ident - [NAND Interface] Scan for the NAND device
  * @mtd:	     MTD device structure
  * @maxchips:	     Number of chips to scan for
+ * @table:	     Alternative NAND ID table
  *
  * This is the first phase of the normal nand_scan() function. It
  * reads the flash ID and sets up MTD fields accordingly.
  *
  * The mtd->owner field must be set to the module of the caller.
  */
-int nand_scan_ident(struct mtd_info *mtd, int maxchips)
+int nand_scan_ident(struct mtd_info *mtd, int maxchips,
+		    struct nand_flash_dev *table)
 {
 	int i, busw, nand_maf_id;
 	struct nand_chip *chip = mtd->priv;
@@ -2598,7 +2599,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips)
 	nand_set_defaults(chip, busw);
 
 	/* Read the flash type */
-	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id);
+	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id, table);
 
 	if (IS_ERR(type)) {
 #ifndef CONFIG_SYS_NAND_QUIET_TEST
@@ -2869,7 +2870,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 	int ret;
 
-	ret = nand_scan_ident(mtd, maxchips);
+	ret = nand_scan_ident(mtd, maxchips, NULL);
 	if (!ret)
 		ret = nand_scan_tail(mtd);
 	return ret;
drivers/mtd/nand/nand_ids.c +1 -1
index 8d7ea76..67da52a 100644
@@ -22,7 +22,7 @@
 +	256	256 Byte page size
 *	512	512 Byte page size
 */
-const struct nand_flash_dev nand_flash_ids[] = {
+struct nand_flash_dev nand_flash_ids[] = {
 
 #ifdef CONFIG_MTD_NAND_MUSEUM_IDS
 	{"NAND 1MiB 5V 8-bit",		0x6e, 256, 1, 0x1000, 0},
include/linux/mtd/nand.h +4 -2
index 1128f5a..bcbf4dd 100644
@@ -33,11 +33,13 @@
 
 
 struct mtd_info;
+struct nand_flash_dev;
 /* Scan and identify a NAND device */
 extern int nand_scan (struct mtd_info *mtd, int max_chips);
 /* Separate phases of nand_scan(), allowing board driver to intervene
  * and override command or ECC setup according to flash type */
-extern int nand_scan_ident(struct mtd_info *mtd, int max_chips);
+extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
+			   struct nand_flash_dev *table);
 extern int nand_scan_tail(struct mtd_info *mtd);
 
 /* Free resources held by the NAND device */
@@ -471,7 +473,7 @@ struct nand_manufacturers {
 	char * name;
 };
 
-extern const struct nand_flash_dev nand_flash_ids[];
+extern struct nand_flash_dev nand_flash_ids[];
 extern const struct nand_manufacturers nand_manuf_ids[];
 
 extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Quoted 2 lines · Lei Wen

This patch sync with newest mtd code in Linux on handling nand_scan_ident.

is there any point to the sync ? doesnt seem like anyone is using the new option.

drivers/mtd/nand/nand_ids.c line 25

Quoted 4 lines
drivers/mtd/nand/nand_ids.c +1 -1
-const struct nand_flash_dev nand_flash_ids[] = {
+struct nand_flash_dev nand_flash_ids[] = {

this is wrong
-mike

#2 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Hi Mike,

Quoted 6 lines · Mike Frysinger
Quoted 2 lines · Lei Wen

This patch sync with newest mtd code in Linux on handling nand_scan_ident.

is there any point to the sync ? ?doesnt seem like anyone is using the new option.

This patch sync with David's patch on Linux.
commit 5e81e88a4c140586d9212999cea683bcd66a15c6

Author: David Woodhouse <[email protected]>
Date:   Fri Feb 26 18:32:56 2010 +0000

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Yes, for this time uboot's code hasn't used this kind of code. But this prepare for
my submition of pxa3xx_nand.c code in the next several weeks, which need this patch
in advance.

Quoted 7 lines

drivers/mtd/nand/nand_ids.c line 25

Quoted 5 lines
drivers/mtd/nand/nand_ids.c +1 -1
-const struct nand_flash_dev nand_flash_ids[] = {
+struct nand_flash_dev nand_flash_ids[] = {

this is wrong

This would bring warning to the compilation, and it is also what Linux does now for the
same code...

Best regards,
Lei

#3 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Quoted 11 lines · Lei Wen
Quoted 7 lines · Mike Frysinger

drivers/mtd/nand/nand_ids.c line 25

Quoted 4 lines · Lei Wen
drivers/mtd/nand/nand_ids.c +1 -1
-const struct nand_flash_dev nand_flash_ids[] = {
+struct nand_flash_dev nand_flash_ids[] = {

this is wrong

This would bring warning to the compilation, and it is also what Linux does now for the same code...

then fix the callers to take a const flash table instead of removing the const markings on a const table
-mike

#4 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

In reply to Lei Wen

Dear Lei Wen,

Quoted 8 lines · In message <[email protected]> you…

This patch sync with David's patch on Linux.
commit 5e81e88a4c140586d9212999cea683bcd66a15c6

Author: David Woodhouse <[email protected]>
Date:   Fri Feb 26 18:32:56 2010 +0000

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

If you ever post such patches, then please pay speacial attention to properly attribute such patches. See
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

All patches that do not adhere to this policy will be rejected.

Best regards,

Wolfgang Denk

Signature · 9 lines
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: wd at denx.de
I've been programming for (35-9=) 24 years myself,  and  I  find  the
best way to learn a new language is to *read* every example snippet I
can find, with a reference book close by. Eventually, the *rhythm* of
the language starts pounding in my head... and my fluency is close at
hand. That's how I learned Perl, and now I'm one of the drummers. :-)
         -- Randal L. Schwartz in <[email protected]>
#5 lore raw

PATCH 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

In reply to Mike Frysinger
Quoted 6 lines · On Mon, 3 Jan 2011 10:35:45 -0500 Mike Frysinger <[email protected]> wrote:
Quoted 2 lines · Lei Wen

This patch sync with newest mtd code in Linux on handling nand_scan_ident.

is there any point to the sync ? doesnt seem like anyone is using the new option.

Even if Lei didn't need this for an upcoming driver, I see value in keeping in sync unless we have a good reason to deviate. It makes it easier to share drivers and bring over new features that we *do* want to use.

Quoted 6 lines

drivers/mtd/nand/nand_ids.c line 25

Quoted 4 lines
drivers/mtd/nand/nand_ids.c +1 -1
-const struct nand_flash_dev nand_flash_ids[] = {
+struct nand_flash_dev nand_flash_ids[] = {

this is wrong

I agree.

-Scott

author
#6 lore raw

PATCH v2 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

This patch sync with David's patch on Linux for handling nand_scan_ident.

commit 5e81e88a4c140586d9212999cea683bcd66a15c6
Author: David Woodhouse <[email protected]>
Date: Fri Feb 26 18:32:56 2010 +0000

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

---
V2: Add original patch owner signature, and fix that patch accoring to comments on const type.

 drivers/mtd/nand/atmel_nand.c |    2 +-
 drivers/mtd/nand/nand_base.c  |   29 +++++++++++++++--------------
 include/linux/mtd/nand.h      |    4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)
drivers/mtd/nand/atmel_nand.c +1 -1
index d5eb54a..ab8bbb3 100644
@@ -296,7 +296,7 @@ int board_nand_init(struct nand_chip *nand)
 	mtd->priv = nand;
 
 	/* Detect NAND chips */
-	if (nand_scan_ident(mtd, 1)) {
+	if (nand_scan_ident(mtd, 1, NULL)) {
 		printk(KERN_WARNING "NAND Flash not found !\n");
 		return -ENXIO;
 	}
drivers/mtd/nand/nand_base.c +15 -14
index 5239c1f..9512ae0 100644
@@ -2414,10 +2414,10 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
  */
 static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 						  struct nand_chip *chip,
-						  int busw, int *maf_id)
+						  int busw, int *maf_id,
+						  const struct nand_flash_dev *type)
 {
-	const struct nand_flash_dev *type = NULL;
-	int i, dev_id, maf_idx;
+	int dev_id, maf_idx;
 	int tmp_id, tmp_manf;
 
 	/* Select the device */
@@ -2456,15 +2456,14 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* Lookup the flash id */
-	for (i = 0; nand_flash_ids[i].name != NULL; i++) {
-		if (dev_id == nand_flash_ids[i].id) {
-			type =  &nand_flash_ids[i];
-			break;
-		}
-	}
+	if (!type)
+		type = nand_flash_ids;
+
+	for (; type->name != NULL; type++)
+		if (dev_id == type->id)
+                        break;
 
-	if (!type) {
+	if (!type->name) {
 		/* supress warning if there is no nand */
 		if (*maf_id != 0x00 && *maf_id != 0xff &&
 		    dev_id  != 0x00 && dev_id  != 0xff)
@@ -2580,13 +2579,15 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
  * nand_scan_ident - [NAND Interface] Scan for the NAND device
  * @mtd:	     MTD device structure
  * @maxchips:	     Number of chips to scan for
+ * @table:	     Alternative NAND ID table
  *
  * This is the first phase of the normal nand_scan() function. It
  * reads the flash ID and sets up MTD fields accordingly.
  *
  * The mtd->owner field must be set to the module of the caller.
  */
-int nand_scan_ident(struct mtd_info *mtd, int maxchips)
+int nand_scan_ident(struct mtd_info *mtd, int maxchips,
+		    struct nand_flash_dev *table)
 {
 	int i, busw, nand_maf_id;
 	struct nand_chip *chip = mtd->priv;
@@ -2598,7 +2599,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips)
 	nand_set_defaults(chip, busw);
 
 	/* Read the flash type */
-	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id);
+	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id, table);
 
 	if (IS_ERR(type)) {
 #ifndef CONFIG_SYS_NAND_QUIET_TEST
@@ -2869,7 +2870,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 	int ret;
 
-	ret = nand_scan_ident(mtd, maxchips);
+	ret = nand_scan_ident(mtd, maxchips, NULL);
 	if (!ret)
 		ret = nand_scan_tail(mtd);
 	return ret;
include/linux/mtd/nand.h +3 -1
index 1128f5a..ff6a1f9 100644
@@ -33,11 +33,13 @@
 
 
 struct mtd_info;
+struct nand_flash_dev;
 /* Scan and identify a NAND device */
 extern int nand_scan (struct mtd_info *mtd, int max_chips);
 /* Separate phases of nand_scan(), allowing board driver to intervene
  * and override command or ECC setup according to flash type */
-extern int nand_scan_ident(struct mtd_info *mtd, int max_chips);
+extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
+			   struct nand_flash_dev *table);
 extern int nand_scan_tail(struct mtd_info *mtd);
 
 /* Free resources held by the NAND device */
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH v2 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Quoted 4 lines · Lei Wen
drivers/mtd/nand/nand_base.c +0 -0
@@ -2580,13 +2579,15 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
  * nand_scan_ident - [NAND Interface] Scan for the NAND device
  * @mtd:	     MTD device structure
  * @maxchips:	     Number of chips to scan for

drivers/mtd/nand/nand_base.c static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, · line 2590

Quoted 10 lines
drivers/mtd/nand/nand_base.c +3 -1
+ * @table:	     Alternative NAND ID table
  *
  * This is the first phase of the normal nand_scan() function. It
  * reads the flash ID and sets up MTD fields accordingly.
  *
  * The mtd->owner field must be set to the module of the caller.
  */
-int nand_scan_ident(struct mtd_info *mtd, int maxchips)
+int nand_scan_ident(struct mtd_info *mtd, int maxchips,
+		    struct nand_flash_dev *table)

table should be const here as well.

-Scott

author
#8 lore raw

PATCH v3 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

This patch sync with David's patch on Linux for handling nand_scan_ident.

commit 5e81e88a4c140586d9212999cea683bcd66a15c6
Author: David Woodhouse <[email protected]>
Date: Fri Feb 26 18:32:56 2010 +0000

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

---
V2: Add original patch owner signature, and fix that patch accoring to comments on const type.
V3: Fix nand_scan_ident parameter as const

 drivers/mtd/nand/atmel_nand.c |    2 +-
 drivers/mtd/nand/nand_base.c  |   29 +++++++++++++++--------------
 include/linux/mtd/nand.h      |    4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)
drivers/mtd/nand/atmel_nand.c +1 -1
index d5eb54a..ab8bbb3 100644
@@ -296,7 +296,7 @@ int board_nand_init(struct nand_chip *nand)
 	mtd->priv = nand;
 
 	/* Detect NAND chips */
-	if (nand_scan_ident(mtd, 1)) {
+	if (nand_scan_ident(mtd, 1, NULL)) {
 		printk(KERN_WARNING "NAND Flash not found !\n");
 		return -ENXIO;
 	}
drivers/mtd/nand/nand_base.c +15 -14
index 5239c1f..3b96b0e 100644
@@ -2414,10 +2414,10 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
  */
 static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 						  struct nand_chip *chip,
-						  int busw, int *maf_id)
+						  int busw, int *maf_id,
+						  const struct nand_flash_dev *type)
 {
-	const struct nand_flash_dev *type = NULL;
-	int i, dev_id, maf_idx;
+	int dev_id, maf_idx;
 	int tmp_id, tmp_manf;
 
 	/* Select the device */
@@ -2456,15 +2456,14 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 		return ERR_PTR(-ENODEV);
 	}
 
-	/* Lookup the flash id */
-	for (i = 0; nand_flash_ids[i].name != NULL; i++) {
-		if (dev_id == nand_flash_ids[i].id) {
-			type =  &nand_flash_ids[i];
-			break;
-		}
-	}
+	if (!type)
+		type = nand_flash_ids;
+
+	for (; type->name != NULL; type++)
+		if (dev_id == type->id)
+                        break;
 
-	if (!type) {
+	if (!type->name) {
 		/* supress warning if there is no nand */
 		if (*maf_id != 0x00 && *maf_id != 0xff &&
 		    dev_id  != 0x00 && dev_id  != 0xff)
@@ -2580,13 +2579,15 @@ static const struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
  * nand_scan_ident - [NAND Interface] Scan for the NAND device
  * @mtd:	     MTD device structure
  * @maxchips:	     Number of chips to scan for
+ * @table:	     Alternative NAND ID table
  *
  * This is the first phase of the normal nand_scan() function. It
  * reads the flash ID and sets up MTD fields accordingly.
  *
  * The mtd->owner field must be set to the module of the caller.
  */
-int nand_scan_ident(struct mtd_info *mtd, int maxchips)
+int nand_scan_ident(struct mtd_info *mtd, int maxchips,
+		    const struct nand_flash_dev *table)
 {
 	int i, busw, nand_maf_id;
 	struct nand_chip *chip = mtd->priv;
@@ -2598,7 +2599,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips)
 	nand_set_defaults(chip, busw);
 
 	/* Read the flash type */
-	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id);
+	type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id, table);
 
 	if (IS_ERR(type)) {
 #ifndef CONFIG_SYS_NAND_QUIET_TEST
@@ -2869,7 +2870,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 	int ret;
 
-	ret = nand_scan_ident(mtd, maxchips);
+	ret = nand_scan_ident(mtd, maxchips, NULL);
 	if (!ret)
 		ret = nand_scan_tail(mtd);
 	return ret;
include/linux/mtd/nand.h +3 -1
index 1128f5a..d299929 100644
@@ -33,11 +33,13 @@
 
 
 struct mtd_info;
+struct nand_flash_dev;
 /* Scan and identify a NAND device */
 extern int nand_scan (struct mtd_info *mtd, int max_chips);
 /* Separate phases of nand_scan(), allowing board driver to intervene
  * and override command or ECC setup according to flash type */
-extern int nand_scan_ident(struct mtd_info *mtd, int max_chips);
+extern int nand_scan_ident(struct mtd_info *mtd, int max_chips,
+			   const struct nand_flash_dev *table);
 extern int nand_scan_tail(struct mtd_info *mtd);
 
 /* Free resources held by the NAND device */
Signature · 1 line
1.7.0.4
#9 lore raw

PATCH v3 1/1 mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

Quoted 6 lines · Lei Wen

This patch sync with David's patch on Linux for handling nand_scan_ident.

commit 5e81e88a4c140586d9212999cea683bcd66a15c6
Author: David Woodhouse <[email protected]>
Date: Fri Feb 26 18:32:56 2010 +0000

Quoted 8 lines

mtd: nand: Allow caller to pass alternative ID table to nand_scan_ident()

---
V2: Add original patch owner signature, and fix that patch accoring to comments on const type.
V3: Fix nand_scan_ident parameter as const

Applied to u-boot-nand-flash.

-Scott