All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] nvmem: allow specifying cells by just names in DT
@ 2022-01-24 16:02 ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This is a simplified & cleaned up version of my:
[PATCH 0/5] nvmem: support more NVMEM cells variants

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml |  7 +++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 32 insertions(+), 5 deletions(-)

-- 
2.31.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 0/3] nvmem: allow specifying cells by just names in DT
@ 2022-01-24 16:02 ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This is a simplified & cleaned up version of my:
[PATCH 0/5] nvmem: support more NVMEM cells variants

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml |  7 +++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 32 insertions(+), 5 deletions(-)

-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 1/3] dt-bindings: nvmem: make "reg" property optional
  2022-01-24 16:02 ` Rafał Miłecki
@ 2022-01-24 16:02   ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 1/3] dt-bindings: nvmem: make "reg" property optional
@ 2022-01-24 16:02   ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  2022-01-24 16:02 ` Rafał Miłecki
@ 2022-01-24 16:02   ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format) . It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

One of cells set in almost every device is "et0macaddr" containing MAC
address. Add it to example to show how it can be referenced.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..ab14e3ae45c8 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -32,6 +32,9 @@ unevaluatedProperties: false
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 2/3] dt-bindings: nvmem: brcm, nvram: add NVMEM cell to example
@ 2022-01-24 16:02   ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:02 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format) . It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

One of cells set in almost every device is "et0macaddr" containing MAC
address. Add it to example to show how it can be referenced.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..ab14e3ae45c8 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -32,6 +32,9 @@ unevaluatedProperties: false
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 3/3] nvmem: core: add cell name based matching of DT cell nodes
  2022-01-24 16:02 ` Rafał Miłecki
@ 2022-01-24 16:03   ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:03 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 23a38dcf0fc4..9a1299a7f46a 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH 3/3] nvmem: core: add cell name based matching of DT cell nodes
@ 2022-01-24 16:03   ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-01-24 16:03 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Florian Fainelli, Hauke Mehrtens, bcm-kernel-feedback-list,
	devicetree, linux-arm-kernel, linux-kernel,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 23a38dcf0fc4..9a1299a7f46a 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH 1/3] dt-bindings: nvmem: make "reg" property optional
  2022-01-24 16:02   ` Rafał Miłecki
@ 2022-02-11 12:38     ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-11 12:38 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: linux-kernel, bcm-kernel-feedback-list, Srinivas Kandagatla,
	Hauke Mehrtens, Florian Fainelli, Rafał Miłecki,
	linux-arm-kernel, devicetree, Rob Herring

On Mon, 24 Jan 2022 17:02:58 +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> Most NVMEM providers have cells at hardcoded addresses however there are
> some exceptions. Some devices store cells layout in internal structs
> using custom formats.
> 
> It's important to allow NVMEM consumers to still reference such NVMEM
> cells. Making "reg" optional allows defining NVMEM cells by their names
> only and using them with phandles.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
>  1 file changed, 3 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 1/3] dt-bindings: nvmem: make "reg" property optional
@ 2022-02-11 12:38     ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-11 12:38 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: linux-kernel, bcm-kernel-feedback-list, Srinivas Kandagatla,
	Hauke Mehrtens, Florian Fainelli, Rafał Miłecki,
	linux-arm-kernel, devicetree, Rob Herring

On Mon, 24 Jan 2022 17:02:58 +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> Most NVMEM providers have cells at hardcoded addresses however there are
> some exceptions. Some devices store cells layout in internal structs
> using custom formats.
> 
> It's important to allow NVMEM consumers to still reference such NVMEM
> cells. Making "reg" optional allows defining NVMEM cells by their names
> only and using them with phandles.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
>  1 file changed, 3 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  2022-01-24 16:02   ` [PATCH 2/3] dt-bindings: nvmem: brcm, nvram: " Rafał Miłecki
@ 2022-02-11 12:45     ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-11 12:45 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Srinivas Kandagatla, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

On Mon, Jan 24, 2022 at 05:02:59PM +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format) . It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> One of cells set in almost every device is "et0macaddr" containing MAC
> address. Add it to example to show how it can be referenced.

"et0macaddr" is defined in the internal struct? Can you make this 
explicit in the the schema that's where the child node names come from. 
Perhaps go as far as documenting what some of the names are if they are 
common and not documented elsewhere.

> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..ab14e3ae45c8 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -32,6 +32,9 @@ unevaluatedProperties: false
>  examples:
>    - |
>      nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>      };
> -- 
> 2.31.1
> 
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
@ 2022-02-11 12:45     ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-11 12:45 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Srinivas Kandagatla, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

On Mon, Jan 24, 2022 at 05:02:59PM +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format) . It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> One of cells set in almost every device is "et0macaddr" containing MAC
> address. Add it to example to show how it can be referenced.

"et0macaddr" is defined in the internal struct? Can you make this 
explicit in the the schema that's where the child node names come from. 
Perhaps go as far as documenting what some of the names are if they are 
common and not documented elsewhere.

> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..ab14e3ae45c8 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -32,6 +32,9 @@ unevaluatedProperties: false
>  examples:
>    - |
>      nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>      };
> -- 
> 2.31.1
> 
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH V2 0/3] nvmem: allow specifying cells by just names in DT
  2022-01-24 16:02 ` Rafał Miłecki
@ 2022-02-11 13:05   ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This is V2 of my:
[PATCH 0/3] nvmem: allow specifying cells by just names in DT

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 16 +++++++++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 41 insertions(+), 5 deletions(-)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 0/3] nvmem: allow specifying cells by just names in DT
@ 2022-02-11 13:05   ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This is V2 of my:
[PATCH 0/3] nvmem: allow specifying cells by just names in DT

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 16 +++++++++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 41 insertions(+), 5 deletions(-)

-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 1/3] dt-bindings: nvmem: make "reg" property optional
  2022-02-11 13:05   ` Rafał Miłecki
@ 2022-02-11 13:05     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 1/3] dt-bindings: nvmem: make "reg" property optional
@ 2022-02-11 13:05     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
  2022-02-11 13:05   ` Rafał Miłecki
@ 2022-02-11 13:05     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format) . It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

One of cells set in almost every device is "et0macaddr" containing MAC
address. Add it to example to show how it can be referenced.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Add children nodes description per Rob's request
---
 .../devicetree/bindings/nvmem/brcm,nvram.yaml    | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..fc1df9d1c4d4 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -27,11 +27,23 @@ properties:
   reg:
     maxItems: 1
 
+patternProperties:
+  ".*":
+    description: |
+      Each child node represents one NVRAM entry (variable). Node name has to
+      match variable name as internally defined in the NVRAM.
+
+      Some of common NVRAM variables are: "board_id", "boardflags", "boot_wait",
+      "clkfreq", "et0macaddr", "sdram_config", "wait_time".
+
 unevaluatedProperties: false
 
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 2/3] dt-bindings: nvmem: brcm, nvram: add NVMEM cell to example
@ 2022-02-11 13:05     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format) . It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

One of cells set in almost every device is "et0macaddr" containing MAC
address. Add it to example to show how it can be referenced.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Add children nodes description per Rob's request
---
 .../devicetree/bindings/nvmem/brcm,nvram.yaml    | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..fc1df9d1c4d4 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -27,11 +27,23 @@ properties:
   reg:
     maxItems: 1
 
+patternProperties:
+  ".*":
+    description: |
+      Each child node represents one NVRAM entry (variable). Node name has to
+      match variable name as internally defined in the NVRAM.
+
+      Some of common NVRAM variables are: "board_id", "boardflags", "boot_wait",
+      "clkfreq", "et0macaddr", "sdram_config", "wait_time".
+
 unevaluatedProperties: false
 
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 3/3] nvmem: core: add cell name based matching of DT cell nodes
  2022-02-11 13:05   ` Rafał Miłecki
@ 2022-02-11 13:05     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 53a43d843743..a891449c52f1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V2 3/3] nvmem: core: add cell name based matching of DT cell nodes
@ 2022-02-11 13:05     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-11 13:05 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 53a43d843743..a891449c52f1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH V2 2/3] dt-bindings: nvmem: brcm, nvram: add NVMEM cell to example
  2022-02-11 13:05     ` [PATCH V2 2/3] dt-bindings: nvmem: brcm, nvram: " Rafał Miłecki
@ 2022-02-17 23:58       ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-17 23:58 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Srinivas Kandagatla, Krzysztof Kozlowski, Florian Fainelli,
	Hauke Mehrtens, bcm-kernel-feedback-list, devicetree,
	linux-arm-kernel, linux-kernel, Rafał Miłecki

On Fri, Feb 11, 2022 at 02:05:53PM +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format) . It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> One of cells set in almost every device is "et0macaddr" containing MAC
> address. Add it to example to show how it can be referenced.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: Add children nodes description per Rob's request
> ---
>  .../devicetree/bindings/nvmem/brcm,nvram.yaml    | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..fc1df9d1c4d4 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -27,11 +27,23 @@ properties:
>    reg:
>      maxItems: 1
>  
> +patternProperties:
> +  ".*":

This doesn't really work as a schema as it matches every property or 
child node.

> +    description: |
> +      Each child node represents one NVRAM entry (variable). Node name has to
> +      match variable name as internally defined in the NVRAM.
> +
> +      Some of common NVRAM variables are: "board_id", "boardflags", "boot_wait",
> +      "clkfreq", "et0macaddr", "sdram_config", "wait_time".

I meant documenting these as schema, not just in a description:

properties:
  board_id:
    type: object
    description: ...

  board_flags:
    type: object
    description: ...

I'm guessing making this list exhaustive is not possible?

> +
>  unevaluatedProperties: false

     type: object

To say anything else must be a child node.

>  
>  examples:
>    - |
>      nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>      };
> -- 
> 2.34.1
> 
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V2 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example
@ 2022-02-17 23:58       ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-17 23:58 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Srinivas Kandagatla, Krzysztof Kozlowski, Florian Fainelli,
	Hauke Mehrtens, bcm-kernel-feedback-list, devicetree,
	linux-arm-kernel, linux-kernel, Rafał Miłecki

On Fri, Feb 11, 2022 at 02:05:53PM +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format) . It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> One of cells set in almost every device is "et0macaddr" containing MAC
> address. Add it to example to show how it can be referenced.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: Add children nodes description per Rob's request
> ---
>  .../devicetree/bindings/nvmem/brcm,nvram.yaml    | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..fc1df9d1c4d4 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -27,11 +27,23 @@ properties:
>    reg:
>      maxItems: 1
>  
> +patternProperties:
> +  ".*":

This doesn't really work as a schema as it matches every property or 
child node.

> +    description: |
> +      Each child node represents one NVRAM entry (variable). Node name has to
> +      match variable name as internally defined in the NVRAM.
> +
> +      Some of common NVRAM variables are: "board_id", "boardflags", "boot_wait",
> +      "clkfreq", "et0macaddr", "sdram_config", "wait_time".

I meant documenting these as schema, not just in a description:

properties:
  board_id:
    type: object
    description: ...

  board_flags:
    type: object
    description: ...

I'm guessing making this list exhaustive is not possible?

> +
>  unevaluatedProperties: false

     type: object

To say anything else must be a child node.

>  
>  examples:
>    - |
>      nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>      };
> -- 
> 2.34.1
> 
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH V3 0/3] nvmem: allow specifying cells by just names in DT
  2022-01-24 16:02 ` Rafał Miłecki
@ 2022-02-18  7:07   ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 50 insertions(+), 5 deletions(-)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 0/3] nvmem: allow specifying cells by just names in DT
@ 2022-02-18  7:07   ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

These changes will allow me to improve BCM5301X support with:

diff --git a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
index 24ae3c8a3..9efcb2424 100644
--- a/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
+++ b/arch/arm/boot/dts/bcm47094-luxul-xwr-3150-v1.dts
@@ -25,6 +25,9 @@ memory@0 {
 	nvram@1eff0000 {
 		compatible = "brcm,nvram";
 		reg = <0x1eff0000 0x10000>;
+
+		et0macaddr: et0macaddr {
+		};
 	};
 
 	leds {
@@ -72,6 +75,11 @@ restart {
 	};
 };
 
+&gmac0 {
+	nvmem-cells = <&et0macaddr>;
+	nvmem-cell-names = "mac-address";
+};
+
 &usb3 {
 	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
 };

Rafał Miłecki (3):
  dt-bindings: nvmem: make "reg" property optional
  dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
  nvmem: core: add cell name based matching of DT cell nodes

 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++--
 .../devicetree/bindings/nvmem/nvmem.yaml      |  3 ---
 drivers/nvmem/core.c                          | 27 +++++++++++++++++++
 3 files changed, 50 insertions(+), 5 deletions(-)

-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 1/3] dt-bindings: nvmem: make "reg" property optional
  2022-02-18  7:07   ` Rafał Miłecki
@ 2022-02-18  7:07     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 1/3] dt-bindings: nvmem: make "reg" property optional
@ 2022-02-18  7:07     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring

From: Rafał Miłecki <rafal@milecki.pl>

Most NVMEM providers have cells at hardcoded addresses however there are
some exceptions. Some devices store cells layout in internal structs
using custom formats.

It's important to allow NVMEM consumers to still reference such NVMEM
cells. Making "reg" optional allows defining NVMEM cells by their names
only and using them with phandles.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
index 43ed7e32e5ac..3bb349c634cb 100644
--- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
+++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
@@ -60,9 +60,6 @@ patternProperties:
             description:
               Size in bit within the address range specified by reg.
 
-    required:
-      - reg
-
 additionalProperties: true
 
 examples:
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
  2022-02-18  7:07   ` Rafał Miłecki
@ 2022-02-18  7:07     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format). It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

Update binding to allow including basic cells as NVMEM device subnodes.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Add children nodes description per Rob's request
V3: Document NVMEM cells as properties
---
 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..25033de3ef6b 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -14,6 +14,8 @@ description: |
   NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
   devices usiong I/O mapped memory.
 
+  NVRAM variables can be defined as NVMEM device subnodes.
+
 maintainers:
   - Rafał Miłecki <rafal@milecki.pl>
 
@@ -27,11 +29,30 @@ properties:
   reg:
     maxItems: 1
 
+  board_id:
+    type: object
+    description: Board identification name
+
+  et0macaddr:
+    type: object
+    description: First Ethernet interface's MAC address
+
+  et1macaddr:
+    type: object
+    description: Second Ethernet interface's MAC address
+
+  et2macaddr:
+    type: object
+    description: Third Ethernet interface's MAC address
+
 unevaluatedProperties: false
 
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
@ 2022-02-18  7:07     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

NVRAM doesn't have cells at hardcoded addresses. They are stored in
internal struct (custom & dynamic format). It's still important to
define relevant cells in DT so NVMEM consumers can reference them.

Update binding to allow including basic cells as NVMEM device subnodes.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Add children nodes description per Rob's request
V3: Document NVMEM cells as properties
---
 .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
index 8c3f0cd22821..25033de3ef6b 100644
--- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
+++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
@@ -14,6 +14,8 @@ description: |
   NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
   devices usiong I/O mapped memory.
 
+  NVRAM variables can be defined as NVMEM device subnodes.
+
 maintainers:
   - Rafał Miłecki <rafal@milecki.pl>
 
@@ -27,11 +29,30 @@ properties:
   reg:
     maxItems: 1
 
+  board_id:
+    type: object
+    description: Board identification name
+
+  et0macaddr:
+    type: object
+    description: First Ethernet interface's MAC address
+
+  et1macaddr:
+    type: object
+    description: Second Ethernet interface's MAC address
+
+  et2macaddr:
+    type: object
+    description: Third Ethernet interface's MAC address
+
 unevaluatedProperties: false
 
 examples:
   - |
     nvram@1eff0000 {
-            compatible = "brcm,nvram";
-            reg = <0x1eff0000 0x10000>;
+        compatible = "brcm,nvram";
+        reg = <0x1eff0000 0x10000>;
+
+        mac: et0macaddr {
+        };
     };
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 3/3] nvmem: core: add cell name based matching of DT cell nodes
  2022-02-18  7:07   ` Rafał Miłecki
