Skip to content

nvmem: raspberrypi: Add nvmem driver for reading customer OTP - #6014

Merged
pelwell merged 2 commits into
raspberrypi:rpi-6.6.yfrom
popcornmix:nvmen
Apr 5, 2024
Merged

pelwell merged 2 commits into
raspberrypi:rpi-6.6.yfrom
popcornmix:nvmen

Conversation

@popcornmix

Copy link
Copy Markdown
Collaborator

This supports reading and writing OTP using the firmware mailbox interface.

It needs supporting firmware to run.

status = "okay";
};

nvmem_mac: nvmem_mac {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for a user to make the MAC addresses visible but read-only via device-tree or module parameters?

@popcornmix
popcornmix force-pushed the nvmen branch 2 times, most recently from 91830df to 58468a1 Compare March 6, 2024 19:39
@popcornmix

Copy link
Copy Markdown
Collaborator Author

@timg236 updated with:

dtparam=nvmem_customer_writeable

Allow write access to customer otp through nvmem driver
(I suspect we will want to change names, and probably where these entries are places in DT files).

Comment thread drivers/nvmem/Kconfig Outdated

config NVMEM_RASPBERRYPI_OTP
tristate "Raspberry Pi OTP support"
depends on ARCH_BCM || COMPILE_TEST

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should depend on or select RASPBERRYPI_FIRMWARE.

@popcornmix
popcornmix force-pushed the nvmen branch 2 times, most recently from 53418d4 to 41d3301 Compare April 3, 2024 17:08
@popcornmix
popcornmix marked this pull request as ready for review April 3, 2024 17:10
@popcornmix

Copy link
Copy Markdown
Collaborator Author

@pelwell @timg236 I think this is ready for review.

@timg236

timg236 commented Apr 3, 2024

Copy link
Copy Markdown
Contributor

@pelwell @timg236 I think this is ready for review.

Thanks I’ll try this out tomorrow

@pelwell pelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the inline comments, this needs to be split into two commits.

Comment thread arch/arm/boot/dts/overlays/README Outdated

nvme Alias for "pciex1" (2712 only)

nvmem_customer_writeable Allow write access to customer otp through nvmem driver

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter decription must start on column 33, and lines must not exceed 80 characters.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name is too long for that. Any preference for a change?
nvmem_customer_w or customer_writeable?

Comment thread drivers/nvmem/raspberrypi-otp.c Outdated
return -EINVAL;

memcpy(data + 3, val, bytes);
err = rpi_firmware_property(priv->fw, RPI_FIRMWARE_SET_USER_OTP,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to drop err and just "return rpi_firmware_property(..."?

Comment thread drivers/nvmem/Kconfig Outdated
default ARCH_BCM && RASPBERRYPI_FIRMWARE
help
Say y here to enable support for reading OTP on Raspberry Pi boards.
such as the M1. These are e.g. used to store non-volatile board

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"such as the M1." is unwanted text copied from the entry above.

@pelwell

pelwell commented Apr 5, 2024

Copy link
Copy Markdown
Contributor

I think you can cover all downstream dtbs by putting the changes in bcm2708-rpi.dtsi, bcm2711-rpi-ds.dtsi and bcm2712-rpi.dtsi. If we want to change upstream as well, move them to bcm2835-common.dtsi and bcm2711-rpi.dtsi.

This supports reading and writing OTP using the firmware
mailbox interface.

It needs supporting firmware to run.

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
@pelwell

pelwell commented Apr 5, 2024

Copy link
Copy Markdown
Contributor

I also notice that the 2712 nvmem entries are in /soc, whereas the others are in /.

@pelwell

pelwell commented Apr 5, 2024

Copy link
Copy Markdown
Contributor

See https://github.com/pelwell/linux/tree/nvmem - the output is identical. Also consider moving the 2712 nvmem nodes to /

@popcornmix

Copy link
Copy Markdown
Collaborator Author

Updated.

@pelwell pelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider moving the 2712 nvmem nodes to /

Actually, moving the non-2712 nvmems to /soc removes a dtc warning about reg property length.

Comment thread arch/arm/boot/dts/overlays/README Outdated

nvme Alias for "pciex1" (2712 only)

nvmem_cust_rw Allow read/write access to cust otp through nvmem driver

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are over 80 characters long

@pelwell

pelwell commented Apr 5, 2024

Copy link
Copy Markdown
Contributor
diff --git a/arch/arm/boot/dts/broadcom/bcm2708-rpi.dtsi b/arch/arm/boot/dts/broadcom/bcm2708-rpi.dtsi
index 4302f55f57b4d..f4949a07272b6 100644
--- a/arch/arm/boot/dts/broadcom/bcm2708-rpi.dtsi
+++ b/arch/arm/boot/dts/broadcom/bcm2708-rpi.dtsi
@@ -15,6 +15,17 @@ aliases {
                i2c2 = &i2c2;
        };
 
+       __overrides__ {
+               hdmi = <&hdmi>,"status";
+               i2c2_iknowwhatimdoing = <&i2c2>,"status";
+               i2c2_baudrate = <&i2c2>,"clock-frequency:0";
+               nvmem_cust_rw = <&nvmem_cust>,"rw?";
+               sd = <&sdhost>,"status";
+               sd_poll_once = <&sdhost>,"non-removable?";
+       };
+};
+
+&soc {
        nvmem_otp: nvmem_otp {
                compatible = "raspberrypi,rpi-otp";
                firmware = <&firmware>;
@@ -28,15 +39,6 @@ nvmem_cust: nvmem_cust {
                reg = <1 8>;
                status = "okay";
        };
-
-       __overrides__ {
-               hdmi = <&hdmi>,"status";
-               i2c2_iknowwhatimdoing = <&i2c2>,"status";
-               i2c2_baudrate = <&i2c2>,"clock-frequency:0";
-               nvmem_cust_rw = <&nvmem_cust>,"rw?";
-               sd = <&sdhost>,"status";
-               sd_poll_once = <&sdhost>,"non-removable?";
-       };
 };
 
 &sdhost {
diff --git a/arch/arm/boot/dts/broadcom/bcm2711-rpi-ds.dtsi b/arch/arm/boot/dts/broadcom/bcm2711-rpi-ds.dtsi
index daa3b5dfa0bf3..b298cd8bb71ce 100644
--- a/arch/arm/boot/dts/broadcom/bcm2711-rpi-ds.dtsi
+++ b/arch/arm/boot/dts/broadcom/bcm2711-rpi-ds.dtsi
@@ -75,6 +75,21 @@ zone_dma {
                #size-cells = <1>;
                dma-ranges = <0x0  0x0 0x0  0x40000000>;
        };
+};
+
+&vc4 {
+       raspberrypi,firmware = <&firmware>;
+};
+
+&cma {
+       /* Limit cma to the lower 768MB to allow room for HIGHMEM on 32-bit */
+       alloc-ranges = <0x0 0x00000000 0x30000000>;
+};
+
+&soc {
+       /* Add the physical <-> DMA mapping for the I/O space */
+       dma-ranges = <0xc0000000  0x0 0x00000000  0x40000000>,
+                    <0x7c000000  0x0 0xfc000000  0x03800000>;
 
        nvmem_otp: nvmem_otp {
                compatible = "raspberrypi,rpi-otp";
@@ -98,21 +113,6 @@ nvmem_priv: nvmem_priv {
        };
 };
 
-&vc4 {
-       raspberrypi,firmware = <&firmware>;
-};
-
-&cma {
-       /* Limit cma to the lower 768MB to allow room for HIGHMEM on 32-bit */
-       alloc-ranges = <0x0 0x00000000 0x30000000>;
-};
-
-&soc {
-       /* Add the physical <-> DMA mapping for the I/O space */
-       dma-ranges = <0xc0000000  0x0 0x00000000  0x40000000>,
-                    <0x7c000000  0x0 0xfc000000  0x03800000>;
-};
-
 &scb {
        #size-cells = <2>;
 

Signed-off-by: Dom Cobley <popcornmix@gmail.com>
@popcornmix

Copy link
Copy Markdown
Collaborator Author

Updated

@pelwell
pelwell merged commit ec2216e into raspberrypi:rpi-6.6.y Apr 5, 2024
@popcornmix
popcornmix deleted the nvmen branch April 5, 2024 12:57
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Apr 5, 2024
See: raspberrypi/linux#6089

kernel: rp1: Support interrupt CPU affinity
See: raspberrypi/linux#6090

kernel: i2c: designware: Make the SDA hold time half LCNT
See: raspberrypi/linux#6091

kernel: Add support for Chipcap 2 sensor
See: raspberrypi/linux#6083

kernel: nvmem: raspberrypi: Add nvmem driver for reading customer OTP
See: raspberrypi/linux#6014

kernel: Add overlays and configs for several i2c sensors
See: raspberrypi/linux#6093
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Apr 5, 2024
See: raspberrypi/linux#6089

kernel: rp1: Support interrupt CPU affinity
See: raspberrypi/linux#6090

kernel: i2c: designware: Make the SDA hold time half LCNT
See: raspberrypi/linux#6091

kernel: Add support for Chipcap 2 sensor
See: raspberrypi/linux#6083

kernel: nvmem: raspberrypi: Add nvmem driver for reading customer OTP
See: raspberrypi/linux#6014

kernel: Add overlays and configs for several i2c sensors
See: raspberrypi/linux#6093
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Apr 17, 2024
See: raspberrypi/linux#6062

firmware: arm_dt: Improve power HAT+ support

firmware: arm_loader: Add user otp read and write functions
See: raspberrypi/linux#6014

firmware: dtoverlay: Use %u when converting u32s to strings
See: raspberrypi/linux#6039

firmware: video_decode: CONFIGCHANGED not wanted with lack of aspect ratio in new frame
See: https://forum.libreelec.tv/thread/28391-cvideoplayeraudio-process-stream-stalled/?postID=190597#post190597
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Apr 17, 2024
See: raspberrypi/linux#6062

firmware: arm_dt: Improve power HAT+ support

firmware: arm_loader: Add user otp read and write functions
See: raspberrypi/linux#6014

firmware: dtoverlay: Use %u when converting u32s to strings
See: raspberrypi/linux#6039

firmware: video_decode: CONFIGCHANGED not wanted with lack of aspect ratio in new frame
See: https://forum.libreelec.tv/thread/28391-cvideoplayeraudio-process-stream-stalled/?postID=190597#post190597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants