Skip to contentSkip to conversation

nvmem: Enable OTP access for Raspberry Pi

RFC PATCH New Stefan Wahren 4 participants 9 messages Mar 9, 2018 – Sep 18, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover nvmem: Enable OTP access for Raspberry Pi

The VC4 firmware exposes a mailbox interface that allows the ARM core to access only the customer part of the OTP memory. This version brings read-only support, but could also be extended to write support.

I think this driver could be helpful for vendors, which integrate the Raspberry Pi Compute Module in their products.

This series depends on commit "soc: bcm2835: sync firmware properties with downstream".

Stefan Wahren (3):
dt-bindings: nvmem: add binding for Raspberry Pi OTP
nvmem: add driver for Raspberry Pi OTP
ARM: dts: bcm2835-rpi: Enable OTP access for Raspberry Pi

 .../nvmem/raspberrypi,bcm2835-customer-otp.txt     |  27 ++++
 arch/arm/boot/dts/bcm2835-rpi.dtsi                 |   6 +
 drivers/nvmem/Kconfig                              |  10 ++
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/raspberrypi-otp.c                    | 138 +++++++++++++++++++++
 5 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
 create mode 100644 drivers/nvmem/raspberrypi-otp.c
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH 1/3 dt-bindings: nvmem: add binding for Raspberry Pi OTP

This patch adds the devicetree binding for Raspberry Pi customer OTP driver.

---
 .../nvmem/raspberrypi,bcm2835-customer-otp.txt     | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt new file +27 -0
new file mode 100644
index 0000000..3f57744
@@ -0,0 +1,27 @@
+Customer OTP Memory for Raspberry Pi
+
+The VC4 firmware exposes a mailbox interface that allows the ARM core
+to access the customer part of the OTP memory.
+
+The OTP node must be a child node of the Raspberry Pi firmware node.
+
+Required properties :
+- compatible     : Should be "raspberrypi,bcm2835-customer-otp"
+- #address-cells : Should be 1
+- #size-cells    : Should be 1
+
+See nvmem.txt for more information.
+
+Example:
+
+firmware: firmware-rpi {
+	compatible = "raspberrypi,bcm2835-firmware";
+	mboxes = <&mailbox>;
+
+	customer_otp: otp {
+		compatible = "raspberrypi,bcm2835-customer-otp";
+		firmware = <&firmware>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+	};
+};
Signature · 1 line
2.7.4
maintainer
#2 lore raw

RFC PATCH 1/3 dt-bindings: nvmem: add binding for Raspberry Pi OTP

Quoted 28 lines · Stefan Wahren

This patch adds the devicetree binding for Raspberry Pi customer OTP driver.

---
 .../nvmem/raspberrypi,bcm2835-customer-otp.txt     | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt new file +13 -0
new file mode 100644
index 0000000..3f57744
@@ -0,0 +1,27 @@
+Customer OTP Memory for Raspberry Pi
+
+The VC4 firmware exposes a mailbox interface that allows the ARM core
+to access the customer part of the OTP memory.
+
+The OTP node must be a child node of the Raspberry Pi firmware node.
+
+Required properties :
+- compatible     : Should be "raspberrypi,bcm2835-customer-otp"
+- #address-cells : Should be 1
+- #size-cells    : Should be 1
+
+See nvmem.txt for more information.

Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt line 23

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt new file +10 -0
+
+Example:
+
+firmware: firmware-rpi {
+	compatible = "raspberrypi,bcm2835-firmware";
+	mboxes = <&mailbox>;
+
+	customer_otp: otp {
+		compatible = "raspberrypi,bcm2835-customer-otp";
+		firmware = <&firmware>;

Not documented nor necessary. It's the parent.

Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt line 25

Quoted 2 lines
Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt new file +2 -0
+		#address-cells = <1>;
+		#size-cells = <1>;

Are there some child nodes? If not, there's no point in having this node.

Rob

#3 lore raw

RFC PATCH 2/3 nvmem: add driver for Raspberry Pi OTP

In reply to Stefan Wahren

This patch brings read-only support for the Raspberry Pi Customer OTP. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware.

---
 drivers/nvmem/Kconfig           |  10 +++
 drivers/nvmem/Makefile          |   2 +
 drivers/nvmem/raspberrypi-otp.c | 138 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 drivers/nvmem/raspberrypi-otp.c
drivers/nvmem/Kconfig +10 -0
index ff505af..76b8af3 100644
@@ -175,4 +175,14 @@ config NVMEM_SNVS_LPGPR
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-snvs-lpgpr.
 
+config NVMEM_RASPBERRYPI_OTP
+	tristate "Raspberry Pi Customer OTP support"
+	depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
+	depends on RASPBERRYPI_FIRMWARE
+	help
+	  This is a driver for access to the Customer OTP on the Raspberry Pi.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-raspberrypi-otp.
+
 endif
drivers/nvmem/Makefile +2 -0
index e54dcfa..3b53b0b 100644
@@ -37,3 +37,5 @@ obj-$(CONFIG_MESON_MX_EFUSE)	+= nvmem_meson_mx_efuse.o
 nvmem_meson_mx_efuse-y		:= meson-mx-efuse.o
 obj-$(CONFIG_NVMEM_SNVS_LPGPR)	+= nvmem_snvs_lpgpr.o
 nvmem_snvs_lpgpr-y		:= snvs_lpgpr.o
+obj-$(CONFIG_NVMEM_RASPBERRYPI_OTP)	+= nvmem-raspberrypi-otp.o
+nvmem-raspberrypi-otp-y		:= raspberrypi-otp.o
drivers/nvmem/raspberrypi-otp.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

RFC PATCH 2/3 nvmem: add driver for Raspberry Pi OTP

Quoted 100 lines · Stefan Wahren

This patch brings read-only support for the Raspberry Pi Customer OTP. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware.

---
 drivers/nvmem/Kconfig           |  10 +++
 drivers/nvmem/Makefile          |   2 +
 drivers/nvmem/raspberrypi-otp.c | 138 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 drivers/nvmem/raspberrypi-otp.c
drivers/nvmem/Kconfig +10 -0
index ff505af..76b8af3 100644
@@ -175,4 +175,14 @@ config NVMEM_SNVS_LPGPR
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-snvs-lpgpr.
 
+config NVMEM_RASPBERRYPI_OTP
+	tristate "Raspberry Pi Customer OTP support"
+	depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
+	depends on RASPBERRYPI_FIRMWARE
+	help
+	  This is a driver for access to the Customer OTP on the Raspberry Pi.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-raspberrypi-otp.
+
 endif
drivers/nvmem/Makefile +2 -0
index e54dcfa..3b53b0b 100644
@@ -37,3 +37,5 @@ obj-$(CONFIG_MESON_MX_EFUSE)	+= nvmem_meson_mx_efuse.o
 nvmem_meson_mx_efuse-y		:= meson-mx-efuse.o
 obj-$(CONFIG_NVMEM_SNVS_LPGPR)	+= nvmem_snvs_lpgpr.o
 nvmem_snvs_lpgpr-y		:= snvs_lpgpr.o
+obj-$(CONFIG_NVMEM_RASPBERRYPI_OTP)	+= nvmem-raspberrypi-otp.o
+nvmem-raspberrypi-otp-y		:= raspberrypi-otp.o
drivers/nvmem/raspberrypi-otp.c new file +53 -0
new file mode 100644
index 0000000..e925435
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Raspberry Pi Customer OTP driver
+ *
+ * Copyright (C) 2018 Stefan Wahren <[email protected]>
+ */
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+#define CUSTOMER_CELLS 8
+
+struct rpi_otp {
+	struct nvmem_device *nvmem;
+	struct rpi_firmware *fw;
+};
+
+/*
+ * Packet definition used by RPI_FIRMWARE_GET_CUSTOMER_OTP
+ */
+struct rpi_customer_otp_packet {
+	u32 index;
+	u32 length;
+	u32 cells[CUSTOMER_CELLS];
+};
+
+static int rpi_otp_read(void *context, unsigned int offset, void *val,
+			size_t bytes)
+{
+	struct rpi_customer_otp_packet packet;
+	struct rpi_otp *otp = context;
+	u32 *buf = val;
+	int ret;
+
+	packet.index = 0;
+	packet.length = CUSTOMER_CELLS;
+	memset(packet.cells, 0xff, sizeof(packet.cells));
+
+	ret = rpi_firmware_property(otp->fw, RPI_FIRMWARE_GET_CUSTOMER_OTP,
+				    &packet, sizeof(packet));
+
+	if (ret)
+		return ret;
+
+	/* Request rejected by firmware */
+	if (packet.index)
+		return -EIO;
+

drivers/nvmem/raspberrypi-otp.c line 63

Quoted 10 lines
drivers/nvmem/raspberrypi-otp.c new file +10 -0
+	while (bytes) {
+		if ((offset / 4) < sizeof(packet.cells))
+			*buf = packet.cells[offset / 4];
+		else
+			*buf = 0;
+
+		buf++;
+		bytes -= 4;
+		offset += 4;
+	}

It looks like nvmem core makes sure that offset + bytes <= nvmem->size, so I think you can turn this loop into just a memcpy.

Other than that,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180309/5edec855/attachment.sig>

maintainer
#5 lore raw

RFC PATCH 2/3 nvmem: add driver for Raspberry Pi OTP

In reply to Stefan Wahren
Quoted 122 lines · Stefan Wahren

This patch brings read-only support for the Raspberry Pi Customer OTP. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware.

---
 drivers/nvmem/Kconfig           |  10 +++
 drivers/nvmem/Makefile          |   2 +
 drivers/nvmem/raspberrypi-otp.c | 138 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 drivers/nvmem/raspberrypi-otp.c
drivers/nvmem/Kconfig +10 -0
index ff505af..76b8af3 100644
@@ -175,4 +175,14 @@ config NVMEM_SNVS_LPGPR
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-snvs-lpgpr.
 
+config NVMEM_RASPBERRYPI_OTP
+	tristate "Raspberry Pi Customer OTP support"
+	depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
+	depends on RASPBERRYPI_FIRMWARE
+	help
+	  This is a driver for access to the Customer OTP on the Raspberry Pi.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-raspberrypi-otp.
+
 endif
drivers/nvmem/Makefile +2 -0
index e54dcfa..3b53b0b 100644
@@ -37,3 +37,5 @@ obj-$(CONFIG_MESON_MX_EFUSE)	+= nvmem_meson_mx_efuse.o
 nvmem_meson_mx_efuse-y		:= meson-mx-efuse.o
 obj-$(CONFIG_NVMEM_SNVS_LPGPR)	+= nvmem_snvs_lpgpr.o
 nvmem_snvs_lpgpr-y		:= snvs_lpgpr.o
+obj-$(CONFIG_NVMEM_RASPBERRYPI_OTP)	+= nvmem-raspberrypi-otp.o
+nvmem-raspberrypi-otp-y		:= raspberrypi-otp.o
drivers/nvmem/raspberrypi-otp.c new file +75 -0
new file mode 100644
index 0000000..e925435
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Raspberry Pi Customer OTP driver
+ *
+ * Copyright (C) 2018 Stefan Wahren <[email protected]>
+ */
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+#define CUSTOMER_CELLS 8
+
+struct rpi_otp {
+	struct nvmem_device *nvmem;
+	struct rpi_firmware *fw;
+};
+
+/*
+ * Packet definition used by RPI_FIRMWARE_GET_CUSTOMER_OTP
+ */
+struct rpi_customer_otp_packet {
+	u32 index;
+	u32 length;
+	u32 cells[CUSTOMER_CELLS];
+};
+
+static int rpi_otp_read(void *context, unsigned int offset, void *val,
+			size_t bytes)
+{
+	struct rpi_customer_otp_packet packet;
+	struct rpi_otp *otp = context;
+	u32 *buf = val;
+	int ret;
+
+	packet.index = 0;
+	packet.length = CUSTOMER_CELLS;
+	memset(packet.cells, 0xff, sizeof(packet.cells));
+
+	ret = rpi_firmware_property(otp->fw, RPI_FIRMWARE_GET_CUSTOMER_OTP,
+				    &packet, sizeof(packet));
+
+	if (ret)
+		return ret;
+
+	/* Request rejected by firmware */
+	if (packet.index)
+		return -EIO;
+
+	while (bytes) {
+		if ((offset / 4) < sizeof(packet.cells))
+			*buf = packet.cells[offset / 4];
+		else
+			*buf = 0;
+
+		buf++;
+		bytes -= 4;
+		offset += 4;
+	}
+
+	return 0;
+}
+
+static struct nvmem_config ocotp_config = {
+	.name = "rpi-customer-otp",
+	.size = CUSTOMER_CELLS * 4,
+	.stride = 4,
+	.word_size = 4,
+	.reg_read = rpi_otp_read,
+};
+

drivers/nvmem/raspberrypi-otp.c line 85

Quoted 10 lines
drivers/nvmem/raspberrypi-otp.c new file +10 -0
+static int rpi_otp_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const struct of_device_id *match;
+	struct device_node *fw_node;
+	struct rpi_otp *otp;
+
+	match = of_match_device(dev->driver->of_match_table, dev);
+	if (!match)
+		return -EINVAL;

This call isn't necessary if there's no match data.

Rob

#6 lore raw

RFC PATCH 2/3 nvmem: add driver for Raspberry Pi OTP

In reply to Stefan Wahren

Hi Stefan,

Quoted 11 lines · Stefan Wahren

This patch brings read-only support for the Raspberry Pi Customer OTP. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware.

---
  drivers/nvmem/Kconfig           |  10 +++
  drivers/nvmem/Makefile          |   2 +
  drivers/nvmem/raspberrypi-otp.c | 138 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 150 insertions(+)

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

Looks there are some pending trivial comments, are you planning to resend this?

--srini

#7 lore raw

RFC PATCH 2/3 nvmem: add driver for Raspberry Pi OTP

Hi Srinivas,

Am 11.07.2018 um 11:45 schrieb Srinivas Kandagatla:

Quoted 16 lines

Hi Stefan,

Quoted 4 lines · Stefan Wahren

This patch brings read-only support for the Raspberry Pi Customer OTP. The driver accesses the OTP via the mailbox property interface provided by the VPU firmware.

Quoted 8 lines

---

? drivers/nvmem/Kconfig?????????? |? 10 +++
? drivers/nvmem/Makefile????????? |?? 2 +
? drivers/nvmem/raspberrypi-otp.c | 138

++++++++++++++++++++++++++++++++++++++++
? 3 files changed, 150 insertions(+)
? create mode 100644 drivers/nvmem/raspberrypi-otp.c

Quoted 2 lines

Looks there are some pending trivial comments, are you planning to resend this?

yes, but this series currently have low prio.

Regards
Stefan

#8 lore raw

RFC PATCH 3/3 ARM: dts: bcm2835-rpi: Enable OTP access for Raspberry Pi

In reply to Stefan Wahren

This patch enables OTP access for all Raspberry Pi variants.

---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +6 -0
index 0198bd4..19a1027 100644
@@ -22,6 +22,12 @@
 			#address-cells = <0>;
 			#size-cells = <0>;
 			mboxes = <&mailbox>;
+
+			customer_otp: otp {
+				compatible = "raspberrypi,bcm2835-customer-otp";
+				#address-cells = <1>;
+				#size-cells = <1>;
+			};
 		};
 
 		power: power {
Signature · 1 line
2.7.4