mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/9] of: partitions: factor out function to parse a single partition
Date: Wed, 10 Jul 2013 12:52:02 +0200	[thread overview]
Message-ID: <1373453528-3723-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1373453528-3723-1-git-send-email-s.hauer@pengutronix.de>

To make it usable for other code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/partition.c | 58 ++++++++++++++++++++++++++++----------------------
 include/of.h           |  1 +
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index e4b7d1e..d69251e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -23,44 +23,52 @@
 #include <linux/mtd/mtd.h>
 #include <nand.h>
 
-int of_parse_partitions(struct cdev *cdev, struct device_node *node)
+struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 {
-	struct device_node *n;
 	const char *partname;
 	char *filename;
+	struct cdev *new;
+	const __be32 *reg;
+	unsigned long offset, size;
+	const char *name;
+	int len;
+	unsigned long flags = 0;
 
-	for_each_child_of_node(node, n) {
-		const __be32 *reg;
-		unsigned long offset, size;
-		const char *name;
-		int len;
-		unsigned long flags = 0;
+	reg = of_get_property(node, "reg", &len);
+	if (!reg)
+		return NULL;
+
+	offset = be32_to_cpu(reg[0]);
+	size = be32_to_cpu(reg[1]);
+
+	partname = of_get_property(node, "label", &len);
+	if (!partname)
+		partname = of_get_property(node, "name", &len);
+	name = (char *)partname;
 
-		reg = of_get_property(n, "reg", &len);
-		if (!reg)
-			continue;
+	debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
 
-		offset = be32_to_cpu(reg[0]);
-		size = be32_to_cpu(reg[1]);
+	if (of_get_property(node, "read-only", &len))
+		flags = DEVFS_PARTITION_READONLY;
 
-		partname = of_get_property(n, "label", &len);
-		if (!partname)
-			partname = of_get_property(n, "name", &len);
-		name = (char *)partname;
+	filename = asprintf("%s.%s", cdev->name, partname);
 
-		debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
+	new = devfs_add_partition(cdev->name, offset, size, flags, filename);
 
-		if (of_get_property(n, "read-only", &len))
-			flags = DEVFS_PARTITION_READONLY;
+	if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
+		dev_add_bb_dev(filename, NULL);
 
-		filename = asprintf("%s.%s", cdev->name, partname);
+	free(filename);
 
-		devfs_add_partition(cdev->name, offset, size, flags, filename);
+	return new;
+}
 
-		if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
-			dev_add_bb_dev(filename, NULL);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node)
+{
+	struct device_node *n;
 
-		free(filename);
+	for_each_child_of_node(node, n) {
+		of_parse_partition(cdev, n);
 	}
 
 	return 0;
diff --git a/include/of.h b/include/of.h
index 0d8f6b3..710383c 100644
--- a/include/of.h
+++ b/include/of.h
@@ -221,6 +221,7 @@ extern int of_platform_populate(struct device_node *root,
 				struct device_d *parent);
 extern struct device_d *of_find_device_by_node(struct device_node *np);
 
+struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-07-10 10:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
2013-07-10 10:52 ` [PATCH 1/9] devfs: let devfs_add_partition return the new partition Sascha Hauer
2013-07-10 10:52 ` [PATCH 2/9] of: export of_default_bus_match_table Sascha Hauer
2013-07-10 10:52 ` Sascha Hauer [this message]
2013-07-10 10:52 ` [PATCH 4/9] cdev: introduce partition names Sascha Hauer
2013-07-10 10:52 ` [PATCH 5/9] cdev: allow to open a struct cdev Sascha Hauer
2013-07-10 10:52 ` [PATCH 6/9] cdev: add device_find_partition Sascha Hauer
2013-07-10 10:52 ` [PATCH 7/9] mci: set partnames of eMMC boot partitions Sascha Hauer
2013-07-10 10:52 ` [PATCH 8/9] Add configurability via devicetree Sascha Hauer
2013-07-10 13:17   ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 13:34     ` Sascha Hauer
2013-07-10 14:33       ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 14:42         ` Sascha Hauer
2013-07-10 15:50           ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 20:17             ` Sascha Hauer
2013-07-15 10:11               ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-16 14:27                 ` Sascha Hauer
2013-07-10 10:52 ` [PATCH 9/9] ARM: i.MX Datamodul edmqx6: configure environment from devicetree Sascha Hauer
2013-07-11  7:37 ` [PATCH] Allow configuration from the devicetree Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373453528-3723-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox