linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Implement nvmem support for mtd
@ 2021-02-16 19:56 Ansuel Smith
  2021-02-16 19:56 ` [PATCH 1/3] mtd: partitions: ofpart: skip subnodes parse with compatible Ansuel Smith
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ansuel Smith @ 2021-02-16 19:56 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Ansuel Smith, Miquel Raynal, Vignesh Raghavendra, Rob Herring,
	Boris Brezillon, linux-mtd, devicetree, linux-kernel

The mtd support for the nvmem api has been stalled from 2018 with a patch
half pushed hoping that a scheme is found for the mtd name later. This
patchset try to address this.

The solution is simple.
New partitions scheme should always have the partitions {} structure and 
declare subnodes as partitions is deprecated and should not be used anymore.
Fixed-partitions parser is changed to parse direct subnode as partitions
only if the appropriate compatible is used. This change make possible
the use of nvmem-partitions compatible and the entire partition node can
be parsed by the nvmem of framework.
The current code register the partition to the nvmem framework every time
but skip actually of_node parting. The new nvmem-partitions compatible is
used to enable of_node parsing on the desired partitions.


Ansuel Smith (3):
  mtd: partitions: ofpart: skip subnodes parse with compatible
  mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells
  dt-bindings: mtd: Document use of nvmem-partitions compatible

 .../mtd/partitions/nvmem-partitions.yaml      | 105 ++++++++++++++++++
 drivers/mtd/mtdcore.c                         |   2 +-
 drivers/mtd/parsers/ofpart.c                  |   5 +
 3 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/nvmem-partitions.yaml

-- 
2.30.0


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

* [PATCH 1/3] mtd: partitions: ofpart: skip subnodes parse with compatible
  2021-02-16 19:56 [PATCH 0/3] Implement nvmem support for mtd Ansuel Smith
@ 2021-02-16 19:56 ` Ansuel Smith
  2021-02-16 19:56 ` [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells Ansuel Smith
  2021-02-16 19:56 ` [PATCH 3/3] dt-bindings: mtd: Document use of nvmem-partitions compatible Ansuel Smith
  2 siblings, 0 replies; 5+ messages in thread
From: Ansuel Smith @ 2021-02-16 19:56 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Ansuel Smith, Miquel Raynal, Vignesh Raghavendra, Rob Herring,
	Boris Brezillon, linux-mtd, devicetree, linux-kernel

If a partitions structure is not used, parse direct subnodes as
fixed-partitions only if a compatible is not found or is of type
fixed-partition. A parser can be used directly on the subnode and
subnodes should not be parsed as fixed-partitions by default.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 drivers/mtd/parsers/ofpart.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/parsers/ofpart.c b/drivers/mtd/parsers/ofpart.c
index daf507c123e6..4b363dd0311c 100644
--- a/drivers/mtd/parsers/ofpart.c
+++ b/drivers/mtd/parsers/ofpart.c
@@ -50,6 +50,11 @@ static int parse_fixed_partitions(struct mtd_info *master,
 			 master->name, mtd_node);
 		ofpart_node = mtd_node;
 		dedicated = false;
