public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Wahren <wahrenst@gmx.net>
To: Gregor Herburger <gregor.herburger@linutronix.de>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Srinivas Kandagatla <srini@kernel.org>
Cc: devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] nvmem: Add the Raspberry Pi OTP driver
Date: Wed, 8 Apr 2026 18:52:46 +0200	[thread overview]
Message-ID: <251100fe-db96-4d83-899a-cd764582d698@gmx.net> (raw)
In-Reply-To: <20260408-rpi-otp-driver-v1-2-e02d1dbe6008@linutronix.de>

Hi Gregor,

[drop Emma's old address]

Am 08.04.26 um 10:00 schrieb Gregor Herburger:
> Raspberry Pis have OTP registers which can be accessed through the
> videocore firmware. Add a nvmem driver to support these OTP registers.
>
> Signed-off-by: Gregor Herburger <gregor.herburger@linutronix.de>
> ---
>   drivers/nvmem/Kconfig                      |  12 +++
>   drivers/nvmem/Makefile                     |   1 +
>   drivers/nvmem/raspberrypi-otp.c            | 159 +++++++++++++++++++++++++++++
>   include/soc/bcm2835/raspberrypi-firmware.h |   2 +
>   4 files changed, 174 insertions(+)
>
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index 74ddbd0f79b0..892d05fe67be 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -483,4 +483,16 @@ config NVMEM_QORIQ_EFUSE
>   	  This driver can also be built as a module. If so, the module
>   	  will be called nvmem_qoriq_efuse.
>   
> +config NVMEM_RASPBERRYPI_OTP
> +	tristate "Raspberry Pi OTP support"
> +	# Make sure not 'y' when RASPBERRYPI_FIRMWARE is 'm'. This can only
> +	# happen when COMPILE_TEST=y, hence the added !RASPBERRYPI_FIRMWARE.
I don't think these comments are necessary, because this applies to 
other firmware drivers, too.
> +	depends on RASPBERRYPI_FIRMWARE || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
> +	help
> +	  This driver provides access to the Raspberry Pi OTP memory via the
> +	  nvmem subsystem. The driver supports the customer otp as well as the
> +	  device specific private key OTP.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called raspberrypi-otp.
>   endif
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index 7252b8ec88d4..8ca2095e068f 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -95,3 +95,4 @@ obj-$(CONFIG_NVMEM_ZYNQMP)		+= nvmem_zynqmp_nvmem.o
>   nvmem_zynqmp_nvmem-y			:= zynqmp_nvmem.o
>   obj-$(CONFIG_NVMEM_QORIQ_EFUSE)		+= nvmem-qoriq-efuse.o
>   nvmem-qoriq-efuse-y			:= qoriq-efuse.o
> +obj-$(CONFIG_NVMEM_RASPBERRYPI_OTP)	+= raspberrypi-otp.o
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 000000000000..13ee3784b137
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,159 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <soc/bcm2835/raspberrypi-firmware.h>
> +
> +struct rpi_otp_priv {
> +	struct rpi_firmware *fw;
> +	struct device *dev;
> +	u32 read_tag;
> +	u32 write_tag;
> +};
> +
> +struct rpi_otp_driver_data {
> +	const char *name;
> +	u32 read_tag;
> +	u32 write_tag;
> +};
> +
> +struct rpi_otp_header {
> +	u32 start;
> +	u32 count;
> +	u32 data[];
> +};
> +
> +static int rpi_otp_read(void *context, unsigned int offset, void *buf, size_t bytes)
> +{
> +	struct rpi_otp_priv *priv = context;
> +	struct rpi_otp_header *fwbuf;
> +	int ret;
> +
> +	fwbuf = kmalloc(sizeof(struct rpi_otp_header) + bytes, GFP_KERNEL);
> +	if (!fwbuf)
> +		return -ENOMEM;
> +
> +	fwbuf->start = offset / 4;
> +	fwbuf->count = bytes / 4;
> +
> +	ret = rpi_firmware_property(priv->fw, priv->read_tag, fwbuf,
> +				    sizeof(struct rpi_otp_header) + bytes);
> +	if (ret)
> +		goto out;
> +
> +	memcpy(buf, fwbuf->data, bytes);
> +
> +out:
> +	kfree(fwbuf);
> +	return ret;
> +}
> +
> +static int rpi_otp_write(void *context, unsigned int offset, void *val, size_t bytes)
> +{
> +	struct rpi_otp_priv *priv = context;
> +	struct rpi_otp_header *fwbuf;
> +	int ret;
> +
> +	fwbuf = kmalloc(sizeof(struct rpi_otp_header) + bytes, GFP_KERNEL);
> +	if (!fwbuf)
> +		return -ENOMEM;
> +
> +	fwbuf->start = offset / 4;
> +	fwbuf->count = bytes / 4;
> +	memcpy(fwbuf->data, val, bytes);
> +
> +	ret = rpi_firmware_property(priv->fw, priv->write_tag, fwbuf,
> +				    sizeof(struct rpi_otp_header) + bytes);
> +
> +	kfree(fwbuf);
> +	return ret;
> +}
> +
> +static const struct rpi_otp_driver_data rpi_otp_customer = {
> +	.name = "rpi-otp-customer",
> +	.read_tag = RPI_FIRMWARE_GET_CUSTOMER_OTP,
> +	.write_tag = RPI_FIRMWARE_SET_CUSTOMER_OTP,
> +};
> +
> +static const struct rpi_otp_driver_data rpi_otp_private = {
> +	.name = "rpi-otp-private",
> +	.read_tag = RPI_FIRMWARE_GET_PRIVATE_OTP,
> +	.write_tag = RPI_FIRMWARE_SET_PRIVATE_OTP,
> +};
> +
> +static int rpi_otp_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct nvmem_device *nvmem;
> +	struct rpi_otp_priv *priv;
> +	struct device_node *np;
> +	const struct rpi_otp_driver_data *data;
> +	struct nvmem_config config = {
> +		.read_only = false,
> +		.word_size = 4,
> +		.stride = 4,
> +		.reg_read = rpi_otp_read,
> +		.reg_write = rpi_otp_write,
> +		.size = 32,
> +	};
> +
> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	data = device_get_match_data(dev);
> +	if (!data)
> +		return -ENODEV;
> +
> +	np = of_get_parent(dev->of_node);
> +	if (!np) {
> +		dev_err(dev, "Missing firmware node\n");
> +		return -ENOENT;
> +	}
> +
> +	priv->fw = devm_rpi_firmware_get(&pdev->dev, np);
> +	of_node_put(np);
> +	if (!priv->fw)
> +		return -EPROBE_DEFER;
> +
> +	priv->dev = dev;
> +	priv->read_tag = data->read_tag;
> +	priv->write_tag = data->write_tag;
> +	config.dev = dev;
> +	config.priv = priv;
> +	config.name = data->name;
> +
> +	nvmem = devm_nvmem_register(dev, &config);
> +	if (IS_ERR(nvmem))
> +		return dev_err_probe(dev, PTR_ERR(nvmem), "error registering nvmem config\n");
> +
> +	return 0;
> +}
Is there any reason, why we cannot register this driver in 
rpi_firmware_probe() like hwmon and clk driver?