@ 2022-02-18  7:07     ` Rafał Miłecki
  -1 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 53a43d843743..a891449c52f1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH V3 3/3] nvmem: core: add cell name based matching of DT cell nodes
@ 2022-02-18  7:07     ` Rafał Miłecki
  0 siblings, 0 replies; 38+ messages in thread
From: Rafał Miłecki @ 2022-02-18  7:07 UTC (permalink / raw)
  To: Srinivas Kandagatla, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

When adding NVMEM cells defined by driver it's important to match them
with DT nodes that specify matching names. That way other bindings &
drivers can reference such "dynamic" NVMEM cells.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 53a43d843743..a891449c52f1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
+ *
+ * @nvmem: nvmem provider
+ * @name: nvmem cell name
+ *
+ * Runtime created nvmem cells (those not coming from DT) may still need to be
+ * referenced in DT. This function allows finding DT node referencing nvmem cell
+ * by its name. Such a DT node can be then used by nvmem consumers.
+ *
+ * Return: NULL or pointer to DT node
+ */
+static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
+						   const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(nvmem->dev.of_node, child) {
+		if (!strcmp(child->name, name))
+			return child;
+	}
+
+	return NULL;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 			goto err;
 		}
 
+		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);
+
 		nvmem_cell_entry_add(cells[i]);
 	}
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
  2022-02-18  7:07     ` Rafał Miłecki
@ 2022-02-24 19:55       ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-24 19:55 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Krzysztof Kozlowski, Hauke Mehrtens, Florian Fainelli,
	devicetree, bcm-kernel-feedback-list, linux-kernel, Rob Herring,
	Rafał Miłecki, linux-arm-kernel, Srinivas Kandagatla

On Fri, 18 Feb 2022 08:07:28 +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format). It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> Update binding to allow including basic cells as NVMEM device subnodes.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: Add children nodes description per Rob's request
> V3: Document NVMEM cells as properties
> ---
>  .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
@ 2022-02-24 19:55       ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2022-02-24 19:55 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Krzysztof Kozlowski, Hauke Mehrtens, Florian Fainelli,
	devicetree, bcm-kernel-feedback-list, linux-kernel, Rob Herring,
	Rafał Miłecki, linux-arm-kernel, Srinivas Kandagatla

On Fri, 18 Feb 2022 08:07:28 +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format). It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> Update binding to allow including basic cells as NVMEM device subnodes.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: Add children nodes description per Rob's request
> V3: Document NVMEM cells as properties
> ---
>  .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 3/3] nvmem: core: add cell name based matching of DT cell nodes
  2022-02-18  7:07     ` Rafał Miłecki
@ 2022-02-25 12:10       ` Srinivas Kandagatla
  -1 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 12:10 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

Hi Rafał

On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> When adding NVMEM cells defined by driver it's important to match them
> with DT nodes that specify matching names. That way other bindings &
> drivers can reference such "dynamic" NVMEM cells.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>   drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
>   1 file changed, 27 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 53a43d843743..a891449c52f1 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
>   	return 0;
>   }
>   
> +/**
> + * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
> + *
> + * @nvmem: nvmem provider
> + * @name: nvmem cell name
> + *
> + * Runtime created nvmem cells (those not coming from DT) may still need to be
> + * referenced in DT. This function allows finding DT node referencing nvmem cell
> + * by its name. Such a DT node can be then used by nvmem consumers.
> + *
> + * Return: NULL or pointer to DT node
> + */
> +static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
> +						   const char *name)
> +{
> +	struct device_node *child;
> +
> +	for_each_child_of_node(nvmem->dev.of_node, child) {
> +		if (!strcmp(child->name, name))
> +			return child;
> +	}

Isn't this just

	return of_get_child_by_name(nvmem->dev.of_node, name);


> +
> +	return NULL;
> +}
> +
>   /**
>    * nvmem_add_cells() - Add cell information to an nvmem device
>    *
> @@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
>   			goto err;
>   		}
>   
> +		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);


This is really assuming that node name will be same as name passed in 
nvmem_cell_info which might not be always true.

This seems be very specific with brcm and this code does not belong in 
nvmem core.

How about adding device_node to struct nvmem_cell_info and update this 
of_node as part of brcm_nvram_parse()?


--srini


> +
>   		nvmem_cell_entry_add(cells[i]);
>   	}
>   

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 3/3] nvmem: core: add cell name based matching of DT cell nodes
@ 2022-02-25 12:10       ` Srinivas Kandagatla
  0 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 12:10 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki

Hi Rafał

