Skip to contentSkip to conversation

nvmem: aspeed: Add read-only AST2600 OTP support

PATCH Superseded Prasanth Kumar Padarthi 3 participants 11 messages Nov 13 – Nov 21

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover nvmem: aspeed: Add read-only AST2600 OTP support

Add a root-only, read-only NVMEM provider for AST2600 OTP, with serialized controller access, bounded polling and configured secure-prefix checks. The driver adapts ASPEED's downstream read sequence and preserves its attribution.

Tested on ASRock Rack B650D4U (AST2600 A3), OpenBMC Linux 6.18.24:
- Repeated, paired and cross-pair reads matched.
- Four concurrent readers completed 40 matching reads.
- Bytes 8172..8183 matched a separate vendor-derived reader.
- Synthetic pre-MMIO timeout, failure latching and rebind recovery passed.

Host fault-injection tests also passed all 42 polling-timeout cases using simulated registers and virtual time.

Prasanth Kumar Padarthi (1):
nvmem: aspeed: Add read-only AST2600 OTP support

 MAINTAINERS                 |   1 +
 drivers/nvmem/Kconfig       |  12 ++
 drivers/nvmem/Makefile      |   1 +
 drivers/nvmem/ast2600-otp.c | 259 ++++++++++++++++++++++++++++++++++++
 4 files changed, 273 insertions(+)
 create mode 100644 drivers/nvmem/ast2600-otp.c
#1 lore raw

PATCH 1/1 nvmem: aspeed: Add read-only AST2600 OTP support

Expose permitted AST2600 OTP data through NVMEM using the existing SBC node. Serialize controller transactions, bound completion polling and reject reads into the configured secure prefix.

Adapt the read sequence from ASPEED's downstream driver, preserving its attribution. Register the driver for ASPEED review and restrict raw OTP access to root.

---
Tested on ASRock Rack B650D4U, AST2600 A3, OpenBMC Linux 6.18.24:
- Repeated, paired and cross-pair reads matched.
- Four concurrent readers completed 40 matching reads.
- Bytes 8172..8183 matched a separate vendor-derived reader.
- Synthetic pre-MMIO timeout, failure latching and rebind recovery passed. Host fault-injection tests passed all 42 polling-timeout cases.

 MAINTAINERS                 |   1 +
 drivers/nvmem/Kconfig       |  12 ++
 drivers/nvmem/Makefile      |   1 +
 drivers/nvmem/ast2600-otp.c | 259 ++++++++++++++++++++++++++++++++++++
 4 files changed, 273 insertions(+)
 create mode 100644 drivers/nvmem/ast2600-otp.c
MAINTAINERS +1 -0
index 93abbb3..c92ea8e 100644
@@ -2813,6 +2813,7 @@ F:	Documentation/devicetree/bindings/arm/aspeed/
 F:	arch/arm/boot/dts/aspeed/
 F:	arch/arm/mach-aspeed/
 F:	arch/arm64/boot/dts/aspeed/
+F:	drivers/nvmem/ast2600-otp.c
 N:	aspeed
 
 ARM/AXIADO ARCHITECTURE
drivers/nvmem/Kconfig +12 -0
index d2f5bb2..cdcd071 100644
@@ -164,6 +164,18 @@ config NVMEM_APPLE_SPMI
 	  This driver can also be built as a module. If so, the module
 	  will be called apple-nvmem-spmi.
 
+config NVMEM_ASPEED_AST2600_OTP
+	tristate "ASPEED AST2600 OTP support"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Read-only access to the AST2600 OTP data region. The configured
+	  secure prefix is not exposed. Fuse programming is not supported.
+	  The controller reads paired 32-bit words through command registers.
+	  Access to raw OTP data is restricted to root.
+
+	  If built as a module, the module will be called ast2600-otp.
+
 config NVMEM_BCM_OCOTP
 	tristate "Broadcom On-Chip OTP Controller support"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
drivers/nvmem/Makefile +1 -0
index 5e70bad..9fac69d 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES)	+= nvmem-apple-efuses.o
 nvmem-apple-efuses-y 			:= apple-efuses.o
 obj-$(CONFIG_NVMEM_APPLE_SPMI)		+= apple_nvmem_spmi.o
 apple_nvmem_spmi-y			:= apple-spmi-nvmem.o
+obj-$(CONFIG_NVMEM_ASPEED_AST2600_OTP)	+= ast2600-otp.o
 obj-$(CONFIG_NVMEM_BCM_OCOTP)		+= nvmem-bcm-ocotp.o
 nvmem-bcm-ocotp-y			:= bcm-ocotp.o
 obj-$(CONFIG_NVMEM_BRCM_NVRAM)		+= nvmem_brcm_nvram.o
drivers/nvmem/ast2600-otp.c new file +259 -0

259 lines not on this page · raw message

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.47.3
#2 lore raw
Quoted 3 lines · Prasanth Kumar Padarthi

Expose permitted AST2600 OTP data through NVMEM using the existing SBC node. Serialize controller transactions, bound completion polling and reject reads into the configured secure prefix.

This only repeats what the code does. Please explain *why*. Who uses the data and which cells?

Quoted 4 lines

Adapt the read sequence from ASPEED's downstream driver, preserving its attribution. Register the driver for ASPEED review and restrict raw OTP access to root.

If you mean the MAINTAINERS hunk, just say so.

Quoted 2 lines

No DCO Sign-off (neither from you nor Neal). And given that you've used the downstream driver as base it'd be cool if you can keep Neal as Co-developed-by in (with Neal's agreement).

Quoted 2 lines

---
Tested on ASRock Rack B650D4U, AST2600 A3, OpenBMC Linux 6.18.24:

Please test against the base commit you've used (i.e. 7.4-rc3). Using a vendor / OpenBMC tree here is not useful at all.

Quoted 31 lines

- Repeated, paired and cross-pair reads matched.
- Four concurrent readers completed 40 matching reads.
- Bytes 8172..8183 matched a separate vendor-derived reader.
- Synthetic pre-MMIO timeout, failure latching and rebind recovery passed. Host fault-injection tests passed all 42 polling-timeout cases.

  MAINTAINERS                 |   1 +
  drivers/nvmem/Kconfig       |  12 ++
  drivers/nvmem/Makefile      |   1 +
  drivers/nvmem/ast2600-otp.c | 259 ++++++++++++++++++++++++++++++++++++
  4 files changed, 273 insertions(+)

create mode 100644 drivers/nvmem/ast2600-otp.c

MAINTAINERS +1 -0
index 93abbb3..c92ea8e 100644
@@ -2813,6 +2813,7 @@ F:	Documentation/devicetree/bindings/arm/aspeed/
  F:	arch/arm/boot/dts/aspeed/
  F:	arch/arm/mach-aspeed/
  F:	arch/arm64/boot/dts/aspeed/
+F:	drivers/nvmem/ast2600-otp.c
  N:	aspeed
 
  ARM/AXIADO ARCHITECTURE
drivers/nvmem/Kconfig +0 -0
index d2f5bb2..cdcd071 100644
@@ -164,6 +164,18 @@ config NVMEM_APPLE_SPMI
  	  This driver can also be built as a module. If so, the module

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 174

Quoted 10 lines
drivers/nvmem/Kconfig +8 -0
  	  will be called apple-nvmem-spmi.
 
+config NVMEM_ASPEED_AST2600_OTP
+	tristate "ASPEED AST2600 OTP support"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Read-only access to the AST2600 OTP data region. The configured
+	  secure prefix is not exposed. Fuse programming is not supported.
+	  The controller reads paired 32-bit words through command registers.

This is implementation-specific and doesn't help whether to enable the option. Drop.

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 178

Quoted 4 lines
drivers/nvmem/Kconfig +4 -0
+	  Access to raw OTP data is restricted to root.
+
+	  If built as a module, the module will be called ast2600-otp.
+

"If unsure, select N"?

drivers/nvmem/Makefile obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o · line 26

Quoted 12 lines
drivers/nvmem/Kconfig +0 -0
  config NVMEM_BCM_OCOTP
  	tristate "Broadcom On-Chip OTP Controller support"
  	depends on ARCH_BCM_IPROC || COMPILE_TEST
drivers/nvmem/Makefile +1 -0
index 5e70bad..9fac69d 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES)	+= nvmem-apple-efuses.o
  nvmem-apple-efuses-y 			:= apple-efuses.o
  obj-$(CONFIG_NVMEM_APPLE_SPMI)		+= apple_nvmem_spmi.o
  apple_nvmem_spmi-y			:= apple-spmi-nvmem.o
+obj-$(CONFIG_NVMEM_ASPEED_AST2600_OTP)	+= ast2600-otp.o

