From patchwork Thu Jun 16 04:41:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 884062 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5G4gE0U011916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 16 Jun 2011 04:42:34 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QX4P3-00061R-0k; Thu, 16 Jun 2011 04:42:01 +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 1QX4P2-0001A6-CL; Thu, 16 Jun 2011 04:42:00 +0000 Received: from mail-pz0-f49.google.com ([209.85.210.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QX4Oi-00016h-Rf for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2011 04:41:42 +0000 Received: by pzk28 with SMTP id 28so956444pzk.36 for ; Wed, 15 Jun 2011 21:41:38 -0700 (PDT) Received: by 10.68.19.36 with SMTP id b4mr270354pbe.213.1308199298760; Wed, 15 Jun 2011 21:41:38 -0700 (PDT) Received: from localhost (S01060002b3d79728.cg.shawcable.net [70.72.87.49]) by mx.google.com with ESMTPS id 10sm637436pbk.29.2011.06.15.21.41.37 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2011 21:41:37 -0700 (PDT) Received: from [127.0.1.1] (localhost [127.0.0.1]) by localhost (Postfix) with ESMTP id 455ED180808; Wed, 15 Jun 2011 22:41:36 -0600 (MDT) Subject: [RFC PATCH 02/11] of/address: Add of_find_matching_node_by_address helper 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:36 -0600 Message-ID: <20110616044130.29371.31242.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_004141_183688_EF86B234 X-CRM114-Status: GOOD ( 15.43 ) 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 [209.85.210.49 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 (demeter2.kernel.org [140.211.167.43]); Thu, 16 Jun 2011 04:42:35 +0000 (UTC) of_find_matching_node_by_address() can be used to find a device tree node for a device at a specific address. Signed-off-by: Grant Likely --- drivers/of/address.c | 18 ++++++++++++++++++ include/linux/of_address.h | 4 ++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index b4559c5..da1f4b9 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -577,6 +577,24 @@ int of_address_to_resource(struct device_node *dev, int index, } EXPORT_SYMBOL_GPL(of_address_to_resource); +struct device_node *of_find_matching_node_by_address(struct device_node *from, + const struct of_device_id *matches, + u64 base_address) +{ + struct device_node *dn = of_find_matching_node(from, matches); + struct resource res; + + while (dn) { + if (of_address_to_resource(dn, 0, &res)) + continue; + if (res.start == base_address) + return dn; + dn = of_find_matching_node(dn, matches); + } + + return NULL; +} + /** * of_iomap - Maps the memory mapped IO for a given device_node diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 2feda6e..bdfc20d 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -6,6 +6,10 @@ extern u64 of_translate_address(struct device_node *np, const __be32 *addr); extern int of_address_to_resource(struct device_node *dev, int index, struct resource *r); +extern struct device_node *of_find_matching_node_by_address( + struct device_node *from, + const struct of_device_id *matches, + u64 base_address); extern void __iomem *of_iomap(struct device_node *device, int index); /* Extract an address from a device, returns the region size and