mtd: spi-nor: Respect flash's hwcaps in spi_nor_adjust_hwcaps()
PATCH 1/2 mtd: spi-nor: Respect flash's hwcaps in spi_nor_adjust_hwcaps()
The smart spi_nor_adjust_hwcaps() does not respect the SPI flash's hwcaps, and only looks to the controller on what can be supported.
The flash's hwcaps needs to be AND'ed before checking.
---
drivers/mtd/spi/spi-nor-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi/spi-nor-core.c +1 -1
@@ -2861,7 +2861,7 @@ spi_nor_adjust_hwcaps(struct spi_nor *nor,* Enable all caps by default. We will mask them after checking what's * really supported using spi_mem_supports_op(). */ - *hwcaps =SNOR_HWCAPS_ALL ; + *hwcaps =SNOR_HWCAPS_ALL & params->hwcaps.mask;/* X-X-X modes are not supported yet, mask them all. */ *hwcaps &= ~SNOR_HWCAPS_X_X_X ;
Signature · 1 line
2.25.1
PATCH 2/2 mtd: spi-nor: Mask out fast read if not requested in DT
The DT bindings of "jedec,spi-nor" [1] defines "m25p,fast-read" property to indicate that "fast read" opcode can be used to read data from the chip instead of the usual "read" opcode.
If this property is not present in DT, mask out fast read in spi_nor_init_params(). This change mirrors the same logic in spi_nor_info_init_params() in drivers/mtd/spi-nor/core.c in the Linux kernel v5.14-rc3.
[1] Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml in the kernel tree
---
drivers/mtd/spi/spi-nor-core.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi-nor-core.c +12 -3
@@ -2597,6 +2597,8 @@ static int spi_nor_init_params(struct spi_nor *nor,const struct flash_info *info, struct spi_nor_flash_parameter *params) { + struct spi_slave *spi = nor->spi; +/* Set legacy flash parameters as default. */ memset (params,0 ,sizeof (*params));
@@ -2604,18 +2606,25 @@ static int spi_nor_init_params(struct spi_nor *nor, params->size = 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 (!ofnode_read_bool (dev_ofnode (spi->dev),"m25p,fast-read" )) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST ; + } +/* (Fast) Read settings. */ params->hwcaps.mask |=SNOR_HWCAPS_READ ;spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ ],0 ,0 ,SPINOR_OP_READ ,SNOR_PROTO_1_1_1 ); -if (!(info->flags &SPI_NOR_NO_FR )) { - params->hwcaps.mask |=SNOR_HWCAPS_READ_FAST ; +if (params->hwcaps.mask &SNOR_HWCAPS_READ_FAST )spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_FAST ],0 ,8 ,SPINOR_OP_READ_FAST ,SNOR_PROTO_1_1_1 ); - }if (info->flags &SPI_NOR_DUAL_READ ) { params->hwcaps.mask |=SNOR_HWCAPS_READ_1_1_2 ;
Signature · 1 line
2.25.1
Re: [PATCH 2/2] mtd: spi-nor: Mask out fast read if not requested in DT
Hi Bin,
Quoted 31 lines · Bin Meng
The DT bindings of "jedec,spi-nor" [1] defines "m25p,fast-read" property to indicate that "fast read" opcode can be used to read data from the chip instead of the usual "read" opcode.
If this property is not present in DT, mask out fast read in
spi_nor_init_params(). This change mirrors the same logic inspi_nor_info_init_params()indrivers/mtd/spi-nor/core.cin the Linux kernel v5.14-rc3.[1]
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yamlin the kernel treeSigned-off-by Bin Meng <[email protected]>---
drivers/mtd/spi/spi-nor-core.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/mtd/spi/spi-nor-core.c +2
-0@@ -2597,6 +2597,8 @@ static int spi_nor_init_params(struct spi_nor *nor,const struct flash_info *info, struct spi_nor_flash_parameter *params) { + struct spi_slave *spi = nor->spi; +/* Set legacy flash parameters as default. */ memset (params,0 ,sizeof (*params));
drivers/mtd/spi/spi-nor-core.c static int spi_nor_init_params(struct spi_nor *nor, · line 2614
Quoted 9 lines
drivers/mtd/spi/spi-nor-core.c +6
-0@@ -2604,18 +2606,25 @@ static int spi_nor_init_params(struct spi_nor *nor, params->size = 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 (!ofnode_read_bool (dev_ofnode (spi->dev),"m25p,fast-read" ))
Do you need to check if dev_ofnode() is valid? Can spi-nor be instantiated from a non-DT platform (like platdata maybe)? I am not very familiar with DT/platdata stuff, other than the basics.
Quoted 6 lines
drivers/mtd/spi/spi-nor-core.c +3
-0+ params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST ; + } +/* (Fast) Read settings. */ params->hwcaps.mask |=SNOR_HWCAPS_READ ; spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ],
drivers/mtd/spi/spi-nor-core.c static int spi_nor_init_params(struct spi_nor *nor, · line 2618
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +1
-30 ,0 ,SPINOR_OP_READ , SNOR_PROTO_1_1_1); -if (!(info->flags &SPI_NOR_NO_FR )) { - params->hwcaps.mask |=SNOR_HWCAPS_READ_FAST ; +if (params->hwcaps.mask &SNOR_HWCAPS_READ_FAST )spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_FAST ],0 ,8 ,SPINOR_OP_READ_FAST ,SNOR_PROTO_1_1_1 ); - }
The patch looks good to me other than the point above.
Quoted 6 lines
drivers/mtd/spi/spi-nor-core.c +0
-0if (info->flags &SPI_NOR_DUAL_READ ) { params->hwcaps.mask |=SNOR_HWCAPS_READ_1_1_2 ;Signature · 1 line
2.25.1
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Hi Bin,
Quoted 17 lines · Bin Meng
The smart
spi_nor_adjust_hwcaps()does not respect the SPI flash's hwcaps, and only looks to the controller on what can be supported.The flash's hwcaps needs to be AND'ed before checking.
Fixes 71025f013ccb ("mtd: spi-nor-core: Rework hwcaps selection")Signed-off-by Bin Meng <[email protected]>---
drivers/mtd/spi/spi-nor-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi/spi-nor-core.c +0
-0
drivers/mtd/spi/spi-nor-core.c spi_nor_adjust_hwcaps(struct spi_nor *nor, · line 2863
Quoted 3 lines
drivers/mtd/spi/spi-nor-core.c +0
-0@@ -2861,7 +2861,7 @@ spi_nor_adjust_hwcaps(struct spi_nor *nor,* Enable all caps by default. We will mask them after checking what's * really supported using spi_mem_supports_op(). */
Please update the comment above. Maybe:
Start by assuming the controller supports every cap. We will mask them...
drivers/mtd/spi/spi-nor-core.c spi_nor_adjust_hwcaps(struct spi_nor *nor, · line 2864
Quoted 2 lines
drivers/mtd/spi/spi-nor-core.c +1
-1- *hwcaps =SNOR_HWCAPS_ALL ; + *hwcaps =SNOR_HWCAPS_ALL & params->hwcaps.mask;
This is practically equivalent to *hwcaps = params->hwcaps.mask but I think having SNOR_HWCAPS_ALL here to signify that we are assuming controller supports everything is not a bad idea IMO.
With the above comment updated,
Thanks.
Quoted 6 lines
drivers/mtd/spi/spi-nor-core.c +0
-0/* X-X-X modes are not supported yet, mask them all. */ *hwcaps &= ~SNOR_HWCAPS_X_X_X ;Signature · 1 line
2.25.1
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Hi Pratyush,
Quoted 33 lines · Pratyush Yadav
Hi Bin,
Quoted 17 lines · Bin Meng
The smart
spi_nor_adjust_hwcaps()does not respect the SPI flash's hwcaps, and only looks to the controller on what can be supported.The flash's hwcaps needs to be AND'ed before checking.
Fixes 71025f013ccb ("mtd: spi-nor-core: Rework hwcaps selection")Signed-off-by Bin Meng <[email protected]>---
drivers/mtd/spi/spi-nor-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mtd/spi/spi-nor-core.c +0
-0drivers/mtd/spi/spi-nor-core.c spi_nor_adjust_hwcaps(struct spi_nor *nor, · line 2863
Quoted 3 lines
drivers/mtd/spi/spi-nor-core.c +0
-0@@ -2861,7 +2861,7 @@ spi_nor_adjust_hwcaps(struct spi_nor *nor,* Enable all caps by default. We will mask them after checking what's * really supported using spi_mem_supports_op(). */ Please update the comment above. Maybe:
Start by assuming the controller supports every cap. We will mask them...
drivers/mtd/spi/spi-nor-core.c spi_nor_adjust_hwcaps(struct spi_nor *nor, · line 2864
Quoted 2 lines
drivers/mtd/spi/spi-nor-core.c +1
-1- *hwcaps =SNOR_HWCAPS_ALL ; + *hwcaps =SNOR_HWCAPS_ALL & params->hwcaps.mask;
Quoted 8 lines
This is practically equivalent to *hwcaps =
params->hwcaps.maskbut I think havingSNOR_HWCAPS_ALLhere to signify that we are assuming controller supports everything is not a bad idea IMO.With the above comment updated,
Reviewed-by Pratyush Yadav <[email protected]>
Thanks for the review! Will update comments in v2.
Regards,
Bin