Maybe call the file "nvmem-aspeed-otp" or so? Would be nice if we can extend the driver for AST2700 support later on.

Quoted 9 lines
drivers/nvmem/Makefile +0 -0
  obj-$(CONFIG_NVMEM_BCM_OCOTP)		+= nvmem-bcm-ocotp.o
  nvmem-bcm-ocotp-y			:= bcm-ocotp.o
  obj-$(CONFIG_NVMEM_BRCM_NVRAM)		+= nvmem_brcm_nvram.o
drivers/nvmem/ast2600-otp.c new file +0 -0
new file mode 100644
index 0000000..94b1225

drivers/nvmem/ast2600-otp.c line 6

Quoted 6 lines
drivers/nvmem/ast2600-otp.c new file +6 -0
@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) ASPEED Technology Inc.
+ *
+ * ASPEED AST2600 OTP Controller driver
+ * Read sequencing adapted from ASPEED's downstream ast2600-otp driver.

This comment feels unnecessary. It's already been said in the commit description.

drivers/nvmem/ast2600-otp.c line 9

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+ */
+
+#include <linux/align.h>

align could be removed if you use round_down() or word & ~1 maybe?

drivers/nvmem/ast2600-otp.c line 17

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>

You don't call any of_ functions. Replace with mod_devicetable.h.

drivers/nvmem/ast2600-otp.c line 19

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>

unused. devm_kzalloc comes through platform_device.h.

drivers/nvmem/ast2600-otp.c line 25

Quoted 6 lines
drivers/nvmem/ast2600-otp.c new file +6 -0
+#include <linux/string.h>
+
+#define AST2600_OTP_PROTECT_KEY		0x00
+#define AST2600_OTP_CMD			0x04
+#define AST2600_OTP_ADDR		0x10
+#define AST2600_OTP_STATUS		0x14

The SB Controller driver checks for the OTP_PROTECTED bit. What happens if OTP protection is enabled?

drivers/nvmem/ast2600-otp.c line 32

Quoted 7 lines
drivers/nvmem/ast2600-otp.c new file +7 -0
+#define AST2600_OTP_COMPARE_1		0x20
+#define AST2600_OTP_COMPARE_2		0x24
+
+#define AST2600_OTP_CMD_READ		0x23b1e361
+#define AST2600_OTP_CMD_WRITE_MODE	0x23b1e362
+#define AST2600_OTP_UNLOCK_KEY		0x349fe38a
+#define AST2600_OTP_STATUS_DONE		0x6

Describe the bits here. Either two BIT() or GENMASK(2, 1).

drivers/nvmem/ast2600-otp.c line 33

Quoted 1 line
drivers/nvmem/ast2600-otp.c new file +1 -0
+#define AST2600_OTP_TIMEOUT_US		100000

Where does this come from?

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+#define AST2600_OTP_DATA_WORDS		0x800
+#define AST2600_OTP_SIZE			(AST2600_OTP_DATA_WORDS * sizeof(u32))
+#define AST2600_OTP_CONF0_ADDR		0x800
+#define AST2600_OTP_CONF0_SEC_SIZE		GENMASK(21, 16)
+#define AST2600_OTP_SEC_SIZE_UNIT		(32 * sizeof(u32))
+
+struct ast2600_otp {
+	void __iomem *base;
+	/* Serialize the complete unlock, read and relock sequence. */
+	struct mutex lock;

drivers/nvmem/ast2600-otp.c line 54

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+	bool failed;
+};
+
+static int ast2600_otp_wait_complete(struct ast2600_otp *otp)
+{
+	u32 status;
+	int i, ret;
+
+	/* Allow the command to start before sampling the idle flags. */
+	udelay(1);

You could use read_poll_timeout too?

drivers/nvmem/ast2600-otp.c line 57

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+
+	/* Match the downstream sequence: observe both idle flags twice. */
+	for (i = 0; i < 2; i++) {

This is not a valid reason. Do you really have to poll twice? Is this an erratum? If so, please cite it.

drivers/nvmem/ast2600-otp.c line 65

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+		ret = readl_poll_timeout(otp->base + AST2600_OTP_STATUS,
+					 status,
+					 (status & AST2600_OTP_STATUS_DONE) ==
+					 AST2600_OTP_STATUS_DONE,
+					 1, AST2600_OTP_TIMEOUT_US);
+		if (ret) {
+			/* Do not reuse a controller with an outstanding command. */
+			otp->failed = true;

That'd disable the device on a single timeout. Do we really have to do this, or would it be enough to retry on the next access? If you want to keep it, then a dev_err() would be good instead of failing it silently.

Quoted 15 lines
drivers/nvmem/ast2600-otp.c new file +15 -0
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int ast2600_otp_prepare_read(struct ast2600_otp *otp)
+{
+	static const u32 mode_addresses[] = { 0x3000, 0x5000, 0x1000 };
+	int i, ret;
+
+	ret = ast2600_otp_wait_complete(otp);
+	if (ret)
+		return ret;

drivers/nvmem/ast2600-otp.c line 90

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+	/*
+	 * Restore the macro's default read mode, as in otp_soak(ctx, 0).
+	 * These writes target volatile mode registers, not OTP fuse cells.
+	 * No fuse programming command or programming timing is used.
+	 */
+	for (i = 0; i < ARRAY_SIZE(mode_addresses); i++) {
+		writel(mode_addresses[i], otp->base + AST2600_OTP_ADDR);
+		writel(0, otp->base + AST2600_OTP_COMPARE_1);
+		writel(AST2600_OTP_CMD_WRITE_MODE, otp->base + AST2600_OTP_CMD);

Setting the OTP back to default doesn't need write mode if I understand the datasheet correctly.

Quoted 7 lines
drivers/nvmem/ast2600-otp.c new file +7 -0
+		ret = ast2600_otp_wait_complete(otp);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}

drivers/nvmem/ast2600-otp.c line 107

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+static int ast2600_otp_read_pair(struct ast2600_otp *otp,
+				 unsigned int aligned_word,
+				 u32 *word0, u32 *word1)
+{
+	int ret;
+
+	/* The hardware reads two words starting at an even word index. */
+	if ((aligned_word & 1) || aligned_word >= AST2600_OTP_DATA_WORDS)
+		return -EINVAL;

You're already passing an aligned index everywhere which makes this code redundant. It also blocks the read for CONF0, so please drop this check and use read_pair() for CONF0 too.

Quoted 22 lines
drivers/nvmem/ast2600-otp.c new file +22 -0
+
+	writel(aligned_word, otp->base + AST2600_OTP_ADDR);
+
+	writel(AST2600_OTP_CMD_READ,
+	       otp->base + AST2600_OTP_CMD);
+
+	ret = ast2600_otp_wait_complete(otp);
+	if (ret)
+		return ret;
+
+	*word0 = readl(otp->base + AST2600_OTP_COMPARE_1);
+	*word1 = readl(otp->base + AST2600_OTP_COMPARE_2);
+
+	return 0;
+}
+
+static int ast2600_otp_read(void *context, unsigned int offset,
+			    void *val, size_t bytes)
+{
+	struct ast2600_otp *otp = context;
+	u8 *buf = val;
+	unsigned int word_index;

drivers/nvmem/ast2600-otp.c line 139

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+	unsigned int aligned_word;
+	unsigned int secure_size;
+	__le32 pair[2];
+	u32 conf0;
+	u32 word0, word1;
+	size_t chunk, skip;
+	int ret;
+
+	if (!bytes)
+		return -EINVAL;

OTP could be empty too?

drivers/nvmem/ast2600-otp.c line 148

Quoted 9 lines
drivers/nvmem/ast2600-otp.c new file +9 -0
+
+	if (offset % sizeof(u32) || bytes % sizeof(u32))
+		return -EINVAL;
+
+	if (offset >= AST2600_OTP_SIZE ||
+	    bytes > AST2600_OTP_SIZE - offset)
+		return -EINVAL;
+
+	mutex_lock(&otp->lock);

guard(mutex)(&priv->lock); ? Requires <linux/cleanup.h>.

drivers/nvmem/ast2600-otp.c line 159

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+	if (otp->failed) {
+		ret = -EIO;
+		goto out_unlock;
+	}
+
+	writel(AST2600_OTP_UNLOCK_KEY, otp->base + AST2600_OTP_PROTECT_KEY);
+
+	ret = ast2600_otp_prepare_read(otp);
+	if (ret)
+		goto out_lock;

The secure region size is fixed once programmed. Maybe read it once in probe instead of on every access? With nvmem_keepout, this would clean up the read path a bit.

drivers/nvmem/ast2600-otp.c line 170

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+	/* Configuration word 0 describes the unreadable secure data prefix. */
+	writel(AST2600_OTP_CONF0_ADDR, otp->base + AST2600_OTP_ADDR);
+	writel(AST2600_OTP_CMD_READ, otp->base + AST2600_OTP_CMD);
+	ret = ast2600_otp_wait_complete(otp);
+	if (ret)
+		goto out_lock;
+
+	conf0 = readl(otp->base + AST2600_OTP_COMPARE_1);
+	secure_size = FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) *
+		      AST2600_OTP_SEC_SIZE_UNIT;

You can also keep out the secure region by using nvmem_keepout.

Quoted 14 lines
drivers/nvmem/ast2600-otp.c new file +14 -0
+	/* Conservatively deny the entire secure prefix, including its header. */
+	if (offset < secure_size) {
+		ret = -EACCES;
+		goto out_lock;
+	}
+
+	while (bytes) {
+		word_index = offset / sizeof(u32);
+		aligned_word = ALIGN_DOWN(word_index, 2);
+
+		ret = ast2600_otp_read_pair(otp, aligned_word,
+					    &word0, &word1);
+		if (ret)
+			goto out_lock;

drivers/nvmem/ast2600-otp.c line 194

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+		pair[0] = cpu_to_le32(word0);
+		pair[1] = cpu_to_le32(word1);
+		skip = (word_index - aligned_word) * sizeof(u32);
+		chunk = min(bytes, sizeof(pair) - skip);
+
+		memcpy(buf, (u8 *)pair + skip, chunk);
+		buf += chunk;
+		offset += chunk;
+		bytes -= chunk;

NVMEM already returns the data in the correct order if I see this right. You can store the readl() results directly into a u32*buf var. That'd make the pair/skip/chunk code and endianness conversion unnecessary.

drivers/nvmem/ast2600-otp.c line 202

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+	}
+
+	ret = 0;
+
+out_lock:
+	writel(0, otp->base + AST2600_OTP_PROTECT_KEY);
+	/* Flush the protection write before another reader takes the mutex. */
+	readl(otp->base + AST2600_OTP_PROTECT_KEY);

for what are you reading the otp key register here?

drivers/nvmem/ast2600-otp.c line 212

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+out_unlock:
+	mutex_unlock(&otp->lock);
+	return ret;
+}
+
+static int ast2600_otp_probe(struct platform_device *pdev)
+{
+	struct nvmem_config config = {};
+	struct nvmem_device *nvmem;
+	struct ast2600_otp *otp;

Can we name this priv maybe?

drivers/nvmem/ast2600-otp.c line 214

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+
+	otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL);

Maybe assign &pdev->dev as struct device * variable and use that one instead?

drivers/nvmem/ast2600-otp.c line 222

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+	if (!otp)
+		return -ENOMEM;
+
+	otp->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(otp->base))
+		return PTR_ERR(otp->base);
+
+	mutex_init(&otp->lock);

devm_mutex_init?

drivers/nvmem/ast2600-otp.c line 224

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+
+	config.dev = &pdev->dev;

Same here with the var.

drivers/nvmem/ast2600-otp.c line 234

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+	config.name = "ast2600-otp";
+	config.id = NVMEM_DEVID_AUTO;
+	config.owner = THIS_MODULE;
+	config.type = NVMEM_TYPE_OTP;
+	config.read_only = true;
+	config.root_only = true;
+	config.word_size = sizeof(u32);
+	config.stride = sizeof(u32);
+	config.size = AST2600_OTP_SIZE;
+	config.reg_read = ast2600_otp_read;

These can already be set in the config struct before.

drivers/nvmem/ast2600-otp.c line 237

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+	config.priv = otp;
+
+	nvmem = devm_nvmem_register(&pdev->dev, &config);

And here.

drivers/nvmem/ast2600-otp.c line 242

Quoted 5 lines
drivers/nvmem/ast2600-otp.c new file +5 -0
+	return PTR_ERR_OR_ZERO(nvmem);
+}
+
+static const struct of_device_id ast2600_otp_of_match[] = {
+	{ .compatible = "aspeed,ast2600-sbc" },

The SB Controller driver has "additionalProperties: false" set and doesn't allow nvmem properties.

Please add "$ref: /schemas/nvmem/nvmem.yaml#" and "unevaluatedProperties: false" as a separate patch.

Tan

Quoted 18 lines
drivers/nvmem/ast2600-otp.c new file +17 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ast2600_otp_of_match);
+
+static struct platform_driver ast2600_otp_driver = {
+	.probe = ast2600_otp_probe,
+	.driver = {
+		.name = "ast2600-otp",
+		.of_match_table = ast2600_otp_of_match,
+	},
+};
+module_platform_driver(ast2600_otp_driver);
+
+MODULE_AUTHOR("Neal Liu <[email protected]>");
+MODULE_AUTHOR("Prasanth Kumar Padarthi <[email protected]>");
+MODULE_DESCRIPTION("ASPEED AST2600 read-only OTP NVMEM driver");
+MODULE_LICENSE("GPL");

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

author
#3 lore raw

Hi Tan,

Thank you for the review. I am preparing v2 with these MOdifications:
- Renamed the driver to nvmem-aspeed-otp.c; updated Kconfig, headers, and attribution comments.
- Used GENMASK(2, 1) and read_poll_timeout() with an initial delay.
- Reused read_pair() for CONF0 and removed its redundant bounds check.
- Moved secure-prefix initialization into probe and registered an NVMEM keepout.
- Simplified word copying using put_unaligned_le32() to preserve byte order and support unaligned buffers.
- Added scoped mutex locking, devm_mutex_init(), and the probe cleanups.
- Added timeout error logging and clarified the SEC00 completion-flush readback.
- Prepared the NVMEM binding update as a separate patch.
I also tested the updated driver on the B650D4U, AST2600 A3, running Linux 7.4-rc1, base commit 6628e7d4c. The test used the working board DTB and OpenBMC initramfs, with temporary diagnostics enabled.

The provider registered successfully. A 12-byte read at offsets 8172–8183, covering an odd starting word and a pair boundary, completed successfully and matched the saved vendor-derived reference.

I have requested ASPEED clarification separately on double completion polling, timeout recovery/value, mode-register initialization, and SEC54 interpretation. These decisions remain pending; the current 100 ms timeout is an engineering choice.

I will finalize v2 after resolving those points and validating the code without temporary diagnostics.

Thanks,
Prasanth Kumar Padarthi

Quoted 461 lines · Tan Siewert
Quoted 3 lines · Prasanth Kumar Padarthi

Expose permitted AST2600 OTP data through NVMEM using the existing SBC node. Serialize controller transactions, bound completion polling and reject reads into the configured secure prefix.

This only repeats what the code does. Please explain *why*. Who uses the data and which cells?

Quoted 4 lines

Adapt the read sequence from ASPEED's downstream driver, preserving its attribution. Register the driver for ASPEED review and restrict raw OTP access to root.

If you mean the MAINTAINERS hunk, just say so.

Quoted 2 lines

No DCO Sign-off (neither from you nor Neal). And given that you've used the downstream driver as base it'd be cool if you can keep Neal as Co-developed-by in (with Neal's agreement).

Quoted 2 lines

---
Tested on ASRock Rack B650D4U, AST2600 A3, OpenBMC Linux 6.18.24:

Please test against the base commit you've used (i.e. 7.4-rc3). Using a vendor / OpenBMC tree here is not useful at all.

Quoted 31 lines

- Repeated, paired and cross-pair reads matched.
- Four concurrent readers completed 40 matching reads.
- Bytes 8172..8183 matched a separate vendor-derived reader.
- Synthetic pre-MMIO timeout, failure latching and rebind recovery passed. Host fault-injection tests passed all 42 polling-timeout cases.

  MAINTAINERS                 |   1 +
  drivers/nvmem/Kconfig       |  12 ++
  drivers/nvmem/Makefile      |   1 +
  drivers/nvmem/ast2600-otp.c | 259 ++++++++++++++++++++++++++++++++++++
  4 files changed, 273 insertions(+)

create mode 100644 drivers/nvmem/ast2600-otp.c

MAINTAINERS +1 -0
index 93abbb3..c92ea8e 100644
@@ -2813,6 +2813,7 @@ F:      Documentation/devicetree/bindings/arm/aspeed/
  F:  arch/arm/boot/dts/aspeed/
  F:  arch/arm/mach-aspeed/
  F:  arch/arm64/boot/dts/aspeed/
+F:   drivers/nvmem/ast2600-otp.c
  N:  aspeed
 
  ARM/AXIADO ARCHITECTURE
drivers/nvmem/Kconfig +0 -0
index d2f5bb2..cdcd071 100644
@@ -164,6 +164,18 @@ config NVMEM_APPLE_SPMI
        This driver can also be built as a module. If so, the module

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 174

Quoted 10 lines
drivers/nvmem/Kconfig +8 -0
        will be called apple-nvmem-spmi.
 
+config NVMEM_ASPEED_AST2600_OTP
+     tristate "ASPEED AST2600 OTP support"
+     depends on ARCH_ASPEED || COMPILE_TEST
+     depends on HAS_IOMEM
+     help
+       Read-only access to the AST2600 OTP data region. The configured
+       secure prefix is not exposed. Fuse programming is not supported.
+       The controller reads paired 32-bit words through command registers.

This is implementation-specific and doesn't help whether to enable the option. Drop.

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 178

Quoted 4 lines
drivers/nvmem/Kconfig +4 -0
+       Access to raw OTP data is restricted to root.
+
+       If built as a module, the module will be called ast2600-otp.
+

"If unsure, select N"?

drivers/nvmem/Makefile obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o · line 26

Quoted 12 lines
drivers/nvmem/Kconfig +0 -0
  config NVMEM_BCM_OCOTP
      tristate "Broadcom On-Chip OTP Controller support"
      depends on ARCH_BCM_IPROC || COMPILE_TEST
drivers/nvmem/Makefile +1 -0
index 5e70bad..9fac69d 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES)    += nvmem-apple-efuses.o
  nvmem-apple-efuses-y                        := apple-efuses.o
  obj-$(CONFIG_NVMEM_APPLE_SPMI)              += apple_nvmem_spmi.o
  apple_nvmem_spmi-y                  := apple-spmi-nvmem.o
+obj-$(CONFIG_NVMEM_ASPEED_AST2600_OTP)       += ast2600-otp.o

Maybe call the file "nvmem-aspeed-otp" or so? Would be nice if we can extend the driver for AST2700 support later on.

Quoted 9 lines
drivers/nvmem/Makefile +0 -0
  obj-$(CONFIG_NVMEM_BCM_OCOTP)               += nvmem-bcm-ocotp.o
  nvmem-bcm-ocotp-y                   := bcm-ocotp.o
  obj-$(CONFIG_NVMEM_BRCM_NVRAM)              += nvmem_brcm_nvram.o
drivers/nvmem/ast2600-otp.c new file +0 -0
new file mode 100644
index 0000000..94b1225

drivers/nvmem/ast2600-otp.c line 6

Quoted 6 lines
drivers/nvmem/ast2600-otp.c new file +6 -0
@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) ASPEED Technology Inc.
+ *
+ * ASPEED AST2600 OTP Controller driver
+ * Read sequencing adapted from ASPEED's downstream ast2600-otp driver.

