mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH 15/15] nvmem: core: drop global cell_post_process
Date: Mon, 04 Aug 2025 16:37:01 +0200	[thread overview]
Message-ID: <20250804-v2025-06-0-topic-nvmem-v1-15-7603eaa4d2b0@pengutronix.de> (raw)
In-Reply-To: <20250804-v2025-06-0-topic-nvmem-v1-0-7603eaa4d2b0@pengutronix.de>

Switch to the cell local read_post_process() hook and drop the global
nvmem cell_post_process() hook to align our code base with Linux, to
make it easier to port nvmem(-layout) drivers.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/nvmem/core.c           | 10 +---------
 drivers/nvmem/imx-ocotp-ele.c  |  8 +++++++-
 drivers/nvmem/internals.h      |  1 -
 drivers/nvmem/ocotp.c          |  8 +++++++-
 drivers/nvmem/regmap.c         |  5 +++--
 include/linux/nvmem-provider.h | 12 ++++++------
 6 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 7f4fd329c196efa3baac2c97016d6651d4c140a3..fb5860bf03956170cb1d32ca21c36568387f1cf9 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -444,7 +444,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	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);
 	if (rval)
@@ -844,13 +843,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 			return rc;
 	}
 
-	if (nvmem->cell_post_process) {
-		rc = nvmem->cell_post_process(nvmem->priv, id, index,
-					      cell->offset, buf, cell->bytes);
-		if (rc)
-			return rc;
-	}
-
 	if (len)
 		*len = cell->bytes;
 
@@ -953,7 +945,7 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, const void *b
 		return -EINVAL;
 
 	/*
-	 * Any cells which have a cell_post_process hook are read-only because
+	 * Any cells which have a read_post_process hook are read-only because
 	 * we cannot reverse the operation and it might affect other cells,
 	 * too.
 	 */
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 8ac4e2a9a6c87f128ff9aaf16d1238ef129d91ca..797c6f8d7a2a069fbf342c517031eb5dc3f09d7a 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -128,6 +128,12 @@ static int imx_ocotp_cell_pp(void *context, const char *id, int index,
 	return 0;
 }
 
+static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem,
+					 struct nvmem_cell_info *cell)
+{
+	cell->read_post_process = imx_ocotp_cell_pp;
+}
+
 static struct regmap_bus imx_ocotp_regmap_bus = {
 	.reg_write = imx_ocotp_reg_write,
 	.reg_read = imx_ocotp_reg_read,
@@ -192,7 +198,7 @@ static int imx_ele_ocotp_probe(struct device *dev)
 		imx_ocotp_set_unique_machine_id(priv);
 
 	nvmem = nvmem_regmap_register_with_pp(priv->map, "imx_ocotp",
-					      imx_ocotp_cell_pp);
+					      imx_ocotp_fixup_dt_cell_info);
 	if (IS_ERR(nvmem))
 		return PTR_ERR(nvmem);
 
diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h
index 10e11ad79bc32364d542c5320e70fb0377e83478..1e050df78621f8cce751577365107bfa16766374 100644
--- a/drivers/nvmem/internals.h
+++ b/drivers/nvmem/internals.h
@@ -21,7 +21,6 @@ struct nvmem_device {
 	void			*priv;
 	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,
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index d4510d4b89ba404c0b0537afc01075cac501042c..7bca27540417ad9ba0ce5c5f8ec43ad1c63638b9 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -803,6 +803,12 @@ static int imx_ocotp_cell_pp(void *context, const char *id, int index,
 	return 0;
 }
 
+static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem,
+					 struct nvmem_cell_info *cell)
+{
+	cell->read_post_process = imx_ocotp_cell_pp;
+}
+
 static int imx_ocotp_init_dt(struct ocotp_priv *priv)
 {
 	char mac[MAC_BYTES];
@@ -898,7 +904,7 @@ static int imx_ocotp_probe(struct device *dev)
 		return PTR_ERR(priv->map);
 
 	nvmem = nvmem_regmap_register_with_pp(priv->map, "imx-ocotp",
-					      imx_ocotp_cell_pp);
+					      imx_ocotp_fixup_dt_cell_info);
 	if (IS_ERR(nvmem))
 		return PTR_ERR(nvmem);
 
