kernel: backport mtd support for subpartitions in DT
[openwrt/openwrt.git] / target / linux / generic / pending-4.9 / 401-mtd-add-support-for-different-partition-parser-types.patch
1 From: Gabor Juhos <juhosg@openwrt.org>
2 Subject: mtd: add support for different partition parser types
3
4 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
5 ---
6 drivers/mtd/mtdpart.c | 56 ++++++++++++++++++++++++++++++++++++++++
7 include/linux/mtd/partitions.h | 11 ++++++++
8 2 files changed, 67 insertions(+)
9
10 --- a/drivers/mtd/mtdpart.c
11 +++ b/drivers/mtd/mtdpart.c
12 @@ -1115,6 +1115,62 @@ void mtd_part_parser_cleanup(struct mtd_
13 }
14 }
15
16 +static struct mtd_part_parser *
17 +get_partition_parser_by_type(enum mtd_parser_type type,
18 + struct mtd_part_parser *start)
19 +{
20 + struct mtd_part_parser *p, *ret = NULL;
21 +
22 + spin_lock(&part_parser_lock);
23 +
24 + p = list_prepare_entry(start, &part_parsers, list);
25 + if (start)
26 + mtd_part_parser_put(start);
27 +
28 + list_for_each_entry_continue(p, &part_parsers, list) {
29 + if (p->type == type && try_module_get(p->owner)) {
30 + ret = p;
31 + break;
32 + }
33 + }
34 +
35 + spin_unlock(&part_parser_lock);
36 +
37 + return ret;
38 +}
39 +
40 +int parse_mtd_partitions_by_type(struct mtd_info *master,
41 + enum mtd_parser_type type,
42 + const struct mtd_partition **pparts,
43 + struct mtd_part_parser_data *data)
44 +{
45 + struct mtd_part_parser *prev = NULL;
46 + int ret = 0;
47 +
48 + while (1) {
49 + struct mtd_part_parser *parser;
50 +
51 + parser = get_partition_parser_by_type(type, prev);
52 + if (!parser)
53 + break;
54 +
55 + ret = (*parser->parse_fn)(master, pparts, data);
56 +
57 + if (ret > 0) {
58 + mtd_part_parser_put(parser);
59 + printk(KERN_NOTICE
60 + "%d %s partitions found on MTD device %s\n",
61 + ret, parser->name, master->name);
62 + break;
63 + }
64 +
65 + prev = parser;
66 + }
67 +
68 + return ret;
69 +}
70 +EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
71 +
72 int mtd_is_partition(const struct mtd_info *mtd)
73 {
74 struct mtd_part *part;
75 --- a/include/linux/mtd/partitions.h
76 +++ b/include/linux/mtd/partitions.h
77 @@ -68,11 +68,14 @@ struct mtd_part_parser_data {
78 unsigned long origin;
79 };
80
81 -
82 /*
83 * Functions dealing with the various ways of partitioning the space
84 */
85
86 +enum mtd_parser_type {
87 + MTD_PARSER_TYPE_DEVICE = 0,
88 +};
89 +
90 struct mtd_part_parser {
91 struct list_head list;
92 struct module *owner;
93 @@ -81,6 +84,7 @@ struct mtd_part_parser {
94 int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
95 struct mtd_part_parser_data *);
96 void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
97 + enum mtd_parser_type type;
98 };
99
100 /* Container for passing around a set of parsed partitions */
101 @@ -113,4 +117,9 @@ uint64_t mtd_get_device_size(const struc
102 extern void __weak arch_split_mtd_part(struct mtd_info *master,
103 const char *name, int offset, int size);
104
105 +int parse_mtd_partitions_by_type(struct mtd_info *master,
106 + enum mtd_parser_type type,
107 + const struct mtd_partition **pparts,
108 + struct mtd_part_parser_data *data);
109 +
110 #endif