mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] nvmem: k3: add regulator support
Date: Thu, 29 Jan 2026 12:40:00 +0100	[thread overview]
Message-ID: <20260129114000.3238194-1-s.hauer@pengutronix.de> (raw)

K3 SoCs need an extra vpp for writing fuses. For boards which have that
controllable add regulator support to the K3 OTP driver. The regulator
is turned on before writing and turned off after writing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/nvmem/k3-fuse.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/k3-fuse.c b/drivers/nvmem/k3-fuse.c
index 214239f2cd..6ee5e78920 100644
--- a/drivers/nvmem/k3-fuse.c
+++ b/drivers/nvmem/k3-fuse.c
@@ -11,6 +11,7 @@
 #include <linux/nvmem-provider.h>
 #include <linux/arm-smccc.h>
 #include <linux/bitmap.h>
+#include <regulator.h>
 
 /*
  * These SIP calls are currently only supported in the TI downstream
@@ -27,6 +28,7 @@ struct ti_k3_otp_driver_data {
 
 struct ti_k3_otp {
 	struct device *dev;
+	struct regulator *regulator_fuse;
 	uint32_t *map;
 	const struct ti_k3_otp_driver_data *data;
 };
@@ -132,20 +134,29 @@ static int ti_k3_otp_write(void *ctx, unsigned int offset, unsigned int val)
 	unsigned int bank = 0;
 	unsigned int word = offset >> 2;
 	unsigned int mask = val;
+	int ret;
+
+	ret = regulator_enable(priv->regulator_fuse);
+	if (ret) {
+		dev_err(priv->dev, "Cannot enable regulator: %pe\n", ERR_PTR(ret));
+		return ret;
+	}
 
 	if (word == 0 && priv->data->skip_init) {
 		unsigned int skip_mask = GENMASK(priv->data->skip_init, 0);
 		if (val & skip_mask) {
 			dev_err(priv->dev, "Lower %d bits of word 0 cannot be written\n",
 				priv->data->skip_init);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto err;
 		}
 	}
 
 	if (val & GENMASK(31, priv->data->bits_per_row)) {
 		dev_err(priv->dev, "Each row only has %d bits",
 			priv->data->bits_per_row);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err;
 	}
 
 	arm_smccc_smc(K3_SIP_OTP_WRITE, bank, word,
@@ -154,10 +165,14 @@ static int ti_k3_otp_write(void *ctx, unsigned int offset, unsigned int val)
 	if (res.a0 != 0) {
 		dev_err(priv->dev, "Writing fuse 0x%08x failed with: %lu\n",
 			offset, res.a0);
-		return -EIO;
+		ret = -EIO;
+		goto err;
 	}
 
-	return 0;
+	ret = 0;
+err:
+	regulator_disable(priv->regulator_fuse);
+	return ret;
 }
 
 static struct regmap_bus ti_k3_otp_regmap_bus = {
@@ -177,6 +192,10 @@ static int ti_k3_otp_probe(struct device *dev)
 	priv->dev = dev;
 	priv->map = xzalloc(sizeof(uint32_t) * priv->data->nrows);
 
+	priv->regulator_fuse = regulator_get(dev, "fuse");
+	if (IS_ERR(priv->regulator_fuse))
+		return PTR_ERR(priv->regulator_fuse);
+
 	config.name = "k3-otp";
 	config.reg_bits = 32;
 	config.val_bits = 32;
-- 
2.47.3




             reply	other threads:[~2026-01-29 11:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 11:40 Sascha Hauer [this message]
2026-02-03 11:08 ` 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=20260129114000.3238194-1-s.hauer@pengutronix.de \
    --to=s.hauer@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