Skip to contentSkip to conversation

nvmem: add fixed cells layout

PATCH Superseded Rafał Miłecki 4 participants 9 messages Mar 17, 2023 – Mar 20, 2023

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover nvmem: add fixed cells layout

From: Rafał Miłecki <[email protected]>

NVMEM bindings received a new feature recently: layouts. They allow defining NVMEM device content in a separated DT node named "nvmem-layout". That improvement results in cleaner and more generic bindings.

New bindings & drivers should use layouts design. If possible we should also try converting existing bindings & drivers to layouts.

This patchset allows defining NVMEM cells in a new way (using NVMEM layout feature).

This deprecates support for defining NVMEM cells as direct DT device node subnodes but IT DOESN'T drop support for that.

PLEASE understand what this patchset handles. It adds new & preferred way of defining NVMEM cells. It is NOT meant to:
1. Convert ALL existing bindings or drivers
2. Add support for new extra features (like multiple layouts)
3. Break any backward compatibility (it WON'T happen)

Note: this is based on top of the:
[PATCH 1/4] nvmem: Add macro to register nvmem layout drivers

Rafał Miłecki (4):
dt-bindings: nvmem: layouts: add fixed-layout
dt-bindings: nvmem: convert base example to use NVMEM fixed cells
layout
nvmem: core: export nvmem_add_cells_from_of()
nvmem: layouts: add fixed cells layout

 .../bindings/nvmem/layouts/fixed-cell.yaml    | 31 ++++++++++
 .../bindings/nvmem/layouts/fixed-layout.yaml  | 49 +++++++++++++++
 .../bindings/nvmem/layouts/nvmem-layout.yaml  |  5 +-
 .../devicetree/bindings/nvmem/nvmem.yaml      | 61 ++++++++-----------
 drivers/nvmem/core.c                          |  7 ++-
 drivers/nvmem/layouts/Kconfig                 |  8 +++
 drivers/nvmem/layouts/Makefile                |  1 +
 drivers/nvmem/layouts/fixed.c                 | 41 +++++++++++++
 include/linux/nvmem-provider.h                |  7 +++
 9 files changed, 168 insertions(+), 42 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml
 create mode 100644 drivers/nvmem/layouts/fixed.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/4 dt-bindings: nvmem: layouts: add fixed-layout

From: Rafał Miłecki <[email protected]>

With the introduction of NVMEM layouts, new NVMEM content structures should be defined as such. We should also try to convert / migrate existing NVMEM content bindings to layouts.

This commit handles fixed NVMEM cells. So far they had to be defined directly - as device subnodes. With this change it's allowed to put them in the DT node named "nvmem-layout".

Having NVMEM cells in separated node is prefered as it draws a nice line between NVMEM device and its content. It results in cleaner bindings.

FWIW a very similiar situation has happened to MTD devices and their
partitions: see commit 5d96ea42eb63 ("dt-bindings: mtd: Clarify all partition subnodes").

---
 .../bindings/nvmem/layouts/fixed-cell.yaml    | 31 ++++++++++++
 .../bindings/nvmem/layouts/fixed-layout.yaml  | 49 +++++++++++++++++++
 .../bindings/nvmem/layouts/nvmem-layout.yaml  |  5 +-
 .../devicetree/bindings/nvmem/nvmem.yaml      | 19 +------
 4 files changed, 83 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml
Documentation/devicetree/bindings/nvmem/layouts/fixed-cell.yaml new file +31 -0
new file mode 100644
index 000000000000..e698098450e1
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/layouts/fixed-cell.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Fixed offset & size NVMEM cell
+
+maintainers:
+  - Rafał Miłecki <[email protected]>
+  - Srinivas Kandagatla <[email protected]>
+
+properties:
+  reg:
+    maxItems: 1
+
+  bits:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    items:
+      - minimum: 0
+        maximum: 7
+        description:
+          Offset in bit within the address range specified by reg.
+      - minimum: 1
+        description:
+          Size in bit within the address range specified by reg.
+
+required:
+  - reg
+
+additionalProperties: true
Documentation/devicetree/bindings/nvmem/layouts/fixed-layout.yaml new file +49 -0

49 lines not on this page · raw message

Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml +1 -4
index 8512ee538c4c..3b40f7880774 100644
@@ -18,16 +18,13 @@ description: |
   perform their parsing. The nvmem-layout container is here to describe these.
 
 oneOf:
+  - $ref: fixed-layout.yaml
   - $ref: kontron,sl28-vpd.yaml
   - $ref: onie,tlv-layout.yaml
 
 properties:
   compatible: true
 
-  '#address-cells': false
-
-  '#size-cells': false
-
 required:
   - compatible
 
Documentation/devicetree/bindings/nvmem/nvmem.yaml +2 -17
index 75bb93dda9df..b79f1bb795fb 100644
@@ -49,23 +49,8 @@ properties:
 patternProperties:
   "@[0-9a-f]+(,[0-7])?$":
     type: object
-
-    properties:
-      reg:
-        maxItems: 1
-        description:
-          Offset and size in bytes within the storage device.
-
-      bits:
-        $ref: /schemas/types.yaml#/definitions/uint32-array
-        items:
-          - minimum: 0
-            maximum: 7
-            description:
-              Offset in bit within the address range specified by reg.
-          - minimum: 1
-            description:
-              Size in bit within the address range specified by reg.
+    $ref: layouts/fixed-cell.yaml
+    deprecated: true
 
 additionalProperties: true
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/4 dt-bindings: nvmem: convert base example to use NVMEM fixed cells layout

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

With support for the "fixed-layout" binding it's possible and preferred now to define fixed NVMEM cells in the layout node. Do that for the binding example binding.

---
 .../devicetree/bindings/nvmem/nvmem.yaml      | 42 +++++++++++--------
 1 file changed, 24 insertions(+), 18 deletions(-)
Documentation/devicetree/bindings/nvmem/nvmem.yaml +24 -18
index b79f1bb795fb..980244100690 100644
@@ -68,24 +68,30 @@ examples:
 
           /* ... */
 
-          /* Data cells */
-          tsens_calibration: calib@404 {
-              reg = <0x404 0x10>;
-          };
-
-          tsens_calibration_bckp: calib_bckp@504 {
-              reg = <0x504 0x11>;
-              bits = <6 128>;
-          };
-
-          pvs_version: pvs-version@6 {
-              reg = <0x6 0x2>;
-              bits = <7 2>;
-          };
-
-          speed_bin: speed-bin@c{
-              reg = <0xc 0x1>;
-              bits = <2 3>;
+          nvmem-layout {
+              compatible = "fixed-layout";
+              #address-cells = <1>;
+              #size-cells = <1>;
+
+              /* Data cells */
+              tsens_calibration: calib@404 {
+                  reg = <0x404 0x10>;
+              };
+
+              tsens_calibration_bckp: calib_bckp@504 {
+                  reg = <0x504 0x11>;
+                  bits = <6 128>;
+              };
+
+              pvs_version: pvs-version@6 {
+                  reg = <0x6 0x2>;
+                  bits = <7 2>;
+              };
+
+              speed_bin: speed-bin@c{
+                  reg = <0xc 0x1>;
+                  bits = <2 3>;
+              };
           };
       };
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/4 nvmem: core: export nvmem_add_cells_from_of()

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This symbol can be cleanly re-used by the fixed NVMEM layout driver. Allow passing DT node as argument to make it a bit more generic.

---
 drivers/nvmem/core.c           | 7 ++++---
 include/linux/nvmem-provider.h | 7 +++++++
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/nvmem/core.c +4 -3
index 212c5ba5789f..985a42cfb0a2 100644
@@ -694,7 +694,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 	return 0;
 }
 
