Skip to contentSkip to conversation

Generic SPMI NVMEM cell driver

PATCH Superseded Sasha Finkelstein 4 participants 14 messages Apr 17, 2025 – Apr 23, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Generic SPMI NVMEM cell driver

Hi.

This patch series adds a driver for exposing a set of SPMI registers as NVMEM cells. This is used on Apple ARM platforms to store the RTC offset and to communicate platform power state between the OS and boot firmware.

The NVMEM cell consumer drivers will be sent in a further series.

---
Changes in v2:
- s/pmu/pmic/
- Sort dts in unit-order, instead of t600x-unit-order
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Hector Martin (2):
nvmem: Add spmi-nvmem driver
arm64: dts: apple: Add PMU NVMEM

Sasha Finkelstein (1):
dt-bindings: spmi: Add generic SPMI NVMEM

 .../devicetree/bindings/nvmem/spmi-nvmem.yaml      | 54 +++++++++++++++++++
 MAINTAINERS                                        |  2 +
 arch/arm64/boot/dts/apple/t6001.dtsi               |  1 +
 arch/arm64/boot/dts/apple/t6002.dtsi               |  1 +
 arch/arm64/boot/dts/apple/t600x-die0.dtsi          | 50 +++++++++++++++++
 arch/arm64/boot/dts/apple/t8103.dtsi               | 50 +++++++++++++++++
 arch/arm64/boot/dts/apple/t8112.dtsi               | 50 +++++++++++++++++
 drivers/nvmem/Kconfig                              | 13 +++++
 drivers/nvmem/Makefile                             |  2 +
 drivers/nvmem/spmi-nvmem.c                         | 62 ++++++++++++++++++++++
 10 files changed, 285 insertions(+)

---
base-commit: 2e0e70c95077172b29a5b13716c4b159d578e82c
change-id: 20250415-spmi-nvmem-e08635316175

Best regards,

Signature · 1 line
Sasha Finkelstein <[email protected]>
#1 lore raw

PATCH v2 1/3 dt-bindings: spmi: Add generic SPMI NVMEM

From: Sasha Finkelstein <[email protected]>

Add bindings for exposing SPMI registers as NVMEM cells

---
 .../devicetree/bindings/nvmem/spmi-nvmem.yaml      | 54 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 55 insertions(+)
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +54 -0
new file mode 100644
index 0000000000000000000000000000000000000000..d16b27128f97b5d38fb6ddb5109c70cda5e2ee15
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/spmi-nvmem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic SPMI NVMEM
+
+description: Exports a series of SPMI registers as NVMEM cells
+
+maintainers:
+  - Sasha Finkelstein <[email protected]>
+
+allOf:
+  - $ref: nvmem.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - apple,maverick-pmic
+          - apple,sera-pmic
+          - apple,stowe-pmic
+      - const: spmi-nvmem
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/spmi/spmi.h>
+
+    pmic@f {
+        compatible = "apple,maverick-pmic", "spmi-nvmem";
+        reg = <0xf SPMI_USID>;
+
+        nvmem-layout {
+            compatible = "fixed-layout";
+            #address-cells = <1>;
+            #size-cells = <1>;
+
+            boot_stage: boot-stage@6001 {
+                reg = <0x6001 0x1>;
+            };
+        };
+    };
+
+...
MAINTAINERS +1 -0
index 96b82704950184bd71623ff41fc4df31e4c7fe87..e7b2d0df81b387ba5398957131971588dc7b89dc 100644
@@ -2277,6 +2277,7 @@ F:	Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 F:	Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml
 F:	Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
 F:	Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
+F:	Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml
 F:	Documentation/devicetree/bindings/pci/apple,pcie.yaml
 F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	Documentation/devicetree/bindings/power/apple*
Signature · 1 line
2.49.0
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Quoted 87 lines · Le Thu , Apr 17, 2025 at 10:14:49PM +0200, Sasha Finkelstein via B4 Relay a…

From: Sasha Finkelstein <[email protected]>

Add bindings for exposing SPMI registers as NVMEM cells

