mtd: spi-nor: Respect flash's hwcaps in spi_nor_adjust_hwcaps()
PATCH v2 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.
---
Changes in v2:
- Update comments per Pratyush's review
drivers/mtd/spi/spi-nor-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi-nor-core.c +4 -3
@@ -2858,10 +2858,11 @@ spi_nor_adjust_hwcaps(struct spi_nor *nor,unsigned int cap;/* -* Enable all caps by default. We will mask them after checking what's -* really supported using spi_mem_supports_op(). +* Start by assuming the controller supports every capability. +* 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 v2 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
---
Changes in v2:
- Guard changes with CONFIG_IS_ENABLED(DM_SPI)
drivers/mtd/spi/spi-nor-core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/mtd/spi/spi-nor-core.c +13 -3
@@ -2604,18 +2604,28 @@ 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 CONFIG_IS_ENABLED (DM_SPI ) +if (!ofnode_read_bool (dev_ofnode (nor->spi->dev), +"m25p,fast-read" )) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST ; +#endif + } +/* (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 v2 2/2] mtd: spi-nor: Mask out fast read if not requested in DT
Quoted 9 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.
Quoted 8 lines
[1]
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yamlin the kernel treeSigned-off-by Bin Meng <[email protected]>---
Changes in v2:
- Guard changes withCONFIG_IS_ENABLED(DM_SPI)
Hehe, I just commented about this on your v1, and I see the v2 in my inbox already ;-)
So this will make sure that dev_ofnode() will be valid, right?
Quoted 9 lines
drivers/mtd/spi/spi-nor-core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)drivers/mtd/spi/spi-nor-core.c +0
-0
drivers/mtd/spi/spi-nor-core.c static int spi_nor_init_params(struct spi_nor *nor, · line 2613
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +7
-0@@ -2604,18 +2604,28 @@ 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 CONFIG_IS_ENABLED(DM_SPI) + if (!ofnode_read_bool(dev_ofnode(nor->spi->dev),
Let's avoid the #if here and do
if (CONFIG_IS_ENABLED(DM_SPI) && !ofnode_read_bool())
Quoted 21 lines
drivers/mtd/spi/spi-nor-core.c +6
-3+ "m25p,fast-read")) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST ; +#endif + } +/* (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 · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v2 2/2] mtd: spi-nor: Mask out fast read if not requested in DT
Hi Pratyush,
Quoted 17 lines · Pratyush Yadav
Quoted 15 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]>---
Quoted 7 lines
Quoted 2 lines
Changes in v2:
- Guard changes withCONFIG_IS_ENABLED(DM_SPI)Hehe, I just commented about this on your v1, and I see the v2 in my inbox already ;-)
So this will make sure that
dev_ofnode()will be valid, right?
This is to avoid build error for non-DM_SPI platforms.
For dev_ofnode() I think it's always valid, as spi_nor_init_params() is called by spi_nor_scan() in sf_probe.c which does not support OF_PLATDATA.
Quoted 23 lines
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)drivers/mtd/spi/spi-nor-core.c +0
-0drivers/mtd/spi/spi-nor-core.c static int spi_nor_init_params(struct spi_nor *nor, · line 2613
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +7
-0@@ -2604,18 +2604,28 @@ 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 CONFIG_IS_ENABLED(DM_SPI) + if (!ofnode_read_bool(dev_ofnode(nor->spi->dev),Let's avoid the #if here and do
Quoted 1 line
if (CONFIG_IS_ENABLED(DM_SPI) && !ofnode_read_bool())
This does not work because nor->spi->dev has to be inside CONFIG_IS_ENABLED(DM_SPI) as well.
Quoted 20 lines
Quoted 20 lines
drivers/mtd/spi/spi-nor-core.c +6
-3+ "m25p,fast-read")) + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST ; +#endif + } +/* (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 ); - }
Quoted 3 lines
drivers/mtd/spi/spi-nor-core.c static int spi_nor_init_params(struct spi_nor *nor, · line 2631
Quoted 2 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 ;
Regards,
Bin
Quoted 11 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]>Reviewed-by Pratyush Yadav <[email protected]>---
Applied to u-boot-spi/master
Re: [PATCH v2 2/2] mtd: spi-nor: Mask out fast read if not requested in DT
In reply to Bin MengQuoted 5 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.
Quoted 8 lines
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]>
Applied to u-boot-spi/master