aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ofpart.c
diff options
context:
space:
mode:
authorScott Wood <scottwood@freescale.com>2008-01-15 18:54:43 -0500
committerDavid Woodhouse <dwmw2@infradead.org>2008-02-03 02:06:48 -0500
commit9a310d21196f38f6ad0ad146057548653e495c09 (patch)
treeea623f5d0f8712bd300e6bebf5695a3e124cb9cb /drivers/mtd/ofpart.c
parentc0d2a48a65a8fc286aa84871cfc20d8c10dbf492 (diff)
[MTD] Factor out OF partition support from the NOR driver.
Signed-off-by: Scott Wood <scottwood@freescale.com> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'drivers/mtd/ofpart.c')
-rw-r--r--drivers/mtd/ofpart.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
new file mode 100644
index 000000000000..f86e06934cd8
--- /dev/null
+++ b/drivers/mtd/ofpart.c
@@ -0,0 +1,74 @@
1/*
2 * Flash partitions described by the OF (or flattened) device tree
3 *
4 * Copyright (C) 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.com>
6 *
7 * Revised to handle newer style flash binding by:
8 * Copyright (C) 2007 David Gibson, IBM Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/of.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/partitions.h>
21
22int __devinit of_mtd_parse_partitions(struct device *dev,
23 struct mtd_info *mtd,
24 struct device_node *node,
25 struct mtd_partition **pparts)
26{
27 const char *partname;
28 struct device_node *pp;
29 int nr_parts, i;
30
31 /* First count the subnodes */
32 pp = NULL;
33 nr_parts = 0;
34 while ((pp = of_get_next_child(node, pp)))
35 nr_parts++;
36
37 if (nr_parts == 0)
38 return 0;
39
40 *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL);
41 if (!*pparts)
42 return -ENOMEM;
43
44 pp = NULL;
45 i = 0;
46 while ((pp = of_get_next_child(node, pp))) {
47 const u32 *reg;
48 int len;
49
50 reg = of_get_property(pp, "reg", &len);
51 if (!reg || (len != 2 * sizeof(u32))) {
52 of_node_put(pp);
53 dev_err(dev, "Invalid 'reg' on %s\n", node->full_name);
54 kfree(*pparts);
55 *pparts = NULL;
56 return -EINVAL;
57 }
58 (*pparts)[i].offset = reg[0];
59 (*pparts)[i].size = reg[1];
60
61 partname = of_get_property(pp, "label", &len);
62 if (!partname)
63 partname = of_get_property(pp, "name", &len);
64 (*pparts)[i].name = (char *)partname;
65
66 if (of_get_property(pp, "read-only", &len))
67 (*pparts)[i].mask_flags = MTD_WRITEABLE;
68
69 i++;
70 }
71
72 return nr_parts;
73}
74EXPORT_SYMBOL(of_mtd_parse_partitions);