1 From ddb8cefb7af288950447ca6eeeafb09977dab56f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 4 Oct 2022 10:37:10 +0200
4 Subject: [PATCH] mtd: core: try to find OF node for every MTD partition
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 So far this feature was limited to the top-level "nvmem-cells" node.
10 There are multiple parsers creating partitions and subpartitions
11 dynamically. Extend that code to handle them too.
13 This allows finding partition-* node for every MTD (sub)partition.
18 compatible = "brcm,bcm947xx-cfe-partitions";
21 compatible = "brcm,trx";
28 Cc: Christian Marangi <ansuelsmth@gmail.com>
29 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
30 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
31 Link: https://lore.kernel.org/linux-mtd/20221004083710.27704-2-zajec5@gmail.com
33 drivers/mtd/mtdcore.c | 18 ++++++------------
34 1 file changed, 6 insertions(+), 12 deletions(-)
36 --- a/drivers/mtd/mtdcore.c
37 +++ b/drivers/mtd/mtdcore.c
38 @@ -566,20 +566,22 @@ static void mtd_check_of_node(struct mtd
39 struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
40 const char *pname, *prefix = "partition-";
41 int plen, mtd_name_len, offset, prefix_len;
44 /* Check if MTD already has a device node */
45 if (mtd_get_of_node(mtd))
48 - /* Check if a partitions node exist */
49 if (!mtd_is_partition(mtd))
52 parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
56 - partitions = of_get_child_by_name(parent_dn, "partitions");
57 + if (mtd_is_partition(mtd->parent))
58 + partitions = of_node_get(parent_dn);
60 + partitions = of_get_child_by_name(parent_dn, "partitions");
64 @@ -603,19 +605,11 @@ static void mtd_check_of_node(struct mtd
65 plen = strlen(pname) - offset;
66 if (plen == mtd_name_len &&
67 !strncmp(mtd->name, pname + offset, plen)) {
69 + mtd_set_of_node(mtd, mtd_dn);
75 - goto exit_partitions;
77 - /* Set of_node only for nvmem */
78 - if (of_device_is_compatible(mtd_dn, "nvmem-cells"))
79 - mtd_set_of_node(mtd, mtd_dn);
82 of_node_put(partitions);
84 of_node_put(parent_dn);