From patchwork Tue Jul 28 13:19:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6884841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 059B29F434 for ; Tue, 28 Jul 2015 13:23:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1AA8F2074A for ; Tue, 28 Jul 2015 13:23:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 833272072E for ; Tue, 28 Jul 2015 13:23:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZK4pT-0005VY-B7; Tue, 28 Jul 2015 13:21:59 +0000 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZK4oU-0004uR-DE for linux-arm-kernel@lists.infradead.org; Tue, 28 Jul 2015 13:21:01 +0000 Received: by wicgb10 with SMTP id gb10so156491408wic.1 for ; Tue, 28 Jul 2015 06:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uj1jQIZhYwzqqsuVCHFqyib5SW/n/XyuOh7ZbpmsIzI=; b=fRo3a72FnfzyZKgbe9hFgqi1U2jIDb8yjRCiEKCa8gvZsvNKxVl4nAKvxc9JYFty7u mH1TUoA0RtGgJyAOvuS3SjtrQ+mEjoxMSXTDeYnF4N0FjuGIlI21TfG64b6TEaNYZJ6C aU2wdU/Hqesi2nb3i5UlDzrkt5O0JemuJqoBcov7Z7h7BV8+OcfmDZD7FPuMCbae2XfG /og1Jj0FId3mOhYKH4RtjVtpmP3L2Xv/FCKIcC4y7jjNXz1QNzmQxFt9JxrkU9bT6UBk E5PnSgnZtEqhWgFVj2mEDv2bvHH5bwh29xXSYbIqZH//AWhHnQinJvrGBY6zSue6IY85 XX0Q== X-Received: by 10.180.77.40 with SMTP id p8mr35565048wiw.29.1438089639943; Tue, 28 Jul 2015 06:20:39 -0700 (PDT) Received: from cizrna.lan ([109.72.12.179]) by smtp.gmail.com with ESMTPSA id h9sm33265696wjx.20.2015.07.28.06.20.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2015 06:20:38 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v2 04/22] of/platform: add of_platform_device_find() Date: Tue, 28 Jul 2015 15:19:35 +0200 Message-Id: <1438089593-7696-5-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1438089593-7696-1-git-send-email-tomeu.vizoso@collabora.com> References: <1438089593-7696-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150728_062058_859158_7FCDAE15 X-CRM114-Status: GOOD ( 18.47 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Tomeu Vizoso , Javier Martinez Canillas , Mark Brown , Thierry Reding , Rob Herring , linux-arm-kernel@lists.infradead.org, Grant Likely MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From an arbitrary node in the tree, find the enclosing node that corresponds to a platform device, as registered by of_platform_populate(). This can be used to find out what device needs to be probed so the dependency described by a given node is made available. Signed-off-by: Tomeu Vizoso --- Changes in v2: - Move the logic for finding a platform device from its firmware node to of/platform.c as it's not needed for ACPI nodes. drivers/of/platform.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 1 + 2 files changed, 61 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index ff27494cda8c..89c5cd513027 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -501,6 +501,66 @@ void of_platform_depopulate(struct device *parent) } EXPORT_SYMBOL_GPL(of_platform_depopulate); +static bool of_is_platform(struct device_node *np) +{ + int count; + + count = of_property_count_strings(np, "compatible"); + + /* The node has to have a compatible string */ + if (!count) + return false; + + /* But it cannot be just a simple memory-mapped bus */ + if (count == 1 && of_match_node(of_default_bus_match_table, np)) + return false; + + /* But AMBA devices aren't platform devices */ + if (of_device_is_compatible(np, "arm,primecell")) + return false; + + /* Node is immediately below root */ + if (!np->parent || !np->parent->parent) + return true; + + /* If it's a node in a simple memory-mapped bus */ + if (of_match_node(of_default_bus_match_table, np->parent)) + return true; + + return false; +} + +/** + * of_platform_device_find() - Find nearest ancestor that is a platform device + * @np: node to find platform device for + * + * Walks the tree up and finds the closest ancestor that has match data and + * either is at the root of the tree or is a child of a simple memory mapped + * bus. + * + * Returns such a device, or NULL if none could be found. + */ +struct device *of_platform_device_find(struct device_node *np) +{ + struct device_node *target; + struct platform_device *pdev; + + of_node_get(np); + + for (target = np; + !of_node_is_root(target); + target = of_get_next_parent(target)) + if (of_is_platform(target)) + break; + + pdev = of_find_device_by_node(target); + + of_node_put(target); + + return pdev ? &pdev->dev : NULL; +} +EXPORT_SYMBOL_GPL(of_platform_device_find); + #ifdef CONFIG_OF_DYNAMIC static int of_platform_notify(struct notifier_block *nb, unsigned long action, void *arg) diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 611a691145c4..baefc941fdb8 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -58,6 +58,7 @@ extern struct platform_device *of_device_alloc(struct device_node *np, const char *bus_id, struct device *parent); extern struct platform_device *of_find_device_by_node(struct device_node *np); +extern struct device *of_platform_device_find(struct device_node *np); /* Platform devices and busses creation */ extern struct platform_device *of_platform_device_create(struct device_node *np,