summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMikhail Kshevetskiy <[email protected]>2025-09-30 03:20:50 +0300
committerMichael Trimarchi <[email protected]>2025-10-05 20:25:51 +0200
commit64b7865c72b8b3bc3c08e095888d6c7dce7c7c27 (patch)
tree58907c7622d6af83c0f4a954ec0cd46ddce48043 /drivers
parentbae27e402d050154ebb8e677d409f49376cc985a (diff)
mtd: spinand: Extend spinand_wait() to match Linux kernel implementation
This aligns spinand_wait() with the linux kernel. Instead of calling into spi_mem_poll_status() which is not implemented in U-Boot, we code the polling logic and make sure that schedule() is called periodically. Signed-off-by: Mikhail Kshevetskiy <[email protected]> Reviewed-by: Frieder Schrempf <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/nand/spi/core.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 34e5ac33c63..3b612bec274 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -32,6 +32,7 @@
#include <linux/bug.h>
#include <linux/mtd/spinand.h>
#include <linux/printk.h>
+#include <linux/delay.h>
#endif
struct spinand_plat {
@@ -362,21 +363,41 @@ static int spinand_erase_op(struct spinand_device *spinand,
return spi_mem_exec_op(spinand->slave, &op);
}
-static int spinand_wait(struct spinand_device *spinand, u8 *s)
+/**
+ * spinand_wait() - Poll memory device status
+ * @spinand: the spinand device
+ * @initial_delay_us: delay in us before starting to poll
+ * @poll_delay_us: time to sleep between reads in us
+ * @s: the pointer to variable to store the value of REG_STATUS
+ *
+ * This function polls a status register (REG_STATUS) and returns when
+ * the STATUS_READY bit is 0 or when the timeout has expired.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+static int spinand_wait(struct spinand_device *spinand,
+ unsigned long initial_delay_us,
+ unsigned long poll_delay_us,
+ u8 *s)
{
unsigned long start, stop;
u8 status;
int ret;
+ udelay(initial_delay_us);
start = get_timer(0);
- stop = 400;
+ stop = SPINAND_WAITRDY_TIMEOUT_MS;
do {
+ schedule();
+
ret = spinand_read_status(spinand, &status);
if (ret)
return ret;
if (!(status & STATUS_BUSY))
goto out;
+
+ udelay(poll_delay_us);
} while (get_timer(start) < stop);
/*
@@ -418,7 +439,10 @@ static int spinand_reset_op(struct spinand_device *spinand)
if (ret)
return ret;
- return spinand_wait(spinand, NULL);
+ return spinand_wait(spinand,
+ SPINAND_RESET_INITIAL_DELAY_US,
+ SPINAND_RESET_POLL_DELAY_US,
+ NULL);
}
static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
@@ -466,7 +490,10 @@ static int spinand_read_page(struct spinand_device *spinand,
if (ret)
return ret;
- ret = spinand_wait(spinand, &status);
+ ret = spinand_wait(spinand,
+ SPINAND_READ_INITIAL_DELAY_US,
+ SPINAND_READ_POLL_DELAY_US,
+ &status);
if (ret < 0)
return ret;
@@ -498,9 +525,12 @@ static int spinand_write_page(struct spinand_device *spinand,
if (ret)
return ret;
- ret = spinand_wait(spinand, &status);
+ ret = spinand_wait(spinand,
+ SPINAND_WRITE_INITIAL_DELAY_US,
+ SPINAND_WRITE_POLL_DELAY_US,
+ &status);
if (!ret && (status & STATUS_PROG_FAILED))
- ret = -EIO;
+ return -EIO;
return ret;
}
@@ -702,7 +732,10 @@ static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos)
if (ret)
return ret;
- ret = spinand_wait(spinand, &status);
+ ret = spinand_wait(spinand,
+ SPINAND_ERASE_INITIAL_DELAY_US,
+ SPINAND_ERASE_POLL_DELAY_US,
+ &status);
if (!ret && (status & STATUS_ERASE_FAILED))
ret = -EIO;