1 From: Hauke Mehrtens <hauke@hauke-m.de>
2 Subject: mtd: part: add generic parsing of linux,part-probe
4 This moves the linux,part-probe device tree parsing code from
5 physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
6 providing a reference to their device tree node in struct
9 THIS METHOD HAS BEEN DEPRECATED
11 Linux supports "compatible" property in the "partitions" subnode now. It
12 should be used to specify partitions format (and trigger proper parser
15 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
17 Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
18 drivers/mtd/maps/physmap_of.c | 46 +-------------------------
19 drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
20 3 files changed, 62 insertions(+), 45 deletions(-)
22 --- a/Documentation/devicetree/bindings/mtd/nand.txt
23 +++ b/Documentation/devicetree/bindings/mtd/nand.txt
24 @@ -44,6 +44,22 @@ Optional NAND chip properties:
25 used by the upper layers, and you want to make your NAND
26 as reliable as possible.
28 +- linux,part-probe: list of name as strings of the partition parser
29 + which should be used to parse the partition table.
30 + They will be tried in the specified ordering and
31 + the next one will be used if the previous one
34 + Example: linux,part-probe = "cmdlinepart", "ofpart";
36 + This is also the default value, which will be used
37 + if this attribute is not specified. It could be
38 + that the flash driver in use overwrote the default
39 + value and uses some other default.
41 + Possible values are: bcm47xxpart, afs, ar7part,
42 + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
44 The ECC strength and ECC step size properties define the correction capability
45 of a controller. Together, they say a controller can correct "{strength} bit
46 errors per {size} bytes".
47 --- a/drivers/mtd/maps/physmap_of_core.c
48 +++ b/drivers/mtd/maps/physmap_of_core.c
49 @@ -114,37 +114,9 @@ static struct mtd_info *obsolete_probe(s
50 static const char * const part_probe_types_def[] = {
51 "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
53 -static const char * const *of_get_probes(struct device_node *dp)
58 - count = of_property_count_strings(dp, "linux,part-probe");
60 - return part_probe_types_def;
62 - res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
66 - count = of_property_read_string_array(dp, "linux,part-probe", res,
74 -static void of_free_probes(const char * const *probes)
76 - if (probes != part_probe_types_def)
80 static const struct of_device_id of_flash_match[];
81 static int of_flash_probe(struct platform_device *dev)
83 - const char * const *part_probe_types;
84 const struct of_device_id *match;
85 struct device_node *dp = dev->dev.of_node;
87 @@ -310,14 +282,8 @@ static int of_flash_probe(struct platfor
89 info->cmtd->dev.parent = &dev->dev;
90 mtd_set_of_node(info->cmtd, dp);
91 - part_probe_types = of_get_probes(dp);
92 - if (!part_probe_types) {
96 - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
97 + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
99 - of_free_probes(part_probe_types);
103 --- a/drivers/mtd/mtdpart.c
104 +++ b/drivers/mtd/mtdpart.c
106 #include <linux/kmod.h>
107 #include <linux/mtd/mtd.h>
108 #include <linux/mtd/partitions.h>
109 +#include <linux/of.h>
110 #include <linux/err.h>
111 #include <linux/of.h>
113 @@ -844,6 +845,37 @@ void deregister_mtd_parser(struct mtd_pa
115 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
117 +#include <linux/version.h>
120 + * Parses the linux,part-probe device tree property.
121 + * When a non null value is returned it has to be freed with kfree() by
124 +static const char * const *of_get_probes(struct device_node *dp)
129 + count = of_property_count_strings(dp, "linux,part-probe");
133 + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
137 + count = of_property_read_string_array(dp, "linux,part-probe", res,
142 + pr_warn("Support for the generic \"linux,part-probe\" has been deprecated and will be removed soon");
143 + BUILD_BUG_ON(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0));
149 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
150 * are changing this array!
151 @@ -993,6 +1025,13 @@ int parse_mtd_partitions(struct mtd_info
152 struct mtd_partitions pparts = { };
153 struct mtd_part_parser *parser;
155 + const char *const *types_of = NULL;
157 + if (mtd_get_of_node(master)) {
158 + types_of = of_get_probes(mtd_get_of_node(master));
159 + if (types_of != NULL)
164 types = mtd_is_partition(master) ? default_subpartition_types :
165 @@ -1034,6 +1073,7 @@ int parse_mtd_partitions(struct mtd_info