kernel: update U-Boot NVMEM driver
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 412-v5.19-mtd-call-of_platform_populate-for-MTD-partitions.patch
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Until this change MTD subsystem supported handling partitions only with
10 MTD partitions parsers. That's a specific / limited API designed around
11 partitions.
12
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
16 drivers.
17
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.
21
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
26 ---
27 drivers/mtd/mtdpart.c | 9 +++++++++
28 1 file changed, 9 insertions(+)
29
30 --- a/drivers/mtd/mtdpart.c
31 +++ b/drivers/mtd/mtdpart.c
32 @@ -17,6 +17,7 @@
33 #include <linux/mtd/partitions.h>
34 #include <linux/err.h>
35 #include <linux/of.h>
36 +#include <linux/of_platform.h>
37
38 #include "mtdcore.h"
39
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;
44 + struct device *dev;
45 const char *compat;
46 const char *fixed = "fixed-partitions";
47 int ret, err = 0;
48
49 + dev = &master->dev;
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;
53 +
54 np = mtd_get_of_node(master);
55 if (mtd_is_partition(master))
56 of_node_get(np);
57 @@ -594,6 +601,7 @@ static int mtd_part_of_parse(struct mtd_
58 continue;
59 ret = mtd_part_do_parse(parser, master, pparts, NULL);
60 if (ret > 0) {
61 + of_platform_populate(np, NULL, NULL, dev);
62 of_node_put(np);
63 return ret;
64 }
65 @@ -601,6 +609,7 @@ static int mtd_part_of_parse(struct mtd_
66 if (ret < 0 && !err)
67 err = ret;
68 }
69 + of_platform_populate(np, NULL, NULL, dev);
70 of_node_put(np);
71
72 /*