linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] mtd: spi-nor: generic flash driver
@ 2022-08-10 22:06 Michael Walle
  2022-08-10 22:06 ` [PATCH v2 1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle

Add a generic flash driver, which is used when we don't find a matching
flash in our database. All the basic features of a flash can be discovered
by SFDP and most (if not all) newer flashes support it.

changes since v1:
 - fix doc prototype mistake reported by the kernel test robot
 - preset page_size to 256 to support flashes which just have
   SFDP data corresponding to JESD216A
 - add new patch
   mtd: spi-nor: fix select_uniform_erase to skip 0 erase size
 - add function doc to explain wanted_size=0 in
   spi_nor_select_uniform_erase()

Michael Walle (7):
  mtd: spi-nor: hide jedec_id sysfs attribute if not present
  mtd: spi-nor: sysfs: hide manufacturer if it is not set
  mtd: spi-nor: remember full JEDEC flash ID
  mtd: spi-nor: move function declaration out of sfdp.h
  mtd: spi-nor: fix select_uniform_erase to skip 0 erase size
  mtd: spi-nor: add generic flash driver
  mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver

 .../ABI/testing/sysfs-bus-spi-devices-spi-nor |  6 ++++
 drivers/mtd/spi-nor/core.c                    | 35 +++++++++++++++++--
 drivers/mtd/spi-nor/core.h                    |  3 ++
 drivers/mtd/spi-nor/debugfs.c                 |  2 +-
 drivers/mtd/spi-nor/sfdp.c                    | 27 ++++++++++++++
 drivers/mtd/spi-nor/sfdp.h                    |  2 --
 drivers/mtd/spi-nor/sysfs.c                   | 20 ++++++++++-
 include/linux/mtd/spi-nor.h                   |  3 ++
 8 files changed, 92 insertions(+), 6 deletions(-)

-- 
2.30.2


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

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

* [PATCH v2 1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-08-10 22:06 ` [PATCH v2 2/7] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

Some non-jedec compliant flashes (like the Everspin flashes) don't have
an ID at all. Hide the attribute in this case.

Fixes: 36ac02286265 ("mtd: spi-nor: add initial sysfs support")
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 .../ABI/testing/sysfs-bus-spi-devices-spi-nor      |  3 +++
 drivers/mtd/spi-nor/sysfs.c                        | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
index d76cd3946434..e9ef69aef20b 100644
--- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
+++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
@@ -5,6 +5,9 @@ Contact:	linux-mtd@lists.infradead.org
 Description:	(RO) The JEDEC ID of the SPI NOR flash as reported by the
 		flash device.
 
+		The attribute is not present if the flash doesn't support
+		the "Read JEDEC ID" command (9Fh). This is the case for
+		non-JEDEC compliant flashes.
 
 What:		/sys/bus/spi/devices/.../spi-nor/manufacturer
 Date:		April 2021
diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 9aec9d8a98ad..4c3b351aef24 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -67,6 +67,19 @@ static struct bin_attribute *spi_nor_sysfs_bin_entries[] = {
 	NULL
 };
 
+static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
+					struct attribute *attr, int n)
+{
+	struct spi_device *spi = to_spi_device(kobj_to_dev(kobj));
+	struct spi_mem *spimem = spi_get_drvdata(spi);
+	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
+
+	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
+		return 0;
+
+	return 0444;
+}
+
 static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
 					    struct bin_attribute *attr, int n)
 {
@@ -82,6 +95,7 @@ static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
 
 static const struct attribute_group spi_nor_sysfs_group = {
 	.name		= "spi-nor",
+	.is_visible	= spi_nor_sysfs_is_visible,
 	.is_bin_visible	= spi_nor_sysfs_is_bin_visible,
 	.attrs		= spi_nor_sysfs_entries,
 	.bin_attrs	= spi_nor_sysfs_bin_entries,
-- 
2.30.2


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

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

* [PATCH v2 2/7] mtd: spi-nor: sysfs: hide manufacturer if it is not set
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
  2022-08-10 22:06 ` [PATCH v2 1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-08-10 22:06 ` [PATCH v2 3/7] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

The manufacturer may be optional when pure SFDP flashes are supported.
Hide the sysfs property if no manufacturer is set.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor | 3 +++
 drivers/mtd/spi-nor/sysfs.c                             | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
index e9ef69aef20b..c800621eff95 100644
--- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
+++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
@@ -15,6 +15,9 @@ KernelVersion:	5.14
 Contact:	linux-mtd@lists.infradead.org
 Description:	(RO) Manufacturer of the SPI NOR flash.
 
+		The attribute is not present if the flash device isn't
+		known to the kernel and is only probed by its SFDP
+		tables.
 
 What:		/sys/bus/spi/devices/.../spi-nor/partname
 Date:		April 2021
diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 4c3b351aef24..20563c1926f4 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -74,6 +74,8 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
 	struct spi_mem *spimem = spi_get_drvdata(spi);
 	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
 
+	if (attr == &dev_attr_manufacturer.attr && !nor->manufacturer)
+		return 0;
 	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
 		return 0;
 
-- 
2.30.2


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

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

* [PATCH v2 3/7] mtd: spi-nor: remember full JEDEC flash ID
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
  2022-08-10 22:06 ` [PATCH v2 1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
  2022-08-10 22:06 ` [PATCH v2 2/7] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-08-10 22:06 ` [PATCH v2 4/7] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

At the moment, we print the JEDEC ID that is stored in our database. The
generic flash support won't have such an entry in our database. To find
out the JEDEC ID later we will have to cache it. There is also another
advantage: If the flash is found in the database, the ID could be
truncated because the ID of the entry is used which can be shorter. Some
flashes still holds valuable information in the bytes after the JEDEC ID
and come in handy during debugging of when coping with INFO6() entries.
These are not accessible for now.

Save a copy of the ID bytes after reading and display it via debugfs.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 drivers/mtd/spi-nor/core.c    | 5 +++++
 drivers/mtd/spi-nor/debugfs.c | 2 +-
 include/linux/mtd/spi-nor.h   | 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f2c64006f8d7..f1d01c7dacce 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1664,6 +1664,11 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
 		return ERR_PTR(ret);
 	}
 
+	/* Cache the complete flash ID. */
+	nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL);
+	if (!nor->id)
+		return ERR_PTR(-ENOMEM);
+
 	info = spi_nor_match_id(nor, id);
 	if (!info) {
 		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c
index df76cb5de3f9..ff895f6758ea 100644
--- a/drivers/mtd/spi-nor/debugfs.c
+++ b/drivers/mtd/spi-nor/debugfs.c
@@ -81,7 +81,7 @@ static int spi_nor_params_show(struct seq_file *s, void *data)
 	int i;
 
 	seq_printf(s, "name\t\t%s\n", info->name);
-	seq_printf(s, "id\t\t%*ph\n", info->id_len, info->id);
+	seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id);
 	string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf));
 	seq_printf(s, "size\t\t%s\n", buf);
 	seq_printf(s, "write size\t%u\n", params->writesize);
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 42218a1164f6..25765556223a 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -349,6 +349,8 @@ struct spi_nor_flash_parameter;
  * @bouncebuf:		bounce buffer used when the buffer passed by the MTD
  *                      layer is not DMA-able
  * @bouncebuf_size:	size of the bounce buffer
+ * @id:			The flash's ID bytes. Always contains
+ *			SPI_NOR_MAX_ID_LEN bytes.
  * @info:		SPI NOR part JEDEC MFR ID and other info
  * @manufacturer:	SPI NOR manufacturer
  * @addr_nbytes:	number of address bytes
@@ -379,6 +381,7 @@ struct spi_nor {
 	struct spi_mem		*spimem;
 	u8			*bouncebuf;
 	size_t			bouncebuf_size;
+	u8			*id;
 	const struct flash_info	*info;
 	const struct spi_nor_manufacturer *manufacturer;
 	u8			addr_nbytes;
-- 
2.30.2


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

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

* [PATCH v2 4/7] mtd: spi-nor: move function declaration out of sfdp.h
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
                   ` (2 preceding siblings ...)
  2022-08-10 22:06 ` [PATCH v2 3/7] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-08-10 22:06 ` [PATCH v2 5/7] mtd: spi-nor: fix select_uniform_erase to skip 0 erase size Michael Walle
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

sfdp.h should only contain constants related to the JEDEC SFDP
specification(s).

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 drivers/mtd/spi-nor/core.h | 2 ++
 drivers/mtd/spi-nor/sfdp.h | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 85b0cf254e97..68aaccaa12d8 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -701,6 +701,8 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
 				     const u8 *buf, size_t len);
 
+int spi_nor_parse_sfdp(struct spi_nor *nor);
+
 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
 {
 	return container_of(mtd, struct spi_nor, mtd);
diff --git a/drivers/mtd/spi-nor/sfdp.h b/drivers/mtd/spi-nor/sfdp.h
index bbf80d2990ab..c1969f0a2f46 100644
--- a/drivers/mtd/spi-nor/sfdp.h
+++ b/drivers/mtd/spi-nor/sfdp.h
@@ -107,6 +107,4 @@ struct sfdp_parameter_header {
 	u8		id_msb;
 };
 
-int spi_nor_parse_sfdp(struct spi_nor *nor);
-
 #endif /* __LINUX_MTD_SFDP_H */
-- 
2.30.2


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

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

* [PATCH v2 5/7] mtd: spi-nor: fix select_uniform_erase to skip 0 erase size
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
                   ` (3 preceding siblings ...)
  2022-08-10 22:06 ` [PATCH v2 4/7] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-08-10 22:06 ` [PATCH v2 6/7] mtd: spi-nor: add generic flash driver Michael Walle
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Jae Hyun Yoo

4bait will set the erase size to 0 if there is no corresponding
opcode for the 4byte erase. Fix spi_nor_select_uniform_erase to skip
the 0 erase size to avoid mtd device registration failure cases.

Reported-by: Jae Hyun Yoo <quic_jaehyoo@quicinc.com>
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index f1d01c7dacce..42f9bb63919c 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2118,6 +2118,10 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map,
 
 		tested_erase = &map->erase_type[i];
 
+		/* Skip masked erase types. */
+		if (!tested_erase->size)
+			continue;
+
 		/*
 		 * If the current erase size is the one, stop here:
 		 * we have found the right uniform Sector Erase command.
-- 
2.30.2


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

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

* [PATCH v2 6/7] mtd: spi-nor: add generic flash driver
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
                   ` (4 preceding siblings ...)
  2022-08-10 22:06 ` [PATCH v2 5/7] mtd: spi-nor: fix select_uniform_erase to skip 0 erase size Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-11-01  8:46   ` Tudor.Ambarus
  2022-11-21 13:35   ` Tudor.Ambarus
  2022-08-10 22:06 ` [PATCH v2 7/7] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
  2022-11-21 13:41 ` [PATCH v2 0/7] mtd: spi-nor: " Tudor Ambarus
  7 siblings, 2 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

Our SFDP parsing is everything we need to support all basic operations
of a flash device. If the flash isn't found in our in-kernel flash
database, gracefully fall back to a driver described solely by its SFDP
tables.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 drivers/mtd/spi-nor/core.c | 26 ++++++++++++++++++++++++--
 drivers/mtd/spi-nor/core.h |  1 +
 drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 42f9bb63919c..f10fca5730b8 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1632,6 +1632,16 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
 	&spi_nor_xmc,
 };
 
+static const struct flash_info spi_nor_generic_flash = {
+	.name = "spi-nor-generic",
+	/*
+	 * JESD216 rev A doesn't specify the page size, therefore we need a
+	 * sane default.
+	 */
+	.page_size = 256,
+	.parse_sfdp = true,
+};
+
 static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
 						 const u8 *id)
 {
@@ -1670,6 +1680,14 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
 		return ERR_PTR(-ENOMEM);
 
 	info = spi_nor_match_id(nor, id);
+
+	/* Fallback to a generic flash described only by its SFDP data. */
+	if (!info) {
+		ret = spi_nor_check_sfdp_signature(nor);
+		if (!ret)
+			info = &spi_nor_generic_flash;
+	}
+
 	if (!info) {
 		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
 			SPI_NOR_MAX_ID_LEN, id);
@@ -2096,8 +2114,12 @@ static int spi_nor_select_pp(struct spi_nor *nor,
  * spi_nor_select_uniform_erase() - select optimum uniform erase type
  * @map:		the erase map of the SPI NOR
  * @wanted_size:	the erase type size to search for. Contains the value of
- *			info->sector_size or of the "small sector" size in case
- *			CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined.
+ *			info->sector_size, the "small sector" size in case
+ *			CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined or 0 if
+ *			there is no information about the sector size. The
+ *			latter is the case if the flash parameters are parsed
+ *			solely by SFDP, then the largest supported erase type
+ *			is selected.
  *
  * Once the optimum uniform sector erase command is found, disable all the
  * other.
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 68aaccaa12d8..ef0a73dbf348 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -701,6 +701,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
 				     const u8 *buf, size_t len);
 
+int spi_nor_check_sfdp_signature(struct spi_nor *nor);
 int spi_nor_parse_sfdp(struct spi_nor *nor);
 
 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index 2257f1b4c2e2..0a77f50a2691 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -1249,6 +1249,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
 		nor->info->fixups->post_sfdp(nor);
 }
 
+/**
+ * spi_nor_check_sfdp_signature() - check for a valid SFDP signature
+ * @nor:	pointer to a 'struct spi_nor'
+ *
+ * Used to detect if the flash supports the RDSFDP command as well as the
+ * presence of a valid SFDP table.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_check_sfdp_signature(struct spi_nor *nor)
+{
+	u32 signature;
+	int err;
+
+	/* Get the SFDP header. */
+	err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
+					   &signature);
+	if (err < 0)
+		return err;
+
+	/* Check the SFDP signature. */
+	if (le32_to_cpu(signature) != SFDP_SIGNATURE)
+		return -EINVAL;
+
+	return 0;
+}
+
 /**
  * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
  * @nor:		pointer to a 'struct spi_nor'
-- 
2.30.2


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

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

* [PATCH v2 7/7] mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
                   ` (5 preceding siblings ...)
  2022-08-10 22:06 ` [PATCH v2 6/7] mtd: spi-nor: add generic flash driver Michael Walle
@ 2022-08-10 22:06 ` Michael Walle
  2022-11-21 13:41 ` [PATCH v2 0/7] mtd: spi-nor: " Tudor Ambarus
  7 siblings, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-08-10 22:06 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	linux-kernel, linux-mtd, Michael Walle, Takahiro Kuwano

We don't have a database entry for the generic SPI-NOR flash driver and
thus we don't have a JEDEC ID to print. Print the (cached) JEDEC ID
instead.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
 drivers/mtd/spi-nor/sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 20563c1926f4..c09bb832b3b9 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -35,8 +35,10 @@ static ssize_t jedec_id_show(struct device *dev,
 	struct spi_device *spi = to_spi_device(dev);
 	struct spi_mem *spimem = spi_get_drvdata(spi);
 	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
+	const u8 *id = nor->info->id_len ? nor->info->id : nor->id;
+	u8 id_len = nor->info->id_len ?: SPI_NOR_MAX_ID_LEN;
 
-	return sysfs_emit(buf, "%*phN\n", nor->info->id_len, nor->info->id);
+	return sysfs_emit(buf, "%*phN\n", id_len, id);
 }
 static DEVICE_ATTR_RO(jedec_id);
 
@@ -76,7 +78,7 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
 
 	if (attr == &dev_attr_manufacturer.attr && !nor->manufacturer)
 		return 0;
-	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
+	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len && !nor->id)
 		return 0;
 
 	return 0444;
-- 
2.30.2


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

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

* Re: [PATCH v2 6/7] mtd: spi-nor: add generic flash driver
  2022-08-10 22:06 ` [PATCH v2 6/7] mtd: spi-nor: add generic flash driver Michael Walle
@ 2022-11-01  8:46   ` Tudor.Ambarus
  2022-11-07 14:42     ` Tudor.Ambarus
  2022-11-07 18:22     ` Michael Walle
  2022-11-21 13:35   ` Tudor.Ambarus
  1 sibling, 2 replies; 13+ messages in thread
From: Tudor.Ambarus @ 2022-11-01  8:46 UTC (permalink / raw)
  To: michael, pratyush
  Cc: miquel.raynal, richard, vigneshr, linux-kernel, linux-mtd,
	Takahiro.Kuwano

On 8/11/22 01:06, Michael Walle wrote:
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1632,6 +1632,16 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
>         &spi_nor_xmc,
>  };
> 
> +static const struct flash_info spi_nor_generic_flash = {
> +       .name = "spi-nor-generic",

How about "jedec,spi-nor" instead? The series looks good, I intend to test it
and apply it soon.

-- 
Cheers,
ta

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

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

* Re: [PATCH v2 6/7] mtd: spi-nor: add generic flash driver
  2022-11-01  8:46   ` Tudor.Ambarus
@ 2022-11-07 14:42     ` Tudor.Ambarus
  2022-11-07 18:22     ` Michael Walle
  1 sibling, 0 replies; 13+ messages in thread
From: Tudor.Ambarus @ 2022-11-07 14:42 UTC (permalink / raw)
  To: michael, pratyush
  Cc: miquel.raynal, richard, vigneshr, linux-kernel, linux-mtd,
	Takahiro.Kuwano

On 11/1/22 10:46, Tudor.Ambarus@microchip.com wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 8/11/22 01:06, Michael Walle wrote:
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
>> @@ -1632,6 +1632,16 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
>>         &spi_nor_xmc,
>>  };
>>
>> +static const struct flash_info spi_nor_generic_flash = {
>> +       .name = "spi-nor-generic",
> 
> How about "jedec,spi-nor" instead? The series looks good, I intend to test it
> and apply it soon.
> 

Pratyush, do you agree with the change proposed, s/spi-nor-generic/jedec,spi-nor.
Michael seems busy and I'd like to progress with this.

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

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

* Re: [PATCH v2 6/7] mtd: spi-nor: add generic flash driver
  2022-11-01  8:46   ` Tudor.Ambarus
  2022-11-07 14:42     ` Tudor.Ambarus
@ 2022-11-07 18:22     ` Michael Walle
  1 sibling, 0 replies; 13+ messages in thread
From: Michael Walle @ 2022-11-07 18:22 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: pratyush, miquel.raynal, richard, vigneshr, linux-kernel,
	linux-mtd, Takahiro.Kuwano

Am 2022-11-01 09:46, schrieb Tudor.Ambarus@microchip.com:
> On 8/11/22 01:06, Michael Walle wrote:
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
>> @@ -1632,6 +1632,16 @@ static const struct spi_nor_manufacturer 
>> *manufacturers[] = {
>>         &spi_nor_xmc,
>>  };
>> 
>> +static const struct flash_info spi_nor_generic_flash = {
>> +       .name = "spi-nor-generic",
> 
> How about "jedec,spi-nor" instead? The series looks good, I intend to 
> test it
> and apply it soon.

I had that string before actually but decided against it because it
looks like "jedec" is the vendor, which is (a) not true for any flash
and (b) if it would be a vendor, it should go into the manufacturer
property, which isn't supported at the moment.

That being said, I don't care too much. After all, it's just a name.

(and yes, I'm on vacation till next week ;)

-michael

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

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

* Re: [PATCH v2 6/7] mtd: spi-nor: add generic flash driver
  2022-08-10 22:06 ` [PATCH v2 6/7] mtd: spi-nor: add generic flash driver Michael Walle
  2022-11-01  8:46   ` Tudor.Ambarus
@ 2022-11-21 13:35   ` Tudor.Ambarus
  1 sibling, 0 replies; 13+ messages in thread
From: Tudor.Ambarus @ 2022-11-21 13:35 UTC (permalink / raw)
  To: michael, pratyush
  Cc: miquel.raynal, richard, vigneshr, linux-kernel, linux-mtd,
	Takahiro.Kuwano

On 8/11/22 01:06, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Our SFDP parsing is everything we need to support all basic operations
> of a flash device. If the flash isn't found in our in-kernel flash
> database, gracefully fall back to a driver described solely by its SFDP
> tables.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
Tested-by: Tudor Ambarus <tudor.ambarus@microchip.com>

> ---
>  drivers/mtd/spi-nor/core.c | 26 ++++++++++++++++++++++++--
>  drivers/mtd/spi-nor/core.h |  1 +
>  drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
>  3 files changed, 52 insertions(+), 2 deletions(-)
> 
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH v2 0/7] mtd: spi-nor: generic flash driver
  2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
                   ` (6 preceding siblings ...)
  2022-08-10 22:06 ` [PATCH v2 7/7] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
@ 2022-11-21 13:41 ` Tudor Ambarus
  7 siblings, 0 replies; 13+ messages in thread
From: Tudor Ambarus @ 2022-11-21 13:41 UTC (permalink / raw)
  To: michael, pratyush
  Cc: Tudor Ambarus, richard, miquel.raynal, linux-kernel, linux-mtd, vigneshr

On Thu, 11 Aug 2022 00:06:47 +0200, Michael Walle wrote:
> Add a generic flash driver, which is used when we don't find a matching
> flash in our database. All the basic features of a flash can be discovered
> by SFDP and most (if not all) newer flashes support it.
> 
> changes since v1:
>  - fix doc prototype mistake reported by the kernel test robot
>  - preset page_size to 256 to support flashes which just have
>    SFDP data corresponding to JESD216A
>  - add new patch
>    mtd: spi-nor: fix select_uniform_erase to skip 0 erase size
>  - add function doc to explain wanted_size=0 in
>    spi_nor_select_uniform_erase()
> 
> [...]

Applied to spi-nor/next, thanks!

[1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present
      https://git.kernel.org/mtd/c/7d388551b688
[2/7] mtd: spi-nor: sysfs: hide manufacturer if it is not set
      https://git.kernel.org/mtd/c/0d9270f2762b
[3/7] mtd: spi-nor: remember full JEDEC flash ID
      https://git.kernel.org/mtd/c/28ef7670414e
[4/7] mtd: spi-nor: move function declaration out of sfdp.h
      https://git.kernel.org/mtd/c/fa06bb26a40c
[5/7] mtd: spi-nor: fix select_uniform_erase to skip 0 erase size
      https://git.kernel.org/mtd/c/39eece67a3cf
[6/7] mtd: spi-nor: add generic flash driver
      https://git.kernel.org/mtd/c/773bbe104497
[7/7] mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver
      https://git.kernel.org/mtd/c/0a92de16b61b

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] 13+ messages in thread

end of thread, other threads:[~2022-11-21 13:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 22:06 [PATCH v2 0/7] mtd: spi-nor: generic flash driver Michael Walle
2022-08-10 22:06 ` [PATCH v2 1/7] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
2022-08-10 22:06 ` [PATCH v2 2/7] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
2022-08-10 22:06 ` [PATCH v2 3/7] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
2022-08-10 22:06 ` [PATCH v2 4/7] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
2022-08-10 22:06 ` [PATCH v2 5/7] mtd: spi-nor: fix select_uniform_erase to skip 0 erase size Michael Walle
2022-08-10 22:06 ` [PATCH v2 6/7] mtd: spi-nor: add generic flash driver Michael Walle
2022-11-01  8:46   ` Tudor.Ambarus
2022-11-07 14:42     ` Tudor.Ambarus
2022-11-07 18:22     ` Michael Walle
2022-11-21 13:35   ` Tudor.Ambarus
2022-08-10 22:06 ` [PATCH v2 7/7] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
2022-11-21 13:41 ` [PATCH v2 0/7] mtd: spi-nor: " Tudor Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).