---
 .../devicetree/bindings/nvmem/spmi-nvmem.yaml      | 54 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 55 insertions(+)
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +54 -0
new file mode 100644
index 0000000000000000000000000000000000000000..d16b27128f97b5d38fb6ddb5109c70cda5e2ee15
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/spmi-nvmem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic SPMI NVMEM
+
+description: Exports a series of SPMI registers as NVMEM cells
+
+maintainers:
+  - Sasha Finkelstein <[email protected]>
+
+allOf:
+  - $ref: nvmem.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - apple,maverick-pmic
+          - apple,sera-pmic
+          - apple,stowe-pmic
+      - const: spmi-nvmem
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/spmi/spmi.h>
+
+    pmic@f {
+        compatible = "apple,maverick-pmic", "spmi-nvmem";
+        reg = <0xf SPMI_USID>;
+
+        nvmem-layout {
+            compatible = "fixed-layout";
+            #address-cells = <1>;
+            #size-cells = <1>;
+
+            boot_stage: boot-stage@6001 {
+                reg = <0x6001 0x1>;
+            };
+        };
+    };
+
+...
MAINTAINERS +1 -0
index 96b82704950184bd71623ff41fc4df31e4c7fe87..e7b2d0df81b387ba5398957131971588dc7b89dc 100644
@@ -2277,6 +2277,7 @@ F:	Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 F:	Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml
 F:	Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
 F:	Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
+F:	Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml
 F:	Documentation/devicetree/bindings/pci/apple,pcie.yaml
 F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	Documentation/devicetree/bindings/power/apple*
Signature · 2 lines
-- 
2.49.0
maintainer
#3 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

In reply to Sasha Finkelstein
Quoted 14 lines · Sasha Finkelstein

Add bindings for exposing SPMI registers as NVMEM cells

---
 .../devicetree/bindings/nvmem/spmi-nvmem.yaml      | 54 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 55 insertions(+)
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..d16b27128f97b5d38fb6ddb5109c70cda5e2ee15

Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml line 7

Quoted 7 lines
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +7 -0
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/spmi-nvmem.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic SPMI NVMEM

What makes this generic?

A generic driver is great, but "generic" or "simple" bindings are generally a mistake.

Quoted 7 lines
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +7 -0
+
+description: Exports a series of SPMI registers as NVMEM cells
+
+maintainers:
+  - Sasha Finkelstein <[email protected]>
+
+allOf:

Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml line 24

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +10 -0
+  - $ref: nvmem.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - apple,maverick-pmic
+          - apple,sera-pmic
+          - apple,stowe-pmic
+      - const: spmi-nvmem

What happens when there's some other feature of the PMIC exposed that's not nvmem?

Quoted 46 lines
Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml new file +30 -0
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/spmi/spmi.h>
+
+    pmic@f {
+        compatible = "apple,maverick-pmic", "spmi-nvmem";
+        reg = <0xf SPMI_USID>;
+
+        nvmem-layout {
+            compatible = "fixed-layout";
+            #address-cells = <1>;
+            #size-cells = <1>;
+
+            boot_stage: boot-stage@6001 {
+                reg = <0x6001 0x1>;
+            };
+        };
+    };
+
+...
MAINTAINERS +1 -0
index 96b82704950184bd71623ff41fc4df31e4c7fe87..e7b2d0df81b387ba5398957131971588dc7b89dc 100644
@@ -2277,6 +2277,7 @@ F:	Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 F:	Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml
 F:	Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
 F:	Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
+F:	Documentation/devicetree/bindings/nvmem/spmi-nvmem.yaml
 F:	Documentation/devicetree/bindings/pci/apple,pcie.yaml
 F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	Documentation/devicetree/bindings/power/apple*
Signature · 2 lines
-- 
2.49.0
#4 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Quoted 6 lines · Rob Herring
Quoted 1 line

+title: Generic SPMI NVMEM

What makes this generic?

A generic driver is great, but "generic" or "simple" bindings are generally a mistake.

There is nothing apple-specific in that driver, just re-exporting several registers as cells. If you think that it is a mistake, I can rename it to apple-pmic, or something similar.

Quoted 4 lines
Quoted 1 line

+ - const: spmi-nvmem

What happens when there's some other feature of the PMIC exposed that's not nvmem?

If you have a PMIC that needs more features exposed, then you'd have to use a different driver. Or am i not understanding the question correctly?

#5 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Sasha Finkelstein 於 2025/4/22 夜晚9:44 寫道:

Quoted 10 lines · Rob Herring
Quoted 5 lines
Quoted 1 line

+title: Generic SPMI NVMEM

What makes this generic?

A generic driver is great, but "generic" or "simple" bindings are generally a mistake.

