All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-10-29 17:26 ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Clean spi_nor_scan() and the flash parameters initialization code. 
Tested all the flashes from patch set. If someone can test the
locking ops on few flashes would be great. It seems that my flashes
have the non volatile bits weared out.

This patch set is split from:
https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
The ID collision series will be set in a dedicated patch set that will
depend on this one.

Changes in v3:
- move late_init() in struct spi_nor_fixups and update patches accordingly.     
R-b tags were dropped.
- new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
moves manufacturer specific flag out of the core.
- update methods description to make it clear who sets when
- introduce flash_info flag masks to make it clear when one should be set.
- rework "parse SFDP first idea".

Tudor Ambarus (25):
  mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
  mtd: spi-nor: core: Use container_of to get the pointer to struct
    spi_nor
  mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  mtd: spi-nor: Get rid of nor->page_size
  mtd: spi-nor: core: Introduce the late_init() hook
  mtd: spi-nor: atmel: Use flash late_init() for locking
  mtd: spi-nor: sst: Use flash late_init() for locking
  mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
  mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
  mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  mtd: spi-nor: spansion: Use manufacturer late_init()
  mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is
    defined
  mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  mtd: spi-nor: Introduce flash_info flags masks
  mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
  mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
  mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
  mtd: spi-nor: core: Init flash params based on SFDP first for new
    flash additions
  mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
  mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
  mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
  mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
  mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
  mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP

 drivers/mtd/spi-nor/atmel.c      |   8 +-
 drivers/mtd/spi-nor/core.c       | 480 +++++++++++++++++--------------
 drivers/mtd/spi-nor/core.h       | 106 ++++---
 drivers/mtd/spi-nor/gigadevice.c |   7 +-
 drivers/mtd/spi-nor/issi.c       |   6 +-
 drivers/mtd/spi-nor/macronix.c   |  15 +-
 drivers/mtd/spi-nor/micron-st.c  |  20 +-
 drivers/mtd/spi-nor/otp.c        |   2 +-
 drivers/mtd/spi-nor/spansion.c   |  15 +-
 drivers/mtd/spi-nor/sst.c        | 105 ++++---
 drivers/mtd/spi-nor/swp.c        |   2 +-
 drivers/mtd/spi-nor/winbond.c    |   7 +-
 drivers/mtd/spi-nor/xilinx.c     |  21 +-
 include/linux/mtd/spi-nor.h      |   2 -
 14 files changed, 460 insertions(+), 336 deletions(-)

-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-10-29 17:26 ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Clean spi_nor_scan() and the flash parameters initialization code. 
Tested all the flashes from patch set. If someone can test the
locking ops on few flashes would be great. It seems that my flashes
have the non volatile bits weared out.

This patch set is split from:
https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
The ID collision series will be set in a dedicated patch set that will
depend on this one.

Changes in v3:
- move late_init() in struct spi_nor_fixups and update patches accordingly.     
R-b tags were dropped.
- new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
moves manufacturer specific flag out of the core.
- update methods description to make it clear who sets when
- introduce flash_info flag masks to make it clear when one should be set.
- rework "parse SFDP first idea".

Tudor Ambarus (25):
  mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
  mtd: spi-nor: core: Use container_of to get the pointer to struct
    spi_nor
  mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  mtd: spi-nor: Get rid of nor->page_size
  mtd: spi-nor: core: Introduce the late_init() hook
  mtd: spi-nor: atmel: Use flash late_init() for locking
  mtd: spi-nor: sst: Use flash late_init() for locking
  mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
  mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
  mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  mtd: spi-nor: spansion: Use manufacturer late_init()
  mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is
    defined
  mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  mtd: spi-nor: Introduce flash_info flags masks
  mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
  mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
  mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
  mtd: spi-nor: core: Init flash params based on SFDP first for new
    flash additions
  mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
  mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
  mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
  mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
  mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
  mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP

 drivers/mtd/spi-nor/atmel.c      |   8 +-
 drivers/mtd/spi-nor/core.c       | 480 +++++++++++++++++--------------
 drivers/mtd/spi-nor/core.h       | 106 ++++---
 drivers/mtd/spi-nor/gigadevice.c |   7 +-
 drivers/mtd/spi-nor/issi.c       |   6 +-
 drivers/mtd/spi-nor/macronix.c   |  15 +-
 drivers/mtd/spi-nor/micron-st.c  |  20 +-
 drivers/mtd/spi-nor/otp.c        |   2 +-
 drivers/mtd/spi-nor/spansion.c   |  15 +-
 drivers/mtd/spi-nor/sst.c        | 105 ++++---
 drivers/mtd/spi-nor/swp.c        |   2 +-
 drivers/mtd/spi-nor/winbond.c    |   7 +-
 drivers/mtd/spi-nor/xilinx.c     |  21 +-
 include/linux/mtd/spi-nor.h      |   2 -
 14 files changed, 460 insertions(+), 336 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Update the description of the otp member of the
