Skip to content

Commit bcdf031

Browse files
Rafał Miłeckimiquelraynal
authored andcommitted
mtd: call of_platform_populate() for MTD partitions
Until this change MTD subsystem supported handling partitions only with MTD partitions parsers. That's a specific / limited API designed around partitions. Some MTD partitions may however require different handling. They may contain specific data that needs to be parsed and somehow extracted. For that purpose MTD subsystem should allow binding of standard platform drivers. An example can be U-Boot (sub)partition with environment variables. There exist a "u-boot,env" DT binding for MTD (sub)partition that requires an NVMEM driver. Ref: 5db1c2d ("dt-bindings: nvmem: add U-Boot environment variables binding") Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220510131259.555-1-zajec5@gmail.com
1 parent 43823c5 commit bcdf031

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/mtd/mtdpart.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/mtd/partitions.h>
1818
#include <linux/err.h>
1919
#include <linux/of.h>
20+
#include <linux/of_platform.h>
2021

2122
#include "mtdcore.h"
2223

@@ -577,10 +578,16 @@ static int mtd_part_of_parse(struct mtd_info *master,
577578
struct mtd_part_parser *parser;
578579
struct device_node *np;
579580
struct property *prop;
581+
struct device *dev;
580582
const char *compat;
581583
const char *fixed = "fixed-partitions";
582584
int ret, err = 0;
583585

586+
dev = &master->dev;
587+
/* Use parent device (controller) if the top level MTD is not registered */
588+
if (!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) && !mtd_is_partition(master))
589+
dev = master->dev.parent;
590+
584591
np = mtd_get_of_node(master);
585592
if (mtd_is_partition(master))
586593
of_node_get(np);
@@ -593,13 +600,15 @@ static int mtd_part_of_parse(struct mtd_info *master,
593600
continue;
594601
ret = mtd_part_do_parse(parser, master, pparts, NULL);
595602
if (ret > 0) {
603+
of_platform_populate(np, NULL, NULL, dev);
596604
of_node_put(np);
597605
return ret;
598606
}
599607
mtd_part_parser_put(parser);
600608
if (ret < 0 && !err)
601609
err = ret;
602610
}
611+
of_platform_populate(np, NULL, NULL, dev);
603612
of_node_put(np);
604613

605614
/*

0 commit comments

Comments
 (0)