On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> When adding NVMEM cells defined by driver it's important to match them
> with DT nodes that specify matching names. That way other bindings &
> drivers can reference such "dynamic" NVMEM cells.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>   drivers/nvmem/core.c | 27 +++++++++++++++++++++++++++
>   1 file changed, 27 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 53a43d843743..a891449c52f1 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -499,6 +499,31 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
>   	return 0;
>   }
>   
> +/**
> + * nvmem_find_cell_of_node() - Find DT node matching nvmem cell
> + *
> + * @nvmem: nvmem provider
> + * @name: nvmem cell name
> + *
> + * Runtime created nvmem cells (those not coming from DT) may still need to be
> + * referenced in DT. This function allows finding DT node referencing nvmem cell
> + * by its name. Such a DT node can be then used by nvmem consumers.
> + *
> + * Return: NULL or pointer to DT node
> + */
> +static struct device_node *nvmem_find_cell_of_node(struct nvmem_device *nvmem,
> +						   const char *name)
> +{
> +	struct device_node *child;
> +
> +	for_each_child_of_node(nvmem->dev.of_node, child) {
> +		if (!strcmp(child->name, name))
> +			return child;
> +	}

Isn't this just

	return of_get_child_by_name(nvmem->dev.of_node, name);


> +
> +	return NULL;
> +}
> +
>   /**
>    * nvmem_add_cells() - Add cell information to an nvmem device
>    *
> @@ -532,6 +557,8 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
>   			goto err;
>   		}
>   
> +		cells[i]->np = nvmem_find_cell_of_node(nvmem, cells[i]->name);


This is really assuming that node name will be same as name passed in 
nvmem_cell_info which might not be always true.

This seems be very specific with brcm and this code does not belong in 
nvmem core.

How about adding device_node to struct nvmem_cell_info and update this 
of_node as part of brcm_nvram_parse()?


--srini


> +
>   		nvmem_cell_entry_add(cells[i]);
>   	}
>   

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 1/3] dt-bindings: nvmem: make "reg" property optional
  2022-02-18  7:07     ` Rafał Miłecki
@ 2022-02-25 13:30       ` Srinivas Kandagatla
  -1 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 13:30 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring



On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> Most NVMEM providers have cells at hardcoded addresses however there are
> some exceptions. Some devices store cells layout in internal structs
> using custom formats.
> 
> It's important to allow NVMEM consumers to still reference such NVMEM
> cells. Making "reg" optional allows defining NVMEM cells by their names
> only and using them with phandles.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> Reviewed-by: Rob Herring <robh@kernel.org>


Applied thanks,

--srini
> ---
>   Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
>   1 file changed, 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> index 43ed7e32e5ac..3bb349c634cb 100644
> --- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> @@ -60,9 +60,6 @@ patternProperties:
>               description:
>                 Size in bit within the address range specified by reg.
>   
> -    required:
> -      - reg
> -
>   additionalProperties: true
>   
>   examples:

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 1/3] dt-bindings: nvmem: make "reg" property optional
@ 2022-02-25 13:30       ` Srinivas Kandagatla
  0 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 13:30 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki, Rob Herring



On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> Most NVMEM providers have cells at hardcoded addresses however there are
> some exceptions. Some devices store cells layout in internal structs
> using custom formats.
> 
> It's important to allow NVMEM consumers to still reference such NVMEM
> cells. Making "reg" optional allows defining NVMEM cells by their names
> only and using them with phandles.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> Reviewed-by: Rob Herring <robh@kernel.org>


Applied thanks,

--srini
> ---
>   Documentation/devicetree/bindings/nvmem/nvmem.yaml | 3 ---
>   1 file changed, 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/nvmem.yaml b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> index 43ed7e32e5ac..3bb349c634cb 100644
> --- a/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/nvmem.yaml
> @@ -60,9 +60,6 @@ patternProperties:
>               description:
>                 Size in bit within the address range specified by reg.
>   
> -    required:
> -      - reg
> -
>   additionalProperties: true
>   
>   examples:

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
  2022-02-18  7:07     ` Rafał Miłecki
@ 2022-02-25 13:30       ` Srinivas Kandagatla
  -1 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 13:30 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki



On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format). It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> Update binding to allow including basic cells as NVMEM device subnodes.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Applied thanks,

--srini

> ---
> V2: Add children nodes description per Rob's request
> V3: Document NVMEM cells as properties
> ---
>   .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
>   1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..25033de3ef6b 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -14,6 +14,8 @@ description: |
>     NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
>     devices usiong I/O mapped memory.
>   
> +  NVRAM variables can be defined as NVMEM device subnodes.
> +
>   maintainers:
>     - Rafał Miłecki <rafal@milecki.pl>
>   
> @@ -27,11 +29,30 @@ properties:
>     reg:
>       maxItems: 1
>   
> +  board_id:
> +    type: object
> +    description: Board identification name
> +
> +  et0macaddr:
> +    type: object
> +    description: First Ethernet interface's MAC address
> +
> +  et1macaddr:
> +    type: object
> +    description: Second Ethernet interface's MAC address
> +
> +  et2macaddr:
> +    type: object
> +    description: Third Ethernet interface's MAC address
> +
>   unevaluatedProperties: false
>   
>   examples:
>     - |
>       nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>       };

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells
@ 2022-02-25 13:30       ` Srinivas Kandagatla
  0 siblings, 0 replies; 38+ messages in thread
From: Srinivas Kandagatla @ 2022-02-25 13:30 UTC (permalink / raw)
  To: Rafał Miłecki, Rob Herring
  Cc: Krzysztof Kozlowski, Florian Fainelli, Hauke Mehrtens,
	bcm-kernel-feedback-list, devicetree, linux-arm-kernel,
	linux-kernel, Rafał Miłecki



On 18/02/2022 07:07, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> NVRAM doesn't have cells at hardcoded addresses. They are stored in
> internal struct (custom & dynamic format). It's still important to
> define relevant cells in DT so NVMEM consumers can reference them.
> 
> Update binding to allow including basic cells as NVMEM device subnodes.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Applied thanks,

--srini

> ---
> V2: Add children nodes description per Rob's request
> V3: Document NVMEM cells as properties
> ---
>   .../devicetree/bindings/nvmem/brcm,nvram.yaml | 25 +++++++++++++++++--
>   1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> index 8c3f0cd22821..25033de3ef6b 100644
> --- a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml
> @@ -14,6 +14,8 @@ description: |
>     NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9
>     devices usiong I/O mapped memory.
>   
> +  NVRAM variables can be defined as NVMEM device subnodes.
> +
>   maintainers:
>     - Rafał Miłecki <rafal@milecki.pl>
>   
> @@ -27,11 +29,30 @@ properties:
>     reg:
>       maxItems: 1
>   
> +  board_id:
> +    type: object
> +    description: Board identification name
> +
> +  et0macaddr:
> +    type: object
> +    description: First Ethernet interface's MAC address
> +
> +  et1macaddr:
> +    type: object
> +    description: Second Ethernet interface's MAC address
> +
> +  et2macaddr:
> +    type: object
> +    description: Third Ethernet interface's MAC address
> +
>   unevaluatedProperties: false
>   
>   examples:
>     - |
>       nvram@1eff0000 {
> -            compatible = "brcm,nvram";
> -            reg = <0x1eff0000 0x10000>;
> +        compatible = "brcm,nvram";
> +        reg = <0x1eff0000 0x10000>;
> +
> +        mac: et0macaddr {
> +        };
>       };

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2022-02-25 13:32 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 16:02 [PATCH 0/3] nvmem: allow specifying cells by just names in DT Rafał Miłecki
2022-01-24 16:02 ` Rafał Miłecki
2022-01-24 16:02 ` [PATCH 1/3] dt-bindings: nvmem: make "reg" property optional Rafał Miłecki
2022-01-24 16:02   ` Rafał Miłecki
2022-02-11 12:38   ` Rob Herring
2022-02-11 12:38     ` Rob Herring
2022-01-24 16:02 ` [PATCH 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example Rafał Miłecki
2022-01-24 16:02   ` [PATCH 2/3] dt-bindings: nvmem: brcm, nvram: " Rafał Miłecki
2022-02-11 12:45   ` [PATCH 2/3] dt-bindings: nvmem: brcm,nvram: " Rob Herring
2022-02-11 12:45     ` Rob Herring
2022-01-24 16:03 ` [PATCH 3/3] nvmem: core: add cell name based matching of DT cell nodes Rafał Miłecki
2022-01-24 16:03   ` Rafał Miłecki
2022-02-11 13:05 ` [PATCH V2 0/3] nvmem: allow specifying cells by just names in DT Rafał Miłecki
2022-02-11 13:05   ` Rafał Miłecki
2022-02-11 13:05   ` [PATCH V2 1/3] dt-bindings: nvmem: make "reg" property optional Rafał Miłecki
2022-02-11 13:05     ` Rafał Miłecki
2022-02-11 13:05   ` [PATCH V2 2/3] dt-bindings: nvmem: brcm,nvram: add NVMEM cell to example Rafał Miłecki
2022-02-11 13:05     ` [PATCH V2 2/3] dt-bindings: nvmem: brcm, nvram: " Rafał Miłecki
2022-02-17 23:58     ` Rob Herring
2022-02-17 23:58       ` [PATCH V2 2/3] dt-bindings: nvmem: brcm,nvram: " Rob Herring
2022-02-11 13:05   ` [PATCH V2 3/3] nvmem: core: add cell name based matching of DT cell nodes Rafał Miłecki
2022-02-11 13:05     ` Rafał Miłecki
2022-02-18  7:07 ` [PATCH V3 0/3] nvmem: allow specifying cells by just names in DT Rafał Miłecki
2022-02-18  7:07   ` Rafał Miłecki
2022-02-18  7:07   ` [PATCH V3 1/3] dt-bindings: nvmem: make "reg" property optional Rafał Miłecki
2022-02-18  7:07     ` Rafał Miłecki
2022-02-25 13:30     ` Srinivas Kandagatla
2022-02-25 13:30       ` Srinivas Kandagatla
2022-02-18  7:07   ` [PATCH V3 2/3] dt-bindings: nvmem: brcm,nvram: add basic NVMEM cells Rafał Miłecki
2022-02-18  7:07     ` Rafał Miłecki
2022-02-24 19:55     ` Rob Herring
2022-02-24 19:55       ` Rob Herring
2022-02-25 13:30     ` Srinivas Kandagatla
2022-02-25 13:30       ` Srinivas Kandagatla
2022-02-18  7:07   ` [PATCH V3 3/3] nvmem: core: add cell name based matching of DT cell nodes Rafał Miłecki
2022-02-18  7:07     ` Rafał Miłecki
2022-02-25 12:10     ` Srinivas Kandagatla
2022-02-25 12:10       ` Srinivas Kandagatla

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.