Skip to contentSkip to conversation

misc: Add RZG2L OTP support

PATCH Superseded Mathieu Othacehe 3 participants 7 messages Apr 14 – Apr 22 Char and misc drivers

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: Add RZG2L OTP support

Add OTP support through the fuse command. Fusing is directly performed by U-Boot, which means that the trusted-firmware must allow the non-secure world to perform fusing operations.

---
 drivers/misc/Kconfig     |   7 ++
 drivers/misc/Makefile    |   1 +
 drivers/misc/rzg2l_otp.c | 222 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 drivers/misc/rzg2l_otp.c
drivers/misc/Kconfig +7 -0
index ea785793d18..16cb800a393 100644
@@ -132,6 +132,13 @@ config SPL_ROCKCHIP_IODOMAIN
 	  for the IO-domain setting of the SoC to match the voltage supplied
 	  by the regulators.
 
+config RZG2L_OTP
+	bool "Renesas RZ/G2L OTP support"
+	depends on MISC
+	help
+	  Enable support for the OTP controller on
+	  Renesas RZ/G2L SoCs.
+
 config SIFIVE_OTP
 	bool "SiFive eMemory OTP driver"
 	depends on MISC
drivers/misc/Makefile +1 -0
index e2170212e5a..64b2701b672 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_QCOM_GENI) += qcom_geni.o
 obj-$(CONFIG_$(PHASE_)ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_$(PHASE_)ROCKCHIP_OTP) += rockchip-otp.o
 obj-$(CONFIG_$(PHASE_)ROCKCHIP_IODOMAIN) += rockchip-io-domain.o
+obj-$(CONFIG_RZG2L_OTP) += rzg2l_otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
drivers/misc/rzg2l_otp.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.52.0
#1 lore raw
Quoted 17 lines · Mathieu Othacehe

Add OTP support through the fuse command. Fusing is directly performed by U-Boot, which means that the trusted-firmware must allow the non-secure world to perform fusing operations.

---
 drivers/misc/Kconfig     |   7 ++
 drivers/misc/Makefile    |   1 +
 drivers/misc/rzg2l_otp.c | 222 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 drivers/misc/rzg2l_otp.c
drivers/misc/Kconfig +0 -0
index ea785793d18..16cb800a393 100644

drivers/misc/Kconfig config SPL_ROCKCHIP_IODOMAIN · line 141

Quoted 10 lines
drivers/misc/Kconfig +7 -0
@@ -132,6 +132,13 @@ config SPL_ROCKCHIP_IODOMAIN
 	  for the IO-domain setting of the SoC to match the voltage supplied
 	  by the regulators.
 
+config RZG2L_OTP
+	bool "Renesas RZ/G2L OTP support"
+	depends on MISC
+	help
+	  Enable support for the OTP controller on
+	  Renesas RZ/G2L SoCs.
+

If there's other feedback, this should have some dependency on CMD_FUSE as well (since that's what makes use of the functionality) but indeed it's very inconsistent currently, and the area in general could use some modernization.

Signature · 1 line
Tom
#2 lore raw
In reply to Mathieu Othacehe

On 4/14/26 11:14 AM, Mathieu Othacehe wrote:

[...]

Quoted 4 lines

+/*
+ * XXX: To enable direct fusing through U-Boot, the trusted-firmware must
+ * allow the non-secure world to perform fusing operations. This is controlled
+ * by the SYS_SLVACCCTL7 register.

Is there some SMC call to perform the fusing via TFA ?

drivers/misc/rzg2l_otp.c line 15

Quoted 3 lines

+ */

drivers/misc/rzg2l_otp.c new file +2 -0
+#define RZG2L_OTP_BASE      0x11860000
+#define RZG2L_SYSC_BASE     0x11020000

Can this be parsed out of DT ?

Quoted 12 lines
drivers/misc/rzg2l_otp.c new file +12 -0
+#define RZ_SYS_BASE_DEVID   (RZG2L_SYSC_BASE + 0x0A04)
+#define RZ_OTP_BASE_DEVID   (RZG2L_OTP_BASE + 0x1178)
+#define RZ_OTP_BASE_CHIPID  (RZG2L_OTP_BASE + 0x1140)
+
+#define RZ_OTP_PWR          (RZG2L_OTP_BASE + 0x0000)
+#define RZ_OTP_STR          (RZG2L_OTP_BASE + 0x0004)
+#define RZ_OTP_STAWR        (RZG2L_OTP_BASE + 0x0008)
+#define RZ_OTP_ADRWR        (RZG2L_OTP_BASE + 0x000c)
+#define RZ_OTP_DATAWR       (RZG2L_OTP_BASE + 0x0010)
+
+#define RZ_OTP_ADRRD        (RZG2L_OTP_BASE + 0x0014)
+#define RZ_OTP_DATARD       (RZG2L_OTP_BASE + 0x0018)

drivers/misc/rzg2l_otp.c line 38

Quoted 10 lines
drivers/misc/rzg2l_otp.c new file +10 -0
+
+#define RZ_OTP_FLAG         (RZG2L_OTP_BASE + 0x001c)
+
+#define OTP_PWR		    BIT(0)
+#define ERR_WR_1	    BIT(1)
+#define ERR_WR_2	    BIT(2)
+#define ERR_WP		    BIT(3)
+#define OTP_ACCL	    BIT(4)
+#define ERR_RDY_WR	    BIT(8)
+#define OTP_DUMMY_READ	    (0x400 >> 2)

What does 0x400 >> 2 mean ?

drivers/misc/rzg2l_otp.c line 44

Quoted 5 lines
drivers/misc/rzg2l_otp.c new file +5 -0
+static int rzg2l_otp_open(void)
+{
+	int i = 0;
+
+	if (readl(RZ_OTP_PWR) & 1) {

What does this magic value 1 mean ? Please add macro for it.

drivers/misc/rzg2l_otp.c line 50

Quoted 6 lines
drivers/misc/rzg2l_otp.c new file +6 -0
+		debug("OTP already powered up\n");
+		return 0;
+	}
+
+	while ((readl(RZ_OTP_STR) & 1) ||
+	       ((readl(RZ_OTP_FLAG) & 1) == 0)) {

read_poll_*() .

Quoted 8 lines
drivers/misc/rzg2l_otp.c new file +8 -0
+		if (i++ > 1000) {
+			printf("OTP power-up timeout\n");
+			return -ETIMEDOUT;
+		}
+
+		mdelay(1);
+	}
+

drivers/misc/rzg2l_otp.c line 68

Quoted 10 lines
drivers/misc/rzg2l_otp.c new file +10 -0
+	writel(readl(RZ_OTP_PWR) | OTP_PWR | OTP_ACCL, RZ_OTP_PWR);
+
+	return 0;
+}
+
+static int rzg2l_otp_dummy_read(void)
+{
+	int i = 0;
+
+	while ((readl(RZ_OTP_STR) & 1) == 0) {

readl_poll_*()

Quoted 13 lines
drivers/misc/rzg2l_otp.c new file +13 -0
+		if (i++ > 1000) {
+			printf("Timeout polling ready for OTP read\n");
+			return -ETIMEDOUT;
+		}
+		mdelay(1);
+	}
+
+	writel(RZG2L_OTP_BASE + OTP_DUMMY_READ, RZ_OTP_ADRRD);
+	readl(RZ_OTP_DATARD);
+
+	return 0;
+}
+

drivers/misc/rzg2l_otp.c line 91

Quoted 10 lines
drivers/misc/rzg2l_otp.c new file +10 -0
+static int rzg2l_otp_close(void)
+{
+	int i = 0;
+	u32 val;
+
+	rzg2l_otp_dummy_read();
+
+	val = readl(RZ_OTP_PWR);
+	val = val & OTP_PWR & OTP_ACCL;
+	writel(val, RZ_OTP_PWR);

clrsetbits_le32()

drivers/misc/rzg2l_otp.c line 93

Quoted 1 line
drivers/misc/rzg2l_otp.c new file +1 -0
+	while (readl(RZ_OTP_STR) & 1) {

readl_poll ...

[...]

#3 lore raw

Hello Marek,

Quoted 5 lines
Quoted 3 lines

+ * XXX: To enable direct fusing through U-Boot, the trusted-firmware must
+ * allow the non-secure world to perform fusing operations. This is controlled
+ * by the SYS_SLVACCCTL7 register.

Is there some SMC call to perform the fusing via TFA ?

No, there is a fusing driver in Renesas OP-TEE fork[1] but that's it.

Quoted 5 lines

drivers/misc/rzg2l_otp.c line 15

Quoted 3 lines

+ */

drivers/misc/rzg2l_otp.c new file +2 -0
+#define RZG2L_OTP_BASE      0x11860000
+#define RZG2L_SYSC_BASE     0x11020000

Can this be parsed out of DT ?

There is no entry for the OTP_BASE in the device-tree. There is one for the SYSC_BASE though.

I took the rest of your comments into account and sent a v2.

Thanks,

Mathieu

[1]: https://github.com/renesas-rz/rzg_optee-os

#4 lore raw

On 4/17/26 10:00 AM, Mathieu Othacehe wrote:

Hello Mathieu,

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

+ * XXX: To enable direct fusing through U-Boot, the trusted-firmware must
+ * allow the non-secure world to perform fusing operations. This is controlled
+ * by the SYS_SLVACCCTL7 register.

Is there some SMC call to perform the fusing via TFA ?

No, there is a fusing driver in Renesas OP-TEE fork[1] but that's it.

Quoted 8 lines
Quoted 5 lines

drivers/misc/rzg2l_otp.c line 15

Quoted 3 lines

+ */

drivers/misc/rzg2l_otp.c new file +2 -0
+#define RZG2L_OTP_BASE      0x11860000
+#define RZG2L_SYSC_BASE     0x11020000

Can this be parsed out of DT ?

There is no entry for the OTP_BASE in the device-tree. There is one for the SYSC_BASE though.

How about adding a new node into the DT which represents the fuse controller ?

Quoted 1 line

I took the rest of your comments into account and sent a v2.

Thank you

#5 lore raw

Hello Marek,

Quoted 1 line

How about adding a new node into the DT which represents the fuse controller ?

I did that in the v3 :)

Thanks,

Mathieu

#6 lore raw

On 4/22/26 11:37 AM, Mathieu Othacehe wrote:

Hello Mathieu,

Quoted 3 lines
Quoted 1 line

How about adding a new node into the DT which represents the fuse controller ?

I did that in the v3 :)

Thank you. I will have a look in the next few days.