linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support
@ 2024-08-04 22:15 Michael Walle
  2024-08-12 13:42 ` Pratyush Yadav
  2024-08-13 14:33 ` Pratyush Yadav
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Walle @ 2024-08-04 22:15 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-mtd, linux-kernel

Zetta normally uses BAh as its vendor ID. But for the ZD25Q128C they
took the one from Winbond and messed up the size parameters in SFDP.
Most functions seem compatible with the W25Q128, we just have to fix up
the size.

Link: http://www.zettadevice.com/upload/file/20150821/DS_Zetta_25Q128_RevA.pdf
Link: https://www.lcsc.com/datasheet/lcsc_datasheet_2312081757_Zetta-ZD25Q128CSIGT_C19626875.pdf
Signed-off-by: Michael Walle <mwalle@kernel.org>
---
$ cat /sys/class/spi_master/spi0/spi0.0/spi-nor/jedec_id
ef4018

$ md5sum /sys/class/spi_master/spi0/spi0.0/spi-nor/sfdp
f19e214c6709a259511bac4bd9c87407  /sys/class/spi_master/spi0/spi0.0/spi-nor/sfdp

$ xxd -p /sys/class/spi_master/spi0/spi0.0/spi-nor/sfdp
53464450000101ff00000109300000ffb3000103600000ffffffffffffff
ffffffffffffffffffffffffffffffffffffe520f9ffffffff0044eb086b
083b80bbeeffffffffff00ffffff00ff0c200f5210d80881ffffffffffff
ffffffffffff003600279ff97764fccbffff

$ cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
Supported read modes by the flash
 1S-1S-1S
  opcode	0x03
  mode cycles	0
  dummy cycles	0
 1S-1S-1S (fast read)
  opcode	0x0b
  mode cycles	0
  dummy cycles	8
 1S-1S-2S
  opcode	0x3b
  mode cycles	0
  dummy cycles	8
 1S-2S-2S
  opcode	0xbb
  mode cycles	4
  dummy cycles	0
 1S-1S-4S
  opcode	0x6b
  mode cycles	0
  dummy cycles	8
 1S-4S-4S
  opcode	0xeb
  mode cycles	2
  dummy cycles	4

Supported page program modes by the flash
 1S-1S-1S
  opcode	0x02

$ cat /sys/kernel/debug/spi-nor/spi0.0/params
name		w25q128
id		ef 40 18 ef 40 18
size		16.0 MiB
write size	1
page size	256
address nbytes	3
flags		HAS_SR_TB | HAS_LOCK | HAS_16BIT_SR

opcodes
 read		0x0b
  dummy cycles	8
 erase		0x20
 program	0x02
 8D extension	none

protocols
 read		1S-1S-1S
 write		1S-1S-1S
 register	1S-1S-1S

erase commands
 81 (256 B) [0]
 20 (4.00 KiB) [1]
 52 (32.0 KiB) [2]
 d8 (64.0 KiB) [3]
 c7 (16.0 MiB)

sector map
 region (in hex)   | erase mask | overlaid
 ------------------+------------+----------
 00000000-00ffffff |     [ 1  ] | no

$ dd if=/dev/urandom of=spi_test bs=1M count=2
2+0 records in
2+0 records out
$ mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash
$ mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
$ hexdump spi_read
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0200000
$ sha256sum spi_read
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  spi_read
$ mtd_debug write /dev/mtd0 0 2097152 spi_test
Copied 2097152 bytes from spi_test to address 0x00000000 in flash
$ mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
$ sha256sum spi*
90145978caa36e84ecc07734d193c97a54ae601884a5ff4e0b90ff8c1f540a03  spi_read
90145978caa36e84ecc07734d193c97a54ae601884a5ff4e0b90ff8c1f540a03  spi_test
$ mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash
$ mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
$ sha256sum spi*
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5  spi_read
90145978caa36e84ecc07734d193c97a54ae601884a5ff4e0b90ff8c1f540a03  spi_test

$ mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_CAP_NORFLASH
mtd.size = 16777216 (16M)
mtd.erasesize = 4096 (4K)
mtd.writesize = 1
mtd.oobsize = 0
regions = 0
---
 drivers/mtd/spi-nor/winbond.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index e065e4fd42a3..9f7ce5763e71 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -17,6 +17,31 @@
 		   SPI_MEM_OP_NO_DUMMY,					\
 		   SPI_MEM_OP_DATA_OUT(1, buf, 0))
 
