1 From 3a041ee543cdf2e707a1dd72946cd6a583509b28 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Fri, 21 Jul 2023 19:26:37 +0100
4 Subject: [PATCH 06/15] mtd: ubi: populate ubi volume fwnode
6 Look for the 'volumes' subnode of an MTD partition attached to a UBI
7 device and attach matching child nodes to UBI volumes.
8 This allows UBI volumes to be referenced in device tree, e.g. for use
11 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
13 drivers/mtd/ubi/vmt.c | 27 +++++++++++++++++++++++++++
14 1 file changed, 27 insertions(+)
16 --- a/drivers/mtd/ubi/vmt.c
17 +++ b/drivers/mtd/ubi/vmt.c
18 @@ -124,6 +124,31 @@ static void vol_release(struct device *d
22 +static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol)
24 + struct fwnode_handle *fw_vols, *fw_vol;
25 + const char *volname;
28 + fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes");
32 + fwnode_for_each_child_node(fw_vols, fw_vol) {
33 + if (!fwnode_property_read_string(fw_vol, "volname", &volname) &&
34 + strncmp(volname, vol->name, vol->name_len))
37 + if (!fwnode_property_read_u32(fw_vol, "volid", &volid) &&
38 + vol->vol_id != volid)
48 * ubi_create_volume - create volume.
49 * @ubi: UBI device description object
50 @@ -223,6 +248,7 @@ int ubi_create_volume(struct ubi_device
51 vol->name_len = req->name_len;
52 memcpy(vol->name, req->name, vol->name_len);
54 + device_set_node(&vol->dev, find_volume_fwnode(vol));
57 * Finish all pending erases because there may be some LEBs belonging
58 @@ -605,6 +631,7 @@ int ubi_add_volume(struct ubi_device *ub
59 vol->dev.class = &ubi_class;
60 vol->dev.groups = volume_dev_groups;
61 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
62 + device_set_node(&vol->dev, find_volume_fwnode(vol));
63 err = device_register(&vol->dev);