openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Potin Lai <potin.lai@quantatw.com>
To: openbmc@lists.ozlabs.org, joel@jms.id.au
Cc: Tudor Ambarus <tudor.ambarus@microchip.com>
Subject: [PATCH linux dev-5.15 14/26] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
Date: Fri, 25 Feb 2022 10:42:09 +0800	[thread overview]
Message-ID: <20220225024221.19422-15-potin.lai@quantatw.com> (raw)
In-Reply-To: <20220225024221.19422-1-potin.lai@quantatw.com>

From: Tudor Ambarus <tudor.ambarus@microchip.com>

Used to init all the mtd_info fields. Move the mtd_info init
the last thing in the spi_nor_scan(), so that we avoid superfluous
initialization of the mtd_info fields in case of errors.

While here use common naming scheme for functions that are setting
mtd_info fields:
s/spi_nor_register_locking_ops/spi_nor_set_mtd_locking_ops
s/spi_nor_otp_init/spi_nor_set_mtd_otp_ops
The functions names are self explanatory, get rid of the comment
for the OTP function.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/20211207140254.87681-4-tudor.ambarus@microchip.com
---
 drivers/mtd/spi-nor/core.c | 56 +++++++++++++++++++++-----------------
 drivers/mtd/spi-nor/core.h |  4 +--
 drivers/mtd/spi-nor/otp.c  |  2 +-
 drivers/mtd/spi-nor/swp.c  |  2 +-
 4 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 5b9c827d411c..dbb2c98c0366 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3080,6 +3080,35 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
 	return info;
 }
 
+static void spi_nor_set_mtd_info(struct spi_nor *nor)
+{
+	struct mtd_info *mtd = &nor->mtd;
+	struct device *dev = nor->dev;
+
+	spi_nor_set_mtd_locking_ops(nor);
+	spi_nor_set_mtd_otp_ops(nor);
+
+	mtd->dev.parent = dev;
+	if (!mtd->name)
+		mtd->name = dev_name(dev);
+	mtd->type = MTD_NORFLASH;
+	mtd->flags = MTD_CAP_NORFLASH;
+	if (nor->info->flags & SPI_NOR_NO_ERASE)
+		mtd->flags |= MTD_NO_ERASE;
+	mtd->writesize = nor->params->writesize;
+	mtd->writebufsize = nor->params->page_size;
+	mtd->size = nor->params->size;
+	mtd->_erase = spi_nor_erase;
+	mtd->_read = spi_nor_read;
+	/* Might be already set by some SST flashes. */
+	if (!mtd->_write)
+		mtd->_write = spi_nor_write;
+	mtd->_suspend = spi_nor_suspend;
+	mtd->_resume = spi_nor_resume;
+	mtd->_get_device = spi_nor_get_device;
+	mtd->_put_device = spi_nor_put_device;
+}
+
 int spi_nor_scan(struct spi_nor *nor, const char *name,
 		 const struct spi_nor_hwcaps *hwcaps)
 {
@@ -3134,26 +3163,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (info->flags & SPI_NOR_HAS_LOCK)
 		nor->flags |= SNOR_F_HAS_LOCK;
 
-	mtd->_write = spi_nor_write;
-
 	/* Init flash parameters based on flash_info struct and SFDP */
 	ret = spi_nor_init_params(nor);
 	if (ret)
 		return ret;
 
-	if (!mtd->name)
-		mtd->name = dev_name(dev);
-	mtd->type = MTD_NORFLASH;
-	mtd->writesize = nor->params->writesize;
-	mtd->flags = MTD_CAP_NORFLASH;
-	mtd->size = nor->params->size;
-	mtd->_erase = spi_nor_erase;
-	mtd->_read = spi_nor_read;
-	mtd->_suspend = spi_nor_suspend;
-	mtd->_resume = spi_nor_resume;
-	mtd->_get_device = spi_nor_get_device;
-	mtd->_put_device = spi_nor_put_device;
-
 	if (info->flags & USE_FSR)
 		nor->flags |= SNOR_F_USE_FSR;
 	if (info->flags & SPI_NOR_HAS_TB) {
@@ -3175,12 +3189,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
 	}
 
-	if (info->flags & SPI_NOR_NO_ERASE)
-		mtd->flags |= MTD_NO_ERASE;
-
-	mtd->dev.parent = dev;
-	mtd->writebufsize = nor->params->page_size;
-
 	if (of_property_read_bool(np, "broken-flash-reset"))
 		nor->flags |= SNOR_F_BROKEN_RESET;
 
@@ -3204,15 +3212,13 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (ret)
 		return ret;
 
-	spi_nor_register_locking_ops(nor);
-
 	/* Send all the required SPI flash commands to initialize device */
 	ret = spi_nor_init(nor);
 	if (ret)
 		return ret;
 
-	/* Configure OTP parameters and ops */
-	spi_nor_otp_init(nor);
+	/* No mtd_info fields should be used up to this point. */
+	spi_nor_set_mtd_info(nor);
 
 	dev_info(dev, "%s (%lld Kbytes)\n", info->name,
 			(long long)mtd->size >> 10);
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 50bae06bc024..f6c4b6f4743b 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -552,8 +552,8 @@ int spi_nor_post_bfpt_fixups(struct spi_nor *nor,
 
 void spi_nor_init_default_locking_ops(struct spi_nor *nor);
 void spi_nor_try_unlock_all(struct spi_nor *nor);
-void spi_nor_register_locking_ops(struct spi_nor *nor);
-void spi_nor_otp_init(struct spi_nor *nor);
+void spi_nor_set_mtd_locking_ops(struct spi_nor *nor);
+void spi_nor_set_mtd_otp_ops(struct spi_nor *nor);
 
 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
 {
diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c
index 983e40b19134..fa63d8571218 100644
--- a/drivers/mtd/spi-nor/otp.c
+++ b/drivers/mtd/spi-nor/otp.c
@@ -480,7 +480,7 @@ static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len)
 	return ret;
 }
 
-void spi_nor_otp_init(struct spi_nor *nor)
+void spi_nor_set_mtd_otp_ops(struct spi_nor *nor)
 {
 	struct mtd_info *mtd = &nor->mtd;
 
diff --git a/drivers/mtd/spi-nor/swp.c b/drivers/mtd/spi-nor/swp.c
index 8594bcbb7dbe..1f178313ba8f 100644
--- a/drivers/mtd/spi-nor/swp.c
+++ b/drivers/mtd/spi-nor/swp.c
@@ -414,7 +414,7 @@ void spi_nor_try_unlock_all(struct spi_nor *nor)
 		dev_dbg(nor->dev, "Failed to unlock the entire flash memory array\n");
 }
 
-void spi_nor_register_locking_ops(struct spi_nor *nor)
+void spi_nor_set_mtd_locking_ops(struct spi_nor *nor)
 {
 	struct mtd_info *mtd = &nor->mtd;
 
-- 
2.17.1


  parent reply	other threads:[~2022-02-25  2:52 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25  2:41 [PATCH linux dev-5.15 00/26] Add w25q01jvq and convert flash_info format Potin Lai
2022-02-25  2:41 ` [PATCH linux dev-5.15 01/26] mtd: spi-nor: Enable locking for n25q128a13 Potin Lai
2022-02-25  2:41 ` [PATCH linux dev-5.15 02/26] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description Potin Lai
2022-02-25  2:41 ` [PATCH linux dev-5.15 03/26] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor Potin Lai
2022-02-25  2:41 ` [PATCH linux dev-5.15 04/26] mtd: spi-nor: Get rid of nor->page_size Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 05/26] mtd: spi-nor: core: Introduce the late_init() hook Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 06/26] mtd: spi-nor: atmel: Use flash late_init() for locking Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 07/26] mtd: spi-nor: sst: " Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 08/26] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 09/26] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 10/26] mtd: spi-nor: sst: Use manufacturer late_init() to set _write() Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 11/26] mtd: spi-nor: spansion: Use manufacturer late_init() Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 12/26] mtd: spi-nor: Fix mtd size for s3an flashes Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 13/26] mtd: spi-nor: core: Don't use mtd_info in the NOR's probe sequence of calls Potin Lai
2022-02-25  2:42 ` Potin Lai [this message]
2022-02-25  2:42 ` [PATCH linux dev-5.15 15/26] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 16/26] mtd: spi-nor: core: Introduce flash_info mfr_flags Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 17/26] mtd: spi-nor: Rework the flash_info flags Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 18/26] mtd: spi-nor: Introduce spi_nor_init_flags() Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 19/26] mtd: spi-nor: Introduce spi_nor_init_fixup_flags() Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 20/26] mtd: spi-nor: core: Init all flash parameters based on SFDP where possible Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 21/26] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup() Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 22/26] mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 23/26] mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 24/26] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 25/26] mtd: spi-nor: issi: is25lp256: " Potin Lai
2022-02-25  2:42 ` [PATCH linux dev-5.15 26/26] mtd: spi-nor: winbond: Add support for w25q01jvq Potin Lai
2022-02-25  4:01 ` [PATCH linux dev-5.15 00/26] Add w25q01jvq and convert flash_info format Joel Stanley
2022-02-25  4:19   ` Potin Lai (賴柏廷)
2022-02-25  4:24     ` Joel Stanley

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=20220225024221.19422-15-potin.lai@quantatw.com \
    --to=potin.lai@quantatw.com \
    --cc=joel@jms.id.au \
    --cc=openbmc@lists.ozlabs.org \
    --cc=tudor.ambarus@microchip.com \
    /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;
as well as URLs for NNTP newsgroup(s).