generic: copy backport, hack, pending patch and config from 6.1 to 6.6
[openwrt/openwrt.git] / target / linux / generic / pending-6.6 / 450-06-mtd-ubi-populate-ubi-volume-fwnode.patch
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
5
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
9 as NVMEM providers.
10
11 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
12 ---
13 drivers/mtd/ubi/vmt.c | 27 +++++++++++++++++++++++++++
14 1 file changed, 27 insertions(+)
15
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
19 kfree(vol);
20 }
21
22 +static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol)
23 +{
24 + struct fwnode_handle *fw_vols, *fw_vol;
25 + const char *volname;
26 + u32 volid;
27 +
28 + fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes");
29 + if (!fw_vols)
30 + return NULL;
31 +
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))
35 + continue;
36 +
37 + if (!fwnode_property_read_u32(fw_vol, "volid", &volid) &&
38 + vol->vol_id != volid)
39 + continue;
40 +
41 + return fw_vol;
42 + }
43 +
44 + return NULL;
45 +}
46 +
47 /**
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);
53 vol->ubi = ubi;
54 + device_set_node(&vol->dev, find_volume_fwnode(vol));
55
56 /*
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);
64 if (err) {
65 cdev_del(&vol->cdev);