I like to avoid the complete dt-binding from patch 1.
> +
> +static const struct of_device_id rpi_otp_of_match[] = {
> +	{
> +		.compatible = "raspberrypi,firmware-otp-customer",
> +		.data = &rpi_otp_customer
> +	},
> +	{
> +		.compatible = "raspberrypi,firmware-otp-private",
> +		.data = &rpi_otp_private,
> +	},
> +	{ /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, rpi_otp_of_match);
> +
> +static struct platform_driver raspberry_otp_driver = {
> +	.probe	= rpi_otp_probe,
> +	.driver = {
> +		.name	= "rpi-otp",
> +		.of_match_table = rpi_otp_of_match,
> +	},
> +};
> +module_platform_driver(raspberry_otp_driver);
> +
> +MODULE_AUTHOR("Gregor Herburger <gregor.herburger@linutronix.de>");
> +MODULE_DESCRIPTION("Raspberry OTP driver");
Raspberry Pi OTP driver ?

Regards
> +MODULE_LICENSE("GPL");
> diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
> index e1f87fbfe554..6e94ccf34f47 100644
> --- a/include/soc/bcm2835/raspberrypi-firmware.h
> +++ b/include/soc/bcm2835/raspberrypi-firmware.h
> @@ -92,6 +92,8 @@ enum rpi_firmware_property_tag {
>   	RPI_FIRMWARE_SET_POE_HAT_VAL =                        0x00030050,
>   	RPI_FIRMWARE_NOTIFY_XHCI_RESET =                      0x00030058,
>   	RPI_FIRMWARE_NOTIFY_DISPLAY_DONE =                    0x00030066,
> +	RPI_FIRMWARE_GET_PRIVATE_OTP =                        0x00030081,
> +	RPI_FIRMWARE_SET_PRIVATE_OTP =                        0x00038081,
>   
>   	/* Dispmanx TAGS */
>   	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
>


  reply	other threads:[~2026-04-08 16:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08  8:00 [PATCH 0/3] nvmem: Add Raspberry Pi OTP nvmem driver Gregor Herburger
2026-04-08  8:00 ` [PATCH 1/3] dt-bindings: nvmem: Add a binding for the RPi Firmware OTP register Gregor Herburger
2026-04-09  8:13   ` Krzysztof Kozlowski
2026-04-08  8:00 ` [PATCH 2/3] nvmem: Add the Raspberry Pi OTP driver Gregor Herburger
2026-04-08 16:52   ` Stefan Wahren [this message]
2026-04-08 19:47     ` Gregor Herburger
2026-04-08 20:03       ` Stefan Wahren
2026-04-09  8:05         ` Gregor Herburger
2026-04-09  8:17   ` Krzysztof Kozlowski
2026-04-08  8:00 ` [PATCH 3/3] arm64: dts: broadcom: bcm2712: Add the otp nodes to firmware Gregor Herburger
2026-04-09  8:15   ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=251100fe-db96-4d83-899a-cd764582d698@gmx.net \
    --to=wahrenst@gmx.net \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=gregor.herburger@linutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=rjui@broadcom.com \
    --cc=robh@kernel.org \
    --cc=sbranden@broadcom.com \
    --cc=srini@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox