* [PATCH RFC 0/3] nvmem: Enable OTP access for Raspberry Pi
@ 2018-03-09 13:32 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland, Eric Anholt, Phil Elwell
Cc: Stefan Wahren, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
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
--
2.7.4
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 0/3] nvmem: Enable OTP access for Raspberry Pi
@ 2018-03-09 13:32 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: linux-arm-kernel
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
--
2.7.4
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 1/3] dt-bindings: nvmem: add binding for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-09 13:32 ` Stefan Wahren
-1 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland, Eric Anholt, Phil Elwell
Cc: Stefan Wahren, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
This patch adds the devicetree binding for Raspberry Pi customer OTP
driver.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
.../nvmem/raspberrypi,bcm2835-customer-otp.txt | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
diff --git a/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
new file mode 100644
index 0000000..3f57744
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
@@ -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>;
+ };
+};
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH RFC 1/3] dt-bindings: nvmem: add binding for Raspberry Pi OTP
@ 2018-03-09 13:32 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: linux-arm-kernel
This patch adds the devicetree binding for Raspberry Pi customer OTP
driver.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
.../nvmem/raspberrypi,bcm2835-customer-otp.txt | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
diff --git a/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
new file mode 100644
index 0000000..3f57744
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
@@ -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>;
+ };
+};
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-09 13:32 ` Stefan Wahren
-1 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland, Eric Anholt, Phil Elwell
Cc: Stefan Wahren, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
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.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
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
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index ff505af..76b8af3 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -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
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index e54dcfa..3b53b0b 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -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
diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
new file mode 100644
index 0000000..e925435
--- /dev/null
+++ b/drivers/nvmem/raspberrypi-otp.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Raspberry Pi Customer OTP driver
+ *
+ * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
+ */
+#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,
+};
+
+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;
+
+ otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
+ if (!otp)
+ return -ENOMEM;
+
+ fw_node = of_get_parent(dev->of_node);
+ if (!fw_node) {
+ dev_err(dev, "Missing firmware node\n");
+ return -ENOENT;
+ }
+
+ otp->fw = rpi_firmware_get(fw_node);
+ of_node_put(fw_node);
+ if (!otp->fw)
+ return -EPROBE_DEFER;
+
+ ocotp_config.priv = otp;
+ ocotp_config.dev = dev;
+ otp->nvmem = nvmem_register(&ocotp_config);
+ if (IS_ERR(otp->nvmem))
+ return PTR_ERR(otp->nvmem);
+
+ platform_set_drvdata(pdev, otp);
+
+ return 0;
+}
+
+static int rpi_otp_remove(struct platform_device *pdev)
+{
+ struct rpi_otp *otp = platform_get_drvdata(pdev);
+
+ return nvmem_unregister(otp->nvmem);
+}
+
+static const struct of_device_id rpi_otp_of_match[] = {
+ { .compatible = "raspberrypi,bcm2835-customer-otp", },
+ { /* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, rpi_otp_of_match);
+
+static struct platform_driver rpi_otp_driver = {
+ .probe = rpi_otp_probe,
+ .remove = rpi_otp_remove,
+ .driver = {
+ .name = "rpi-customer-otp",
+ .of_match_table = rpi_otp_of_match,
+ },
+};
+module_platform_driver(rpi_otp_driver);
+
+MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
+MODULE_DESCRIPTION("Raspberry Pi Customer OTP driver");
+MODULE_LICENSE("GPL v2");
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
@ 2018-03-09 13:32 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
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
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index ff505af..76b8af3 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -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
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index e54dcfa..3b53b0b 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -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
diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
new file mode 100644
index 0000000..e925435
--- /dev/null
+++ b/drivers/nvmem/raspberrypi-otp.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Raspberry Pi Customer OTP driver
+ *
+ * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
+ */
+#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,
+};
+
+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;
+
+ otp = devm_kzalloc(dev, sizeof(*otp), GFP_KERNEL);
+ if (!otp)
+ return -ENOMEM;
+
+ fw_node = of_get_parent(dev->of_node);
+ if (!fw_node) {
+ dev_err(dev, "Missing firmware node\n");
+ return -ENOENT;
+ }
+
+ otp->fw = rpi_firmware_get(fw_node);
+ of_node_put(fw_node);
+ if (!otp->fw)
+ return -EPROBE_DEFER;
+
+ ocotp_config.priv = otp;
+ ocotp_config.dev = dev;
+ otp->nvmem = nvmem_register(&ocotp_config);
+ if (IS_ERR(otp->nvmem))
+ return PTR_ERR(otp->nvmem);
+
+ platform_set_drvdata(pdev, otp);
+
+ return 0;
+}
+
+static int rpi_otp_remove(struct platform_device *pdev)
+{
+ struct rpi_otp *otp = platform_get_drvdata(pdev);
+
+ return nvmem_unregister(otp->nvmem);
+}
+
+static const struct of_device_id rpi_otp_of_match[] = {
+ { .compatible = "raspberrypi,bcm2835-customer-otp", },
+ { /* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, rpi_otp_of_match);
+
+static struct platform_driver rpi_otp_driver = {
+ .probe = rpi_otp_probe,
+ .remove = rpi_otp_remove,
+ .driver = {
+ .name = "rpi-customer-otp",
+ .of_match_table = rpi_otp_of_match,
+ },
+};
+module_platform_driver(rpi_otp_driver);
+
+MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
+MODULE_DESCRIPTION("Raspberry Pi Customer OTP driver");
+MODULE_LICENSE("GPL v2");
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH RFC 3/3] ARM: dts: bcm2835-rpi: Enable OTP access for Raspberry Pi
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-09 13:32 ` Stefan Wahren
-1 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland, Eric Anholt, Phil Elwell
Cc: Stefan Wahren, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
This patch enables OTP access for all Raspberry Pi variants.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
arch/arm/boot/dts/bcm2835-rpi.dtsi | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
index 0198bd4..19a1027 100644
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
@@ -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 {
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH RFC 3/3] ARM: dts: bcm2835-rpi: Enable OTP access for Raspberry Pi
@ 2018-03-09 13:32 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-03-09 13:32 UTC (permalink / raw)
To: linux-arm-kernel
This patch enables OTP access for all Raspberry Pi variants.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
arch/arm/boot/dts/bcm2835-rpi.dtsi | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
index 0198bd4..19a1027 100644
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
@@ -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 {
--
2.7.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-09 21:06 ` Eric Anholt
-1 siblings, 0 replies; 18+ messages in thread
From: Eric Anholt @ 2018-03-09 21:06 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland, Phil Elwell
Cc: Stefan Wahren, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
[-- Attachment #1.1: Type: text/plain, Size: 3771 bytes --]
Stefan Wahren <stefan.wahren@i2se.com> writes:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index ff505af..76b8af3 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -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
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index e54dcfa..3b53b0b 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -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
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 0000000..e925435
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Raspberry Pi Customer OTP driver
> + *
> + * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
> + */
> +#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;
> + }
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,
Reviewed-by: Eric Anholt <eric@anholt.net>
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
@ 2018-03-09 21:06 ` Eric Anholt
0 siblings, 0 replies; 18+ messages in thread
From: Eric Anholt @ 2018-03-09 21:06 UTC (permalink / raw)
To: linux-arm-kernel
Stefan Wahren <stefan.wahren@i2se.com> writes:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index ff505af..76b8af3 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -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
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index e54dcfa..3b53b0b 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -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
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 0000000..e925435
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Raspberry Pi Customer OTP driver
> + *
> + * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
> + */
> +#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;
> + }
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,
Reviewed-by: Eric Anholt <eric@anholt.net>
-------------- 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>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH RFC 1/3] dt-bindings: nvmem: add binding for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-18 12:48 ` Rob Herring
-1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2018-03-18 12:48 UTC (permalink / raw)
To: Stefan Wahren
Cc: Mark Rutland, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, Phil Elwell, Eric Anholt, Srinivas Kandagatla,
linux-rpi-kernel, bcm-kernel-feedback-list, linux-arm-kernel
On Fri, Mar 09, 2018 at 02:32:06PM +0100, Stefan Wahren wrote:
> This patch adds the devicetree binding for Raspberry Pi customer OTP
> driver.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> .../nvmem/raspberrypi,bcm2835-customer-otp.txt | 27 ++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
>
> diff --git a/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
> new file mode 100644
> index 0000000..3f57744
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
> @@ -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>;
Not documented nor necessary. It's the parent.
> + #address-cells = <1>;
> + #size-cells = <1>;
Are there some child nodes? If not, there's no point in having this
node.
Rob
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 1/3] dt-bindings: nvmem: add binding for Raspberry Pi OTP
@ 2018-03-18 12:48 ` Rob Herring
0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2018-03-18 12:48 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Mar 09, 2018 at 02:32:06PM +0100, Stefan Wahren wrote:
> This patch adds the devicetree binding for Raspberry Pi customer OTP
> driver.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> .../nvmem/raspberrypi,bcm2835-customer-otp.txt | 27 ++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
>
> diff --git a/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
> new file mode 100644
> index 0000000..3f57744
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/raspberrypi,bcm2835-customer-otp.txt
> @@ -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>;
Not documented nor necessary. It's the parent.
> + #address-cells = <1>;
> + #size-cells = <1>;
Are there some child nodes? If not, there's no point in having this
node.
Rob
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-03-18 12:48 ` Rob Herring
-1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2018-03-18 12:48 UTC (permalink / raw)
To: Stefan Wahren
Cc: Mark Rutland, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, Phil Elwell, Eric Anholt, Srinivas Kandagatla,
linux-rpi-kernel, bcm-kernel-feedback-list, linux-arm-kernel
On Fri, Mar 09, 2018 at 02:32:07PM +0100, Stefan Wahren wrote:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index ff505af..76b8af3 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -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
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index e54dcfa..3b53b0b 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -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
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 0000000..e925435
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Raspberry Pi Customer OTP driver
> + *
> + * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
> + */
> +#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,
> +};
> +
> +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
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
@ 2018-03-18 12:48 ` Rob Herring
0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2018-03-18 12:48 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Mar 09, 2018 at 02:32:07PM +0100, Stefan Wahren wrote:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index ff505af..76b8af3 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -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
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index e54dcfa..3b53b0b 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -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
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 0000000..e925435
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Raspberry Pi Customer OTP driver
> + *
> + * Copyright (C) 2018 Stefan Wahren <stefan.wahren@i2se.com>
> + */
> +#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,
> +};
> +
> +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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
2018-03-09 13:32 ` Stefan Wahren
@ 2018-07-11 9:45 ` Srinivas Kandagatla
-1 siblings, 0 replies; 18+ messages in thread
From: Srinivas Kandagatla @ 2018-07-11 9:45 UTC (permalink / raw)
To: Stefan Wahren, Rob Herring, Mark Rutland, Eric Anholt, Phil Elwell
Cc: devicetree, Florian Fainelli, Scott Branden, Ray Jui,
bcm-kernel-feedback-list, linux-rpi-kernel, linux-arm-kernel
Hi Stefan,
On 09/03/18 13:32, Stefan Wahren wrote:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
@ 2018-07-11 9:45 ` Srinivas Kandagatla
0 siblings, 0 replies; 18+ messages in thread
From: Srinivas Kandagatla @ 2018-07-11 9:45 UTC (permalink / raw)
To: linux-arm-kernel
Hi Stefan,
On 09/03/18 13:32, Stefan Wahren wrote:
> 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.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> 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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
2018-07-11 9:45 ` Srinivas Kandagatla
@ 2018-09-18 14:40 ` Stefan Wahren
-1 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-09-18 14:40 UTC (permalink / raw)
To: Srinivas Kandagatla, Eric Anholt, Phil Elwell
Cc: Mark Rutland, devicetree, Florian Fainelli, Scott Branden,
Ray Jui, Rob Herring, bcm-kernel-feedback-list, linux-rpi-kernel,
linux-arm-kernel
Hi Srinivas,
Am 11.07.2018 um 11:45 schrieb Srinivas Kandagatla:
> Hi Stefan,
>
> On 09/03/18 13:32, Stefan Wahren wrote:
>> 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.
>>
>> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
>> ---
>> 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?
yes, but this series currently have low prio.
Regards
Stefan
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH RFC 2/3] nvmem: add driver for Raspberry Pi OTP
@ 2018-09-18 14:40 ` Stefan Wahren
0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-09-18 14:40 UTC (permalink / raw)
To: linux-arm-kernel
Hi Srinivas,
Am 11.07.2018 um 11:45 schrieb Srinivas Kandagatla:
> Hi Stefan,
>
> On 09/03/18 13:32, Stefan Wahren wrote:
>> 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.
>>
>> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
>> ---
>> ? 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?
yes, but this series currently have low prio.
Regards
Stefan
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2018-09-18 14:40 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09 13:32 [PATCH RFC 0/3] nvmem: Enable OTP access for Raspberry Pi Stefan Wahren
2018-03-09 13:32 ` Stefan Wahren
2018-03-09 13:32 ` [PATCH RFC 1/3] dt-bindings: nvmem: add binding for Raspberry Pi OTP Stefan Wahren
2018-03-09 13:32 ` Stefan Wahren
2018-03-18 12:48 ` Rob Herring
2018-03-18 12:48 ` Rob Herring
2018-03-09 13:32 ` [PATCH RFC 2/3] nvmem: add driver " Stefan Wahren
2018-03-09 13:32 ` Stefan Wahren
2018-03-09 21:06 ` Eric Anholt
2018-03-09 21:06 ` Eric Anholt
2018-03-18 12:48 ` Rob Herring
2018-03-18 12:48 ` Rob Herring
2018-07-11 9:45 ` Srinivas Kandagatla
2018-07-11 9:45 ` Srinivas Kandagatla
2018-09-18 14:40 ` Stefan Wahren
2018-09-18 14:40 ` Stefan Wahren
2018-03-09 13:32 ` [PATCH RFC 3/3] ARM: dts: bcm2835-rpi: Enable OTP access for Raspberry Pi Stefan Wahren
2018-03-09 13:32 ` Stefan Wahren
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.