-static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
+int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct device_node *np)
 {
 	struct nvmem_layout *layout = nvmem->layout;
 	struct device *dev = &nvmem->dev;
@@ -702,7 +702,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 	const __be32 *addr;
 	int len, ret;
 
-	for_each_child_of_node(dev->of_node, child) {
+	for_each_child_of_node(np, child) {
 		struct nvmem_cell_info info = {0};
 
 		addr = of_get_property(child, "reg", &len);
@@ -739,6 +739,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(nvmem_add_cells_from_of);
 
 int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner)
 {
@@ -970,7 +971,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (rval)
 		goto err_remove_cells;
 
-	rval = nvmem_add_cells_from_of(nvmem);
+	rval = nvmem_add_cells_from_of(nvmem, nvmem->dev.of_node);
 	if (rval)
 		goto err_remove_cells;
 
include/linux/nvmem-provider.h +7 -0
index 3e97c8315c45..2b5410be2636 100644
@@ -195,6 +195,8 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table);
 int nvmem_add_one_cell(struct nvmem_device *nvmem,
 		       const struct nvmem_cell_info *info);
 
+int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct device_node *np);
+
 int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner);
 #define nvmem_layout_register(layout) \
 	__nvmem_layout_register(layout, THIS_MODULE)
@@ -226,6 +228,11 @@ static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
 	return -EOPNOTSUPP;
 }
 
