Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode
@ 2025-09-04 13:13 Santhosh Kumar K
  2025-09-04 13:35 ` Tudor Ambarus
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Santhosh Kumar K @ 2025-09-04 13:13 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, tudor.ambarus, pratyush, mwalle
  Cc: linux-mtd, linux-kernel, s-k6, praneeth, p-mantena, a-dutta,
	u-kumar1

The nor->params->addr_mode_nbytes parameter defines the address byte
count for the current addressing mode. When transitioning between SDR
and DDR modes, this parameter must be properly updated to maintain the
correct addressing behavior. So, implement the necessary updates to
nor->params->addr_mode_nbytes during both DDR mode enablement and
disablement operations to ensure address byte counts remain consistent
with the active transfer mode.

Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---

Tested on TI's AM62x SK
Logs: https://gist.github.com/santhosh21/8d69756bd54605d79086b00850e1083a

---
 drivers/mtd/spi-nor/spansion.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
index a0296c871634..678f7f4052c9 100644
--- a/drivers/mtd/spi-nor/spansion.c
+++ b/drivers/mtd/spi-nor/spansion.c
@@ -230,6 +230,8 @@ static int cypress_nor_octal_dtr_en(struct spi_nor *nor)
 			return ret;
 	}
 
+	nor->params->addr_mode_nbytes = 4;
+
 	/* Read flash ID to make sure the switch was successful. */
 	ret = spi_nor_read_id(nor, nor->addr_nbytes, 3, buf,
 			      SNOR_PROTO_8_8_8_DTR);
@@ -275,6 +277,8 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
 			return ret;
 	}
 
+	nor->params->addr_mode_nbytes = 3;
+
 	/* Read flash ID to make sure the switch was successful. */
 	ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1);
 	if (ret) {
-- 
2.34.1


______________________________________________________
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: spansion: Modify addr_mode_nbytes for DTR mode
  2025-09-04 13:13 [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode Santhosh Kumar K
@ 2025-09-04 13:35 ` Tudor Ambarus
  2025-09-04 14:28 ` Pratyush Yadav
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tudor Ambarus @ 2025-09-04 13:35 UTC (permalink / raw)
  To: Santhosh Kumar K, miquel.raynal, richard, vigneshr, pratyush,
	mwalle, Takahiro Kuwano
  Cc: linux-mtd, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1

Hi, Takahiro,

Would you please review this patch?

Thanks!
ta


On 9/4/25 2:13 PM, Santhosh Kumar K wrote:
> The nor->params->addr_mode_nbytes parameter defines the address byte
> count for the current addressing mode. When transitioning between SDR
> and DDR modes, this parameter must be properly updated to maintain the
> correct addressing behavior. So, implement the necessary updates to
> nor->params->addr_mode_nbytes during both DDR mode enablement and
> disablement operations to ensure address byte counts remain consistent
> with the active transfer mode.
> 
> Signed-off-by: Santhosh Kumar K <s-k6@ti.com>

______________________________________________________
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: spansion: Modify addr_mode_nbytes for DTR mode
  2025-09-04 13:13 [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode Santhosh Kumar K
  2025-09-04 13:35 ` Tudor Ambarus
@ 2025-09-04 14:28 ` Pratyush Yadav
  2025-09-08  9:28 ` Takahiro Kuwano
  2025-09-15  7:41 ` Santhosh Kumar K
  3 siblings, 0 replies; 5+ messages in thread
From: Pratyush Yadav @ 2025-09-04 14:28 UTC (permalink / raw)
  To: Santhosh Kumar K
  Cc: miquel.raynal, richard, vigneshr, tudor.ambarus, pratyush, mwalle,
	linux-mtd, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1

On Thu, Sep 04 2025, Santhosh Kumar K wrote:

> The nor->params->addr_mode_nbytes parameter defines the address byte
> count for the current addressing mode. When transitioning between SDR
> and DDR modes, this parameter must be properly updated to maintain the
> correct addressing behavior. So, implement the necessary updates to
> nor->params->addr_mode_nbytes during both DDR mode enablement and
> disablement operations to ensure address byte counts remain consistent
> with the active transfer mode.

Doesn't spi_nor_set_4byte_addr_mode() do this already? What is the
difference here? Are we missing a call to it after
spi_nor_set_octal_dtr() in some path?

Also, do you see a real bug with this or is this purely theoretical?

[...]

-- 
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: spansion: Modify addr_mode_nbytes for DTR mode
  2025-09-04 13:13 [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode Santhosh Kumar K
  2025-09-04 13:35 ` Tudor Ambarus
  2025-09-04 14:28 ` Pratyush Yadav
@ 2025-09-08  9:28 ` Takahiro Kuwano
  2025-09-15  7:41 ` Santhosh Kumar K
  3 siblings, 0 replies; 5+ messages in thread
From: Takahiro Kuwano @ 2025-09-08  9:28 UTC (permalink / raw)
  To: Santhosh Kumar K, miquel.raynal, richard, vigneshr, tudor.ambarus,
	pratyush, mwalle
  Cc: linux-mtd, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1

On 9/4/2025 10:13 PM, Santhosh Kumar K wrote:
> The nor->params->addr_mode_nbytes parameter defines the address byte
> count for the current addressing mode. When transitioning between SDR
> and DDR modes, this parameter must be properly updated to maintain the
> correct addressing behavior. So, implement the necessary updates to
> nor->params->addr_mode_nbytes during both DDR mode enablement and
> disablement operations to ensure address byte counts remain consistent
> with the active transfer mode.
> 
The address byte count for the current addressing mode is defined as
params->addr_nbytes. The params->addr_mode_nbytes tracks flash's internal
addressing mode and is not used in octal DDR mode.

> Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
> ---
> 
> Tested on TI's AM62x SK
> Logs: https://gist.github.com/santhosh21/8d69756bd54605d79086b00850e1083a
> 
> ---
>  drivers/mtd/spi-nor/spansion.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
> index a0296c871634..678f7f4052c9 100644
> --- a/drivers/mtd/spi-nor/spansion.c
> +++ b/drivers/mtd/spi-nor/spansion.c
> @@ -230,6 +230,8 @@ static int cypress_nor_octal_dtr_en(struct spi_nor *nor)
>  			return ret;
>  	}
>  
> +	nor->params->addr_mode_nbytes = 4;
> +
Are there any problems if we don't do this?

>  	/* Read flash ID to make sure the switch was successful. */
>  	ret = spi_nor_read_id(nor, nor->addr_nbytes, 3, buf,
>  			      SNOR_PROTO_8_8_8_DTR);
> @@ -275,6 +277,8 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
>  			return ret;
>  	}
>  
> +	nor->params->addr_mode_nbytes = 3;
> +
This doesn't work in case flash's internal address mode is 4.

>  	/* Read flash ID to make sure the switch was successful. */
>  	ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1);
>  	if (ret) {

Thanks,
Takahiro


______________________________________________________
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: spansion: Modify addr_mode_nbytes for DTR mode
  2025-09-04 13:13 [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode Santhosh Kumar K
                   ` (2 preceding siblings ...)
  2025-09-08  9:28 ` Takahiro Kuwano
@ 2025-09-15  7:41 ` Santhosh Kumar K
  3 siblings, 0 replies; 5+ messages in thread
From: Santhosh Kumar K @ 2025-09-15  7:41 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, tudor.ambarus, pratyush, mwalle,
	tkuw584924
  Cc: linux-mtd, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1,
	s-k6

Hello Pratyush and Takahiro,

On 04/09/25 18:43, Santhosh Kumar K wrote:
> The nor->params->addr_mode_nbytes parameter defines the address byte
> count for the current addressing mode. When transitioning between SDR
> and DDR modes, this parameter must be properly updated to maintain the
> correct addressing behavior. So, implement the necessary updates to
> nor->params->addr_mode_nbytes during both DDR mode enablement and
> disablement operations to ensure address byte counts remain consistent
> with the active transfer mode.
> 
> Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
> ---
> 
> Tested on TI's AM62x SK
> Logs: https://gist.github.com/santhosh21/8d69756bd54605d79086b00850e1083a

We were facing write and erase failures in NOR flashes without this fix.

Failure log:

root@am62xx-evm:~# flash_erase /dev/mtd6 0 0
Erasing 256 Kibyte @ 0 --  0 % complete [   33.078034] spi-nor spi0.0: 
Erase Error occurred
[   33.086178] spi-nor spi0.0: Erase Error occurredock 0 (mtd6)

         error 5 (Input/output error)
flash_erase: error!: /dev/mtd6: MTD Erase entire chip failureTrying one 
by one each sector.
              error 5 (Input/output error)
Erasing 256 Kibyte @ 0 --  0 % complete libmtd: error!: MEMERASE64 ioctl 
failed for eraseblock 0 (mtd6)
         error 5 (Input/output error)
flash_erase: error!: /dev/mtd6: MTD Erase failure
              error 5 (Input/output error)
Erasing 256 Kibyte @ 0 -- 100 % complete
root@am62xx-evm:~#

But, I just bisected and got to know that the
commit b61c35e3404557779ec427c077f7a9f057bb053d
"mtd: spi-nor: spansion: Use nor->addr_nbytes in octal DTR mode in 
RD_ANY_REG_OP"
fixed this issue. My bad!
Lets drop this patch.

Thanks and Regards,
Santhosh.


______________________________________________________
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:[~2025-09-15  7:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04 13:13 [PATCH] mtd: spi-nor: spansion: Modify addr_mode_nbytes for DTR mode Santhosh Kumar K
2025-09-04 13:35 ` Tudor Ambarus
2025-09-04 14:28 ` Pratyush Yadav
2025-09-08  9:28 ` Takahiro Kuwano
2025-09-15  7:41 ` Santhosh Kumar K

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox