linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional
@ 2018-07-27  7:44 Boris Brezillon
  2018-07-27  7:44 ` [PATCH 1/2] mtd: rawnand: Add the nand_wait_readrdy() helper and use it Boris Brezillon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Boris Brezillon @ 2018-07-27  7:44 UTC (permalink / raw)
  To: Boris Brezillon, Richard Weinberger, Miquel Raynal, linux-mtd
  Cc: David Woodhouse, Brian Norris, Marek Vasut

Hello,

These 2 patches remove the last dependency we had on ->dev_ready() and
->chip_delay when ->exec_op() is defined. Will be needed to deprecate
both fields, which is about to happen (see this branch [1] if you want
to have the big picture).

Regards,

Boris

[1]https://github.com/bbrezillon/linux-0day/commits/nand/api-cleanup

Boris Brezillon (2):
  mtd: rawnand: Add the nand_wait_readrdy() helper and use it
  mtd: rawnand: Add the nand_wait_rdy_op() helper and use it

 drivers/mtd/nand/raw/nand_base.c | 49 ++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 14 deletions(-)

-- 
2.14.1

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

* [PATCH 1/2] mtd: rawnand: Add the nand_wait_readrdy() helper and use it
  2018-07-27  7:44 [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Boris Brezillon
@ 2018-07-27  7:44 ` Boris Brezillon
  2018-07-27  7:44 ` [PATCH 2/2] mtd: rawnand: Add the nand_wait_rdy_op() " Boris Brezillon
  2018-09-04 21:47 ` [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Miquel Raynal
  2 siblings, 0 replies; 4+ messages in thread
From: Boris Brezillon @ 2018-07-27  7:44 UTC (permalink / raw)
  To: Boris Brezillon, Richard Weinberger, Miquel Raynal, linux-mtd
  Cc: David Woodhouse, Brian Norris, Marek Vasut

The logic to wait for chip readiness after a page read has been
duplicated in nand_do_read_ops() and nand_do_read_oob(). Provide an
helper that does the right thing and call it where appropriate.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
 drivers/mtd/nand/raw/nand_base.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index d527e448ce19..21a04b7b918c 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -3524,6 +3524,18 @@ static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
 	return chip->setup_read_retry(mtd, retry_mode);
 }
 
+static void nand_wait_readrdy(struct nand_chip *chip)
+{
+	if (!(chip->options & NAND_NEED_READRDY))
+		return;
+
+	/* Apply delay or wait for ready/busy pin */
+	if (!chip->dev_ready)
+		udelay(chip->chip_delay);
+	else
+		nand_wait_ready(nand_to_mtd(chip));
+}
+
 /**
  * nand_do_read_ops - [INTERN] Read data with ECC
  * @mtd: MTD device structure
@@ -3631,13 +3643,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
 				}
 			}
 
-			if (chip->options & NAND_NEED_READRDY) {
-				/* Apply delay or wait for ready/busy pin */
-				if (!chip->dev_ready)
-					udelay(chip->chip_delay);
-				else
-					nand_wait_ready(mtd);
-			}
+			nand_wait_readrdy(chip);
 
 			if (mtd->ecc_stats.failed - ecc_failures) {
 				if (retry_mode + 1 < chip->read_retries) {
@@ -3908,13 +3914,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 		len = min(len, readlen);
 		buf = nand_transfer_oob(mtd, buf, ops, len);
 
-		if (chip->options & NAND_NEED_READRDY) {
-			/* Apply delay or wait for ready/busy pin */
-			if (!chip->dev_ready)
-				udelay(chip->chip_delay);
-			else
-				nand_wait_ready(mtd);
-		}
+		nand_wait_readrdy(chip);
 
 		max_bitflips = max_t(unsigned int, max_bitflips, ret);
 
-- 
2.14.1

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

* [PATCH 2/2] mtd: rawnand: Add the nand_wait_rdy_op() helper and use it
  2018-07-27  7:44 [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Boris Brezillon
  2018-07-27  7:44 ` [PATCH 1/2] mtd: rawnand: Add the nand_wait_readrdy() helper and use it Boris Brezillon
@ 2018-07-27  7:44 ` Boris Brezillon
  2018-09-04 21:47 ` [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Miquel Raynal
  2 siblings, 0 replies; 4+ messages in thread
From: Boris Brezillon @ 2018-07-27  7:44 UTC (permalink / raw)
  To: Boris Brezillon, Richard Weinberger, Miquel Raynal, linux-mtd
  Cc: David Woodhouse, Brian Norris, Marek Vasut

In order to make sure we use ->exec_op() to wait for chip readiness
when it's available we provide an helper that does the selection
between ->exec_op(), udelay(chip->chip_delay) and nand_wait_ready()
based on what's implemented by the controller driver.

We then use it in nand_wait_readrdy().

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
 drivers/mtd/nand/raw/nand_base.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 21a04b7b918c..e591410cddc9 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -2246,6 +2246,28 @@ static int nand_get_features_op(struct nand_chip *chip, u8 feature,
 	return 0;
 }
 
+static int nand_wait_rdy_op(struct nand_chip *chip, unsigned int timeout_ms,
+			    unsigned int delay_ns)
+{
+	if (chip->exec_op) {
+		struct nand_op_instr instrs[] = {
+			NAND_OP_WAIT_RDY(PSEC_TO_MSEC(timeout_ms),
+					 PSEC_TO_NSEC(delay_ns)),
+		};
+		struct nand_operation op = NAND_OPERATION(instrs);
+
+		return nand_exec_op(chip, &op);
+	}
+
+	/* Apply delay or wait for ready/busy pin */
+	if (!chip->dev_ready)
+		udelay(chip->chip_delay);
+	else
+		nand_wait_ready(nand_to_mtd(chip));
+
+	return 0;
+}
+
 /**
  * nand_reset_op - Do a reset operation
  * @chip: The NAND chip
@@ -3526,14 +3548,13 @@ static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
 
 static void nand_wait_readrdy(struct nand_chip *chip)
 {
+	const struct nand_sdr_timings *sdr;
+
 	if (!(chip->options & NAND_NEED_READRDY))
 		return;
 
-	/* Apply delay or wait for ready/busy pin */
-	if (!chip->dev_ready)
-		udelay(chip->chip_delay);
-	else
-		nand_wait_ready(nand_to_mtd(chip));
+	sdr = nand_get_sdr_timings(&chip->data_interface);
+	WARN_ON(nand_wait_rdy_op(chip, PSEC_TO_MSEC(sdr->tR_max), 0));
 }
 
 /**
-- 
2.14.1

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

* Re: [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional
  2018-07-27  7:44 [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Boris Brezillon
  2018-07-27  7:44 ` [PATCH 1/2] mtd: rawnand: Add the nand_wait_readrdy() helper and use it Boris Brezillon
  2018-07-27  7:44 ` [PATCH 2/2] mtd: rawnand: Add the nand_wait_rdy_op() " Boris Brezillon
@ 2018-09-04 21:47 ` Miquel Raynal
  2 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2018-09-04 21:47 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Richard Weinberger, linux-mtd, David Woodhouse, Brian Norris,
	Marek Vasut

Hi Boris,

Boris Brezillon <boris.brezillon@bootlin.com> wrote on Fri, 27 Jul 2018
09:44:16 +0200:

> Hello,
> 
> These 2 patches remove the last dependency we had on ->dev_ready() and
> ->chip_delay when ->exec_op() is defined. Will be needed to deprecate  
> both fields, which is about to happen (see this branch [1] if you want
> to have the big picture).
> 
> Regards,
> 
> Boris
> 
> [1]https://github.com/bbrezillon/linux-0day/commits/nand/api-cleanup
> 
> Boris Brezillon (2):
>   mtd: rawnand: Add the nand_wait_readrdy() helper and use it
>   mtd: rawnand: Add the nand_wait_rdy_op() helper and use it
> 
>  drivers/mtd/nand/raw/nand_base.c | 49 ++++++++++++++++++++++++++++------------
>  1 file changed, 35 insertions(+), 14 deletions(-)
> 

Applied to nand/next.
Thanks

-- 
Miquel Raynal, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2018-09-04 21:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-27  7:44 [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Boris Brezillon
2018-07-27  7:44 ` [PATCH 1/2] mtd: rawnand: Add the nand_wait_readrdy() helper and use it Boris Brezillon
2018-07-27  7:44 ` [PATCH 2/2] mtd: rawnand: Add the nand_wait_rdy_op() " Boris Brezillon
2018-09-04 21:47 ` [PATCH 0/2] mtd: rawnand: Make ->dev_ready() and ->chip_delay optional Miquel Raynal

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).