There is nothing apple-specific in that driver, just re-exporting several registers as cells. If you think that it is a mistake, I can rename it to apple-pmic, or something similar.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ - const: spmi-nvmem

What happens when there's some other feature of the PMIC exposed that's not nvmem?

If you have a PMIC that needs more features exposed, then you'd have to use a different driver. Or am i not understanding the question correctly?

I think the problem is what happens if more functionalities needed to be exposed from the M1 SoC's PMIC. (right now I do not believe anything else is needed from it)

It would be multiple drivers. A simple-mfd-spmi driver (like drivers/mfd/simple-mfd-i2c.c but SPMI) that exports a regmap and a generic driver that reexports regmap (any regmap, not necessarily SPMI) as nvmem cells, plus extra drivers that uses the regmap exposed by the mfd driver for extra functionalities.

To make this submission more generic and extensible, what would be submitted should be a simple-mfd-spmi driver and a generic regmap nvmem driver. For specific examples, see below:

The PMICs from dialog semiconductor on older Apple SoCs definitely needs such functionalities.

On Apple A11 SoC there is a RTC clock device on the PMIC and the SMC on there does not have RTC functionalities. To make the RTC clock work there a driver would read a counter that could count a maximum of 194 days from the SPMI PMIC, and then access the PMIC nvmem cells that held the rest of the time. In this case these drivers are needed:

(1) simple-mfd-spmi (2) rtc driver (3) generic regmap nvmem driver.

On Apple A7-A10X SoC a similar PMIC also exist, but is over I2C instead of SPMI, those devices do not have a SMC. To make the rtc clock work there three drivers are needed:

(1) simple-mfd-i2c (already exists) (2) rtc driver (same one as above) (3) generic regmap nvmem driver

The PMICs on A7-A10X SoCs are also known to have WLED output for backlight, shutdown controls and some sort of pinctrl needed for things like bluetooth.

In both cases a combination of (1) and (3) is more generic and applies to more than one bus types, and allow extra functionalities other than nvmem to be added.

Quoted 1 line

Nick Chan

maintainer
#6 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Quoted 12 lines · Nick Chan

Sasha Finkelstein 於 2025/4/22 夜晚9:44 寫道:

Quoted 9 lines · Rob Herring
Quoted 5 lines
Quoted 1 line

+title: Generic SPMI NVMEM

What makes this generic?

A generic driver is great, but "generic" or "simple" bindings are generally a mistake.

There is nothing apple-specific in that driver, just re-exporting several registers as cells. If you think that it is a mistake, I can rename it to apple-pmic, or something similar.

Like I said, a generic *driver* is great! I'm all for them. We should have more of them! Generic bindings on the other hand are generally a mistake. The problem is whether a generic driver works for you or not can evolve in either direction. You add more things like described below and then a generic driver doesn't work.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ - const: spmi-nvmem

What happens when there's some other feature of the PMIC exposed that's not nvmem?

If you have a PMIC that needs more features exposed, then you'd have to use a different driver. Or am i not understanding the question correctly?

I think the problem is what happens if more functionalities needed to be exposed from the M1 SoC's PMIC. (right now I do not believe anything else is needed from it)

Yes, and you can add to the binding then, but you are stuck with what you define now.

Quoted 7 lines

It would be multiple drivers. A simple-mfd-spmi driver (like drivers/mfd/simple-mfd-i2c.c but SPMI) that exports a regmap and a generic driver that reexports regmap (any regmap, not necessarily SPMI) as nvmem cells, plus extra drivers that uses the regmap exposed by the mfd driver for extra functionalities.

To make this submission more generic and extensible, what would be submitted should be a simple-mfd-spmi driver and a generic regmap nvmem driver. For specific examples, see below:

It is not an MFD currently, so you don't need an MFD driver. As I said, that can evolve.

Drivers are bus specific, so you can't have a generic regmap driver. There's only 4 nvmem drivers using regmap anyways. qcom-spmi-sdam is one of them, and maybe one driver could handle that and Apple.

Quoted 7 lines

The PMICs from dialog semiconductor on older Apple SoCs definitely needs such functionalities.

On Apple A11 SoC there is a RTC clock device on the PMIC and the SMC on there does not have RTC functionalities. To make the RTC clock work there a driver would read a counter that could count a maximum of 194 days from the SPMI PMIC, and then access the PMIC nvmem cells that held the rest of the time. In this case these drivers are needed:

Quoted 6 lines

(1) simple-mfd-spmi (2) rtc driver (3) generic regmap nvmem driver.

On Apple A7-A10X SoC a similar PMIC also exist, but is over I2C instead of SPMI, those devices do not have a SMC. To make the rtc clock work there three drivers are needed:

(1) simple-mfd-i2c (already exists) (2) rtc driver (same one as above) (3) generic regmap nvmem driver

It all sounds a bit different from what's there on the M series, so perhaps better not to mix the 2 just because it is all apple. The A series stuff might have more in common with existing Dialog PMICs.

Rob

#7 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

What makes this generic?

A generic driver is great, but "generic" or "simple" bindings are generally a mistake.

There is nothing apple-specific in that driver, just re-exporting several registers as cells. If you think that it is a mistake, I can rename it to apple-pmic, or something similar.

Quoted 5 lines

Like I said, a generic *driver* is great! I'm all for them. We should have more of them! Generic bindings on the other hand are generally a mistake. The problem is whether a generic driver works for you or not can evolve in either direction. You add more things like described below and then a generic driver doesn't work.

It sounds like the path of least resistance here is then:

1. rename the bindings to be apple m1+ (at least for now)
2. keep the driver as-is (no mfd, etc - at least for now)
3. land just that (at least for now)

Evolving the driver to share with not-Apple, or evolving the bindings+driver to share with pre-M1, can happen in future series if/when somebody wants to do that work.

Is this a fair understanding of the situation?

#8 lore raw

Re: [PATCH v2 1/3] dt-bindings: spmi: Add generic SPMI NVMEM

Quoted 9 lines · Alyssa Rosenzweig

It sounds like the path of least resistance here is then:

1. rename the bindings to be apple m1+ (at least for now)
2. keep the driver as-is (no mfd, etc - at least for now)
3. land just that (at least for now)

Evolving the driver to share with not-Apple, or evolving the bindings+driver to share with pre-M1, can happen in future series if/when somebody wants to do that work.

That is precisely my plan for v3, which I intend to send soon-ish.

#9 lore raw

PATCH v2 2/3 nvmem: Add spmi-nvmem driver

In reply to Sasha Finkelstein

From: Hector Martin <[email protected]>

This driver exposes a SPMI device as an NVMEM device. It is intended to be used with e.g. PMUs/PMICs that are used to hold power management configuration, such as used on Apple Silicon Macs.

---
 MAINTAINERS                |  1 +
 drivers/nvmem/Kconfig      | 13 ++++++++++
 drivers/nvmem/Makefile     |  2 ++
 drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+)
MAINTAINERS +1 -0
index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644
@@ -2298,6 +2298,7 @@ F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
 F:	drivers/nvme/host/apple.c
 F:	drivers/nvmem/apple-efuses.c
