From: Viresh Kumar <viresh.kumar@linaro.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Stephen Boyd <sboyd@kernel.org>,
Rajendra Nayak <rnayak@codeaurora.org>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, robdclark@gmail.com,
s.hauer@pengutronix.de, l.stach@pengutronix.de,
shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com,
xuwei5@hisilicon.com, robh+dt@kernel.org, olof@lixom.net
Subject: [PATCH V7 01/13] of: platform: Add of_find_any_device_by_node()
Date: Fri, 23 Feb 2018 15:53:40 +0530 [thread overview]
Message-ID: <483bc64db23821497d0634a86e801510e439fe3d.1519380923.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1519380923.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1519380923.git.viresh.kumar@linaro.org>
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 <viresh.kumar@linaro.org>
---
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 c00d81dfac0b..72853f9043e6 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -55,6 +55,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 84a966623e78..5fb20afaf895 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -54,11 +54,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 */
--
2.15.0.194.g9af6a3dea062
next prev parent reply other threads:[~2018-02-23 10:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 10:23 [PATCH V7 00/13] drivers: Boot Constraint core Viresh Kumar
2018-02-23 10:23 ` Viresh Kumar [this message]
2018-02-23 10:23 ` [PATCH V7 02/13] of: platform: Make of_platform_bus_create() global Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 03/13] drivers: Add boot constraints core Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 04/13] boot_constraint: Add support for supply constraints Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 05/13] boot_constraint: Add support for clk constraints Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 06/13] boot_constraint: Add support for PM constraints Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 07/13] boot_constraint: Add debugfs support Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 08/13] boot_constraint: Manage deferrable constraints Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 09/13] boot_constraint: Add support for Hisilicon platforms Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 10/13] boot_constraint: Add support for IMX platform Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 11/13] boot_constraint: Add Qualcomm display controller constraints Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 12/13] boot_constraint: Update MAINTAINERS Viresh Kumar
2018-02-23 10:23 ` [PATCH V7 13/13] boot_constraint: Add documentation Viresh Kumar
2018-03-16 5:34 ` [PATCH V7 00/13] drivers: Boot Constraint core Viresh Kumar
2018-03-22 1:26 ` Viresh Kumar
2018-03-23 15:04 ` Greg Kroah-Hartman
2018-03-30 15:24 ` Georgi Djakov
2018-04-10 13:40 ` Lucas Stach
2018-04-11 4:39 ` Viresh Kumar
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=483bc64db23821497d0634a86e801510e439fe3d.1519380923.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=fabio.estevam@nxp.com \
--cc=gregkh@linuxfoundation.org \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nm@ti.com \
--cc=olof@lixom.net \
--cc=rnayak@codeaurora.org \
--cc=robdclark@gmail.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=xuwei5@hisilicon.com \
/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;
as well as URLs for NNTP newsgroup(s).