Skip to contentSkip to conversation

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

PATCH In review Marek Vasut 4 participants 14 messages May 17, 2023 – Jun 1, 2023 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: Use generic syscon supernode

---
 .../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..7c1173a1a6218
@@ -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:
+  - |
+    syscon {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        syscon@14c {
+            compatible = "nvmem-syscon";
+            reg = <0x14c 0x4>;
+        };
+    };
Signature · 1 line
2.39.2
#1 lore raw

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

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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
 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 b291b27048c76..4e4aecdd9c293 100644
@@ -303,6 +303,16 @@ config NVMEM_STM32_BSEC_OPTEE_TA
 	  This library is a used by stm32-romem driver or included in the module
 	  called nvmem-stm32-romem.
 
+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 f82431ec8aef0..d10e478e6a6c9 100644
@@ -60,6 +60,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
 nvmem_stm32_romem-$(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA) += stm32-bsec-optee-ta.o
drivers/nvmem/nvmem-syscon.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 2/3] nvmem: syscon: Add syscon backed nvmem driver

Quoted 121 lines · 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
 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 b291b27048c76..4e4aecdd9c293 100644
@@ -303,6 +303,16 @@ config NVMEM_STM32_BSEC_OPTEE_TA
 	  This library is a used by stm32-romem driver or included in the module
 	  called nvmem-stm32-romem.
 
+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 f82431ec8aef0..d10e478e6a6c9 100644
@@ -60,6 +60,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
 nvmem_stm32_romem-$(CONFIG_NVMEM_STM32_BSEC_OPTEE_TA) += stm32-bsec-optee-ta.o
drivers/nvmem/nvmem-syscon.c new file +54 -0
new file mode 100644
index 0000000000000..e0aa5af0300d3
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Marek Vasut <[email protected]>
+ *
+ * Based on snvs_lpgpr.c .
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+
+struct nvmem_syscon_priv {
+	struct device_d		*dev;
+	struct regmap		*regmap;
+	struct nvmem_config	cfg;
+	unsigned int		off;
+};
+
+static int nvmem_syscon_write(void *context, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	struct nvmem_syscon_priv *priv = context;
+
+	return regmap_bulk_write(priv->regmap, priv->off + offset,
+				 val, bytes / 4);
+}
+
+static int nvmem_syscon_read(void *context, unsigned int offset, void *val,
+			     size_t bytes)
+{
+	struct nvmem_syscon_priv *priv = context;
+
+	return regmap_bulk_read(priv->regmap, priv->off + offset,
+				val, bytes / 4);
+}
+
+static int nvmem_syscon_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct device_node *syscon_node;
+	struct nvmem_syscon_priv *priv;
+	struct nvmem_device *nvmem;
+	struct nvmem_config *cfg;
+	int ret;
+
+	if (!node)
+		return -ENOENT;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

drivers/nvmem/nvmem-syscon.c line 64

Quoted 10 lines
drivers/nvmem/nvmem-syscon.c new file +10 -0
+
+	ret = of_property_read_u32_index(node, "reg", 0, &priv->off);
+	if (ret)
+		return ret;
+
+	ret = of_property_read_u32_index(node, "reg", 1, &priv->cfg.size);
+	if (ret)
+		return ret;
+
+	syscon_node = of_get_parent(node);

This does not look correct. You hard-code dependency that it must be a child of syscon node. This is weird requirement and not explained in the bindings.

Why this cannot be then generic MMIO node? Why it has to be a child of syscon?

drivers/nvmem/nvmem-syscon.c line 71

Quoted 7 lines
drivers/nvmem/nvmem-syscon.c new file +7 -0
+	if (!syscon_node)
+		return -ENODEV;
+
+	priv->regmap = syscon_node_to_regmap(syscon_node);
+	of_node_put(syscon_node);
+	if (IS_ERR(priv->regmap))
+		return PTR_ERR(priv->regmap);

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 2/3] nvmem: syscon: Add syscon backed nvmem driver

On 5/18/23 16:22, Krzysztof Kozlowski wrote:

[...]

Quoted 71 lines
Quoted 56 lines

