]> git.itanic.dy.fi Git - linux-stable/commitdiff
nvmem: core: allow to modify a cell before adding it
authorMichael Walle <michael@walle.cc>
Tue, 4 Apr 2023 17:21:25 +0000 (18:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Apr 2023 17:41:11 +0000 (19:41 +0200)
Provide a way to modify a cell before it will get added. This is useful
to attach a custom post processing hook via a layout.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230404172148.82422-18-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c
include/linux/nvmem-provider.h

index 0708f9f2789882e7c73a0f9c5b03a3fc64224969..f43025ad315b7b34fff8d963f885cb5a288d27cd 100644 (file)
@@ -695,6 +695,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 
 static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 {
+       struct nvmem_layout *layout = nvmem->layout;
        struct device *dev = &nvmem->dev;
        struct device_node *child;
        const __be32 *addr;
@@ -724,6 +725,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 
                info.np = of_node_get(child);
 
+               if (layout && layout->fixup_cell_info)
+                       layout->fixup_cell_info(nvmem, layout, &info);
+
                ret = nvmem_add_one_cell(nvmem, &info);
                kfree(info.name);
                if (ret) {
index 3bfc23553a9e87e25546c6d380b22a0fe2382c09..be81cc88eabca21c9eded02a52447fda18a3b678 100644 (file)
@@ -155,6 +155,8 @@ struct nvmem_cell_table {
  * @add_cells:         Will be called if a nvmem device is found which
  *                     has this layout. The function will add layout
  *                     specific cells with nvmem_add_one_cell().
+ * @fixup_cell_info:   Will be called before a cell is added. Can be
+ *                     used to modify the nvmem_cell_info.
  * @owner:             Pointer to struct module.
  * @node:              List node.
  *
@@ -168,6 +170,9 @@ struct nvmem_layout {
        const struct of_device_id *of_match_table;
        int (*add_cells)(struct device *dev, struct nvmem_device *nvmem,
                         struct nvmem_layout *layout);
+       void (*fixup_cell_info)(struct nvmem_device *nvmem,
+                               struct nvmem_layout *layout,
+                               struct nvmem_cell_info *cell);
 
        /* private */
        struct module *owner;