32990148c806f9307aecc9f7321225f8da597a70
[librecmc/librecmc.git] /
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
5
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.
8
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>
14 ---
15  drivers/nvmem/core.c           | 4 ++++
16  include/linux/nvmem-provider.h | 5 +++++
17  2 files changed, 9 insertions(+)
18
19 --- a/drivers/nvmem/core.c
20 +++ b/drivers/nvmem/core.c
21 @@ -695,6 +695,7 @@ static int nvmem_validate_keepouts(struc
22  
23  static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
24  {
25 +       struct nvmem_layout *layout = nvmem->layout;
26         struct device *dev = &nvmem->dev;
27         struct device_node *child;
28         const __be32 *addr;
29 @@ -724,6 +725,9 @@ static int nvmem_add_cells_from_of(struc
30  
31                 info.np = of_node_get(child);
32  
33 +               if (layout && layout->fixup_cell_info)
34 +                       layout->fixup_cell_info(nvmem, layout, &info);
35 +
36                 ret = nvmem_add_one_cell(nvmem, &info);
37                 kfree(info.name);
38                 if (ret) {
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.
48   * @node:              List node.
49   *
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);
57  
58         /* private */
59         struct module *owner;