Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752094AbdI2Kk5 (ORCPT ); Fri, 29 Sep 2017 06:40:57 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:57738 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750807AbdI2Kkz (ORCPT ); Fri, 29 Sep 2017 06:40:55 -0400 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com v8TAcmAD012917 X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Masahiro Yamada , Cyrille Pitchen , linux-kernel@vger.kernel.org, Boris Brezillon , Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse Subject: [PATCH v2 1/2] mtd: nand: wait for tWHR after NAND_CMD_STATUS / NAND_CMD_READID Date: Fri, 29 Sep 2017 19:38:39 +0900 Message-Id: <1506681520-13897-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506681520-13897-1-git-send-email-yamada.masahiro@socionext.com> References: <1506681520-13897-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3140 Lines: 97 For commands such as Read Status, Read ID, etc. the controller needs to wait for tWHR before it reads out the first data. If the controller does not take care of it, the driver has to wait explicitly to make sure to meet the spec. Introduce NAND_WAIT_TWHR, which works like NAND_WAIT_TCCS. The driver can set this flag to let the core to handle the tWHR delay. Signed-off-by: Masahiro Yamada --- Changes in v2: - Add nand_whr_delay() helper Wait for tWHR only for drivers that explicitly set NAND_WAIT_TWHR flag drivers/mtd/nand/nand_base.c | 21 +++++++++++++++++++-- include/linux/mtd/rawnand.h | 13 ++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index b1cf32c..455085d 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -676,6 +676,17 @@ static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) } while (time_before(jiffies, timeo)); }; +static void nand_whr_delay(struct nand_chip *chip) +{ + if (!(chip->options & NAND_WAIT_TWHR)) + return; + + if (chip->data_interface && chip->data_interface->timings.sdr.tWHR_min) + ndelay(chip->data_interface->timings.sdr.tWHR_min / 1000); + else + ndelay(200); +} + /** * nand_command - [DEFAULT] Send command to NAND device * @mtd: MTD device structure @@ -742,9 +753,12 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, case NAND_CMD_ERASE1: case NAND_CMD_ERASE2: case NAND_CMD_SEQIN: + case NAND_CMD_SET_FEATURES: + return; + case NAND_CMD_STATUS: case NAND_CMD_READID: - case NAND_CMD_SET_FEATURES: + nand_whr_delay(chip); return; case NAND_CMD_RESET: @@ -871,9 +885,12 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, case NAND_CMD_ERASE1: case NAND_CMD_ERASE2: case NAND_CMD_SEQIN: + case NAND_CMD_SET_FEATURES: + return; + case NAND_CMD_STATUS: case NAND_CMD_READID: - case NAND_CMD_SET_FEATURES: + nand_whr_delay(chip); return; case NAND_CMD_RNDIN: diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 749bb08..bb0165b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -213,13 +213,16 @@ enum nand_ecc_algo { /* * In case your controller is implementing ->cmd_ctrl() and is relying on the - * default ->cmdfunc() implementation, you may want to let the core handle the - * tCCS delay which is required when a column change (RNDIN or RNDOUT) is - * requested. - * If your controller already takes care of this delay, you don't need to set - * this flag. + * default ->cmdfunc() implementation, you may want to let the core handle + * some delays to meet the timing specification. + * If your controller already takes care of these delays, you don't need to set + * the following flags. */ + +/* tCCS for a column change (RNDIN or RNDOUT) */ #define NAND_WAIT_TCCS 0x00200000 +/* tWHR for STATUS, READID, etc. */ +#define NAND_WAIT_TWHR 0x00400000 /* Options set by nand scan */ /* Nand scan has allocated controller struct */ -- 2.7.4