From patchwork Fri Nov 29 13:40:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 295324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9AEDC2C00EF for ; Sat, 30 Nov 2013 00:43:14 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmOL4-0003aA-Mq; Fri, 29 Nov 2013 13:42:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmOKm-0001OH-Ac; Fri, 29 Nov 2013 13:42:16 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmOKJ-0001KM-W6; Fri, 29 Nov 2013 13:41:51 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 43822897; Fri, 29 Nov 2013 14:41:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost.localdomain (unknown [190.2.98.212]) by mail.free-electrons.com (Postfix) with ESMTPA id F22CB89C; Fri, 29 Nov 2013 14:41:02 +0100 (CET) From: Ezequiel Garcia To: , , , Subject: [RFC/PATCH] mtd: nand: auto-detection of NAND bus-width from ONFI param or nand_id[] Date: Fri, 29 Nov 2013 10:40:56 -0300 Message-Id: <1385732456-32696-2-git-send-email-ezequiel.garcia@free-electrons.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1385732456-32696-1-git-send-email-ezequiel.garcia@free-electrons.com> References: <1385732456-32696-1-git-send-email-ezequiel.garcia@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131129_084148_401163_13F7066C X-CRM114-Status: GOOD ( 19.63 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: mark.rutland@arm.com, shc_work@mail.ru, swarren@wwwdotorg.org, Tony Lindgren , Artem Bityutskiy , rob.herring@calxeda.com, Pekon Gupta , Ezequiel Garcia , Brian Norris , David Woodhouse X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Pekon Gupta 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 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 Signed-off-by: Ezequiel Garcia --- drivers/mtd/nand/nand_base.c | 43 +++++++++++++------------------------------ include/linux/mtd/nand.h | 7 ------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index bd39f7b..2fff3d0 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,20 @@ 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); + /* Select the device */ chip->select_chip(mtd, 0); @@ -3431,22 +3429,11 @@ ident_done: break; } - if (chip->options & NAND_BUSWIDTH_AUTO) { - WARN_ON(chip->options & NAND_BUSWIDTH_16); + /* re-configure driver using detected bus-width */ + if (busw) { + pr_debug("reconfiguring bus width to %d bit\n", busw ? 16 : 8); 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)) { diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 9e6c8f9..d5cc642 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -183,13 +183,6 @@ typedef enum { #define NAND_OWN_BUFFERS 0x00020000 /* Chip may not exist, so silence any errors in scan */ #define NAND_SCAN_SILENT_NODEV 0x00040000 -/* - * Autodetect nand buswidth with readid/onfi. - * This suppose the driver will configure the hardware in 8 bits mode - * when calling nand_scan_ident, and update its configuration - * before calling nand_scan_tail. - */ -#define NAND_BUSWIDTH_AUTO 0x00080000 /* Options set by nand scan */ /* Nand scan has allocated controller struct */