+static int
+w25q128_post_bfpt_fixups(struct spi_nor *nor,
+			 const struct sfdp_parameter_header *bfpt_header,
+			 const struct sfdp_bfpt *bfpt)
+{
+	/*
+	 * Zetta ZD25Q128C is a clone of the Winbond device. But the encoded
+	 * size is really wrong. It seems that they confused Mbit with MiB.
+	 * Thus the flash is discovered as a 2MiB device.
+	 */
+	if (bfpt_header->major == SFDP_JESD216_MAJOR &&
+	    bfpt_header->minor == SFDP_JESD216_MINOR &&
+	    nor->params->size == SZ_2M &&
+	    nor->params->erase_map.regions[0].size == SZ_2M) {
+		nor->params->size = SZ_16M;
+		nor->params->erase_map.regions[0].size = SZ_16M;
+	}
+
+	return 0;
+}
+
+static const struct spi_nor_fixups w25q128_fixups = {
+	.post_bfpt = w25q128_post_bfpt_fixups,
+};
+
 static int
 w25q256_post_bfpt_fixups(struct spi_nor *nor,
 			 const struct sfdp_parameter_header *bfpt_header,
@@ -108,6 +133,7 @@ static const struct flash_info winbond_nor_parts[] = {
 		.size = SZ_16M,
 		.flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
 		.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
+		.fixups = &w25q128_fixups,
 	}, {
 		.id = SNOR_ID(0xef, 0x40, 0x19),
 		.name = "w25q256",
-- 
2.39.2


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

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

* Re: [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support
  2024-08-04 22:15 [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support Michael Walle
@ 2024-08-12 13:42 ` Pratyush Yadav
  2024-08-12 14:36   ` Michael Walle
  2024-08-13 14:33 ` Pratyush Yadav
  1 sibling, 1 reply; 5+ messages in thread
From: Pratyush Yadav @ 2024-08-12 13:42 UTC (permalink / raw)
  To: Michael Walle
  Cc: Tudor Ambarus, Pratyush Yadav, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd, linux-kernel

On Mon, Aug 05 2024, Michael Walle wrote:

> Zetta normally uses BAh as its vendor ID. But for the ZD25Q128C they
> took the one from Winbond and messed up the size parameters in SFDP.
> Most functions seem compatible with the W25Q128, we just have to fix up
> the size.
>
> Link: http://www.zettadevice.com/upload/file/20150821/DS_Zetta_25Q128_RevA.pdf
> Link: https://www.lcsc.com/datasheet/lcsc_datasheet_2312081757_Zetta-ZD25Q128CSIGT_C19626875.pdf
> Signed-off-by: Michael Walle <mwalle@kernel.org>
> ---
[...]
> diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
> index e065e4fd42a3..9f7ce5763e71 100644
> --- a/drivers/mtd/spi-nor/winbond.c
> +++ b/drivers/mtd/spi-nor/winbond.c
> @@ -17,6 +17,31 @@
>  		   SPI_MEM_OP_NO_DUMMY,					\
>  		   SPI_MEM_OP_DATA_OUT(1, buf, 0))
>  
> +static int
> +w25q128_post_bfpt_fixups(struct spi_nor *nor,
> +			 const struct sfdp_parameter_header *bfpt_header,
> +			 const struct sfdp_bfpt *bfpt)
> +{
> +	/*
> +	 * Zetta ZD25Q128C is a clone of the Winbond device. But the encoded
> +	 * size is really wrong. It seems that they confused Mbit with MiB.
> +	 * Thus the flash is discovered as a 2MiB device.
> +	 */
> +	if (bfpt_header->major == SFDP_JESD216_MAJOR &&
> +	    bfpt_header->minor == SFDP_JESD216_MINOR &&
> +	    nor->params->size == SZ_2M &&
> +	    nor->params->erase_map.regions[0].size == SZ_2M) {
> +		nor->params->size = SZ_16M;
> +		nor->params->erase_map.regions[0].size = SZ_16M;
> +	}

Since the size is 16 MiB for both Zetta and Winbond, why do you have
these conditions here? Why not just do it unconditionally? What
situation do you want to protect against?

> +
> +	return 0;
> +}
> +
> +static const struct spi_nor_fixups w25q128_fixups = {
> +	.post_bfpt = w25q128_post_bfpt_fixups,
> +};
> +
>  static int
>  w25q256_post_bfpt_fixups(struct spi_nor *nor,
>  			 const struct sfdp_parameter_header *bfpt_header,
> @@ -108,6 +133,7 @@ static const struct flash_info winbond_nor_parts[] = {
>  		.size = SZ_16M,
>  		.flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
>  		.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
> +		.fixups = &w25q128_fixups,
>  	}, {
>  		.id = SNOR_ID(0xef, 0x40, 0x19),
>  		.name = "w25q256",

-- 
Regards,
Pratyush Yadav

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

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

* Re: [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support
  2024-08-12 13:42 ` Pratyush Yadav
@ 2024-08-12 14:36   ` Michael Walle
  2024-08-12 14:45     ` Pratyush Yadav
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Walle @ 2024-08-12 14:36 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2229 bytes --]

Hi,

> > Zetta normally uses BAh as its vendor ID. But for the ZD25Q128C they
> > took the one from Winbond and messed up the size parameters in SFDP.
> > Most functions seem compatible with the W25Q128, we just have to fix up
> > the size.
> >
> > Link: http://www.zettadevice.com/upload/file/20150821/DS_Zetta_25Q128_RevA.pdf
> > Link: https://www.lcsc.com/datasheet/lcsc_datasheet_2312081757_Zetta-ZD25Q128CSIGT_C19626875.pdf
> > Signed-off-by: Michael Walle <mwalle@kernel.org>
> > ---
> [...]
> > diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
> > index e065e4fd42a3..9f7ce5763e71 100644
> > --- a/drivers/mtd/spi-nor/winbond.c
> > +++ b/drivers/mtd/spi-nor/winbond.c
> > @@ -17,6 +17,31 @@
> >  		   SPI_MEM_OP_NO_DUMMY,					\
> >  		   SPI_MEM_OP_DATA_OUT(1, buf, 0))
> >  
> > +static int
> > +w25q128_post_bfpt_fixups(struct spi_nor *nor,
> > +			 const struct sfdp_parameter_header *bfpt_header,
> > +			 const struct sfdp_bfpt *bfpt)
> > +{
> > +	/*
> > +	 * Zetta ZD25Q128C is a clone of the Winbond device. But the encoded
> > +	 * size is really wrong. It seems that they confused Mbit with MiB.
> > +	 * Thus the flash is discovered as a 2MiB device.
> > +	 */
> > +	if (bfpt_header->major == SFDP_JESD216_MAJOR &&
> > +	    bfpt_header->minor == SFDP_JESD216_MINOR &&
> > +	    nor->params->size == SZ_2M &&
> > +	    nor->params->erase_map.regions[0].size == SZ_2M) {
> > +		nor->params->size = SZ_16M;
> > +		nor->params->erase_map.regions[0].size = SZ_16M;
> > +	}
>
> Since the size is 16 MiB for both Zetta and Winbond, why do you have
> these conditions here? Why not just do it unconditionally? What
> situation do you want to protect against?

Two things, I want to make sure, the values I'll overwrite (which
were set indirectly by the SFDP data I check here) are really the
"before" value I expect them to be. And secondly, I want to
fingerprint the SFDP as accurately as possible. I mean you wouldn't
need the SFDP version either. Think of a preparation for a possible
.match() callback in zetta.c. That would probably look like this,
i.e. check the flash id and these four conditions.

What are your concerns?

-michael

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]

[-- Attachment #2: Type: text/plain, Size: 144 bytes --]

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

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

* Re: [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support
  2024-08-12 14:36   ` Michael Walle
@ 2024-08-12 14:45     ` Pratyush Yadav
  0 siblings, 0 replies; 5+ messages in thread
From: Pratyush Yadav @ 2024-08-12 14:45 UTC (permalink / raw)
  To: Michael Walle
  Cc: Pratyush Yadav, Tudor Ambarus, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd, linux-kernel

On Mon, Aug 12 2024, Michael Walle wrote:

> Hi,
>
>> > Zetta normally uses BAh as its vendor ID. But for the ZD25Q128C they
>> > took the one from Winbond and messed up the size parameters in SFDP.
>> > Most functions seem compatible with the W25Q128, we just have to fix up
>> > the size.
>> >
>> > Link: http://www.zettadevice.com/upload/file/20150821/DS_Zetta_25Q128_RevA.pdf
>> > Link: https://www.lcsc.com/datasheet/lcsc_datasheet_2312081757_Zetta-ZD25Q128CSIGT_C19626875.pdf
>> > Signed-off-by: Michael Walle <mwalle@kernel.org>
>> > ---
>> [...]
>> > diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
>> > index e065e4fd42a3..9f7ce5763e71 100644
>> > --- a/drivers/mtd/spi-nor/winbond.c
>> > +++ b/drivers/mtd/spi-nor/winbond.c
>> > @@ -17,6 +17,31 @@
>> >  		   SPI_MEM_OP_NO_DUMMY,					\
>> >  		   SPI_MEM_OP_DATA_OUT(1, buf, 0))
>> >  
>> > +static int
>> > +w25q128_post_bfpt_fixups(struct spi_nor *nor,
>> > +			 const struct sfdp_parameter_header *bfpt_header,
>> > +			 const struct sfdp_bfpt *bfpt)
>> > +{
>> > +	/*
>> > +	 * Zetta ZD25Q128C is a clone of the Winbond device. But the encoded
>> > +	 * size is really wrong. It seems that they confused Mbit with MiB.
>> > +	 * Thus the flash is discovered as a 2MiB device.
>> > +	 */
>> > +	if (bfpt_header->major == SFDP_JESD216_MAJOR &&
>> > +	    bfpt_header->minor == SFDP_JESD216_MINOR &&
>> > +	    nor->params->size == SZ_2M &&
>> > +	    nor->params->erase_map.regions[0].size == SZ_2M) {
>> > +		nor->params->size = SZ_16M;
>> > +		nor->params->erase_map.regions[0].size = SZ_16M;
>> > +	}
>>
>> Since the size is 16 MiB for both Zetta and Winbond, why do you have
>> these conditions here? Why not just do it unconditionally? What
>> situation do you want to protect against?
>
> Two things, I want to make sure, the values I'll overwrite (which
> were set indirectly by the SFDP data I check here) are really the
> "before" value I expect them to be. And secondly, I want to
> fingerprint the SFDP as accurately as possible. I mean you wouldn't
> need the SFDP version either. Think of a preparation for a possible
> .match() callback in zetta.c. That would probably look like this,
> i.e. check the flash id and these four conditions.

Hmm, I see. I personally find doing it unconditional a bit easier to
grok but this is fine too I think.

Reviewed-by: Pratyush Yadav <pratyush@kernel.org>

> What are your concerns?

None. I was mostly curious why you did it this way.

-- 
Regards,
Pratyush Yadav

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

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

* Re: [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support
  2024-08-04 22:15 [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support Michael Walle
  2024-08-12 13:42 ` Pratyush Yadav
@ 2024-08-13 14:33 ` Pratyush Yadav
  1 sibling, 0 replies; 5+ messages in thread
From: Pratyush Yadav @ 2024-08-13 14:33 UTC (permalink / raw)
  To: Michael Walle
  Cc: Tudor Ambarus, Pratyush Yadav, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd, linux-kernel

On Mon, Aug 05 2024, Michael Walle wrote:

> Zetta normally uses BAh as its vendor ID. But for the ZD25Q128C they
> took the one from Winbond and messed up the size parameters in SFDP.
> Most functions seem compatible with the W25Q128, we just have to fix up
> the size.
>
> Link: http://www.zettadevice.com/upload/file/20150821/DS_Zetta_25Q128_RevA.pdf
> Link: https://www.lcsc.com/datasheet/lcsc_datasheet_2312081757_Zetta-ZD25Q128CSIGT_C19626875.pdf
> Signed-off-by: Michael Walle <mwalle@kernel.org>

Applied to spi-nor/next. Thanks!

-- 
Regards,
Pratyush Yadav

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

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

end of thread, other threads:[~2024-08-13 14:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-04 22:15 [PATCH] mtd: spi-nor: winbond: add Zetta ZD25Q128C support Michael Walle
2024-08-12 13:42 ` Pratyush Yadav
2024-08-12 14:36   ` Michael Walle
2024-08-12 14:45     ` Pratyush Yadav
2024-08-13 14:33 ` Pratyush Yadav

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).