struct spi_nor_flash_parameter.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 3348e1dd1445..da3fd3636d3c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -250,7 +250,7 @@ struct spi_nor_otp {
  *                      higher index in the array, the higher priority.
  * @erase_map:		the erase map parsed from the SFDP Sector Map Parameter
  *                      Table.
- * @otp_info:		describes the OTP regions.
+ * @otp:		SPI NOR OTP info.
  * @octal_dtr_enable:	enables SPI NOR octal DTR mode.
  * @quad_enable:	enables SPI NOR quad mode.
  * @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
@@ -262,7 +262,6 @@ struct spi_nor_otp {
  *                      e.g. different opcodes, specific address calculation,
  *                      page size, etc.
  * @locking_ops:	SPI NOR locking methods.
- * @otp:		SPI NOR OTP methods.
  */
 struct spi_nor_flash_parameter {
 	u64				size;
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Update the description of the otp member of the
struct spi_nor_flash_parameter.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 3348e1dd1445..da3fd3636d3c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -250,7 +250,7 @@ struct spi_nor_otp {
  *                      higher index in the array, the higher priority.
  * @erase_map:		the erase map parsed from the SFDP Sector Map Parameter
  *                      Table.
- * @otp_info:		describes the OTP regions.
+ * @otp:		SPI NOR OTP info.
  * @octal_dtr_enable:	enables SPI NOR octal DTR mode.
  * @quad_enable:	enables SPI NOR quad mode.
  * @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
@@ -262,7 +262,6 @@ struct spi_nor_otp {
  *                      e.g. different opcodes, specific address calculation,
  *                      page size, etc.
  * @locking_ops:	SPI NOR locking methods.
- * @otp:		SPI NOR OTP methods.
  */
 struct spi_nor_flash_parameter {
 	u64				size;
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

"struct mtd_info mtd" is member of "struct spi_nor", there's no need
to use "mtd->priv". Get the pointer to the containing struct spi_nor
by using container_of. While here, make the function inline and
get rid of the __maybe_unused.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 1 -
 drivers/mtd/spi-nor/core.h | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index cc08bd707378..277d1fde84c8 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3134,7 +3134,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 
 	if (!mtd->name)
 		mtd->name = dev_name(dev);
-	mtd->priv = nor;
 	mtd->type = MTD_NORFLASH;
 	mtd->writesize = nor->params->writesize;
 	mtd->flags = MTD_CAP_NORFLASH;
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index da3fd3636d3c..223a03769950 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -551,9 +551,9 @@ 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);
 
-static struct spi_nor __maybe_unused *mtd_to_spi_nor(struct mtd_info *mtd)
+static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
 {
-	return mtd->priv;
+	return container_of(mtd, struct spi_nor, mtd);
 }
 
 #endif /* __LINUX_MTD_SPI_NOR_INTERNAL_H */
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

"struct mtd_info mtd" is member of "struct spi_nor", there's no need
to use "mtd->priv". Get the pointer to the containing struct spi_nor
by using container_of. While here, make the function inline and
get rid of the __maybe_unused.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 1 -
 drivers/mtd/spi-nor/core.h | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index cc08bd707378..277d1fde84c8 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3134,7 +3134,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 
 	if (!mtd->name)
 		mtd->name = dev_name(dev);
-	mtd->priv = nor;
 	mtd->type = MTD_NORFLASH;
 	mtd->writesize = nor->params->writesize;
 	mtd->flags = MTD_CAP_NORFLASH;
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index da3fd3636d3c..223a03769950 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -551,9 +551,9 @@ 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);
 
-static struct spi_nor __maybe_unused *mtd_to_spi_nor(struct mtd_info *mtd)
+static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
 {
-	return mtd->priv;
+	return container_of(mtd, struct spi_nor, mtd);
 }
 
 #endif /* __LINUX_MTD_SPI_NOR_INTERNAL_H */
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

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>
---
 drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
 drivers/mtd/spi-nor/core.h |  4 +--
 drivers/mtd/spi-nor/otp.c  |  2 +-
 drivers/mtd/spi-nor/swp.c  |  2 +-
 4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 277d1fde84c8..ae971c773334 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3071,6 +3071,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->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)
 {
@@ -3125,26 +3154,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) {
@@ -3166,12 +3180,7 @@ 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;
 	nor->page_size = nor->params->page_size;
-	mtd->writebufsize = nor->page_size;
 
 	if (of_property_read_bool(np, "broken-flash-reset"))
 		nor->flags |= SNOR_F_BROKEN_RESET;
@@ -3196,15 +3205,12 @@ 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);
+	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 223a03769950..48f26d3f1b3c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -548,8 +548,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.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

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>
---
 drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
 drivers/mtd/spi-nor/core.h |  4 +--
 drivers/mtd/spi-nor/otp.c  |  2 +-
 drivers/mtd/spi-nor/swp.c  |  2 +-
 4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 277d1fde84c8..ae971c773334 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3071,6 +3071,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->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)
 {
@@ -3125,26 +3154,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) {
@@ -3166,12 +3180,7 @@ 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;
 	nor->page_size = nor->params->page_size;
-	mtd->writebufsize = nor->page_size;
 
 	if (of_property_read_bool(np, "broken-flash-reset"))
 		nor->flags |= SNOR_F_BROKEN_RESET;
@@ -3196,15 +3205,12 @@ 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);
+	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 223a03769950..48f26d3f1b3c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -548,8 +548,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.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

nor->page_size duplicated what nor->params->page_size indicates
for no good reason. page_size is a flash parameter of fixed value
and it is better suited to be found in nor->params->page_size.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.c   | 20 +++++++++-----------
 drivers/mtd/spi-nor/xilinx.c | 17 ++++++++++-------
 include/linux/mtd/spi-nor.h  |  2 --
 3 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ae971c773334..13515ad12bf1 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1952,6 +1952,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	size_t page_offset, page_remain, i;
 	ssize_t ret;
+	u32 page_size = nor->params->page_size;
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
@@ -1968,16 +1969,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		 * calculated with an AND operation. On the other cases we
 		 * need to do a modulus operation (more expensive).
 		 */
-		if (is_power_of_2(nor->page_size)) {
-			page_offset = addr & (nor->page_size - 1);
+		if (is_power_of_2(page_size)) {
+			page_offset = addr & (page_size - 1);
 		} else {
 			uint64_t aux = addr;
 
-			page_offset = do_div(aux, nor->page_size);
+			page_offset = do_div(aux, page_size);
 		}
 		/* the size of data remaining on the first page */
-		page_remain = min_t(size_t,
-				    nor->page_size - page_offset, len - i);
+		page_remain = min_t(size_t, page_size - page_offset, len - i);
 
 		addr = spi_nor_convert_addr(nor, addr);
 
@@ -3087,7 +3087,7 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	if (nor->info->flags & SPI_NOR_NO_ERASE)
 		mtd->flags |= MTD_NO_ERASE;
 	mtd->writesize = nor->params->writesize;
-	mtd->writebufsize = nor->page_size;
+	mtd->writebufsize = nor->params->page_size;
 	mtd->size = nor->params->size;
 	mtd->_erase = spi_nor_erase;
 	mtd->_read = spi_nor_read;
@@ -3123,7 +3123,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	 * We need the bounce buffer early to read/write registers when going
 	 * through the spi-mem layer (buffers have to be DMA-able).
 	 * For spi-mem drivers, we'll reallocate a new buffer if
-	 * nor->page_size turns out to be greater than PAGE_SIZE (which
+	 * nor->params->page_size turns out to be greater than PAGE_SIZE (which
 	 * shouldn't happen before long since NOR pages are usually less
 	 * than 1KB) after spi_nor_scan() returns.
 	 */
@@ -3180,8 +3180,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
 	}
 
-	nor->page_size = nor->params->page_size;
-
 	if (of_property_read_bool(np, "broken-flash-reset"))
 		nor->flags |= SNOR_F_BROKEN_RESET;
 
@@ -3346,8 +3344,8 @@ static int spi_nor_probe(struct spi_mem *spimem)
 	 * and add this logic so that if anyone ever adds support for such
 	 * a NOR we don't end up with buffer overflows.
 	 */
-	if (nor->page_size > PAGE_SIZE) {
-		nor->bouncebuf_size = nor->page_size;
+	if (nor->params->page_size > PAGE_SIZE) {
+		nor->bouncebuf_size = nor->params->page_size;
 		devm_kfree(nor->dev, nor->bouncebuf);
 		nor->bouncebuf = devm_kmalloc(nor->dev,
 					      nor->bouncebuf_size,
diff --git a/drivers/mtd/spi-nor/xilinx.c b/drivers/mtd/spi-nor/xilinx.c
index 1138bdbf4199..0658e47564ba 100644
--- a/drivers/mtd/spi-nor/xilinx.c
+++ b/drivers/mtd/spi-nor/xilinx.c
@@ -28,11 +28,12 @@ static const struct flash_info xilinx_parts[] = {
  */
 static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
 {
+	u32 page_size = nor->params->page_size;
 	u32 offset, page;
 
-	offset = addr % nor->page_size;
-	page = addr / nor->page_size;
-	page <<= (nor->page_size > 512) ? 10 : 9;
+	offset = addr % page_size;
+	page = addr / page_size;
+	page <<= (page_size > 512) ? 10 : 9;
 
 	return page | offset;
 }
@@ -40,6 +41,7 @@ static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
 static int xilinx_nor_setup(struct spi_nor *nor,
 			    const struct spi_nor_hwcaps *hwcaps)
 {
+	u32 page_size;
 	int ret;
 
 	ret = spi_nor_xread_sr(nor, nor->bouncebuf);
@@ -64,10 +66,11 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 	 */
 	if (nor->bouncebuf[0] & XSR_PAGESIZE) {
 		/* Flash in Power of 2 mode */
-		nor->page_size = (nor->page_size == 264) ? 256 : 512;
-		nor->mtd.writebufsize = nor->page_size;
-		nor->mtd.size = 8 * nor->page_size * nor->info->n_sectors;
-		nor->mtd.erasesize = 8 * nor->page_size;
+		page_size = (nor->params->page_size == 264) ? 256 : 512;
+		nor->params->page_size = page_size;
+		nor->mtd.writebufsize = page_size;
+		nor->mtd.size = 8 * page_size * nor->info->n_sectors;
+		nor->mtd.erasesize = 8 * page_size;
 	} else {
 		/* Flash in Default addressing mode */
 		nor->params->convert_addr = s3an_convert_addr;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index f67457748ed8..fc90fce26e33 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -371,7 +371,6 @@ struct spi_nor_flash_parameter;
  * @bouncebuf_size:	size of the bounce buffer
  * @info:		SPI NOR part JEDEC MFR ID and other info
  * @manufacturer:	SPI NOR manufacturer
- * @page_size:		the page size of the SPI NOR
  * @addr_width:		number of address bytes
  * @erase_opcode:	the opcode for erasing a sector
  * @read_opcode:	the read opcode
@@ -401,7 +400,6 @@ struct spi_nor {
 	size_t			bouncebuf_size;
 	const struct flash_info	*info;
 	const struct spi_nor_manufacturer *manufacturer;
-	u32			page_size;
 	u8			addr_width;
 	u8			erase_opcode;
 	u8			read_opcode;
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

nor->page_size duplicated what nor->params->page_size indicates
for no good reason. page_size is a flash parameter of fixed value
and it is better suited to be found in nor->params->page_size.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.c   | 20 +++++++++-----------
 drivers/mtd/spi-nor/xilinx.c | 17 ++++++++++-------
 include/linux/mtd/spi-nor.h  |  2 --
 3 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ae971c773334..13515ad12bf1 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1952,6 +1952,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
 	size_t page_offset, page_remain, i;
 	ssize_t ret;
+	u32 page_size = nor->params->page_size;
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
@@ -1968,16 +1969,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 		 * calculated with an AND operation. On the other cases we
 		 * need to do a modulus operation (more expensive).
 		 */
-		if (is_power_of_2(nor->page_size)) {
-			page_offset = addr & (nor->page_size - 1);
+		if (is_power_of_2(page_size)) {
+			page_offset = addr & (page_size - 1);
 		} else {
 			uint64_t aux = addr;
 
-			page_offset = do_div(aux, nor->page_size);
+			page_offset = do_div(aux, page_size);
 		}
 		/* the size of data remaining on the first page */
-		page_remain = min_t(size_t,
-				    nor->page_size - page_offset, len - i);
+		page_remain = min_t(size_t, page_size - page_offset, len - i);
 
 		addr = spi_nor_convert_addr(nor, addr);
 
@@ -3087,7 +3087,7 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
 	if (nor->info->flags & SPI_NOR_NO_ERASE)
 		mtd->flags |= MTD_NO_ERASE;
 	mtd->writesize = nor->params->writesize;
-	mtd->writebufsize = nor->page_size;
+	mtd->writebufsize = nor->params->page_size;
 	mtd->size = nor->params->size;
 	mtd->_erase = spi_nor_erase;
 	mtd->_read = spi_nor_read;
@@ -3123,7 +3123,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	 * We need the bounce buffer early to read/write registers when going
 	 * through the spi-mem layer (buffers have to be DMA-able).
 	 * For spi-mem drivers, we'll reallocate a new buffer if
-	 * nor->page_size turns out to be greater than PAGE_SIZE (which
+	 * nor->params->page_size turns out to be greater than PAGE_SIZE (which
 	 * shouldn't happen before long since NOR pages are usually less
 	 * than 1KB) after spi_nor_scan() returns.
 	 */
@@ -3180,8 +3180,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
 	}
 
-	nor->page_size = nor->params->page_size;
-
 	if (of_property_read_bool(np, "broken-flash-reset"))
 		nor->flags |= SNOR_F_BROKEN_RESET;
 
@@ -3346,8 +3344,8 @@ static int spi_nor_probe(struct spi_mem *spimem)
 	 * and add this logic so that if anyone ever adds support for such
 	 * a NOR we don't end up with buffer overflows.
 	 */
-	if (nor->page_size > PAGE_SIZE) {
-		nor->bouncebuf_size = nor->page_size;
+	if (nor->params->page_size > PAGE_SIZE) {
+		nor->bouncebuf_size = nor->params->page_size;
 		devm_kfree(nor->dev, nor->bouncebuf);
 		nor->bouncebuf = devm_kmalloc(nor->dev,
 					      nor->bouncebuf_size,
diff --git a/drivers/mtd/spi-nor/xilinx.c b/drivers/mtd/spi-nor/xilinx.c
index 1138bdbf4199..0658e47564ba 100644
--- a/drivers/mtd/spi-nor/xilinx.c
+++ b/drivers/mtd/spi-nor/xilinx.c
@@ -28,11 +28,12 @@ static const struct flash_info xilinx_parts[] = {
  */
 static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
 {
+	u32 page_size = nor->params->page_size;
 	u32 offset, page;
 
-	offset = addr % nor->page_size;
-	page = addr / nor->page_size;
-	page <<= (nor->page_size > 512) ? 10 : 9;
+	offset = addr % page_size;
+	page = addr / page_size;
+	page <<= (page_size > 512) ? 10 : 9;
 
 	return page | offset;
 }
@@ -40,6 +41,7 @@ static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
 static int xilinx_nor_setup(struct spi_nor *nor,
 			    const struct spi_nor_hwcaps *hwcaps)
 {
+	u32 page_size;
 	int ret;
 
 	ret = spi_nor_xread_sr(nor, nor->bouncebuf);
@@ -64,10 +66,11 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 	 */
 	if (nor->bouncebuf[0] & XSR_PAGESIZE) {
 		/* Flash in Power of 2 mode */
-		nor->page_size = (nor->page_size == 264) ? 256 : 512;
-		nor->mtd.writebufsize = nor->page_size;
-		nor->mtd.size = 8 * nor->page_size * nor->info->n_sectors;
-		nor->mtd.erasesize = 8 * nor->page_size;
+		page_size = (nor->params->page_size == 264) ? 256 : 512;
+		nor->params->page_size = page_size;
+		nor->mtd.writebufsize = page_size;
+		nor->mtd.size = 8 * page_size * nor->info->n_sectors;
+		nor->mtd.erasesize = 8 * page_size;
 	} else {
 		/* Flash in Default addressing mode */
 		nor->params->convert_addr = s3an_convert_addr;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index f67457748ed8..fc90fce26e33 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -371,7 +371,6 @@ struct spi_nor_flash_parameter;
  * @bouncebuf_size:	size of the bounce buffer
  * @info:		SPI NOR part JEDEC MFR ID and other info
  * @manufacturer:	SPI NOR manufacturer
- * @page_size:		the page size of the SPI NOR
  * @addr_width:		number of address bytes
  * @erase_opcode:	the opcode for erasing a sector
  * @read_opcode:	the read opcode
@@ -401,7 +400,6 @@ struct spi_nor {
 	size_t			bouncebuf_size;
 	const struct flash_info	*info;
 	const struct spi_nor_manufacturer *manufacturer;
-	u32			page_size;
 	u8			addr_width;
 	u8			erase_opcode;
 	u8			read_opcode;
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Flash parameters init is done in a spaghetti way right now.
There is the init based on the flash_info data, then there is the
default_init() hook, then SFDP init, an intermediary post_bft(),
then post_sfdp() and a spi_nor_late_init_params(). Each method can
overwrite previuosly initialized parameters.

We want to separate what is SFDP and non-SFDP specific. late_init()
will replace the default_init() hook and will be used only to initialize
flash parameters that are not declared in the JESD216 SFDP standard, or
where SFDP tables are not defined at all.
We cut a member in the chain of initializing parameters by getting rid
of the default_init() hook, and we make it clear that everything that is
in late_init() is not covered by the SFDP tables defined by the flash.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 17 +++++++++++++----
 drivers/mtd/spi-nor/core.h |  4 ++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 13515ad12bf1..4679298c5301 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2666,11 +2666,19 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
  *
- * Used to set default flash parameters and settings when the ->default_init()
- * hook or the SFDP parser let voids.
+ * Used to initialize flash parameters that are not declared in the JESD216
+ * SFDP standard, or where SFDP tables are not defined at all.
+ * Will replace the spi_nor_manufacturer_init_params() method.
  */
 static void spi_nor_late_init_params(struct spi_nor *nor)
 {
+	if (nor->manufacturer && nor->manufacturer->fixups &&
+	    nor->manufacturer->fixups->late_init)
+		nor->manufacturer->fixups->late_init(nor);
+
+	if (nor->info->fixups && nor->info->fixups->late_init)
+		nor->info->fixups->late_init(nor);
+
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
 	 * the default ones.
@@ -2712,8 +2720,9 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
  *    wrong).
  *		spi_nor_post_sfdp_fixups()
  *
- * 5/ Late default flash parameters initialization, used when the
- * ->default_init() hook or the SFDP parser do not set specific params.
+ * 5/ Late flash parameters initialization, used to initialize flash
+ * parameters that are not declared in the JESD216 SFDP standard, or where SFDP
+ * tables are not defined at all.
  *		spi_nor_late_init_params()
  */
 static int spi_nor_init_params(struct spi_nor *nor)
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 48f26d3f1b3c..f6c4b6f4743b 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -297,6 +297,9 @@ struct spi_nor_flash_parameter {
  *             parameters that could not be extracted by other means (i.e.
  *             when information provided by the SFDP/flash_info tables are
  *             incomplete or wrong).
+ * @late_init: used to initialize flash parameters that are not declared in the
+ *             JESD216 SFDP standard, or where SFDP tables not defined at all.
+ *             Will replace the default_init() hook.
  *
  * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
  * table is broken or not available.
@@ -307,6 +310,7 @@ struct spi_nor_fixups {
 			 const struct sfdp_parameter_header *bfpt_header,
 			 const struct sfdp_bfpt *bfpt);
 	void (*post_sfdp)(struct spi_nor *nor);
+	void (*late_init)(struct spi_nor *nor);
 };
 
 struct flash_info {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Flash parameters init is done in a spaghetti way right now.
There is the init based on the flash_info data, then there is the
default_init() hook, then SFDP init, an intermediary post_bft(),
then post_sfdp() and a spi_nor_late_init_params(). Each method can
overwrite previuosly initialized parameters.

We want to separate what is SFDP and non-SFDP specific. late_init()
will replace the default_init() hook and will be used only to initialize
flash parameters that are not declared in the JESD216 SFDP standard, or
where SFDP tables are not defined at all.
We cut a member in the chain of initializing parameters by getting rid
of the default_init() hook, and we make it clear that everything that is
in late_init() is not covered by the SFDP tables defined by the flash.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 17 +++++++++++++----
 drivers/mtd/spi-nor/core.h |  4 ++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 13515ad12bf1..4679298c5301 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2666,11 +2666,19 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
  *
- * Used to set default flash parameters and settings when the ->default_init()
- * hook or the SFDP parser let voids.
+ * Used to initialize flash parameters that are not declared in the JESD216
+ * SFDP standard, or where SFDP tables are not defined at all.
+ * Will replace the spi_nor_manufacturer_init_params() method.
  */
 static void spi_nor_late_init_params(struct spi_nor *nor)
 {
+	if (nor->manufacturer && nor->manufacturer->fixups &&
+	    nor->manufacturer->fixups->late_init)
+		nor->manufacturer->fixups->late_init(nor);
+
+	if (nor->info->fixups && nor->info->fixups->late_init)
+		nor->info->fixups->late_init(nor);
+
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
 	 * the default ones.
@@ -2712,8 +2720,9 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
  *    wrong).
  *		spi_nor_post_sfdp_fixups()
  *
- * 5/ Late default flash parameters initialization, used when the
- * ->default_init() hook or the SFDP parser do not set specific params.
+ * 5/ Late flash parameters initialization, used to initialize flash
+ * parameters that are not declared in the JESD216 SFDP standard, or where SFDP
+ * tables are not defined at all.
  *		spi_nor_late_init_params()
  */
 static int spi_nor_init_params(struct spi_nor *nor)
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 48f26d3f1b3c..f6c4b6f4743b 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -297,6 +297,9 @@ struct spi_nor_flash_parameter {
  *             parameters that could not be extracted by other means (i.e.
  *             when information provided by the SFDP/flash_info tables are
  *             incomplete or wrong).
+ * @late_init: used to initialize flash parameters that are not declared in the
+ *             JESD216 SFDP standard, or where SFDP tables not defined at all.
+ *             Will replace the default_init() hook.
  *
  * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
  * table is broken or not available.
@@ -307,6 +310,7 @@ struct spi_nor_fixups {
 			 const struct sfdp_parameter_header *bfpt_header,
 			 const struct sfdp_bfpt *bfpt);
 	void (*post_sfdp)(struct spi_nor *nor);
+	void (*late_init)(struct spi_nor *nor);
 };
 
 struct flash_info {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Locking is not described in JESD216 SFDP standard, place the
locking init in late_init().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/atmel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c
index 1fea5cab492c..d0e7883b38e3 100644
--- a/drivers/mtd/spi-nor/atmel.c
+++ b/drivers/mtd/spi-nor/atmel.c
@@ -48,13 +48,13 @@ static const struct spi_nor_locking_ops atmel_at25fs_locking_ops = {
 	.is_locked = atmel_at25fs_is_locked,
 };
 
-static void atmel_at25fs_default_init(struct spi_nor *nor)
+static void atmel_at25fs_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &atmel_at25fs_locking_ops;
 }
 
 static const struct spi_nor_fixups atmel_at25fs_fixups = {
-	.default_init = atmel_at25fs_default_init,
+	.late_init = atmel_at25fs_late_init,
 };
 
 /**
@@ -146,13 +146,13 @@ static const struct spi_nor_locking_ops atmel_global_protection_ops = {
 	.is_locked = atmel_is_global_protected,
 };
 
-static void atmel_global_protection_default_init(struct spi_nor *nor)
+static void atmel_global_protection_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &atmel_global_protection_ops;
 }
 
 static const struct spi_nor_fixups atmel_global_protection_fixups = {
-	.default_init = atmel_global_protection_default_init,
+	.late_init = atmel_global_protection_late_init,
 };
 
 static const struct flash_info atmel_parts[] = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Locking is not described in JESD216 SFDP standard, place the
locking init in late_init().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/atmel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c
index 1fea5cab492c..d0e7883b38e3 100644
--- a/drivers/mtd/spi-nor/atmel.c
+++ b/drivers/mtd/spi-nor/atmel.c
@@ -48,13 +48,13 @@ static const struct spi_nor_locking_ops atmel_at25fs_locking_ops = {
 	.is_locked = atmel_at25fs_is_locked,
 };
 
-static void atmel_at25fs_default_init(struct spi_nor *nor)
+static void atmel_at25fs_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &atmel_at25fs_locking_ops;
 }
 
 static const struct spi_nor_fixups atmel_at25fs_fixups = {
-	.default_init = atmel_at25fs_default_init,
+	.late_init = atmel_at25fs_late_init,
 };
 
 /**
@@ -146,13 +146,13 @@ static const struct spi_nor_locking_ops atmel_global_protection_ops = {
 	.is_locked = atmel_is_global_protected,
 };
 
-static void atmel_global_protection_default_init(struct spi_nor *nor)
+static void atmel_global_protection_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &atmel_global_protection_ops;
 }
 
 static const struct spi_nor_fixups atmel_global_protection_fixups = {
-	.default_init = atmel_global_protection_default_init,
+	.late_init = atmel_global_protection_late_init,
 };
 
 static const struct flash_info atmel_parts[] = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Locking is not described in JESD216 SFDP standard, place the
locking init in late_init().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 980f4c09c91d..660aabde477a 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -46,13 +46,13 @@ static const struct spi_nor_locking_ops sst26vf_locking_ops = {
 	.is_locked = sst26vf_is_locked,
 };
 
-static void sst26vf_default_init(struct spi_nor *nor)
+static void sst26vf_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &sst26vf_locking_ops;
 }
 
 static const struct spi_nor_fixups sst26vf_fixups = {
-	.default_init = sst26vf_default_init,
+	.late_init = sst26vf_late_init,
 };
 
 static const struct flash_info sst_parts[] = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Locking is not described in JESD216 SFDP standard, place the
locking init in late_init().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 980f4c09c91d..660aabde477a 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -46,13 +46,13 @@ static const struct spi_nor_locking_ops sst26vf_locking_ops = {
 	.is_locked = sst26vf_is_locked,
 };
 
-static void sst26vf_default_init(struct spi_nor *nor)
+static void sst26vf_late_init(struct spi_nor *nor)
 {
 	nor->params->locking_ops = &sst26vf_locking_ops;
 }
 
 static const struct spi_nor_fixups sst26vf_fixups = {
-	.default_init = sst26vf_default_init,
+	.late_init = sst26vf_late_init,
 };
 
 static const struct flash_info sst_parts[] = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

OTP is not described in the JESD216 SFDP standard, place the
OTP ops init in late_init().

We can't get rid of the default_init() hook for winbond, as the
4byte_addr_mode is SFDP specific and will require to have all
flashes at hand, in order to check which has the SFDP tables defined,
in which case there's nothing to do if the SFDP tables are corect,
and which of the flashes do not define the SFDP tables in which case
each flash should declare a late_init() fixup.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/winbond.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index 96573f61caf5..dd4be0f78e67 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -147,12 +147,17 @@ static const struct spi_nor_otp_ops winbond_otp_ops = {
 static void winbond_default_init(struct spi_nor *nor)
 {
 	nor->params->set_4byte_addr_mode = winbond_set_4byte_addr_mode;
+}
+
+static void winbond_late_init(struct spi_nor *nor)
+{
 	if (nor->params->otp.org->n_regions)
 		nor->params->otp.ops = &winbond_otp_ops;
 }
 
 static const struct spi_nor_fixups winbond_fixups = {
 	.default_init = winbond_default_init,
+	.late_init = winbond_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_winbond = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

OTP is not described in the JESD216 SFDP standard, place the
OTP ops init in late_init().

We can't get rid of the default_init() hook for winbond, as the
4byte_addr_mode is SFDP specific and will require to have all
flashes at hand, in order to check which has the SFDP tables defined,
in which case there's nothing to do if the SFDP tables are corect,
and which of the flashes do not define the SFDP tables in which case
each flash should declare a late_init() fixup.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/winbond.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index 96573f61caf5..dd4be0f78e67 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -147,12 +147,17 @@ static const struct spi_nor_otp_ops winbond_otp_ops = {
 static void winbond_default_init(struct spi_nor *nor)
 {
 	nor->params->set_4byte_addr_mode = winbond_set_4byte_addr_mode;
+}
+
+static void winbond_late_init(struct spi_nor *nor)
+{
 	if (nor->params->otp.org->n_regions)
 		nor->params->otp.ops = &winbond_otp_ops;
 }
 
 static const struct spi_nor_fixups winbond_fixups = {
 	.default_init = winbond_default_init,
+	.late_init = winbond_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_winbond = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

post_sfdp was misleading in this case, as SFDP is not supported by
xilinx. Plus, there's no fixup here, just setting the correct
setup method, as required by xilinx parts.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/xilinx.c b/drivers/mtd/spi-nor/xilinx.c
index 0658e47564ba..7e970ccf7903 100644
--- a/drivers/mtd/spi-nor/xilinx.c
+++ b/drivers/mtd/spi-nor/xilinx.c
@@ -80,13 +80,13 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 	return 0;
 }
 
-static void xilinx_post_sfdp_fixups(struct spi_nor *nor)
+static void xilinx_late_init(struct spi_nor *nor)
 {
 	nor->params->setup = xilinx_nor_setup;
 }
 
 static const struct spi_nor_fixups xilinx_fixups = {
-	.post_sfdp = xilinx_post_sfdp_fixups,
+	.late_init = xilinx_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_xilinx = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

post_sfdp was misleading in this case, as SFDP is not supported by
xilinx. Plus, there's no fixup here, just setting the correct
setup method, as required by xilinx parts.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/xilinx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/xilinx.c b/drivers/mtd/spi-nor/xilinx.c
index 0658e47564ba..7e970ccf7903 100644
--- a/drivers/mtd/spi-nor/xilinx.c
+++ b/drivers/mtd/spi-nor/xilinx.c
@@ -80,13 +80,13 @@ static int xilinx_nor_setup(struct spi_nor *nor,
 	return 0;
 }
 
-static void xilinx_post_sfdp_fixups(struct spi_nor *nor)
+static void xilinx_late_init(struct spi_nor *nor)
 {
 	nor->params->setup = xilinx_nor_setup;
 }
 
 static const struct spi_nor_fixups xilinx_fixups = {
-	.post_sfdp = xilinx_post_sfdp_fixups,
+	.late_init = xilinx_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_xilinx = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Setting the correct nor->mtd._write in a fixup hook was misleading,
since this is not a fixup, just a specific setting for SST, that differs
from the SPI NOR core default init.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 660aabde477a..3593aae0920f 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return ret;
 }
 
-static void sst_post_sfdp_fixups(struct spi_nor *nor)
+static void sst_late_init(struct spi_nor *nor)
 {
 	if (nor->info->flags & SST_WRITE)
 		nor->mtd._write = sst_write;
 }
 
 static const struct spi_nor_fixups sst_fixups = {
-	.post_sfdp = sst_post_sfdp_fixups,
+	.late_init = sst_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_sst = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Setting the correct nor->mtd._write in a fixup hook was misleading,
since this is not a fixup, just a specific setting for SST, that differs
from the SPI NOR core default init.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 660aabde477a..3593aae0920f 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return ret;
 }
 
-static void sst_post_sfdp_fixups(struct spi_nor *nor)
+static void sst_late_init(struct spi_nor *nor)
 {
 	if (nor->info->flags & SST_WRITE)
 		nor->mtd._write = sst_write;
 }
 
 static const struct spi_nor_fixups sst_fixups = {
-	.post_sfdp = sst_post_sfdp_fixups,
+	.late_init = sst_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_sst = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

spansion_post_sfdp_fixups() was called regardless if the flash defined
SFDP tables or not. A better place for this kind of parameters init is
in manufacturer's late_init() hook. post_sfdp() should be called only
when SFDP is defined. No functional change in this patch.

Instead of doing the 4b opcodes settings at manufacturer level, thus
also for every flash that will be introduced, this should be done
just where it is needed, per flash. I'll let this for other patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/spansion.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index ee82dcd75310..a3ea0135f7b1 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -276,7 +276,7 @@ static const struct flash_info spansion_parts[] = {
 	},
 };
 
-static void spansion_post_sfdp_fixups(struct spi_nor *nor)
+static void spansion_late_init(struct spi_nor *nor)
 {
 	if (nor->params->size <= SZ_16M)
 		return;
@@ -288,7 +288,7 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor)
 }
 
 static const struct spi_nor_fixups spansion_fixups = {
-	.post_sfdp = spansion_post_sfdp_fixups,
+	.late_init = spansion_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_spansion = {
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

spansion_post_sfdp_fixups() was called regardless if the flash defined
SFDP tables or not. A better place for this kind of parameters init is
in manufacturer's late_init() hook. post_sfdp() should be called only
when SFDP is defined. No functional change in this patch.

Instead of doing the 4b opcodes settings at manufacturer level, thus
also for every flash that will be introduced, this should be done
just where it is needed, per flash. I'll let this for other patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/spansion.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index ee82dcd75310..a3ea0135f7b1 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -276,7 +276,7 @@ static const struct flash_info spansion_parts[] = {
 	},
 };
 
-static void spansion_post_sfdp_fixups(struct spi_nor *nor)
+static void spansion_late_init(struct spi_nor *nor)
 {
 	if (nor->params->size <= SZ_16M)
 		return;
@@ -288,7 +288,7 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor)
 }
 
 static const struct spi_nor_fixups spansion_fixups = {
-	.post_sfdp = spansion_post_sfdp_fixups,
+	.late_init = spansion_late_init,
 };
 
 const struct spi_nor_manufacturer spi_nor_spansion = {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

spi_nor_post_sfdp_fixups() was called even when there were no SFDP
tables defined. late_init() should be instead used for flashes that
do not define SFDP tables.

Use spi_nor_post_sfdp_fixups() just to fix SFDP data. post_sfdp()
hook is as of now used just by s28hs512t, mt35xu512aba, and both
support SFDP, there's no functional change with this patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 56 ++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 4679298c5301..82cc56c9d09e 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2508,6 +2508,25 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor)
 		nor->info->fixups->default_init(nor);
 }
 
+/**
+ * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
+ * after SFDP has been parsed. Called only for flashes that define JESD216 SFDP
+ * tables.
+ * @nor:	pointer to a 'struct spi_nor'
+ *
+ * Used to tweak various flash parameters when information provided by the SFDP
+ * tables are wrong.
+ */
+static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
+{
+	if (nor->manufacturer && nor->manufacturer->fixups &&
+	    nor->manufacturer->fixups->post_sfdp)
+		nor->manufacturer->fixups->post_sfdp(nor);
+
+	if (nor->info->fixups && nor->info->fixups->post_sfdp)
+		nor->info->fixups->post_sfdp(nor);
+}
+
 /**
  * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
  * based on JESD216 SFDP standard.
@@ -2522,7 +2541,9 @@ static void spi_nor_sfdp_init_params(struct spi_nor *nor)
 
 	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
 
-	if (spi_nor_parse_sfdp(nor)) {
+	if (!spi_nor_parse_sfdp(nor)) {
+		spi_nor_post_sfdp_fixups(nor);
+	} else {
 		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
 		nor->addr_width = 0;
 		nor->flags &= ~SNOR_F_4B_OPCODES;
@@ -2642,26 +2663,6 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
-/**
- * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
- * after SFDP has been parsed (is also called for SPI NORs that do not
- * support RDSFDP).
- * @nor:	pointer to a 'struct spi_nor'
- *
- * Typically used to tweak various parameters that could not be extracted by
- * other means (i.e. when information provided by the SFDP/flash_info tables
- * are incomplete or wrong).
- */
-static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
-{
-	if (nor->manufacturer && nor->manufacturer->fixups &&
-	    nor->manufacturer->fixups->post_sfdp)
-		nor->manufacturer->fixups->post_sfdp(nor);
-
-	if (nor->info->fixups && nor->info->fixups->post_sfdp)
-		nor->info->fixups->post_sfdp(nor);
-}
-
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2712,15 +2713,12 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
  *    Please note that there is a ->post_bfpt() fixup hook that can overwrite
  *    the flash parameters and settings immediately after parsing the Basic
  *    Flash Parameter Table.
+ *    spi_nor_post_sfdp_fixups() is called after the SFDP tables are parsed.
+ *    It is used to tweak various flash parameters when information provided
+ *    by the SFDP tables are wrong.
  *
  * which can be overwritten by:
- * 4/ Post SFDP flash parameters initialization. Used to tweak various
- *    parameters that could not be extracted by other means (i.e. when
- *    information provided by the SFDP/flash_info tables are incomplete or
- *    wrong).
- *		spi_nor_post_sfdp_fixups()
- *
- * 5/ Late flash parameters initialization, used to initialize flash
+ * 4/ Late flash parameters initialization, used to initialize flash
  * parameters that are not declared in the JESD216 SFDP standard, or where SFDP
  * tables are not defined at all.
  *		spi_nor_late_init_params()
@@ -2740,8 +2738,6 @@ static int spi_nor_init_params(struct spi_nor *nor)
 	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
 		spi_nor_sfdp_init_params(nor);
 
-	spi_nor_post_sfdp_fixups(nor);
-
 	spi_nor_late_init_params(nor);
 
 	return 0;
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

spi_nor_post_sfdp_fixups() was called even when there were no SFDP
tables defined. late_init() should be instead used for flashes that
do not define SFDP tables.

Use spi_nor_post_sfdp_fixups() just to fix SFDP data. post_sfdp()
hook is as of now used just by s28hs512t, mt35xu512aba, and both
support SFDP, there's no functional change with this patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 56 ++++++++++++++++++--------------------
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 4679298c5301..82cc56c9d09e 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2508,6 +2508,25 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor)
 		nor->info->fixups->default_init(nor);
 }
 
+/**
+ * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
+ * after SFDP has been parsed. Called only for flashes that define JESD216 SFDP
+ * tables.
+ * @nor:	pointer to a 'struct spi_nor'
+ *
+ * Used to tweak various flash parameters when information provided by the SFDP
+ * tables are wrong.
+ */
+static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
+{
+	if (nor->manufacturer && nor->manufacturer->fixups &&
+	    nor->manufacturer->fixups->post_sfdp)
+		nor->manufacturer->fixups->post_sfdp(nor);
+
+	if (nor->info->fixups && nor->info->fixups->post_sfdp)
+		nor->info->fixups->post_sfdp(nor);
+}
+
 /**
  * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
  * based on JESD216 SFDP standard.
@@ -2522,7 +2541,9 @@ static void spi_nor_sfdp_init_params(struct spi_nor *nor)
 
 	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
 
-	if (spi_nor_parse_sfdp(nor)) {
+	if (!spi_nor_parse_sfdp(nor)) {
+		spi_nor_post_sfdp_fixups(nor);
+	} else {
 		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
 		nor->addr_width = 0;
 		nor->flags &= ~SNOR_F_4B_OPCODES;
@@ -2642,26 +2663,6 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
-/**
- * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
- * after SFDP has been parsed (is also called for SPI NORs that do not
- * support RDSFDP).
- * @nor:	pointer to a 'struct spi_nor'
- *
- * Typically used to tweak various parameters that could not be extracted by
- * other means (i.e. when information provided by the SFDP/flash_info tables
- * are incomplete or wrong).
- */
-static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
-{
-	if (nor->manufacturer && nor->manufacturer->fixups &&
-	    nor->manufacturer->fixups->post_sfdp)
-		nor->manufacturer->fixups->post_sfdp(nor);
-
-	if (nor->info->fixups && nor->info->fixups->post_sfdp)
-		nor->info->fixups->post_sfdp(nor);
-}
-
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2712,15 +2713,12 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
  *    Please note that there is a ->post_bfpt() fixup hook that can overwrite
  *    the flash parameters and settings immediately after parsing the Basic
  *    Flash Parameter Table.
+ *    spi_nor_post_sfdp_fixups() is called after the SFDP tables are parsed.
+ *    It is used to tweak various flash parameters when information provided
+ *    by the SFDP tables are wrong.
  *
  * which can be overwritten by:
- * 4/ Post SFDP flash parameters initialization. Used to tweak various
- *    parameters that could not be extracted by other means (i.e. when
- *    information provided by the SFDP/flash_info tables are incomplete or
- *    wrong).
- *		spi_nor_post_sfdp_fixups()
- *
- * 5/ Late flash parameters initialization, used to initialize flash
+ * 4/ Late flash parameters initialization, used to initialize flash
  * parameters that are not declared in the JESD216 SFDP standard, or where SFDP
  * tables are not defined at all.
  *		spi_nor_late_init_params()
@@ -2740,8 +2738,6 @@ static int spi_nor_init_params(struct spi_nor *nor)
 	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
 		spi_nor_sfdp_init_params(nor);
 
-	spi_nor_post_sfdp_fixups(nor);
-
 	spi_nor_late_init_params(nor);
 
 	return 0;
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

The flash_info flags should be generic and not manufacturer specific.
Get rid of the manufacturer specific flag and use the late_init() fixup
hook instead.
Please note that sst_write is now set at flash level and not globally,
per manufacturer. Manufacturer hooks are generally a bad idea, because
it affects settings for all the flashes and we might end up with fixups
for "manufacturer settings".

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.h |   1 -
 drivers/mtd/spi-nor/sst.c  | 100 +++++++++++++++++++++----------------
 2 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index f6c4b6f4743b..6fc63ef4267b 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -336,7 +336,6 @@ struct flash_info {
 	u32		flags;
 #define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
 #define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
-#define SST_WRITE		BIT(2)	/* use SST byte programming */
 #define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
 #define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
 #define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 3593aae0920f..40e55b531edb 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -55,42 +55,6 @@ static const struct spi_nor_fixups sst26vf_fixups = {
 	.late_init = sst26vf_late_init,
 };
 
-static const struct flash_info sst_parts[] = {
-	/* SST -- large erase sizes are "overlays", "sectors" are 4K */
-	{ "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024,  8,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf064c", INFO(0xbf254b, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_4BIT_BP | SPI_NOR_HAS_LOCK |
-			      SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf512",  INFO(0xbf2501, 0, 64 * 1024,  1,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf010",  INFO(0xbf2502, 0, 64 * 1024,  2,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf020",  INFO(0xbf2503, 0, 64 * 1024,  4,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf020a", INFO(0x621612, 0, 64 * 1024,  4, SECT_4K | SPI_NOR_HAS_LOCK) },
-	{ "sst25wf040b", INFO(0x621613, 0, 64 * 1024,  8, SECT_4K | SPI_NOR_HAS_LOCK) },
-	{ "sst25wf040",  INFO(0xbf2504, 0, 64 * 1024,  8,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf080",  INFO(0xbf2505, 0, 64 * 1024, 16,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst26wf016b", INFO(0xbf2651, 0, 64 * 1024, 32,
-			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ) },
-	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
-			      SECT_4K | SPI_NOR_DUAL_READ) },
-	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
-		.fixups = &sst26vf_fixups },
-};
-
 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 		     size_t *retlen, const u_char *buf)
 {
@@ -177,19 +141,71 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return ret;
 }
 
-static void sst_late_init(struct spi_nor *nor)
+static void sst_write_late_init(struct spi_nor *nor)
 {
-	if (nor->info->flags & SST_WRITE)
-		nor->mtd._write = sst_write;
+	nor->mtd._write = sst_write;
 }
 
-static const struct spi_nor_fixups sst_fixups = {
-	.late_init = sst_late_init,
+static const struct spi_nor_fixups sst_write_fixup = {
+	.late_init = sst_write_late_init,
+};
+
+static const struct flash_info sst_parts[] = {
+	/* SST -- large erase sizes are "overlays", "sectors" are 4K */
+	{ "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024,  8,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf064c", INFO(0xbf254b, 0, 64 * 1024, 128,
+			      SECT_4K | SPI_NOR_4BIT_BP | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE) },
+	{ "sst25wf512",  INFO(0xbf2501, 0, 64 * 1024,  1,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf010",  INFO(0xbf2502, 0, 64 * 1024,  2,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf020",  INFO(0xbf2503, 0, 64 * 1024,  4,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf020a", INFO(0x621612, 0, 64 * 1024,  4, SECT_4K | SPI_NOR_HAS_LOCK) },
+	{ "sst25wf040b", INFO(0x621613, 0, 64 * 1024,  8, SECT_4K | SPI_NOR_HAS_LOCK) },
+	{ "sst25wf040",  INFO(0xbf2504, 0, 64 * 1024,  8,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf080",  INFO(0xbf2505, 0, 64 * 1024, 16,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst26wf016b", INFO(0xbf2651, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_DUAL_READ |
+			      SPI_NOR_QUAD_READ) },
+	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_DUAL_READ) },
+	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
+			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst26vf_fixups },
 };
 
 const struct spi_nor_manufacturer spi_nor_sst = {
 	.name = "sst",
 	.parts = sst_parts,
 	.nparts = ARRAY_SIZE(sst_parts),
-	.fixups = &sst_fixups,
 };
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

The flash_info flags should be generic and not manufacturer specific.
Get rid of the manufacturer specific flag and use the late_init() fixup
hook instead.
Please note that sst_write is now set at flash level and not globally,
per manufacturer. Manufacturer hooks are generally a bad idea, because
it affects settings for all the flashes and we might end up with fixups
for "manufacturer settings".

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.h |   1 -
 drivers/mtd/spi-nor/sst.c  | 100 +++++++++++++++++++++----------------
 2 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index f6c4b6f4743b..6fc63ef4267b 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -336,7 +336,6 @@ struct flash_info {
 	u32		flags;
 #define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
 #define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
-#define SST_WRITE		BIT(2)	/* use SST byte programming */
 #define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
 #define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
 #define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 3593aae0920f..40e55b531edb 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -55,42 +55,6 @@ static const struct spi_nor_fixups sst26vf_fixups = {
 	.late_init = sst26vf_late_init,
 };
 
-static const struct flash_info sst_parts[] = {
-	/* SST -- large erase sizes are "overlays", "sectors" are 4K */
-	{ "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024,  8,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25vf064c", INFO(0xbf254b, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_4BIT_BP | SPI_NOR_HAS_LOCK |
-			      SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf512",  INFO(0xbf2501, 0, 64 * 1024,  1,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf010",  INFO(0xbf2502, 0, 64 * 1024,  2,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf020",  INFO(0xbf2503, 0, 64 * 1024,  4,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf020a", INFO(0x621612, 0, 64 * 1024,  4, SECT_4K | SPI_NOR_HAS_LOCK) },
-	{ "sst25wf040b", INFO(0x621613, 0, 64 * 1024,  8, SECT_4K | SPI_NOR_HAS_LOCK) },
-	{ "sst25wf040",  INFO(0xbf2504, 0, 64 * 1024,  8,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst25wf080",  INFO(0xbf2505, 0, 64 * 1024, 16,
-			      SECT_4K | SST_WRITE | SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE) },
-	{ "sst26wf016b", INFO(0xbf2651, 0, 64 * 1024, 32,
-			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ) },
-	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
-			      SECT_4K | SPI_NOR_DUAL_READ) },
-	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
-		.fixups = &sst26vf_fixups },
-};
-
 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 		     size_t *retlen, const u_char *buf)
 {
@@ -177,19 +141,71 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
 	return ret;
 }
 
-static void sst_late_init(struct spi_nor *nor)
+static void sst_write_late_init(struct spi_nor *nor)
 {
-	if (nor->info->flags & SST_WRITE)
-		nor->mtd._write = sst_write;
+	nor->mtd._write = sst_write;
 }
 
-static const struct spi_nor_fixups sst_fixups = {
-	.late_init = sst_late_init,
+static const struct spi_nor_fixups sst_write_fixup = {
+	.late_init = sst_write_late_init,
+};
+
+static const struct flash_info sst_parts[] = {
+	/* SST -- large erase sizes are "overlays", "sectors" are 4K */
+	{ "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024,  8,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25vf064c", INFO(0xbf254b, 0, 64 * 1024, 128,
+			      SECT_4K | SPI_NOR_4BIT_BP | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE) },
+	{ "sst25wf512",  INFO(0xbf2501, 0, 64 * 1024,  1,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf010",  INFO(0xbf2502, 0, 64 * 1024,  2,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf020",  INFO(0xbf2503, 0, 64 * 1024,  4,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf020a", INFO(0x621612, 0, 64 * 1024,  4, SECT_4K | SPI_NOR_HAS_LOCK) },
+	{ "sst25wf040b", INFO(0x621613, 0, 64 * 1024,  8, SECT_4K | SPI_NOR_HAS_LOCK) },
+	{ "sst25wf040",  INFO(0xbf2504, 0, 64 * 1024,  8,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst25wf080",  INFO(0xbf2505, 0, 64 * 1024, 16,
+			      SECT_4K | SPI_NOR_HAS_LOCK |
+			      SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst_write_fixup },
+	{ "sst26wf016b", INFO(0xbf2651, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_DUAL_READ |
+			      SPI_NOR_QUAD_READ) },
+	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
+			      SECT_4K | SPI_NOR_DUAL_READ) },
+	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
+			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
+		.fixups = &sst26vf_fixups },
 };
 
 const struct spi_nor_manufacturer spi_nor_sst = {
 	.name = "sst",
 	.parts = sst_parts,
 	.nparts = ARRAY_SIZE(sst_parts),
-	.fixups = &sst_fixups,
 };
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Clarify for what the flash_info flags are used for. Split them in
three categories:
1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
   by the JESD216 standard in its SFDP tables.
2/ SFDP_FLAGS: flags that indicate support that can be discovered
   via SFDP. These flags are used when the flash does not define the
   SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
3/ FIXUP_FLAGS: flags that indicate support that can be discovered
   via SFDP ideally, but can not be discovered for this particular flash
   because the SFDP table that indicates this support is not defined by
   the flash. In case the table for this support is defined but has wrong
   values, one should instead use a post_sfdp() hook to set the SNOR_F
   equivalent flag.

Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
will be removed in a future series.

BIT(0) was kept for SPI_NOR_PARSE_SFDP (will be introduced in a
further patch).

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.h | 89 ++++++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 6fc63ef4267b..1fadd0e74103 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -334,56 +334,81 @@ struct flash_info {
 	u16		addr_width;
 
 	u32		flags;
-#define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
-#define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
-#define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
-#define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
-#define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
-#define SPI_NOR_QUAD_READ	BIT(6)	/* Flash supports Quad Read */
-#define USE_FSR			BIT(7)	/* use flag status register */
-#define SPI_NOR_HAS_LOCK	BIT(8)	/* Flash supports lock/unlock via SR */
-#define SPI_NOR_HAS_TB		BIT(9)	/*
+#define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
+
+/*
+ * Flags that indicate support that is not defined by the JESD216 standard in
+ * its SFDP tables.
+ */
+#define NON_SFDP_FLAGS_MASK	GENMASK(15, 2)
+#define NON_SFDP_FLAGS(x)	((x) & NON_SFDP_FLAGS_MASK)
+#define SPI_NOR_HAS_LOCK	BIT(2)	/* Flash supports lock/unlock via SR */
+#define SPI_NOR_HAS_TB		BIT(3)	/*
 					 * Flash SR has Top/Bottom (TB) protect
 					 * bit. Must be used with
 					 * SPI_NOR_HAS_LOCK.
 					 */
-#define SPI_NOR_XSR_RDY		BIT(10)	/*
-					 * S3AN flashes have specific opcode to
-					 * read the status register.
-					 */
-#define SPI_NOR_4B_OPCODES	BIT(11)	/*
-					 * Use dedicated 4byte address op codes
-					 * to support memory size above 128Mib.
-					 */
-#define NO_CHIP_ERASE		BIT(12) /* Chip does not support chip erase */
-#define SPI_NOR_SKIP_SFDP	BIT(13)	/* Skip parsing of SFDP tables */
-#define USE_CLSR		BIT(14)	/* use CLSR command */
-#define SPI_NOR_OCTAL_READ	BIT(15)	/* Flash supports Octal Read */
-#define SPI_NOR_TB_SR_BIT6	BIT(16)	/*
+#define SPI_NOR_TB_SR_BIT6	BIT(4)	/*
 					 * Top/Bottom (TB) is bit 6 of
 					 * status register. Must be used with
 					 * SPI_NOR_HAS_TB.
 					 */
-#define SPI_NOR_4BIT_BP		BIT(17) /*
+#define SPI_NOR_4BIT_BP		BIT(5) /*
 					 * Flash SR has 4 bit fields (BP0-3)
 					 * for block protection.
 					 */
-#define SPI_NOR_BP3_SR_BIT6	BIT(18) /*
+#define SPI_NOR_BP3_SR_BIT6	BIT(6) /*
 					 * BP3 is bit 6 of status register.
 					 * Must be used with SPI_NOR_4BIT_BP.
 					 */
-#define SPI_NOR_OCTAL_DTR_READ	BIT(19) /* Flash supports octal DTR Read. */
-#define SPI_NOR_OCTAL_DTR_PP	BIT(20) /* Flash supports Octal DTR Page Program */
-#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(21) /*
-						 * Flash enables the best
-						 * available I/O mode via a
-						 * volatile bit.
-						 */
-#define SPI_NOR_SWP_IS_VOLATILE	BIT(22)	/*
+#define SPI_NOR_SWP_IS_VOLATILE	BIT(7)	/*
 					 * Flash has volatile software write
 					 * protection bits. Usually these will
 					 * power-up in a write-protected state.
 					 */
+#define SPI_NOR_NO_ERASE	BIT(8)	/* No erase command needed */
+#define NO_CHIP_ERASE		BIT(9) /* Chip does not support chip erase */
+#define SPI_NOR_NO_FR		BIT(10)	/* Can't do fastread */
+#define USE_CLSR		BIT(11)	/* use CLSR command */
+#define USE_FSR			BIT(12)	/* use flag status register */
+#define SPI_NOR_XSR_RDY		BIT(13)	/*
+					 * S3AN flashes have specific opcode to
+					 * read the status register.
+					 */
+
+/*
+ * Flags that indicate support that can be discovered via SFDP. Used when SFDP
+ * tables are not defined in the flash. These flags are used together with the
+ * SPI_NOR_SKIP_SFDP flag.
+ */
+#define SFDP_FLAGS_MASK		GENMASK(23, 16)
+#define SFDP_FLAGS(x)		((x) & SFDP_FLAGS_MASK)
+#define SECT_4K			BIT(16)	/* SPINOR_OP_BE_4K works uniformly */
+#define SECT_4K_PMC		BIT(17)	/* SPINOR_OP_BE_4K_PMC works uniformly */
+#define SPI_NOR_DUAL_READ	BIT(18)	/* Flash supports Dual Read */
+#define SPI_NOR_QUAD_READ	BIT(19)	/* Flash supports Quad Read */
+#define SPI_NOR_OCTAL_READ	BIT(20)	/* Flash supports Octal Read */
+#define SPI_NOR_OCTAL_DTR_READ	BIT(21) /* Flash supports octal DTR Read. */
+#define SPI_NOR_OCTAL_DTR_PP	BIT(22) /* Flash supports Octal DTR Page Program */
+
+/*
+ * Flags that indicate support that can be discovered via SFDP ideally, but can
+ * not be discovered for this particular flash because the SFDP table that
+ * indicates this support is not defined by the flash. In case the table for
+ * this support is defined but has wrong values, one should instead use a
+ * post_sfdp() hook to set the SNOR_F equivalent flag.
+ */
+#define FIXUP_FLAGS_MASK	GENMASK(31, 24)
+#define FIXUP_FLAGS(x)		((x) & FIXUP_FLAGS_MASK)
+#define SPI_NOR_4B_OPCODES	BIT(24)	/*
+					 * Use dedicated 4byte address op codes
+					 * to support memory size above 128Mib.
+					 */
+#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(25) /*
+						 * Flash enables the best
+						 * available I/O mode via a
+						 * volatile bit.
+						 */
 
 	const struct spi_nor_otp_organization otp_org;
 
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Clarify for what the flash_info flags are used for. Split them in
three categories:
1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
   by the JESD216 standard in its SFDP tables.
2/ SFDP_FLAGS: flags that indicate support that can be discovered
   via SFDP. These flags are used when the flash does not define the
   SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
3/ FIXUP_FLAGS: flags that indicate support that can be discovered
   via SFDP ideally, but can not be discovered for this particular flash
   because the SFDP table that indicates this support is not defined by
   the flash. In case the table for this support is defined but has wrong
   values, one should instead use a post_sfdp() hook to set the SNOR_F
   equivalent flag.

Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
will be removed in a future series.

BIT(0) was kept for SPI_NOR_PARSE_SFDP (will be introduced in a
further patch).

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.h | 89 ++++++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 6fc63ef4267b..1fadd0e74103 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -334,56 +334,81 @@ struct flash_info {
 	u16		addr_width;
 
 	u32		flags;
-#define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
-#define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
-#define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
-#define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
-#define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
-#define SPI_NOR_QUAD_READ	BIT(6)	/* Flash supports Quad Read */
-#define USE_FSR			BIT(7)	/* use flag status register */
-#define SPI_NOR_HAS_LOCK	BIT(8)	/* Flash supports lock/unlock via SR */
-#define SPI_NOR_HAS_TB		BIT(9)	/*
+#define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
+
+/*
+ * Flags that indicate support that is not defined by the JESD216 standard in
+ * its SFDP tables.
+ */
+#define NON_SFDP_FLAGS_MASK	GENMASK(15, 2)
+#define NON_SFDP_FLAGS(x)	((x) & NON_SFDP_FLAGS_MASK)
+#define SPI_NOR_HAS_LOCK	BIT(2)	/* Flash supports lock/unlock via SR */
+#define SPI_NOR_HAS_TB		BIT(3)	/*
 					 * Flash SR has Top/Bottom (TB) protect
 					 * bit. Must be used with
 					 * SPI_NOR_HAS_LOCK.
 					 */
-#define SPI_NOR_XSR_RDY		BIT(10)	/*
-					 * S3AN flashes have specific opcode to
-					 * read the status register.
-					 */
-#define SPI_NOR_4B_OPCODES	BIT(11)	/*
-					 * Use dedicated 4byte address op codes
-					 * to support memory size above 128Mib.
-					 */
-#define NO_CHIP_ERASE		BIT(12) /* Chip does not support chip erase */
-#define SPI_NOR_SKIP_SFDP	BIT(13)	/* Skip parsing of SFDP tables */
-#define USE_CLSR		BIT(14)	/* use CLSR command */
-#define SPI_NOR_OCTAL_READ	BIT(15)	/* Flash supports Octal Read */
-#define SPI_NOR_TB_SR_BIT6	BIT(16)	/*
+#define SPI_NOR_TB_SR_BIT6	BIT(4)	/*
 					 * Top/Bottom (TB) is bit 6 of
 					 * status register. Must be used with
 					 * SPI_NOR_HAS_TB.
 					 */
-#define SPI_NOR_4BIT_BP		BIT(17) /*
+#define SPI_NOR_4BIT_BP		BIT(5) /*
 					 * Flash SR has 4 bit fields (BP0-3)
 					 * for block protection.
 					 */
-#define SPI_NOR_BP3_SR_BIT6	BIT(18) /*
+#define SPI_NOR_BP3_SR_BIT6	BIT(6) /*
 					 * BP3 is bit 6 of status register.
 					 * Must be used with SPI_NOR_4BIT_BP.
 					 */
-#define SPI_NOR_OCTAL_DTR_READ	BIT(19) /* Flash supports octal DTR Read. */
-#define SPI_NOR_OCTAL_DTR_PP	BIT(20) /* Flash supports Octal DTR Page Program */
-#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(21) /*
-						 * Flash enables the best
-						 * available I/O mode via a
-						 * volatile bit.
-						 */
-#define SPI_NOR_SWP_IS_VOLATILE	BIT(22)	/*
+#define SPI_NOR_SWP_IS_VOLATILE	BIT(7)	/*
 					 * Flash has volatile software write
 					 * protection bits. Usually these will
 					 * power-up in a write-protected state.
 					 */
+#define SPI_NOR_NO_ERASE	BIT(8)	/* No erase command needed */
+#define NO_CHIP_ERASE		BIT(9) /* Chip does not support chip erase */
+#define SPI_NOR_NO_FR		BIT(10)	/* Can't do fastread */
+#define USE_CLSR		BIT(11)	/* use CLSR command */
+#define USE_FSR			BIT(12)	/* use flag status register */
+#define SPI_NOR_XSR_RDY		BIT(13)	/*
+					 * S3AN flashes have specific opcode to
+					 * read the status register.
+					 */
+
+/*
+ * Flags that indicate support that can be discovered via SFDP. Used when SFDP
+ * tables are not defined in the flash. These flags are used together with the
+ * SPI_NOR_SKIP_SFDP flag.
+ */
+#define SFDP_FLAGS_MASK		GENMASK(23, 16)
+#define SFDP_FLAGS(x)		((x) & SFDP_FLAGS_MASK)
+#define SECT_4K			BIT(16)	/* SPINOR_OP_BE_4K works uniformly */
+#define SECT_4K_PMC		BIT(17)	/* SPINOR_OP_BE_4K_PMC works uniformly */
+#define SPI_NOR_DUAL_READ	BIT(18)	/* Flash supports Dual Read */
+#define SPI_NOR_QUAD_READ	BIT(19)	/* Flash supports Quad Read */
+#define SPI_NOR_OCTAL_READ	BIT(20)	/* Flash supports Octal Read */
+#define SPI_NOR_OCTAL_DTR_READ	BIT(21) /* Flash supports octal DTR Read. */
+#define SPI_NOR_OCTAL_DTR_PP	BIT(22) /* Flash supports Octal DTR Page Program */
+
+/*
+ * Flags that indicate support that can be discovered via SFDP ideally, but can
+ * not be discovered for this particular flash because the SFDP table that
+ * indicates this support is not defined by the flash. In case the table for
+ * this support is defined but has wrong values, one should instead use a
+ * post_sfdp() hook to set the SNOR_F equivalent flag.
+ */
+#define FIXUP_FLAGS_MASK	GENMASK(31, 24)
+#define FIXUP_FLAGS(x)		((x) & FIXUP_FLAGS_MASK)
+#define SPI_NOR_4B_OPCODES	BIT(24)	/*
+					 * Use dedicated 4byte address op codes
+					 * to support memory size above 128Mib.
+					 */
+#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(25) /*
+						 * Flash enables the best
+						 * available I/O mode via a
+						 * volatile bit.
+						 */
 
 	const struct spi_nor_otp_organization otp_org;
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Used to initialize the NOR flags for settings that are not defined
in the JESD216 SFDP standard, thus can not be retrieved when parsing
SFDP.
This moves the setting of SNOR_F_READY_XSR_RDY and SNOR_F_HAS_LOCK
late in the init call, without any functional change expected.
The rest of the flags were already set after the spi_nor_init_params().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 88 ++++++++++++++++++++++----------------
 1 file changed, 52 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 82cc56c9d09e..0e31f8a2457d 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2663,6 +2663,56 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
+/**
+ * spi_nor_nonsfdp_init_flags() - Initialize NOR flags for settings that are not
+ * defined in the JESD216 SFDP standard, thus can not be retrieved when parsing
+ * SFDP.
+ * @nor:	pointer to a 'struct spi_nor'
+ */
+static void spi_nor_nonsfdp_init_flags(struct spi_nor *nor)
+{
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	const u32 info_flags = nor->info->flags & NON_SFDP_FLAGS_MASK;
+
+	if (of_property_read_bool(np, "broken-flash-reset"))
+		nor->flags |= SNOR_F_BROKEN_RESET;
+
+	if (info_flags & SPI_NOR_SWP_IS_VOLATILE)
+		nor->flags |= SNOR_F_SWP_IS_VOLATILE;
+
+	if (info_flags & SPI_NOR_HAS_LOCK)
+		nor->flags |= SNOR_F_HAS_LOCK;
+
+	if (info_flags & SPI_NOR_HAS_TB) {
+		nor->flags |= SNOR_F_HAS_SR_TB;
+		if (info_flags & SPI_NOR_TB_SR_BIT6)
+			nor->flags |= SNOR_F_HAS_SR_TB_BIT6;
+	}
+
+	if (info_flags & SPI_NOR_4BIT_BP) {
+		nor->flags |= SNOR_F_HAS_4BIT_BP;
+		if (info_flags & SPI_NOR_BP3_SR_BIT6)
+			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
+	}
+
+	if (info_flags & NO_CHIP_ERASE)
+		nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
+
+	if (info_flags & USE_CLSR)
+		nor->flags |= SNOR_F_USE_CLSR;
+
+	if (info_flags & USE_FSR)
+		nor->flags |= SNOR_F_USE_FSR;
+
+	/*
+	 * Make sure the XSR_RDY flag is set before calling
+	 * spi_nor_wait_till_ready(). Xilinx S3AN share MFR
+	 * with Atmel SPI NOR.
+	 */
+	if (info_flags & SPI_NOR_XSR_RDY)
+		nor->flags |=  SNOR_F_READY_XSR_RDY;
+}
+
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2680,6 +2730,8 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 	if (nor->info->fixups && nor->info->fixups->late_init)
 		nor->info->fixups->late_init(nor);
 
+	spi_nor_nonsfdp_init_flags(nor);
+
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
 	 * the default ones.
@@ -3111,7 +3163,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	const struct flash_info *info;
 	struct device *dev = nor->dev;
 	struct mtd_info *mtd = &nor->mtd;
-	struct device_node *np = spi_nor_get_flash_node(nor);
 	int ret;
 	int i;
 
@@ -3148,46 +3199,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 
 	mutex_init(&nor->lock);
 
-	/*
-	 * Make sure the XSR_RDY flag is set before calling
-	 * spi_nor_wait_till_ready(). Xilinx S3AN share MFR
-	 * with Atmel SPI NOR.
-	 */
-	if (info->flags & SPI_NOR_XSR_RDY)
-		nor->flags |=  SNOR_F_READY_XSR_RDY;
-
-	if (info->flags & SPI_NOR_HAS_LOCK)
-		nor->flags |= SNOR_F_HAS_LOCK;
-
 	/* Init flash parameters based on flash_info struct and SFDP */
 	ret = spi_nor_init_params(nor);
 	if (ret)
 		return ret;
 
-	if (info->flags & USE_FSR)
-		nor->flags |= SNOR_F_USE_FSR;
-	if (info->flags & SPI_NOR_HAS_TB) {
-		nor->flags |= SNOR_F_HAS_SR_TB;
-		if (info->flags & SPI_NOR_TB_SR_BIT6)
-			nor->flags |= SNOR_F_HAS_SR_TB_BIT6;
-	}
-
-	if (info->flags & NO_CHIP_ERASE)
-		nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
-	if (info->flags & USE_CLSR)
-		nor->flags |= SNOR_F_USE_CLSR;
-	if (info->flags & SPI_NOR_SWP_IS_VOLATILE)
-		nor->flags |= SNOR_F_SWP_IS_VOLATILE;
-
-	if (info->flags & SPI_NOR_4BIT_BP) {
-		nor->flags |= SNOR_F_HAS_4BIT_BP;
-		if (info->flags & SPI_NOR_BP3_SR_BIT6)
-			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
-	}
-
-	if (of_property_read_bool(np, "broken-flash-reset"))
-		nor->flags |= SNOR_F_BROKEN_RESET;
-
 	/*
 	 * Configure the SPI memory:
 	 * - select op codes for (Fast) Read, Page Program and Sector Erase.
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Used to initialize the NOR flags for settings that are not defined
in the JESD216 SFDP standard, thus can not be retrieved when parsing
SFDP.
This moves the setting of SNOR_F_READY_XSR_RDY and SNOR_F_HAS_LOCK
late in the init call, without any functional change expected.
The rest of the flags were already set after the spi_nor_init_params().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 88 ++++++++++++++++++++++----------------
 1 file changed, 52 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 82cc56c9d09e..0e31f8a2457d 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2663,6 +2663,56 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
+/**
+ * spi_nor_nonsfdp_init_flags() - Initialize NOR flags for settings that are not
+ * defined in the JESD216 SFDP standard, thus can not be retrieved when parsing
+ * SFDP.
+ * @nor:	pointer to a 'struct spi_nor'
+ */
+static void spi_nor_nonsfdp_init_flags(struct spi_nor *nor)
+{
+	struct device_node *np = spi_nor_get_flash_node(nor);
+	const u32 info_flags = nor->info->flags & NON_SFDP_FLAGS_MASK;
+
+	if (of_property_read_bool(np, "broken-flash-reset"))
+		nor->flags |= SNOR_F_BROKEN_RESET;
+
+	if (info_flags & SPI_NOR_SWP_IS_VOLATILE)
+		nor->flags |= SNOR_F_SWP_IS_VOLATILE;
+
+	if (info_flags & SPI_NOR_HAS_LOCK)
+		nor->flags |= SNOR_F_HAS_LOCK;
+
+	if (info_flags & SPI_NOR_HAS_TB) {
+		nor->flags |= SNOR_F_HAS_SR_TB;
+		if (info_flags & SPI_NOR_TB_SR_BIT6)
+			nor->flags |= SNOR_F_HAS_SR_TB_BIT6;
+	}
+
+	if (info_flags & SPI_NOR_4BIT_BP) {
+		nor->flags |= SNOR_F_HAS_4BIT_BP;
+		if (info_flags & SPI_NOR_BP3_SR_BIT6)
+			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
+	}
+
+	if (info_flags & NO_CHIP_ERASE)
+		nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
+
+	if (info_flags & USE_CLSR)
+		nor->flags |= SNOR_F_USE_CLSR;
+
+	if (info_flags & USE_FSR)
+		nor->flags |= SNOR_F_USE_FSR;
+
+	/*
+	 * Make sure the XSR_RDY flag is set before calling
+	 * spi_nor_wait_till_ready(). Xilinx S3AN share MFR
+	 * with Atmel SPI NOR.
+	 */
+	if (info_flags & SPI_NOR_XSR_RDY)
+		nor->flags |=  SNOR_F_READY_XSR_RDY;
+}
+
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2680,6 +2730,8 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 	if (nor->info->fixups && nor->info->fixups->late_init)
 		nor->info->fixups->late_init(nor);
 
+	spi_nor_nonsfdp_init_flags(nor);
+
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
 	 * the default ones.
@@ -3111,7 +3163,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	const struct flash_info *info;
 	struct device *dev = nor->dev;
 	struct mtd_info *mtd = &nor->mtd;
-	struct device_node *np = spi_nor_get_flash_node(nor);
 	int ret;
 	int i;
 
@@ -3148,46 +3199,11 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 
 	mutex_init(&nor->lock);
 
-	/*
-	 * Make sure the XSR_RDY flag is set before calling
-	 * spi_nor_wait_till_ready(). Xilinx S3AN share MFR
-	 * with Atmel SPI NOR.
-	 */
-	if (info->flags & SPI_NOR_XSR_RDY)
-		nor->flags |=  SNOR_F_READY_XSR_RDY;
-
-	if (info->flags & SPI_NOR_HAS_LOCK)
-		nor->flags |= SNOR_F_HAS_LOCK;
-
 	/* Init flash parameters based on flash_info struct and SFDP */
 	ret = spi_nor_init_params(nor);
 	if (ret)
 		return ret;
 
-	if (info->flags & USE_FSR)
-		nor->flags |= SNOR_F_USE_FSR;
-	if (info->flags & SPI_NOR_HAS_TB) {
-		nor->flags |= SNOR_F_HAS_SR_TB;
-		if (info->flags & SPI_NOR_TB_SR_BIT6)
-			nor->flags |= SNOR_F_HAS_SR_TB_BIT6;
-	}
-
-	if (info->flags & NO_CHIP_ERASE)
-		nor->flags |= SNOR_F_NO_OP_CHIP_ERASE;
-	if (info->flags & USE_CLSR)
-		nor->flags |= SNOR_F_USE_CLSR;
-	if (info->flags & SPI_NOR_SWP_IS_VOLATILE)
-		nor->flags |= SNOR_F_SWP_IS_VOLATILE;
-
-	if (info->flags & SPI_NOR_4BIT_BP) {
-		nor->flags |= SNOR_F_HAS_4BIT_BP;
-		if (info->flags & SPI_NOR_BP3_SR_BIT6)
-			nor->flags |= SNOR_F_HAS_SR_BP3_BIT6;
-	}
-
-	if (of_property_read_bool(np, "broken-flash-reset"))
-		nor->flags |= SNOR_F_BROKEN_RESET;
-
 	/*
 	 * Configure the SPI memory:
 	 * - select op codes for (Fast) Read, Page Program and Sector Erase.
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Initialize NOR flags for settings that can not be discovered by SFDP
for this particular flash because the SFDP table that indicates this
support is not defined in the flash. In case the table for his support
is defined but has wrong values, one should instead use a post_sfdp()
hook to set the SNOR_F equivalent flag.
Update all flash_info entries that use SPI_NOR_4B_OPCODES or
SPI_NOR_IO_MODE_EN_VOLATILE to also use the FIXUP_FLAGS() macro. This
should highlight to developers that those flags should be used only
as fixups, where flashes miss to define the SFDP tables that describe
those settings.
No functional change intended in this patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c       | 26 ++++++++++++++++++++------
 drivers/mtd/spi-nor/gigadevice.c |  5 +++--
 drivers/mtd/spi-nor/issi.c       |  4 ++--
 drivers/mtd/spi-nor/macronix.c   | 13 ++++++++-----
 drivers/mtd/spi-nor/micron-st.c  | 20 ++++++++++++--------
 drivers/mtd/spi-nor/spansion.c   |  6 +++---
 6 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0e31f8a2457d..6f7978e7a46a 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2713,6 +2713,25 @@ static void spi_nor_nonsfdp_init_flags(struct spi_nor *nor)
 		nor->flags |=  SNOR_F_READY_XSR_RDY;
 }
 
+/**
+ * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
+ * be discovered by SFDP for this particular flash because the SFDP table that
+ * indicates this support is not defined in the flash. In case the table for
+ * this support is defined but has wrong values, one should instead use a
+ * post_sfdp() hook to set the SNOR_F equivalent flag.
+ * @nor:	pointer to a 'struct spi_nor'
+ */
+static void spi_nor_init_fixup_flags(struct spi_nor *nor)
+{
+	const u32 info_flags = nor->info->flags & FIXUP_FLAGS_MASK;
+
+	if (info_flags & SPI_NOR_4B_OPCODES)
+		nor->flags |= SNOR_F_4B_OPCODES;
+
+	if (info_flags & SPI_NOR_IO_MODE_EN_VOLATILE)
+		nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
+}
+
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2731,6 +2750,7 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 		nor->info->fixups->late_init(nor);
 
 	spi_nor_nonsfdp_init_flags(nor);
+	spi_nor_init_fixup_flags(nor);
 
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
@@ -3214,12 +3234,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (ret)
 		return ret;
 
-	if (info->flags & SPI_NOR_4B_OPCODES)
-		nor->flags |= SNOR_F_4B_OPCODES;
-
-	if (info->flags & SPI_NOR_IO_MODE_EN_VOLATILE)
-		nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
-
 	ret = spi_nor_set_addr_width(nor);
 	if (ret)
 		return ret;
diff --git a/drivers/mtd/spi-nor/gigadevice.c b/drivers/mtd/spi-nor/gigadevice.c
index 447d84bb2128..59053f419642 100644
--- a/drivers/mtd/spi-nor/gigadevice.c
+++ b/drivers/mtd/spi-nor/gigadevice.c
@@ -47,8 +47,9 @@ static const struct flash_info gigadevice_parts[] = {
 			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) },
 	{ "gd25q256", INFO(0xc84019, 0, 64 * 1024, 512,
 			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			   SPI_NOR_4B_OPCODES | SPI_NOR_HAS_LOCK |
-			   SPI_NOR_HAS_TB | SPI_NOR_TB_SR_BIT6)
+			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
+			   SPI_NOR_TB_SR_BIT6 |
+			   FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &gd25q256_fixups },
 };
 
diff --git a/drivers/mtd/spi-nor/issi.c b/drivers/mtd/spi-nor/issi.c
index 1e5bb5408b68..b2abe8202143 100644
--- a/drivers/mtd/spi-nor/issi.c
+++ b/drivers/mtd/spi-nor/issi.c
@@ -46,7 +46,7 @@ static const struct flash_info issi_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "is25lp256",  INFO(0x9d6019, 0, 64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES)
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 	{ "is25wp032",  INFO(0x9d7016, 0, 64 * 1024,  64,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
@@ -56,7 +56,7 @@ static const struct flash_info issi_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
 	{ "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 512,
 			    SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			    SPI_NOR_4B_OPCODES)
+			    FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 
 	/* PMC */
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 27498ed0cc0d..d0285e60092e 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -65,20 +65,22 @@ static const struct flash_info macronix_parts[] = {
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
 		.fixups = &mx25l25635_fixups },
 	{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
-			      SECT_4K | SPI_NOR_4B_OPCODES) },
+			      SECT_4K | FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx25u51245g", INFO(0xc2253a, 0, 64 * 1024, 1024,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx25v8035f",  INFO(0xc22314, 0, 64 * 1024,  16,
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
 	{ "mx66l51235f", INFO(0xc2201a, 0, 64 * 1024, 1024,
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_4B_OPCODES) },
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx66u51235f", INFO(0xc2253a, 0, 64 * 1024, 1024,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048,
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
@@ -86,7 +88,8 @@ static const struct flash_info macronix_parts[] = {
 			      SPI_NOR_QUAD_READ) },
 	{ "mx66u2g45g",	 INFO(0xc2253c, 0, 64 * 1024, 4096,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 };
 
 static void macronix_default_init(struct spi_nor *nor)
diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index f3d19b716b7b..c982458d5e31 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -121,13 +121,13 @@ static struct spi_nor_fixups mt35xu512aba_fixups = {
 static const struct flash_info micron_parts[] = {
 	{ "mt35xu512aba", INFO(0x2c5b1a, 0, 128 * 1024, 512,
 			       SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
-			       SPI_NOR_4B_OPCODES | SPI_NOR_OCTAL_DTR_READ |
-			       SPI_NOR_OCTAL_DTR_PP |
-			       SPI_NOR_IO_MODE_EN_VOLATILE)
+			       SPI_NOR_OCTAL_DTR_READ | SPI_NOR_OCTAL_DTR_PP |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES |
+					   SPI_NOR_IO_MODE_EN_VOLATILE))
 	  .fixups = &mt35xu512aba_fixups},
 	{ "mt35xu02g", INFO(0x2c5b1c, 0, 128 * 1024, 2048,
 			    SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
-			    SPI_NOR_4B_OPCODES) },
+			    FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 };
 
 static const struct flash_info st_parts[] = {
@@ -151,25 +151,29 @@ static const struct flash_info st_parts[] = {
 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
 	{ "mt25ql256a",  INFO6(0x20ba19, 0x104400, 64 * 1024,  512,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q256a",    INFO(0x20ba19, 0, 64 * 1024,  512, SECT_4K |
 			      USE_FSR | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mt25qu256a",  INFO6(0x20bb19, 0x104400, 64 * 1024,  512,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q256ax1",  INFO(0x20bb19, 0, 64 * 1024,  512,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
 	{ "mt25ql512a",  INFO6(0x20ba20, 0x104400, 64 * 1024, 1024,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q512ax3",  INFO(0x20ba20, 0, 64 * 1024, 1024,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
 	{ "mt25qu512a",  INFO6(0x20bb20, 0x104400, 64 * 1024, 1024,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q512a",    INFO(0x20bb20, 0, 64 * 1024, 1024,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index a3ea0135f7b1..3ee1cd3b8fb5 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -260,13 +260,13 @@ static const struct flash_info spansion_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "s25fl064l",  INFO(0x016017,      0,  64 * 1024, 128,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "s25fl128l",  INFO(0x016018,      0,  64 * 1024, 256,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "s25fl256l",  INFO(0x016019,      0,  64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "cy15x104q",  INFO6(0x042cc2, 0x7f7f7f, 512 * 1024, 1,
 			      SPI_NOR_NO_ERASE) },
 	{ "s28hs512t",   INFO(0x345b1a,      0, 256 * 1024, 256,
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Initialize NOR flags for settings that can not be discovered by SFDP
for this particular flash because the SFDP table that indicates this
support is not defined in the flash. In case the table for his support
is defined but has wrong values, one should instead use a post_sfdp()
hook to set the SNOR_F equivalent flag.
Update all flash_info entries that use SPI_NOR_4B_OPCODES or
SPI_NOR_IO_MODE_EN_VOLATILE to also use the FIXUP_FLAGS() macro. This
should highlight to developers that those flags should be used only
as fixups, where flashes miss to define the SFDP tables that describe
those settings.
No functional change intended in this patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c       | 26 ++++++++++++++++++++------
 drivers/mtd/spi-nor/gigadevice.c |  5 +++--
 drivers/mtd/spi-nor/issi.c       |  4 ++--
 drivers/mtd/spi-nor/macronix.c   | 13 ++++++++-----
 drivers/mtd/spi-nor/micron-st.c  | 20 ++++++++++++--------
 drivers/mtd/spi-nor/spansion.c   |  6 +++---
 6 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0e31f8a2457d..6f7978e7a46a 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2713,6 +2713,25 @@ static void spi_nor_nonsfdp_init_flags(struct spi_nor *nor)
 		nor->flags |=  SNOR_F_READY_XSR_RDY;
 }
 
+/**
+ * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
+ * be discovered by SFDP for this particular flash because the SFDP table that
+ * indicates this support is not defined in the flash. In case the table for
+ * this support is defined but has wrong values, one should instead use a
+ * post_sfdp() hook to set the SNOR_F equivalent flag.
+ * @nor:	pointer to a 'struct spi_nor'
+ */
+static void spi_nor_init_fixup_flags(struct spi_nor *nor)
+{
+	const u32 info_flags = nor->info->flags & FIXUP_FLAGS_MASK;
+
+	if (info_flags & SPI_NOR_4B_OPCODES)
+		nor->flags |= SNOR_F_4B_OPCODES;
+
+	if (info_flags & SPI_NOR_IO_MODE_EN_VOLATILE)
+		nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
+}
+
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:	pointer to a 'struct spi_nor'
@@ -2731,6 +2750,7 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 		nor->info->fixups->late_init(nor);
 
 	spi_nor_nonsfdp_init_flags(nor);
+	spi_nor_init_fixup_flags(nor);
 
 	/*
 	 * NOR protection support. When locking_ops are not provided, we pick
@@ -3214,12 +3234,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (ret)
 		return ret;
 
-	if (info->flags & SPI_NOR_4B_OPCODES)
-		nor->flags |= SNOR_F_4B_OPCODES;
-
-	if (info->flags & SPI_NOR_IO_MODE_EN_VOLATILE)
-		nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
-
 	ret = spi_nor_set_addr_width(nor);
 	if (ret)
 		return ret;
diff --git a/drivers/mtd/spi-nor/gigadevice.c b/drivers/mtd/spi-nor/gigadevice.c
index 447d84bb2128..59053f419642 100644
--- a/drivers/mtd/spi-nor/gigadevice.c
+++ b/drivers/mtd/spi-nor/gigadevice.c
@@ -47,8 +47,9 @@ static const struct flash_info gigadevice_parts[] = {
 			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) },
 	{ "gd25q256", INFO(0xc84019, 0, 64 * 1024, 512,
 			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			   SPI_NOR_4B_OPCODES | SPI_NOR_HAS_LOCK |
-			   SPI_NOR_HAS_TB | SPI_NOR_TB_SR_BIT6)
+			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
+			   SPI_NOR_TB_SR_BIT6 |
+			   FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &gd25q256_fixups },
 };
 
diff --git a/drivers/mtd/spi-nor/issi.c b/drivers/mtd/spi-nor/issi.c
index 1e5bb5408b68..b2abe8202143 100644
--- a/drivers/mtd/spi-nor/issi.c
+++ b/drivers/mtd/spi-nor/issi.c
@@ -46,7 +46,7 @@ static const struct flash_info issi_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "is25lp256",  INFO(0x9d6019, 0, 64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES)
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 	{ "is25wp032",  INFO(0x9d7016, 0, 64 * 1024,  64,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
@@ -56,7 +56,7 @@ static const struct flash_info issi_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
 	{ "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 512,
 			    SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			    SPI_NOR_4B_OPCODES)
+			    FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 
 	/* PMC */
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 27498ed0cc0d..d0285e60092e 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -65,20 +65,22 @@ static const struct flash_info macronix_parts[] = {
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
 		.fixups = &mx25l25635_fixups },
 	{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
-			      SECT_4K | SPI_NOR_4B_OPCODES) },
+			      SECT_4K | FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx25u51245g", INFO(0xc2253a, 0, 64 * 1024, 1024,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx25v8035f",  INFO(0xc22314, 0, 64 * 1024,  16,
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
 	{ "mx66l51235f", INFO(0xc2201a, 0, 64 * 1024, 1024,
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_4B_OPCODES) },
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx66u51235f", INFO(0xc2253a, 0, 64 * 1024, 1024,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "mx66l1g45g",  INFO(0xc2201b, 0, 64 * 1024, 2048,
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
@@ -86,7 +88,8 @@ static const struct flash_info macronix_parts[] = {
 			      SPI_NOR_QUAD_READ) },
 	{ "mx66u2g45g",	 INFO(0xc2253c, 0, 64 * 1024, 4096,
 			      SECT_4K | SPI_NOR_DUAL_READ |
-			      SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			      SPI_NOR_QUAD_READ |
+			      FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 };
 
 static void macronix_default_init(struct spi_nor *nor)
diff --git a/drivers/mtd/spi-nor/micron-st.c b/drivers/mtd/spi-nor/micron-st.c
index f3d19b716b7b..c982458d5e31 100644
--- a/drivers/mtd/spi-nor/micron-st.c
+++ b/drivers/mtd/spi-nor/micron-st.c
@@ -121,13 +121,13 @@ static struct spi_nor_fixups mt35xu512aba_fixups = {
 static const struct flash_info micron_parts[] = {
 	{ "mt35xu512aba", INFO(0x2c5b1a, 0, 128 * 1024, 512,
 			       SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
-			       SPI_NOR_4B_OPCODES | SPI_NOR_OCTAL_DTR_READ |
-			       SPI_NOR_OCTAL_DTR_PP |
-			       SPI_NOR_IO_MODE_EN_VOLATILE)
+			       SPI_NOR_OCTAL_DTR_READ | SPI_NOR_OCTAL_DTR_PP |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES |
+					   SPI_NOR_IO_MODE_EN_VOLATILE))
 	  .fixups = &mt35xu512aba_fixups},
 	{ "mt35xu02g", INFO(0x2c5b1c, 0, 128 * 1024, 2048,
 			    SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
-			    SPI_NOR_4B_OPCODES) },
+			    FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 };
 
 static const struct flash_info st_parts[] = {
@@ -151,25 +151,29 @@ static const struct flash_info st_parts[] = {
 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
 	{ "mt25ql256a",  INFO6(0x20ba19, 0x104400, 64 * 1024,  512,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q256a",    INFO(0x20ba19, 0, 64 * 1024,  512, SECT_4K |
 			      USE_FSR | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mt25qu256a",  INFO6(0x20bb19, 0x104400, 64 * 1024,  512,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q256ax1",  INFO(0x20bb19, 0, 64 * 1024,  512,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
 	{ "mt25ql512a",  INFO6(0x20ba20, 0x104400, 64 * 1024, 1024,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q512ax3",  INFO(0x20ba20, 0, 64 * 1024, 1024,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
 	{ "mt25qu512a",  INFO6(0x20bb20, 0x104400, 64 * 1024, 1024,
 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
-			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
+			       SPI_NOR_QUAD_READ |
+			       FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "n25q512a",    INFO(0x20bb20, 0, 64 * 1024, 1024,
 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index a3ea0135f7b1..3ee1cd3b8fb5 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -260,13 +260,13 @@ static const struct flash_info spansion_parts[] = {
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "s25fl064l",  INFO(0x016017,      0,  64 * 1024, 128,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "s25fl128l",  INFO(0x016018,      0,  64 * 1024, 256,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "s25fl256l",  INFO(0x016019,      0,  64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			     SPI_NOR_4B_OPCODES) },
+			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
 	{ "cy15x104q",  INFO6(0x042cc2, 0x7f7f7f, 512 * 1024, 1,
 			      SPI_NOR_NO_ERASE) },
 	{ "s28hs512t",   INFO(0x345b1a,      0, 256 * 1024, 256,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 17/25] mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

SPI NOR flashes that statically declare one of the
SPI_NOR_{DUAL, QUAD, OCTAL, OCTAL_DTR}_READ flags and do not support
the RDSFDP command are gratuiously receiving the RDSFDP command
in the attempt of parsing the SFDP tables. It is not desirable to issue
commands that are not supported, so introduce a flag to help on this
situation.

New flash additions that support the SFDP standard should be declared
using SPI_NOR_PARSE_SFDP. Support that can be discovered when parsing
SFDP should not be duplicated by explicit flags at flash declaration.
All the flash parameters will be discovered when parsing SFDP.
Sometimes manufacturers wrongly define some fields in the SFDP tables.
If that's the case, SFDP data can be amended with the fixups() hooks.
It is not common, but if the SFDP tables are entirely wrong, and it
does not worth the hassle to tweak the SFDP parameters by using the
fixups hooks, or if the flash does not define the SFDP tables at all,
then statically init the flash with the SPI_NOR_SKIP_SFDP flag and
specify the rest of flash capabilities with the flash info flags.

With time, we want to convert all flashes to SPI_NOR_PARSE_SFDP and
stop triggering the SFDP parsing with the
SPI_NOR_{DUAL, QUAD, OCTAL*}_READ flags. Getting rid of the
SPI_NOR_{OCTAL, OCTAL_DTR}_READ trigger is easily achievable, the rest
are a long term goal.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Heiko Thiery <heiko.thiery@gmail.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c | 3 ++-
 drivers/mtd/spi-nor/core.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 6f7978e7a46a..40d98ae300ca 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2805,7 +2805,8 @@ static int spi_nor_init_params(struct spi_nor *nor)
 
 	spi_nor_manufacturer_init_params(nor);
 
-	if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+	if ((nor->info->flags & (SPI_NOR_PARSE_SFDP |
+				 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 				 SPI_NOR_OCTAL_READ | SPI_NOR_OCTAL_DTR_READ)) &&
 	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
 		spi_nor_sfdp_init_params(nor);
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 1fadd0e74103..9dd8ada65f0c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -334,6 +334,7 @@ struct flash_info {
 	u16		addr_width;
 
 	u32		flags;
+#define SPI_NOR_PARSE_SFDP	BIT(0)	/* Flash initialized based on SFDP. */
 #define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
 
 /*
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 17/25] mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

SPI NOR flashes that statically declare one of the
SPI_NOR_{DUAL, QUAD, OCTAL, OCTAL_DTR}_READ flags and do not support
the RDSFDP command are gratuiously receiving the RDSFDP command
in the attempt of parsing the SFDP tables. It is not desirable to issue
commands that are not supported, so introduce a flag to help on this
situation.

New flash additions that support the SFDP standard should be declared
using SPI_NOR_PARSE_SFDP. Support that can be discovered when parsing
SFDP should not be duplicated by explicit flags at flash declaration.
All the flash parameters will be discovered when parsing SFDP.
Sometimes manufacturers wrongly define some fields in the SFDP tables.
If that's the case, SFDP data can be amended with the fixups() hooks.
It is not common, but if the SFDP tables are entirely wrong, and it
does not worth the hassle to tweak the SFDP parameters by using the
fixups hooks, or if the flash does not define the SFDP tables at all,
then statically init the flash with the SPI_NOR_SKIP_SFDP flag and
specify the rest of flash capabilities with the flash info flags.

With time, we want to convert all flashes to SPI_NOR_PARSE_SFDP and
stop triggering the SFDP parsing with the
SPI_NOR_{DUAL, QUAD, OCTAL*}_READ flags. Getting rid of the
SPI_NOR_{OCTAL, OCTAL_DTR}_READ trigger is easily achievable, the rest
are a long term goal.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Heiko Thiery <heiko.thiery@gmail.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c | 3 ++-
 drivers/mtd/spi-nor/core.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 6f7978e7a46a..40d98ae300ca 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2805,7 +2805,8 @@ static int spi_nor_init_params(struct spi_nor *nor)
 
 	spi_nor_manufacturer_init_params(nor);
 
-	if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+	if ((nor->info->flags & (SPI_NOR_PARSE_SFDP |
+				 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 				 SPI_NOR_OCTAL_READ | SPI_NOR_OCTAL_DTR_READ)) &&
 	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
 		spi_nor_sfdp_init_params(nor);
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 1fadd0e74103..9dd8ada65f0c 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -334,6 +334,7 @@ struct flash_info {
 	u16		addr_width;
 
 	u32		flags;
+#define SPI_NOR_PARSE_SFDP	BIT(0)	/* Flash initialized based on SFDP. */
 #define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
 
 /*
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

New flash additions that support SFDP should be declared with
SPI_NOR_PARSE_SFDP and with all the other flags that are not SFDP
discoverable.
Keep the old way of initializing the flash, until all the flashes
are converted to use either SPI_NOR_PARSE_SFDP or SPI_NOR_SKIP_SFDP.
Since we want to get rid of the default_init() hook, the rollback
mechanism for flashes that use SPI_NOR_PARSE_SFDP does not call
spi_nor_manufacturer_init_params().
Split spi_nor_info_init_params() in spi_nor_init_default_params()
and spi_nor_skip_sfdp_init_params(). spi_nor_init_default_params() is
called for all the flashes regardless if they support SFDP or not.
spi_nor_skip_sfdp_init_params() is called just for the flashes that
do not define SFDP and initializes parameters and setting solely based
on flash_info data.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 187 +++++++++++++++++++++----------------
 1 file changed, 105 insertions(+), 82 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 40d98ae300ca..c509f257a6c3 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2493,6 +2493,56 @@ static int spi_nor_setup(struct spi_nor *nor,
 	return nor->params->setup(nor, hwcaps);
 }
 
+/**
+ * spi_nor_init_default_params() - Default initialization of flash parameters
+ * and settings. Done for all flashes, regardless is they define SFDP tables
+ * or not.
+ * @nor:	pointer to a 'struct spi_nor'.
+ */
+static void spi_nor_init_default_params(struct spi_nor *nor)
+{
+	struct spi_nor_flash_parameter *params = nor->params;
+	const struct flash_info *info = nor->info;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+
+	params->quad_enable = spi_nor_sr2_bit1_quad_enable;
+	params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
+	params->setup = spi_nor_default_setup;
+	params->otp.org = &info->otp_org;
+
+	/* Default to 16-bit Write Status (01h) Command */
+	nor->flags |= SNOR_F_HAS_16BIT_SR;
+
+	/* Set SPI NOR sizes. */
+	params->writesize = 1;
+	params->size = (u64)info->sector_size * info->n_sectors;
+	params->page_size = info->page_size;
+
+	if (!(info->flags & SPI_NOR_NO_FR)) {
+		/* Default to Fast Read for DT and non-DT platform devices. */
+		params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
+
+		/* Mask out Fast Read if not requested at DT instantiation. */
+		if (np && !of_property_read_bool(np, "m25p,fast-read"))
+			params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
+	}
+
+	/* (Fast) Read settings. */
+	params->hwcaps.mask |= SNOR_HWCAPS_READ;
+	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ],
+				  0, 0, SPINOR_OP_READ,
+				  SNOR_PROTO_1_1_1);
+
+	if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
+		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_FAST],
+					  0, 8, SPINOR_OP_READ_FAST,
+					  SNOR_PROTO_1_1_1);
+	/* Page Program settings. */
+	params->hwcaps.mask |= SNOR_HWCAPS_PP;
+	spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP],
+				SPINOR_OP_PP, SNOR_PROTO_1_1_1);
+}
+
 /**
  * spi_nor_manufacturer_init_params() - Initialize the flash's parameters and
  * settings based on MFR register and ->default_init() hook.
@@ -2528,109 +2578,46 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
 }
 
 /**
- * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
- * based on JESD216 SFDP standard.
- * @nor:	pointer to a 'struct spi_nor'.
- *
- * The method has a roll-back mechanism: in case the SFDP parsing fails, the
- * legacy flash parameters and settings will be restored.
- */
-static void spi_nor_sfdp_init_params(struct spi_nor *nor)
-{
-	struct spi_nor_flash_parameter sfdp_params;
-
-	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
-
-	if (!spi_nor_parse_sfdp(nor)) {
-		spi_nor_post_sfdp_fixups(nor);
-	} else {
-		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
-		nor->addr_width = 0;
-		nor->flags &= ~SNOR_F_4B_OPCODES;
-	}
-}
-
-/**
- * spi_nor_info_init_params() - Initialize the flash's parameters and settings
- * based on nor->info data.
+ * spi_nor_skip_sfdp_init_params() - Initialize the flash's parameters and
+ * settings based on nor->info data.
  * @nor:	pointer to a 'struct spi_nor'.
  */
-static void spi_nor_info_init_params(struct spi_nor *nor)
+static void spi_nor_skip_sfdp_init_params(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params = nor->params;
 	struct spi_nor_erase_map *map = &params->erase_map;
-	const struct flash_info *info = nor->info;
-	struct device_node *np = spi_nor_get_flash_node(nor);
+	const u32 info_flags = nor->info->flags & SFDP_FLAGS_MASK;
 	u8 i, erase_mask;
 
-	/* Initialize default flash parameters and settings. */
-	params->quad_enable = spi_nor_sr2_bit1_quad_enable;
-	params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
-	params->setup = spi_nor_default_setup;
-	params->otp.org = &info->otp_org;
-
-	/* Default to 16-bit Write Status (01h) Command */
-	nor->flags |= SNOR_F_HAS_16BIT_SR;
-
-	/* Set SPI NOR sizes. */
-	params->writesize = 1;
-	params->size = (u64)info->sector_size * info->n_sectors;
-	params->page_size = info->page_size;
-
-	if (!(info->flags & SPI_NOR_NO_FR)) {
-		/* Default to Fast Read for DT and non-DT platform devices. */
-		params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
-
-		/* Mask out Fast Read if not requested at DT instantiation. */
-		if (np && !of_property_read_bool(np, "m25p,fast-read"))
-			params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
-	}
-
-	/* (Fast) Read settings. */
-	params->hwcaps.mask |= SNOR_HWCAPS_READ;
-	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ],
-				  0, 0, SPINOR_OP_READ,
-				  SNOR_PROTO_1_1_1);
-
-	if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
-		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_FAST],
-					  0, 8, SPINOR_OP_READ_FAST,
-					  SNOR_PROTO_1_1_1);
-
-	if (info->flags & SPI_NOR_DUAL_READ) {
+	if (info_flags & SPI_NOR_DUAL_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_2],
 					  0, 8, SPINOR_OP_READ_1_1_2,
 					  SNOR_PROTO_1_1_2);
 	}
 
-	if (info->flags & SPI_NOR_QUAD_READ) {
+	if (info_flags & SPI_NOR_QUAD_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_4],
 					  0, 8, SPINOR_OP_READ_1_1_4,
 					  SNOR_PROTO_1_1_4);
 	}
 
-	if (info->flags & SPI_NOR_OCTAL_READ) {
+	if (info_flags & SPI_NOR_OCTAL_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_8],
 					  0, 8, SPINOR_OP_READ_1_1_8,
 					  SNOR_PROTO_1_1_8);
 	}
 
-	if (info->flags & SPI_NOR_OCTAL_DTR_READ) {
+	if (info_flags & SPI_NOR_OCTAL_DTR_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_8_8_8_DTR],
 					  0, 20, SPINOR_OP_READ_FAST,
 					  SNOR_PROTO_8_8_8_DTR);
 	}
 
-	/* Page Program settings. */
-	params->hwcaps.mask |= SNOR_HWCAPS_PP;
-	spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP],
-				SPINOR_OP_PP, SNOR_PROTO_1_1_1);
-
-	if (info->flags & SPI_NOR_OCTAL_DTR_PP) {
+	if (info_flags & SPI_NOR_OCTAL_DTR_PP) {
 		params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
 		/*
 		 * Since xSPI Page Program opcode is backward compatible with
@@ -2646,23 +2633,49 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	 */
 	erase_mask = 0;
 	i = 0;
-	if (info->flags & SECT_4K_PMC) {
+	if (info_flags & SECT_4K_PMC) {
 		erase_mask |= BIT(i);
 		spi_nor_set_erase_type(&map->erase_type[i], 4096u,
 				       SPINOR_OP_BE_4K_PMC);
 		i++;
-	} else if (info->flags & SECT_4K) {
+	} else if (info_flags & SECT_4K) {
 		erase_mask |= BIT(i);
 		spi_nor_set_erase_type(&map->erase_type[i], 4096u,
 				       SPINOR_OP_BE_4K);
 		i++;
 	}
 	erase_mask |= BIT(i);
-	spi_nor_set_erase_type(&map->erase_type[i], info->sector_size,
+	spi_nor_set_erase_type(&map->erase_type[i], nor->info->sector_size,
 			       SPINOR_OP_SE);
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
+/**
+ * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
+ * based on JESD216 SFDP standard.
+ * @nor:	pointer to a 'struct spi_nor'.
+ *
+ * The method has a roll-back mechanism: in case the SFDP parsing fails, the
+ * legacy flash parameters and settings will be restored.
+ */
+static void spi_nor_sfdp_init_params(struct spi_nor *nor)
+{
+	struct spi_nor_flash_parameter sfdp_params;
+
+	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
+
+	if (!spi_nor_parse_sfdp(nor)) {
+		spi_nor_post_sfdp_fixups(nor);
+	} else {
+		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
+		nor->addr_width = 0;
+		nor->flags &= ~SNOR_F_4B_OPCODES;
+
+		if (nor->info->flags & SPI_NOR_PARSE_SFDP)
+			spi_nor_skip_sfdp_init_params(nor);
+	}
+}
+
 /**
  * spi_nor_nonsfdp_init_flags() - Initialize NOR flags for settings that are not
  * defined in the JESD216 SFDP standard, thus can not be retrieved when parsing
@@ -2760,6 +2773,19 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 		spi_nor_init_default_locking_ops(nor);
 }
 
+static void spi_nor_init_params_deprecated(struct spi_nor *nor)
+{
+	spi_nor_skip_sfdp_init_params(nor);
+
+	spi_nor_manufacturer_init_params(nor);
+
+	if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+				 SPI_NOR_OCTAL_READ |
+				 SPI_NOR_OCTAL_DTR_READ)) &&
+	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
+		spi_nor_sfdp_init_params(nor);
+}
+
 /**
  * spi_nor_init_params() - Initialize the flash's parameters and settings.
  * @nor:	pointer to a 'struct spi_nor'.
@@ -2801,15 +2827,12 @@ static int spi_nor_init_params(struct spi_nor *nor)
 	if (!nor->params)
 		return -ENOMEM;
 
-	spi_nor_info_init_params(nor);
+	spi_nor_init_default_params(nor);
 
-	spi_nor_manufacturer_init_params(nor);
-
-	if ((nor->info->flags & (SPI_NOR_PARSE_SFDP |
-				 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-				 SPI_NOR_OCTAL_READ | SPI_NOR_OCTAL_DTR_READ)) &&
-	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
+	if (nor->info->flags & SPI_NOR_PARSE_SFDP)
 		spi_nor_sfdp_init_params(nor);
+	else
+		spi_nor_init_params_deprecated(nor);
 
 	spi_nor_late_init_params(nor);
 
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

New flash additions that support SFDP should be declared with
SPI_NOR_PARSE_SFDP and with all the other flags that are not SFDP
discoverable.
Keep the old way of initializing the flash, until all the flashes
are converted to use either SPI_NOR_PARSE_SFDP or SPI_NOR_SKIP_SFDP.
Since we want to get rid of the default_init() hook, the rollback
mechanism for flashes that use SPI_NOR_PARSE_SFDP does not call
spi_nor_manufacturer_init_params().
Split spi_nor_info_init_params() in spi_nor_init_default_params()
and spi_nor_skip_sfdp_init_params(). spi_nor_init_default_params() is
called for all the flashes regardless if they support SFDP or not.
spi_nor_skip_sfdp_init_params() is called just for the flashes that
do not define SFDP and initializes parameters and setting solely based
on flash_info data.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 187 +++++++++++++++++++++----------------
 1 file changed, 105 insertions(+), 82 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 40d98ae300ca..c509f257a6c3 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2493,6 +2493,56 @@ static int spi_nor_setup(struct spi_nor *nor,
 	return nor->params->setup(nor, hwcaps);
 }
 
+/**
+ * spi_nor_init_default_params() - Default initialization of flash parameters
+ * and settings. Done for all flashes, regardless is they define SFDP tables
+ * or not.
+ * @nor:	pointer to a 'struct spi_nor'.
+ */
+static void spi_nor_init_default_params(struct spi_nor *nor)
+{
+	struct spi_nor_flash_parameter *params = nor->params;
+	const struct flash_info *info = nor->info;
+	struct device_node *np = spi_nor_get_flash_node(nor);
+
+	params->quad_enable = spi_nor_sr2_bit1_quad_enable;
+	params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
+	params->setup = spi_nor_default_setup;
+	params->otp.org = &info->otp_org;
+
+	/* Default to 16-bit Write Status (01h) Command */
+	nor->flags |= SNOR_F_HAS_16BIT_SR;
+
+	/* Set SPI NOR sizes. */
+	params->writesize = 1;
+	params->size = (u64)info->sector_size * info->n_sectors;
+	params->page_size = info->page_size;
+
+	if (!(info->flags & SPI_NOR_NO_FR)) {
+		/* Default to Fast Read for DT and non-DT platform devices. */
+		params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
+
+		/* Mask out Fast Read if not requested at DT instantiation. */
+		if (np && !of_property_read_bool(np, "m25p,fast-read"))
+			params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
+	}
+
+	/* (Fast) Read settings. */
+	params->hwcaps.mask |= SNOR_HWCAPS_READ;
+	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ],
+				  0, 0, SPINOR_OP_READ,
+				  SNOR_PROTO_1_1_1);
+
+	if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
+		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_FAST],
+					  0, 8, SPINOR_OP_READ_FAST,
+					  SNOR_PROTO_1_1_1);
+	/* Page Program settings. */
+	params->hwcaps.mask |= SNOR_HWCAPS_PP;
+	spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP],
+				SPINOR_OP_PP, SNOR_PROTO_1_1_1);
+}
+
 /**
  * spi_nor_manufacturer_init_params() - Initialize the flash's parameters and
  * settings based on MFR register and ->default_init() hook.
@@ -2528,109 +2578,46 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
 }
 
 /**
- * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
- * based on JESD216 SFDP standard.
- * @nor:	pointer to a 'struct spi_nor'.
- *
- * The method has a roll-back mechanism: in case the SFDP parsing fails, the
- * legacy flash parameters and settings will be restored.
- */
-static void spi_nor_sfdp_init_params(struct spi_nor *nor)
-{
-	struct spi_nor_flash_parameter sfdp_params;
-
-	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
-
-	if (!spi_nor_parse_sfdp(nor)) {
-		spi_nor_post_sfdp_fixups(nor);
-	} else {
-		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
-		nor->addr_width = 0;
-		nor->flags &= ~SNOR_F_4B_OPCODES;
-	}
-}
-
-/**
- * spi_nor_info_init_params() - Initialize the flash's parameters and settings
- * based on nor->info data.
+ * spi_nor_skip_sfdp_init_params() - Initialize the flash's parameters and
+ * settings based on nor->info data.
  * @nor:	pointer to a 'struct spi_nor'.
  */
-static void spi_nor_info_init_params(struct spi_nor *nor)
+static void spi_nor_skip_sfdp_init_params(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter *params = nor->params;
 	struct spi_nor_erase_map *map = &params->erase_map;
-	const struct flash_info *info = nor->info;
-	struct device_node *np = spi_nor_get_flash_node(nor);
+	const u32 info_flags = nor->info->flags & SFDP_FLAGS_MASK;
 	u8 i, erase_mask;
 
-	/* Initialize default flash parameters and settings. */
-	params->quad_enable = spi_nor_sr2_bit1_quad_enable;
-	params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
-	params->setup = spi_nor_default_setup;
-	params->otp.org = &info->otp_org;
-
-	/* Default to 16-bit Write Status (01h) Command */
-	nor->flags |= SNOR_F_HAS_16BIT_SR;
-
-	/* Set SPI NOR sizes. */
-	params->writesize = 1;
-	params->size = (u64)info->sector_size * info->n_sectors;
-	params->page_size = info->page_size;
-
-	if (!(info->flags & SPI_NOR_NO_FR)) {
-		/* Default to Fast Read for DT and non-DT platform devices. */
-		params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
-
-		/* Mask out Fast Read if not requested at DT instantiation. */
-		if (np && !of_property_read_bool(np, "m25p,fast-read"))
-			params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
-	}
-
-	/* (Fast) Read settings. */
-	params->hwcaps.mask |= SNOR_HWCAPS_READ;
-	spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ],
-				  0, 0, SPINOR_OP_READ,
-				  SNOR_PROTO_1_1_1);
-
-	if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
-		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_FAST],
-					  0, 8, SPINOR_OP_READ_FAST,
-					  SNOR_PROTO_1_1_1);
-
-	if (info->flags & SPI_NOR_DUAL_READ) {
+	if (info_flags & SPI_NOR_DUAL_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_2],
 					  0, 8, SPINOR_OP_READ_1_1_2,
 					  SNOR_PROTO_1_1_2);
 	}
 
-	if (info->flags & SPI_NOR_QUAD_READ) {
+	if (info_flags & SPI_NOR_QUAD_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_4;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_4],
 					  0, 8, SPINOR_OP_READ_1_1_4,
 					  SNOR_PROTO_1_1_4);
 	}
 
-	if (info->flags & SPI_NOR_OCTAL_READ) {
+	if (info_flags & SPI_NOR_OCTAL_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_8],
 					  0, 8, SPINOR_OP_READ_1_1_8,
 					  SNOR_PROTO_1_1_8);
 	}
 
-	if (info->flags & SPI_NOR_OCTAL_DTR_READ) {
+	if (info_flags & SPI_NOR_OCTAL_DTR_READ) {
 		params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
 		spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_8_8_8_DTR],
 					  0, 20, SPINOR_OP_READ_FAST,
 					  SNOR_PROTO_8_8_8_DTR);
 	}
 
-	/* Page Program settings. */
-	params->hwcaps.mask |= SNOR_HWCAPS_PP;
-	spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP],
-				SPINOR_OP_PP, SNOR_PROTO_1_1_1);
-
-	if (info->flags & SPI_NOR_OCTAL_DTR_PP) {
+	if (info_flags & SPI_NOR_OCTAL_DTR_PP) {
 		params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR;
 		/*
 		 * Since xSPI Page Program opcode is backward compatible with
@@ -2646,23 +2633,49 @@ static void spi_nor_info_init_params(struct spi_nor *nor)
 	 */
 	erase_mask = 0;
 	i = 0;
-	if (info->flags & SECT_4K_PMC) {
+	if (info_flags & SECT_4K_PMC) {
 		erase_mask |= BIT(i);
 		spi_nor_set_erase_type(&map->erase_type[i], 4096u,
 				       SPINOR_OP_BE_4K_PMC);
 		i++;
-	} else if (info->flags & SECT_4K) {
+	} else if (info_flags & SECT_4K) {
 		erase_mask |= BIT(i);
 		spi_nor_set_erase_type(&map->erase_type[i], 4096u,
 				       SPINOR_OP_BE_4K);
 		i++;
 	}
 	erase_mask |= BIT(i);
-	spi_nor_set_erase_type(&map->erase_type[i], info->sector_size,
+	spi_nor_set_erase_type(&map->erase_type[i], nor->info->sector_size,
 			       SPINOR_OP_SE);
 	spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
 
+/**
+ * spi_nor_sfdp_init_params() - Initialize the flash's parameters and settings
+ * based on JESD216 SFDP standard.
+ * @nor:	pointer to a 'struct spi_nor'.
+ *
+ * The method has a roll-back mechanism: in case the SFDP parsing fails, the
+ * legacy flash parameters and settings will be restored.
+ */
+static void spi_nor_sfdp_init_params(struct spi_nor *nor)
+{
+	struct spi_nor_flash_parameter sfdp_params;
+
+	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
+
+	if (!spi_nor_parse_sfdp(nor)) {
+		spi_nor_post_sfdp_fixups(nor);
+	} else {
+		memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
+		nor->addr_width = 0;
+		nor->flags &= ~SNOR_F_4B_OPCODES;
+
+		if (nor->info->flags & SPI_NOR_PARSE_SFDP)
+			spi_nor_skip_sfdp_init_params(nor);
+	}
+}
+
 /**
  * spi_nor_nonsfdp_init_flags() - Initialize NOR flags for settings that are not
  * defined in the JESD216 SFDP standard, thus can not be retrieved when parsing
@@ -2760,6 +2773,19 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
 		spi_nor_init_default_locking_ops(nor);
 }
 
+static void spi_nor_init_params_deprecated(struct spi_nor *nor)
+{
+	spi_nor_skip_sfdp_init_params(nor);
+
+	spi_nor_manufacturer_init_params(nor);
+
+	if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+				 SPI_NOR_OCTAL_READ |
+				 SPI_NOR_OCTAL_DTR_READ)) &&
+	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
+		spi_nor_sfdp_init_params(nor);
+}
+
 /**
  * spi_nor_init_params() - Initialize the flash's parameters and settings.
  * @nor:	pointer to a 'struct spi_nor'.
@@ -2801,15 +2827,12 @@ static int spi_nor_init_params(struct spi_nor *nor)
 	if (!nor->params)
 		return -ENOMEM;
 
-	spi_nor_info_init_params(nor);
+	spi_nor_init_default_params(nor);
 
-	spi_nor_manufacturer_init_params(nor);
-
-	if ((nor->info->flags & (SPI_NOR_PARSE_SFDP |
-				 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-				 SPI_NOR_OCTAL_READ | SPI_NOR_OCTAL_DTR_READ)) &&
-	    !(nor->info->flags & SPI_NOR_SKIP_SFDP))
+	if (nor->info->flags & SPI_NOR_PARSE_SFDP)
 		spi_nor_sfdp_init_params(nor);
+	else
+		spi_nor_init_params_deprecated(nor);
 
 	spi_nor_late_init_params(nor);
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

spi_nor_setup() configures the SPI NOR memory. Setting the addr width
is too a configuration, hence we can move the spi_nor_set_addr_width()
in spi_nor_setup().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.c | 102 +++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 50 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index c509f257a6c3..ea26f27a3229 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2484,13 +2484,61 @@ static int spi_nor_default_setup(struct spi_nor *nor,
 	return 0;
 }
 
+static int spi_nor_set_addr_width(struct spi_nor *nor)
+{
+	if (nor->addr_width) {
+		/* already configured from SFDP */
+	} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
+		/*
+		 * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
+		 * in this protocol an odd address width cannot be used because
+		 * then the address phase would only span a cycle and a half.
+		 * Half a cycle would be left over. We would then have to start
+		 * the dummy phase in the middle of a cycle and so too the data
+		 * phase, and we will end the transaction with half a cycle left
+		 * over.
+		 *
+		 * Force all 8D-8D-8D flashes to use an address width of 4 to
+		 * avoid this situation.
+		 */
+		nor->addr_width = 4;
+	} else if (nor->info->addr_width) {
+		nor->addr_width = nor->info->addr_width;
+	} else {
+		nor->addr_width = 3;
+	}
+
+	if (nor->addr_width == 3 && nor->mtd.size > 0x1000000) {
+		/* enable 4-byte addressing if the device exceeds 16MiB */
+		nor->addr_width = 4;
+	}
+
+	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
+		dev_dbg(nor->dev, "address width is too large: %u\n",
+			nor->addr_width);
+		return -EINVAL;
+	}
+
+	/* Set 4byte opcodes when possible. */
+	if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
+	    !(nor->flags & SNOR_F_HAS_4BAIT))
+		spi_nor_set_4byte_opcodes(nor);
+
+	return 0;
+}
+
 static int spi_nor_setup(struct spi_nor *nor,
 			 const struct spi_nor_hwcaps *hwcaps)
 {
-	if (!nor->params->setup)
-		return 0;
+	int ret;
 
-	return nor->params->setup(nor, hwcaps);
+	if (nor->params->setup) {
+		ret = nor->params->setup(nor, hwcaps);
+		if (ret)
+			return ret;
+	}
+
+	return spi_nor_set_addr_width(nor);
 }
 
 /**
@@ -3079,49 +3127,6 @@ static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
 	return NULL;
 }
 
-static int spi_nor_set_addr_width(struct spi_nor *nor)
-{
-	if (nor->addr_width) {
-		/* already configured from SFDP */
-	} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
-		/*
-		 * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
-		 * in this protocol an odd address width cannot be used because
-		 * then the address phase would only span a cycle and a half.
-		 * Half a cycle would be left over. We would then have to start
-		 * the dummy phase in the middle of a cycle and so too the data
-		 * phase, and we will end the transaction with half a cycle left
-		 * over.
-		 *
-		 * Force all 8D-8D-8D flashes to use an address width of 4 to
-		 * avoid this situation.
-		 */
-		nor->addr_width = 4;
-	} else if (nor->info->addr_width) {
-		nor->addr_width = nor->info->addr_width;
-	} else {
-		nor->addr_width = 3;
-	}
-
-	if (nor->addr_width == 3 && nor->mtd.size > 0x1000000) {
-		/* enable 4-byte addressing if the device exceeds 16MiB */
-		nor->addr_width = 4;
-	}
-
-	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
-		dev_dbg(nor->dev, "address width is too large: %u\n",
-			nor->addr_width);
-		return -EINVAL;
-	}
-
-	/* Set 4byte opcodes when possible. */
-	if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
-	    !(nor->flags & SNOR_F_HAS_4BAIT))
-		spi_nor_set_4byte_opcodes(nor);
-
-	return 0;
-}
-
 static void spi_nor_debugfs_init(struct spi_nor *nor,
 				 const struct flash_info *info)
 {
@@ -3253,15 +3258,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	 * - select op codes for (Fast) Read, Page Program and Sector Erase.
 	 * - set the number of dummy cycles (mode cycles + wait states).
 	 * - set the SPI protocols for register and memory accesses.
+	 * - set the address width.
 	 */
 	ret = spi_nor_setup(nor, hwcaps);
 	if (ret)
 		return ret;
 
-	ret = spi_nor_set_addr_width(nor);
-	if (ret)
-		return ret;
-
 	/* Send all the required SPI flash commands to initialize device */
 	ret = spi_nor_init(nor);
 	if (ret)
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

spi_nor_setup() configures the SPI NOR memory. Setting the addr width
is too a configuration, hence we can move the spi_nor_set_addr_width()
in spi_nor_setup().

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi-nor/core.c | 102 +++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 50 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index c509f257a6c3..ea26f27a3229 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2484,13 +2484,61 @@ static int spi_nor_default_setup(struct spi_nor *nor,
 	return 0;
 }
 
+static int spi_nor_set_addr_width(struct spi_nor *nor)
+{
+	if (nor->addr_width) {
+		/* already configured from SFDP */
+	} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
+		/*
+		 * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
+		 * in this protocol an odd address width cannot be used because
+		 * then the address phase would only span a cycle and a half.
+		 * Half a cycle would be left over. We would then have to start
+		 * the dummy phase in the middle of a cycle and so too the data
+		 * phase, and we will end the transaction with half a cycle left
+		 * over.
+		 *
+		 * Force all 8D-8D-8D flashes to use an address width of 4 to
+		 * avoid this situation.
+		 */
+		nor->addr_width = 4;
+	} else if (nor->info->addr_width) {
+		nor->addr_width = nor->info->addr_width;
+	} else {
+		nor->addr_width = 3;
+	}
+
+	if (nor->addr_width == 3 && nor->mtd.size > 0x1000000) {
+		/* enable 4-byte addressing if the device exceeds 16MiB */
+		nor->addr_width = 4;
+	}
+
+	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
+		dev_dbg(nor->dev, "address width is too large: %u\n",
+			nor->addr_width);
+		return -EINVAL;
+	}
+
+	/* Set 4byte opcodes when possible. */
+	if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
+	    !(nor->flags & SNOR_F_HAS_4BAIT))
+		spi_nor_set_4byte_opcodes(nor);
+
+	return 0;
+}
+
 static int spi_nor_setup(struct spi_nor *nor,
 			 const struct spi_nor_hwcaps *hwcaps)
 {
-	if (!nor->params->setup)
-		return 0;
+	int ret;
 
-	return nor->params->setup(nor, hwcaps);
+	if (nor->params->setup) {
+		ret = nor->params->setup(nor, hwcaps);
+		if (ret)
+			return ret;
+	}
+
+	return spi_nor_set_addr_width(nor);
 }
 
 /**
@@ -3079,49 +3127,6 @@ static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
 	return NULL;
 }
 
-static int spi_nor_set_addr_width(struct spi_nor *nor)
-{
-	if (nor->addr_width) {
-		/* already configured from SFDP */
-	} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
-		/*
-		 * In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
-		 * in this protocol an odd address width cannot be used because
-		 * then the address phase would only span a cycle and a half.
-		 * Half a cycle would be left over. We would then have to start
-		 * the dummy phase in the middle of a cycle and so too the data
-		 * phase, and we will end the transaction with half a cycle left
-		 * over.
-		 *
-		 * Force all 8D-8D-8D flashes to use an address width of 4 to
-		 * avoid this situation.
-		 */
-		nor->addr_width = 4;
-	} else if (nor->info->addr_width) {
-		nor->addr_width = nor->info->addr_width;
-	} else {
-		nor->addr_width = 3;
-	}
-
-	if (nor->addr_width == 3 && nor->mtd.size > 0x1000000) {
-		/* enable 4-byte addressing if the device exceeds 16MiB */
-		nor->addr_width = 4;
-	}
-
-	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
-		dev_dbg(nor->dev, "address width is too large: %u\n",
-			nor->addr_width);
-		return -EINVAL;
-	}
-
-	/* Set 4byte opcodes when possible. */
-	if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
-	    !(nor->flags & SNOR_F_HAS_4BAIT))
-		spi_nor_set_4byte_opcodes(nor);
-
-	return 0;
-}
-
 static void spi_nor_debugfs_init(struct spi_nor *nor,
 				 const struct flash_info *info)
 {
@@ -3253,15 +3258,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	 * - select op codes for (Fast) Read, Page Program and Sector Erase.
 	 * - set the number of dummy cycles (mode cycles + wait states).
 	 * - set the SPI protocols for register and memory accesses.
+	 * - set the address width.
 	 */
 	ret = spi_nor_setup(nor, hwcaps);
 	if (ret)
 		return ret;
 
-	ret = spi_nor_set_addr_width(nor);
-	if (ret)
-		return ret;
-
 	/* Send all the required SPI flash commands to initialize device */
 	ret = spi_nor_init(nor);
 	if (ret)
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 40e55b531edb..b3fd54b24e25 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -199,8 +199,9 @@ static const struct flash_info sst_parts[] = {
 	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
 			      SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
+			      SPI_NOR_PARSE_SFDP |
+			      NON_SFDP_FLAGS(SPI_NOR_HAS_LOCK |
+					     SPI_NOR_SWP_IS_VOLATILE))
 		.fixups = &sst26vf_fixups },
 };
 
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/sst.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
index 40e55b531edb..b3fd54b24e25 100644
--- a/drivers/mtd/spi-nor/sst.c
+++ b/drivers/mtd/spi-nor/sst.c
@@ -199,8 +199,9 @@ static const struct flash_info sst_parts[] = {
 	{ "sst26vf016b", INFO(0xbf2641, 0, 64 * 1024, 32,
 			      SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "sst26vf064b", INFO(0xbf2643, 0, 64 * 1024, 128,
-			      SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      SPI_NOR_HAS_LOCK | SPI_NOR_SWP_IS_VOLATILE)
+			      SPI_NOR_PARSE_SFDP |
+			      NON_SFDP_FLAGS(SPI_NOR_HAS_LOCK |
+					     SPI_NOR_SWP_IS_VOLATILE))
 		.fixups = &sst26vf_fixups },
 };
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/winbond.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index dd4be0f78e67..fd65fa7a5d94 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -95,7 +95,7 @@ static const struct flash_info winbond_parts[] = {
 			  SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
 	  .fixups = &w25q256_fixups },
 	{ "w25q256jvm", INFO(0xef7019, 0, 64 * 1024, 512,
-			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
+			     SPI_NOR_PARSE_SFDP) },
 	{ "w25q256jw", INFO(0xef6019, 0, 64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
 	{ "w25m512jv", INFO(0xef7119, 0, 64 * 1024, 1024,
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/winbond.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index dd4be0f78e67..fd65fa7a5d94 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -95,7 +95,7 @@ static const struct flash_info winbond_parts[] = {
 			  SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
 	  .fixups = &w25q256_fixups },
 	{ "w25q256jvm", INFO(0xef7019, 0, 64 * 1024, 512,
-			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
+			     SPI_NOR_PARSE_SFDP) },
 	{ "w25q256jw", INFO(0xef6019, 0, 64 * 1024, 512,
 			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
 	{ "w25m512jv", INFO(0xef7119, 0, 64 * 1024, 1024,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 22/25] mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

s25fl256s0 does not define the SFDP tables nor implements the
RDSFDP 0x5a command. Skip the SFDP parsing in order to avoid
issuing an unsupported command to the flash.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/spansion.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index 3ee1cd3b8fb5..463ddd0776ec 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -209,8 +209,9 @@ static const struct flash_info spansion_parts[] = {
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			      USE_CLSR) },
 	{ "s25fl256s0", INFO6(0x010219, 0x4d0080, 256 * 1024, 128,
-			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      USE_CLSR) },
+			      SPI_NOR_SKIP_SFDP |
+			      SFDP_FLAGS(SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+					 USE_CLSR)) },
 	{ "s25fl256s1", INFO6(0x010219, 0x4d0180, 64 * 1024, 512,
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			      USE_CLSR) },
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 22/25] mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

s25fl256s0 does not define the SFDP tables nor implements the
RDSFDP 0x5a command. Skip the SFDP parsing in order to avoid
issuing an unsupported command to the flash.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/spansion.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index 3ee1cd3b8fb5..463ddd0776ec 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -209,8 +209,9 @@ static const struct flash_info spansion_parts[] = {
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			      USE_CLSR) },
 	{ "s25fl256s0", INFO6(0x010219, 0x4d0080, 256 * 1024, 128,
-			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			      USE_CLSR) },
+			      SPI_NOR_SKIP_SFDP |
+			      SFDP_FLAGS(SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+					 USE_CLSR)) },
 	{ "s25fl256s1", INFO6(0x010219, 0x4d0180, 64 * 1024, 512,
 			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			      USE_CLSR) },
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_1_4_4B
0x34.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/gigadevice.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/gigadevice.c b/drivers/mtd/spi-nor/gigadevice.c
index 59053f419642..90573c59ad8b 100644
--- a/drivers/mtd/spi-nor/gigadevice.c
+++ b/drivers/mtd/spi-nor/gigadevice.c
@@ -46,9 +46,9 @@ static const struct flash_info gigadevice_parts[] = {
 			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) },
 	{ "gd25q256", INFO(0xc84019, 0, 64 * 1024, 512,
-			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
-			   SPI_NOR_TB_SR_BIT6 |
+			   SPI_NOR_PARSE_SFDP |
+			   NON_SFDP_FLAGS(SPI_NOR_HAS_LOCK |
+					  SPI_NOR_HAS_TB | SPI_NOR_TB_SR_BIT6) |
 			   FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &gd25q256_fixups },
 };
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_1_4_4B
0x34.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/gigadevice.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/gigadevice.c b/drivers/mtd/spi-nor/gigadevice.c
index 59053f419642..90573c59ad8b 100644
--- a/drivers/mtd/spi-nor/gigadevice.c
+++ b/drivers/mtd/spi-nor/gigadevice.c
@@ -46,9 +46,9 @@ static const struct flash_info gigadevice_parts[] = {
 			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
 			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) },
 	{ "gd25q256", INFO(0xc84019, 0, 64 * 1024, 512,
-			   SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
-			   SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
-			   SPI_NOR_TB_SR_BIT6 |
+			   SPI_NOR_PARSE_SFDP |
+			   NON_SFDP_FLAGS(SPI_NOR_HAS_LOCK |
+					  SPI_NOR_HAS_TB | SPI_NOR_TB_SR_BIT6) |
 			   FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &gd25q256_fixups },
 };
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_4B 0x12.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/issi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/issi.c b/drivers/mtd/spi-nor/issi.c
index b2abe8202143..3c5ce2c2c646 100644
--- a/drivers/mtd/spi-nor/issi.c
+++ b/drivers/mtd/spi-nor/issi.c
@@ -45,7 +45,7 @@ static const struct flash_info issi_parts[] = {
 	{ "is25lp128",  INFO(0x9d6018, 0, 64 * 1024, 256,
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "is25lp256",  INFO(0x9d6019, 0, 64 * 1024, 512,
-			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+			     SPI_NOR_PARSE_SFDP |
 			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 	{ "is25wp032",  INFO(0x9d7016, 0, 64 * 1024,  64,
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_4B 0x12.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/issi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/issi.c b/drivers/mtd/spi-nor/issi.c
index b2abe8202143..3c5ce2c2c646 100644
--- a/drivers/mtd/spi-nor/issi.c
+++ b/drivers/mtd/spi-nor/issi.c
@@ -45,7 +45,7 @@ static const struct flash_info issi_parts[] = {
 	{ "is25lp128",  INFO(0x9d6018, 0, 64 * 1024, 256,
 			     SECT_4K | SPI_NOR_DUAL_READ) },
 	{ "is25lp256",  INFO(0x9d6019, 0, 64 * 1024, 512,
-			     SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ |
+			     SPI_NOR_PARSE_SFDP |
 			     FIXUP_FLAGS(SPI_NOR_4B_OPCODES))
 		.fixups = &is25lp256_fixups },
 	{ "is25wp032",  INFO(0x9d7016, 0, 64 * 1024,  64,
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-10-29 17:26   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_4_4_4B
0x3e.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/macronix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index d0285e60092e..bd7b1d63783e 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -62,7 +62,7 @@ static const struct flash_info macronix_parts[] = {
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512,
-			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
+			      SPI_NOR_PARSE_SFDP)
 		.fixups = &mx25l25635_fixups },
 	{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
 			      SECT_4K | FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
@ 2021-10-29 17:26   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-10-29 17:26 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, Tudor Ambarus, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, mail, zhengxunli

Get rid of the static initialization of the flash parameters and
init them when parsing SFDP.
Generated a 256 Kbyte random data and did an erase, write, read back
and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_4_4_4B
0x3e.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/mtd/spi-nor/macronix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index d0285e60092e..bd7b1d63783e 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -62,7 +62,7 @@ static const struct flash_info macronix_parts[] = {
 			      SECT_4K | SPI_NOR_DUAL_READ |
 			      SPI_NOR_QUAD_READ) },
 	{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512,
-			      SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
+			      SPI_NOR_PARSE_SFDP)
 		.fixups = &mx25l25635_fixups },
 	{ "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512,
 			      SECT_4K | FIXUP_FLAGS(SPI_NOR_4B_OPCODES)) },
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-10-29 17:31     ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:31 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
bf2643
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
sst
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
sst26vf064b
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sst26vf064b-sfdp
root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp 
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 0081 0601 0100 ff00 00bf 1801 0200 0100
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20fd fff1 ffff 03ff eb44 6b08 3b08 bb80
0000040 fffe ffff ffff ff00 ffff 0b44 200c d80d
0000050 d80f d810 9120 2448 6f80 811d 0fed 3877
0000060 b030 b030 fff7 ffff c229 ff5c 30f0 80c0
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000100 00ff ff04 7ff3 0000 7ff5 0000 fff9 007d
0000110 7ff5 0000 7ff3 0000 ffff ffff ffff ffff
0000120 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000200 26bf ff43 5fb9 fffd f230 f360 ff32 120a
0000210 4623 0fff 3219 190f ff19 ffff ffff ffff
0000220 6600 3899 05ff 3501 0406 3202 30b0 4272
0000230 e88d 8898 85a5 9fc0 5aaf ffff ec06 0c06
0000240 0300 0b08 ffff ffff 07ff ffff 0202 06ff
0000250 0003 fdfd 0704 fc00 0003 fefe 0202 0e07
0000260

>  drivers/mtd/spi-nor/sst.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
@ 2021-10-29 17:31     ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:31 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
bf2643
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
sst
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
sst26vf064b
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sst26vf064b-sfdp
root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp 
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 0081 0601 0100 ff00 00bf 1801 0200 0100
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20fd fff1 ffff 03ff eb44 6b08 3b08 bb80
0000040 fffe ffff ffff ff00 ffff 0b44 200c d80d
0000050 d80f d810 9120 2448 6f80 811d 0fed 3877
0000060 b030 b030 fff7 ffff c229 ff5c 30f0 80c0
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000100 00ff ff04 7ff3 0000 7ff5 0000 fff9 007d
0000110 7ff5 0000 7ff3 0000 ffff ffff ffff ffff
0000120 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000200 26bf ff43 5fb9 fffd f230 f360 ff32 120a
0000210 4623 0fff 3219 190f ff19 ffff ffff ffff
0000220 6600 3899 05ff 3501 0406 3202 30b0 4272
0000230 e88d 8898 85a5 9fc0 5aaf ffff ec06 0c06
0000240 0300 0b08 ffff ffff 07ff ffff 0202 06ff
0000250 0003 fdfd 0704 fc00 0003 fefe 0202 0e07
0000260

>  drivers/mtd/spi-nor/sst.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-10-29 17:31     ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:31 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
ef7019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
winbond
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
w25q256jvm
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sfdp-w25q256jvm
root@sama5d2-xplained:~# hexdump sfdp-w25q256jvm
0000000 4653 5044 0105 ff00 0500 1001 0080 ff00
0000010 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000080 20e5 fffb ffff 0fff eb44 6b08 3b08 bb42
0000090 fffe ffff ffff 0000 ffff eb40 200c 520f
00000a0 d810 0000 0236 00a6 ea82 d314 63e9 3376
00000b0 757a 757a a2f7 5cd5 f719 ff4d 70e9 a5f9
00000c0

>  drivers/mtd/spi-nor/winbond.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
@ 2021-10-29 17:31     ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:31 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
ef7019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
winbond
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
w25q256jvm
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sfdp-w25q256jvm
root@sama5d2-xplained:~# hexdump sfdp-w25q256jvm
0000000 4653 5044 0105 ff00 0500 1001 0080 ff00
0000010 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000080 20e5 fffb ffff 0fff eb44 6b08 3b08 bb42
0000090 fffe ffff ffff 0000 ffff eb40 200c 520f
00000a0 d810 0000 0236 00a6 ea82 d314 63e9 3376
00000b0 757a 757a a2f7 5cd5 f719 ff4d 70e9 a5f9
00000c0

>  drivers/mtd/spi-nor/winbond.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-10-29 17:33     ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:33 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_1_4_4B
> 0x34.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
c84019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
gigadevice
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname    
gd25q256
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > gd25q256-sfdp
root@sama5d2-xplained:~# hexdump gd25q256-sfdp 
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 00c8 0301 0090 ff00 0084 0201 00c0 ff00
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fff3 ffff 0fff eb44 6b08 3b08 bb42
0000040 ffee ffff ffff ff00 ffff ff00 200c 520f
0000050 d810 ff00 6242 fec9 e982 5814 60ec 3306
0000060 757a 757a bd04 5cd5 0600 0044 5008 0100
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000090 3600 2700 f99e 6477 cbfc ffff ffff ffff
00000a0 ffff ffff ffff ffff ffff ffff ffff ffff
*
00000c0 0eff fff0 5c21 ffdc                    
00000c8

>  drivers/mtd/spi-nor/gigadevice.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
@ 2021-10-29 17:33     ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:33 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_1_4_4B
> 0x34.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---

root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
c84019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
gigadevice
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname    
gd25q256
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > gd25q256-sfdp
root@sama5d2-xplained:~# hexdump gd25q256-sfdp 
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 00c8 0301 0090 ff00 0084 0201 00c0 ff00
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fff3 ffff 0fff eb44 6b08 3b08 bb42
0000040 ffee ffff ffff ff00 ffff ff00 200c 520f
0000050 d810 ff00 6242 fec9 e982 5814 60ec 3306
0000060 757a 757a bd04 5cd5 0600 0044 5008 0100
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000090 3600 2700 f99e 6477 cbfc ffff ffff ffff
00000a0 ffff ffff ffff ffff ffff ffff ffff ffff
*
00000c0 0eff fff0 5c21 ffdc                    
00000c8

>  drivers/mtd/spi-nor/gigadevice.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-10-29 17:33     ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:33 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_4B 0x12.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
9d6019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
issi
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
is25lp256
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sfdp-issi
root@sama5d2-xplained:~# hexdump sfdp-issi 
0000000 4653 5044 0106 ff01 0600 1001 0030 ff00
0000010 059d 0301 0080 0200 ffff ffff ffff ffff
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fff9 ffff 0fff eb44 6b08 3b08 bb80
0000040 fffe ffff ffff ff00 ffff eb44 200c 520f
0000050 d810 ff00 4a23 00c9 d882 ce11 cdcc 4668
0000060 757a 757a aef7 5cd5 424a ff2c 30f0 a9f2
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
0000080 3600 2300 f99e 64c0 ef8f ffff          
000008c
>  drivers/mtd/spi-nor/issi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
@ 2021-10-29 17:33     ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:33 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_4B 0x12.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
9d6019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
issi
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
is25lp256
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > sfdp-issi
root@sama5d2-xplained:~# hexdump sfdp-issi 
0000000 4653 5044 0106 ff01 0600 1001 0030 ff00
0000010 059d 0301 0080 0200 ffff ffff ffff ffff
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fff9 ffff 0fff eb44 6b08 3b08 bb80
0000040 fffe ffff ffff ff00 ffff eb44 200c 520f
0000050 d810 ff00 4a23 00c9 d882 ce11 cdcc 4668
0000060 757a 757a aef7 5cd5 424a ff2c 30f0 a9f2
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
0000080 3600 2300 f99e 64c0 ef8f ffff          
000008c
>  drivers/mtd/spi-nor/issi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-10-29 17:34     ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:34 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_4_4_4B
> 0x3e.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
c22019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
macronix
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname    
mx25l25635e
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > mx25l25635e-sfdp
root@sama5d2-xplained:~# hexdump mx25l25635e-sfdp
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 00c2 0401 0110 ff00 0084 0201 00c0 ff00
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fffb ffff 0fff eb44 6b08 3b08 bb04
0000040 fffe ffff ffff ff00 ffff eb44 200c 520f
0000050 d810 ff00 59d6 00dd 9f82 db03 0344 3867
0000060 b030 b030 bdf7 5cd5 9e4a ff29 50f0 85f9
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
00000c0 8f7f ffff 5c21 ffdc ffff ffff ffff ffff
00000d0 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000110 3600 2700 f99d 64c0 cb85 ffff ffff ffff
0000120
>  drivers/mtd/spi-nor/macronix.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
@ 2021-10-29 17:34     ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-10-29 17:34 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Get rid of the static initialization of the flash parameters and
> init them when parsing SFDP.
> Generated a 256 Kbyte random data and did an erase, write, read back
> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4_4B 0xec,
> for erases SPINOR_OP_BE_4K_4B 0x21, and for writes SPINOR_OP_PP_1_4_4_4B
> 0x3e.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
c22019
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
macronix
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname    
mx25l25635e
root@sama5d2-xplained:~# cat /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp > mx25l25635e-sfdp
root@sama5d2-xplained:~# hexdump mx25l25635e-sfdp
0000000 4653 5044 0106 ff02 0600 1001 0030 ff00
0000010 00c2 0401 0110 ff00 0084 0201 00c0 ff00
0000020 ffff ffff ffff ffff ffff ffff ffff ffff
0000030 20e5 fffb ffff 0fff eb44 6b08 3b08 bb04
0000040 fffe ffff ffff ff00 ffff eb44 200c 520f
0000050 d810 ff00 59d6 00dd 9f82 db03 0344 3867
0000060 b030 b030 bdf7 5cd5 9e4a ff29 50f0 85f9
0000070 ffff ffff ffff ffff ffff ffff ffff ffff
*
00000c0 8f7f ffff 5c21 ffdc ffff ffff ffff ffff
00000d0 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000110 3600 2700 f99d 64c0 cb85 ffff ffff ffff
0000120
>  drivers/mtd/spi-nor/macronix.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-11-08 10:15   ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-08 10:15 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	Nicolas.Ferre, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, mail, zhengxunli

Hi,

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code. 
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.
> 
> Changes in v3:
> - move late_init() in struct spi_nor_fixups and update patches accordingly.     
> R-b tags were dropped.
> - new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
> moves manufacturer specific flag out of the core.
> - update methods description to make it clear who sets when
> - introduce flash_info flag masks to make it clear when one should be set.
> - rework "parse SFDP first idea".
> 
> Tudor Ambarus (25):
>   mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
>   mtd: spi-nor: core: Use container_of to get the pointer to struct
>     spi_nor
>   mtd: spi-nor: Introduce spi_nor_set_mtd_info()
>   mtd: spi-nor: Get rid of nor->page_size
>   mtd: spi-nor: core: Introduce the late_init() hook
>   mtd: spi-nor: atmel: Use flash late_init() for locking
>   mtd: spi-nor: sst: Use flash late_init() for locking
>   mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
>   mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
>   mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
>   mtd: spi-nor: spansion: Use manufacturer late_init()
>   mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is
>     defined
>   mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
>   mtd: spi-nor: Introduce flash_info flags masks
>   mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
>   mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
>   mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
>   mtd: spi-nor: core: Init flash params based on SFDP first for new
>     flash additions
>   mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
>   mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
>   mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
>   mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
>   mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
>   mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
>   mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
> 
>  drivers/mtd/spi-nor/atmel.c      |   8 +-
>  drivers/mtd/spi-nor/core.c       | 480 +++++++++++++++++--------------
>  drivers/mtd/spi-nor/core.h       | 106 ++++---
>  drivers/mtd/spi-nor/gigadevice.c |   7 +-
>  drivers/mtd/spi-nor/issi.c       |   6 +-
>  drivers/mtd/spi-nor/macronix.c   |  15 +-
>  drivers/mtd/spi-nor/micron-st.c  |  20 +-
>  drivers/mtd/spi-nor/otp.c        |   2 +-
>  drivers/mtd/spi-nor/spansion.c   |  15 +-
>  drivers/mtd/spi-nor/sst.c        | 105 ++++---
>  drivers/mtd/spi-nor/swp.c        |   2 +-
>  drivers/mtd/spi-nor/winbond.c    |   7 +-
>  drivers/mtd/spi-nor/xilinx.c     |  21 +-
>  include/linux/mtd/spi-nor.h      |   2 -
>  14 files changed, 460 insertions(+), 336 deletions(-)
> 

I would like to apply this when -rc1 is out. Can some of you run some tests
and check if everything is ok? I have done few tests on the flashes that I
mentioned in the cover letter, all should be ok. I'm particularly interested
in the locking support. I can test the unlock_all on sst26vf064b validating
the locking part, but it would be good if locking is tested on other flash
too.

Thanks,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-11-08 10:15   ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-08 10:15 UTC (permalink / raw)
  To: michael, vigneshr, p.yadav
  Cc: macromorgan, jaimeliao, richard, esben, linux, knaerzche,
	linux-mtd, linux-arm-kernel, code, miquel.raynal, heiko.thiery,
	sr, figgyc, mail, zhengxunli

Hi,

On 10/29/21 8:26 PM, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code. 
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.
> 
> Changes in v3:
> - move late_init() in struct spi_nor_fixups and update patches accordingly.     
> R-b tags were dropped.
> - new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
> moves manufacturer specific flag out of the core.
> - update methods description to make it clear who sets when
> - introduce flash_info flag masks to make it clear when one should be set.
> - rework "parse SFDP first idea".
> 
> Tudor Ambarus (25):
>   mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
>   mtd: spi-nor: core: Use container_of to get the pointer to struct
>     spi_nor
>   mtd: spi-nor: Introduce spi_nor_set_mtd_info()
>   mtd: spi-nor: Get rid of nor->page_size
>   mtd: spi-nor: core: Introduce the late_init() hook
>   mtd: spi-nor: atmel: Use flash late_init() for locking
>   mtd: spi-nor: sst: Use flash late_init() for locking
>   mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
>   mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
>   mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
>   mtd: spi-nor: spansion: Use manufacturer late_init()
>   mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is
>     defined
>   mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
>   mtd: spi-nor: Introduce flash_info flags masks
>   mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
>   mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
>   mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
>   mtd: spi-nor: core: Init flash params based on SFDP first for new
>     flash additions
>   mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
>   mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
>   mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
>   mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
>   mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
>   mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
>   mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
> 
>  drivers/mtd/spi-nor/atmel.c      |   8 +-
>  drivers/mtd/spi-nor/core.c       | 480 +++++++++++++++++--------------
>  drivers/mtd/spi-nor/core.h       | 106 ++++---
>  drivers/mtd/spi-nor/gigadevice.c |   7 +-
>  drivers/mtd/spi-nor/issi.c       |   6 +-
>  drivers/mtd/spi-nor/macronix.c   |  15 +-
>  drivers/mtd/spi-nor/micron-st.c  |  20 +-
>  drivers/mtd/spi-nor/otp.c        |   2 +-
>  drivers/mtd/spi-nor/spansion.c   |  15 +-
>  drivers/mtd/spi-nor/sst.c        | 105 ++++---
>  drivers/mtd/spi-nor/swp.c        |   2 +-
>  drivers/mtd/spi-nor/winbond.c    |   7 +-
>  drivers/mtd/spi-nor/xilinx.c     |  21 +-
>  include/linux/mtd/spi-nor.h      |   2 -
>  14 files changed, 460 insertions(+), 336 deletions(-)
> 

I would like to apply this when -rc1 is out. Can some of you run some tests
and check if everything is ok? I have done few tests on the flashes that I
mentioned in the cover letter, all should be ok. I'm particularly interested
in the locking support. I can test the unlock_all on sst26vf064b validating
the locking part, but it would be good if locking is tested on other flash
too.

Thanks,
ta
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
  2021-11-08 10:15   ` Tudor.Ambarus
@ 2021-11-08 10:31     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-08 10:31 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-11-08 11:15, schrieb Tudor.Ambarus@microchip.com:
> Hi,
> 
> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>> Clean spi_nor_scan() and the flash parameters initialization code.
>> Tested all the flashes from patch set. If someone can test the
>> locking ops on few flashes would be great. It seems that my flashes
>> have the non volatile bits weared out.
>> 
>> This patch set is split from:
>> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
>> The ID collision series will be set in a dedicated patch set that will
>> depend on this one.
>> 
>> Changes in v3:
>> - move late_init() in struct spi_nor_fixups and update patches 
>> accordingly.
>> R-b tags were dropped.
>> - new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
>> moves manufacturer specific flag out of the core.
>> - update methods description to make it clear who sets when
>> - introduce flash_info flag masks to make it clear when one should be 
>> set.
>> - rework "parse SFDP first idea".
>> 
>> Tudor Ambarus (25):
>>   mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
>>   mtd: spi-nor: core: Use container_of to get the pointer to struct
>>     spi_nor
>>   mtd: spi-nor: Introduce spi_nor_set_mtd_info()
>>   mtd: spi-nor: Get rid of nor->page_size
>>   mtd: spi-nor: core: Introduce the late_init() hook
>>   mtd: spi-nor: atmel: Use flash late_init() for locking
>>   mtd: spi-nor: sst: Use flash late_init() for locking
>>   mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
>>   mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup 
>> method
>>   mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
>>   mtd: spi-nor: spansion: Use manufacturer late_init()
>>   mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP 
>> is
>>     defined
>>   mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
>>   mtd: spi-nor: Introduce flash_info flags masks
>>   mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
>>   mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
>>   mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
>>   mtd: spi-nor: core: Init flash params based on SFDP first for new
>>     flash additions
>>   mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
>>   mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
>>   mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
>>   mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
>>   mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
>>   mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
>>   mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
>> 
>>  drivers/mtd/spi-nor/atmel.c      |   8 +-
>>  drivers/mtd/spi-nor/core.c       | 480 
>> +++++++++++++++++--------------
>>  drivers/mtd/spi-nor/core.h       | 106 ++++---
>>  drivers/mtd/spi-nor/gigadevice.c |   7 +-
>>  drivers/mtd/spi-nor/issi.c       |   6 +-
>>  drivers/mtd/spi-nor/macronix.c   |  15 +-
>>  drivers/mtd/spi-nor/micron-st.c  |  20 +-
>>  drivers/mtd/spi-nor/otp.c        |   2 +-
>>  drivers/mtd/spi-nor/spansion.c   |  15 +-
>>  drivers/mtd/spi-nor/sst.c        | 105 ++++---
>>  drivers/mtd/spi-nor/swp.c        |   2 +-
>>  drivers/mtd/spi-nor/winbond.c    |   7 +-
>>  drivers/mtd/spi-nor/xilinx.c     |  21 +-
>>  include/linux/mtd/spi-nor.h      |   2 -
>>  14 files changed, 460 insertions(+), 336 deletions(-)
>> 
> 
> I would like to apply this when -rc1 is out. Can some of you run some 
> tests
> and check if everything is ok? I have done few tests on the flashes 
> that I
> mentioned in the cover letter, all should be ok. I'm particularly 
> interested
> in the locking support. I can test the unlock_all on sst26vf064b 
> validating
> the locking part, but it would be good if locking is tested on other 
> flash
> too.
> 

FWIW, I've quickly tested the series on a W25Q32JW (OTP only) and 
W25Q128 (OTP
and locking, OTP patch is not upstream).

Tested-by: Michael Walle <michael@walle.cc> #on w25q32jw and w25q128fw

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-11-08 10:31     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-08 10:31 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-11-08 11:15, schrieb Tudor.Ambarus@microchip.com:
> Hi,
> 
> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>> Clean spi_nor_scan() and the flash parameters initialization code.
>> Tested all the flashes from patch set. If someone can test the
>> locking ops on few flashes would be great. It seems that my flashes
>> have the non volatile bits weared out.
>> 
>> This patch set is split from:
>> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
>> The ID collision series will be set in a dedicated patch set that will
>> depend on this one.
>> 
>> Changes in v3:
>> - move late_init() in struct spi_nor_fixups and update patches 
>> accordingly.
>> R-b tags were dropped.
>> - new patch "mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag"
>> moves manufacturer specific flag out of the core.
>> - update methods description to make it clear who sets when
>> - introduce flash_info flag masks to make it clear when one should be 
>> set.
>> - rework "parse SFDP first idea".
>> 
>> Tudor Ambarus (25):
>>   mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
>>   mtd: spi-nor: core: Use container_of to get the pointer to struct
>>     spi_nor
>>   mtd: spi-nor: Introduce spi_nor_set_mtd_info()
>>   mtd: spi-nor: Get rid of nor->page_size
>>   mtd: spi-nor: core: Introduce the late_init() hook
>>   mtd: spi-nor: atmel: Use flash late_init() for locking
>>   mtd: spi-nor: sst: Use flash late_init() for locking
>>   mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
>>   mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup 
>> method
>>   mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
>>   mtd: spi-nor: spansion: Use manufacturer late_init()
>>   mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP 
>> is
>>     defined
>>   mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
>>   mtd: spi-nor: Introduce flash_info flags masks
>>   mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
>>   mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
>>   mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP
>>   mtd: spi-nor: core: Init flash params based on SFDP first for new
>>     flash additions
>>   mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
>>   mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
>>   mtd: spi-nor: winbond: w25q256jvm: Init flash based on SFDP
>>   mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing
>>   mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP
>>   mtd: spi-nor: issi: is25lp256: Init flash based on SFDP
>>   mtd: spi-nor: macronix: mx25l25635e: Init flash based on SFDP
>> 
>>  drivers/mtd/spi-nor/atmel.c      |   8 +-
>>  drivers/mtd/spi-nor/core.c       | 480 
>> +++++++++++++++++--------------
>>  drivers/mtd/spi-nor/core.h       | 106 ++++---
>>  drivers/mtd/spi-nor/gigadevice.c |   7 +-
>>  drivers/mtd/spi-nor/issi.c       |   6 +-
>>  drivers/mtd/spi-nor/macronix.c   |  15 +-
>>  drivers/mtd/spi-nor/micron-st.c  |  20 +-
>>  drivers/mtd/spi-nor/otp.c        |   2 +-
>>  drivers/mtd/spi-nor/spansion.c   |  15 +-
>>  drivers/mtd/spi-nor/sst.c        | 105 ++++---
>>  drivers/mtd/spi-nor/swp.c        |   2 +-
>>  drivers/mtd/spi-nor/winbond.c    |   7 +-
>>  drivers/mtd/spi-nor/xilinx.c     |  21 +-
>>  include/linux/mtd/spi-nor.h      |   2 -
>>  14 files changed, 460 insertions(+), 336 deletions(-)
>> 
> 
> I would like to apply this when -rc1 is out. Can some of you run some 
> tests
> and check if everything is ok? I have done few tests on the flashes 
> that I
> mentioned in the cover letter, all should be ok. I'm particularly 
> interested
> in the locking support. I can test the unlock_all on sst26vf064b 
> validating
> the locking part, but it would be good if locking is tested on other 
> flash
> too.
> 

FWIW, I've quickly tested the series on a W25Q32JW (OTP only) and 
W25Q128 (OTP
and locking, OTP patch is not upstream).

Tested-by: Michael Walle <michael@walle.cc> #on w25q32jw and w25q128fw

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  8:18     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:18 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Update the description of the otp member of the
> struct spi_nor_flash_parameter.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
> ---

You've forgot to add my former tag here. Anyway:

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
@ 2021-11-09  8:18     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:18 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Update the description of the otp member of the
> struct spi_nor_flash_parameter.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
> ---

You've forgot to add my former tag here. Anyway:

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  8:21     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:21 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> "struct mtd_info mtd" is member of "struct spi_nor", there's no need
> to use "mtd->priv". Get the pointer to the containing struct spi_nor
> by using container_of. While here, make the function inline and
> get rid of the __maybe_unused.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
@ 2021-11-09  8:21     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:21 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> "struct mtd_info mtd" is member of "struct spi_nor", there's no need
> to use "mtd->priv". Get the pointer to the containing struct spi_nor
> by using container_of. While here, make the function inline and
> get rid of the __maybe_unused.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  8:22     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:22 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> 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>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-09  8:22     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:22 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> 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>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  8:24     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:24 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> nor->page_size duplicated what nor->params->page_size indicates
> for no good reason. page_size is a flash parameter of fixed value
> and it is better suited to be found in nor->params->page_size.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

IIRC this patch already had my:
Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
@ 2021-11-09  8:24     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  8:24 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> nor->page_size duplicated what nor->params->page_size indicates
> for no good reason. page_size is a flash parameter of fixed value
> and it is better suited to be found in nor->params->page_size.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

IIRC this patch already had my:
Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
  2021-11-09  8:24     ` Michael Walle
@ 2021-11-09  8:34       ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09  8:34 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/9/21 10:24 AM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> nor->page_size duplicated what nor->params->page_size indicates
>> for no good reason. page_size is a flash parameter of fixed value
>> and it is better suited to be found in nor->params->page_size.
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
> 
> IIRC this patch already had my:

You're right, sorry. Next time I'll download the patches
from ml, to get the tags automatically.

> Reviewed-by: Michael Walle <michael@walle.cc>
Thanks,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size
@ 2021-11-09  8:34       ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09  8:34 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/9/21 10:24 AM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> nor->page_size duplicated what nor->params->page_size indicates
>> for no good reason. page_size is a flash parameter of fixed value
>> and it is better suited to be found in nor->params->page_size.
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
> 
> IIRC this patch already had my:

You're right, sorry. Next time I'll download the patches
from ml, to get the tags automatically.

> Reviewed-by: Michael Walle <michael@walle.cc>
Thanks,
ta
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:31     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:31 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Flash parameters init is done in a spaghetti way right now.
> There is the init based on the flash_info data, then there is the
> default_init() hook, then SFDP init, an intermediary post_bft(),
> then post_sfdp() and a spi_nor_late_init_params(). Each method can
> overwrite previuosly initialized parameters.
> 
> We want to separate what is SFDP and non-SFDP specific. late_init()
> will replace the default_init() hook and will be used only to 
> initialize
> flash parameters that are not declared in the JESD216 SFDP standard, or
> where SFDP tables are not defined at all.
> We cut a member in the chain of initializing parameters by getting rid
> of the default_init() hook, and we make it clear that everything that 
> is
> in late_init() is not covered by the SFDP tables defined by the flash.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
@ 2021-11-09  9:31     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:31 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Flash parameters init is done in a spaghetti way right now.
> There is the init based on the flash_info data, then there is the
> default_init() hook, then SFDP init, an intermediary post_bft(),
> then post_sfdp() and a spi_nor_late_init_params(). Each method can
> overwrite previuosly initialized parameters.
> 
> We want to separate what is SFDP and non-SFDP specific. late_init()
> will replace the default_init() hook and will be used only to 
> initialize
> flash parameters that are not declared in the JESD216 SFDP standard, or
> where SFDP tables are not defined at all.
> We cut a member in the chain of initializing parameters by getting rid
> of the default_init() hook, and we make it clear that everything that 
> is
> in late_init() is not covered by the SFDP tables defined by the flash.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:31     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:31 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
@ 2021-11-09  9:31     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:31 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:34     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:34 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
@ 2021-11-09  9:34     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:34 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:36     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:36 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> OTP is not described in the JESD216 SFDP standard, place the
> OTP ops init in late_init().
> 
> We can't get rid of the default_init() hook for winbond, as the
> 4byte_addr_mode is SFDP specific and will require to have all
> flashes at hand, in order to check which has the SFDP tables defined,
> in which case there's nothing to do if the SFDP tables are corect,
> and which of the flashes do not define the SFDP tables in which case
> each flash should declare a late_init() fixup.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
@ 2021-11-09  9:36     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:36 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> OTP is not described in the JESD216 SFDP standard, place the
> OTP ops init in late_init().
> 
> We can't get rid of the default_init() hook for winbond, as the
> 4byte_addr_mode is SFDP specific and will require to have all
> flashes at hand, in order to check which has the SFDP tables defined,
> in which case there's nothing to do if the SFDP tables are corect,
> and which of the flashes do not define the SFDP tables in which case
> each flash should declare a late_init() fixup.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:43     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:43 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> post_sfdp was misleading in this case, as SFDP is not supported by
> xilinx. Plus, there's no fixup here, just setting the correct
> setup method, as required by xilinx parts.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
@ 2021-11-09  9:43     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:43 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> post_sfdp was misleading in this case, as SFDP is not supported by
> xilinx. Plus, there's no fixup here, just setting the correct
> setup method, as required by xilinx parts.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:47     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:47 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Setting the correct nor->mtd._write in a fixup hook was misleading,
> since this is not a fixup, just a specific setting for SST, that 
> differs
> from the SPI NOR core default init.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

Just a comment below.

> ---
>  drivers/mtd/spi-nor/sst.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
> index 660aabde477a..3593aae0920f 100644
> --- a/drivers/mtd/spi-nor/sst.c
> +++ b/drivers/mtd/spi-nor/sst.c
> @@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd,
> loff_t to, size_t len,
>  	return ret;
>  }
> 
> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
> +static void sst_late_init(struct spi_nor *nor)
>  {
>  	if (nor->info->flags & SST_WRITE)

SST_WRITE is only used during to set this. Shouldn't this be
a fixup per flash so we don't need that flag.

>  		nor->mtd._write = sst_write;
>  }
> 
>  static const struct spi_nor_fixups sst_fixups = {
> -	.post_sfdp = sst_post_sfdp_fixups,
> +	.late_init = sst_late_init,
>  };
> 
>  const struct spi_nor_manufacturer spi_nor_sst = {

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-11-09  9:47     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:47 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Setting the correct nor->mtd._write in a fixup hook was misleading,
> since this is not a fixup, just a specific setting for SST, that 
> differs
> from the SPI NOR core default init.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

Just a comment below.

> ---
>  drivers/mtd/spi-nor/sst.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
> index 660aabde477a..3593aae0920f 100644
> --- a/drivers/mtd/spi-nor/sst.c
> +++ b/drivers/mtd/spi-nor/sst.c
> @@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd,
> loff_t to, size_t len,
>  	return ret;
>  }
> 
> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
> +static void sst_late_init(struct spi_nor *nor)
>  {
>  	if (nor->info->flags & SST_WRITE)

SST_WRITE is only used during to set this. Shouldn't this be
a fixup per flash so we don't need that flag.

>  		nor->mtd._write = sst_write;
>  }
> 
>  static const struct spi_nor_fixups sst_fixups = {
> -	.post_sfdp = sst_post_sfdp_fixups,
> +	.late_init = sst_late_init,
>  };
> 
>  const struct spi_nor_manufacturer spi_nor_sst = {

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09  9:48     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:48 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spansion_post_sfdp_fixups() was called regardless if the flash defined
> SFDP tables or not. A better place for this kind of parameters init is
> in manufacturer's late_init() hook. post_sfdp() should be called only
> when SFDP is defined. No functional change in this patch.
> 
> Instead of doing the 4b opcodes settings at manufacturer level, thus
> also for every flash that will be introduced, this should be done
> just where it is needed, per flash. I'll let this for other patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
@ 2021-11-09  9:48     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09  9:48 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spansion_post_sfdp_fixups() was called regardless if the flash defined
> SFDP tables or not. A better place for this kind of parameters init is
> in manufacturer's late_init() hook. post_sfdp() should be called only
> when SFDP is defined. No functional change in this patch.
> 
> Instead of doing the 4b opcodes settings at manufacturer level, thus
> also for every flash that will be introduced, this should be done
> just where it is needed, per flash. I'll let this for other patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09 10:18     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 10:18 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spi_nor_post_sfdp_fixups() was called even when there were no SFDP
> tables defined. late_init() should be instead used for flashes that
> do not define SFDP tables.
> 
> Use spi_nor_post_sfdp_fixups() just to fix SFDP data. post_sfdp()
> hook is as of now used just by s28hs512t, mt35xu512aba, and both
> support SFDP, there's no functional change with this patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
>  drivers/mtd/spi-nor/core.c | 56 ++++++++++++++++++--------------------
>  1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 4679298c5301..82cc56c9d09e 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2508,6 +2508,25 @@ static void
> spi_nor_manufacturer_init_params(struct spi_nor *nor)
>  		nor->info->fixups->default_init(nor);
>  }
> 
> +/**
> + * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and 
> settings
> + * after SFDP has been parsed. Called only for flashes that define 
> JESD216 SFDP
> + * tables.
> + * @nor:	pointer to a 'struct spi_nor'
> + *
> + * Used to tweak various flash parameters when information provided by 
> the SFDP
> + * tables are wrong.
> + */
> +static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
> +{
> +	if (nor->manufacturer && nor->manufacturer->fixups &&
> +	    nor->manufacturer->fixups->post_sfdp)
> +		nor->manufacturer->fixups->post_sfdp(nor);
> +
> +	if (nor->info->fixups && nor->info->fixups->post_sfdp)
> +		nor->info->fixups->post_sfdp(nor);
> +}
> +
>  /**
>   * spi_nor_sfdp_init_params() - Initialize the flash's parameters and 
> settings
>   * based on JESD216 SFDP standard.
> @@ -2522,7 +2541,9 @@ static void spi_nor_sfdp_init_params(struct 
> spi_nor *nor)
> 
>  	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
> 
> -	if (spi_nor_parse_sfdp(nor)) {
> +	if (!spi_nor_parse_sfdp(nor)) {
> +		spi_nor_post_sfdp_fixups(nor);

I find this function particulary confusing. Why is it
copying the params around? I know the function doc
says rollback, but can't we make this better?

Either make spi_nor_parse_sfdp() commit the nor->params update
atomically, or pass a second parameter sfdp_params, which are
copied to nor->params here if spi_nor_parse_sfdp() was successful.

Also the control flow could be better.

ret = spi_nor_parse_sfdp(nor, &sfdp_params);
if (!ret) {
     /* clever comment, why is addr_width = 0 here */
     nor->addr_width = 0;
     nor->flags &= ~SNOR_F_4B_OPCODES;
     return 0;
}

memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
spi_nor_post_sfdp_fixups(nor);

Having an even closer look, addr_width is set to 0 because
spi_nor_parse_sfdp() is also changing that. nor->flags
is also changed and not only the SNOR_F_4B_OPCODES bit. But
only that one is cleared?!

I think this deserves another cleanup series. Having the
rollback here makes no sense. You'd have to keep both in
sync.

IMHO best would be a second parameter and make sure all
code in sfdp.c don't change anything else. Which would
probably mean that addr_width and flags will move to
nor->params.

Anyway, for now:
Reviewed-by: Michael Walle <michael@walle.cc>

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined
@ 2021-11-09 10:18     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 10:18 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spi_nor_post_sfdp_fixups() was called even when there were no SFDP
> tables defined. late_init() should be instead used for flashes that
> do not define SFDP tables.
> 
> Use spi_nor_post_sfdp_fixups() just to fix SFDP data. post_sfdp()
> hook is as of now used just by s28hs512t, mt35xu512aba, and both
> support SFDP, there's no functional change with this patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
>  drivers/mtd/spi-nor/core.c | 56 ++++++++++++++++++--------------------
>  1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 4679298c5301..82cc56c9d09e 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2508,6 +2508,25 @@ static void
> spi_nor_manufacturer_init_params(struct spi_nor *nor)
>  		nor->info->fixups->default_init(nor);
>  }
> 
> +/**
> + * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and 
> settings
> + * after SFDP has been parsed. Called only for flashes that define 
> JESD216 SFDP
> + * tables.
> + * @nor:	pointer to a 'struct spi_nor'
> + *
> + * Used to tweak various flash parameters when information provided by 
> the SFDP
> + * tables are wrong.
> + */
> +static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
> +{
> +	if (nor->manufacturer && nor->manufacturer->fixups &&
> +	    nor->manufacturer->fixups->post_sfdp)
> +		nor->manufacturer->fixups->post_sfdp(nor);
> +
> +	if (nor->info->fixups && nor->info->fixups->post_sfdp)
> +		nor->info->fixups->post_sfdp(nor);
> +}
> +
>  /**
>   * spi_nor_sfdp_init_params() - Initialize the flash's parameters and 
> settings
>   * based on JESD216 SFDP standard.
> @@ -2522,7 +2541,9 @@ static void spi_nor_sfdp_init_params(struct 
> spi_nor *nor)
> 
>  	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
> 
> -	if (spi_nor_parse_sfdp(nor)) {
> +	if (!spi_nor_parse_sfdp(nor)) {
> +		spi_nor_post_sfdp_fixups(nor);

I find this function particulary confusing. Why is it
copying the params around? I know the function doc
says rollback, but can't we make this better?

Either make spi_nor_parse_sfdp() commit the nor->params update
atomically, or pass a second parameter sfdp_params, which are
copied to nor->params here if spi_nor_parse_sfdp() was successful.

Also the control flow could be better.

ret = spi_nor_parse_sfdp(nor, &sfdp_params);
if (!ret) {
     /* clever comment, why is addr_width = 0 here */
     nor->addr_width = 0;
     nor->flags &= ~SNOR_F_4B_OPCODES;
     return 0;
}

memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
spi_nor_post_sfdp_fixups(nor);

Having an even closer look, addr_width is set to 0 because
spi_nor_parse_sfdp() is also changing that. nor->flags
is also changed and not only the SNOR_F_4B_OPCODES bit. But
only that one is cleared?!

I think this deserves another cleanup series. Having the
rollback here makes no sense. You'd have to keep both in
sync.

IMHO best would be a second parameter and make sure all
code in sfdp.c don't change anything else. Which would
probably mean that addr_width and flags will move to
nor->params.

Anyway, for now:
Reviewed-by: Michael Walle <michael@walle.cc>

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-11-09  9:47     ` Michael Walle
@ 2021-11-09 10:22       ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 10:22 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/9/21 11:47 AM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> Setting the correct nor->mtd._write in a fixup hook was misleading,
>> since this is not a fixup, just a specific setting for SST, that
>> differs
>> from the SPI NOR core default init.
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> Reviewed-by: Michael Walle <michael@walle.cc>
> 
> Just a comment below.
> 
>> ---
>>  drivers/mtd/spi-nor/sst.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
>> index 660aabde477a..3593aae0920f 100644
>> --- a/drivers/mtd/spi-nor/sst.c
>> +++ b/drivers/mtd/spi-nor/sst.c
>> @@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd,
>> loff_t to, size_t len,
>>       return ret;
>>  }
>>
>> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
>> +static void sst_late_init(struct spi_nor *nor)
>>  {
>>       if (nor->info->flags & SST_WRITE)
> 
> SST_WRITE is only used during to set this. Shouldn't this be
> a fixup per flash so we don't need that flag.

We should get rid of the SST_WRITE indeed. Do you want me to handle this
or do you want to take care of it yourself?

As a side note, I find the manufacturer fixup hooks and generic settings
not scalable. We may consider to remove the per manufacturer settings
in the future.

Cheers,
ta

> 
>>               nor->mtd._write = sst_write;
>>  }
>>
>>  static const struct spi_nor_fixups sst_fixups = {
>> -     .post_sfdp = sst_post_sfdp_fixups,
>> +     .late_init = sst_late_init,
>>  };
>>
>>  const struct spi_nor_manufacturer spi_nor_sst = {
> 
> -michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-11-09 10:22       ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 10:22 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/9/21 11:47 AM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> Setting the correct nor->mtd._write in a fixup hook was misleading,
>> since this is not a fixup, just a specific setting for SST, that
>> differs
>> from the SPI NOR core default init.
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> Reviewed-by: Michael Walle <michael@walle.cc>
> 
> Just a comment below.
> 
>> ---
>>  drivers/mtd/spi-nor/sst.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
>> index 660aabde477a..3593aae0920f 100644
>> --- a/drivers/mtd/spi-nor/sst.c
>> +++ b/drivers/mtd/spi-nor/sst.c
>> @@ -177,14 +177,14 @@ static int sst_write(struct mtd_info *mtd,
>> loff_t to, size_t len,
>>       return ret;
>>  }
>>
>> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
>> +static void sst_late_init(struct spi_nor *nor)
>>  {
>>       if (nor->info->flags & SST_WRITE)
> 
> SST_WRITE is only used during to set this. Shouldn't this be
> a fixup per flash so we don't need that flag.

We should get rid of the SST_WRITE indeed. Do you want me to handle this
or do you want to take care of it yourself?

As a side note, I find the manufacturer fixup hooks and generic settings
not scalable. We may consider to remove the per manufacturer settings
in the future.

Cheers,
ta

> 
>>               nor->mtd._write = sst_write;
>>  }
>>
>>  static const struct spi_nor_fixups sst_fixups = {
>> -     .post_sfdp = sst_post_sfdp_fixups,
>> +     .late_init = sst_late_init,
>>  };
>>
>>  const struct spi_nor_manufacturer spi_nor_sst = {
> 
> -michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-11-09 10:22       ` Tudor.Ambarus
@ 2021-11-09 10:23         ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 10:23 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/9/21 12:22 PM, Tudor Ambarus wrote:
> On 11/9/21 11:47 AM, Michael Walle wrote:

cut

>>> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
>>> +static void sst_late_init(struct spi_nor *nor)
>>>  {
>>>       if (nor->info->flags & SST_WRITE)
>>
>> SST_WRITE is only used during to set this. Shouldn't this be
>> a fixup per flash so we don't need that flag.
> 
> We should get rid of the SST_WRITE indeed. Do you want me to handle this
> or do you want to take care of it yourself?
> 

oh, I forgot, I have already took care of it, check:
[PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-11-09 10:23         ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 10:23 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/9/21 12:22 PM, Tudor Ambarus wrote:
> On 11/9/21 11:47 AM, Michael Walle wrote:

cut

>>> -static void sst_post_sfdp_fixups(struct spi_nor *nor)
>>> +static void sst_late_init(struct spi_nor *nor)
>>>  {
>>>       if (nor->info->flags & SST_WRITE)
>>
>> SST_WRITE is only used during to set this. Shouldn't this be
>> a fixup per flash so we don't need that flag.
> 
> We should get rid of the SST_WRITE indeed. Do you want me to handle this
> or do you want to take care of it yourself?
> 

oh, I forgot, I have already took care of it, check:
[PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-11-09 10:22       ` Tudor.Ambarus
@ 2021-11-09 10:24         ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 10:24 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

>> SST_WRITE is only used during to set this. Shouldn't this be
>> a fixup per flash so we don't need that flag.
> 
> We should get rid of the SST_WRITE indeed. Do you want me to handle 
> this
> or do you want to take care of it yourself?

Well you already got a patch (in this series) which will do exactly this 
;)
But I didn't notice, because its later in this series.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-11-09 10:24         ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 10:24 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

>> SST_WRITE is only used during to set this. Shouldn't this be
>> a fixup per flash so we don't need that flag.
> 
> We should get rid of the SST_WRITE indeed. Do you want me to handle 
> this
> or do you want to take care of it yourself?

Well you already got a patch (in this series) which will do exactly this 
;)
But I didn't notice, because its later in this series.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-09 12:21     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:21 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> The flash_info flags should be generic and not manufacturer specific.
> Get rid of the manufacturer specific flag and use the late_init() fixup
> hook instead.
> Please note that sst_write is now set at flash level and not globally,
> per manufacturer. Manufacturer hooks are generally a bad idea, because
> it affects settings for all the flashes and we might end up with fixups
> for "manufacturer settings".
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

I'm still not sure, if having a just one fixup function will scale with
different flashes. What do you think about having an additional (opaque
to the core) (bit)field for the manufacturer and flash fixups functions?
In this case, you can reuse the same function - and then a manufacturer
will make more sense (addressing Pratyush comment about a common
manufacturer fixup here).

I.e. the SST_WRITE flag would go into these flags, set per flash device
and the fixup can still remain in the manufacturer fixup.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
@ 2021-11-09 12:21     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:21 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> The flash_info flags should be generic and not manufacturer specific.
> Get rid of the manufacturer specific flag and use the late_init() fixup
> hook instead.
> Please note that sst_write is now set at flash level and not globally,
> per manufacturer. Manufacturer hooks are generally a bad idea, because
> it affects settings for all the flashes and we might end up with fixups
> for "manufacturer settings".
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Michael Walle <michael@walle.cc>

I'm still not sure, if having a just one fixup function will scale with
different flashes. What do you think about having an additional (opaque
to the core) (bit)field for the manufacturer and flash fixups functions?
In this case, you can reuse the same function - and then a manufacturer
will make more sense (addressing Pratyush comment about a common
manufacturer fixup here).

I.e. the SST_WRITE flag would go into these flags, set per flash device
and the fixup can still remain in the manufacturer fixup.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  2021-10-29 17:31     ` Tudor.Ambarus
@ 2021-11-09 12:25       ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:25 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:31, schrieb Tudor.Ambarus@microchip.com:
> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>> Get rid of the static initialization of the flash parameters and
>> init them when parsing SFDP.
>> Generated a 256 Kbyte random data and did an erase, write, read back
>> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
>> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
>> 
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> ---
> 
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
> bf2643
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
> sst
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
> sst26vf064b
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp
> > sst26vf064b-sfdp
> root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp

xxd please, and md5sum or sha256sum or really any
checksum is missing.

same goes for the other flashes.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
@ 2021-11-09 12:25       ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:25 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:31, schrieb Tudor.Ambarus@microchip.com:
> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>> Get rid of the static initialization of the flash parameters and
>> init them when parsing SFDP.
>> Generated a 256 Kbyte random data and did an erase, write, read back
>> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
>> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
>> 
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> ---
> 
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
> bf2643
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
> sst
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
> sst26vf064b
> root@sama5d2-xplained:~# cat
> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp
> > sst26vf064b-sfdp
> root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp

xxd please, and md5sum or sha256sum or really any
checksum is missing.

same goes for the other flashes.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  2021-11-09 12:21     ` Michael Walle
@ 2021-11-09 12:31       ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 12:31 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/9/21 2:21 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> The flash_info flags should be generic and not manufacturer specific.
>> Get rid of the manufacturer specific flag and use the late_init() fixup
>> hook instead.
>> Please note that sst_write is now set at flash level and not globally,
>> per manufacturer. Manufacturer hooks are generally a bad idea, because
>> it affects settings for all the flashes and we might end up with fixups
>> for "manufacturer settings".
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> Reviewed-by: Michael Walle <michael@walle.cc>
> 
> I'm still not sure, if having a just one fixup function will scale with
> different flashes. What do you think about having an additional (opaque
> to the core) (bit)field for the manufacturer and flash fixups functions?

Sounds fine. I can reserve few bits to manufacturers and introduce a 
MANUF_FLAGS genmask for the flash_info flags. Each specific manufacturer 
flag will be visible just for that manufacturer. Please check patch 14/25,
I can extend the idea from there.


> In this case, you can reuse the same function - and then a manufacturer
> will make more sense (addressing Pratyush comment about a common
> manufacturer fixup here).
> 
> I.e. the SST_WRITE flag would go into these flags, set per flash device
> and the fixup can still remain in the manufacturer fixup.
> 

Right. Let me know if a MANUF_FLAGS genmask is better than this patch.

Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
@ 2021-11-09 12:31       ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 12:31 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/9/21 2:21 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> The flash_info flags should be generic and not manufacturer specific.
>> Get rid of the manufacturer specific flag and use the late_init() fixup
>> hook instead.
>> Please note that sst_write is now set at flash level and not globally,
>> per manufacturer. Manufacturer hooks are generally a bad idea, because
>> it affects settings for all the flashes and we might end up with fixups
>> for "manufacturer settings".
>>
>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> 
> Reviewed-by: Michael Walle <michael@walle.cc>
> 
> I'm still not sure, if having a just one fixup function will scale with
> different flashes. What do you think about having an additional (opaque
> to the core) (bit)field for the manufacturer and flash fixups functions?

Sounds fine. I can reserve few bits to manufacturers and introduce a 
MANUF_FLAGS genmask for the flash_info flags. Each specific manufacturer 
flag will be visible just for that manufacturer. Please check patch 14/25,
I can extend the idea from there.


> In this case, you can reuse the same function - and then a manufacturer
> will make more sense (addressing Pratyush comment about a common
> manufacturer fixup here).
> 
> I.e. the SST_WRITE flag would go into these flags, set per flash device
> and the fixup can still remain in the manufacturer fixup.
> 

Right. Let me know if a MANUF_FLAGS genmask is better than this patch.

Cheers,
ta
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  2021-11-09 12:25       ` Michael Walle
@ 2021-11-09 12:33         ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 12:33 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/9/21 2:25 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:31, schrieb Tudor.Ambarus@microchip.com:
>> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>>> Get rid of the static initialization of the flash parameters and
>>> init them when parsing SFDP.
>>> Generated a 256 Kbyte random data and did an erase, write, read back
>>> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
>>> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
>>>
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>>> ---
>>
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
>> bf2643
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
>> sst
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
>> sst26vf064b
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp
>> > sst26vf064b-sfdp
>> root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp
> 
> xxd please, and md5sum or sha256sum or really any
> checksum is missing.
> 

right, I forgot the checksum.
Just curious, why do you prefer xxd over hexdump? Does it matter
which tool we use?

> same goes for the other flashes.

ok, will do.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
@ 2021-11-09 12:33         ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-09 12:33 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/9/21 2:25 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:31, schrieb Tudor.Ambarus@microchip.com:
>> On 10/29/21 8:26 PM, Tudor Ambarus wrote:
>>> Get rid of the static initialization of the flash parameters and
>>> init them when parsing SFDP.
>>> Generated a 256 Kbyte random data and did an erase, write, read back
>>> and compare test. The flash uses for reads SPINOR_OP_READ_1_4_4 0xeb,
>>> for erases SPINOR_OP_BE_4K 0x20, and for writes SPINOR_OP_PP 0x02.
>>>
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>>> ---
>>
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
>> bf2643
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
>> sst
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/partname
>> sst26vf064b
>> root@sama5d2-xplained:~# cat
>> /sys/devices/platform/ahb/ahb:apb/f0020000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp
>> > sst26vf064b-sfdp
>> root@sama5d2-xplained:~# hexdump sst26vf064b-sfdp
> 
> xxd please, and md5sum or sha256sum or really any
> checksum is missing.
> 

right, I forgot the checksum.
Just curious, why do you prefer xxd over hexdump? Does it matter
which tool we use?

> same goes for the other flashes.

ok, will do.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
  2021-11-09 12:33         ` Tudor.Ambarus
@ 2021-11-09 12:37           ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:37 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-11-09 13:33, schrieb Tudor.Ambarus@microchip.com:

>> xxd please, and md5sum or sha256sum or really any
>> checksum is missing.
>> 
> 
> right, I forgot the checksum.
> Just curious, why do you prefer xxd over hexdump? Does it matter
> which tool we use?

xxd can do the reverse and its easier to get the binary version
of it again. also, if you use hexdump without -C (or -c) I'm not
sure about the endianess.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP
@ 2021-11-09 12:37           ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-09 12:37 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-11-09 13:33, schrieb Tudor.Ambarus@microchip.com:

>> xxd please, and md5sum or sha256sum or really any
>> checksum is missing.
>> 
> 
> right, I forgot the checksum.
> Just curious, why do you prefer xxd over hexdump? Does it matter
> which tool we use?

xxd can do the reverse and its easier to get the binary version
of it again. also, if you use hexdump without -C (or -c) I'm not
sure about the endianess.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
  2021-11-09 12:31       ` Tudor.Ambarus
@ 2021-11-12 21:28         ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:28 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-11-09 13:31, schrieb Tudor.Ambarus@microchip.com:
> On 11/9/21 2:21 PM, Michael Walle wrote:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know 
>> the content is safe
>> 
>> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>>> The flash_info flags should be generic and not manufacturer specific.
>>> Get rid of the manufacturer specific flag and use the late_init() 
>>> fixup
>>> hook instead.
>>> Please note that sst_write is now set at flash level and not 
>>> globally,
>>> per manufacturer. Manufacturer hooks are generally a bad idea, 
>>> because
>>> it affects settings for all the flashes and we might end up with 
>>> fixups
>>> for "manufacturer settings".
>>> 
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> 
>> Reviewed-by: Michael Walle <michael@walle.cc>
>> 
>> I'm still not sure, if having a just one fixup function will scale 
>> with
>> different flashes. What do you think about having an additional 
>> (opaque
>> to the core) (bit)field for the manufacturer and flash fixups 
>> functions?
> 
> Sounds fine. I can reserve few bits to manufacturers and introduce a
> MANUF_FLAGS genmask for the flash_info flags. Each specific 
> manufacturer
> flag will be visible just for that manufacturer. Please check patch 
> 14/25,
> I can extend the idea from there.
> 
> 
>> In this case, you can reuse the same function - and then a 
>> manufacturer
>> will make more sense (addressing Pratyush comment about a common
>> manufacturer fixup here).
>> 
>> I.e. the SST_WRITE flag would go into these flags, set per flash 
>> device
>> and the fixup can still remain in the manufacturer fixup.
>> 
> 
> Right. Let me know if a MANUF_FLAGS genmask is better than this patch.

Yes, I think so.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag
@ 2021-11-12 21:28         ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:28 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-11-09 13:31, schrieb Tudor.Ambarus@microchip.com:
> On 11/9/21 2:21 PM, Michael Walle wrote:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know 
>> the content is safe
>> 
>> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>>> The flash_info flags should be generic and not manufacturer specific.
>>> Get rid of the manufacturer specific flag and use the late_init() 
>>> fixup
>>> hook instead.
>>> Please note that sst_write is now set at flash level and not 
>>> globally,
>>> per manufacturer. Manufacturer hooks are generally a bad idea, 
>>> because
>>> it affects settings for all the flashes and we might end up with 
>>> fixups
>>> for "manufacturer settings".
>>> 
>>> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
>> 
>> Reviewed-by: Michael Walle <michael@walle.cc>
>> 
>> I'm still not sure, if having a just one fixup function will scale 
>> with
>> different flashes. What do you think about having an additional 
>> (opaque
>> to the core) (bit)field for the manufacturer and flash fixups 
>> functions?
> 
> Sounds fine. I can reserve few bits to manufacturers and introduce a
> MANUF_FLAGS genmask for the flash_info flags. Each specific 
> manufacturer
> flag will be visible just for that manufacturer. Please check patch 
> 14/25,
> I can extend the idea from there.
> 
> 
>> In this case, you can reuse the same function - and then a 
>> manufacturer
>> will make more sense (addressing Pratyush comment about a common
>> manufacturer fixup here).
>> 
>> I.e. the SST_WRITE flag would go into these flags, set per flash 
>> device
>> and the fixup can still remain in the manufacturer fixup.
>> 
> 
> Right. Let me know if a MANUF_FLAGS genmask is better than this patch.

Yes, I think so.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-12 21:50     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:50 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Clarify for what the flash_info flags are used for. Split them in
> three categories:
> 1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
>    by the JESD216 standard in its SFDP tables.
> 2/ SFDP_FLAGS: flags that indicate support that can be discovered
>    via SFDP. These flags are used when the flash does not define the
>    SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
> 3/ FIXUP_FLAGS: flags that indicate support that can be discovered
>    via SFDP ideally, but can not be discovered for this particular 
> flash
>    because the SFDP table that indicates this support is not defined by
>    the flash. In case the table for this support is defined but has 
> wrong
>    values, one should instead use a post_sfdp() hook to set the SNOR_F
>    equivalent flag.
> 
> Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
> will be removed in a future series.

While i like the partitioning of the flags, I don't really like
that masks etc. Why don't you just use different members, like
non_sfdp_flags sfdp_flags and fixup_flags?

This will make sure, the flags won't get mixed up. Also I'm
not sure about your intention of the
   info_flags = nor->info->flags & SOME_MASK;
pattern in the subsequent patches. But if you have different
members you don't have to do that (although its superfluous
anyway).

The flags of each group can start with BIT(0) and reorganizations
of the flags won't affect other groups and will then make these
patches smaller and easier to review.

If your concern is memory, then you can also use bitfields, no?
To populate the flash_info structure, you already introduced a
new macro. This can then just use the new member instead of
".flags".

> BIT(0) was kept for SPI_NOR_PARSE_SFDP (will be introduced in a
> further patch).
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
>  drivers/mtd/spi-nor/core.h | 89 ++++++++++++++++++++++++--------------
>  1 file changed, 57 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index 6fc63ef4267b..1fadd0e74103 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -334,56 +334,81 @@ struct flash_info {
>  	u16		addr_width;
> 
>  	u32		flags;
> -#define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
> -#define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
> -#define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
> -#define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
> -#define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
> -#define SPI_NOR_QUAD_READ	BIT(6)	/* Flash supports Quad Read */
> -#define USE_FSR			BIT(7)	/* use flag status register */
> -#define SPI_NOR_HAS_LOCK	BIT(8)	/* Flash supports lock/unlock via SR 
> */
> -#define SPI_NOR_HAS_TB		BIT(9)	/*
> +#define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
> +
> +/*
> + * Flags that indicate support that is not defined by the JESD216 
> standard in
> + * its SFDP tables.
> + */
> +#define NON_SFDP_FLAGS_MASK	GENMASK(15, 2)
> +#define NON_SFDP_FLAGS(x)	((x) & NON_SFDP_FLAGS_MASK)
> +#define SPI_NOR_HAS_LOCK	BIT(2)	/* Flash supports lock/unlock via SR 
> */
> +#define SPI_NOR_HAS_TB		BIT(3)	/*
>  					 * Flash SR has Top/Bottom (TB) protect
>  					 * bit. Must be used with
>  					 * SPI_NOR_HAS_LOCK.
>  					 */
> -#define SPI_NOR_XSR_RDY		BIT(10)	/*
> -					 * S3AN flashes have specific opcode to
> -					 * read the status register.
> -					 */
> -#define SPI_NOR_4B_OPCODES	BIT(11)	/*
> -					 * Use dedicated 4byte address op codes
> -					 * to support memory size above 128Mib.
> -					 */
> -#define NO_CHIP_ERASE		BIT(12) /* Chip does not support chip erase */
> -#define SPI_NOR_SKIP_SFDP	BIT(13)	/* Skip parsing of SFDP tables */
> -#define USE_CLSR		BIT(14)	/* use CLSR command */
> -#define SPI_NOR_OCTAL_READ	BIT(15)	/* Flash supports Octal Read */
> -#define SPI_NOR_TB_SR_BIT6	BIT(16)	/*
> +#define SPI_NOR_TB_SR_BIT6	BIT(4)	/*
>  					 * Top/Bottom (TB) is bit 6 of
>  					 * status register. Must be used with
>  					 * SPI_NOR_HAS_TB.
>  					 */
> -#define SPI_NOR_4BIT_BP		BIT(17) /*
> +#define SPI_NOR_4BIT_BP		BIT(5) /*
>  					 * Flash SR has 4 bit fields (BP0-3)
>  					 * for block protection.
>  					 */
> -#define SPI_NOR_BP3_SR_BIT6	BIT(18) /*
> +#define SPI_NOR_BP3_SR_BIT6	BIT(6) /*
>  					 * BP3 is bit 6 of status register.
>  					 * Must be used with SPI_NOR_4BIT_BP.
>  					 */
> -#define SPI_NOR_OCTAL_DTR_READ	BIT(19) /* Flash supports octal DTR 
> Read. */
> -#define SPI_NOR_OCTAL_DTR_PP	BIT(20) /* Flash supports Octal DTR Page
> Program */
> -#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(21) /*
> -						 * Flash enables the best
> -						 * available I/O mode via a
> -						 * volatile bit.
> -						 */
> -#define SPI_NOR_SWP_IS_VOLATILE	BIT(22)	/*
> +#define SPI_NOR_SWP_IS_VOLATILE	BIT(7)	/*
>  					 * Flash has volatile software write
>  					 * protection bits. Usually these will
>  					 * power-up in a write-protected state.
>  					 */
> +#define SPI_NOR_NO_ERASE	BIT(8)	/* No erase command needed */
> +#define NO_CHIP_ERASE		BIT(9) /* Chip does not support chip erase */
> +#define SPI_NOR_NO_FR		BIT(10)	/* Can't do fastread */
> +#define USE_CLSR		BIT(11)	/* use CLSR command */
> +#define USE_FSR			BIT(12)	/* use flag status register */
> +#define SPI_NOR_XSR_RDY		BIT(13)	/*
> +					 * S3AN flashes have specific opcode to
> +					 * read the status register.
> +					 */
> +
> +/*
> + * Flags that indicate support that can be discovered via SFDP. Used 
> when SFDP
> + * tables are not defined in the flash. These flags are used together 
> with the
> + * SPI_NOR_SKIP_SFDP flag.
> + */
> +#define SFDP_FLAGS_MASK		GENMASK(23, 16)
> +#define SFDP_FLAGS(x)		((x) & SFDP_FLAGS_MASK)
> +#define SECT_4K			BIT(16)	/* SPINOR_OP_BE_4K works uniformly */
> +#define SECT_4K_PMC		BIT(17)	/* SPINOR_OP_BE_4K_PMC works uniformly */
> +#define SPI_NOR_DUAL_READ	BIT(18)	/* Flash supports Dual Read */
> +#define SPI_NOR_QUAD_READ	BIT(19)	/* Flash supports Quad Read */
> +#define SPI_NOR_OCTAL_READ	BIT(20)	/* Flash supports Octal Read */
> +#define SPI_NOR_OCTAL_DTR_READ	BIT(21) /* Flash supports octal DTR 
> Read. */
> +#define SPI_NOR_OCTAL_DTR_PP	BIT(22) /* Flash supports Octal DTR Page
> Program */
> +
> +/*
> + * Flags that indicate support that can be discovered via SFDP 
> ideally, but can
> + * not be discovered for this particular flash because the SFDP table 
> that
> + * indicates this support is not defined by the flash. In case the 
> table for
> + * this support is defined but has wrong values, one should instead 
> use a
> + * post_sfdp() hook to set the SNOR_F equivalent flag.
> + */
> +#define FIXUP_FLAGS_MASK	GENMASK(31, 24)
> +#define FIXUP_FLAGS(x)		((x) & FIXUP_FLAGS_MASK)
> +#define SPI_NOR_4B_OPCODES	BIT(24)	/*
> +					 * Use dedicated 4byte address op codes
> +					 * to support memory size above 128Mib.
> +					 */
> +#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(25) /*
> +						 * Flash enables the best
> +						 * available I/O mode via a
> +						 * volatile bit.
> +						 */
> 
>  	const struct spi_nor_otp_organization otp_org;

-- 
-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
@ 2021-11-12 21:50     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:50 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> Clarify for what the flash_info flags are used for. Split them in
> three categories:
> 1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
>    by the JESD216 standard in its SFDP tables.
> 2/ SFDP_FLAGS: flags that indicate support that can be discovered
>    via SFDP. These flags are used when the flash does not define the
>    SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
> 3/ FIXUP_FLAGS: flags that indicate support that can be discovered
>    via SFDP ideally, but can not be discovered for this particular 
> flash
>    because the SFDP table that indicates this support is not defined by
>    the flash. In case the table for this support is defined but has 
> wrong
>    values, one should instead use a post_sfdp() hook to set the SNOR_F
>    equivalent flag.
> 
> Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
> will be removed in a future series.

While i like the partitioning of the flags, I don't really like
that masks etc. Why don't you just use different members, like
non_sfdp_flags sfdp_flags and fixup_flags?

This will make sure, the flags won't get mixed up. Also I'm
not sure about your intention of the
   info_flags = nor->info->flags & SOME_MASK;
pattern in the subsequent patches. But if you have different
members you don't have to do that (although its superfluous
anyway).

The flags of each group can start with BIT(0) and reorganizations
of the flags won't affect other groups and will then make these
patches smaller and easier to review.

If your concern is memory, then you can also use bitfields, no?
To populate the flash_info structure, you already introduced a
new macro. This can then just use the new member instead of
".flags".

> BIT(0) was kept for SPI_NOR_PARSE_SFDP (will be introduced in a
> further patch).
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
>  drivers/mtd/spi-nor/core.h | 89 ++++++++++++++++++++++++--------------
>  1 file changed, 57 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index 6fc63ef4267b..1fadd0e74103 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -334,56 +334,81 @@ struct flash_info {
>  	u16		addr_width;
> 
>  	u32		flags;
> -#define SECT_4K			BIT(0)	/* SPINOR_OP_BE_4K works uniformly */
> -#define SPI_NOR_NO_ERASE	BIT(1)	/* No erase command needed */
> -#define SPI_NOR_NO_FR		BIT(3)	/* Can't do fastread */
> -#define SECT_4K_PMC		BIT(4)	/* SPINOR_OP_BE_4K_PMC works uniformly */
> -#define SPI_NOR_DUAL_READ	BIT(5)	/* Flash supports Dual Read */
> -#define SPI_NOR_QUAD_READ	BIT(6)	/* Flash supports Quad Read */
> -#define USE_FSR			BIT(7)	/* use flag status register */
> -#define SPI_NOR_HAS_LOCK	BIT(8)	/* Flash supports lock/unlock via SR 
> */
> -#define SPI_NOR_HAS_TB		BIT(9)	/*
> +#define SPI_NOR_SKIP_SFDP	BIT(1)	/* Skip parsing of SFDP tables */
> +
> +/*
> + * Flags that indicate support that is not defined by the JESD216 
> standard in
> + * its SFDP tables.
> + */
> +#define NON_SFDP_FLAGS_MASK	GENMASK(15, 2)
> +#define NON_SFDP_FLAGS(x)	((x) & NON_SFDP_FLAGS_MASK)
> +#define SPI_NOR_HAS_LOCK	BIT(2)	/* Flash supports lock/unlock via SR 
> */
> +#define SPI_NOR_HAS_TB		BIT(3)	/*
>  					 * Flash SR has Top/Bottom (TB) protect
>  					 * bit. Must be used with
>  					 * SPI_NOR_HAS_LOCK.
>  					 */
> -#define SPI_NOR_XSR_RDY		BIT(10)	/*
> -					 * S3AN flashes have specific opcode to
> -					 * read the status register.
> -					 */
> -#define SPI_NOR_4B_OPCODES	BIT(11)	/*
> -					 * Use dedicated 4byte address op codes
> -					 * to support memory size above 128Mib.
> -					 */
> -#define NO_CHIP_ERASE		BIT(12) /* Chip does not support chip erase */
> -#define SPI_NOR_SKIP_SFDP	BIT(13)	/* Skip parsing of SFDP tables */
> -#define USE_CLSR		BIT(14)	/* use CLSR command */
> -#define SPI_NOR_OCTAL_READ	BIT(15)	/* Flash supports Octal Read */
> -#define SPI_NOR_TB_SR_BIT6	BIT(16)	/*
> +#define SPI_NOR_TB_SR_BIT6	BIT(4)	/*
>  					 * Top/Bottom (TB) is bit 6 of
>  					 * status register. Must be used with
>  					 * SPI_NOR_HAS_TB.
>  					 */
> -#define SPI_NOR_4BIT_BP		BIT(17) /*
> +#define SPI_NOR_4BIT_BP		BIT(5) /*
>  					 * Flash SR has 4 bit fields (BP0-3)
>  					 * for block protection.
>  					 */
> -#define SPI_NOR_BP3_SR_BIT6	BIT(18) /*
> +#define SPI_NOR_BP3_SR_BIT6	BIT(6) /*
>  					 * BP3 is bit 6 of status register.
>  					 * Must be used with SPI_NOR_4BIT_BP.
>  					 */
> -#define SPI_NOR_OCTAL_DTR_READ	BIT(19) /* Flash supports octal DTR 
> Read. */
> -#define SPI_NOR_OCTAL_DTR_PP	BIT(20) /* Flash supports Octal DTR Page
> Program */
> -#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(21) /*
> -						 * Flash enables the best
> -						 * available I/O mode via a
> -						 * volatile bit.
> -						 */
> -#define SPI_NOR_SWP_IS_VOLATILE	BIT(22)	/*
> +#define SPI_NOR_SWP_IS_VOLATILE	BIT(7)	/*
>  					 * Flash has volatile software write
>  					 * protection bits. Usually these will
>  					 * power-up in a write-protected state.
>  					 */
> +#define SPI_NOR_NO_ERASE	BIT(8)	/* No erase command needed */
> +#define NO_CHIP_ERASE		BIT(9) /* Chip does not support chip erase */
> +#define SPI_NOR_NO_FR		BIT(10)	/* Can't do fastread */
> +#define USE_CLSR		BIT(11)	/* use CLSR command */
> +#define USE_FSR			BIT(12)	/* use flag status register */
> +#define SPI_NOR_XSR_RDY		BIT(13)	/*
> +					 * S3AN flashes have specific opcode to
> +					 * read the status register.
> +					 */
> +
> +/*
> + * Flags that indicate support that can be discovered via SFDP. Used 
> when SFDP
> + * tables are not defined in the flash. These flags are used together 
> with the
> + * SPI_NOR_SKIP_SFDP flag.
> + */
> +#define SFDP_FLAGS_MASK		GENMASK(23, 16)
> +#define SFDP_FLAGS(x)		((x) & SFDP_FLAGS_MASK)
> +#define SECT_4K			BIT(16)	/* SPINOR_OP_BE_4K works uniformly */
> +#define SECT_4K_PMC		BIT(17)	/* SPINOR_OP_BE_4K_PMC works uniformly */
> +#define SPI_NOR_DUAL_READ	BIT(18)	/* Flash supports Dual Read */
> +#define SPI_NOR_QUAD_READ	BIT(19)	/* Flash supports Quad Read */
> +#define SPI_NOR_OCTAL_READ	BIT(20)	/* Flash supports Octal Read */
> +#define SPI_NOR_OCTAL_DTR_READ	BIT(21) /* Flash supports octal DTR 
> Read. */
> +#define SPI_NOR_OCTAL_DTR_PP	BIT(22) /* Flash supports Octal DTR Page
> Program */
> +
> +/*
> + * Flags that indicate support that can be discovered via SFDP 
> ideally, but can
> + * not be discovered for this particular flash because the SFDP table 
> that
> + * indicates this support is not defined by the flash. In case the 
> table for
> + * this support is defined but has wrong values, one should instead 
> use a
> + * post_sfdp() hook to set the SNOR_F equivalent flag.
> + */
> +#define FIXUP_FLAGS_MASK	GENMASK(31, 24)
> +#define FIXUP_FLAGS(x)		((x) & FIXUP_FLAGS_MASK)
> +#define SPI_NOR_4B_OPCODES	BIT(24)	/*
> +					 * Use dedicated 4byte address op codes
> +					 * to support memory size above 128Mib.
> +					 */
> +#define SPI_NOR_IO_MODE_EN_VOLATILE	BIT(25) /*
> +						 * Flash enables the best
> +						 * available I/O mode via a
> +						 * volatile bit.
> +						 */
> 
>  	const struct spi_nor_otp_organization otp_org;

-- 
-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-12 21:53     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:53 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spi_nor_setup() configures the SPI NOR memory. Setting the addr width
> is too a configuration, hence we can move the spi_nor_set_addr_width()
> in spi_nor_setup().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

Reviewed-by: Michael Walle <michael@walle.cc>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup()
@ 2021-11-12 21:53     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-12 21:53 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spi_nor_setup() configures the SPI NOR memory. Setting the addr width
> is too a configuration, hence we can move the spi_nor_set_addr_width()
> in spi_nor_setup().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

Reviewed-by: Michael Walle <michael@walle.cc>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
  2021-11-12 21:50     ` Michael Walle
@ 2021-11-15  4:55       ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-15  4:55 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, p.yadav, mail, zhengxunli

On 11/12/21 11:50 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> Clarify for what the flash_info flags are used for. Split them in
>> three categories:
>> 1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
>>    by the JESD216 standard in its SFDP tables.
>> 2/ SFDP_FLAGS: flags that indicate support that can be discovered
>>    via SFDP. These flags are used when the flash does not define the
>>    SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
>> 3/ FIXUP_FLAGS: flags that indicate support that can be discovered
>>    via SFDP ideally, but can not be discovered for this particular
>> flash
>>    because the SFDP table that indicates this support is not defined by
>>    the flash. In case the table for this support is defined but has
>> wrong
>>    values, one should instead use a post_sfdp() hook to set the SNOR_F
>>    equivalent flag.
>>
>> Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
>> will be removed in a future series.
> 
> While i like the partitioning of the flags, I don't really like
> that masks etc. Why don't you just use different members, like
> non_sfdp_flags sfdp_flags and fixup_flags?

because of memory concerns. But I think I can substitute the u32 flags
with u16 and u8 equivalents, so will end with the same memory footprint.
Will implement this, thanks.

ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks
@ 2021-11-15  4:55       ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-15  4:55 UTC (permalink / raw)
  To: michael
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, linux-mtd, linux-arm-kernel, code, miquel.raynal,
	heiko.thiery, sr, figgyc, p.yadav, mail, zhengxunli

On 11/12/21 11:50 PM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Am 2021-10-29 19:26, schrieb Tudor Ambarus:
>> Clarify for what the flash_info flags are used for. Split them in
>> three categories:
>> 1/ NON_SFDP_FLAGS: flags that indicate support that is not defined
>>    by the JESD216 standard in its SFDP tables.
>> 2/ SFDP_FLAGS: flags that indicate support that can be discovered
>>    via SFDP. These flags are used when the flash does not define the
>>    SFDP tables. Used together with SPI_NOR_SKIP_SFDP flag.
>> 3/ FIXUP_FLAGS: flags that indicate support that can be discovered
>>    via SFDP ideally, but can not be discovered for this particular
>> flash
>>    because the SFDP table that indicates this support is not defined by
>>    the flash. In case the table for this support is defined but has
>> wrong
>>    values, one should instead use a post_sfdp() hook to set the SNOR_F
>>    equivalent flag.
>>
>> Manufacturer specific flags like USE_CLSR, USE_FSR, SPI_NOR_XSR_RDY,
>> will be removed in a future series.
> 
> While i like the partitioning of the flags, I don't really like
> that masks etc. Why don't you just use different members, like
> non_sfdp_flags sfdp_flags and fixup_flags?

because of memory concerns. But I think I can substitute the u32 flags
with u16 and u8 equivalents, so will end with the same memory footprint.
Will implement this, thanks.

ta
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 10:59     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 10:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> "struct mtd_info mtd" is member of "struct spi_nor", there's no need
> to use "mtd->priv". Get the pointer to the containing struct spi_nor
> by using container_of. While here, make the function inline and
> get rid of the __maybe_unused.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
@ 2021-11-15 10:59     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 10:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> "struct mtd_info mtd" is member of "struct spi_nor", there's no need
> to use "mtd->priv". Get the pointer to the containing struct spi_nor
> by using container_of. While here, make the function inline and
> get rid of the __maybe_unused.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 18:52     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:52 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> 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>
> ---
>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
>  drivers/mtd/spi-nor/core.h |  4 +--
>  drivers/mtd/spi-nor/otp.c  |  2 +-
>  drivers/mtd/spi-nor/swp.c  |  2 +-
>  4 files changed, 34 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 277d1fde84c8..ae971c773334 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -3071,6 +3071,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->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;

You should also merge in spi_nor_debugfs_init() in here which 
initializes mtd->dbg.

> +}
> +
>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		 const struct spi_nor_hwcaps *hwcaps)
>  {
> @@ -3125,26 +3154,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) {
> @@ -3166,12 +3180,7 @@ 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;
>  	nor->page_size = nor->params->page_size;
> -	mtd->writebufsize = nor->page_size;
>  
>  	if (of_property_read_bool(np, "broken-flash-reset"))
>  		nor->flags |= SNOR_F_BROKEN_RESET;
> @@ -3196,15 +3205,12 @@ 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);
> +	spi_nor_set_mtd_info(nor);

This will break multiple things.

- spi_nor_set_addr_width(), which is called by spi_nor-setup(). It 
  checks for nor->mtd.size which has not been set yet.
- spi_nor_spimem_check_op(), which is called (indirectly) by 
  spi_nor_default_setup(). It check for nor->mtd.size.
- spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't 
  think it actually uses any values you initialize here but still worth 
  pointing out.

>  
>  	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 223a03769950..48f26d3f1b3c 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -548,8 +548,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.25.1
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-15 18:52     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:52 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> 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>
> ---
>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
>  drivers/mtd/spi-nor/core.h |  4 +--
>  drivers/mtd/spi-nor/otp.c  |  2 +-
>  drivers/mtd/spi-nor/swp.c  |  2 +-
>  4 files changed, 34 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 277d1fde84c8..ae971c773334 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -3071,6 +3071,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->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;

You should also merge in spi_nor_debugfs_init() in here which 
initializes mtd->dbg.

> +}
> +
>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		 const struct spi_nor_hwcaps *hwcaps)
>  {
> @@ -3125,26 +3154,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) {
> @@ -3166,12 +3180,7 @@ 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;
>  	nor->page_size = nor->params->page_size;
> -	mtd->writebufsize = nor->page_size;
>  
>  	if (of_property_read_bool(np, "broken-flash-reset"))
>  		nor->flags |= SNOR_F_BROKEN_RESET;
> @@ -3196,15 +3205,12 @@ 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);
> +	spi_nor_set_mtd_info(nor);

This will break multiple things.

- spi_nor_set_addr_width(), which is called by spi_nor-setup(). It 
  checks for nor->mtd.size which has not been set yet.
- spi_nor_spimem_check_op(), which is called (indirectly) by 
  spi_nor_default_setup(). It check for nor->mtd.size.
- spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't 
  think it actually uses any values you initialize here but still worth 
  pointing out.

>  
>  	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 223a03769950..48f26d3f1b3c 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -548,8 +548,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.25.1
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 18:56     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:56 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Flash parameters init is done in a spaghetti way right now.
> There is the init based on the flash_info data, then there is the
> default_init() hook, then SFDP init, an intermediary post_bft(),
> then post_sfdp() and a spi_nor_late_init_params(). Each method can
> overwrite previuosly initialized parameters.
> 
> We want to separate what is SFDP and non-SFDP specific. late_init()
> will replace the default_init() hook and will be used only to initialize
> flash parameters that are not declared in the JESD216 SFDP standard, or
> where SFDP tables are not defined at all.
> We cut a member in the chain of initializing parameters by getting rid
> of the default_init() hook, and we make it clear that everything that is
> in late_init() is not covered by the SFDP tables defined by the flash.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook
@ 2021-11-15 18:56     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:56 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Flash parameters init is done in a spaghetti way right now.
> There is the init based on the flash_info data, then there is the
> default_init() hook, then SFDP init, an intermediary post_bft(),
> then post_sfdp() and a spi_nor_late_init_params(). Each method can
> overwrite previuosly initialized parameters.
> 
> We want to separate what is SFDP and non-SFDP specific. late_init()
> will replace the default_init() hook and will be used only to initialize
> flash parameters that are not declared in the JESD216 SFDP standard, or
> where SFDP tables are not defined at all.
> We cut a member in the chain of initializing parameters by getting rid
> of the default_init() hook, and we make it clear that everything that is
> in late_init() is not covered by the SFDP tables defined by the flash.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 18:59     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
@ 2021-11-15 18:59     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 18:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:00     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:00 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 07/25] mtd: spi-nor: sst: Use flash late_init() for locking
@ 2021-11-15 19:00     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:00 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Locking is not described in JESD216 SFDP standard, place the
> locking init in late_init().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:00     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:00 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> OTP is not described in the JESD216 SFDP standard, place the
> OTP ops init in late_init().
> 
> We can't get rid of the default_init() hook for winbond, as the
> 4byte_addr_mode is SFDP specific and will require to have all
> flashes at hand, in order to check which has the SFDP tables defined,
> in which case there's nothing to do if the SFDP tables are corect,
> and which of the flashes do not define the SFDP tables in which case
> each flash should declare a late_init() fixup.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
@ 2021-11-15 19:00     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:00 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> OTP is not described in the JESD216 SFDP standard, place the
> OTP ops init in late_init().
> 
> We can't get rid of the default_init() hook for winbond, as the
> 4byte_addr_mode is SFDP specific and will require to have all
> flashes at hand, in order to check which has the SFDP tables defined,
> in which case there's nothing to do if the SFDP tables are corect,
> and which of the flashes do not define the SFDP tables in which case
> each flash should declare a late_init() fixup.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:01     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:01 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> post_sfdp was misleading in this case, as SFDP is not supported by
> xilinx. Plus, there's no fixup here, just setting the correct
> setup method, as required by xilinx parts.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
@ 2021-11-15 19:01     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:01 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> post_sfdp was misleading in this case, as SFDP is not supported by
> xilinx. Plus, there's no fixup here, just setting the correct
> setup method, as required by xilinx parts.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:03     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:03 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Setting the correct nor->mtd._write in a fixup hook was misleading,
> since this is not a fixup, just a specific setting for SST, that differs
> from the SPI NOR core default init.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
@ 2021-11-15 19:03     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:03 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Setting the correct nor->mtd._write in a fixup hook was misleading,
> since this is not a fixup, just a specific setting for SST, that differs
> from the SPI NOR core default init.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:06     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:06 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> spansion_post_sfdp_fixups() was called regardless if the flash defined
> SFDP tables or not. A better place for this kind of parameters init is
> in manufacturer's late_init() hook. post_sfdp() should be called only
> when SFDP is defined. No functional change in this patch.
> 
> Instead of doing the 4b opcodes settings at manufacturer level, thus
> also for every flash that will be introduced, this should be done
> just where it is needed, per flash. I'll let this for other patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
@ 2021-11-15 19:06     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:06 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> spansion_post_sfdp_fixups() was called regardless if the flash defined
> SFDP tables or not. A better place for this kind of parameters init is
> in manufacturer's late_init() hook. post_sfdp() should be called only
> when SFDP is defined. No functional change in this patch.
> 
> Instead of doing the 4b opcodes settings at manufacturer level, thus
> also for every flash that will be introduced, this should be done
> just where it is needed, per flash. I'll let this for other patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-15 19:12     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:12 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Used to initialize the NOR flags for settings that are not defined
> in the JESD216 SFDP standard, thus can not be retrieved when parsing
> SFDP.
> This moves the setting of SNOR_F_READY_XSR_RDY and SNOR_F_HAS_LOCK
> late in the init call, without any functional change expected.
> The rest of the flags were already set after the spi_nor_init_params().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags()
@ 2021-11-15 19:12     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-15 19:12 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Used to initialize the NOR flags for settings that are not defined
> in the JESD216 SFDP standard, thus can not be retrieved when parsing
> SFDP.
> This moves the setting of SNOR_F_READY_XSR_RDY and SNOR_F_HAS_LOCK
> late in the init call, without any functional change expected.
> The rest of the flags were already set after the spi_nor_init_params().
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-16 10:57     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 10:57 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Initialize NOR flags for settings that can not be discovered by SFDP
> for this particular flash because the SFDP table that indicates this
> support is not defined in the flash. In case the table for his support
> is defined but has wrong values, one should instead use a post_sfdp()
> hook to set the SNOR_F equivalent flag.
> Update all flash_info entries that use SPI_NOR_4B_OPCODES or
> SPI_NOR_IO_MODE_EN_VOLATILE to also use the FIXUP_FLAGS() macro. This
> should highlight to developers that those flags should be used only
> as fixups, where flashes miss to define the SFDP tables that describe
> those settings.
> No functional change intended in this patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
@ 2021-11-16 10:57     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 10:57 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Initialize NOR flags for settings that can not be discovered by SFDP
> for this particular flash because the SFDP table that indicates this
> support is not defined in the flash. In case the table for his support
> is defined but has wrong values, one should instead use a post_sfdp()
> hook to set the SNOR_F equivalent flag.
> Update all flash_info entries that use SPI_NOR_4B_OPCODES or
> SPI_NOR_IO_MODE_EN_VOLATILE to also use the FIXUP_FLAGS() macro. This
> should highlight to developers that those flags should be used only
> as fixups, where flashes miss to define the SFDP tables that describe
> those settings.
> No functional change intended in this patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions
  2021-10-29 17:26   ` Tudor Ambarus
@ 2021-11-16 11:07     ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 11:07 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> New flash additions that support SFDP should be declared with
> SPI_NOR_PARSE_SFDP and with all the other flags that are not SFDP
> discoverable.
> Keep the old way of initializing the flash, until all the flashes
> are converted to use either SPI_NOR_PARSE_SFDP or SPI_NOR_SKIP_SFDP.
> Since we want to get rid of the default_init() hook, the rollback
> mechanism for flashes that use SPI_NOR_PARSE_SFDP does not call
> spi_nor_manufacturer_init_params().
> Split spi_nor_info_init_params() in spi_nor_init_default_params()
> and spi_nor_skip_sfdp_init_params(). spi_nor_init_default_params() is
> called for all the flashes regardless if they support SFDP or not.
> spi_nor_skip_sfdp_init_params() is called just for the flashes that
> do not define SFDP and initializes parameters and setting solely based
> on flash_info data.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions
@ 2021-11-16 11:07     ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 11:07 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> New flash additions that support SFDP should be declared with
> SPI_NOR_PARSE_SFDP and with all the other flags that are not SFDP
> discoverable.
> Keep the old way of initializing the flash, until all the flashes
> are converted to use either SPI_NOR_PARSE_SFDP or SPI_NOR_SKIP_SFDP.
> Since we want to get rid of the default_init() hook, the rollback
> mechanism for flashes that use SPI_NOR_PARSE_SFDP does not call
> spi_nor_manufacturer_init_params().
> Split spi_nor_info_init_params() in spi_nor_init_default_params()
> and spi_nor_skip_sfdp_init_params(). spi_nor_init_default_params() is
> called for all the flashes regardless if they support SFDP or not.
> spi_nor_skip_sfdp_init_params() is called just for the flashes that
> do not define SFDP and initializes parameters and setting solely based
> on flash_info data.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-11-16 11:36   ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 11:36 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, nicolas.ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code. 
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.

I generated some random data (4 MiB), erased the flash, wrote the data 
to the flash, read the data back, and compared it with the original 
image. Works fine on Micron MT35XU512ABA, Micron N25Q128A13, Cypress 
S28HS512T.

Tested-by: Pratyush Yadav <p.yadav@ti.com> # mt35xu512aba, s28hs512t, n25q128a13

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-11-16 11:36   ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 11:36 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 29/10/21 08:26PM, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code. 
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.

I generated some random data (4 MiB), erased the flash, wrote the data 
to the flash, read the data back, and compared it with the original 
image. Works fine on Micron MT35XU512ABA, Micron N25Q128A13, Cypress 
S28HS512T.

Tested-by: Pratyush Yadav <p.yadav@ti.com> # mt35xu512aba, s28hs512t, n25q128a13

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
  2021-11-16 11:36   ` Pratyush Yadav
@ 2021-11-16 11:56     ` Michael Walle
  -1 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-16 11:56 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: macromorgan, vigneshr, Tudor Ambarus, jaimeliao, richard, esben,
	linux, knaerzche, nicolas.ferre, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Am 2021-11-16 12:36, schrieb Pratyush Yadav:
> On 29/10/21 08:26PM, Tudor Ambarus wrote:
>> Clean spi_nor_scan() and the flash parameters initialization code.
>> Tested all the flashes from patch set. If someone can test the
>> locking ops on few flashes would be great. It seems that my flashes
>> have the non volatile bits weared out.
>> 
>> This patch set is split from:
>> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
>> The ID collision series will be set in a dedicated patch set that will
>> depend on this one.
> 
> I generated some random data (4 MiB), erased the flash, wrote the data
> to the flash, read the data back, and compared it with the original
> image. Works fine on Micron MT35XU512ABA, Micron N25Q128A13, Cypress
> S28HS512T.

Ahh btw. I've tested the locking with a custom patch which can dump the
status register. Haven't posted that yet, because it still uses sysfs 
and
I was thinking of converting it to debugfs.

-michael

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-11-16 11:56     ` Michael Walle
  0 siblings, 0 replies; 156+ messages in thread
From: Michael Walle @ 2021-11-16 11:56 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: macromorgan, vigneshr, Tudor Ambarus, jaimeliao, richard, esben,
	linux, knaerzche, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

Am 2021-11-16 12:36, schrieb Pratyush Yadav:
> On 29/10/21 08:26PM, Tudor Ambarus wrote:
>> Clean spi_nor_scan() and the flash parameters initialization code.
>> Tested all the flashes from patch set. If someone can test the
>> locking ops on few flashes would be great. It seems that my flashes
>> have the non volatile bits weared out.
>> 
>> This patch set is split from:
>> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
>> The ID collision series will be set in a dedicated patch set that will
>> depend on this one.
> 
> I generated some random data (4 MiB), erased the flash, wrote the data
> to the flash, read the data back, and compared it with the original
> image. Works fine on Micron MT35XU512ABA, Micron N25Q128A13, Cypress
> S28HS512T.

Ahh btw. I've tested the locking with a custom patch which can dump the
status register. Haven't posted that yet, because it still uses sysfs 
and
I was thinking of converting it to debugfs.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-11-15 18:52     ` Pratyush Yadav
@ 2021-11-16 14:25       ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-16 14:25 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 11/15/21 8:52 PM, Pratyush Yadav wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 29/10/21 08:26PM, Tudor Ambarus wrote:
>> 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>
>> ---
>>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
>>  drivers/mtd/spi-nor/core.h |  4 +--
>>  drivers/mtd/spi-nor/otp.c  |  2 +-
>>  drivers/mtd/spi-nor/swp.c  |  2 +-
>>  4 files changed, 34 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>> index 277d1fde84c8..ae971c773334 100644
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
>> @@ -3071,6 +3071,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->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;
> 
> You should also merge in spi_nor_debugfs_init() in here which
> initializes mtd->dbg.
> 

I was thinking of getting rid of debugfs entries since they duplicate
those on sysfs.

>> +}
>> +
>>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                const struct spi_nor_hwcaps *hwcaps)
>>  {
>> @@ -3125,26 +3154,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) {
>> @@ -3166,12 +3180,7 @@ 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;
>>       nor->page_size = nor->params->page_size;
>> -     mtd->writebufsize = nor->page_size;
>>
>>       if (of_property_read_bool(np, "broken-flash-reset"))
>>               nor->flags |= SNOR_F_BROKEN_RESET;
>> @@ -3196,15 +3205,12 @@ 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);
>> +     spi_nor_set_mtd_info(nor);
> 
> This will break multiple things.

this is gold :), thanks
> 
> - spi_nor_set_addr_width(), which is called by spi_nor-setup(). It
>   checks for nor->mtd.size which has not been set yet.> - spi_nor_spimem_check_op(), which is called (indirectly) by
>   spi_nor_default_setup(). It check for nor->mtd.size.

Let's use NOR parameters in SPI NOR core, thus nor->params->size instead,
and let the mtd fields for mtd. This will spare us of these problems.
And it's cleaner too.

> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>   think it actually uses any values you initialize here but still worth
>   pointing out.

we are safe here, the pointer to mtd is used just to get the pointer to
nor.

Thanks again.
ta

> 
>>
>>       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 223a03769950..48f26d3f1b3c 100644
>> --- a/drivers/mtd/spi-nor/core.h
>> +++ b/drivers/mtd/spi-nor/core.h
>> @@ -548,8 +548,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.25.1
>>
> 
> --
> Regards,
> Pratyush Yadav
> Texas Instruments Inc.
> 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-16 14:25       ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-16 14:25 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 11/15/21 8:52 PM, Pratyush Yadav wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 29/10/21 08:26PM, Tudor Ambarus wrote:
>> 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>
>> ---
>>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
>>  drivers/mtd/spi-nor/core.h |  4 +--
>>  drivers/mtd/spi-nor/otp.c  |  2 +-
>>  drivers/mtd/spi-nor/swp.c  |  2 +-
>>  4 files changed, 34 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>> index 277d1fde84c8..ae971c773334 100644
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
>> @@ -3071,6 +3071,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->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;
> 
> You should also merge in spi_nor_debugfs_init() in here which
> initializes mtd->dbg.
> 

I was thinking of getting rid of debugfs entries since they duplicate
those on sysfs.

>> +}
>> +
>>  int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                const struct spi_nor_hwcaps *hwcaps)
>>  {
>> @@ -3125,26 +3154,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) {
>> @@ -3166,12 +3180,7 @@ 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;
>>       nor->page_size = nor->params->page_size;
>> -     mtd->writebufsize = nor->page_size;
>>
>>       if (of_property_read_bool(np, "broken-flash-reset"))
>>               nor->flags |= SNOR_F_BROKEN_RESET;
>> @@ -3196,15 +3205,12 @@ 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);
>> +     spi_nor_set_mtd_info(nor);
> 
> This will break multiple things.

this is gold :), thanks
> 
> - spi_nor_set_addr_width(), which is called by spi_nor-setup(). It
>   checks for nor->mtd.size which has not been set yet.> - spi_nor_spimem_check_op(), which is called (indirectly) by
>   spi_nor_default_setup(). It check for nor->mtd.size.

