Skip to contentSkip to conversation

mtd: spi: Replace ad-hoc default implementation with spi_mem_op

PATCH New Marek Vasut 4 participants 7 messages Apr 2, 2019 – Apr 12, 2019 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>
---
 drivers/mtd/spi/spi-nor-core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/mtd/spi/spi-nor-core.c +6 -8
index b7f0733877..c4e2f6a08f 100644
@@ -524,8 +524,11 @@ static int read_bar(struct spi_nor *nor, const struct flash_info *info)
  */
 static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 {
-	u8 buf[SPI_NOR_MAX_ADDR_WIDTH];
-	int i;
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->erase_opcode, 1),
+			   SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+			   SPI_MEM_OP_NO_DUMMY,
+			   SPI_MEM_OP_NO_DATA);
 
 	if (nor->erase)
 		return nor->erase(nor, addr);
@@ -534,12 +537,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 	 * Default implementation, if driver doesn't have a specialized HW
 	 * control
 	 */
-	for (i = nor->addr_width - 1; i >= 0; i--) {
-		buf[i] = addr & 0xff;
-		addr >>= 8;
-	}
-
-	return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width);
+	return spi_mem_exec_op(nor->spi, &op);
 }
 
 /*
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

+ Ashish,

Quoted 11 lines · Marek Vasut

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Marek, thanks for the fix!

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Quoted 36 lines
 drivers/mtd/spi/spi-nor-core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/mtd/spi/spi-nor-core.c +6 -8
index b7f0733877..c4e2f6a08f 100644
@@ -524,8 +524,11 @@ static int read_bar(struct spi_nor *nor, const struct flash_info *info)
  */
 static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 {
-	u8 buf[SPI_NOR_MAX_ADDR_WIDTH];
-	int i;
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->erase_opcode, 1),
+			   SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+			   SPI_MEM_OP_NO_DUMMY,
+			   SPI_MEM_OP_NO_DATA);
 
 	if (nor->erase)
 		return nor->erase(nor, addr);
@@ -534,12 +537,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
 	 * Default implementation, if driver doesn't have a specialized HW
 	 * control
 	 */
-	for (i = nor->addr_width - 1; i >= 0; i--) {
-		buf[i] = addr & 0xff;
-		addr >>= 8;
-	}
-
-	return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width);
+	return spi_mem_exec_op(nor->spi, &op);
 }
 
 /*
Signature · 2 lines
Regards
Vignesh
#2 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Quoted 35 lines

-----Original Message-----
From: Vignesh Raghavendra <[email protected]>
Sent: Tuesday, April 2, 2019 10:04 AM
To: Marek Vasut <[email protected]>; u-boot at lists.denx.de
Cc: Marek Vasut <[email protected]>; Horatiu Vultur <[email protected]>; Jagan Teki <[email protected]>; Simon Goldschmidt <[email protected]>; Stefan Roese <[email protected]>; Ashish Kumar <[email protected]>
Subject: Re: [PATCH] mtd: spi: Replace ad-hoc default implementation with spi_mem_op

+ Ashish,

Quoted 11 lines · Marek Vasut

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Quoted 6 lines

Marek, thanks for the fix!

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Yes, follow patch reverts back to old method of erase implementation.

Regards
Ashish

Quoted 42 lines

drivers/mtd/spi/spi-nor-core.c static int read_bar(struct spi_nor *nor, const struct

Quoted 9 lines
 drivers/mtd/spi/spi-nor-core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/drivers/mtd/spi/spi-nor-core.c index b7f0733877..c4e2f6a08f 100644

drivers/mtd/spi/spi-nor-core.c +0 -0
@@ -524,8 +524,11 @@ static int read_bar(struct spi_nor *nor, const struct

flash_info *info)

drivers/mtd/spi/spi-nor-core.c static int spi_nor_erase_sector(struct spi_nor *nor,

Quoted 13 lines
drivers/mtd/spi/spi-nor-core.c +5 -2
  */
 static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)  {
-	u8 buf[SPI_NOR_MAX_ADDR_WIDTH];
-	int i;
+	struct spi_mem_op op =
+		SPI_MEM_OP(SPI_MEM_OP_CMD(nor->erase_opcode, 1),
+			   SPI_MEM_OP_ADDR(nor->addr_width, addr, 1),
+			   SPI_MEM_OP_NO_DUMMY,
+			   SPI_MEM_OP_NO_DATA);
 
 	if (nor->erase)
 		return nor->erase(nor, addr);
@@ -534,12 +537,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor,

u32 addr)

Quoted 4 lines
drivers/mtd/spi/spi-nor-core.c +0 -0
 	 * Default implementation, if driver doesn't have a specialized HW
 	 * control
 	 */