+
+		/* Skip parsing direct subnodes if a compatible is found and is not fixed-partitions */
+		if (node_has_compatible(ofpart_node) &&
+		    !of_device_is_compatible(ofpart_node, "fixed-partitions"))
+			return 0;
 	} else if (!of_device_is_compatible(ofpart_node, "fixed-partitions")) {
 		/* The 'partitions' subnode might be used by another parser */
 		return 0;
-- 
2.30.0


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

* [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells
  2021-02-16 19:56 [PATCH 0/3] Implement nvmem support for mtd Ansuel Smith
  2021-02-16 19:56 ` [PATCH 1/3] mtd: partitions: ofpart: skip subnodes parse with compatible Ansuel Smith
@ 2021-02-16 19:56 ` Ansuel Smith
  2021-02-16 21:10   ` kernel test robot
  2021-02-16 19:56 ` [PATCH 3/3] dt-bindings: mtd: Document use of nvmem-partitions compatible Ansuel Smith
  2 siblings, 1 reply; 5+ messages in thread
From: Ansuel Smith @ 2021-02-16 19:56 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Ansuel Smith, Miquel Raynal, Vignesh Raghavendra, Rob Herring,
	Boris Brezillon, linux-mtd, devicetree, linux-kernel

Partitions that contains the nvmem-partitions compatible will register
their direct subonodes as nvmem cells and the node will be treated as a
nvmem provider.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 drivers/mtd/mtdcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 2d6423d89a17..2a40b00ec3d0 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -543,7 +543,7 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
 	config.stride = 1;
 	config.read_only = true;
 	config.root_only = true;
-	config.no_of_node = true;
+	config.no_of_node = !of_device_is_compatible(node, "nvmem-partitions");
 	config.priv = mtd;
 
 	mtd->nvmem = nvmem_register(&config);
-- 
2.30.0


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

* [PATCH 3/3] dt-bindings: mtd: Document use of nvmem-partitions compatible
  2021-02-16 19:56 [PATCH 0/3] Implement nvmem support for mtd Ansuel Smith
  2021-02-16 19:56 ` [PATCH 1/3] mtd: partitions: ofpart: skip subnodes parse with compatible Ansuel Smith
  2021-02-16 19:56 ` [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells Ansuel Smith
@ 2021-02-16 19:56 ` Ansuel Smith
  2 siblings, 0 replies; 5+ messages in thread
From: Ansuel Smith @ 2021-02-16 19:56 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Ansuel Smith, Miquel Raynal, Vignesh Raghavendra, Rob Herring,
	Boris Brezillon, linux-mtd, devicetree, linux-kernel

Document nvmem-partitions compatible used to treat mtd partitions as a
nvmem provider.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 .../mtd/partitions/nvmem-partitions.yaml      | 105 ++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/nvmem-partitions.yaml

diff --git a/Documentation/devicetree/bindings/mtd/partitions/nvmem-partitions.yaml b/Documentation/devicetree/bindings/mtd/partitions/nvmem-partitions.yaml
new file mode 100644
index 000000000000..1ff283febcaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/partitions/nvmem-partitions.yaml
@@ -0,0 +1,105 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mtd/partitions/nvmem-partitions.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nvmem partitions
+
+description: |
+  This binding can be used to treat the specific partition as a nvmem provider.
+  Each direct subnodes represents the nvmem cells and won't be parsed as fixed-partitions.
+  Fixed-partitions bindings described in fixed-partitions.yaml apply to the nvmem provider node.
+
+maintainers:
+  - Ansuel Smith <ansuelsmth@gmail.com>
+
+properties:
+  compatible:
+    const: nvmem-partitions
+
+  "#address-cells": true
+
+  "#size-cells": true
+
+  reg:
+    description: partition's offset and size within the flash
+    maxItems: 1
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+  - reg
+
+additionalProperties: true
+
+examples:
+  - |
+    partitions {
+      compatible = "fixed-partitions";
+      #address-cells = <1>;
+      #size-cells = <1>;
+
+      /* ... */
+
+      };
+      art: art@1200000 {
+        compatible = "nvmem-partitions";
+        reg = <0x1200000 0x0140000>;
+        label = "art";
+        read-only;
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        macaddr_gmac1: macaddr_gmac1@0 {
+          reg = <0x0 0x6>;
+        };
+
+        macaddr_gmac2: macaddr_gmac2@6 {
+          reg = <0x6 0x6>;
+        };
+
+        pre_cal_24g: pre_cal_24g@1000 {
+          reg = <0x1000 0x2f20>;
+        };
+
+        pre_cal_5g: pre_cal_5g@5000{
+          reg = <0x5000 0x2f20>;
+        };
+      };
+  - |
+    partitions {
+        compatible = "fixed-partitions";
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        partition@0 {
+            label = "bootloader";
+            reg = <0x000000 0x100000>;
+            read-only;
+        };
+
+        firmware@100000 {
+            compatible = "brcm,trx";
+            label = "firmware";
+            reg = <0x100000 0xe00000>;
+        };
+
+        calibration@f00000 {
+            compatible = "nvmem-partitions";
+            label = "calibration";
+            reg = <0xf00000 0x100000>;
+            ranges = <0 0xf00000 0x100000>;
+            #address-cells = <1>;
+            #size-cells = <1>;
+
+            wifi0@0 {
+                reg = <0x000000 0x080000>;
+            };
+
+            wifi1@80000 {
+                reg = <0x080000 0x080000>;
+            };
+        };
+    };
-- 
2.30.0


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

* Re: [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells
  2021-02-16 19:56 ` [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells Ansuel Smith
@ 2021-02-16 21:10   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-02-16 21:10 UTC (permalink / raw)
  To: Ansuel Smith, Richard Weinberger
  Cc: kbuild-all, Ansuel Smith, Miquel Raynal, Vignesh Raghavendra,
	Rob Herring, Boris Brezillon, linux-mtd, devicetree,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3068 bytes --]

Hi Ansuel,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mtd/mtd/next]
[also build test ERROR on mtd/mtd/fixes robh/for-next v5.11 next-20210216]
[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]

url:    https://github.com/0day-ci/linux/commits/Ansuel-Smith/Implement-nvmem-support-for-mtd/20210217-035931
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next
config: m68k-randconfig-r011-20210216 (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.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/0day-ci/linux/commit/ea1902bc853fa1f1050cc741912709fe5ebbdc41
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ansuel-Smith/Implement-nvmem-support-for-mtd/20210217-035931
        git checkout ea1902bc853fa1f1050cc741912709fe5ebbdc41
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/mtd/mtdcore.c: In function 'mtd_nvmem_add':
>> drivers/mtd/mtdcore.c:546:47: error: 'node' undeclared (first use in this function); did you mean 'inode'?
     546 |  config.no_of_node = !of_device_is_compatible(node, "nvmem-partitions");
         |                                               ^~~~
         |                                               inode
   drivers/mtd/mtdcore.c:546:47: note: each undeclared identifier is reported only once for each function it appears in


vim +546 drivers/mtd/mtdcore.c

   531	
   532	static int mtd_nvmem_add(struct mtd_info *mtd)
   533	{
   534		struct nvmem_config config = {};
   535	
   536		config.id = -1;
   537		config.dev = &mtd->dev;
   538		config.name = dev_name(&mtd->dev);
   539		config.owner = THIS_MODULE;
   540		config.reg_read = mtd_nvmem_reg_read;
   541		config.size = mtd->size;
   542		config.word_size = 1;
   543		config.stride = 1;
   544		config.read_only = true;
   545		config.root_only = true;
 > 546		config.no_of_node = !of_device_is_compatible(node, "nvmem-partitions");
   547		config.priv = mtd;
   548	
   549		mtd->nvmem = nvmem_register(&config);
   550		if (IS_ERR(mtd->nvmem)) {
   551			/* Just ignore if there is no NVMEM support in the kernel */
   552			if (PTR_ERR(mtd->nvmem) == -EOPNOTSUPP) {
   553				mtd->nvmem = NULL;
   554			} else {
   555				dev_err(&mtd->dev, "Failed to register NVMEM device\n");
   556				return PTR_ERR(mtd->nvmem);
   557			}
   558		}
   559	
   560		return 0;
   561	}
   562	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 22660 bytes --]

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

end of thread, other threads:[~2021-02-16 21:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 19:56 [PATCH 0/3] Implement nvmem support for mtd Ansuel Smith
2021-02-16 19:56 ` [PATCH 1/3] mtd: partitions: ofpart: skip subnodes parse with compatible Ansuel Smith
2021-02-16 19:56 ` [PATCH 2/3] mtd: core: add nvmem-partitions compatible to parse mtd as nvmem cells Ansuel Smith
2021-02-16 21:10   ` kernel test robot
2021-02-16 19:56 ` [PATCH 3/3] dt-bindings: mtd: Document use of nvmem-partitions compatible Ansuel Smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).