This comment feels unnecessary. It's already been said in the commit description.

drivers/nvmem/ast2600-otp.c line 9

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+ */
+
+#include <linux/align.h>

align could be removed if you use round_down() or word & ~1 maybe?

drivers/nvmem/ast2600-otp.c line 17

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>

You don't call any of_ functions. Replace with mod_devicetable.h.

drivers/nvmem/ast2600-otp.c line 19

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+#include <linux/platform_device.h>
+#include <linux/slab.h>

unused. devm_kzalloc comes through platform_device.h.

drivers/nvmem/ast2600-otp.c line 25

Quoted 6 lines
drivers/nvmem/ast2600-otp.c new file +6 -0
+#include <linux/string.h>
+
+#define AST2600_OTP_PROTECT_KEY              0x00
+#define AST2600_OTP_CMD                      0x04
+#define AST2600_OTP_ADDR             0x10
+#define AST2600_OTP_STATUS           0x14

The SB Controller driver checks for the OTP_PROTECTED bit. What happens if OTP protection is enabled?

drivers/nvmem/ast2600-otp.c line 32

Quoted 7 lines
drivers/nvmem/ast2600-otp.c new file +7 -0
+#define AST2600_OTP_COMPARE_1                0x20
+#define AST2600_OTP_COMPARE_2                0x24
+
+#define AST2600_OTP_CMD_READ         0x23b1e361
+#define AST2600_OTP_CMD_WRITE_MODE   0x23b1e362
+#define AST2600_OTP_UNLOCK_KEY               0x349fe38a
+#define AST2600_OTP_STATUS_DONE              0x6

Describe the bits here. Either two BIT() or GENMASK(2, 1).

drivers/nvmem/ast2600-otp.c line 33

Quoted 1 line
drivers/nvmem/ast2600-otp.c new file +1 -0
+#define AST2600_OTP_TIMEOUT_US               100000

Where does this come from?

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+#define AST2600_OTP_DATA_WORDS               0x800
+#define AST2600_OTP_SIZE                     (AST2600_OTP_DATA_WORDS * sizeof(u32))
+#define AST2600_OTP_CONF0_ADDR               0x800
+#define AST2600_OTP_CONF0_SEC_SIZE           GENMASK(21, 16)
+#define AST2600_OTP_SEC_SIZE_UNIT            (32 * sizeof(u32))
+
+struct ast2600_otp {
+     void __iomem *base;
+     /* Serialize the complete unlock, read and relock sequence. */
+     struct mutex lock;

drivers/nvmem/ast2600-otp.c line 54

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+     bool failed;
+};
+
+static int ast2600_otp_wait_complete(struct ast2600_otp *otp)
+{
+     u32 status;
+     int i, ret;
+
+     /* Allow the command to start before sampling the idle flags. */
+     udelay(1);

You could use read_poll_timeout too?

drivers/nvmem/ast2600-otp.c line 57

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+
+     /* Match the downstream sequence: observe both idle flags twice. */
+     for (i = 0; i < 2; i++) {

This is not a valid reason. Do you really have to poll twice? Is this an erratum? If so, please cite it.

drivers/nvmem/ast2600-otp.c line 65

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+             ret = readl_poll_timeout(otp->base + AST2600_OTP_STATUS,
+                                      status,
+                                      (status & AST2600_OTP_STATUS_DONE) ==
+                                      AST2600_OTP_STATUS_DONE,
+                                      1, AST2600_OTP_TIMEOUT_US);
+             if (ret) {
+                     /* Do not reuse a controller with an outstanding command. */
+                     otp->failed = true;

That'd disable the device on a single timeout. Do we really have to do this, or would it be enough to retry on the next access? If you want to keep it, then a dev_err() would be good instead of failing it silently.

Quoted 15 lines
drivers/nvmem/ast2600-otp.c new file +15 -0
+                     return ret;
+             }
+     }
+
+     return 0;
+}
+
+static int ast2600_otp_prepare_read(struct ast2600_otp *otp)
+{
+     static const u32 mode_addresses[] = { 0x3000, 0x5000, 0x1000 };
+     int i, ret;
+
+     ret = ast2600_otp_wait_complete(otp);
+     if (ret)
+             return ret;

drivers/nvmem/ast2600-otp.c line 90

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+     /*
+      * Restore the macro's default read mode, as in otp_soak(ctx, 0).
+      * These writes target volatile mode registers, not OTP fuse cells.
+      * No fuse programming command or programming timing is used.
+      */
+     for (i = 0; i < ARRAY_SIZE(mode_addresses); i++) {
+             writel(mode_addresses[i], otp->base + AST2600_OTP_ADDR);
+             writel(0, otp->base + AST2600_OTP_COMPARE_1);
+             writel(AST2600_OTP_CMD_WRITE_MODE, otp->base + AST2600_OTP_CMD);

Setting the OTP back to default doesn't need write mode if I understand the datasheet correctly.

Quoted 7 lines
drivers/nvmem/ast2600-otp.c new file +7 -0
+             ret = ast2600_otp_wait_complete(otp);
+             if (ret)
+                     return ret;
+     }
+
+     return 0;
+}

drivers/nvmem/ast2600-otp.c line 107

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+static int ast2600_otp_read_pair(struct ast2600_otp *otp,
+                              unsigned int aligned_word,
+                              u32 *word0, u32 *word1)
+{
+     int ret;
+
+     /* The hardware reads two words starting at an even word index. */
+     if ((aligned_word & 1) || aligned_word >= AST2600_OTP_DATA_WORDS)
+             return -EINVAL;

You're already passing an aligned index everywhere which makes this code redundant. It also blocks the read for CONF0, so please drop this check and use read_pair() for CONF0 too.

Quoted 22 lines
drivers/nvmem/ast2600-otp.c new file +22 -0
+
+     writel(aligned_word, otp->base + AST2600_OTP_ADDR);
+
+     writel(AST2600_OTP_CMD_READ,
+            otp->base + AST2600_OTP_CMD);
+
+     ret = ast2600_otp_wait_complete(otp);
+     if (ret)
+             return ret;
+
+     *word0 = readl(otp->base + AST2600_OTP_COMPARE_1);
+     *word1 = readl(otp->base + AST2600_OTP_COMPARE_2);
+
+     return 0;
+}
+
+static int ast2600_otp_read(void *context, unsigned int offset,
+                         void *val, size_t bytes)
+{
+     struct ast2600_otp *otp = context;
+     u8 *buf = val;
+     unsigned int word_index;

drivers/nvmem/ast2600-otp.c line 139

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+     unsigned int aligned_word;
+     unsigned int secure_size;
+     __le32 pair[2];
+     u32 conf0;
+     u32 word0, word1;
+     size_t chunk, skip;
+     int ret;
+
+     if (!bytes)
+             return -EINVAL;

OTP could be empty too?

drivers/nvmem/ast2600-otp.c line 148

Quoted 9 lines
drivers/nvmem/ast2600-otp.c new file +9 -0
+
+     if (offset % sizeof(u32) || bytes % sizeof(u32))
+             return -EINVAL;
+
+     if (offset >= AST2600_OTP_SIZE ||
+         bytes > AST2600_OTP_SIZE - offset)
+             return -EINVAL;
+
+     mutex_lock(&otp->lock);

guard(mutex)(&priv->lock); ? Requires <linux/cleanup.h>.

drivers/nvmem/ast2600-otp.c line 159

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+     if (otp->failed) {
+             ret = -EIO;
+             goto out_unlock;
+     }
+
+     writel(AST2600_OTP_UNLOCK_KEY, otp->base + AST2600_OTP_PROTECT_KEY);
+
+     ret = ast2600_otp_prepare_read(otp);
+     if (ret)
+             goto out_lock;

The secure region size is fixed once programmed. Maybe read it once in probe instead of on every access? With nvmem_keepout, this would clean up the read path a bit.

drivers/nvmem/ast2600-otp.c line 170

Quoted 11 lines
drivers/nvmem/ast2600-otp.c new file +11 -0
+
+     /* Configuration word 0 describes the unreadable secure data prefix. */
+     writel(AST2600_OTP_CONF0_ADDR, otp->base + AST2600_OTP_ADDR);
+     writel(AST2600_OTP_CMD_READ, otp->base + AST2600_OTP_CMD);
+     ret = ast2600_otp_wait_complete(otp);
+     if (ret)
+             goto out_lock;
+
+     conf0 = readl(otp->base + AST2600_OTP_COMPARE_1);
+     secure_size = FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) *
+                   AST2600_OTP_SEC_SIZE_UNIT;

You can also keep out the secure region by using nvmem_keepout.

Quoted 14 lines
drivers/nvmem/ast2600-otp.c new file +14 -0
+     /* Conservatively deny the entire secure prefix, including its header. */
+     if (offset < secure_size) {
+             ret = -EACCES;
+             goto out_lock;
+     }
+
+     while (bytes) {
+             word_index = offset / sizeof(u32);
+             aligned_word = ALIGN_DOWN(word_index, 2);
+
+             ret = ast2600_otp_read_pair(otp, aligned_word,
+                                         &word0, &word1);
+             if (ret)
+                     goto out_lock;

drivers/nvmem/ast2600-otp.c line 194

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+
+             pair[0] = cpu_to_le32(word0);
+             pair[1] = cpu_to_le32(word1);
+             skip = (word_index - aligned_word) * sizeof(u32);
+             chunk = min(bytes, sizeof(pair) - skip);
+
+             memcpy(buf, (u8 *)pair + skip, chunk);
+             buf += chunk;
+             offset += chunk;
+             bytes -= chunk;

NVMEM already returns the data in the correct order if I see this right. You can store the readl() results directly into a u32*buf var. That'd make the pair/skip/chunk code and endianness conversion unnecessary.

drivers/nvmem/ast2600-otp.c line 202

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+     }
+
+     ret = 0;
+
+out_lock:
+     writel(0, otp->base + AST2600_OTP_PROTECT_KEY);
+     /* Flush the protection write before another reader takes the mutex. */
+     readl(otp->base + AST2600_OTP_PROTECT_KEY);

for what are you reading the otp key register here?

drivers/nvmem/ast2600-otp.c line 212

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+out_unlock:
+     mutex_unlock(&otp->lock);
+     return ret;
+}
+
+static int ast2600_otp_probe(struct platform_device *pdev)
+{
+     struct nvmem_config config = {};
+     struct nvmem_device *nvmem;
+     struct ast2600_otp *otp;

Can we name this priv maybe?

drivers/nvmem/ast2600-otp.c line 214

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+
+     otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL);

Maybe assign &pdev->dev as struct device * variable and use that one instead?

drivers/nvmem/ast2600-otp.c line 222

Quoted 8 lines
drivers/nvmem/ast2600-otp.c new file +8 -0
+     if (!otp)
+             return -ENOMEM;
+
+     otp->base = devm_platform_ioremap_resource(pdev, 0);
+     if (IS_ERR(otp->base))
+             return PTR_ERR(otp->base);
+
+     mutex_init(&otp->lock);

devm_mutex_init?

drivers/nvmem/ast2600-otp.c line 224

Quoted 2 lines
drivers/nvmem/ast2600-otp.c new file +2 -0
+
+     config.dev = &pdev->dev;

Same here with the var.

drivers/nvmem/ast2600-otp.c line 234

Quoted 10 lines
drivers/nvmem/ast2600-otp.c new file +10 -0
+     config.name = "ast2600-otp";
+     config.id = NVMEM_DEVID_AUTO;
+     config.owner = THIS_MODULE;
+     config.type = NVMEM_TYPE_OTP;
+     config.read_only = true;
+     config.root_only = true;
+     config.word_size = sizeof(u32);
+     config.stride = sizeof(u32);
+     config.size = AST2600_OTP_SIZE;
+     config.reg_read = ast2600_otp_read;

These can already be set in the config struct before.

drivers/nvmem/ast2600-otp.c line 237

Quoted 3 lines
drivers/nvmem/ast2600-otp.c new file +3 -0
+     config.priv = otp;
+
+     nvmem = devm_nvmem_register(&pdev->dev, &config);

And here.

drivers/nvmem/ast2600-otp.c line 242

Quoted 5 lines
drivers/nvmem/ast2600-otp.c new file +5 -0
+     return PTR_ERR_OR_ZERO(nvmem);
+}
+
+static const struct of_device_id ast2600_otp_of_match[] = {
+     { .compatible = "aspeed,ast2600-sbc" },

The SB Controller driver has "additionalProperties: false" set and doesn't allow nvmem properties.

Please add "$ref: /schemas/nvmem/nvmem.yaml#" and "unevaluatedProperties: false" as a separate patch.

Tan

Quoted 18 lines
drivers/nvmem/ast2600-otp.c new file +17 -0
+     { }
+};
+MODULE_DEVICE_TABLE(of, ast2600_otp_of_match);
+
+static struct platform_driver ast2600_otp_driver = {
+     .probe = ast2600_otp_probe,
+     .driver = {
+             .name = "ast2600-otp",
+             .of_match_table = ast2600_otp_of_match,
+     },
+};
+module_platform_driver(ast2600_otp_driver);
+
+MODULE_AUTHOR("Neal Liu <[email protected]>");
+MODULE_AUTHOR("Prasanth Kumar Padarthi <[email protected]>");
+MODULE_DESCRIPTION("ASPEED AST2600 read-only OTP NVMEM driver");
+MODULE_LICENSE("GPL");

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

#4 lore raw

v2 cover nvmem: aspeed: Add read-only AST2600 OTP support

In reply to Prasanth Kumar Padarthi

Hi,

This series exposes permitted AST2600 OTP data through root-only NVMEM for userspace diagnostics using raw offsets. It adds the SBC NVMEM binding and a read-only driver adapted from ASPEED's downstream driver.

Changes since v1:
- Add the separate binding patch and rename the driver nvmem-aspeed-otp.
- Poll once after a 1-us delay; retain the 100-ms timeout and log failures.
- Initialize read mode once at probe and stop commands after a timeout.
- Use a fixed secure-prefix keepout and check the live SEC54 range on reads.
- Simplify copying, locking, configuration and Kconfig help.

Tested on B650D4U (AST2600 A3), OpenBMC Linux 6.18.24 and upstream-based Linux 7.4-rc1: repeated reads, cross-pair reads and 40 reads from four concurrent readers passed. A 12-byte range matched the saved ASPEED-derived reference fingerprint. The 7.4-rc1 RAM boot used the working OpenBMC DTB and initramfs and also passed the final-pair comparison. ARM zImage built successfully.

AI assisted with driver revisions, validation tooling and patch text, using the downstream code, review comments and Neal's hardware guidance. Hardware tests were run by the submitter.

Prasanth Kumar Padarthi (2):
dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider
nvmem: aspeed: Add read-only AST2600 OTP support

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

#5 lore raw

PATCH v2 1/2 dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider

The AST2600 secure boot controller also provides access to its OTP data region. Reference the NVMEM provider schema and use unevaluatedProperties so common NVMEM properties are accepted while unknown properties remain rejected. Describe the cell offset address space and extend the example with the read-only property.

---

Documentation/devicetree/bindings/arm/aspeed/aspeed,sbc.yaml +8 -2
index b8c5cacb0..d8e19c224 100644
@@ -13,7 +13,12 @@ maintainers:
 
 description: |
   The ASPEED SoCs have a register bank for interacting with the secure boot
-  controller.
+  controller. The controller also provides access to the OTP data region
+  through NVMEM. NVMEM cell offsets are byte offsets within the OTP data
+  region, not offsets within the controller register bank.
+
+allOf:
+  - $ref: /schemas/nvmem/nvmem.yaml#
 
 properties:
   compatible:
@@ -27,11 +32,12 @@ required:
   - compatible
   - reg
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   - |
     sbc: secure-boot-controller@1e6f2000 {
             compatible = "aspeed,ast2600-sbc";
             reg = <0x1e6f2000 0x1000>;
+            read-only;
     };
#6 lore raw

PATCH v2 2/2 nvmem: aspeed: Add read-only AST2600 OTP support

In reply to Prasanth Kumar Padarthi

Provide root-only NVMEM access for userspace diagnostics comparing OTP ranges with vendor-derived reference data during BMC bring-up. The consumer uses raw offsets rather than named cells or a private ioctl.

Initialize read mode once at probe and mask the fixed secure prefix using an NVMEM keepout. Recheck SEC54 on each controller read and reject requests into an extended protected prefix. Programming protection does not block reads. Serialize transactions and stop issuing commands after a timeout. Use a 1-us initial polling delay and a generous 100-ms timeout.

Adapt the read sequence from ASPEED's downstream driver, preserving its attribution, and add the driver to the ASPEED MAINTAINERS entry.

Tested on ASRock Rack B650D4U (AST2600 A3) with Linux 7.4-rc1 and OpenBMC Linux 6.18.24. Repeated reads, cross-pair reads and four concurrent readers (40 reads) passed. The selected 12-byte range matched a saved ASPEED-derived reference. The 7.4-rc1 run used a RAM-booted kernel with the working OpenBMC board DTB and initramfs; its final-pair check also passed.

---
 MAINTAINERS                      |    1 
 drivers/nvmem/Kconfig            |   13 ++
 drivers/nvmem/Makefile           |    1 
 drivers/nvmem/nvmem-aspeed-otp.c |  297 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 312 insertions(+)
MAINTAINERS +1 -0
index 93abbb315..5415e2be4 100644
@@ -2813,6 +2813,7 @@ F:	Documentation/devicetree/bindings/arm/aspeed/
 F:	arch/arm/boot/dts/aspeed/
 F:	arch/arm/mach-aspeed/
 F:	arch/arm64/boot/dts/aspeed/
+F:	drivers/nvmem/nvmem-aspeed-otp.c
 N:	aspeed
 
 ARM/AXIADO ARCHITECTURE
drivers/nvmem/Kconfig +13 -0
index d2f5bb236..e6445262b 100644
@@ -164,6 +164,19 @@ config NVMEM_APPLE_SPMI
 	  This driver can also be built as a module. If so, the module
 	  will be called apple-nvmem-spmi.
 
+config NVMEM_ASPEED_AST2600_OTP
+	tristate "ASPEED AST2600 OTP support"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Say Y here to enable read-only access to the OTP data region
+	  on ASPEED AST2600 BMCs through the NVMEM interface.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-aspeed-otp.
+
+	  If unsure, say N.
+
 config NVMEM_BCM_OCOTP
 	tristate "Broadcom On-Chip OTP Controller support"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
drivers/nvmem/Makefile +1 -0
index 5e70bad9f..f09b7a8a5 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES)	+= nvmem-apple-efuses.o
 nvmem-apple-efuses-y 			:= apple-efuses.o
 obj-$(CONFIG_NVMEM_APPLE_SPMI)		+= apple_nvmem_spmi.o
 apple_nvmem_spmi-y			:= apple-spmi-nvmem.o
+obj-$(CONFIG_NVMEM_ASPEED_AST2600_OTP)	+= nvmem-aspeed-otp.o
 obj-$(CONFIG_NVMEM_BCM_OCOTP)		+= nvmem-bcm-ocotp.o
 nvmem-bcm-ocotp-y			:= bcm-ocotp.o
 obj-$(CONFIG_NVMEM_BRCM_NVRAM)		+= nvmem_brcm_nvram.o
drivers/nvmem/nvmem-aspeed-otp.c new file +297 -0

297 lines not on this page · raw message

#7 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] nvmem: aspeed: mix of guard(mutex) and goto cleanup in OTP helpers --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] nvmem: aspeed: mix of guard(mutex) and goto cleanup in OTP helpers
--

commit 34b51f06ae272e72e9e379fc1f5bbb493333d824
Author: Prasanth Kumar Padarthi <[email protected]>

nvmem: aspeed: Add read-only AST2600 OTP support

This commit adds a read-only NVMEM provider driver for the ASPEED AST2600 OTP controller, masking the secure prefix with an NVMEM keepout and serializing hardware unlock, read, and relock transactions.

Quoted 6 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +0 -0
new file mode 100644
index 0000000000000..8a433dccaaaf0
@@ -0,0 +1,297 @@

[ ... ]

Quoted 101 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +101 -0
+static int ast2600_otp_init_keepout(struct ast2600_otp *priv)
+{
+	u32 conf0, unused;
+	int ret;
+
+	guard(mutex)(&priv->lock);
+
+	writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
+	if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
+		ret = -EACCES;
+		goto out_lock;
+	}
+
+	ret = ast2600_otp_init_read_mode(priv);
+	if (ret)
+		goto out_lock;
+
+	ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR,
+				    &conf0, &unused);
+	if (ret)
+		goto out_lock;
+
+	priv->secure_keepout.start = 0;
+	priv->secure_keepout.end =
+		FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) *
+		AST2600_OTP_SEC_SIZE_UNIT;
+	priv->secure_keepout.value = 0;
+
+out_lock:
+	writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
+	/* Complete the lock write before returning and releasing the mutex. */
+	readl(priv->base + AST2600_OTP_PROTECT_KEY);
+	return ret;
+}
+
+static int ast2600_otp_read(void *context, unsigned int offset,
+			    void *val, size_t bytes)
+{
+	struct ast2600_otp *priv = context;
+	u8 *buf = val;
+	unsigned int word_index;
+	unsigned int aligned_word;
+	unsigned int secure_size;
+	u32 extra_read;
+	u32 word0, word1;
+	int ret;
+
+	if (!bytes)
+		return 0;
+
+	if (offset % sizeof(u32) || bytes % sizeof(u32))
+		return -EINVAL;
+
+	if (offset >= AST2600_OTP_SIZE ||
+	    bytes > AST2600_OTP_SIZE - offset)
+		return -EINVAL;
+
+	guard(mutex)(&priv->lock);
+
+	if (priv->failed)
+		return -EIO;
+
+	/* SEC54 can grow after probe; keep the registered keepout immutable. */
+	extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT);
+	secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) *
+		      AST2600_OTP_SEC_SIZE_UNIT;
+	secure_size = max(priv->secure_keepout.end, secure_size);
+	if (offset < secure_size)
+		return -EACCES;
+
+	writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
+	if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
+		ret = -EACCES;
+		goto out_lock;
+	}
+
+	ret = ast2600_otp_wait_complete(priv);
+	if (ret)
+		goto out_lock;
+
+	word_index = offset / sizeof(u32);
+	while (bytes) {
+		aligned_word = word_index & ~1U;
+
+		ret = ast2600_otp_read_pair(priv, aligned_word,
+					    &word0, &word1);
+		if (ret)
+			goto out_lock;
+
+		if (!(word_index & 1)) {
+			put_unaligned_le32(word0, buf);
+			buf += sizeof(u32);
+			bytes -= sizeof(u32);
+			word_index++;
+		}
+		if (bytes) {
+			put_unaligned_le32(word1, buf);
+			buf += sizeof(u32);
+			bytes -= sizeof(u32);
+			word_index++;
+		}

drivers/nvmem/nvmem-aspeed-otp.c line 230

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+	}
+
+	ret = 0;
+
+out_lock:
+	writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
+	/* Complete the lock write before returning and releasing the mutex. */
+	readl(priv->base + AST2600_OTP_PROTECT_KEY);
+	return ret;
+}

[Severity: Low]
This isn't a bug, but both ast2600_otp_init_keepout() and ast2600_otp_read() mix guard(mutex) with goto out_lock cleanup within the same function, contrary to the Cleanup API convention in include/linux/cleanup.h. Moving the work performed while AST2600_OTP_PROTECT_KEY is unlocked into inner helpers (or using consistent cleanup) would avoid mixing guard() with goto labels and also share the duplicated unlock/relock sequence.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#8 lore raw
In reply to Prasanth Kumar Padarthi
Quoted 10 lines · Prasanth Kumar Padarthi

Provide root-only NVMEM access for userspace diagnostics comparing OTP ranges with vendor-derived reference data during BMC bring-up. The consumer uses raw offsets rather than named cells or a private ioctl.

Initialize read mode once at probe and mask the fixed secure prefix using an NVMEM keepout. Recheck SEC54 on each controller read and reject requests into an extended protected prefix. Programming protection does not block reads. Serialize transactions and stop issuing commands after a timeout. Use a 1-us initial polling delay and a generous 100-ms timeout.

This is describing the code...
Most of it belongs in the cover letter or below the --- line.
Please explain what the *hardware* does and *why* the driver is designed this way, not what the code is doing!

Quoted 9 lines

Adapt the read sequence from ASPEED's downstream driver, preserving its attribution, and add the driver to the ASPEED MAINTAINERS entry.

Tested on ASRock Rack B650D4U (AST2600 A3) with Linux 7.4-rc1 and OpenBMC Linux 6.18.24. Repeated reads, cross-pair reads and four concurrent readers (40 reads) passed. The selected 12-byte range matched a saved ASPEED-derived reference. The 7.4-rc1 run used a RAM-booted kernel with the working OpenBMC board DTB and initramfs; its final-pair check also passed.

This part should be outside of the commit message, like I explained earlier.

Quoted 19 lines
---
  MAINTAINERS                      |    1
  drivers/nvmem/Kconfig            |   13 ++
  drivers/nvmem/Makefile           |    1
  drivers/nvmem/nvmem-aspeed-otp.c |  297 ++++++++++++++++++++++++++++++++++++++
  4 files changed, 312 insertions(+)
MAINTAINERS +0 -0
index 93abbb315..5415e2be4 100644

MAINTAINERS F: Documentation/devicetree/bindings/arm/aspeed/ · line 2816

Quoted 4 lines
MAINTAINERS +1 -0
@@ -2813,6 +2813,7 @@ F:	Documentation/devicetree/bindings/arm/aspeed/
  F:	arch/arm/boot/dts/aspeed/
  F:	arch/arm/mach-aspeed/
  F:	arch/arm64/boot/dts/aspeed/
+F:	drivers/nvmem/nvmem-aspeed-otp.c

The matcher here *may* be unnecessary given that we have N.

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 168

Quoted 13 lines
MAINTAINERS +0 -0
  N:	aspeed
 
  ARM/AXIADO ARCHITECTURE
drivers/nvmem/Kconfig +2 -0
index d2f5bb236..e6445262b 100644
@@ -164,6 +164,19 @@ config NVMEM_APPLE_SPMI
  	  This driver can also be built as a module. If so, the module
  	  will be called apple-nvmem-spmi.
 
+config NVMEM_ASPEED_AST2600_OTP
+	tristate "ASPEED AST2600 OTP support"

The file is now named generic. Please name the kconfig "NVMEM_ASPEED_OTP" so it doesn't need to be renamed once AST2700 support is implemented.

Quoted 4 lines
drivers/nvmem/Kconfig +4 -0
+	depends on ARCH_ASPEED || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Say Y here to enable read-only access to the OTP data region

drivers/nvmem/Kconfig config NVMEM_APPLE_SPMI · line 182

Quoted 10 lines
drivers/nvmem/Kconfig +7 -0
+	  on ASPEED AST2600 BMCs through the NVMEM interface.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-aspeed-otp.
+
+	  If unsure, say N.
+
  config NVMEM_BCM_OCOTP
  	tristate "Broadcom On-Chip OTP Controller support"
  	depends on ARCH_BCM_IPROC || COMPILE_TEST

*snip*

Quoted 21 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +16 -0
new file mode 100644
@@ -0,0 +1,297 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) ASPEED Technology Inc.
+ *
+ * ASPEED AST2600 OTP Controller driver
+ */
+
+#include <linux/bitfield.h>
+#include <linux/cleanup.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/nvmem-provider.h>
+#include <linux/platform_device.h>

drivers/nvmem/nvmem-aspeed-otp.c line 26

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+#include <linux/unaligned.h>
+
+#define AST2600_OTP_PROTECT_KEY		0x00
+#define AST2600_OTP_CMD			0x04
+#define AST2600_OTP_ADDR		0x10
+#define AST2600_OTP_STATUS		0x14
+#define AST2600_OTP_COMPARE_1		0x20
+#define AST2600_OTP_COMPARE_2		0x24
+#define AST2600_OTP_EXTRA_READ_PROTECT	0x54
+#define AST2600_OTP_EXTRA_READ_RANGE	GENMASK(5, 0)

Please keep register offsets and field masks visually separate.
Usually you put the fields directly below their register, indented with an extra space. For example:

   #define AST2600_OTP_EXTRA_READ_PROTECT	0x54
   #define  AST2600_OTP_EXTRA_READ_RANGE	GENMASK(5, 0)

drivers/nvmem/nvmem-aspeed-otp.c line 39

Quoted 13 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +13 -0
+
+#define AST2600_OTP_CMD_READ		0x23b1e361
+#define AST2600_OTP_CMD_WRITE_MODE	0x23b1e362
+#define AST2600_OTP_UNLOCK_KEY		0x349fe38a
+#define AST2600_OTP_STATUS_DONE		GENMASK(2, 1)
+/* Normal reads take less than 1 us; allow a generous bounded wait. */
+#define AST2600_OTP_TIMEOUT_US		100000
+
+#define AST2600_OTP_DATA_WORDS		0x800
+#define AST2600_OTP_SIZE			(AST2600_OTP_DATA_WORDS * sizeof(u32))
+#define AST2600_OTP_CONF0_ADDR		0x800
+#define AST2600_OTP_CONF0_SEC_SIZE		GENMASK(21, 16)
+#define AST2600_OTP_SEC_SIZE_UNIT		(32 * sizeof(u32))

The alignment is somewhat inconsistent.

drivers/nvmem/nvmem-aspeed-otp.c line 49

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+
+struct ast2600_otp {
+	struct device *dev;
+	void __iomem *base;
+	/* Serialize the complete unlock, read and relock sequence. */
+	struct mutex lock;
+	struct nvmem_keepout secure_keepout;
+	bool failed;
+};
+

*snip*

drivers/nvmem/nvmem-aspeed-otp.c line 74

Quoted 3 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +3 -0
+static int ast2600_otp_init_read_mode(struct ast2600_otp *priv)
+{
+	static const u32 mode_addresses[] = { 0x3000, 0x5000, 0x1000 };

Please give these registers names instead of using an anonymous array.

drivers/nvmem/nvmem-aspeed-otp.c line 85

Quoted 11 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +11 -0
+	int i, ret;
+
+	ret = ast2600_otp_wait_complete(priv);
+	if (ret)
+		return ret;
+
+	/*
+	 * Restore read mode once at probe; this driver never programs fuses.
+	 * These writes target volatile mode registers, not OTP fuse cells.
+	 * No fuse programming command or programming timing is used.
+	 */

All the sentences say the same in slightly different ways, but none of them says *why* the step is needed. Maybe: "Linux never programs the OTP, but it might be left in it before, so restore the read mode once"?

Quoted 25 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +25 -0
+	for (i = 0; i < ARRAY_SIZE(mode_addresses); i++) {
+		writel(mode_addresses[i], priv->base + AST2600_OTP_ADDR);
+		writel(0, priv->base + AST2600_OTP_COMPARE_1);
+		writel(AST2600_OTP_CMD_WRITE_MODE, priv->base + AST2600_OTP_CMD);
+		ret = ast2600_otp_wait_complete(priv);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int ast2600_otp_read_pair(struct ast2600_otp *priv,
+				 unsigned int aligned_word,
+				 u32 *word0, u32 *word1)
+{
+	int ret;
+
+	/* The hardware reads two words starting at an even word index. */
+	writel(aligned_word, priv->base + AST2600_OTP_ADDR);
+
+	writel(AST2600_OTP_CMD_READ,
+	       priv->base + AST2600_OTP_CMD);
+
+	ret = ast2600_otp_wait_complete(priv);

drivers/nvmem/nvmem-aspeed-otp.c line 120

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+	if (ret)
+		return ret;
+
+	*word0 = readl(priv->base + AST2600_OTP_COMPARE_1);
+	*word1 = readl(priv->base + AST2600_OTP_COMPARE_2);
+
+	return 0;
+}
+
+static int ast2600_otp_init_keepout(struct ast2600_otp *priv)

The is misleading, because it also restores read mode.

drivers/nvmem/nvmem-aspeed-otp.c line 131

Quoted 11 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +11 -0
+{
+	u32 conf0, unused;
+	int ret;
+
+	guard(mutex)(&priv->lock);
+
+	writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
+	if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
+		ret = -EACCES;
+		goto out_lock;
+	}

Mixing goto and scope-based cleanup in the same function isn't allowed
(see the big comment in include/linux/cleanup.h). The same applies to ast2600_otp_read().
The unlock/relock sequence is also duplicated between both functions. Please move this into helpers (or a DEFINE_GUARD()) so it doesn't need labels.

Also, -EIO might be better here given that it's a hardware problem, and not a permission problem.

Quoted 5 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +5 -0
+
+	ret = ast2600_otp_init_read_mode(priv);
+	if (ret)
+		goto out_lock;
+

drivers/nvmem/nvmem-aspeed-otp.c line 146

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+	ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR,
+				    &conf0, &unused);
+	if (ret)
+		goto out_lock;
+
+	priv->secure_keepout.start = 0;
+	priv->secure_keepout.end =
+		FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) *
+		AST2600_OTP_SEC_SIZE_UNIT;
+	priv->secure_keepout.value = 0;

priv comes from devm_kzalloc(), so they're are already zero.

drivers/nvmem/nvmem-aspeed-otp.c line 151

Quoted 5 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +5 -0
+
+out_lock:
+	writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
+	/* Complete the lock write before returning and releasing the mutex. */
+	readl(priv->base + AST2600_OTP_PROTECT_KEY);

Again (as in v1), nothing else accesses the device during probe. This read is useless.

Quoted 21 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +21 -0
+	return ret;
+}
+
+static int ast2600_otp_read(void *context, unsigned int offset,
+			    void *val, size_t bytes)
+{
+	struct ast2600_otp *priv = context;
+	u8 *buf = val;
+	unsigned int word_index;
+	unsigned int aligned_word;
+	unsigned int secure_size;
+	u32 extra_read;
+	u32 word0, word1;
+	int ret;
+
+	if (!bytes)
+		return 0;
+
+	if (offset % sizeof(u32) || bytes % sizeof(u32))
+		return -EINVAL;
+

drivers/nvmem/nvmem-aspeed-otp.c line 182

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+	if (offset >= AST2600_OTP_SIZE ||
+	    bytes > AST2600_OTP_SIZE - offset)
+		return -EINVAL;
+
+	guard(mutex)(&priv->lock);
+
+	if (priv->failed)
+		return -EIO;
+
+	/* SEC54 can grow after probe; keep the registered keepout immutable. */

Please describe the hardware behaviour instead, e.g. "SEC54[5:0] can only grow until the ARM cores reset."

Quoted 28 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +28 -0
+	extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT);
+	secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) *
+		      AST2600_OTP_SEC_SIZE_UNIT;
+	secure_size = max(priv->secure_keepout.end, secure_size);
+	if (offset < secure_size)
+		return -EACCES;
+
+	writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
+	if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
+		ret = -EACCES;
+		goto out_lock;
+	}
+
+	ret = ast2600_otp_wait_complete(priv);
+	if (ret)
+		goto out_lock;
+
+	word_index = offset / sizeof(u32);
+	while (bytes) {
+		aligned_word = word_index & ~1U;
+
+		ret = ast2600_otp_read_pair(priv, aligned_word,
+					    &word0, &word1);
+		if (ret)
+			goto out_lock;
+
+		if (!(word_index & 1)) {
+			put_unaligned_le32(word0, buf);

drivers/nvmem/nvmem-aspeed-otp.c line 220

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+			buf += sizeof(u32);
+			bytes -= sizeof(u32);
+			word_index++;
+		}
+		if (bytes) {
+			put_unaligned_le32(word1, buf);
+			buf += sizeof(u32);
+			bytes -= sizeof(u32);
+			word_index++;
+		}

Why not reading the pair into an array? That'd remove the duplicates.

Quoted 46 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +46 -0
+	}
+
+	ret = 0;
+
+out_lock:
+	writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
+	/* Complete the lock write before returning and releasing the mutex. */
+	readl(priv->base + AST2600_OTP_PROTECT_KEY);
+	return ret;
+}
+
+static int ast2600_otp_probe(struct platform_device *pdev)
+{
+	struct nvmem_config config = {
+		.name = "ast2600-otp",
+		.id = NVMEM_DEVID_AUTO,
+		.owner = THIS_MODULE,
+		.type = NVMEM_TYPE_OTP,
+		.read_only = true,
+		.root_only = true,
+		.word_size = sizeof(u32),
+		.stride = sizeof(u32),
+		.size = AST2600_OTP_SIZE,
+		.reg_read = ast2600_otp_read,
+	};
+	struct nvmem_device *nvmem;
+	struct ast2600_otp *priv;
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->dev = dev;
+	priv->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	ret = devm_mutex_init(dev, &priv->lock);
+	if (ret)
+		return ret;
+
+	ret = ast2600_otp_init_keepout(priv);
+	if (ret)
+		return dev_err_probe(dev, ret,

drivers/nvmem/nvmem-aspeed-otp.c line 276

Quoted 10 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +10 -0
+				     "Failed to initialize OTP read mode and secure prefix\n");
+
+	config.dev = dev;
+	config.priv = priv;
+	if (priv->secure_keepout.end) {
+		config.keepout = &priv->secure_keepout;
+		config.nkeepout = 1;
+	}
+	nvmem = devm_nvmem_register(dev, &config);
+	return PTR_ERR_OR_ZERO(nvmem);

nit: return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));

drivers/nvmem/nvmem-aspeed-otp.c line 288

Quoted 12 lines
drivers/nvmem/nvmem-aspeed-otp.c new file +12 -0
+}
+
+static const struct of_device_id ast2600_otp_of_match[] = {
+	{ .compatible = "aspeed,ast2600-sbc" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ast2600_otp_of_match);
+
+static struct platform_driver ast2600_otp_driver = {
+	.probe = ast2600_otp_probe,
+	.driver = {
+		.name = "ast2600-otp",

If the plan is to add AST2700 later, then please use "aspeed-otp" and aspeed_otp_* names.

Last: Please run your next build with W=1 and do checkpatch.pl + dt_binding_check...

Tan

author
#9 lore raw

Hi Tan,

Thanks for reviewing v2.

I misunderstood the distinction between inline replies and threading a new revision. I’ll send v3 as a new thread and link the previous revision in the cover letter.

I’ll rewrite the commit message to explain the hardware behaviour and design rationale, and move the test results below ---. I’ll also include a GitHub link to the design notes as supplementary context.

I’ll address the cleanup structure, naming, register definitions, shared unlock/relock helpers, error handling, redundant initialization, readback and copying comments.

Thanks,
Prasanth

#10 lore raw
In reply to Prasanth Kumar Padarthi
Quoted 24 lines · Prasanth Kumar Padarthi

Hi,

This series exposes permitted AST2600 OTP data through root-only NVMEM for userspace diagnostics using raw offsets. It adds the SBC NVMEM binding and a read-only driver adapted from ASPEED's downstream driver.

Changes since v1:
- Add the separate binding patch and rename the driver nvmem-aspeed-otp.
- Poll once after a 1-us delay; retain the 100-ms timeout and log failures.
- Initialize read mode once at probe and stop commands after a timeout.
- Use a fixed secure-prefix keepout and check the live SEC54 range on reads.
- Simplify copying, locking, configuration and Kconfig help.

Tested on B650D4U (AST2600 A3), OpenBMC Linux 6.18.24 and upstream-based Linux 7.4-rc1: repeated reads, cross-pair reads and 40 reads from four concurrent readers passed. A 12-byte range matched the saved ASPEED-derived reference fingerprint. The 7.4-rc1 RAM boot used the working OpenBMC DTB and initramfs and also passed the final-pair comparison. ARM zImage built successfully.

AI assisted with driver revisions, validation tooling and patch text, using the downstream code, review comments and Neal's hardware guidance. Hardware tests were run by the submitter.

Quoted 5 lines

Prasanth Kumar Padarthi (2):
dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider
nvmem: aspeed: Add read-only AST2600 OTP support

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Again, please fix your threading... Other maintainers and reviewers already told you in other threads that sending a new revision must not be "In-reply-to" to the previous revision. See the "Explicit In-Reply-To headers" section of the submission documentation [1]. Consider the use of b4 [2], which can handle it more consistently.

Tan

[1] https://docs.kernel.org/process/submitting-patches.html#explicit-in-reply-to-headers
[2] https://b4.docs.kernel.org/en/latest/