mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/5] nvmem: ocotp: add post processing for MAC cells
Date: Thu,  2 Feb 2023 18:33:11 +0100	[thread overview]
Message-ID: <20230202173312.504493-4-l.stach@pengutronix.de> (raw)
In-Reply-To: <20230202173312.504493-1-l.stach@pengutronix.de>

Add a nvmem post process callback to swap the MAC address as required
when read via nvmem.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/nvmem/ocotp.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 78c9f9726db0..b478ece30680 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -641,6 +641,21 @@ static struct regmap_bus imx_ocotp_regmap_bus = {
 	.reg_read = imx_ocotp_reg_read,
 };
 
+static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset,
+			     void *data, size_t bytes)
+{
+	/* Deal with some post processing of nvmem cell data */
+	if (id && !strcmp(id, "mac-address")) {
+		u8 *buf = data;
+		int i;
+
+		for (i = 0; i < bytes/2; i++)
+			swap(buf[i], buf[bytes - i - 1]);
+	}
+
+	return 0;
+}
+
 static int imx_ocotp_init_dt(struct ocotp_priv *priv)
 {
 	char mac[MAC_BYTES];
@@ -731,7 +746,8 @@ static int imx_ocotp_probe(struct device *dev)
 	if (IS_ERR(priv->map))
 		return PTR_ERR(priv->map);
 
-	nvmem = nvmem_regmap_register(priv->map, "imx-ocotp");
+	nvmem = nvmem_regmap_register_with_pp(priv->map, "imx-ocotp",
+					      imx_ocotp_cell_pp);
 	if (IS_ERR(nvmem))
 		return PTR_ERR(nvmem);
 
-- 
2.39.1




  parent reply	other threads:[~2023-02-02 17:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 17:33 [PATCH 1/5] nvmem: add support for post processing Lucas Stach
2023-02-02 17:33 ` [PATCH 2/5] nvmem: ocotp: switch to nvmem_regmap_register Lucas Stach
2023-02-02 17:33 ` [PATCH 3/5] nvmem: regmap: allow to register with post processing Lucas Stach
2023-02-02 17:33 ` Lucas Stach [this message]
2023-02-02 17:33 ` [PATCH 5/5] ARM: dts: i.MX8MP: drop OCOTP MAC address provider Lucas Stach
2023-02-06  7:43 ` [PATCH 1/5] nvmem: add support for post processing 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=20230202173312.504493-4-l.stach@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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