kernel: update kernel 4.4 to version 4.4.50
[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 --- a/drivers/mtd/maps/physmap_of.c
21 +++ b/drivers/mtd/maps/physmap_of.c
22 @@ -112,9 +112,47 @@ static struct mtd_info *obsolete_probe(s
23 static const char * const part_probe_types_def[] = {
24 "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
25
26 +static const char * const *of_get_probes(struct device_node *dp)
27 +{
28 + const char *cp;
29 + int cplen;
30 + unsigned int l;
31 + unsigned int count;
32 + const char **res;
33 +
34 + cp = of_get_property(dp, "linux,part-probe", &cplen);
35 + if (cp == NULL)
36 + return part_probe_types_def;
37 +
38 + count = 0;
39 + for (l = 0; l != cplen; l++)
40 + if (cp[l] == 0)
41 + count++;
42 +
43 + res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
44 + if (!res)
45 + return NULL;
46 + count = 0;
47 + while (cplen > 0) {
48 + res[count] = cp;
49 + l = strlen(cp) + 1;
50 + cp += l;
51 + cplen -= l;
52 + count++;
53 + }
54 + return res;
55 +}
56 +
57 +static void of_free_probes(const char * const *probes)
58 +{
59 + if (probes != part_probe_types_def)
60 + kfree(probes);
61 +}
62 +
63 static const struct of_device_id of_flash_match[];
64 static int of_flash_probe(struct platform_device *dev)
65 {
66 + const char * const *part_probe_types;
67 const struct of_device_id *match;
68 struct device_node *dp = dev->dev.of_node;
69 struct resource res;
70 @@ -273,8 +311,14 @@ static int of_flash_probe(struct platfor
71 goto err_out;
72
73 ppdata.of_node = dp;
74 - mtd_device_parse_register(info->cmtd, part_probe_types_def, &ppdata,
75 + part_probe_types = of_get_probes(dp);
76 + if (!part_probe_types) {
77 + err = -ENOMEM;
78 + goto err_out;
79 + }
80 + mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
81 NULL, 0);
82 + of_free_probes(part_probe_types);
83
84 kfree(mtd_list);
85