Let's use NOR parameters in SPI NOR core, thus nor->params->size instead,
and let the mtd fields for mtd. This will spare us of these problems.
And it's cleaner too.

> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>   think it actually uses any values you initialize here but still worth
>   pointing out.

we are safe here, the pointer to mtd is used just to get the pointer to
nor.

Thanks again.
ta

> 
>>
>>       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 223a03769950..48f26d3f1b3c 100644
>> --- a/drivers/mtd/spi-nor/core.h
>> +++ b/drivers/mtd/spi-nor/core.h
>> @@ -548,8 +548,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.25.1
>>
> 
> --
> Regards,
> Pratyush Yadav
> Texas Instruments Inc.
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-11-16 14:25       ` Tudor.Ambarus
@ 2021-11-16 18:11         ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 18:11 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 16/11/21 02:25PM, Tudor.Ambarus@microchip.com wrote:
> On 11/15/21 8:52 PM, Pratyush Yadav wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > On 29/10/21 08:26PM, Tudor Ambarus wrote:
> >> 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>
> >> ---
> >>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
> >>  drivers/mtd/spi-nor/core.h |  4 +--
> >>  drivers/mtd/spi-nor/otp.c  |  2 +-
> >>  drivers/mtd/spi-nor/swp.c  |  2 +-
> >>  4 files changed, 34 insertions(+), 28 deletions(-)
> >>
> >> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> >> index 277d1fde84c8..ae971c773334 100644
> >> --- a/drivers/mtd/spi-nor/core.c
> >> +++ b/drivers/mtd/spi-nor/core.c
> >> @@ -3071,6 +3071,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->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;
> > 
> > You should also merge in spi_nor_debugfs_init() in here which
> > initializes mtd->dbg.
> > 
> 
> I was thinking of getting rid of debugfs entries since they duplicate
> those on sysfs.

Okay. Fine by me either way.

> 
> >> +}
> >> +
> >>  int spi_nor_scan(struct spi_nor *nor, const char *name,
> >>                const struct spi_nor_hwcaps *hwcaps)
> >>  {
> >> @@ -3125,26 +3154,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) {
> >> @@ -3166,12 +3180,7 @@ 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;
> >>       nor->page_size = nor->params->page_size;
> >> -     mtd->writebufsize = nor->page_size;
> >>
> >>       if (of_property_read_bool(np, "broken-flash-reset"))
> >>               nor->flags |= SNOR_F_BROKEN_RESET;
> >> @@ -3196,15 +3205,12 @@ 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);
> >> +     spi_nor_set_mtd_info(nor);
> > 
> > This will break multiple things.
> 
> this is gold :), thanks
> > 
> > - spi_nor_set_addr_width(), which is called by spi_nor-setup(). It
> >   checks for nor->mtd.size which has not been set yet.> - spi_nor_spimem_check_op(), which is called (indirectly) by
> >   spi_nor_default_setup(). It check for nor->mtd.size.
> 
> Let's use NOR parameters in SPI NOR core, thus nor->params->size instead,
> and let the mtd fields for mtd. This will spare us of these problems.
> And it's cleaner too.

I agree.

> 
> > - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
> >   think it actually uses any values you initialize here but still worth
> >   pointing out.
> 
> we are safe here, the pointer to mtd is used just to get the pointer to
> nor.

Yeah, but who knows if that might change some time later. I would prefer 
we don't use a member we haven't initialized yet.

> 
> Thanks again.
> ta
> 
> > 
> >>
> >>       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 223a03769950..48f26d3f1b3c 100644
> >> --- a/drivers/mtd/spi-nor/core.h
> >> +++ b/drivers/mtd/spi-nor/core.h
> >> @@ -548,8 +548,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.25.1
> >>
> > 
> > --
> > Regards,
> > Pratyush Yadav
> > Texas Instruments Inc.
> > 
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-16 18:11         ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-16 18:11 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 16/11/21 02:25PM, Tudor.Ambarus@microchip.com wrote:
> On 11/15/21 8:52 PM, Pratyush Yadav wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > On 29/10/21 08:26PM, Tudor Ambarus wrote:
> >> 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>
> >> ---
> >>  drivers/mtd/spi-nor/core.c | 54 +++++++++++++++++++++-----------------
> >>  drivers/mtd/spi-nor/core.h |  4 +--
> >>  drivers/mtd/spi-nor/otp.c  |  2 +-
> >>  drivers/mtd/spi-nor/swp.c  |  2 +-
> >>  4 files changed, 34 insertions(+), 28 deletions(-)
> >>
> >> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> >> index 277d1fde84c8..ae971c773334 100644
> >> --- a/drivers/mtd/spi-nor/core.c
> >> +++ b/drivers/mtd/spi-nor/core.c
> >> @@ -3071,6 +3071,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->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;
> > 
> > You should also merge in spi_nor_debugfs_init() in here which
> > initializes mtd->dbg.
> > 
> 
> I was thinking of getting rid of debugfs entries since they duplicate
> those on sysfs.

Okay. Fine by me either way.

> 
> >> +}
> >> +
> >>  int spi_nor_scan(struct spi_nor *nor, const char *name,
> >>                const struct spi_nor_hwcaps *hwcaps)
> >>  {
> >> @@ -3125,26 +3154,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) {
> >> @@ -3166,12 +3180,7 @@ 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;
> >>       nor->page_size = nor->params->page_size;
> >> -     mtd->writebufsize = nor->page_size;
> >>
> >>       if (of_property_read_bool(np, "broken-flash-reset"))
> >>               nor->flags |= SNOR_F_BROKEN_RESET;
> >> @@ -3196,15 +3205,12 @@ 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);
> >> +     spi_nor_set_mtd_info(nor);
> > 
> > This will break multiple things.
> 
> this is gold :), thanks
> > 
> > - spi_nor_set_addr_width(), which is called by spi_nor-setup(). It
> >   checks for nor->mtd.size which has not been set yet.> - spi_nor_spimem_check_op(), which is called (indirectly) by
> >   spi_nor_default_setup(). It check for nor->mtd.size.
> 
> Let's use NOR parameters in SPI NOR core, thus nor->params->size instead,
> and let the mtd fields for mtd. This will spare us of these problems.
> And it's cleaner too.

I agree.

> 
> > - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
> >   think it actually uses any values you initialize here but still worth
> >   pointing out.
> 
> we are safe here, the pointer to mtd is used just to get the pointer to
> nor.

Yeah, but who knows if that might change some time later. I would prefer 
we don't use a member we haven't initialized yet.

> 
> Thanks again.
> ta
> 
> > 
> >>
> >>       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 223a03769950..48f26d3f1b3c 100644
> >> --- a/drivers/mtd/spi-nor/core.h
> >> +++ b/drivers/mtd/spi-nor/core.h
> >> @@ -548,8 +548,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.25.1
> >>
> > 
> > --
> > Regards,
> > Pratyush Yadav
> > Texas Instruments Inc.
> > 
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: (subset)[PATCH v3 00/25] mtd: spi-nor: Clean params init
  2021-10-29 17:26 ` Tudor Ambarus
@ 2021-11-17 13:17   ` Tudor Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-11-17 13:17 UTC (permalink / raw)
  To: vigneshr, p.yadav, Tudor Ambarus, michael
  Cc: jaimeliao, esben, richard, nicolas.ferre, macromorgan,
	zhengxunli, linux-mtd, miquel.raynal, mail, linux-arm-kernel,
	knaerzche, code, linux, sr, heiko.thiery

On Fri, 29 Oct 2021 20:26:08 +0300, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code.
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.
> 
> [...]

Applied to spi-nor/next, thanks!

[01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
        https://git.kernel.org/mtd/c/a360ae43217c
[02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
        https://git.kernel.org/mtd/c/7158c86e5607
[04/25] mtd: spi-nor: Get rid of nor->page_size
        https://git.kernel.org/mtd/c/5854d4a6cc35
[05/25] mtd: spi-nor: core: Introduce the late_init() hook
        https://git.kernel.org/mtd/c/dacc8cfee493
[06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
        https://git.kernel.org/mtd/c/b0fa1db7d2f6
[07/25] mtd: spi-nor: sst: Use flash late_init() for locking
        https://git.kernel.org/mtd/c/7d4ff0613fb5
[08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
        https://git.kernel.org/mtd/c/00947a964949
[09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
        https://git.kernel.org/mtd/c/3fdad69e7fb2
[10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
        https://git.kernel.org/mtd/c/f22a48dbd01b
[11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
        https://git.kernel.org/mtd/c/d396e735ba0c

Best regards,
-- 
Tudor Ambarus <tudor.ambarus@microchip.com>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: (subset)[PATCH v3 00/25] mtd: spi-nor: Clean params init
@ 2021-11-17 13:17   ` Tudor Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor Ambarus @ 2021-11-17 13:17 UTC (permalink / raw)
  To: vigneshr, p.yadav, Tudor Ambarus, michael
  Cc: code, jaimeliao, richard, esben, linux, knaerzche, linux-mtd,
	linux-arm-kernel, macromorgan, miquel.raynal, heiko.thiery, sr,
	mail, zhengxunli

