814-v6.4-0006-nvmem-core-allow-to-modify-a-cell-before-adding-it.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From de12c9691501ccba41a154c223869f82be4c12fd Mon Sep 17 00:00:00 2001
  2. From: Michael Walle <[email protected]>
  3. Date: Tue, 4 Apr 2023 18:21:25 +0100
  4. Subject: [PATCH] nvmem: core: allow to modify a cell before adding it
  5. Provide a way to modify a cell before it will get added. This is useful
  6. to attach a custom post processing hook via a layout.
  7. Signed-off-by: Michael Walle <[email protected]>
  8. Signed-off-by: Miquel Raynal <[email protected]>
  9. Signed-off-by: Srinivas Kandagatla <[email protected]>
  10. Link: https://lore.kernel.org/r/[email protected]
  11. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  12. ---
  13. drivers/nvmem/core.c | 4 ++++
  14. include/linux/nvmem-provider.h | 5 +++++
  15. 2 files changed, 9 insertions(+)
  16. --- a/drivers/nvmem/core.c
  17. +++ b/drivers/nvmem/core.c
  18. @@ -695,6 +695,7 @@ static int nvmem_validate_keepouts(struc
  19. static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
  20. {
  21. + struct nvmem_layout *layout = nvmem->layout;
  22. struct device *dev = &nvmem->dev;
  23. struct device_node *child;
  24. const __be32 *addr;
  25. @@ -724,6 +725,9 @@ static int nvmem_add_cells_from_of(struc
  26. info.np = of_node_get(child);
  27. + if (layout && layout->fixup_cell_info)
  28. + layout->fixup_cell_info(nvmem, layout, &info);
  29. +
  30. ret = nvmem_add_one_cell(nvmem, &info);
  31. kfree(info.name);
  32. if (ret) {
  33. --- a/include/linux/nvmem-provider.h
  34. +++ b/include/linux/nvmem-provider.h
  35. @@ -155,6 +155,8 @@ struct nvmem_cell_table {
  36. * @add_cells: Will be called if a nvmem device is found which
  37. * has this layout. The function will add layout
  38. * specific cells with nvmem_add_one_cell().
  39. + * @fixup_cell_info: Will be called before a cell is added. Can be
  40. + * used to modify the nvmem_cell_info.
  41. * @owner: Pointer to struct module.
  42. * @node: List node.
  43. *
  44. @@ -168,6 +170,9 @@ struct nvmem_layout {
  45. const struct of_device_id *of_match_table;
  46. int (*add_cells)(struct device *dev, struct nvmem_device *nvmem,
  47. struct nvmem_layout *layout);
  48. + void (*fixup_cell_info)(struct nvmem_device *nvmem,
  49. + struct nvmem_layout *layout,
  50. + struct nvmem_cell_info *cell);
  51. /* private */
  52. struct module *owner;