2022-04-12 22:03:58

by Tudor Ambarus

[permalink] [raw]
Subject: [PATCH v3 0/9] mtd: spi-nor: Rework Octal DTR methods

v3:
- queue patch: "mtd: spi-nor: Introduce templates for SPI NOR operations"
from
https://lore.kernel.org/lkml/[email protected]/
The dependancy chain between patches was too long and hard to follow.

- Rework patch "mtd: spi-nor: core: Use auto-detection only once"
according to Pratyush's and Michael's suggestions
- Remove dev_dbg messge from spi_nor_read_id() method and let the callers
use their own message (detection, octal dtr enable/disable)
- detailed version changes in each patch

v2:
- Fix bug on octal dtr disable, s/nor->reg_proto/SNOR_PROTO_1_1_1,
because after disable the nor->proto is not yet updated
- update function/macros names to comply with Michael's rename series.

Tudor Ambarus (9):
mtd: spi-nor: Rename method, s/spi_nor_match_id/spi_nor_match_name
mtd: spi-nor: Introduce spi_nor_match_id()
mtd: spi-nor: core: Use auto-detection only once
mtd: spi-nor: core: Introduce method for RDID op
mtd: spi-nor: manufacturers: Use spi_nor_read_id() core method
mtd: spi-nor: core: Add helpers to read/write any register
mtd: spi-nor: micron-st: Rework spi_nor_micron_octal_dtr_enable()
mtd: spi-nor: spansion: Rework spi_nor_cypress_octal_dtr_enable()
mtd: spi-nor: Introduce templates for SPI NOR operations

drivers/mtd/spi-nor/core.c | 249 ++++++++++++++++----------------
drivers/mtd/spi-nor/core.h | 115 +++++++++++++++
drivers/mtd/spi-nor/micron-st.c | 142 +++++++++---------
drivers/mtd/spi-nor/spansion.c | 161 +++++++++++----------
drivers/mtd/spi-nor/xilinx.c | 12 +-
5 files changed, 405 insertions(+), 274 deletions(-)

--
2.25.1


2022-04-12 22:24:09

by Tudor Ambarus

[permalink] [raw]
Subject: [PATCH v3 3/9] mtd: spi-nor: core: Use auto-detection only once

In case spi_nor_match_name() returned NULL, the auto detection was
issued twice. There's no reason to try to detect the same chip twice,
do the auto detection only once.

Signed-off-by: Tudor Ambarus <[email protected]>
---
v3:
- caller of spi_nor_get_flash_info now handles NULL and translates it to
ENOENT.

drivers/mtd/spi-nor/core.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index b9cc8bbf1f62..b55d922d46dd 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2896,13 +2896,14 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
{
const struct flash_info *info = NULL;

- if (name)
+ if (name) {
info = spi_nor_match_name(nor, name);
+ if (IS_ERR(info))
+ return info;
+ }
/* Try to auto-detect if chip name wasn't specified or not found */
if (!info)
- info = spi_nor_read_id(nor);
- if (IS_ERR_OR_NULL(info))
- return ERR_PTR(-ENOENT);
+ return spi_nor_read_id(nor);

/*
* If caller has specified name of flash model that can normally be
@@ -2994,7 +2995,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
return -ENOMEM;

info = spi_nor_get_flash_info(nor, name);
- if (IS_ERR(info))
+ if (!info)
+ return -ENOENT;
+ else if (IS_ERR(info))
return PTR_ERR(info);

nor->info = info;
--
2.25.1

2022-04-22 19:19:34

by Michael Walle

[permalink] [raw]
Subject: Re: [PATCH v3 3/9] mtd: spi-nor: core: Use auto-detection only once

Am 2022-04-11 11:10, schrieb Tudor Ambarus:
> In case spi_nor_match_name() returned NULL, the auto detection was
> issued twice. There's no reason to try to detect the same chip twice,
> do the auto detection only once.
>
> Signed-off-by: Tudor Ambarus <[email protected]>
> ---
> v3:
> - caller of spi_nor_get_flash_info now handles NULL and translates it
> to
> ENOENT.
>
> drivers/mtd/spi-nor/core.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index b9cc8bbf1f62..b55d922d46dd 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2896,13 +2896,14 @@ static const struct flash_info
> *spi_nor_get_flash_info(struct spi_nor *nor,
> {
> const struct flash_info *info = NULL;
>
> - if (name)
> + if (name) {
> info = spi_nor_match_name(nor, name);
> + if (IS_ERR(info))
> + return info;
> + }

That is unnecessary, as spi_nor_match_name() doesn't
return an error code, just NULL or a valid pointer.

Apart from that:
Reviewed-by: Michael Walle <[email protected]>

> /* Try to auto-detect if chip name wasn't specified or not found */
> if (!info)
> - info = spi_nor_read_id(nor);
> - if (IS_ERR_OR_NULL(info))
> - return ERR_PTR(-ENOENT);
> + return spi_nor_read_id(nor);
>
> /*
> * If caller has specified name of flash model that can normally be
> @@ -2994,7 +2995,9 @@ int spi_nor_scan(struct spi_nor *nor, const char
> *name,
> return -ENOMEM;
>
> info = spi_nor_get_flash_info(nor, name);
> - if (IS_ERR(info))
> + if (!info)
> + return -ENOENT;
> + else if (IS_ERR(info))
> return PTR_ERR(info);
>
> nor->info = info;