+F:	drivers/nvmem/spmi-nvmem.c
 F:	drivers/pinctrl/pinctrl-apple-gpio.c
 F:	drivers/pwm/pwm-apple.c
 F:	drivers/soc/apple/*
drivers/nvmem/Kconfig +13 -0
index 8671b7c974b933e147154bb40b5d41b5730518d2..c25c599fc79648e890ccc4e003224c9a218f393f 100644
@@ -310,6 +310,19 @@ 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_SPMI
+	tristate "Generic SPMI NVMEM"
+	depends on SPMI
+	select REGMAP_SPMI
+	help
+	  Say y here to build a generic driver to expose a SPMI device
+	  as a NVMEM provider. This can be used for PMIC/PMU devices which
+	  are used to store power and RTC-related settings on certain
+	  platforms, such as Apple Silicon Macs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-spmi.
+
 config NVMEM_SPMI_SDAM
 	tristate "SPMI SDAM Support"
 	depends on SPMI
drivers/nvmem/Makefile +2 -0
index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..b639f4284184db026bb27b11e04d54b8f7ff166f 100644
@@ -64,6 +64,8 @@ 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_SPMI)		+= nvmem_spmi.o
+nvmem_spmi-y				:= spmi-nvmem.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/spmi-nvmem.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v2 2/3
#10 lore raw

Re: [PATCH v2 2/3] nvmem: Add spmi-nvmem driver

Quoted 140 lines · Le Thu , Apr 17, 2025 at 10:14:50PM +0200, Sasha Finkelstein via B4 Relay a…

From: Hector Martin <[email protected]>

This driver exposes a SPMI device as an NVMEM device. It is intended to be used with e.g. PMUs/PMICs that are used to hold power management configuration, such as used on Apple Silicon Macs.

---
 MAINTAINERS                |  1 +
 drivers/nvmem/Kconfig      | 13 ++++++++++
 drivers/nvmem/Makefile     |  2 ++
 drivers/nvmem/spmi-nvmem.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+)
MAINTAINERS +1 -0
index e7b2d0df81b387ba5398957131971588dc7b89dc..63c12f901aed1f3e6de8227d6db34af1bd046fe6 100644
@@ -2298,6 +2298,7 @@ F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
 F:	drivers/nvme/host/apple.c
 F:	drivers/nvmem/apple-efuses.c
+F:	drivers/nvmem/spmi-nvmem.c
 F:	drivers/pinctrl/pinctrl-apple-gpio.c
 F:	drivers/pwm/pwm-apple.c
 F:	drivers/soc/apple/*
drivers/nvmem/Kconfig +13 -0
index 8671b7c974b933e147154bb40b5d41b5730518d2..c25c599fc79648e890ccc4e003224c9a218f393f 100644
@@ -310,6 +310,19 @@ 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_SPMI
+	tristate "Generic SPMI NVMEM"
+	depends on SPMI
+	select REGMAP_SPMI
+	help
+	  Say y here to build a generic driver to expose a SPMI device
+	  as a NVMEM provider. This can be used for PMIC/PMU devices which
+	  are used to store power and RTC-related settings on certain
+	  platforms, such as Apple Silicon Macs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-spmi.
+
 config NVMEM_SPMI_SDAM
 	tristate "SPMI SDAM Support"
 	depends on SPMI
drivers/nvmem/Makefile +2 -0
index 5b77bbb6488bf89bfb305750a1cbf4a6731a0a58..b639f4284184db026bb27b11e04d54b8f7ff166f 100644
@@ -64,6 +64,8 @@ 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_SPMI)		+= nvmem_spmi.o
+nvmem_spmi-y				:= spmi-nvmem.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/spmi-nvmem.c new file +62 -0
new file mode 100644
index 0000000000000000000000000000000000000000..fff6162cb22dd7ab45883f004f5b63ebae014698
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * Generic SPMI NVMEM driver
+ *
+ * Copyright The Asahi Linux Contributors
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/spmi.h>
+#include <linux/regmap.h>
+
+static const struct regmap_config spmi_regmap_config = {
+	.reg_bits	= 16,
+	.val_bits	= 8,
+	.max_register	= 0xffff,
+};
+
+static int spmi_nvmem_probe(struct spmi_device *sdev)
+{
+	struct regmap *regmap;
+	struct nvmem_config nvmem_cfg = {
+		.dev = &sdev->dev,
+		.name = "spmi_nvmem",
+		.id = NVMEM_DEVID_AUTO,
+		.word_size = 1,
+		.stride = 1,
+		.size = 0xffff,
+		.reg_read = (void *)regmap_bulk_read,
+		.reg_write = (void *)regmap_bulk_write,
+	};
+
+	regmap = devm_regmap_init_spmi_ext(sdev, &spmi_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	nvmem_cfg.priv = regmap;
+
+	return PTR_ERR_OR_ZERO(devm_nvmem_register(&sdev->dev, &nvmem_cfg));
+}
+
+static const struct of_device_id spmi_nvmem_id_table[] = {
+	{ .compatible = "spmi-nvmem" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, spmi_nvmem_id_table);
+
+static struct spmi_driver spmi_nvmem_driver = {
+	.probe = spmi_nvmem_probe,
+	.driver = {
+		.name = "spmi-nvmem",
+		.of_match_table	= spmi_nvmem_id_table,
+	},
+};
+
+module_spmi_driver(spmi_nvmem_driver);
+
+MODULE_LICENSE("Dual MIT/GPL");
+MODULE_AUTHOR("Hector Martin <[email protected]>");
+MODULE_DESCRIPTION("SPMI NVMEM driver");
Signature · 2 lines
-- 
2.49.0
#11 lore raw

PATCH v2 3/3 arm64: dts: apple: Add PMU NVMEM

In reply to Sasha Finkelstein

From: Hector Martin <[email protected]>

Add device tree entries for NVMEM cells present on the PMU

---
 arch/arm64/boot/dts/apple/t6001.dtsi      |  1 +
 arch/arm64/boot/dts/apple/t6002.dtsi      |  1 +
 arch/arm64/boot/dts/apple/t600x-die0.dtsi | 50 +++++++++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8103.dtsi      | 50 +++++++++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8112.dtsi      | 50 +++++++++++++++++++++++++++++++
 5 files changed, 152 insertions(+)
arch/arm64/boot/dts/apple/t6001.dtsi +1 -0
index 620b17e4031f069874aaabadbf06b7b29ec4031e..d2cf81926f284ccf7627701cc82edff31d4d72d6 100644
@@ -11,6 +11,7 @@
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/pinctrl/apple.h>
+#include <dt-bindings/spmi/spmi.h>
 
 #include "multi-die-cpp.h"
 
arch/arm64/boot/dts/apple/t6002.dtsi +1 -0
index a963a5011799a0480f88688fb4372a31f0bbf806..e36f422d257d8fe3a62bfa6e0f0e0dc6c34608a4 100644
@@ -11,6 +11,7 @@
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/pinctrl/apple.h>
+#include <dt-bindings/spmi/spmi.h>
 
 #include "multi-die-cpp.h"
 
arch/arm64/boot/dts/apple/t600x-die0.dtsi +50 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/apple/t8103.dtsi +50 -0

56 lines not on this page · raw message

arch/arm64/boot/dts/apple/t8112.dtsi +50 -0

56 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v2 3/3
#12 lore raw

Re: [PATCH v2 3/3] arm64: dts: apple: Add PMU NVMEM

Quoted 227 lines · Le Thu , Apr 17, 2025 at 10:14:51PM +0200, Sasha Finkelstein via B4 Relay a…

From: Hector Martin <[email protected]>

Add device tree entries for NVMEM cells present on the PMU

---
 arch/arm64/boot/dts/apple/t6001.dtsi      |  1 +
 arch/arm64/boot/dts/apple/t6002.dtsi      |  1 +
 arch/arm64/boot/dts/apple/t600x-die0.dtsi | 50 +++++++++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8103.dtsi      | 50 +++++++++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8112.dtsi      | 50 +++++++++++++++++++++++++++++++
 5 files changed, 152 insertions(+)
arch/arm64/boot/dts/apple/t6001.dtsi +1 -0
index 620b17e4031f069874aaabadbf06b7b29ec4031e..d2cf81926f284ccf7627701cc82edff31d4d72d6 100644
@@ -11,6 +11,7 @@
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/pinctrl/apple.h>
+#include <dt-bindings/spmi/spmi.h>
 
 #include "multi-die-cpp.h"
 
arch/arm64/boot/dts/apple/t6002.dtsi +1 -0
index a963a5011799a0480f88688fb4372a31f0bbf806..e36f422d257d8fe3a62bfa6e0f0e0dc6c34608a4 100644
@@ -11,6 +11,7 @@
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/pinctrl/apple.h>
+#include <dt-bindings/spmi/spmi.h>
 
 #include "multi-die-cpp.h"
 
arch/arm64/boot/dts/apple/t600x-die0.dtsi +50 -0
index 4c224e686ffe5602329f7f394d3354559c4130ab..fba01727ee8bd67990cb001a5727d5dd2d01e2ee 100644
@@ -50,6 +50,56 @@ nub_spmi0: spmi@2920a1300 {
 		reg = <0x2 0x920a1300 0x0 0x100>;
 		#address-cells = <2>;
 		#size-cells = <0>;
+
+		pmic1: pmic@f {
+			compatible = "apple,maverick-pmic", "spmi-nvmem";
+			reg = <0xf SPMI_USID>;
+
+			nvmem-layout {
+				compatible = "fixed-layout";
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				pm_setting: pm-setting@1405 {
+					reg = <0x1405 0x1>;
+				};
+
+				rtc_offset: rtc-offset@1411 {
+					reg = <0x1411 0x6>;
+				};
+
+				boot_stage: boot-stage@6001 {
+					reg = <0x6001 0x1>;
+				};
+
+				boot_error_count: boot-error-count@6002 {
+					reg = <0x6002 0x1>;
+					bits = <0 4>;
+				};
+
+				panic_count: panic-count@6002 {
+					reg = <0x6002 0x1>;
+					bits = <4 4>;
+				};
+
+				boot_error_stage: boot-error-stage@6003 {
+					reg = <0x6003 0x1>;
+				};
+
+				shutdown_flag: shutdown-flag@600f {
+					reg = <0x600f 0x1>;
+					bits = <3 1>;
+				};
+
+				fault_shadow: fault-shadow@867b {
+					reg = <0x867b 0x10>;
+				};
+
+				socd: socd@8b00 {
+					reg = <0x8b00 0x400>;
+				};
+			};
+		};
 	};
 
 	wdt: watchdog@2922b0000 {
arch/arm64/boot/dts/apple/t8103.dtsi +50 -0
index bdb1cb9e406a441e458b1c735359b0148146e91b..3892fbe6a955513cad2ae836acc3e83009ab7cc5 100644
@@ -747,6 +747,56 @@ nub_spmi: spmi@23d0d9300 {
 			reg = <0x2 0x3d0d9300 0x0 0x100>;
 			#address-cells = <2>;
 			#size-cells = <0>;
+
+			pmic1: pmic@f {
+				compatible = "apple,sera-pmic", "spmi-nvmem";
+				reg = <0xf SPMI_USID>;
+
+				nvmem-layout {
+					compatible = "fixed-layout";
+					#address-cells = <1>;
+					#size-cells = <1>;
+
+					boot_stage: boot-stage@9f01 {
+						reg = <0x9f01 0x1>;
+					};
+
+					boot_error_count: boot-error-count@9f02 {
+						reg = <0x9f02 0x1>;
+						bits = <0 4>;
+					};
+
+					panic_count: panic-count@9f02 {
+						reg = <0x9f02 0x1>;
+						bits = <4 4>;
+					};
+
+					boot_error_stage: boot-error-stage@9f03 {
+						reg = <0x9f03 0x1>;
+					};
+
+					shutdown_flag: shutdown-flag@9f0f {
+						reg = <0x9f0f 0x1>;
+						bits = <3 1>;
+					};
+
+					fault_shadow: fault-shadow@a67b {
+						reg = <0xa67b 0x10>;
+					};
+
+					socd: socd@ab00 {
+						reg = <0xab00 0x400>;
+					};
+
+					pm_setting: pm-setting@d001 {
+						reg = <0xd001 0x1>;
+					};
+
+					rtc_offset: rtc-offset@d100 {
+						reg = <0xd100 0x6>;
+					};
+				};
+			};
 		};
 
 		pinctrl_nub: pinctrl@23d1f0000 {
arch/arm64/boot/dts/apple/t8112.dtsi +50 -0
index 950d1f906ba3023c1d118179207a2099345aae94..325e2ac22b3c88d863b2270c39a0a05d625e3f10 100644
@@ -787,6 +787,56 @@ nub_spmi: spmi@23d714000 {
 			reg = <0x2 0x3d714000 0x0 0x100>;
 			#address-cells = <2>;
 			#size-cells = <0>;
+
+			pmic1: pmic@e {
+				compatible = "apple,stowe-pmic", "spmi-nvmem";
+				reg = <0xe SPMI_USID>;
+
+				nvmem-layout {
+					compatible = "fixed-layout";
+					#address-cells = <1>;
+					#size-cells = <1>;
+
+					fault_shadow: fault-shadow@867b {
+						reg = <0x867b 0x10>;
+					};
+
+					socd: socd@8b00 {
+						reg = <0x8b00 0x400>;
+					};
+
+					boot_stage: boot-stage@f701 {
+						reg = <0xf701 0x1>;
+					};
+
+					boot_error_count: boot-error-count@f702 {
+						reg = <0xf702 0x1>;
+						bits = <0 4>;
+					};
+
+					panic_count: panic-count@f702 {
+						reg = <0xf702 0x1>;
+						bits = <4 4>;
+					};
+
+					boot_error_stage: boot-error-stage@f703 {
+						reg = <0xf703 0x1>;
+					};
+
+					shutdown_flag: shutdown-flag@f70f {
+						reg = <0xf70f 0x1>;
+						bits = <3 1>;
+					};
+
+					pm_setting: pm-setting@f801 {
+						reg = <0xf801 0x1>;
+					};
+
+					rtc_offset: rtc-offset@f900 {
+						reg = <0xf900 0x6>;
+					};
+				};
+			};
 		};
 
 		pinctrl_smc: pinctrl@23e820000 {
Signature · 2 lines
-- 
2.49.0