drivers/mtd/spi/spi-nor-core.c static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) · line 543

Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +1 -6
-	for (i = nor->addr_width - 1; i >= 0; i--) {
-		buf[i] = addr & 0xff;
-		addr >>= 8;
-	}
-
-	return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width);
+	return spi_mem_exec_op(nor->spi, &op);
 }
 
 /*

--
Regards
Vignesh

#3 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Quoted 37 lines · Ashish Kumar
Quoted 37 lines

-----Original Message-----
From: Vignesh Raghavendra <[email protected]>
Sent: Tuesday, April 2, 2019 10:04 AM
To: Marek Vasut <[email protected]>; u-boot at lists.denx.de
Cc: Marek Vasut <[email protected]>; Horatiu Vultur <[email protected]>; Jagan Teki <[email protected]>; Simon Goldschmidt <[email protected]>; Stefan Roese <[email protected]>; Ashish Kumar <[email protected]>
Subject: Re: [PATCH] mtd: spi: Replace ad-hoc default implementation with spi_mem_op

+ Ashish,

Quoted 11 lines · Marek Vasut

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Marek, thanks for the fix!

Quoted 8 lines
Quoted 4 lines

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Yes, follow patch reverts back to old method of erase implementation.

I guess this never made it into the release, so the SPI NOR erase is broken in v2019.04 ?

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Quoted 45 lines · Marek Vasut
Quoted 43 lines · Ashish Kumar
Quoted 41 lines

-----Original Message-----
From: Vignesh Raghavendra <[email protected]>
Sent: Tuesday, April 2, 2019 10:04 AM
To: Marek Vasut <[email protected]>; u-boot at lists.denx.de
Cc: Marek Vasut <[email protected]>; Horatiu Vultur <[email protected]>; Jagan Teki <[email protected]>; Simon Goldschmidt <[email protected]>; Stefan Roese <[email protected]>; Ashish Kumar <[email protected]>
Subject: Re: [PATCH] mtd: spi: Replace ad-hoc default implementation with spi_mem_op

+ Ashish,

Quoted 11 lines · Marek Vasut

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Marek, thanks for the fix!

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Quoted 5 lines
Quoted 2 lines

Yes, follow patch reverts back to old method of erase implementation.

I guess this never made it into the release, so the SPI NOR erase is broken in v2019.04 ?

I usually review on top of patchwork, that seems not assigned to me. Vignesh will this break? I can see the erase seems fine on my microzed with last week testing.

#5 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Quoted 32 lines · Jagan Teki
Quoted 32 lines
Quoted 31 lines
Quoted 21 lines · Marek Vasut
Quoted 11 lines

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Quoted 6 lines

Marek, thanks for the fix!

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Yes, follow patch reverts back to old method of erase implementation.

Quoted 7 lines
Quoted 2 lines

I guess this never made it into the release, so the SPI NOR erase is broken in v2019.04 ?

I usually review on top of patchwork, that seems not assigned to me. Vignesh will this break? I can see the erase seems fine on my microzed with last week testing.

This issue affects SPI controllers that try to interpret spi_xfer() calls back into cmd+addr+data format instead of just sending dout over the bus as is.
So, it does not all SPI controllers. From a quick look fsl-qspi, renesas_rpc_spi and mtk_qspi maybe affected.

This is a valid fix. Would be great if this patch is part of early pull request

Signature · 2 lines
Regards
Vignesh
#6 lore raw

PATCH 1/1 mtd: spi: Replace ad-hoc default implementation with spi_mem_op

Quoted 45 lines · Vignesh Raghavendra
Quoted 32 lines · Jagan Teki
Quoted 32 lines
Quoted 31 lines
Quoted 21 lines · Marek Vasut
Quoted 11 lines

Replace the ad-hoc erase operation implementation with a simple spi_mem_op implementation of the same functionality. This is a minor optimization and removal of the ad-hoc code.

This however also changes the behavior of the execution of the erase opcode from two separate transfer requests to the SPI NOR driver to one transfer request to the SPI NOR driver. The former was how U-Boot behaved before the SPI NOR framework was imported and the later was introduced by the SPI NOR framework. The former is more optimal, so keep that.

Quoted 7 lines
Cc Horatiu Vultur <[email protected]>
Cc Jagan Teki <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vignesh R <[email protected]>

---

Quoted 6 lines

Marek, thanks for the fix!

Jagan,

Could we get this merged before v2019.04 release as this should fix regression wrt erase reported by Ashish.

Yes, follow patch reverts back to old method of erase implementation.

Quoted 7 lines
Quoted 2 lines

I guess this never made it into the release, so the SPI NOR erase is broken in v2019.04 ?

I usually review on top of patchwork, that seems not assigned to me. Vignesh will this break? I can see the erase seems fine on my microzed with last week testing.

Quoted 8 lines

This issue affects SPI controllers that try to interpret spi_xfer() calls back into cmd+addr+data format instead of just sending dout over the bus as is.
So, it does not all SPI controllers. From a quick look fsl-qspi, renesas_rpc_spi and mtk_qspi maybe affected.

This is a valid fix. Would be great if this patch is part of early pull request

Thanks, re-assigned from patchwork and applied.