mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 02/15] mtd: nand: base: implement nand_gpio_waitrdy
Date: Wed, 11 Jan 2023 18:40:10 +0100	[thread overview]
Message-ID: <20230111174023.1719129-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230111174023.1719129-1-a.fatoum@pengutronix.de>

To simplify porting kernel NAND drivers a tiny bit, provide the Linux
nand_gpio_waitrdy. This is readily implementable with barebox' own
gpio_poll_timeout_us.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mtd/nand/nand_base.c | 22 ++++++++++++++++++++++
 include/linux/mtd/rawnand.h  |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 4c90ad975771..c3cd22935bb2 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -36,6 +36,7 @@
 #include <asm/byteorder.h>
 #include <io.h>
 #include <malloc.h>
+#include <gpio.h>
 #include <module.h>
 #include <of_mtd.h>
 
@@ -785,6 +786,27 @@ int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms)
 };
 EXPORT_SYMBOL_GPL(nand_soft_waitrdy);
 
+/**
+ * nand_gpio_waitrdy - Poll R/B GPIO pin until ready
+ * @chip: NAND chip structure
+ * @gpiod: GPIO descriptor of R/B pin
+ * @timeout_ms: Timeout in ms
+ *
+ * Poll the R/B GPIO pin until it becomes ready. If that does not happen
+ * whitin the specified timeout, -ETIMEDOUT is returned.
+ *
+ * This helper is intended to be used when the controller has access to the
+ * NAND R/B pin over GPIO.
+ *
+ * Return 0 if the R/B pin indicates chip is ready, a negative error otherwise.
+ */
+int nand_gpio_waitrdy(struct nand_chip *chip, int gpio,
+		      unsigned long timeout_ms)
+{
+	return gpio_poll_timeout_us(gpio, true, timeout_ms * USEC_PER_MSEC);
+};
+EXPORT_SYMBOL_GPL(nand_gpio_waitrdy);
+
 static bool nand_supports_get_features(struct nand_chip *chip, int addr)
 {
 	return (chip->parameters.supports_set_get_features &&
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 1147f235a680..a05c67e1404b 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1414,6 +1414,8 @@ void nand_cleanup(struct nand_chip *chip);
  * instruction and have no physical pin to check it.
  */
 int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms);
+int nand_gpio_waitrdy(struct nand_chip *chip, int gpio,
+		      unsigned long timeout_ms);
 
 /* Select/deselect a NAND target. */
 void nand_select_target(struct nand_chip *chip, unsigned int cs);
-- 
2.30.2




  parent reply	other threads:[~2023-01-11 17:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 17:40 [PATCH 00/15] mtd: nand: atmel: import Linux NAND controller driver Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 01/15] asm-generic: io.h: sync with Linux Ahmad Fatoum
2023-01-11 17:40 ` Ahmad Fatoum [this message]
2023-01-11 17:40 ` [PATCH 03/15] mtd: nand: prefix enum nand_ecc_algo constants with NAND_ECC_ALGO_ Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 04/15] mtd: nand: rename nand_device::eccreq to Linux' ecc.requirements Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 05/15] mtd: nand: define nand_get_(small|large)_page_ooblayout Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 06/15] mtd: nand: define nand_interface_is_sdr Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 07/15] mtd: nand: provide Linux' struct nand_ecc_ctrl::engine_type Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 08/15] driver: implement dev_request_resource Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 09/15] lib: provide stub Linux "generic" allocator API Ahmad Fatoum
2023-01-12 13:26   ` Sascha Hauer
2023-01-11 17:40 ` [PATCH 10/15] memory: add Atmel EBI driver Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 11/15] mfd: add atmel-smc driver Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 12/15] mtd: nand: atmel: import Linux NAND controller driver Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 13/15] ARM: AT91: sama5d3_xplained: switch to upstream binding Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 14/15] mtd: nand: drop DT support in legacy driver Ahmad Fatoum
2023-01-11 17:40 ` [PATCH 15/15] ARM: AT91: sama5d3: always read memory size from controller Ahmad Fatoum
2023-01-12 14:22 ` [PATCH 00/15] mtd: nand: atmel: import Linux NAND controller driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230111174023.1719129-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox