f8d3a370d448f3c0aa5f7007aab49b6ed3199765
[openwrt/staging/ldir.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
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.
12
13 This allows finding partition-* node for every MTD (sub)partition.
14
15 Random example:
16
17 partitions {
18 compatible = "brcm,bcm947xx-cfe-partitions";
19
20 partition-firmware {
21 compatible = "brcm,trx";
22
23 partition-loader {
24 };
25 };
26 };
27
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
32 ---
33 drivers/mtd/mtdcore.c | 18 ++++++------------
34 1 file changed, 6 insertions(+), 12 deletions(-)
35
36 --- a/drivers/mtd/mtdcore.c
37 +++ b/drivers/mtd/mtdcore.c
38 @@ -551,20 +551,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;
42 - bool found = false;
43
44 /* Check if MTD already has a device node */
45 if (mtd_get_of_node(mtd))
46 return;
47
48 - /* Check if a partitions node exist */
49 if (!mtd_is_partition(mtd))
50 return;
51 +
52 parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
53 if (!parent_dn)
54 return;
55
56 - partitions = of_get_child_by_name(parent_dn, "partitions");
57 + if (mtd_is_partition(mtd->parent))
58 + partitions = of_node_get(parent_dn);
59 + else
60 + partitions = of_get_child_by_name(parent_dn, "partitions");
61 if (!partitions)
62 goto exit_parent;
63
64 @@ -588,19 +590,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)) {
68 - found = true;
69 + mtd_set_of_node(mtd, mtd_dn);
70 break;
71 }
72 }
73
74 - if (!found)
75 - goto exit_partitions;
76 -
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);
80 -
81 -exit_partitions:
82 of_node_put(partitions);
83 exit_parent:
84 of_node_put(parent_dn);