All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* NAND: Verify probe by retrying to checking the results match
@ 2008-04-14 13:16 Ben Dooks
  2008-04-14 13:33 ` Artem Bityutskiy
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Dooks @ 2008-04-14 13:16 UTC (permalink / raw
  To: linux-mtd; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-drivers-mtd-nand-doubleprobe.patch --]
[-- Type: text/plain, Size: 1423 bytes --]

With modern systems using bus-hold instead of bus pull-up, it can
often lead to erroneous reporting of NAND devices where there are
none. Do a double probe to ensure that the result we got the first
time is repeatable, and if it is not then return that there is no
chip there.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

--- linux-2.6.24-quilt16.orig/drivers/mtd/nand/nand_base.c
+++ linux-2.6.24-quilt16/drivers/mtd/nand/nand_base.c
@@ -2229,6 +2229,7 @@ static struct nand_flash_dev *nand_get_f
 {
 	struct nand_flash_dev *type = NULL;
 	int i, dev_id, maf_idx;
+	int tmp_id, tmp_manf;
 
 	/* Select the device */
 	chip->select_chip(mtd, 0);
@@ -2239,6 +2240,22 @@ static struct nand_flash_dev *nand_get_f
 	/* Read manufacturer and device IDs */
 	*maf_id = chip->read_byte(mtd);
 	dev_id = chip->read_byte(mtd);
+	
+	/* Try again to make sure. */
+
+	chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
+
+	/* Read manufacturer and device IDs */
+
+	tmp_manf = chip->read_byte(mtd);
+	tmp_id = chip->read_byte(mtd);
+
+	if (tmp_manf != *maf_id || tmp_id != dev_id) {
+		printk(KERN_INFO "%s: second ID read did not match "
+		       "%02x,%02x against %02x,%02x\n", __func__,
+		       *maf_id, dev_id, tmp_manf, tmp_id);
+		return ERR_PTR(-ENODEV);
+	}
 
 	/* Lookup the flash id */
 	for (i = 0; nand_flash_ids[i].name != NULL; i++) {

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

* Re: NAND: Verify probe by retrying to checking the results match
  2008-04-14 13:16 Ben Dooks
@ 2008-04-14 13:33 ` Artem Bityutskiy
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2008-04-14 13:33 UTC (permalink / raw
  To: Ben Dooks; +Cc: linux-mtd

On Mon, 2008-04-14 at 14:16 +0100, Ben Dooks wrote:
> With modern systems using bus-hold instead of bus pull-up, it can
> often lead to erroneous reporting of NAND devices where there are
> none. Do a double probe to ensure that the result we got the first
> time is repeatable, and if it is not then return that there is no
> chip there.
> 
> Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Could you please put the same comment to the code, to make it easier for
the curious code reader understand why is the second read?

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

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

* NAND: Verify probe by retrying to checking the results match
@ 2008-04-14 13:58 Ben Dooks
  0 siblings, 0 replies; 3+ messages in thread
From: Ben Dooks @ 2008-04-14 13:58 UTC (permalink / raw
  To: linux-mtd; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-drivers-mtd-nand-doubleprobe.patch --]
[-- Type: text/plain, Size: 1839 bytes --]

With modern systems using bus-hold instead of bus pull-up, it can
often lead to erroneous reporting of NAND devices where there are
none. Do a double probe to ensure that the result we got the first
time is repeatable, and if it is not then return that there is no
chip there.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.24-quilt17/drivers/mtd/nand/nand_base.c
===================================================================
--- linux-2.6.24-quilt17.orig/drivers/mtd/nand/nand_base.c	2008-03-18 10:07:07.000000000 +0000
+++ linux-2.6.24-quilt17/drivers/mtd/nand/nand_base.c	2008-04-14 14:49:06.000000000 +0100
@@ -2229,6 +2229,7 @@ static struct nand_flash_dev *nand_get_f
 {
 	struct nand_flash_dev *type = NULL;
 	int i, dev_id, maf_idx;
+	int tmp_id, tmp_manf;
 
 	/* Select the device */
 	chip->select_chip(mtd, 0);
@@ -2239,6 +2240,26 @@ static struct nand_flash_dev *nand_get_f
 	/* Read manufacturer and device IDs */
 	*maf_id = chip->read_byte(mtd);
 	dev_id = chip->read_byte(mtd);
+	
+	/* Try again to make sure, as some systems the bus-hold or other
+	 * interface concerns can cause random data which looks like a
+	 * possibly credible NAND flash to appear. If the two results do
+	 * not match, ignore the device completely.
+	 */
+
+	chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
+
+	/* Read manufacturer and device IDs */
+
+	tmp_manf = chip->read_byte(mtd);
+	tmp_id = chip->read_byte(mtd);
+
+	if (tmp_manf != *maf_id || tmp_id != dev_id) {
+		printk(KERN_INFO "%s: second ID read did not match "
+		       "%02x,%02x against %02x,%02x\n", __func__,
+		       *maf_id, dev_id, tmp_manf, tmp_id);
+		return ERR_PTR(-ENODEV);
+	}
 
 	/* Lookup the flash id */
 	for (i = 0; nand_flash_ids[i].name != NULL; i++) {

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

end of thread, other threads:[~2008-04-14 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-14 13:58 NAND: Verify probe by retrying to checking the results match Ben Dooks
  -- strict thread matches above, loose matches on Subject: below --
2008-04-14 13:16 Ben Dooks
2008-04-14 13:33 ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.