From patchwork Thu Jun 16 04:41:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 884132 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5G4gq29008491 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 16 Jun 2011 04:43:13 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QX4Pf-0006qp-59; Thu, 16 Jun 2011 04:42:39 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QX4Pe-0001H1-HG; Thu, 16 Jun 2011 04:42:38 +0000 Received: from mail-pv0-f177.google.com ([74.125.83.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QX4P2-00019v-RJ for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2011 04:42:02 +0000 Received: by pvh11 with SMTP id 11so1012571pvh.36 for ; Wed, 15 Jun 2011 21:41:57 -0700 (PDT) Received: by 10.68.1.137 with SMTP id 9mr231351pbm.475.1308199317845; Wed, 15 Jun 2011 21:41:57 -0700 (PDT) Received: from localhost (S01060002b3d79728.cg.shawcable.net [70.72.87.49]) by mx.google.com with ESMTPS id 10sm639843pbk.13.2011.06.15.21.41.56 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2011 21:41:57 -0700 (PDT) Received: from [127.0.1.1] (localhost [127.0.0.1]) by localhost (Postfix) with ESMTP id 68F29180808; Wed, 15 Jun 2011 22:41:55 -0600 (MDT) Subject: [RFC PATCH 04/11] dt: add of_platform_populate() for creating device from the device tree To: Nicolas Pitre , Russell King , Arnd Bergmann , devicetree-discuss@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org From: Grant Likely Date: Wed, 15 Jun 2011 22:41:55 -0600 Message-ID: <20110616044150.29371.19347.stgit@ponder> In-Reply-To: <20110616042653.29371.2052.stgit@ponder> References: <20110616042653.29371.2052.stgit@ponder> User-Agent: StGit/0.15 MIME-Version: 1.0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110616_004201_449653_4BC01A69 X-CRM114-Status: GOOD ( 21.91 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.83.177 listed in list.dnswl.org] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 16 Jun 2011 04:43:13 +0000 (UTC) of_platform_populate() is similar to of_platform_bus_probe() except that it strictly enforces that all device nodes must have a compatible property, and it can be used to register devices (not buses) which are children of the root node. Signed-off-by: Grant Likely --- drivers/of/platform.c | 54 +++++++++++++++++++++++++++++++++++++++--- include/linux/of_platform.h | 3 ++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 63d3cb7..9b785be 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -221,19 +221,26 @@ EXPORT_SYMBOL(of_platform_device_create); */ static int of_platform_bus_create(struct device_node *bus, const struct of_device_id *matches, - struct device *parent) + struct device *parent, bool strict) { struct device_node *child; struct platform_device *dev; int rc = 0; + /* Make sure it has a compatible property */ + if (strict && (!of_get_property(bus, "compatible", NULL))) { + pr_debug("%s() - skipping %s, no compatible prop\n", + __func__, bus->full_name); + return 0; + } + dev = of_platform_device_create(bus, NULL, parent); if (!dev || !of_match_node(matches, bus)) return 0; for_each_child_of_node(bus, child) { pr_debug(" create child: %s\n", child->full_name); - rc = of_platform_bus_create(child, matches, &dev->dev); + rc = of_platform_bus_create(child, matches, &dev->dev, strict); if (rc) { of_node_put(child); break; @@ -267,11 +274,11 @@ int of_platform_bus_probe(struct device_node *root, /* Do a self check of bus type, if there's a match, create children */ if (of_match_node(matches, root)) { - rc = of_platform_bus_create(root, matches, parent); + rc = of_platform_bus_create(root, matches, parent, false); } else for_each_child_of_node(root, child) { if (!of_match_node(matches, child)) continue; - rc = of_platform_bus_create(child, matches, parent); + rc = of_platform_bus_create(child, matches, parent, false); if (rc) break; } @@ -280,4 +287,43 @@ int of_platform_bus_probe(struct device_node *root, return rc; } EXPORT_SYMBOL(of_platform_bus_probe); + +/** + * of_platform_populate() - Populate platform_devices from device tree data + * @root: parent of the first level to probe or NULL for the root of the tree + * @matches: match table, NULL to use the default + * @parent: parent to hook devices from, NULL for toplevel + * + * Similar to of_platform_bus_probe(), this function walks the device tree + * and creates devices from nodes. It differs in that it follows the modern + * convention of requiring all device nodes to have a 'compatible' property, + * and it is suitable for creating devices which are children of the root + * node (of_platform_bus_probe will only create children of the root which + * are selected by the @matches argument). + * + * New board support should be using this function instead of + * of_platform_bus_probe(). + * + * Returns 0 on success, < 0 on failure. + */ +int of_platform_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent) +{ + struct device_node *child; + int rc = 0; + + root = root ? of_node_get(root) : of_find_node_by_path("/"); + if (!root) + return -EINVAL; + + for_each_child_of_node(root, child) { + rc = of_platform_bus_create(child, matches, parent, true); + if (rc) + break; + } + + of_node_put(root); + return rc; +} #endif /* !CONFIG_SPARC */ diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index fb51ae3..43c723d 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -55,6 +55,9 @@ extern struct platform_device *of_platform_device_create(struct device_node *np, extern int of_platform_bus_probe(struct device_node *root, const struct of_device_id *matches, struct device *parent); +extern int of_platform_populate(struct device_node *root, + const struct of_device_id *matches, + struct device *parent); #endif /* !CONFIG_SPARC */ #endif /* CONFIG_OF_DEVICE */