aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ofpart.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2011-05-29 17:26:17 -0400
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2011-09-11 08:02:12 -0400
commitfbcf62a32be1e897a1d730af430758f881f8ef35 (patch)
tree43a99117f7857424f1f57b2dcf2e62ecd2d7ced0 /drivers/mtd/ofpart.c
parent628376fb5369c353680f03f47705b1437ff8de80 (diff)
mtd: physmap_of: move parse_obsolete_partitions to become separate parser
Move parse_obsolete_partitions() to ofpart.c and register it as an ofoldpart partitions parser. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>
Diffstat (limited to 'drivers/mtd/ofpart.c')
-rw-r--r--drivers/mtd/ofpart.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index 24007f3c2c2f..41c451842fd2 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -93,9 +93,82 @@ static struct mtd_part_parser ofpart_parser = {
93 .name = "ofpart", 93 .name = "ofpart",
94}; 94};
95 95
96static int parse_ofoldpart_partitions(struct mtd_info *master,
97 struct mtd_partition **pparts,
98 struct mtd_part_parser_data *data)
99{
100 struct device_node *dp;
101 int i, plen, nr_parts;
102 const struct {
103 __be32 offset, len;
104 } *part;
105 const char *names;
106
107 if (!data)
108 return 0;
109
110 dp = data->of_node;
111 if (!dp)
112 return 0;
113
114 part = of_get_property(dp, "partitions", &plen);
115 if (!part)
116 return 0; /* No partitions found */
117
118 pr_warning("Device tree uses obsolete partition map binding: %s\n",
119 dp->full_name);
120
121 nr_parts = plen / sizeof(part[0]);
122
123 *pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL);
124 if (!pparts)
125 return -ENOMEM;
126
127 names = of_get_property(dp, "partition-names", &plen);
128
129 for (i = 0; i < nr_parts; i++) {
130 (*pparts)[i].offset = be32_to_cpu(part->offset);
131 (*pparts)[i].size = be32_to_cpu(part->len) & ~1;
132 /* bit 0 set signifies read only partition */
133 if (be32_to_cpu(part->len) & 1)
134 (*pparts)[i].mask_flags = MTD_WRITEABLE;
135
136 if (names && (plen > 0)) {
137 int len = strlen(names) + 1;
138
139 (*pparts)[i].name = (char *)names;
140 plen -= len;
141 names += len;
142 } else {
143 (*pparts)[i].name = "unnamed";
144 }
145
146 part++;
147 }
148
149 return nr_parts;
150}
151
152static struct mtd_part_parser ofoldpart_parser = {
153 .owner = THIS_MODULE,
154 .parse_fn = parse_ofoldpart_partitions,
155 .name = "ofoldpart",
156};
157
96static int __init ofpart_parser_init(void) 158static int __init ofpart_parser_init(void)
97{ 159{
98 return register_mtd_parser(&ofpart_parser); 160 int rc;
161 rc = register_mtd_parser(&ofpart_parser);
162 if (rc)
163 goto out;
164
165 rc = register_mtd_parser(&ofoldpart_parser);
166 if (!rc)
167 return 0;
168
169 deregister_mtd_parser(&ofoldpart_parser);
170out:
171 return rc;
99} 172}
100 173
101module_init(ofpart_parser_init); 174module_init(ofpart_parser_init);