From: Biju Das <biju.das.jz@bp.renesas.com>
To: michael@walle.cc
Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
miquel.raynal@bootlin.com, p.yadav@ti.com, richard@nod.at,
tudor.ambarus@microchip.com, vigneshr@ti.com
Subject: Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
Date: Thu, 21 Jul 2022 10:32:16 +0100 [thread overview]
Message-ID: <202205132220.uRTFaqNA-lkp@intel.com> (raw) (raw)
Message-ID: <20220721093216.ZjX_zjDkJZMtmnR28nTDJ9N1o8EEFvo9ONrim9KYd5I@z> (raw)
In-Reply-To: <20220513133520.3945820-6-michael@walle.cc>
> Our SFDP is parsing is everything we need to support all basic operations of
> a flash device. If the flash isn't found in our in-kernel flash database,
> gracefully fall back to a driver described solely by its SFDP tables.
>
> It is still recommended to add the flash to the in-kernel database.
> First, we get a proper partname and secondly, for all features not described
> by the SFDP like OTP we need the entry anyway.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
> drivers/mtd/spi-nor/core.c | 13 +++++++++++++ drivers/mtd/spi-nor/core.h |
> 1 + drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
> 3 files changed, 41 insertions(+)
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index
> 65cd8e668579..ee193a61310a 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1632,6 +1632,11 @@ static const struct spi_nor_manufacturer
> *manufacturers[] = {
> &spi_nor_xmc,
> };
>
> +static const struct flash_info spi_nor_generic_flash = {
> + .name = "spi-nor-generic",
> + .parse_sfdp = true,
> +};
> +
> static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
> const u8 *id)
> {
> @@ -1670,6 +1675,14 @@ static const struct flash_info *spi_nor_detect(struct
> spi_nor *nor)
> return ERR_PTR(-ENOMEM);
>
> info = spi_nor_match_id(nor, id);
> +
> + /* Fallback to a generic flash described only by its SFDP data. */
> + if (!info) {
> + ret = spi_nor_check_sfdp_signature(nor);
> + if (!ret)
> + info = &spi_nor_generic_flash;
> + }
May be this can be combined as
if (!info && (!spi_nor_check_sfdp_signature(nor)))
info = &spi_nor_generic_flash;
Cheers,
Biju
> if (!info) {
> dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
> SPI_NOR_MAX_ID_LEN, id);
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index
> 153cb4b174ee..b084cb6db401 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -703,6 +703,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor,
> u8 opcode, int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8
> opcode,
> const u8 *buf, size_t len);
>
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor);
> int spi_nor_parse_sfdp(struct spi_nor *nor);
>
> static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) diff --
> git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index
> a5211543d30d..9bdb3d5dc7e8 100644
> --- a/drivers/mtd/spi-nor/sfdp.c
> +++ b/drivers/mtd/spi-nor/sfdp.c
> @@ -1247,6 +1247,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor
> *nor)
> nor->info->fixups->post_sfdp(nor);
> }
>
> +/**
> + * spi_nor_check_sfdp_header() - check for a valid SFDP header
> + * @nor: pointer to a 'struct spi_nor'
> + *
> + * Used to detect if the flash supports the RDSFDP command as well as
> +the
> + * presence of a valid SFDP table.
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor) {
> + u32 signature;
> + int err;
> +
> + /* Get the SFDP header. */
> + err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
> + &signature);
> + if (err < 0)
> + return err;
> +
> + /* Check the SFDP signature. */
> + if (le32_to_cpu(signature) != SFDP_SIGNATURE)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> /**
> * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
> * @nor: pointer to a 'struct spi_nor'
> --
> 2.25.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2022-07-21 9:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
2022-07-26 10:00 ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
2022-07-26 10:04 ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
2022-07-29 1:00 ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
2022-07-26 23:41 ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
2022-05-13 14:47 ` kernel test robot [this message]
2022-07-21 9:32 ` Biju Das
2022-07-21 9:48 ` Michael Walle
2022-07-21 9:52 ` Biju Das
2022-10-28 18:00 ` Biju Das
2022-07-28 3:28 ` Tudor.Ambarus
2022-07-29 1:40 ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
2022-07-29 1:25 ` Takahiro Kuwano
2022-07-26 8:06 ` [PATCH 0/6] mtd: spi-nor: " Tudor.Ambarus
2022-07-29 1:52 ` Takahiro Kuwano
2022-07-29 5:34 ` Tudor.Ambarus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202205132220.uRTFaqNA-lkp@intel.com \
--to=biju.das.jz@bp.renesas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=miquel.raynal@bootlin.com \
--cc=p.yadav@ti.com \
--cc=richard@nod.at \
--cc=tudor.ambarus@microchip.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).