Skip to contentSkip to conversation

Add read-only SpacemiT K3 eFuse support

PATCH Superseded Jiayu Du 3 participants 9 messages Nov 16 – Nov 18

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiayu Du

author
#0 lore raw

v2 cover Add read-only SpacemiT K3 eFuse support

This series adds read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Tested on a SpacemiT K3 COM260 Kit: shadow reload completed successfully, and reads of both banks matched v1. Repeated reads and reads crossing bank/keepout boundaries returned the expected data.

Changes in v2:
- Trigger a shadow reload before polling FUSE_READY; fail probe on timeout.
- Enable the clock only while accessing hardware and leave the shared reset deasserted on teardown.
- Explain why the root key and SSK registers are excluded.
- Use an aligned __le32 cache instead of put_unaligned_le32().
- Drop unnecessary Kconfig dependencies and the bootloader initialization requirement.
- Use devm_platform_ioremap_resource() and align the register definitions.
- Enable the eFuse node by default in k3.dtsi.
- Add Conor's Acked-by to the binding patch.

v1: https://lore.kernel.org/all/[email protected]/

Jiayu Du (3):
dt-bindings: nvmem: Add SpacemiT K3 eFuse controller
nvmem: Add read-only SpacemiT K3 eFuse support
riscv: dts: spacemit: Add K3 eFuse and temperature trim cells

 .../bindings/nvmem/spacemit,k3-efuse.yaml     |  63 ++++++
 MAINTAINERS                                   |   6 +
 arch/riscv/boot/dts/spacemit/k3.dtsi          |  23 ++
 drivers/nvmem/Kconfig                         |  11 +
 drivers/nvmem/Makefile                        |   1 +
 drivers/nvmem/spacemit-k3-efuse.c             | 199 ++++++++++++++++++
 6 files changed, 303 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/spacemit,k3-efuse.yaml
 create mode 100644 drivers/nvmem/spacemit-k3-efuse.c

base-commit: d6bcfc94eb4da6e089c5473970cd96727292fd97

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/3 dt-bindings: nvmem: Add SpacemiT K3 eFuse controller

Describe the SpacemiT K3 eFuse controller and its readable bank 0 and bank 7 shadow windows, which contain temperature calibration parameters and other configuration data.

Define the AES_WTM clock and reset, little-endian data and controller-relative NVMEM offsets. Use fixed-layout cells for the temperature calibration parameters.

---
 .../bindings/nvmem/spacemit,k3-efuse.yaml     | 63 +++++++++++++++++++
 MAINTAINERS                                   |  5 ++
 2 files changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/spacemit,k3-efuse.yaml
Documentation/devicetree/bindings/nvmem/spacemit,k3-efuse.yaml new file +63 -0
new file mode 100644
index 000000000000..93f4301c8289
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/spacemit,k3-efuse.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 eFuse controller
+
+maintainers:
+  - Jiayu Du <[email protected]>
+
+description:
+  The K3 eFuse controller provides configuration and calibration data through
+  shadow registers. NVMEM uses little-endian data and controller-relative
+  offsets. Read access is limited to bank 0 (0x104-0x123) and bank 7 (0x190-0x1af).
+
+allOf:
+  - $ref: nvmem.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k3-efuse
+
+  reg:
+    maxItems: 1
+    description: The 0x400-byte eFuse controller register block.
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/spacemit,k3-clocks.h>
+    #include <dt-bindings/reset/spacemit,k3-resets.h>
+
+    efuse@f0702800 {
+        compatible = "spacemit,k3-efuse";
+        reg = <0xf0702800 0x400>;
+        clocks = <&syscon_apmu CLK_APMU_AES_WTM>;
+        resets = <&syscon_apmu RESET_APMU_AES_WTM>;
+
+        nvmem-layout {
+            compatible = "fixed-layout";
+            #address-cells = <1>;
+            #size-cells = <1>;
+
+            temperature-trim@19a {
+                reg = <0x19a 0x2>;
+                bits = <4 8>;
+            };
+        };
+    };
MAINTAINERS +5 -0
index 46c416cadacd..0a9eb764ffee 100644
@@ -26525,6 +26525,11 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
 F:	sound/soc/spacemit/k1_i2s.c
 
+SPACEMIT K3 EFUSE DRIVER
+M:	Jiayu Du <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/nvmem/spacemit,k3-efuse.yaml
+
 SPACEMIT RESET CONTROLLER DRIVER
 M:	Guodong Xu <[email protected]>
 L:	[email protected]
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/3 nvmem: Add read-only SpacemiT K3 eFuse support

In reply to Jiayu Du

Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Keep the root key and SSK registers outside the exposed bank ranges.

FUSE_READY reports completion of a software-triggered reload. Trigger a reload through GEU_CONFIG bit 22 with a 1 us reset pulse, then poll FUSE_READY at a 1 us interval with a 10 ms timeout before taking the snapshot. Fail probe if the reload times out.

Snapshot the shadow registers with aligned 32-bit reads and expose the data in little-endian order at controller-relative offsets. Serve reads from the snapshot and use keepouts for the remaining register ranges.

Enable the AES_WTM clock only while accessing the hardware. Leave its shared reset deasserted on teardown because WTM_RST resets the entire GEU.

---
 MAINTAINERS                       |   1 +
 drivers/nvmem/Kconfig             |  11 ++
 drivers/nvmem/Makefile            |   1 +
 drivers/nvmem/spacemit-k3-efuse.c | 199 ++++++++++++++++++++++++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/nvmem/spacemit-k3-efuse.c
MAINTAINERS +1 -0
index 0a9eb764ffee..e0af83ecee37 100644
@@ -26529,6 +26529,7 @@ SPACEMIT K3 EFUSE DRIVER
 M:	Jiayu Du <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/nvmem/spacemit,k3-efuse.yaml
+F:	drivers/nvmem/spacemit-k3-efuse.c
 
 SPACEMIT RESET CONTROLLER DRIVER
 M:	Guodong Xu <[email protected]>
drivers/nvmem/Kconfig +11 -0
index d2f5bb236663..4a8f975b35c7 100644
@@ -476,6 +476,17 @@ 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_SPACEMIT_K3_EFUSE
+	tristate "SpacemiT K3 eFuse support"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on OF && HAS_IOMEM
+	help
+	  Say Y here to read configuration and calibration data from the
+	  SpacemiT K3 eFuse shadow banks. Programming the fuses is not supported.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called spacemit-k3-efuse.
+
 config NVMEM_SPMI_SDAM
 	tristate "SPMI SDAM Support"
 	depends on SPMI
drivers/nvmem/Makefile +1 -0
index 5e70bad9f0f9..d29716957faf 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_NVMEM_SC27XX_EFUSE)	+= nvmem-sc27xx-efuse.o
 nvmem-sc27xx-efuse-y			:= sc27xx-efuse.o
 obj-$(CONFIG_NVMEM_SNVS_LPGPR)		+= nvmem_snvs_lpgpr.o
 nvmem_snvs_lpgpr-y			:= snvs_lpgpr.o
+obj-$(CONFIG_NVMEM_SPACEMIT_K3_EFUSE)	+= spacemit-k3-efuse.o
 obj-$(CONFIG_NVMEM_SPMI_SDAM)		+= nvmem_qcom-spmi-sdam.o
 nvmem_qcom-spmi-sdam-y			+= qcom-spmi-sdam.o
 obj-$(CONFIG_NVMEM_SPRD_EFUSE)		+= nvmem_sprd_efuse.o
drivers/nvmem/spacemit-k3-efuse.c new file +199 -0

199 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v2 2/3] nvmem: Add read-only SpacemiT K3 eFuse support

Quoted 11 lines · Jiayu Du

Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Keep the root key and SSK registers outside the exposed bank ranges.

FUSE_READY reports completion of a software-triggered reload. Trigger a reload through GEU_CONFIG bit 22 with a 1 us reset pulse, then poll FUSE_READY at a 1 us interval with a 10 ms timeout before taking the snapshot. Fail probe if the reload times out.

Quoted 6 lines

Snapshot the shadow registers with aligned 32-bit reads and expose the data in little-endian order at controller-relative offsets. Serve reads from the snapshot and use keepouts for the remaining register ranges.

Enable the AES_WTM clock only while accessing the hardware. Leave its shared reset deasserted on teardown because WTM_RST resets the entire GEU.

I don't understand this, possibly because I don't know what GEU is.

What is this reset shared with, and why exactly does the reset need to stay deasserted?

regards
Philipp

author
#4 lore raw

Re: [PATCH v2 2/3] nvmem: Add read-only SpacemiT K3 eFuse support

Quoted 16 lines · Philipp Zabel
Quoted 15 lines · Jiayu Du

Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Keep the root key and SSK registers outside the exposed bank ranges.

FUSE_READY reports completion of a software-triggered reload. Trigger a reload through GEU_CONFIG bit 22 with a 1 us reset pulse, then poll FUSE_READY at a 1 us interval with a 10 ms timeout before taking the snapshot. Fail probe if the reload times out.

Snapshot the shadow registers with aligned 32-bit reads and expose the data in little-endian order at controller-relative offsets. Serve reads from the snapshot and use keepouts for the remaining register ranges.

Quoted 7 lines
Quoted 2 lines

Enable the AES_WTM clock only while accessing the hardware. Leave its shared reset deasserted on teardown because WTM_RST resets the entire GEU.

I don't understand this, possibly because I don't know what GEU is.

What is this reset shared with, and why exactly does the reset need to stay deasserted?

GEU stands for Generic Encryption and Fuse Unit. This reset is not shared with another consumer and only resets the controller state. My explanation about needing to keep it deasserted was incorrect.

For v3, I've switched to devm_reset_control_get_exclusive_deasserted() and removed that explanation. The reset is now asserted on driver detach or a subsequent probe failure.

Best regards
Jiayu Du

Quoted 3 lines

regards
Philipp

#5 lore raw

Re: [PATCH v2 2/3] nvmem: Add read-only SpacemiT K3 eFuse support

In reply to Jiayu Du

Hi,

Quoted 18 lines · Jiayu Du

Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Keep the root key and SSK registers outside the exposed bank ranges.

FUSE_READY reports completion of a software-triggered reload. Trigger a reload through GEU_CONFIG bit 22 with a 1 us reset pulse, then poll FUSE_READY at a 1 us interval with a 10 ms timeout before taking the snapshot. Fail probe if the reload times out.

Snapshot the shadow registers with aligned 32-bit reads and expose the data in little-endian order at controller-relative offsets. Serve reads from the snapshot and use keepouts for the remaining register ranges.

Enable the AES_WTM clock only while accessing the hardware. Leave its shared reset deasserted on teardown because WTM_RST resets the entire GEU.

Quoted 8 lines
---
 MAINTAINERS                       |   1 +
 drivers/nvmem/Kconfig             |  11 ++
 drivers/nvmem/Makefile            |   1 +
 drivers/nvmem/spacemit-k3-efuse.c | 199 ++++++++++++++++++++++++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/nvmem/spacemit-k3-efuse.c

I have been looking at the code with more details. Is there any reason to "expose" the whole 1024-byte efuse address space in the nvmem layout (of course with some masking) as opposed to the 16 banks x 32 bytes = 4096 bits only (still with masking)?

I find strange that user space has to know the address of bank 0 or bank 7 instead of just looking respectively at addresses 0x000 and 0x0e0.

As the layout exposed to user space also includes status or control registers (although masked), this might makes difficult to support a newer version of the efuse controller which have a similar data layout, but slightly different registers colliding with the bank data.

Regards
Aurelien

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net
author
#6 lore raw

Re: [PATCH v2 2/3] nvmem: Add read-only SpacemiT K3 eFuse support

Quoted 35 lines · Aurelien Jarno

Hi,

Quoted 18 lines · Jiayu Du

Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse controller. These banks contain temperature calibration parameters and other configuration data.

Keep the root key and SSK registers outside the exposed bank ranges.

FUSE_READY reports completion of a software-triggered reload. Trigger a reload through GEU_CONFIG bit 22 with a 1 us reset pulse, then poll FUSE_READY at a 1 us interval with a 10 ms timeout before taking the snapshot. Fail probe if the reload times out.

Snapshot the shadow registers with aligned 32-bit reads and expose the data in little-endian order at controller-relative offsets. Serve reads from the snapshot and use keepouts for the remaining register ranges.

Enable the AES_WTM clock only while accessing the hardware. Leave its shared reset deasserted on teardown because WTM_RST resets the entire GEU.

Quoted 8 lines
---
 MAINTAINERS                       |   1 +
 drivers/nvmem/Kconfig             |  11 ++
 drivers/nvmem/Makefile            |   1 +
 drivers/nvmem/spacemit-k3-efuse.c | 199 ++++++++++++++++++++++++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/nvmem/spacemit-k3-efuse.c

I have been looking at the code with more details. Is there any reason to "expose" the whole 1024-byte efuse address space in the nvmem layout (of course with some masking) as opposed to the 16 banks x 32 bytes = 4096 bits only (still with masking)?

Quoted 8 lines

I find strange that user space has to know the address of bank 0 or bank 7 instead of just looking respectively at addresses 0x000 and 0x0e0.

As the layout exposed to user space also includes status or control registers (although masked), this might makes difficult to support a newer version of the efuse controller which have a similar data layout, but slightly different registers colliding with the bank data.

Hi Aurelien,

I will use a 512-byte NVMEM space, with bank 0 starting at 0x000 and bank 7 at 0x0e0. The other banks will remain covered by keepouts.

I will also update the temperature calibration cell offsets in the device tree to 0x1c and 0xea. The hardware accesses will stay unchanged.

Best regards,
Jiayu Du

author
#7 lore raw

PATCH v2 3/3 riscv: dts: spacemit: Add K3 eFuse and temperature trim cells

In reply to Jiayu Du

Add the K3 eFuse controller with its AES_WTM clock and reset. Describe fixed-layout cells for the temperature calibration parameters stored in bank 0 and bank 7, using controller-relative offsets.

---
 arch/riscv/boot/dts/spacemit/k3.dtsi | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
arch/riscv/boot/dts/spacemit/k3.dtsi +23 -0
index e89d2cc5ca8c..b548f5029d59 100644
@@ -1439,6 +1439,29 @@ saplic: interrupt-controller@e0804000 {
 
 		/* sec_i2c3: 0xf0614000, not available from Linux */
 
+		efuse: efuse@f0702800 {
+			compatible = "spacemit,k3-efuse";
+			reg = <0x0 0xf0702800 0x0 0x400>;
+			clocks = <&syscon_apmu CLK_APMU_AES_WTM>;
+			resets = <&syscon_apmu RESET_APMU_AES_WTM>;
+
+			nvmem-layout {
+				compatible = "fixed-layout";
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				soc_rtemp_trim1: temperature-trim@120 {
+					reg = <0x120 0x1>;
+					bits = <0 8>;
+				};
+
+				soc_rtemp_trim: temperature-trim@19a {
+					reg = <0x19a 0x2>;
+					bits = <4 8>;
+				};
+			};
+		};
+
 		mimsic: interrupt-controller@f1000000 {
 			compatible = "spacemit,k3-imsics", "riscv,imsics";
 			reg = <0x0 0xf1000000 0x0 0x10000>;
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v2 3/3] riscv: dts: spacemit: Add K3 eFuse and temperature trim cells

Hi,

Quoted 33 lines · Jiayu Du

Add the K3 eFuse controller with its AES_WTM clock and reset. Describe fixed-layout cells for the temperature calibration parameters stored in bank 0 and bank 7, using controller-relative offsets.

---
 arch/riscv/boot/dts/spacemit/k3.dtsi | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
arch/riscv/boot/dts/spacemit/k3.dtsi +16 -0
index e89d2cc5ca8c..b548f5029d59 100644
@@ -1439,6 +1439,29 @@ saplic: interrupt-controller@e0804000 {
 
 		/* sec_i2c3: 0xf0614000, not available from Linux */
 
+		efuse: efuse@f0702800 {
+			compatible = "spacemit,k3-efuse";
+			reg = <0x0 0xf0702800 0x0 0x400>;
+			clocks = <&syscon_apmu CLK_APMU_AES_WTM>;
+			resets = <&syscon_apmu RESET_APMU_AES_WTM>;
+
+			nvmem-layout {
+				compatible = "fixed-layout";
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				soc_rtemp_trim1: temperature-trim@120 {
+					reg = <0x120 0x1>;
+					bits = <0 8>;
+				};
+

arch/riscv/boot/dts/spacemit/k3.dtsi saplic: interrupt-controller@e0804000 { · line 1467

Quoted 10 lines
arch/riscv/boot/dts/spacemit/k3.dtsi +7 -0
+				soc_rtemp_trim: temperature-trim@19a {
+					reg = <0x19a 0x2>;
+					bits = <4 8>;
+				};
+			};
+		};
+
 		mimsic: interrupt-controller@f1000000 {
 			compatible = "spacemit,k3-imsics", "riscv,imsics";
 			reg = <0x0 0xf1000000 0x0 0x10000>;

Thanks for this new version which is now enabled directly at the K3 level instead of the board level. This looks good to me, except the offsets values, given my remark on the other patch.

Regards
Aurelien

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net