[PATCH v4 3/7] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device

Linus Walleij linusw at kernel.org
Tue Jun 30 15:25:19 PDT 2026


Hi Manikandan,

thanks for your patch!

On Tue, Jun 30, 2026 at 11:25 AM Manikandan Muralidharan
<manikandan.m at microchip.com> wrote:

> Register the cached SFDP as a read-only NVMEM device rooted at the
> flash's "sfdp" child node, exposing it in on-flash byte order. This lets
> NVMEM cells reference any SFDP data: a fixed-layout for parameters at a
> known offset, or an nvmem-layout parser for vendor data whose location
> must be discovered at runtime. The device is only registered when an
> "sfdp" node is present in the device tree.

It seems the existing serial NOR driver core already reads out the SFDP
and stores it in  nor->sfdp->dwords, right?

This should be mentioned in the commit so we know when the stuff
is actually read in from the flash memory.

>
> Signed-off-by: Manikandan Muralidharan <manikandan.m at microchip.com>
(...)

> @@ -3204,6 +3204,11 @@ static int spi_nor_init_params(struct spi_nor *nor)
>                 spi_nor_init_params_deprecated(nor);
>         }
>
> +       /* Expose the SFDP as an NVMEM device. */

Add "if and only if the flash has an SFDP"

> +static int spi_nor_sfdp_nvmem_read(void *priv, unsigned int offset,
> +                                  void *val, size_t bytes)

Name it _reg_read() to mirror the nvmem prototype.

> +/**
> + * spi_nor_register_sfdp_nvmem() - expose the SFDP as a read-only NVMEM device
> + * @nor:       pointer to a 'struct spi_nor'
> + *
> + * Expose the whole SFDP, in on-flash byte order, as a read-only NVMEM device
> + * rooted at the flash's "sfdp" child node. This lets generic (fixed-layout) or
> + * vendor (nvmem-layout) cells reference any SFDP data. The device is only
> + * registered when an "sfdp" node is described in the device tree.
> + *
> + * Return: 0 on success or if there is nothing to do, -errno otherwise.
> + */
> +int spi_nor_register_sfdp_nvmem(struct spi_nor *nor)
> +{
> +       struct device *dev = nor->dev;
> +       struct nvmem_config config = { };
> +       struct nvmem_device *nvmem;
> +       struct device_node *np;
> +       int ret;
> +
> +       if (!nor->sfdp)
> +               return 0;
> +
> +       np = of_get_child_by_name(dev_of_node(dev), "sfdp");
> +       if (!np)
> +               return 0;

If this node name is required to be named like that it has to be
enforced in the schema.

I would instead check all the nodes (for_each_available_child)
for the right compatible "jedec,sfdp".

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list