diff --git a/drivers/nvmem/regmap.c b/drivers/nvmem/regmap.c
index 24712fbb0f332e98474955aa433c0a5e02502054..d35814c9a2a955926781768fb3e1126b6f041c26 100644
--- a/drivers/nvmem/regmap.c
+++ b/drivers/nvmem/regmap.c
@@ -65,7 +65,8 @@ static int nvmem_regmap_read(void *ctx, unsigned offset, void *buf, size_t bytes
 
 struct nvmem_device *
 nvmem_regmap_register_with_pp(struct regmap *map, const char *name,
-			      nvmem_cell_post_process_t cell_post_process)
+			      void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
+							 struct nvmem_cell_info *cell))
 {
 	struct nvmem_config config = {};
 
@@ -79,7 +80,7 @@ nvmem_regmap_register_with_pp(struct regmap *map, const char *name,
 	config.stride = 1;
 	config.word_size = 1;
 	config.size = regmap_size_bytes(map);
-	config.cell_post_process = cell_post_process;
+	config.fixup_dt_cell_info = fixup_dt_cell_info;
 	config.reg_write = nvmem_regmap_write;
 	config.reg_read = nvmem_regmap_read;
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index e1e7d8871d67465157191e7e6a46b400a285e834..2ea2a20d9efbcd704c347da9d0bd77bfaf14be61 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -84,7 +84,6 @@ struct nvmem_config {
 	int			word_size;
 	int			stride;
 	void			*priv;
-	nvmem_cell_post_process_t cell_post_process;
 };
 
 /**
@@ -120,8 +119,9 @@ struct cdev;
 
 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
 struct nvmem_device *nvmem_regmap_register(struct regmap *regmap, const char *name);
-struct nvmem_device *nvmem_regmap_register_with_pp(struct regmap *regmap,
-		const char *name, nvmem_cell_post_process_t cell_post_process);
+struct nvmem_device *nvmem_regmap_register_with_pp(struct regmap *map, const char *name,
+			      void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
+							 struct nvmem_cell_info *cell));
 struct device *nvmem_device_get_device(struct nvmem_device *nvmem);
 int nvmem_add_one_cell(struct nvmem_device *nvmem,
 		       const struct nvmem_cell_info *info);
@@ -145,9 +145,9 @@ static inline struct nvmem_device *nvmem_regmap_register(struct regmap *regmap,
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct nvmem_device *
-nvmem_regmap_register_with_pp(struct regmap *regmap, const char *name,
-			      nvmem_cell_post_process_t cell_post_process)
+struct nvmem_device *nvmem_regmap_register_with_pp(struct regmap *map, const char *name,
+			      void (*fixup_dt_cell_info)(struct nvmem_device *nvmem,
+							 struct nvmem_cell_info *cell))
 {
 	return ERR_PTR(-ENOSYS);
 }

-- 
2.39.5




  parent reply	other threads:[~2025-08-04 15:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 14:36 [PATCH 00/15] NVMEM: Add support for layout drivers Marco Felsch
2025-08-04 14:36 ` [PATCH 01/15] of: sync of_*_phandle_with_args with Linux Marco Felsch
2025-08-04 14:36 ` [PATCH 02/15] of: base: add of_parse_phandle_with_optional_args() Marco Felsch
2025-08-04 14:36 ` [PATCH 03/15] of: device: Export of_device_make_bus_id() Marco Felsch
2025-08-04 14:36 ` [PATCH 04/15] nvmem: core: fix nvmem_register error path Marco Felsch
2025-08-04 14:36 ` [PATCH 05/15] nvmem: core: sync with Linux Marco Felsch
2025-08-04 14:36 ` [PATCH 06/15] nvmem: core: expose nvmem cells as cdev Marco Felsch
2025-08-04 14:36 ` [PATCH 07/15] nvmem: core: allow single and dynamic device ids Marco Felsch
2025-08-04 14:36 ` [PATCH 08/15] eeprom: at24: fix device name handling Marco Felsch
2025-08-04 14:36 ` [PATCH 09/15] nvmem: core: create a header for internal sharing Marco Felsch
2025-08-04 14:36 ` [PATCH 10/15] nvmem: core: add nvmem-layout support Marco Felsch
2025-08-04 14:36 ` [PATCH 11/15] nvmem: core: add an index parameter to the cell Marco Felsch
2025-08-04 14:36 ` [PATCH 12/15] nvmem: core: add per-cell post processing Marco Felsch
2025-08-04 14:36 ` [PATCH 13/15] nvmem: core: add cell based fixup logic Marco Felsch
2025-08-04 14:37 ` [PATCH 14/15] nvmem: core: provide own priv pointer in post process callback Marco Felsch
2025-08-04 14:37 ` Marco Felsch [this message]
2025-08-05 10:44 ` [PATCH 00/15] NVMEM: Add support for layout drivers Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250804-v2025-06-0-topic-nvmem-v1-15-7603eaa4d2b0@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox