From patchwork Thu Dec 14 15:33:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10112515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8414060327 for ; Thu, 14 Dec 2017 15:34:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 753A728047 for ; Thu, 14 Dec 2017 15:34:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A10229006; Thu, 14 Dec 2017 15:34:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F29F428047 for ; Thu, 14 Dec 2017 15:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GS/C+0um+r8luyAL6a8PGlw8M0g4V9QjyJR+gmrE26Y=; b=QJr7rw5qiCsE+9uUHO/sWOnJrH Lnqttsi+MfshWpC1Hxhn6/ogNs7U89gQhWdcklrl/7cjGO7bOKX5w6DH+CwpR1luboKPCw4ZBF7LL lDu6tv28+XJ6Wnk8gZ/6X41YQkd3irhVBRRrBL4Y6sb8xiSZS5TnxIHJ9i6ffQdkz4AjYLWRGQc5y iXyT1XDoTJY0VpoarU+NXZd2pe/aLcwipJTpczGxTmQ5WWZckvdLeHk7J9PbQD4LFERHlVVGzp6Cd Nq0g6NzLpwYqfzj2dQisLweToZQ9cAkynZhhj89q6fw7keBibSzTh9spkbQMtIC/UylxUI6plarfB ERvWb4iA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ePVWu-00045k-Ez; Thu, 14 Dec 2017 15:34:36 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePVWY-0003dg-1S for linux-arm-kernel@lists.infradead.org; Thu, 14 Dec 2017 15:34:15 +0000 Received: by mail-pg0-x244.google.com with SMTP id j4so3637342pgp.1 for ; Thu, 14 Dec 2017 07:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=cYdJ9iaR7RB/2eh2ysuLTqt6mI8pRef5ilpcS+/OGV7qaWUZIw/NSF4z3dxvnp7prh vFEVJHAApLYR20XT886s98bX+wjgNTnvlVakyfhkSqVsCWvg9VMDVxVa09N59A+YxPIS D0jbvh+SZsa6NKLPA4uJ0Al/mbZwaJuBdkh3Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=tWuEUDoI6cqqY085QIj0EnF5HZiSnDH7FdPyYDgYCqZWe4iOxznfL2zWlkyZOSrPdP 8pFAIpPylLIoG8xM3vI1sxLMrYebqdSGEpgGb9wuzL89fpgzhI5vsgTyrgzq9d7hzURg 1RkHbQSqTrfw7+lgS9wbXUhREWc0XQcZULNWrPCymZznIMlDjbf3p/cKgxvTcFloG0iS g8fyVL4I3QFfFqZYbq1Xq7yhz1eG1z//yN6L6OYrvexGJobYnDLtlMx3JmwZubu0jxds 1Vz2gUD3ubxNm8Szo4eo/37n8NIWqk/ToV4cRxnOYy1W5RGF7FsVQVhsktwbuyNWorzv TQ5Q== X-Gm-Message-State: AKGB3mIMUx7Tdp+lEdUYoWbozAPHs3EWGilgMbnxy7PPh1y1JoxPOQO1 a7JEBBQGQZfQXjV+gOTPdiOf/g== X-Google-Smtp-Source: ACJfBouuGIAAwbyY0ezuZ+sZo+IoKsXljFyWbt9b6k0YS6qa9+/QAh/8D9S4Dm/sOiqtzQ2+gey1DQ== X-Received: by 10.99.109.5 with SMTP id i5mr8631028pgc.359.1513265633370; Thu, 14 Dec 2017 07:33:53 -0800 (PST) Received: from localhost ([122.172.99.7]) by smtp.gmail.com with ESMTPSA id r90sm8676848pfj.148.2017.12.14.07.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 07:33:52 -0800 (PST) From: Viresh Kumar To: Greg Kroah-Hartman Subject: [PATCH V5 01/13] of: platform: Add of_find_any_device_by_node() Date: Thu, 14 Dec 2017 21:03:08 +0530 Message-Id: <6dbdbc0e5fa8ca4722e9d3b1a92a6f9e008066e2.1513264961.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171214_073414_110113_94920885 X-CRM114-Status: GOOD ( 12.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nm@ti.com, Rajendra Nayak , Viresh Kumar , s.hauer@pengutronix.de, Stephen Boyd , linux-kernel@vger.kernel.org, xuwei5@hisilicon.com, robdclark@gmail.com, robh+dt@kernel.org, fabio.estevam@nxp.com, Vincent Guittot , shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org, l.stach@pengutronix.de MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This creates a new helper that returns the struct device corresponding to a struct device_node. This currently works only for amba and platform devices, but can be easily extended to include other bus types. This also creates an internal of_find_amba_device_by_node() helper, which isn't exported as of now. Signed-off-by: Viresh Kumar --- drivers/of/platform.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index b7cf84b29737..61a4a81bea9f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -60,6 +60,61 @@ struct platform_device *of_find_device_by_node(struct device_node *np) } EXPORT_SYMBOL(of_find_device_by_node); +#ifdef CONFIG_ARM_AMBA +/** + * of_find_amba_device_by_node - Find the amba_device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * Returns amba_device pointer, or NULL if not found + */ +static struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + struct device *dev; + + dev = bus_find_device(&amba_bustype, NULL, np, of_dev_node_match); + return dev ? to_amba_device(dev) : NULL; +} +#else +static inline struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + return NULL; +} +#endif + +/** + * of_find_any_device_by_node - Find the struct device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * This currently supports only AMBA and platform devices. + * + * Returns struct device pointer, or NULL if not found + */ +struct device *of_find_any_device_by_node(struct device_node *np) +{ + struct device *dev = NULL; + + if (of_device_is_compatible(np, "arm,primecell")) { + struct amba_device *adev = of_find_amba_device_by_node(np); + + if (adev) + dev = &adev->dev; + } else { + struct platform_device *pdev = of_find_device_by_node(np); + + if (pdev) + dev = &pdev->dev; + } + + return dev; +} +EXPORT_SYMBOL(of_find_any_device_by_node); + #ifdef CONFIG_OF_ADDRESS /* * The following routines scan a subtree and registers a device for diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index fb908e598348..4909d1aa47ec 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -59,11 +59,16 @@ extern struct platform_device *of_device_alloc(struct device_node *np, struct device *parent); #ifdef CONFIG_OF extern struct platform_device *of_find_device_by_node(struct device_node *np); +extern struct device *of_find_any_device_by_node(struct device_node *np); #else static inline struct platform_device *of_find_device_by_node(struct device_node *np) { return NULL; } +static inline struct device *of_find_any_device_by_node(struct device_node *np) +{ + return NULL; +} #endif /* Platform devices and busses creation */