linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH v2] NAND bus-width detection extreme makeover
@ 2013-11-30 17:17 Ezequiel Garcia
  2013-11-30 17:17 ` [RFC/PATCH v2] mtd: nand: Fix ONFI detection of 16-bit width NAND devices Ezequiel Garcia
  0 siblings, 1 reply; 2+ messages in thread
From: Ezequiel Garcia @ 2013-11-30 17:17 UTC (permalink / raw)
  To: linux-mtd, linux-arm-kernel, linux-omap, devicetree
  Cc: shc_work, Artem Bityutskiy, Pekon Gupta, Ezequiel Garcia,
	u.kleine-koenig, Brian Norris, David Woodhouse

Another iteration of this proposal, although Brian Norris already said
he didn't like the v1. I guess I'm stubborn ;-)

This patch removes the flash device bus-width configuration, prior to
the device detection. With this modification, a NAND driver *shouldn't*
need to set the device width, but can instead obtain the detected
bus-width after the call to nand_scan_ident() and perform any neccessary
action.

As usual, this has been tested on a AM335x board with 8-bit and 16-bit devices,
which were successfully detected and nandtest'ed, using ONFI and flash-based
detection.

Improving from v1, now driver's shouldn't need *any* modification to work in
both 8-bit and 16-bit modes (although I'm only testing the omap2-nand driver).

Brian and others:

I'm no longer talking about removing any property or option :-), but merely
fixing our current incapability of detecting x16 devices by ONFI. I think
we can discuss about the DT property or the future of NAND_BUSWIDTH_AUTO
in another thread.

Probably there's more work needed along the lines of Uwe's patch to
fix other ONFI-related usage.

Changes from v1:

  * In addition to setting nand_set_default to x8 for the detection phase,
    this commit now clears the NAND_BUSWIDTH_16 flag from chip->options
    as it prevented device from getting detected.

  * This v2 no longer removes the NAND_BUSWIDTH_AUTO option. We can do that
    later after some proper discussion.

Ezequiel Garcia (1):
  mtd: nand: Fix ONFI detection of 16-bit width NAND devices

 drivers/mtd/nand/nand_base.c | 43 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)

-- 
1.8.1.5

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

* [RFC/PATCH v2] mtd: nand: Fix ONFI detection of 16-bit width NAND devices
  2013-11-30 17:17 [RFC/PATCH v2] NAND bus-width detection extreme makeover Ezequiel Garcia
@ 2013-11-30 17:17 ` Ezequiel Garcia
  0 siblings, 0 replies; 2+ messages in thread
From: Ezequiel Garcia @ 2013-11-30 17:17 UTC (permalink / raw)
  To: linux-mtd, linux-arm-kernel, linux-omap, devicetree
  Cc: shc_work, Artem Bityutskiy, Pekon Gupta, Ezequiel Garcia,
	u.kleine-koenig, Brian Norris, David Woodhouse

This patch is alternative implementation for following commit which introduced
NAND_BUSWIDTH_AUTO for detection of bus-width during device probe
   commit 64b37b2a63eb2f80b65c7185f0013f8ffc637ae3
   Author:     Matthieu CASTET <matthieu.castet@parrot.com>
   AuthorDate: 2012-11-06

As NAND device is identified only during nand_scan_ident(), so this patch
assumes that NAND driver may un-initialized or partially congigured while
calling nand_scan_ident(). Hence, this patch does following:

 1. Temporarily configures 'bus-width=x8' mode before reading ONFI parameters,
    as required by ONFI specification [1].

 2. Reconfigures the driver with correct bus-width determined by either reading
    ONFI param, or the nand_flash_id[] table.

This patch removes any dependency on either 'DT binding' or 'platform data' to
specify the NAND device bus-width.

[*] Reference: ONFI spec version 3.1 (section 3.5.3. Target Initialization)
    "The Read ID and Read Parameter Page commands only use the lower 8-bits
     of the data bus. The host shall not issue commands that use a word
     data width on x16 devices until the host determines the device supports
     a 16-bit data bus width in the parameter page."

Signed-off-by: Pekon Gupta <pekon@ti.com>
Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
---
 drivers/mtd/nand/nand_base.c | 43 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index bd39f7b..3ff9944 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2942,15 +2942,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 		chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I')
 		return 0;
 
-	/*
-	 * ONFI must be probed in 8-bit mode or with NAND_BUSWIDTH_AUTO, not
-	 * with NAND_BUSWIDTH_16
-	 */
-	if (chip->options & NAND_BUSWIDTH_16) {
-		pr_err("ONFI cannot be probed in 16-bit mode; aborting\n");
-		return 0;
-	}
-
 	chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
 	for (i = 0; i < 3; i++) {
 		chip->read_buf(mtd, (uint8_t *)p, sizeof(*p));
@@ -3335,13 +3326,21 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip,
  */
 static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
 						  struct nand_chip *chip,
-						  int busw,
 						  int *maf_id, int *dev_id,
 						  struct nand_flash_dev *type)
 {
 	int i, maf_idx;
+	int busw = 0;
 	u8 id_data[8];
 
+	/*
+	 * The device detection is done in 8-bit mode. The real bus width
+	 * will be autodetected (either ONFI or flash-based), the
+	 * defaults re-configured and the chip->options updated.
+	 */
+	nand_set_defaults(chip, 0);
+	chip->options &= ~NAND_BUSWIDTH_16;
+
 	/* Select the device */
 	chip->select_chip(mtd, 0);
 
@@ -3431,22 +3430,10 @@ ident_done:
 			break;
 	}
 
-	if (chip->options & NAND_BUSWIDTH_AUTO) {
-		WARN_ON(chip->options & NAND_BUSWIDTH_16);
+	/* Configure driver using detected bus-width */
+	if (busw) {
 		chip->options |= busw;
 		nand_set_defaults(chip, busw);
-	} else if (busw != (chip->options & NAND_BUSWIDTH_16)) {
-		/*
-		 * Check, if buswidth is correct. Hardware drivers should set
-		 * chip correct!
-		 */
-		pr_info("NAND device: Manufacturer ID:"
-			" 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id,
-			*dev_id, nand_manuf_ids[maf_idx].name, mtd->name);
-		pr_warn("NAND bus width %d instead %d bit\n",
-			   (chip->options & NAND_BUSWIDTH_16) ? 16 : 8,
-			   busw ? 16 : 8);
-		return ERR_PTR(-EINVAL);
 	}
 
 	nand_decode_bbm_options(mtd, chip, id_data);
@@ -3497,17 +3484,13 @@ ident_done:
 int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 		    struct nand_flash_dev *table)
 {
-	int i, busw, nand_maf_id, nand_dev_id;
+	int i, nand_maf_id, nand_dev_id;
 	struct nand_chip *chip = mtd->priv;
 	struct nand_flash_dev *type;
 
-	/* Get buswidth to select the correct functions */
-	busw = chip->options & NAND_BUSWIDTH_16;
-	/* Set the default functions */
-	nand_set_defaults(chip, busw);
 
 	/* Read the flash type */
-	type = nand_get_flash_type(mtd, chip, busw,
+	type = nand_get_flash_type(mtd, chip,
 				&nand_maf_id, &nand_dev_id, table);
 
 	if (IS_ERR(type)) {
-- 
1.8.1.5

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

end of thread, other threads:[~2013-11-30 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-30 17:17 [RFC/PATCH v2] NAND bus-width detection extreme makeover Ezequiel Garcia
2013-11-30 17:17 ` [RFC/PATCH v2] mtd: nand: Fix ONFI detection of 16-bit width NAND devices Ezequiel Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).