On Fri, 29 Oct 2021 20:26:08 +0300, Tudor Ambarus wrote:
> Clean spi_nor_scan() and the flash parameters initialization code.
> Tested all the flashes from patch set. If someone can test the
> locking ops on few flashes would be great. It seems that my flashes
> have the non volatile bits weared out.
> 
> This patch set is split from:
> https://lore.kernel.org/linux-mtd/20210727045222.905056-1-tudor.ambarus@microchip.com/
> The ID collision series will be set in a dedicated patch set that will
> depend on this one.
> 
> [...]

Applied to spi-nor/next, thanks!

[01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description
        https://git.kernel.org/mtd/c/a360ae43217c
[02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor
        https://git.kernel.org/mtd/c/7158c86e5607
[04/25] mtd: spi-nor: Get rid of nor->page_size
        https://git.kernel.org/mtd/c/5854d4a6cc35
[05/25] mtd: spi-nor: core: Introduce the late_init() hook
        https://git.kernel.org/mtd/c/dacc8cfee493
[06/25] mtd: spi-nor: atmel: Use flash late_init() for locking
        https://git.kernel.org/mtd/c/b0fa1db7d2f6
[07/25] mtd: spi-nor: sst: Use flash late_init() for locking
        https://git.kernel.org/mtd/c/7d4ff0613fb5
[08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops
        https://git.kernel.org/mtd/c/00947a964949
[09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method
        https://git.kernel.org/mtd/c/3fdad69e7fb2
[10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write()
        https://git.kernel.org/mtd/c/f22a48dbd01b
[11/25] mtd: spi-nor: spansion: Use manufacturer late_init()
        https://git.kernel.org/mtd/c/d396e735ba0c

Best regards,
-- 
Tudor Ambarus <tudor.ambarus@microchip.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-11-16 18:11         ` Pratyush Yadav
@ 2021-11-17 14:36           ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-17 14:36 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 11/16/21 8:11 PM, Pratyush Yadav wrote:

>>
>>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>>>   think it actually uses any values you initialize here but still worth
>>>   pointing out.
>>
>> we are safe here, the pointer to mtd is used just to get the pointer to
>> nor.
> 
> Yeah, but who knows if that might change some time later. I would prefer
> we don't use a member we haven't initialized yet.

If it weren't for the SPI NOR controller drivers that use
spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
above the mtd_device_register(). It will indicate that no mtd_info
field is used up to that point, less things to worry about.
spi_nor_try_unlock_all() calls
	spi_nor_unlock(&nor->mtd, 0, nor->params->size);
I can't see for now if we will ever need some specific mtd_info
parameter. I would say that we won't, we're just unlocking the full
flash, every info we would need we can obtain from NOR. The discussion
would be different if it were about mtd partitions, but it isn't, we're
dealing with the entire flash.

Would you accept the place where I put spi_nor_set_mtd_info() if I add
a comment before calling it? Something like:
/* No mtd_info fields are used up to this point. */
spi_nor_set_mtd_info();

Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-17 14:36           ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-17 14:36 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 11/16/21 8:11 PM, Pratyush Yadav wrote:

>>
>>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>>>   think it actually uses any values you initialize here but still worth
>>>   pointing out.
>>
>> we are safe here, the pointer to mtd is used just to get the pointer to
>> nor.
> 
> Yeah, but who knows if that might change some time later. I would prefer
> we don't use a member we haven't initialized yet.

If it weren't for the SPI NOR controller drivers that use
spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
above the mtd_device_register(). It will indicate that no mtd_info
field is used up to that point, less things to worry about.
spi_nor_try_unlock_all() calls
	spi_nor_unlock(&nor->mtd, 0, nor->params->size);
I can't see for now if we will ever need some specific mtd_info
parameter. I would say that we won't, we're just unlocking the full
flash, every info we would need we can obtain from NOR. The discussion
would be different if it were about mtd partitions, but it isn't, we're
dealing with the entire flash.

Would you accept the place where I put spi_nor_set_mtd_info() if I add
a comment before calling it? Something like:
/* No mtd_info fields are used up to this point. */
spi_nor_set_mtd_info();

Cheers,
ta
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-11-17 14:36           ` Tudor.Ambarus
@ 2021-11-19 18:23             ` Pratyush Yadav
  -1 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-19 18:23 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

On 17/11/21 02:36PM, Tudor.Ambarus@microchip.com wrote:
> On 11/16/21 8:11 PM, Pratyush Yadav wrote:
> 
> >>
> >>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
> >>>   think it actually uses any values you initialize here but still worth
> >>>   pointing out.
> >>
> >> we are safe here, the pointer to mtd is used just to get the pointer to
> >> nor.
> > 
> > Yeah, but who knows if that might change some time later. I would prefer
> > we don't use a member we haven't initialized yet.
> 
> If it weren't for the SPI NOR controller drivers that use
> spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
> above the mtd_device_register(). It will indicate that no mtd_info
> field is used up to that point, less things to worry about.
> spi_nor_try_unlock_all() calls
> 	spi_nor_unlock(&nor->mtd, 0, nor->params->size);
> I can't see for now if we will ever need some specific mtd_info
> parameter. I would say that we won't, we're just unlocking the full
> flash, every info we would need we can obtain from NOR. The discussion
> would be different if it were about mtd partitions, but it isn't, we're
> dealing with the entire flash.
> 
> Would you accept the place where I put spi_nor_set_mtd_info() if I add
> a comment before calling it? Something like:
> /* No mtd_info fields are used up to this point. */
> spi_nor_set_mtd_info();

I see that everything that spi_nor_set_mtd_info() needs is set by the 
time spi_nor_init_params() is finished. Everything after that is 
concerned about selecting the protocol and sending the init commands to 
the flash. So why can't you call it right after spi_nor_init_params()? 
That and updating spi_nor_spimem_check_op() and spi_nor_set_addr_width() 
to use nor->params->size instead of nor->mtd.size should do the trick.

I think that it is implied that mtd_info fields are not being used until 
they are initialized so I don't think the comment itself is of much use, 
but I don't care much about it either way.

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-19 18:23             ` Pratyush Yadav
  0 siblings, 0 replies; 156+ messages in thread
From: Pratyush Yadav @ 2021-11-19 18:23 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

On 17/11/21 02:36PM, Tudor.Ambarus@microchip.com wrote:
> On 11/16/21 8:11 PM, Pratyush Yadav wrote:
> 
> >>
> >>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
> >>>   think it actually uses any values you initialize here but still worth
> >>>   pointing out.
> >>
> >> we are safe here, the pointer to mtd is used just to get the pointer to
> >> nor.
> > 
> > Yeah, but who knows if that might change some time later. I would prefer
> > we don't use a member we haven't initialized yet.
> 
> If it weren't for the SPI NOR controller drivers that use
> spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
> above the mtd_device_register(). It will indicate that no mtd_info
> field is used up to that point, less things to worry about.
> spi_nor_try_unlock_all() calls
> 	spi_nor_unlock(&nor->mtd, 0, nor->params->size);
> I can't see for now if we will ever need some specific mtd_info
> parameter. I would say that we won't, we're just unlocking the full
> flash, every info we would need we can obtain from NOR. The discussion
> would be different if it were about mtd partitions, but it isn't, we're
> dealing with the entire flash.
> 
> Would you accept the place where I put spi_nor_set_mtd_info() if I add
> a comment before calling it? Something like:
> /* No mtd_info fields are used up to this point. */
> spi_nor_set_mtd_info();

I see that everything that spi_nor_set_mtd_info() needs is set by the 
time spi_nor_init_params() is finished. Everything after that is 
concerned about selecting the protocol and sending the init commands to 
the flash. So why can't you call it right after spi_nor_init_params()? 
That and updating spi_nor_spimem_check_op() and spi_nor_set_addr_width() 
to use nor->params->size instead of nor->mtd.size should do the trick.

I think that it is implied that mtd_info fields are not being used until 
they are initialized so I don't think the comment itself is of much use, 
but I don't care much about it either way.

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
  2021-11-19 18:23             ` Pratyush Yadav
@ 2021-11-22  8:38               ` Tudor.Ambarus
  -1 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-22  8:38 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, Nicolas.Ferre, michael, linux-mtd, linux-arm-kernel,
	code, miquel.raynal, heiko.thiery, sr, mail, zhengxunli

Hi, Pratyush,

On 11/19/21 8:23 PM, Pratyush Yadav wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 17/11/21 02:36PM, Tudor.Ambarus@microchip.com wrote:
>> On 11/16/21 8:11 PM, Pratyush Yadav wrote:
>>
>>>>
>>>>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>>>>>   think it actually uses any values you initialize here but still worth
>>>>>   pointing out.
>>>>
>>>> we are safe here, the pointer to mtd is used just to get the pointer to
>>>> nor.
>>>
>>> Yeah, but who knows if that might change some time later. I would prefer
>>> we don't use a member we haven't initialized yet.
>>
>> If it weren't for the SPI NOR controller drivers that use
>> spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
>> above the mtd_device_register(). It will indicate that no mtd_info
>> field is used up to that point, less things to worry about.
>> spi_nor_try_unlock_all() calls
>>       spi_nor_unlock(&nor->mtd, 0, nor->params->size);
>> I can't see for now if we will ever need some specific mtd_info
>> parameter. I would say that we won't, we're just unlocking the full
>> flash, every info we would need we can obtain from NOR. The discussion
>> would be different if it were about mtd partitions, but it isn't, we're
>> dealing with the entire flash.
>>
>> Would you accept the place where I put spi_nor_set_mtd_info() if I add
>> a comment before calling it? Something like:
>> /* No mtd_info fields are used up to this point. */
>> spi_nor_set_mtd_info();
> 
> I see that everything that spi_nor_set_mtd_info() needs is set by the
> time spi_nor_init_params() is finished. Everything after that is
> concerned about selecting the protocol and sending the init commands to
> the flash. So why can't you call it right after spi_nor_init_params()?

Because I would like to move it just above mtd_device_register() in the future.
If unlock_all() will need some mtd fields in the future, we can introduce a
spi_nor_prepare_mtd_for_unlock_all(). I don't want the mtd fields init to be
scattered through the SPI NOR core. They shouldn't be used in the NOR's
probe sequence of calls anyway, keeping them closer to mtd_device_register()
makes the code easier to grasp I think.

I will respin the series soon and wanted to let you know why I kept
spi_nor_set_mtd_info() where it is in this patch set.

Cheers,
ta

> That and updating spi_nor_spimem_check_op() and spi_nor_set_addr_width()
> to use nor->params->size instead of nor->mtd.size should do the trick.
> 
> I think that it is implied that mtd_info fields are not being used until
> they are initialized so I don't think the comment itself is of much use,
> but I don't care much about it either way.
> 
> --
> Regards,
> Pratyush Yadav
> Texas Instruments Inc.
> 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info()
@ 2021-11-22  8:38               ` Tudor.Ambarus
  0 siblings, 0 replies; 156+ messages in thread
From: Tudor.Ambarus @ 2021-11-22  8:38 UTC (permalink / raw)
  To: p.yadav
  Cc: macromorgan, vigneshr, jaimeliao, richard, esben, linux,
	knaerzche, michael, linux-mtd, linux-arm-kernel, code,
	miquel.raynal, heiko.thiery, sr, figgyc, mail, zhengxunli

Hi, Pratyush,

On 11/19/21 8:23 PM, Pratyush Yadav wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 17/11/21 02:36PM, Tudor.Ambarus@microchip.com wrote:
>> On 11/16/21 8:11 PM, Pratyush Yadav wrote:
>>
>>>>
>>>>> - spi_nor_try_unlock_all(), which is called by spi_nor_init(). I don't
>>>>>   think it actually uses any values you initialize here but still worth
>>>>>   pointing out.
>>>>
>>>> we are safe here, the pointer to mtd is used just to get the pointer to
>>>> nor.
>>>
>>> Yeah, but who knows if that might change some time later. I would prefer
>>> we don't use a member we haven't initialized yet.
>>
>> If it weren't for the SPI NOR controller drivers that use
>> spi_nor_scan(), I would put the spi_nor_set_mtd_info() just
>> above the mtd_device_register(). It will indicate that no mtd_info
>> field is used up to that point, less things to worry about.
>> spi_nor_try_unlock_all() calls
>>       spi_nor_unlock(&nor->mtd, 0, nor->params->size);
>> I can't see for now if we will ever need some specific mtd_info
>> parameter. I would say that we won't, we're just unlocking the full
>> flash, every info we would need we can obtain from NOR. The discussion
>> would be different if it were about mtd partitions, but it isn't, we're
>> dealing with the entire flash.
>>
>> Would you accept the place where I put spi_nor_set_mtd_info() if I add
>> a comment before calling it? Something like:
>> /* No mtd_info fields are used up to this point. */
>> spi_nor_set_mtd_info();
> 
> I see that everything that spi_nor_set_mtd_info() needs is set by the
> time spi_nor_init_params() is finished. Everything after that is
> concerned about selecting the protocol and sending the init commands to
> the flash. So why can't you call it right after spi_nor_init_params()?

Because I would like to move it just above mtd_device_register() in the future.
If unlock_all() will need some mtd fields in the future, we can introduce a
spi_nor_prepare_mtd_for_unlock_all(). I don't want the mtd fields init to be
scattered through the SPI NOR core. They shouldn't be used in the NOR's
probe sequence of calls anyway, keeping them closer to mtd_device_register()
makes the code easier to grasp I think.

I will respin the series soon and wanted to let you know why I kept
spi_nor_set_mtd_info() where it is in this patch set.

Cheers,
ta

> That and updating spi_nor_spimem_check_op() and spi_nor_set_addr_width()
> to use nor->params->size instead of nor->mtd.size should do the trick.
> 
> I think that it is implied that mtd_info fields are not being used until
> they are initialized so I don't think the comment itself is of much use,
> but I don't care much about it either way.
> 
> --
> Regards,
> Pratyush Yadav
> Texas Instruments Inc.
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-11-22  8:41 UTC | newest]

Thread overview: 156+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 17:26 [PATCH v3 00/25] mtd: spi-nor: Clean params init Tudor Ambarus
2021-10-29 17:26 ` Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  8:18   ` Michael Walle
2021-11-09  8:18     ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  8:21   ` Michael Walle
2021-11-09  8:21     ` Michael Walle
2021-11-15 10:59   ` Pratyush Yadav
2021-11-15 10:59     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  8:22   ` Michael Walle
2021-11-09  8:22     ` Michael Walle
2021-11-15 18:52   ` Pratyush Yadav
2021-11-15 18:52     ` Pratyush Yadav
2021-11-16 14:25     ` Tudor.Ambarus
2021-11-16 14:25       ` Tudor.Ambarus
2021-11-16 18:11       ` Pratyush Yadav
2021-11-16 18:11         ` Pratyush Yadav
2021-11-17 14:36         ` Tudor.Ambarus
2021-11-17 14:36           ` Tudor.Ambarus
2021-11-19 18:23           ` Pratyush Yadav
2021-11-19 18:23             ` Pratyush Yadav
2021-11-22  8:38             ` Tudor.Ambarus
2021-11-22  8:38               ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  8:24   ` Michael Walle
2021-11-09  8:24     ` Michael Walle
2021-11-09  8:34     ` Tudor.Ambarus
2021-11-09  8:34       ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:31   ` Michael Walle
2021-11-09  9:31     ` Michael Walle
2021-11-15 18:56   ` Pratyush Yadav
2021-11-15 18:56     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:31   ` Michael Walle
2021-11-09  9:31     ` Michael Walle
2021-11-15 18:59   ` Pratyush Yadav
2021-11-15 18:59     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 07/25] mtd: spi-nor: sst: " Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:34   ` Michael Walle
2021-11-09  9:34     ` Michael Walle
2021-11-15 19:00   ` Pratyush Yadav
2021-11-15 19:00     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:36   ` Michael Walle
2021-11-09  9:36     ` Michael Walle
2021-11-15 19:00   ` Pratyush Yadav
2021-11-15 19:00     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:43   ` Michael Walle
2021-11-09  9:43     ` Michael Walle
2021-11-15 19:01   ` Pratyush Yadav
2021-11-15 19:01     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:47   ` Michael Walle
2021-11-09  9:47     ` Michael Walle
2021-11-09 10:22     ` Tudor.Ambarus
2021-11-09 10:22       ` Tudor.Ambarus
2021-11-09 10:23       ` Tudor.Ambarus
2021-11-09 10:23         ` Tudor.Ambarus
2021-11-09 10:24       ` Michael Walle
2021-11-09 10:24         ` Michael Walle
2021-11-15 19:03   ` Pratyush Yadav
2021-11-15 19:03     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09  9:48   ` Michael Walle
2021-11-09  9:48     ` Michael Walle
2021-11-15 19:06   ` Pratyush Yadav
2021-11-15 19:06     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09 10:18   ` Michael Walle
2021-11-09 10:18     ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-09 12:21   ` Michael Walle
2021-11-09 12:21     ` Michael Walle
2021-11-09 12:31     ` Tudor.Ambarus
2021-11-09 12:31       ` Tudor.Ambarus
2021-11-12 21:28       ` Michael Walle
2021-11-12 21:28         ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-12 21:50   ` Michael Walle
2021-11-12 21:50     ` Michael Walle
2021-11-15  4:55     ` Tudor.Ambarus
2021-11-15  4:55       ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-15 19:12   ` Pratyush Yadav
2021-11-15 19:12     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-16 10:57   ` Pratyush Yadav
2021-11-16 10:57     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 17/25] mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-16 11:07   ` Pratyush Yadav
2021-11-16 11:07     ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup() Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-11-12 21:53   ` Michael Walle
2021-11-12 21:53     ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:31   ` Tudor.Ambarus
2021-10-29 17:31     ` Tudor.Ambarus
2021-11-09 12:25     ` Michael Walle
2021-11-09 12:25       ` Michael Walle
2021-11-09 12:33       ` Tudor.Ambarus
2021-11-09 12:33         ` Tudor.Ambarus
2021-11-09 12:37         ` Michael Walle
2021-11-09 12:37           ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: " Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:31   ` Tudor.Ambarus
2021-10-29 17:31     ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 22/25] mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:33   ` Tudor.Ambarus
2021-10-29 17:33     ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: " Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:33   ` Tudor.Ambarus
2021-10-29 17:33     ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: " Tudor Ambarus
2021-10-29 17:26   ` Tudor Ambarus
2021-10-29 17:34   ` Tudor.Ambarus
2021-10-29 17:34     ` Tudor.Ambarus
2021-11-08 10:15 ` [PATCH v3 00/25] mtd: spi-nor: Clean params init Tudor.Ambarus
2021-11-08 10:15   ` Tudor.Ambarus
2021-11-08 10:31   ` Michael Walle
2021-11-08 10:31     ` Michael Walle
2021-11-16 11:36 ` Pratyush Yadav
2021-11-16 11:36   ` Pratyush Yadav
2021-11-16 11:56   ` Michael Walle
2021-11-16 11:56     ` Michael Walle
2021-11-17 13:17 ` (subset)[PATCH " Tudor Ambarus
2021-11-17 13:17   ` Tudor Ambarus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.