+static int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct device_node *np)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline int nvmem_layout_register(struct nvmem_layout *layout)
 {
 	return -EOPNOTSUPP;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH V4 3/4] nvmem: core: export nvmem_add_cells_from_of()

I love your patch! Yet something to improve:

Hi Rafał,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20230317]
[cannot apply to robh/for-next krzk-dt/for-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.3-rc2 v6.3-rc1 v6.2 v6.3-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948
patch link:    https://lore.kernel.org/r/20230317132620.31142-4-zajec5%40gmail.com
patch subject: [PATCH V4 3/4] nvmem: core: export nvmem_add_cells_from_of()
config: powerpc-allnoconfig (https://download.01.org/0day-ci/archive/20230318/[email protected]/config)
compiler: powerpc-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/70d21b7988db0cad28a2cb4b0d7f5d77d587a51f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948 git checkout 70d21b7988db0cad28a2cb4b0d7f5d77d587a51f
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/kernel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/linux/rtc.h:18,
from arch/powerpc/kernel/time.c:48:

>> include/linux/nvmem-provider.h:230:12: error: 'nvmem_add_cells_from_of' defined but not used [-Werror=unused-function]

230 | static int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct device_node *np)
| ^~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

vim +/nvmem_add_cells_from_of +230 include/linux/nvmem-provider.h

229

 > 230	static int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct device_node *np)

231 {
232 return -EOPNOTSUPP;
233 }
234

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#5 lore raw

Re: [PATCH V4 3/4] nvmem: core: export nvmem_add_cells_from_of()

In reply to Rafał Miłecki

Am 2023-03-17 14:26, schrieb Rafał Miłecki:

Quoted 16 lines

From: Rafał Miłecki <[email protected]>

This symbol can be cleanly re-used by the fixed NVMEM layout driver. Allow passing DT node as argument to make it a bit more generic.

---
 drivers/nvmem/core.c           | 7 ++++---
 include/linux/nvmem-provider.h | 7 +++++++
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/nvmem/core.c +0 -0
index 212c5ba5789f..985a42cfb0a2 100644

drivers/nvmem/core.c static int nvmem_validate_keepouts(struct · line 699

Quoted 7 lines
drivers/nvmem/core.c +1 -1
@@ -694,7 +694,7 @@ static int nvmem_validate_keepouts(struct
 nvmem_device *nvmem)
 	return 0;
 }
 
-static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
+int nvmem_add_cells_from_of(struct nvmem_device *nvmem, struct 
 device_node *np)

I'm not sure, how to feel about exposing an "internal" function to the layouts module. I mean all these nvmem_add_cells_from_* are internal to the core. Also the help text of the add_cells() callback tells you to use nvmem_add_one_cell().

Although there is a bit of code duplication, I'd rather refactor the nvmem_add_cells_from_of() to split it into parsing and adding. Then re-use just the parsing from the fixed layout module and call the appropriate nvmem_add_one_cell() yourself there.

-michael

#6 lore raw

PATCH v4 4/4 nvmem: layouts: add fixed cells layout

In reply to Rafał Miłecki

From: Rafał Miłecki <[email protected]>

This adds a driver for the "fixed-layout" NVMEM layout binding. It allows defining NVMEM cells in a layout DT node named "nvmem-layout".

