layerscape: add ls2088ardb device support
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 1239-mtd-extend-physmap_of-to-let-the-device-tree-specify.patch
1 From 6b54054c4053215fe4add195c67daca9a466ba92 Mon Sep 17 00:00:00 2001
2 From: "ying.zhang" <ying.zhang22455@nxp.com>
3 Date: Fri, 23 Dec 2016 22:21:22 +0800
4 Subject: [PATCH] mtd: extend physmap_of to let the device tree specify the
5 parition probe
6
7 This is to support custom partitioning schemes for embedded PPC. To use
8 define your own mtd_part_parser and then add something like:
9 linux,part-probe = "my_probe", "cmdlinepart";
10 To the board's dts file.
11
12 If linux,part-probe is not specified then this behaves the same as before.
13
14 Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
15 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
16 ---
17 drivers/mtd/maps/physmap_of.c | 46 ++++++++++++++++++++++++++++++++++++++++-
18 1 file changed, 45 insertions(+), 1 deletion(-)
19
20 diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
21 index fef1d1b..e46b4e9 100644
22 --- a/drivers/mtd/maps/physmap_of.c
23 +++ b/drivers/mtd/maps/physmap_of.c
24 @@ -112,9 +112,47 @@ static struct mtd_info *obsolete_probe(struct platform_device *dev,
25 static const char * const part_probe_types_def[] = {
26 "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
27
28 +static const char * const *of_get_probes(struct device_node *dp)
29 +{
30 + const char *cp;
31 + int cplen;
32 + unsigned int l;
33 + unsigned int count;
34 + const char **res;
35 +
36 + cp = of_get_property(dp, "linux,part-probe", &cplen);
37 + if (cp == NULL)
38 + return part_probe_types_def;
39 +
40 + count = 0;
41 + for (l = 0; l != cplen; l++)
42 + if (cp[l] == 0)
43 + count++;
44 +
45 + res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
46 + if (!res)
47 + return NULL;
48 + count = 0;
49 + while (cplen > 0) {
50 + res[count] = cp;
51 + l = strlen(cp) + 1;
52 + cp += l;
53 + cplen -= l;
54 + count++;
55 + }
56 + return res;
57 +}
58 +
59 +static void of_free_probes(const char * const *probes)
60 +{
61 + if (probes != part_probe_types_def)
62 + kfree(probes);
63 +}
64 +
65 static const struct of_device_id of_flash_match[];
66 static int of_flash_probe(struct platform_device *dev)
67 {
68 + const char * const *part_probe_types;
69 const struct of_device_id *match;
70 struct device_node *dp = dev->dev.of_node;
71 struct resource res;
72 @@ -273,8 +311,14 @@ static int of_flash_probe(struct platform_device *dev)
73 goto err_out;
74
75 ppdata.of_node = dp;
76 - mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
77 + part_probe_types = of_get_probes(dp);
78 + if (!part_probe_types) {
79 + err = -ENOMEM;
80 + goto err_out;
81 + }
82 + mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
83 NULL, 0);
84 + of_free_probes(part_probe_types);
85
86 kfree(mtd_list);
87
88 --
89 1.7.9.5
90