[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241226135623.43098-4-mmkurbanov@salutedevices.com>
Date: Thu, 26 Dec 2024 16:55:48 +0300
From: Martin Kurbanov <mmkurbanov@...utedevices.com>
To: Miquel Raynal <miquel.raynal@...tlin.com>, Richard Weinberger
<richard@....at>, Vignesh Raghavendra <vigneshr@...com>, Ezra Buehler
<ezra.buehler@...qvarnagroup.com>, Alexey Romanov
<avromanov@...utedevices.com>, Frieder Schrempf <frieder.schrempf@...tron.de>
CC: <linux-kernel@...r.kernel.org>, <linux-mtd@...ts.infradead.org>,
<kernel@...utedevices.com>, Martin Kurbanov <mmkurbanov@...utedevices.com>
Subject: [PATCH v3 3/7] mtd: spinand: make spinand_{wait,otp_page_size} global
Change the functions spinand_wait() and spinand_otp_page_size() from
static to global so that SPI NAND flash drivers don't duplicate it.
Signed-off-by: Martin Kurbanov <mmkurbanov@...utedevices.com>
---
drivers/mtd/nand/spi/core.c | 18 ++++++++++++++----
drivers/mtd/nand/spi/otp.c | 19 ++++++++++++++-----
include/linux/mtd/spinand.h | 4 ++++
3 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index d12f09b28e371..018d6b6c61d10 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -496,10 +496,20 @@ static int spinand_erase_op(struct spinand_device *spinand,
return spi_mem_exec_op(spinand->spimem, &op);
}
-static int spinand_wait(struct spinand_device *spinand,
- unsigned long initial_delay_us,
- unsigned long poll_delay_us,
- 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.
+ */
+int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us,
+ unsigned long poll_delay_us, u8 *s)
{
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS,
spinand->scratchbuf);
diff --git a/drivers/mtd/nand/spi/otp.c b/drivers/mtd/nand/spi/otp.c
index 3650ff336db14..a50d6af818613 100644
--- a/drivers/mtd/nand/spi/otp.c
+++ b/drivers/mtd/nand/spi/otp.c
@@ -8,6 +8,19 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/spinand.h>
+/**
+ * spinand_otp_page_size() - Get SPI-NAND OTP page size
+ * @spinand: the spinand device
+ *
+ * Return: the OTP page size.
+ */
+size_t spinand_otp_page_size(struct spinand_device *spinand)
+{
+ struct nand_device *nand = spinand_to_nand(spinand);
+
+ return nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
+}
+
/**
* spinand_otp_size() - Get SPI-NAND OTP area size
* @spinand: the spinand device
@@ -16,11 +29,7 @@
*/
size_t spinand_otp_size(struct spinand_device *spinand)
{
- struct nand_device *nand = spinand_to_nand(spinand);
- size_t otp_pagesize = nanddev_page_size(nand) +
- nanddev_per_page_oobsize(nand);
-
- return spinand->otp->layout.npages * otp_pagesize;
+ return spinand->otp->layout.npages * spinand_otp_page_size(spinand);
}
static int spinand_otp_check_bounds(struct spinand_device *spinand, loff_t ofs,
diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h
index a9ad286de2902..19d76057c0444 100644
--- a/include/linux/mtd/spinand.h
+++ b/include/linux/mtd/spinand.h
@@ -567,12 +567,16 @@ int spinand_match_and_init(struct spinand_device *spinand,
int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
int spinand_select_target(struct spinand_device *spinand, unsigned int target);
+int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us,
+ unsigned long poll_delay_us, u8 *s);
+
int spinand_read_page(struct spinand_device *spinand,
const struct nand_page_io_req *req);
int spinand_write_page(struct spinand_device *spinand,
const struct nand_page_io_req *req);
+size_t spinand_otp_page_size(struct spinand_device *spinand);
size_t spinand_otp_size(struct spinand_device *spinand);
int spinand_set_mtd_otp_ops(struct spinand_device *spinand);
--
2.43.0
Powered by blists - more mailing lists