Skip to contentSkip to conversation

mtd: Factor out OF partition support from the NOR driver.

PATCH In review Scott Wood 2 participants 2 messages Jan 11, 2008 – Jan 14, 2008 Memory technology devices (MTD)

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 2/3 mtd: Factor out OF partition support from the NOR driver.

---
 drivers/mtd/Kconfig            |    8 ++++
 drivers/mtd/Makefile           |    1 +
 drivers/mtd/maps/physmap_of.c  |   89 ++++++++++++----------------------------
 drivers/mtd/ofpart.c           |   70 +++++++++++++++++++++++++++++++
 include/linux/mtd/partitions.h |    9 ++++-
 5 files changed, 114 insertions(+), 63 deletions(-)
 create mode 100644 drivers/mtd/ofpart.c
drivers/mtd/Kconfig +8 -0
index 661eac0..e850334 100644
@@ -150,6 +150,14 @@ config MTD_AFS_PARTS
 	  for your particular device. It won't happen automatically. The
 	  'armflash' map driver (CONFIG_MTD_ARMFLASH) does this, for example.
 
+config MTD_OF_PARTS
+	tristate "Flash partition map based on OF description"
+	depends on PPC_OF && MTD_PARTITIONS
+	help
+	  This provides a partition parsing function which derives
+	  the partition map from the children of the flash node,
+	  as described in Documentation/powerpc/booting-without-of.txt.
+
 comment "User Modules And Translation Layers"
 
 config MTD_CHAR
drivers/mtd/Makefile +1 -0
index 7f0b04b..538e33d 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT)	+= mtdconcat.o
 obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
 obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
 obj-$(CONFIG_MTD_AFS_PARTS)	+= afs.o
+obj-$(CONFIG_MTD_OF_PARTS)      += ofpart.o
 
 # 'Users' - code which presents functionality to userspace.
 obj-$(CONFIG_MTD_CHAR)		+= mtdchar.o
drivers/mtd/maps/physmap_of.c +27 -62

111 lines not on this page · raw message

drivers/mtd/ofpart.c new file +70 -0

70 lines not on this page · raw message

include/linux/mtd/partitions.h +8 -1
index da6b3d6..7c37d7e 100644
@@ -71,5 +71,12 @@ extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
 
 #define put_partition_parser(p) do { module_put((p)->owner); } while(0)
 
-#endif
+struct device;
+struct device_node;
+
+int __devinit of_mtd_parse_partitions(struct device *dev,
+                                      struct mtd_info *mtd,
+                                      struct device_node *node,
+                                      struct mtd_partition **pparts);
 
+#endif
Signature · 1 line
1.5.3.8
#1 lore raw

Hi Scott,

drivers/mtd/ofpart.c line 33

Quoted 7 lines · On Fri, 11 Jan 2008 14:43:16 -0600 Scott Wood <[email protected]> wrote:

+++ b/drivers/mtd/ofpart.c

drivers/mtd/ofpart.c new file +3 -0
+int __devinit of_mtd_parse_partitions(struct device *dev,
 
+	nr_parts = 0;
+	for (pp = node->child; pp; pp = pp->sibling)

for_each_child_of_node(node, pp)

drivers/mtd/ofpart.c line 44

Quoted 4 lines
drivers/mtd/ofpart.c new file +3 -0
+		nr_parts++;
 
+	for (pp = of_get_next_child(node, NULL), i = 0; pp; 
+	     pp = of_get_next_child(node, pp), i++) {
	i = 0;
	for_each_child_of_node(node, pp) {

drivers/mtd/ofpart.c line 49

Quoted 5 lines
drivers/mtd/ofpart.c new file +5 -0
+		const u32 *reg;
+		int len;
+
+		reg = of_get_property(pp, "reg", &len);
+		if (!reg || (len != 2*sizeof(u32))) {

Spaces around '*'.

Quoted 6 lines
drivers/mtd/ofpart.c new file +6 -0
+			of_node_put(pp);
+			dev_err(dev, "Invalid 'reg' on %s\n", node->full_name);
+			kfree(*pparts);
+			*pparts = NULL;
+			return -EINVAL;
+		}

drivers/mtd/ofpart.c line 65

Quoted 10 lines
drivers/mtd/ofpart.c new file +10 -0
+		(*pparts)[i].offset = reg[0];
+		(*pparts)[i].size = reg[1];
+
+		partname = of_get_property(pp, "label", &len);
+		if (!partname)
+			partname = of_get_property(pp, "name", &len);
+		(*pparts)[i].name = (char *)partname;
+
+		if (of_get_property(pp, "read-only", &len))
+			(*pparts)[i].mask_flags = MTD_WRITEABLE;
		i++;
Quoted 1 line
(quoted diff) +1 -0
+	}
Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/