---
 drivers/nvmem/layouts/Kconfig  |  8 +++++++
 drivers/nvmem/layouts/Makefile |  1 +
 drivers/nvmem/layouts/fixed.c  | 41 ++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 drivers/nvmem/layouts/fixed.c
drivers/nvmem/layouts/Kconfig +8 -0
index 7ff1ee1c1f05..2ebbde7b15b2 100644
@@ -2,6 +2,14 @@
 
 menu "Layout Types"
 
+config NVMEM_LAYOUT_FIXED
+	tristate "Fixed cells layout support"
+	help
+	  Say Y here if you want to support layout with fixed cells (hardcoded
+	  offsets and sizes).
+
+	  If unsure, say N.
+
 config NVMEM_LAYOUT_SL28_VPD
 	tristate "Kontron sl28 VPD layout support"
 	select CRC8
drivers/nvmem/layouts/Makefile +1 -0
index 2974bd7d33ed..449dd893f968 100644
@@ -3,5 +3,6 @@
 # Makefile for nvmem layouts.
 #
 
+obj-$(CONFIG_NVMEM_LAYOUT_FIXED) += fixed.o
 obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
 obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
drivers/nvmem/layouts/fixed.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH V4 4/4] nvmem: layouts: add fixed cells layout

I love your patch! Perhaps something to improve:

Hi Rafał,

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20230317]
[cannot apply to robh/for-next krzk-dt/for-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.3-rc2 v6.3-rc1 v6.2 v6.3-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948
patch link:    https://lore.kernel.org/r/20230317132620.31142-5-zajec5%40gmail.com
patch subject: [PATCH V4 4/4] nvmem: layouts: add fixed cells layout
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230317/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/7ffae9ad6cdb83ae60e3eacf96ab779e0b69a65b
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948 git checkout 7ffae9ad6cdb83ae60e3eacf96ab779e0b69a65b
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/nvmem/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/nvmem/layouts/fixed.c:37:1: warning: data definition has no type or storage class
      37 | module_nvmem_layout_driver(fixed_nvmem_layout);
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/nvmem/layouts/fixed.c:37:1: error: type defaults to 'int' in declaration of 'module_nvmem_layout_driver' [-Werror=implicit-int]
>> drivers/nvmem/layouts/fixed.c:37:1: warning: parameter names (without types) in function declaration

cc1: some warnings being treated as errors

vim +37 drivers/nvmem/layouts/fixed.c

    36	
  > 37	module_nvmem_layout_driver(fixed_nvmem_layout);
    38	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#8 lore raw

Re: [PATCH V4 4/4] nvmem: layouts: add fixed cells layout

Quoted 29 lines · kernel test robot

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20230317]
[cannot apply to robh/for-next krzk-dt/for-next char-misc/char-misc-testing char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.3-rc2 v6.3-rc1 v6.2 v6.3-rc2] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948
patch link:    https://lore.kernel.org/r/20230317132620.31142-5-zajec5%40gmail.com
patch subject: [PATCH V4 4/4] nvmem: layouts: add fixed cells layout
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230317/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/7ffae9ad6cdb83ae60e3eacf96ab779e0b69a65b
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Rafa-Mi-ecki/dt-bindings-nvmem-layouts-add-fixed-layout/20230317-212948 git checkout 7ffae9ad6cdb83ae60e3eacf96ab779e0b69a65b
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/nvmem/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 8 lines

All warnings (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

drivers/nvmem/layouts/fixed.c:37:1: warning: data definition has no type or storage class

       37 | module_nvmem_layout_driver(fixed_nvmem_layout);
          | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/nvmem/layouts/fixed.c:37:1: error: type defaults to 'int' in declaration of 'module_nvmem_layout_driver' [-Werror=implicit-int]
Quoted 1 line
Quoted 1 line

drivers/nvmem/layouts/fixed.c:37:1: warning: parameter names (without types) in function declaration

cc1: some warnings being treated as errors

I reported that to Miquel already, he's going to improve his patch:
https://lore.kernel.org/lkml/20230316173741.4f572068@xps-13/

Quoted 6 lines

vim +37 drivers/nvmem/layouts/fixed.c

     36	
Quoted 1 line

37 module_nvmem_layout_driver(fixed_nvmem_layout);

     38