450-06-mtd-ubi-populate-ubi-volume-fwnode.patch 2.0 KB

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