mtd: spi-nor: core: Discard HW capabilities if no enable function
Subsystems (2)
PATCH 1/1 mtd: spi-nor: core: Discard HW capabilities if no enable function
From: JaimeLiao <[email protected]>
Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.
--- drivers/mtd/spi-nor/core.c | 13 +++++++------ include/linux/mtd/spi-nor.h | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/mtd/spi-nor/core.c +7 -6
@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor *nor,*/ shared_mask = hwcaps->mask & params->hwcaps.mask; +/* Mask out Octal DTR if no enable function */ +if (!params->set_octal_dtr) + shared_mask &= ~SNOR_HWCAPS_X_X_X_DTR ; + +if (!params->quad_enable) + shared_mask &= ~SNOR_HWCAPS_4_4_4 ; +if (nor->spimem) {/* * When called from spi_nor_probe(), all caps are set and we
@@ -3093,9 +3100,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) {int ret; -if (!nor->params->set_octal_dtr) -return 0 ; -if (!(nor->read_proto ==SNOR_PROTO_8_8_8_DTR && nor->write_proto ==SNOR_PROTO_8_8_8_DTR ))return 0 ;
@@ -3123,9 +3127,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable)*/ static int spi_nor_quad_enable (struct spi_nor *nor) { -if (!nor->params->quad_enable) -return 0 ; -if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 ||spi_nor_get_protocol_width (nor->write_proto) ==4 ))return 0 ;
include/linux/mtd/spi-nor.h +3 -0
@@ -266,6 +266,9 @@ struct spi_nor_hwcaps {#define SNOR_HWCAPS_PP_8_8_8 BIT(22)#define SNOR_HWCAPS_PP_8_8_8_DTR BIT(23) +#define SNOR_HWCAPS_4_4_4 (SNOR_HWCAPS_READ_4_4_4 | \ + SNOR_HWCAPS_PP_4_4_4) +#define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \ SNOR_HWCAPS_READ_4_4_4 | \ SNOR_HWCAPS_READ_8_8_8 | \
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi,
Quoted 14 lines
Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.
Signed-off-by JaimeLiao <[email protected]>--- drivers/mtd/spi-nor/core.c | 13 +++++++------ include/linux/mtd/spi-nor.h | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-)drivers/mtd/spi-nor/core.c +0
-0
drivers/mtd/spi-nor/core.c static int spi_nor_default_setup(struct spi_nor · line 2627
Quoted 7 lines
drivers/mtd/spi-nor/core.c +3
-0@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor*nor, */ shared_mask = hwcaps->mask & params->hwcaps.mask; +/* Mask out Octal DTR if no enable function */ +if (!params->set_octal_dtr) + shared_mask &= ~SNOR_HWCAPS_X_X_X_DTR ;
please also create a new SNOR_HWCAPS_8_8_8_DTR. While this is the same for now, I suspect the SNOR_HWCAPS_X_X_X_DTR is might also carry the 2_2_2_DTR and 4_4_4_DTR flags, just like SNOR_HWCAPS_X_X_X. In any case, it's easier to read and more consistent with the code below if you use SNOR_HWCAPS_8_8_8_DTR.
Quoted 8 lines
drivers/mtd/spi-nor/core.c +4
-0+ +if (!params->quad_enable) + shared_mask &= ~SNOR_HWCAPS_4_4_4 ; +if (nor->spimem) {/* drivers/mtd/spi-nor/core.c +0
-0* When called from spi_nor_probe(), all caps are set and we
drivers/mtd/spi-nor/core.c static int spi_nor_set_octal_dtr(struct spi_nor · line 3099
Quoted 7 lines
drivers/mtd/spi-nor/core.c +0
-3@@ -3093,9 +3100,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) {int ret; -if (!nor->params->set_octal_dtr) -return 0 ; -
I'd keep these checks, just in case.
drivers/mtd/spi-nor/core.c static int spi_nor_set_octal_dtr(struct spi_nor · line 3129
Quoted 11 lines
drivers/mtd/spi-nor/core.c +0
-0if (!(nor->read_proto ==SNOR_PROTO_8_8_8_DTR && nor->write_proto ==SNOR_PROTO_8_8_8_DTR ))drivers/mtd/spi-nor/core.c +0
-3return 0 ;@@ -3123,9 +3127,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor*nor, bool enable) */ static int spi_nor_quad_enable (struct spi_nor *nor) { -if (!nor->params->quad_enable) -return 0 ; -
same here.
Otherwise looks good.
-michael
Quoted 8 lines
drivers/mtd/spi-nor/core.c +0
-0if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 ||spi_nor_get_protocol_width (nor->write_proto) ==4 ))drivers/mtd/spi-nor/core.c +0
-0return 0 ;include/linux/mtd/spi-nor.h +0
-0
include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 274
Quoted 9 lines
include/linux/mtd/spi-nor.h +3
-0@@ -266,6 +266,9 @@ struct spi_nor_hwcaps {#define SNOR_HWCAPS_PP_8_8_8 BIT(22)#define SNOR_HWCAPS_PP_8_8_8_DTR BIT(23) +#define SNOR_HWCAPS_4_4_4 (SNOR_HWCAPS_READ_4_4_4 | \ + SNOR_HWCAPS_PP_4_4_4) +#define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \ SNOR_HWCAPS_READ_4_4_4 | \ SNOR_HWCAPS_READ_8_8_8 | \
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi Michael
Quoted 21 lines
Hi,
Quoted 18 lines
Discard corresponding HW capabilities to prevent carrying the wrong protocol if no QUAD/Octal DTR enable function hooked.
Signed-off-by JaimeLiao <[email protected]>--- drivers/mtd/spi-nor/core.c | 13 +++++++------ include/linux/mtd/spi-nor.h | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-)drivers/mtd/spi-nor/core.c +0
-0@@ -2621,6 +2621,13 @@ static int spi_nor_default_setup(struct spi_nor*nor, */ shared_mask = hwcaps->mask & params->hwcaps.mask;
Quoted 9 lines
drivers/mtd/spi-nor/core.c static int spi_nor_default_setup(struct spi_nor *nor, · line 2626
Quoted 3 lines
drivers/mtd/spi-nor/core.c +3
-0+/* Mask out Octal DTR if no enable function */ +if (!params->set_octal_dtr) + shared_mask &= ~SNOR_HWCAPS_X_X_X_DTR ;please also create a new
SNOR_HWCAPS_8_8_8_DTR. While this is the same for now, I suspect theSNOR_HWCAPS_X_X_X_DTRis might also carry the 2_2_2_DTR and 4_4_4_DTR flags, just likeSNOR_HWCAPS_X_X_X. In any case, it's easier to read and more consistent with the code below if you useSNOR_HWCAPS_8_8_8_DTR.
Got it.
I will prepare the next version.
Quoted 13 lines
Quoted 13 lines
drivers/mtd/spi-nor/core.c +4
-0+ +if (!params->quad_enable) + shared_mask &= ~SNOR_HWCAPS_4_4_4 ; +if (nor->spimem) {/* * When called from
spi_nor_probe(), all caps are set and wedrivers/mtd/spi-nor/core.c +0
-0@@ -3093,9 +3100,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) {int ret;
Quoted 5 lines
drivers/mtd/spi-nor/core.c static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) · line 3098
Quoted 3 lines
drivers/mtd/spi-nor/core.c +0
-3-if (!nor->params->set_octal_dtr) -return 0 ; -I'd keep these checks, just in case.
OK
Quoted 14 lines
drivers/mtd/spi-nor/core.c static int spi_nor_set_octal_dtr(struct spi_nor · line 3129
Quoted 12 lines
drivers/mtd/spi-nor/core.c +0
-0if (!(nor->read_proto ==SNOR_PROTO_8_8_8_DTR && nor->write_proto ==SNOR_PROTO_8_8_8_DTR ))return 0;drivers/mtd/spi-nor/core.c +0
-3@@ -3123,9 +3127,6 @@ static int spi_nor_set_octal_dtr(struct spi_nor*nor, bool enable) */ static int spi_nor_quad_enable (struct spi_nor *nor) { -if (!nor->params->quad_enable) -return 0 ; -same here.
OK
Quoted 16 lines
Otherwise looks good.
-michael
Quoted 11 lines
drivers/mtd/spi-nor/core.c +0
-0if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 ||spi_nor_get_protocol_width (nor->write_proto) ==4 ))return 0;include/linux/mtd/spi-nor.h +0
-0@@ -266,6 +266,9 @@ struct spi_nor_hwcaps {#define SNOR_HWCAPS_PP_8_8_8 BIT(22)#define SNOR_HWCAPS_PP_8_8_8_DTR BIT(23)
Quoted 6 lines
include/linux/mtd/spi-nor.h struct spi_nor_hwcaps { · line 274
Quoted 6 lines
include/linux/mtd/spi-nor.h +3
-0+#define SNOR_HWCAPS_4_4_4 (SNOR_HWCAPS_READ_4_4_4 | \ + SNOR_HWCAPS_PP_4_4_4) +#define SNOR_HWCAPS_X_X_X (SNOR_HWCAPS_READ_2_2_2 | \ SNOR_HWCAPS_READ_4_4_4 | \ SNOR_HWCAPS_READ_8_8_8 | \
Thanks
Jaime
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/