Skip to contentSkip to conversation

dt-bindings: nvmem: syscon: Add syscon backed nvmem bindings

RFC PATCH Superseded Marek Vasut 2 participants 6 messages Oct 27, 2022 – Nov 27, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/3 dt-bindings: nvmem: syscon: Add syscon backed nvmem bindings

Add trivial bindings for driver which permits exposing syscon backed register to userspace. This is useful e.g. to expose U-Boot boot counter on various platforms where the boot counter is stored in random volatile register, like STM32MP15xx TAMP_BKPxR register.

---
Cc: Alexandre Torgue <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]

---
 .../bindings/nvmem/nvmem-syscon.yaml          | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +39 -0
new file mode 100644
index 0000000000000..3035a0b2cd24a
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/nvmem-syscon.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic syscon backed nvmem
+
+maintainers:
+  - Marek Vasut <[email protected]>
+
+allOf:
+  - $ref: "nvmem.yaml#"
+
+properties:
+  compatible:
+    enum:
+      - nvmem-syscon
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    tamp@5c00a000 {
+        compatible = "st,stm32-tamp", "syscon", "simple-mfd";
+        reg = <0x5c00a000 0x400>;
+
+        nvmem-syscon {
+            compatible = "nvmem-syscon";
+            reg = <0x14c 0x4>;
+        };
+    };
Signature · 1 line
2.35.1
#2 lore raw

RFC PATCH 3/3 ARM: dts: stm32: Add nvmem-syscon node to TAMP to expose boot count on DHSOM

Add nvmem-syscon subnode to expose TAMP_BKPxR register 19 to user space. This register contains U-Boot boot counter, by exposing it to user space the user space can reset the boot counter.

Read access example:
"

$ hexdump -vC /sys/bus/nvmem/devices/5c00a000.tamp\:nvmem0/nvmem
00000000  0c 00 c4 b0
"

---
Cc: Alexandre Torgue <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]

---
 arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi | 11 +++++++++++
 arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi | 11 +++++++++++
 2 files changed, 22 insertions(+)
arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi +11 -0
index 155843e1402fb..8277837be8a51 100644
@@ -533,6 +533,17 @@ &sdmmc3 {
 	status = "okay";
 };
 
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};
+
 &uart4 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart4_pins_a>;
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +11 -0
index 134a798ad3f23..42a8d5cdd7024 100644
@@ -271,3 +271,14 @@ &rng1 {
 &rtc {
 	status = "okay";
 };
+
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};
Signature · 1 line
2.35.1
#1 lore raw

RFC PATCH 2/3 nvmem: syscon: Add syscon backed nvmem driver

In reply to Marek Vasut

Add trivial driver which permits exposing syscon backed register to userspace. This is useful e.g. to expose U-Boot boot counter on various platforms where the boot counter is stored in random volatile register, like STM32MP15xx TAMP_BKPxR register.

---
Cc: Alexandre Torgue <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]

---
 drivers/nvmem/Kconfig        |  10 ++++
 drivers/nvmem/Makefile       |   2 +
 drivers/nvmem/nvmem-syscon.c | 105 +++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/nvmem/nvmem-syscon.c
drivers/nvmem/Kconfig +10 -0
index ec8a49c040031..cd9a7b00bc1ab 100644
@@ -290,6 +290,16 @@ config NVMEM_SPRD_EFUSE
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-sprd-efuse.
 
+config NVMEM_SYSCON
+	tristate "Generic syscon backed nvmem"
+	help
+	  This is a driver for generic syscon backed nvmem. This can be
+	  used to expose arbitrary syscon backed register to user space
+	  via nvmem, like the U-Boot boot counter.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem-syscon.
+
 config NVMEM_STM32_ROMEM
 	tristate "STMicroelectronics STM32 factory-programmed memory support"
 	depends on ARCH_STM32 || COMPILE_TEST
drivers/nvmem/Makefile +2 -0
index fa80fe17e567e..6e170b30a1d1d 100644
@@ -59,6 +59,8 @@ 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
 nvmem_sprd_efuse-y			:= sprd-efuse.o
+obj-$(CONFIG_NVMEM_SYSCON)		+= nvmem_syscon.o
+nvmem_syscon-y				:= nvmem-syscon.o
 obj-$(CONFIG_NVMEM_STM32_ROMEM)		+= nvmem_stm32_romem.o
 nvmem_stm32_romem-y 			:= stm32-romem.o
 obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP)	+= nvmem_sunplus_ocotp.o
drivers/nvmem/nvmem-syscon.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#3 lore raw
In reply to Marek Vasut
Quoted 14 lines · Marek Vasut

Add trivial bindings for driver which permits exposing syscon backed register to userspace. This is useful e.g. to expose U-Boot boot counter on various platforms where the boot counter is stored in random volatile register, like STM32MP15xx TAMP_BKPxR register.

---
Cc: Alexandre Torgue <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]

Quoted 5 lines
---
 .../bindings/nvmem/nvmem-syscon.yaml          | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dts:24.17-35: Warning (reg_format): /example-0/tamp@5c00a000/nvmem-syscon:reg: property has invalid length (8 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dts:22.26-25.15: Warning (unit_address_vs_reg): /example-0/tamp@5c00a000/nvmem-syscon: node has a reg or ranges property, but no unit name Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (pci_device_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (simple_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dts:22.26-25.15: Warning (avoid_default_addr_size): /example-0/tamp@5c00a000/nvmem-syscon: Relying on default #address-cells value Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dts:22.26-25.15: Warning (avoid_default_addr_size): /example-0/tamp@5c00a000/nvmem-syscon: Relying on default #size-cells value Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: Warning (unique_unit_address_if_enabled): Failed prerequisite 'avoid_default_addr_size' /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/nvmem/nvmem-syscon.example.dtb: tamp@5c00a000: 'nvmem-syscon' does not match any of the regexes: 'pinctrl-[0-9]+'
From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/arm/stm32/st,stm32-syscon.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

maintainer
#4 lore raw
In reply to Marek Vasut
Quoted 4 lines · Marek Vasut

Add trivial bindings for driver which permits exposing syscon backed register to userspace. This is useful e.g. to expose U-Boot boot counter on various platforms where the boot counter is stored in random volatile register, like STM32MP15xx TAMP_BKPxR register.

Generic bindings always start trivial until they get appended one property at a time...

What happens when you have more than 1 field and/or more than 1 register?

Quoted 42 lines

---
Cc: Alexandre Torgue <[email protected]>
Cc: Rafał Miłecki <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
To: [email protected]

---
 .../bindings/nvmem/nvmem-syscon.yaml          | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +22 -0
new file mode 100644
index 0000000000000..3035a0b2cd24a
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/nvmem-syscon.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic syscon backed nvmem
+
+maintainers:
+  - Marek Vasut <[email protected]>
+
+allOf:
+  - $ref: "nvmem.yaml#"
+
+properties:
+  compatible:
+    enum:
+      - nvmem-syscon
+
+  reg:
+    maxItems: 1
+

Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +10 -0
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    tamp@5c00a000 {
+        compatible = "st,stm32-tamp", "syscon", "simple-mfd";

This is very common, but personally I think "syscon" and "simple-mfd" should be mutually exclusive. "simple-mfd" is saying the children have no dependency on the parent, yet the child nodes need a regmap from the parent. Sounds like a dependency.

Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml line 37

Quoted 5 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +5 -0
+        reg = <0x5c00a000 0x400>;
+
+        nvmem-syscon {
+            compatible = "nvmem-syscon";
+            reg = <0x14c 0x4>;

How does one identify this is the bootloader's boot count? How does the bootloader know it can write to this?

Quoted 6 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +2 -0
+        };
+    };
Signature · 1 line
2.35.1
#5 lore raw
Quoted 11 lines · Rob Herring
Quoted 4 lines · Marek Vasut

Add trivial bindings for driver which permits exposing syscon backed register to userspace. This is useful e.g. to expose U-Boot boot counter on various platforms where the boot counter is stored in random volatile register, like STM32MP15xx TAMP_BKPxR register.

Generic bindings always start trivial until they get appended one property at a time...

What happens when you have more than 1 field and/or more than 1 register?

If it is a continuous register array, the user can use the size field to describe such register array here.

If it is a sparse register array, multiple nvmem-syscon nodes would be needed. I haven't seen anything which would require one node for sparse register arrays, like boot counter distributed across multiple non-continuous registers or such.

Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +15 -0
+properties:
+  compatible:
+    enum:
+      - nvmem-syscon
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
Quoted 8 lines

Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml line 32

Quoted 3 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +3 -0
+  - |
+    tamp@5c00a000 {
+        compatible = "st,stm32-tamp", "syscon", "simple-mfd";

This is very common, but personally I think "syscon" and "simple-mfd" should be mutually exclusive. "simple-mfd" is saying the children have no dependency on the parent, yet the child nodes need a regmap from the parent. Sounds like a dependency.

So what exactly should be changed here?

Quoted 7 lines

Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml line 37

Quoted 5 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +5 -0
+        reg = <0x5c00a000 0x400>;
+
+        nvmem-syscon {
+            compatible = "nvmem-syscon";
+            reg = <0x14c 0x4>;

How does one identify this is the bootloader's boot count?

The user has to know where the boot counter is stored (by hardware path). I wouldn't attempt to assign any complex logic here, since the boot counter could be implemented in various ways. Besides, this may not even be a boot counter, but some other variable exposed to user space. Maybe a unique node name can be used to discern the different nvmem-syscon nodes representing different variables if needed.

Quoted 2 lines

How does the
bootloader know it can write to this?

The bootloader implementer selected the bootcounter register based on hardware knowledge .