+++ b/drivers/nvmem/nvmem-syscon.c

drivers/nvmem/nvmem-syscon.c new file +54 -0
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Marek Vasut <[email protected]>
+ *
+ * Based on snvs_lpgpr.c .
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+
+struct nvmem_syscon_priv {
+	struct device_d		*dev;
+	struct regmap		*regmap;
+	struct nvmem_config	cfg;
+	unsigned int		off;
+};
+
+static int nvmem_syscon_write(void *context, unsigned int offset, void *val,
+			      size_t bytes)
+{
+	struct nvmem_syscon_priv *priv = context;
+
+	return regmap_bulk_write(priv->regmap, priv->off + offset,
+				 val, bytes / 4);
+}
+
+static int nvmem_syscon_read(void *context, unsigned int offset, void *val,
+			     size_t bytes)
+{
+	struct nvmem_syscon_priv *priv = context;
+
+	return regmap_bulk_read(priv->regmap, priv->off + offset,
+				val, bytes / 4);
+}
+
+static int nvmem_syscon_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct device_node *syscon_node;
+	struct nvmem_syscon_priv *priv;
+	struct nvmem_device *nvmem;
+	struct nvmem_config *cfg;
+	int ret;
+
+	if (!node)
+		return -ENOENT;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;

drivers/nvmem/nvmem-syscon.c line 64

Quoted 10 lines
drivers/nvmem/nvmem-syscon.c new file +10 -0
+
+	ret = of_property_read_u32_index(node, "reg", 0, &priv->off);
+	if (ret)
+		return ret;
+
+	ret = of_property_read_u32_index(node, "reg", 1, &priv->cfg.size);
+	if (ret)
+		return ret;
+
+	syscon_node = of_get_parent(node);

This does not look correct. You hard-code dependency that it must be a child of syscon node. This is weird requirement and not explained in the bindings.

Quoted 2 lines

Why this cannot be then generic MMIO node? Why it has to be a child of syscon?

Because I already have a syscon node and I want to expose only a subset of it to userspace (bootcounter in my case) . See 1/3, I replied there, let's continue the discussion there.

I fixed the rest in prep for V3, sorry for the horrid delays in replies.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#4 lore raw

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

In reply to Marek Vasut

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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
 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 74735552f4803..b2557bb718f52 100644
@@ -537,6 +537,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 bba19f21e5277..864960387e634 100644
@@ -269,3 +269,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.39.2
maintainer
#5 lore raw

Re: [PATCH v2 3/3] ARM: dts: stm32: Add nvmem-syscon node to TAMP to expose boot count on DHSOM

Quoted 35 lines · Marek Vasut

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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
  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 +0 -0
index 74735552f4803..b2557bb718f52 100644

arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi &sdmmc3 { · line 545

Quoted 9 lines
arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi +6 -0
@@ -537,6 +537,17 @@ &sdmmc3 {
  	status = "okay";
  };
 
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {

nvmem@14c ?

Quoted 13 lines
arch/arm/boot/dts/stm32mp15xx-dhcom-som.dtsi +5 -0
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};
+
  &uart4 {
  	pinctrl-names = "default";
  	pinctrl-0 = <&uart4_pins_a>;
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +0 -0
index bba19f21e5277..864960387e634 100644

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 278

Quoted 10 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +7 -0
@@ -269,3 +269,14 @@ &rng1 {
  &rtc {
  	status = "okay";
  };
+
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {

nvmem@14c ?

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 282

Quoted 4 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +4 -0
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

RE: [PATCH v2 3/3] ARM: dts: stm32: Add nvmem-syscon node to TAMP to expose boot count on DHSOM

In reply to Marek Vasut

Hi Marek,

Quoted 64 lines

From: Marek Vasut <[email protected]>
Sent: Wednesday, May 17, 2023 5:25 PM
Subject: [PATCH v2 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
 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 74735552f4803..b2557bb718f52 100644
@@ -537,6 +537,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 +0 -0
index bba19f21e5277..864960387e634 100644

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 278

Quoted 10 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +7 -0
@@ -269,3 +269,14 @@ &rng1 {
 &rtc {
 	status = "okay";
 };
+
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {

According binding you need to add "@<reg>" => nvmem@14c

And you export only TAMP_BKP19R directly in a nvmem region ?

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 282

Quoted 4 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +4 -0
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};

the boot counter could be a nvem cell so you could expose other backup registers

For example :

&tamp {
	#address-cells = <1>;
	#size-cells = <1>;

	nvmem@14c  {
		compatible = "nvmem-syscon";
		reg = <0x14c 0x4>;

		/* Data cells */
		boot_counter: boot-counter@14c {
			reg = <0x14c 0x4>;
		};
	};
};

Even if you export more backup register the cell will be correctly described in DT and could be accessible directly with sysfs without managed offset in userland

with https://lore.kernel.org/lkml/[email protected]/T/
Or previous serie https://lore.kernel.org/lkml/[email protected]/

for example to export all the free register:

Reference: https://wiki.st.com/stm32mpu/wiki/STM32MP15_backup_registers

the cell " boot-counter" will be always available for users.

&tamp {
	#address-cells = <1>;
	#size-cells = <1>;

	/* backup register: 10 to 21 */
	nvmem@0x128  {
		compatible = "nvmem-syscon";
		reg = <0x128 0x44>;

		/* Data cells */
		boot_counter: boot-counter@14c {
			reg = <0x14c 0x4>;
		};
		boot_mode: boot-mode@150 {
			reg = <0x150 0x4>;
		};
....
	};
};

Patrick

Quoted 2 lines

--
2.39.2

ST Restricted

#7 lore raw

Re: [PATCH v2 3/3] ARM: dts: stm32: Add nvmem-syscon node to TAMP to expose boot count on DHSOM

Quoted 1 line · On 5/26/23 17:28, [email protected] wrote:

Hi Marek,

Hi,

Quoted 77 lines
Quoted 64 lines

From: Marek Vasut <[email protected]>
Sent: Wednesday, May 17, 2023 5:25 PM
Subject: [PATCH v2 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change

---
  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 74735552f4803..b2557bb718f52 100644
@@ -537,6 +537,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 +0 -0
index bba19f21e5277..864960387e634 100644

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 278

Quoted 10 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +7 -0
@@ -269,3 +269,14 @@ &rng1 {
  &rtc {
  	status = "okay";
  };
+
+&tamp {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	/* Boot counter */
+	nvmem {

According binding you need to add "@<reg>" => nvmem@14c

Quoted 1 line

And you export only TAMP_BKP19R directly in a nvmem region ?

4 bytes is more than plenty for boot counter , yes.

Quoted 49 lines

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 282

Quoted 4 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +4 -0
+		compatible = "nvmem-syscon";
+		reg = <0x14c 0x4>;
+	};
+};

the boot counter could be a nvem cell so you could expose other backup registers

For example :

&tamp {
	#address-cells = <1>;
	#size-cells = <1>;

	nvmem@14c  {
		compatible = "nvmem-syscon";
		reg = <0x14c 0x4>;

		/* Data cells */
		boot_counter: boot-counter@14c {
			reg = <0x14c 0x4>;
		};
	};
};

Even if you export more backup register the cell will be correctly described in DT and could be accessible directly with sysfs without managed offset in userland

with https://lore.kernel.org/lkml/[email protected]/T/
Or previous serie https://lore.kernel.org/lkml/[email protected]/

for example to export all the free register:

Reference: https://wiki.st.com/stm32mpu/wiki/STM32MP15_backup_registers

the cell " boot-counter" will be always available for users.

&tamp {
	#address-cells = <1>;
	#size-cells = <1>;

	/* backup register: 10 to 21 */
	nvmem@0x128  {
		compatible = "nvmem-syscon";
		reg = <0x128 0x44>;

		/* Data cells */
		boot_counter: boot-counter@14c {
Quoted 8 lines
			reg = <0x14c 0x4>;
		};
		boot_mode: boot-mode@150 {
			reg = <0x150 0x4>;
		};
....
	};
};

Sure, thanks. I'm not sure I understood the message above.

#8 lore raw

Re: [PATCH v2 3/3] ARM: dts: stm32: Add nvmem-syscon node to TAMP to expose boot count on DHSOM

Hi,

Quoted 144 lines · Marek Vasut
Quoted 1 line · On 5/26/23 17:28, [email protected] wrote:

Hi Marek,

Hi,

Quoted 77 lines
Quoted 64 lines

From: Marek Vasut <[email protected]>
Sent: Wednesday, May 17, 2023 5:25 PM
Subject: [PATCH v2 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: No change
---
  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 74735552f4803..b2557bb718f52 100644
@@ -537,6 +537,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 +0 -0
index bba19f21e5277..864960387e634 100644

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 278

Quoted 10 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +7 -0
@@ -269,3 +269,14 @@ &rng1 {
   &rtc {
       status = "okay";
   };
+
+&tamp {
+    #address-cells = <1>;
+    #size-cells = <1>;
+
+    /* Boot counter */
+    nvmem {

According binding you need to add "@<reg>" => nvmem@14c

Quoted 1 line

And you export only TAMP_BKP19R directly in a nvmem region ?

4 bytes is more than plenty for boot counter , yes.

Quoted 47 lines

arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi &rng1 { · line 282

Quoted 4 lines
arch/arm/boot/dts/stm32mp15xx-dhcor-som.dtsi +4 -0
+        compatible = "nvmem-syscon";
+        reg = <0x14c 0x4>;
+    };
+};

the boot counter could be a nvem cell so you could expose  other backup registers

For example :

&tamp {
    #address-cells = <1>;
    #size-cells = <1>;

    nvmem@14c  {
        compatible = "nvmem-syscon";
        reg = <0x14c 0x4>;

        /* Data cells */
        boot_counter: boot-counter@14c {
            reg = <0x14c 0x4>;
        };
    };
};

Even if you export more backup register the cell will be correctly described in DT and could be accessible directly  with sysfs without managed offset in userland

with https://lore.kernel.org/lkml/[email protected]/T/
Or previous serie https://lore.kernel.org/lkml/[email protected]/

for example to export all the free register:

Reference: https://wiki.st.com/stm32mpu/wiki/STM32MP15_backup_registers

the cell " boot-counter" will be always available for users.

&tamp {
    #address-cells = <1>;
    #size-cells = <1>;

    /* backup register: 10 to 21 */
    nvmem@0x128  {
        compatible = "nvmem-syscon";
        reg = <0x128 0x44>;

Quoted 10 lines

        /* Data cells */
        boot_counter: boot-counter@14c {
            reg = <0x14c 0x4>;
        };
        boot_mode: boot-mode@150 {
            reg = <0x150 0x4>;
        };
....
    };
};

Quoted 1 line

Sure, thanks. I'm not sure I understood the message above.

sorry if it wasn't clear

TAMP register a nvmem driver = NVRAM provider

=> it should export ALL the free backup registers

      as they can used by application / kernel for many purpose....

      and not only for boot counterfor you use-case

So limit the exported backup register to this 4 bytes is strange for me.

and COUNTER is a nvem cell =  a part of backup register = TAMP_BKP19R

=> I agree 4 byte for this count is fine for this cell

NB: today we have no means to read only one nvmem cell with sysfs API

       but I see this feature is proposed to have something as

/sys/bus/nvmem/devices/nvmem@0x128/ => all the backup registers

/sys/bus/nvmem/devices/nvmem@0x128/cells/boot-mode => only the nvmem cell used as counter I think it is more safe for long term support to manage your counter as a nvmem cell. regards Patrick

#9 lore raw
In reply to Marek Vasut
Quoted 34 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: Use generic syscon supernode

---
 .../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 +3 -0
new file mode 100644
index 0000000000000..7c1173a1a6218
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

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

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +10 -0
+$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#"

Usual comment: drop quotes. We removed them everywhere, so you based your work on some old tree.

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

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

Rob's questions are not solved. The nvmem.yaml schema expects here to allow children. This should not be created per-register, but per entire block of registers.

OTOH, using nvmem for syscon (which are MMIO and writeable registers usually) seems odd.

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

Quoted 1 line
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +1 -0
+

missing nvmem cells

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

Quoted 5 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +5 -0
+required:
+  - compatible
+  - reg
+
+additionalProperties: false

unevaluatedProps: false

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

Quoted 8 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +8 -0
+
+examples:
+  - |
+    syscon {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        syscon@14c {

It's not really a syscon, but efuse, otp or nvmem.

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

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

Missing nvmem cells

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

Quoted 2 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +2 -0
+        };
+    };

Best regards,
Krzysztof

#10 lore raw
Quoted 49 lines · Krzysztof Kozlowski
Quoted 34 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: Use generic syscon supernode

---
  .../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 +3 -0
new file mode 100644
index 0000000000000..7c1173a1a6218
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

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

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +10 -0
+$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#"

Usual comment: drop quotes. We removed them everywhere, so you based your work on some old tree.

Quoted 10 lines

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

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

Rob's questions are not solved.

Can you reiterate this one ? I likely missed it.

Quoted 3 lines

The nvmem.yaml schema expects here to
allow children. This should not be created per-register, but per entire block of registers.

This thing works the other way around, I have a syscon register block already, and I want to expose subset of it to userspace as read/write accessible file to expose bootcounter available in that register (so I can read it and reset it from user application).

Quoted 6 lines

OTOH, using nvmem for syscon (which are MMIO and writeable registers usually) seems odd.

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

Quoted 1 line
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +1 -0
+

missing nvmem cells

See above, I don't think nvmem-cells applies here.

[...]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 65 lines · Marek Vasut
Quoted 64 lines · Krzysztof Kozlowski
Quoted 62 lines · Marek Vasut
Quoted 49 lines · Krzysztof Kozlowski
Quoted 34 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: Conor Dooley <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
V2: Use generic syscon supernode

---
   .../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 +3 -0
new file mode 100644
index 0000000000000..7c1173a1a6218
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

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

Quoted 10 lines
Documentation/devicetree/bindings/nvmem/nvmem-syscon.yaml new file +10 -0
+$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#"

Usual comment: drop quotes. We removed them everywhere, so you based your work on some old tree.

Quoted 10 lines

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

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

Rob's questions are not solved.

Can you reiterate this one ? I likely missed it.

Quoted 8 lines
Quoted 2 lines

You did not solve the case of more than one register. This isn't an odd case.

So why not just extend the bindings to support

reg = <0x14c 0x4>, <0x180 0x10>, ... ;

this kind of stuff ?

Does not look right. Look at nvmem bindings and don't do it differently.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

The nvmem.yaml schema expects here to
allow children. This should not be created per-register, but per entire block of registers.

This thing works the other way around, I have a syscon register block already, and I want to expose subset of it to userspace as read/write accessible file to expose bootcounter available in that register (so I can read it and reset it from user application).

Quoted 4 lines
Quoted 2 lines

And this makes it too limited. I would expect one device exposing multiple blocks or registers, just like all nvmem providers are doing.

What would be the real-world use case of that ?

The same as the real world use cases for nvmem. One syscon block has multiple registers so I can easily imagine wanting boottrap, bootstat, boot-whatever you want.

Best regards,
Krzysztof

#14 lore raw
In reply to Marek Vasut
Quoted 7 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.

---

Let me also leave a note here - cross linking for all parties:

Please propose a solution solving also mediatek,boottrap, probably extendable to range of registers. Other solution is what Rob mentioned - this might not be suitable for generic binding and device.

Best regards,
Krzysztof

#15 lore raw
Quoted 6 lines · Krzysztof Kozlowski
Quoted 5 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.

Quoted 8 lines
Quoted 2 lines

---

Let me also leave a note here - cross linking for all parties:

Please propose a solution solving also mediatek,boottrap, probably extendable to range of registers. Other solution is what Rob mentioned - this might not be suitable for generic binding and device.

From what I can tell, shouldn't the mediatek 1g MAC driver have a nvmem-cells phandle to this OTP/fuses/whatever area and shouldn't the driver read out and decode its settings within the kernel ?

That doesn't seem really related to this particular issue I'm trying to solve I'm afraid.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel