devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	<linux-kernel@vger.kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Michael Walle" <michael@walle.cc>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Robert Marko" <robert.marko@sartura.hr>,
	"Luka Perkov" <luka.perkov@sartura.hr>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	devicetree@vger.kernel.org,
	"Miquel Raynal" <miquel.raynal@bootlin.com>
Subject: [PATCH v3 14/20] nvmem: imx-ocotp: replace global post processing with layouts
Date: Wed,  8 Mar 2023 16:31:54 +0100	[thread overview]
Message-ID: <20230308153200.682248-15-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com>

From: Michael Walle <michael@walle.cc>

In preparation of retiring the global post processing hook change this
driver to use layouts. The layout will be supplied during registration
and will be used to add the post processing hook to all added cells.

Signed-off-by: Michael Walle <michael@walle.cc>
Tested-by: Michael Walle <michael@walle.cc> # on kontron-pitx-imx8m
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index e9b52ecb3f72..ac0edb6398f1 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 static int imx_ocotp_cell_pp(void *context, const char *id, int index,
 			     unsigned int offset, void *data, size_t bytes)
 {
-	struct ocotp_priv *priv = context;
+	u8 *buf = data;
+	int i;
 
 	/* Deal with some post processing of nvmem cell data */
-	if (id && !strcmp(id, "mac-address")) {
-		if (priv->params->reverse_mac_address) {
-			u8 *buf = data;
-			int i;
-
-			for (i = 0; i < bytes/2; i++)
-				swap(buf[i], buf[bytes - i - 1]);
-		}
-	}
+	if (id && !strcmp(id, "mac-address"))
+		for (i = 0; i < bytes / 2; i++)
+			swap(buf[i], buf[bytes - i - 1]);
 
 	return 0;
 }
@@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = {
 	.stride = 1,
 	.reg_read = imx_ocotp_read,
 	.reg_write = imx_ocotp_write,
-	.cell_post_process = imx_ocotp_cell_pp,
 };
 
 static const struct ocotp_params imx6q_params = {
@@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
 
+static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem,
+				      struct nvmem_layout *layout,
+				      struct nvmem_cell_info *cell)
+{
+	cell->read_post_process = imx_ocotp_cell_pp;
+}
+
+struct nvmem_layout imx_ocotp_layout = {
+	.fixup_cell_info = imx_ocotp_fixup_cell_info,
+};
+
 static int imx_ocotp_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev)
 	imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
 	imx_ocotp_nvmem_config.dev = dev;
 	imx_ocotp_nvmem_config.priv = priv;
+	if (priv->params->reverse_mac_address)
+		imx_ocotp_nvmem_config.layout = &imx_ocotp_layout;
+
 	priv->config = &imx_ocotp_nvmem_config;
 
 	clk_prepare_enable(priv->clk);
-- 
2.34.1


  parent reply	other threads:[~2023-03-08 15:33 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 15:31 [PATCH v3 00/20] [PATCH v3 00/20] nvmem: Layouts support Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 01/20] of: Fix modalias string generation Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 02/20] of: Update of_device_get_modalias() Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 03/20] of: Rename of_modalias_node() Miquel Raynal
2023-03-08 15:38   ` Mark Brown
2023-03-08 15:31 ` [PATCH v3 04/20] of: Move of_modalias() to module.c Miquel Raynal
2023-03-09  2:22   ` Rob Herring
2023-03-08 15:31 ` [PATCH v3 05/20] of: Move the request module helper logic " Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 06/20] usb: ulpi: Use of_request_module() Miquel Raynal
2023-03-08 15:50   ` Heikki Krogerus
2023-03-08 15:31 ` [PATCH v3 07/20] of: device: Kill of_device_request_module() Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 08/20] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 09/20] nvmem: core: introduce NVMEM layouts Miquel Raynal
2023-03-10 10:55   ` Srinivas Kandagatla
2023-03-10 11:00     ` Rafał Miłecki
2023-03-08 15:31 ` [PATCH v3 10/20] nvmem: core: handle the absence of expected layouts Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 11/20] nvmem: core: request layout modules loading Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 12/20] nvmem: core: add per-cell post processing Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 13/20] nvmem: core: allow to modify a cell before adding it Miquel Raynal
2023-03-08 15:31 ` Miquel Raynal [this message]
2023-03-08 15:31 ` [PATCH v3 15/20] nvmem: cell: drop global cell_post_process Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 16/20] nvmem: core: provide own priv pointer in post process callback Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 17/20] nvmem: layouts: sl28vpd: Add new layout driver Miquel Raynal
2023-03-10 11:03   ` Srinivas Kandagatla
2023-03-10 11:16     ` Miquel Raynal
2023-03-10 11:43       ` Srinivas Kandagatla
2023-03-08 15:31 ` [PATCH v3 18/20] MAINTAINERS: add myself as sl28vpd nvmem " Miquel Raynal
2023-03-08 15:31 ` [PATCH v3 19/20] nvmem: layouts: onie-tlv: Add new " Miquel Raynal
2023-03-08 15:32 ` [PATCH v3 20/20] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Miquel Raynal
2023-03-14 11:28 ` [PATCH v3 00/20] [PATCH v3 00/20] nvmem: Layouts support Srinivas Kandagatla

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=20230308153200.682248-15-miquel.raynal@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luka.perkov@sartura.hr \
    --cc=michael@walle.cc \
    --cc=rafal@milecki.pl \
    --cc=robert.marko@sartura.hr \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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;
as well as URLs for NNTP newsgroup(s).