2 * Flash partitions described by the OF (or flattened) device tree
4 * Copyright (C) 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.com>
7 * Revised to handle newer style flash binding by:
8 * Copyright (C) 2007 David Gibson, IBM Corporation.
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.
16 #include <linux/module.h>
17 #include <linux/init.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/partitions.h>
22 int __devinit
of_mtd_parse_partitions(struct device
*dev
,
23 struct device_node
*node
,
24 struct mtd_partition
**pparts
)
27 struct device_node
*pp
;
30 /* First count the subnodes */
33 while ((pp
= of_get_next_child(node
, pp
)))
39 *pparts
= kzalloc(nr_parts
* sizeof(**pparts
), GFP_KERNEL
);
45 while ((pp
= of_get_next_child(node
, pp
))) {
49 reg
= of_get_property(pp
, "reg", &len
);
50 if (!reg
|| (len
!= 2 * sizeof(u32
))) {
52 dev_err(dev
, "Invalid 'reg' on %s\n", node
->full_name
);
57 (*pparts
)[i
].offset
= reg
[0];
58 (*pparts
)[i
].size
= reg
[1];
60 partname
= of_get_property(pp
, "label", &len
);
62 partname
= of_get_property(pp
, "name", &len
);
63 (*pparts
)[i
].name
= (char *)partname
;
65 if (of_get_property(pp
, "read-only", &len
))
66 (*pparts
)[i
].mask_flags
= MTD_WRITEABLE
;
73 EXPORT_SYMBOL(of_mtd_parse_partitions
);
75 MODULE_LICENSE("GPL");