[PATCH 13/15] nvmem: core: add cell based fixup logic
Marco Felsch
m.felsch at pengutronix.de
Mon Aug 4 07:36:59 PDT 2025
To further sync the nvmem code base port Linux commits:
| commit de12c9691501ccba41a154c223869f82be4c12fd
| Author: Michael Walle <michael at walle.cc>
| Date: Tue Apr 4 18:21:25 2023 +0100
|
| nvmem: core: allow to modify a cell before adding it
|
| 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 at walle.cc>
| Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
| Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
| Link: https://lore.kernel.org/r/20230404172148.82422-18-srinivas.kandagatla@linaro.org
| Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
| commit 1172460e716784ac7e1049a537bdca8edbf97360
| Author: Miquel Raynal <miquel.raynal at bootlin.com>
| Date: Fri Dec 15 11:15:31 2023 +0000
|
| nvmem: Move and rename ->fixup_cell_info()
|
| This hook is meant to be used by any provider and instantiating a layout
| just for this is useless. Let's instead move this hook to the nvmem
| device and add it to the config structure to be easily shared by the
| providers.
|
| While at moving this hook, rename it ->fixup_dt_cell_info() to clarify
| its main intended purpose.
|
| Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
| Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
| Link: https://lore.kernel.org/r/20231215111536.316972-6-srinivas.kandagatla@linaro.org
| Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
The next commit will get rid of the global nvmem->cell_post_process()
hook.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
drivers/nvmem/core.c | 4 ++++
drivers/nvmem/internals.h | 2 ++
include/linux/nvmem-provider.h | 4 ++++
3 files changed, 10 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 0c78d61e3c58fbe019a1def08d06e2ecf561a9b1..d9b3e3bc8c1b9016975480d45da53f8c77a52881 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -344,6 +344,9 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
info.np = of_node_get(child);
+ if (nvmem->fixup_dt_cell_info)
+ nvmem->fixup_dt_cell_info(nvmem, &info);
+
ret = nvmem_add_one_cell(nvmem, &info);
kfree(info.name);
if (ret) {
@@ -438,6 +441,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->dev.of_node = np;
nvmem->priv = config->priv;
INIT_LIST_HEAD(&nvmem->cells);
+ nvmem->fixup_dt_cell_info = config->fixup_dt_cell_info;
nvmem->cell_post_process = config->cell_post_process;
rval = nvmem_add_cells_from_legacy_of(nvmem);
diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h
index 97ffdfe79dfe6c5459d1bba5ba717c861678e9a2..10e11ad79bc32364d542c5320e70fb0377e83478 100644
--- a/drivers/nvmem/internals.h
+++ b/drivers/nvmem/internals.h
@@ -22,6 +22,8 @@ struct nvmem_device {
struct nvmem_layout *layout;
struct list_head cells;
nvmem_cell_post_process_t cell_post_process;
+ void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
+ struct nvmem_cell_info *cell);
int (*reg_write)(void *ctx, unsigned int reg,
const void *val, size_t val_size);
int (*reg_read)(void *ctx, unsigned int reg,
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 892e3604ef83ef8b616041f5d4dbfdcae1136fc9..a8aa6b741395f810315d7f018d62e4ef64e618a5 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -58,6 +58,8 @@ struct nvmem_cell_info {
* @dev: Parent device.
* @name: Optional name.
* @id: Optional device ID used in full name. Ignored if name is NULL.
+ * @fixup_dt_cell_info: Will be called before a cell is added. Can be
+ * used to modify the nvmem_cell_info.
* @read_only: Device is read-only.
* @reg_read: Callback to read data; return zero if successful.
* @reg_write: Callback to write data; return zero if successful.
@@ -70,6 +72,8 @@ struct nvmem_config {
struct device *dev;
const char *name;
int id;
+ void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
+ struct nvmem_cell_info *cell);
bool read_only;
struct cdev *cdev;
nvmem_reg_read_t reg_read;
--
2.39.5
More information about the barebox
mailing list