From patchwork Wed Feb 27 15:10:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 223629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F2DBD2C007A for ; Thu, 28 Feb 2013 02:12:24 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UAiey-00072N-9n; Wed, 27 Feb 2013 15:11:08 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UAies-000724-Of for linux-mtd@lists.infradead.org; Wed, 27 Feb 2013 15:11:04 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1UAiep-0001r5-Iu; Wed, 27 Feb 2013 16:10:59 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1UAiem-0004ko-Hq; Wed, 27 Feb 2013 16:10:56 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd/nand: don't use {read,write}_buf for 8-bit transfers Date: Wed, 27 Feb 2013 16:10:52 +0100 Message-Id: <1361977852-18233-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130227_101103_272577_9EE34678 X-CRM114-Status: GOOD ( 19.32 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 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: Huang Shijie , David Woodhouse , Artem Bityutskiy 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: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org According to the Open NAND Flash Interface Specification (ONFI) Revision 3.1 "Parameters are always transferred on the lower 8-bits of the data bus." for the Get Features and Set Features commands. So using read_buf and write_buf is wrong for 16-bit wide nand chips as they use I/O[15:0]. The Get Features command is easily fixed using 4 times the read_byte callback. For Set Features error out as there is no write_byte callback. Signed-off-by: Uwe Kleine-König Acked-by: Huang Shijie --- Hello, note this is only compile tested and I don't have a 16-bit wide nand, so I don't even saw a failure. The problem exists since commit 7db03ec (mtd: add helpers to set/get features for ONFI nand) which introduced the two functions. Still I'd like to know how I can write a byte (or a sequence of bytes) as this is necessary for locking the otp are of micron chips. Well, I could implement it for 8-bit chips only, but this isn't very satisfying. Do we need to add a write_byte callback to struct nand_chip? Or is there a way to do write a byte that I'm just too blind to see? Is this patch relevant for stable? Probably not!? Best regards Uwe drivers/mtd/nand/nand_base.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 4321415..abfd8ca 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2706,7 +2706,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) } /** - * nand_onfi_set_features- [REPLACEABLE] set features for ONFI nand + * nand_onfi_set_features - [REPLACEABLE] set features for ONFI nand * @mtd: MTD device structure * @chip: nand chip info structure * @addr: feature address. @@ -2720,6 +2720,11 @@ static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip, if (!chip->onfi_version) return -EINVAL; + if (chip->options & NAND_BUSWIDTH_16) { + pr_warn("onfi set feature command buggy for 16-bit chips\n"); + return -ENOTSUPP; + } + chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, addr, -1); chip->write_buf(mtd, subfeature_param, ONFI_SUBFEATURE_PARAM_LEN); status = chip->waitfunc(mtd, chip); @@ -2729,7 +2734,7 @@ static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip, } /** - * nand_onfi_get_features- [REPLACEABLE] get features for ONFI nand + * nand_onfi_get_features - [REPLACEABLE] get features for ONFI nand * @mtd: MTD device structure * @chip: nand chip info structure * @addr: feature address. @@ -2738,6 +2743,8 @@ static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip, static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, int addr, uint8_t *subfeature_param) { + int i; + if (!chip->onfi_version) return -EINVAL; @@ -2745,7 +2752,8 @@ static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, memset(subfeature_param, 0, ONFI_SUBFEATURE_PARAM_LEN); chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, addr, -1); - chip->read_buf(mtd, subfeature_param, ONFI_SUBFEATURE_PARAM_LEN); + for (i = 0; i < ONFI_SUBFEATURE_PARAM_LEN; ++i) + *subfeature_param++ = chip->read_byte(mtd); return 0; }