Re: [PATCH v6 3/7] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device
"Michael Walle" <[email protected]> Wed, 29 Jul 2026 10:01:59 +0200
| Newsgroups | org.infradead.lists.linux-mtd,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
--===============7165828398680673433==
Content-Type: multipart/signed;
boundary=a369d9f282471ab4613f2d34b9edebaf16481b78715d95de6253cba98872;
micalg=pgp-sha384; protocol="application/pgp-signature"
--a369d9f282471ab4613f2d34b9edebaf16481b78715d95de6253cba98872
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
On Wed Jul 29, 2026 at 6:30 AM CEST, Manikandan Muralidharan wrote:
..
> +static void spi_nor_sfdp_nvmem_put_np(void *data)
> +{
> + of_node_put(data);
> +}
> +
> +/**
> + * 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 d=
evice
> + * rooted at the flash's SFDP child node (compatible "jedec,sfdp"). This=
lets
> + * generic (fixed-layout) or vendor (nvmem-layout) cells reference any S=
FDP
> + * data. The device is only registered when a child node with the "jedec=
,sfdp"
> + * compatible is described in the device tree.
> + *
> + * Return: 0 on success or if there is nothing to do, -errno otherwise.
> + */
> +static int spi_nor_register_sfdp_nvmem(struct spi_nor *nor)
> +{
> + struct device *dev =3D nor->dev;
> + struct nvmem_config config =3D { };
> + struct nvmem_device *nvmem;
> + struct device_node *np;
> + int ret;
> +
> + if (!nor->sfdp)
> + return 0;
> +
> + np =3D of_get_compatible_child(dev_of_node(dev), "jedec,sfdp");
> + if (!np)
> + return 0;
> +
> + /*
> + * Register the put before devm_nvmem_register() so it runs last on
> + * detach, after the NVMEM device that uses the node is gone.
> + */
> + ret =3D devm_add_action_or_reset(dev, spi_nor_sfdp_nvmem_put_np, np);
> + if (ret)
> + return ret;
Sorry I've missed that in the previous version. I guess we do that
because we hand the device_node to nvmem. But shouldn't it be part
of the NVMEM framework to do a of_node_get()?
> +
> + config.dev =3D dev;
> + config.of_node =3D np;
> + config.name =3D "sfdp";
> + config.id =3D NVMEM_DEVID_AUTO;
> + config.owner =3D THIS_MODULE;
> + config.read_only =3D true;
> + config.word_size =3D 1;
> + config.stride =3D 1;
> + config.size =3D (int)(nor->sfdp->num_dwords * sizeof(*nor->sfdp->dwords=
));
> + config.reg_read =3D spi_nor_sfdp_reg_read;
> + config.priv =3D nor;
> +
> + nvmem =3D devm_nvmem_register(dev, &config);
> + if (IS_ERR(nvmem)) {
> + /* NVMEM support is optional. */
> + if (PTR_ERR(nvmem) =3D=3D -EOPNOTSUPP)
> + return 0;
> + return dev_err_probe(dev, PTR_ERR(nvmem),
> + "failed to register SFDP NVMEM device\n");
> + }
> +
so we can do a of_node_put() here?
-michael
> + dev_dbg(dev, "exposed %d-byte SFDP as an NVMEM device\n", config.size);
> +
> + return 0;
> +}
> +
--a369d9f282471ab4613f2d34b9edebaf16481b78715d95de6253cba98872
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iKgEABMJADAWIQTIVZIcOo5wfU/AngkSJzzuPgIf+AUCammzdxIcbXdhbGxlQGtl
cm5lbC5vcmcACgkQEic87j4CH/it6gF/V3GubkwpHoS9P9IU244sBsKtytRavuvh
hXPhPMqXriH2cB1f70x+LBiHYBye74L+AYDkK5z86ahoo8Muf+vFJGWwpFHZziaa
0bbnosqgeVloCl0urxpv75kT0JbgJEHN8es=
=fp/9
-----END PGP SIGNATURE-----
--a369d9f282471ab4613f2d34b9edebaf16481b78715d95de6253cba98872--
--===============7165828398680673433==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
--===============7165828398680673433==--