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