1 From bcdf0315a61a29eb753a607d3a85a4032de72d94 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 10 May 2022 15:12:59 +0200
4 Subject: [PATCH] mtd: call of_platform_populate() for MTD partitions
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Until this change MTD subsystem supported handling partitions only with
10 MTD partitions parsers. That's a specific / limited API designed around
13 Some MTD partitions may however require different handling. They may
14 contain specific data that needs to be parsed and somehow extracted. For
15 that purpose MTD subsystem should allow binding of standard platform
18 An example can be U-Boot (sub)partition with environment variables.
19 There exist a "u-boot,env" DT binding for MTD (sub)partition that
20 requires an NVMEM driver.
22 Ref: 5db1c2dbc04c ("dt-bindings: nvmem: add U-Boot environment variables binding")
23 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
24 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
25 Link: https://lore.kernel.org/linux-mtd/20220510131259.555-1-zajec5@gmail.com
27 drivers/mtd/mtdpart.c | 9 +++++++++
28 1 file changed, 9 insertions(+)
30 --- a/drivers/mtd/mtdpart.c
31 +++ b/drivers/mtd/mtdpart.c
33 #include <linux/mtd/partitions.h>
34 #include <linux/err.h>
36 +#include <linux/of_platform.h>
40 @@ -578,10 +579,16 @@ static int mtd_part_of_parse(struct mtd_
41 struct mtd_part_parser *parser;
42 struct device_node *np;
43 struct property *prop;
46 const char *fixed = "fixed-partitions";
50 + /* Use parent device (controller) if the top level MTD is not registered */
51 + if (!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) && !mtd_is_partition(master))
52 + dev = master->dev.parent;
54 np = mtd_get_of_node(master);
55 if (mtd_is_partition(master))
57 @@ -594,6 +601,7 @@ static int mtd_part_of_parse(struct mtd_
59 ret = mtd_part_do_parse(parser, master, pparts, NULL);
61 + of_platform_populate(np, NULL, NULL, dev);
65 @@ -601,6 +609,7 @@ static int mtd_part_of_parse(struct mtd_
69 + of_platform_populate(np, NULL, NULL, dev);