* [RFC RFT PATCH v3 1/2] dt-bindings: mtd: partitions: Document new partition-dynamic nodes
2022-02-24 15:20 [RFC RFT PATCH v3 0/2] Add nvmem support for dynamic partitions Ansuel Smith
@ 2022-02-24 15:20 ` Ansuel Smith
2022-02-24 15:20 ` [RFC RFT PATCH v3 2/2] mtd: core: introduce of support for dynamic partitions Ansuel Smith
1 sibling, 0 replies; 3+ messages in thread
From: Ansuel Smith @ 2022-02-24 15:20 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Rob Herring, Ansuel Smith, Manivannan Sadhasivam, linux-mtd,
devicetree, linux-kernel
Document new partition-dynamic nodes used to provide an OF node for
partition registred at runtime by parsers. This is required for nvmem
system to declare and detect nvmem-cells.
With these special partitions, the reg / offset is not required.
The node name must be in the form of "partition name"-dynamic.
If the partition can't be displayed using the node name, it's possible
to use the label binding that will be used instead of the node name.
The node name or the label binding is used to match the partition
allocated by the parser at runtime and the parser will provide reg
and offset of the mtd.
NVMEM will use the data from the parser and provide the NVMEM cells
declared in the DTS, "connecting" the dynamic partition with a
static declaration of cells in them.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
.../mtd/partitions/partition-dynamic.yaml | 56 +++++++++++++++++++
.../mtd/partitions/qcom,smem-part.yaml | 4 ++
2 files changed, 60 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mtd/partitions/partition-dynamic.yaml
diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition-dynamic.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition-dynamic.yaml
new file mode 100644
index 000000000000..e0efa58e4fac
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/partitions/partition-dynamic.yaml
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mtd/partitions/partition-dynamic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Dynamic Partition
+
+description: |
+ This binding describes a single flash partition that is dynamically allocated
+ by a dedicated parser that is not a fixed-partition parser.
+
+ A dynamic partition require the node ending with the "-dynamic" tag and if the
+ dynamic partition name can't be displayed using the node name, the label
+ properties can be used. The node name or the label have to match the dynamic
+ partition allocated by the parser.
+
+ These special partition definition can be used to give a dynamic partition
+ an OF node to declare NVMEM cells. An example is declaring the partition
+ label and all the NVMEM cells in it. The parser will detect the correct reg
+ and offset and the NVMEM will register the cells in it based on the data
+ extracted by the parser.
+
+maintainers:
+ - Ansuel Smith <ansuelsmth@gmail.com>
+
+properties:
+ label:
+ description: The label / name for the partition assigned by the parser at
+ runtime. This is needed for sybsystem like NVMEM to define cells and
+ register with this OF node.
+
+additionalProperties: true
+
+examples:
+ - |
+ flash {
+ partitions {
+ compatible = "qcom,smem-part";
+
+ art-dynamic {
+ compatible = "nvmem-cells";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ label = "0:art";
+
+ macaddr_art_0: macaddr@0 {
+ reg = <0x0 0x6>;
+ };
+
+ macaddr_art_6: macaddr@6 {
+ reg = <0x6 0x6>;
+ };
+ };
+ };
+ };
diff --git a/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml b/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml
index cf3f8c1e035d..1d7d9b3378c3 100644
--- a/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml
+++ b/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml
@@ -19,6 +19,10 @@ properties:
compatible:
const: qcom,smem-part
+patternProperties:
+ "-dynamic$":
+ $ref: "partition-dynamic.yaml#"
+
required:
- compatible
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [RFC RFT PATCH v3 2/2] mtd: core: introduce of support for dynamic partitions
2022-02-24 15:20 [RFC RFT PATCH v3 0/2] Add nvmem support for dynamic partitions Ansuel Smith
2022-02-24 15:20 ` [RFC RFT PATCH v3 1/2] dt-bindings: mtd: partitions: Document new partition-dynamic nodes Ansuel Smith
@ 2022-02-24 15:20 ` Ansuel Smith
1 sibling, 0 replies; 3+ messages in thread
From: Ansuel Smith @ 2022-02-24 15:20 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Rob Herring, Ansuel Smith, Manivannan Sadhasivam, linux-mtd,
devicetree, linux-kernel
We have many parser that register mtd partitions at runtime. One example
is the cmdlinepart or the smem-part parser where the compatible is defined
in the dts and the partitions gets detected and registered by the
parser. This is problematic for the NVMEM subsystem that requires an OF node
to detect NVMEM cells.
To fix this problem, introduce an additional logic that will try to
assign an OF node to the MTD if declared.
On MTD addition, it will be checked if the MTD has an OF node and if
not declared will check if a partition with the same name / label is
declared in DTS. If an exact match is found, the partition dynamically
allocated by the parser will have a connected OF node.
The NVMEM subsystem will detect the OF node and register any NVMEM cells
declared statically in the DTS.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
drivers/mtd/mtdcore.c | 56 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 9186268d361b..80e28a288f65 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -563,6 +563,61 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
return 0;
}
+static void mtd_check_of_node(struct mtd_info *mtd)
+{
+ struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
+ const char *mtd_name, *suffix = "-dynamic";
+ int plen, suffix_len = 8;
+ struct mtd_info *parent;
+ bool found = false;
+
+ /* Check if MTD already has a device node */
+ if (dev_of_node(&mtd->dev))
+ return;
+
+ /* Check if a partitions node exist */
+ parent = mtd->parent;
+ parent_dn = dev_of_node(&parent->dev);
+ if (!parent_dn)
+ return;
+
+ partitions = of_get_child_by_name(parent_dn, "partitions");
+ if (!partitions)
+ goto exit_parent;
+
+ /* Search if a partition is defined with the same name */
+ for_each_child_of_node(partitions, mtd_dn) {
+ mtd_name = of_get_property(mtd_dn, "label", &plen);
+ if (!mtd_name) {
+ mtd_name = of_get_property(mtd_dn, "name", &plen);
+
+ /* Check correct suffix */
+ if (plen <= suffix_len ||
+ strncmp(mtd_name + plen - suffix_len, suffix, suffix_len))
+ continue;
+
+ plen = plen - suffix_len;
+ }
+
+ if (!strncmp(mtd->name, mtd_name, plen)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ goto exit_partitions;
+
+ /* Set of_node only for nvmem */
+ if (of_device_is_compatible(mtd_dn, "nvmem-cells"))
+ mtd_set_of_node(mtd, mtd_dn);
+
+exit_partitions:
+ of_node_put(partitions);
+exit_parent:
+ of_node_put(parent_dn);
+}
+
/**
* add_mtd_device - register an MTD device
* @mtd: pointer to new MTD device info structure
@@ -668,6 +723,7 @@ int add_mtd_device(struct mtd_info *mtd)
mtd->dev.devt = MTD_DEVT(i);
dev_set_name(&mtd->dev, "mtd%d", i);
dev_set_drvdata(&mtd->dev, mtd);
+ mtd_check_of_node(mtd);
of_node_get(mtd_get_of_node(mtd));
error = device_register(&mtd->dev);
if (error)
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread