From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Sascha Hauer <sha@pengutronix.de>
Cc: "Rafał Miłecki" <zajec5@gmail.com>,
"Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
"Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Tom Rini" <trini@konsulko.com>,
"Ahmad Fatoum" <a.fatoum@pengutronix.de>,
linux-arm-kernel@lists.infradead.org, u-boot@lists.denx.de,
devicetree@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org, "Rafał Miłecki" <rafal@milecki.pl>
Subject: Re: [PATCH V3 2/2] nvmem: add driver handling U-Boot environment variables
Date: Tue, 14 Jun 2022 11:02:30 +0200 [thread overview]
Message-ID: <20220614110230.46fab506@xps-13> (raw)
In-Reply-To: <20220614074657.GQ2387@pengutronix.de>
Hello,
> > +static int u_boot_env_probe(struct platform_device *pdev)
> > +{
> > + struct nvmem_config config = {
> > + .name = "u-boot-env",
> > + .reg_read = u_boot_env_read,
> > + };
> > + struct device *dev = &pdev->dev;
> > + struct device_node *np = dev->of_node;
> > + const struct of_device_id *of_id;
> > + struct u_boot_env *priv;
> > + int err;
> > +
> > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > + if (!priv)
> > + return -ENOMEM;
> > + priv->dev = dev;
> > +
> > + of_id = of_match_device(u_boot_env_of_match_table, dev);
> > + if (!of_id)
> > + return -EINVAL;
> > + priv->format = (uintptr_t)of_id->data;
> > +
> > + if (of_property_read_u32(np, "reg", (u32 *)&priv->offset) ||
> > + of_property_read_u32_index(np, "reg", 1, (u32 *)&priv->size)) {
> > + dev_err(dev, "Failed to read \"reg\" property\n");
> > + return -EINVAL;
> > + }
> > +
> > + priv->mtd = of_get_mtd_device_by_node(np->parent);
> > + if (IS_ERR(priv->mtd)) {
> > + dev_err(dev, "Failed to get %pOF MTD: %ld\n", np->parent, PTR_ERR(priv->mtd));
> > + return PTR_ERR(priv->mtd);
> > + }
>
> Partitions are mtd devices themselves and the mtd layer directly
> associates these devices to their OF node, so it should be possible
> to do a of_get_mtd_device_by_node(np) which gets you the partition.
> You can use the whole mtd device then and do not have to fiddle with
> reg properties, offsets and sizes in your driver yourself.
Just for the record, there will be one mtd device per partition, but
the "full" mtd device will only exist if the configuration contains
CONFIG_MTD_PARTITIONED_MASTER.
Thanks,
Miquèl
next prev parent reply other threads:[~2022-06-14 9:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-11 20:46 [PATCH V3 1/2] mtd: allow getting MTD device associated with a specific DT node Rafał Miłecki
2022-06-11 20:46 ` [PATCH V3 2/2] nvmem: add driver handling U-Boot environment variables Rafał Miłecki
2022-06-14 6:45 ` Ahmad Fatoum
2022-06-15 18:30 ` Rafał Miłecki
2022-06-14 7:46 ` Sascha Hauer
2022-06-14 9:02 ` Miquel Raynal [this message]
2022-06-13 14:04 ` [PATCH V3 1/2] mtd: allow getting MTD device associated with a specific DT node Miquel Raynal
2022-06-13 14:15 ` Rafał Miłecki
2022-06-13 14:33 ` Miquel Raynal
2022-06-14 6:49 ` Ahmad Fatoum
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=20220614110230.46fab506@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=a.fatoum@pengutronix.de \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
--cc=sha@pengutronix.de \
--cc=srinivas.kandagatla@linaro.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=vigneshr@ti.com \
--cc=zajec5@gmail.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).