From: Daniel Golle <daniel@makrotopia.org>
To: Richard Weinberger <richard@nod.at>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org
Subject: [PATCH 5/6] mtd: ubi: populate ubi volume fwnode
Date: Mon, 31 Jul 2023 20:13:47 +0100 [thread overview]
Message-ID: <3efb1ac62048dd6818688737e22cdaabb9f65ce3.1690823629.git.daniel@makrotopia.org> (raw)
In-Reply-To: <cover.1690823629.git.daniel@makrotopia.org>
Look for the 'volumes' subnode of an MTD partition attached to a UBI
device and attach matching child nodes to UBI volumes.
This allows UBI volumes to be referenced in device tree, e.g. for use
as NVMEM providers.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/mtd/ubi/vmt.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index eed4b57c61bda..3b997256cfba7 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -124,6 +124,35 @@ static void vol_release(struct device *dev)
kfree(vol);
}
+static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol)
+{
+ struct fwnode_handle *fw_vols, *fw_vol;
+ const char *volname;
+ u32 reg;
+
+ fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes");
+ if (!fw_vols)
+ return NULL;
+
+ fwnode_for_each_child_node(fw_vols, fw_vol) {
+ if (!fwnode_property_read_string(fw_vol, "volname", &volname) &&
+ strncmp(volname, vol->name, vol->name_len))
+ continue;
+
+ /*
+ * volume id (reg) in device tree greater than UBI_MAX_VOLUMES
+ * can be used to match by volname only
+ */
+ if (!fwnode_property_read_u32(fw_vol, "reg", ®) &&
+ reg < UBI_MAX_VOLUMES && vol->vol_id != reg)
+ continue;
+
+ return fw_vol;
+ }
+
+ return NULL;
+}
+
/**
* ubi_create_volume - create volume.
* @ubi: UBI device description object
@@ -223,6 +252,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
vol->name_len = req->name_len;
memcpy(vol->name, req->name, vol->name_len);
vol->ubi = ubi;
+ device_set_node(&vol->dev, find_volume_fwnode(vol));
/*
* Finish all pending erases because there may be some LEBs belonging
@@ -597,6 +627,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
vol->dev.class = &ubi_class;
vol->dev.groups = volume_dev_groups;
dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
+ device_set_node(&vol->dev, find_volume_fwnode(vol));
err = device_register(&vol->dev);
if (err) {
cdev_del(&vol->cdev);
--
2.41.0
next prev parent reply other threads:[~2023-07-31 19:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 19:10 [PATCH 0/6] mtd: ubi: allow UBI volumes to provide NVMEM Daniel Golle
2023-07-31 19:11 ` [PATCH 1/6] mtd: ubi: block: don't return on error when removing Daniel Golle
2023-07-31 19:11 ` [PATCH 2/6] mtd: ubi: block: use notifier to create ubiblock from parameter Daniel Golle
2023-07-31 19:12 ` [PATCH 3/6] mtd: ubi: attach MTD partition from device-tree Daniel Golle
2023-07-31 19:13 ` [PATCH 4/6] mtd: ubi: introduce pre-removal notification for UBI volumes Daniel Golle
2023-07-31 19:13 ` Daniel Golle [this message]
2023-07-31 19:14 ` [PATCH 6/6] mtd: ubi: provide NVMEM layer over " Daniel Golle
2023-07-31 21:54 ` Randy Dunlap
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=3efb1ac62048dd6818688737e22cdaabb9f65ce3.1690823629.git.daniel@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--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
all inboxes | Powered by JetHome®