linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Driver core: add bus_find_device_by_of_node
@ 2018-09-20  5:42 Silesh C V
  2018-09-20  7:36 ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Silesh C V @ 2018-09-20  5:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: linux-kernel, Silesh C V

Similar to bus_find_device_by_name, but finds the device having a
specific of_node.

Signed-off-by: Silesh C V <svellattu@mvista.com>
---
 drivers/base/bus.c     | 21 +++++++++++++++++++++
 include/linux/device.h |  3 +++
 2 files changed, 24 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8bfd27e..39f90d1 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -373,6 +373,27 @@ struct device *bus_find_device_by_name(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device_by_name);
 
+static int match_of_node(struct device *dev, void *data)
+{
+	struct device_node *node = data;
+
+	return dev->of_node == node;
+}
+
+/**
+ * bus_find_device_by_name - device iterator for locating a particular device
+ * having a specific device node
+ * @bus: bus type
+ * @start: Device to begin with
+ * @node: device node pointer
+ */
+struct device *bus_find_device_by_of_node(struct bus_type *bus,
+					struct device *start, struct device_node *node)
+{
+	return bus_find_device(bus, start, (void *)node, match_of_node);
+}
+EXPORT_SYMBOL_GPL(bus_find_device_by_of_node);
+
 /**
  * subsys_find_device_by_id - find a device with a specific enumeration number
  * @subsys: subsystem
diff --git a/include/linux/device.h b/include/linux/device.h
index 055a69d..49006fd 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -171,6 +171,9 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start,
 struct device *bus_find_device_by_name(struct bus_type *bus,
 				       struct device *start,
 				       const char *name);
+struct device *bus_find_device_by_of_node(struct bus_type *bus,
+				       struct device *start,
+				       struct device_node *node);
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Driver core: add bus_find_device_by_of_node
  2018-09-20  5:42 [PATCH] Driver core: add bus_find_device_by_of_node Silesh C V
@ 2018-09-20  7:36 ` Rafael J. Wysocki
  2018-09-21  3:44   ` Silesh C V
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2018-09-20  7:36 UTC (permalink / raw)
  To: svellattu
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Linux Kernel Mailing List

On Thu, Sep 20, 2018 at 7:43 AM Silesh C V <svellattu@mvista.com> wrote:
>
> Similar to bus_find_device_by_name, but finds the device having a
> specific of_node.

First, what do you need it for?  Please describe your use case in the changelog.

Second, what about a more generic bus_find_device_by_fwnode() ?

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Driver core: add bus_find_device_by_of_node
  2018-09-20  7:36 ` Rafael J. Wysocki
@ 2018-09-21  3:44   ` Silesh C V
  2018-09-21  9:17     ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Silesh C V @ 2018-09-21  3:44 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, linux-kernel

Hello Rafael,

On Thu, Sep 20, 2018 at 1:06 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Thu, Sep 20, 2018 at 7:43 AM Silesh C V <svellattu@mvista.com> wrote:
> >
> > Similar to bus_find_device_by_name, but finds the device having a
> > specific of_node.
>
> First, what do you need it for?  Please describe your use case in the changelog.

This will be useful for drivers that do not register a platform_driver
(but retrieve the "simple-bus" device_node using
of_find_compatible_node etc.) but are still interested in the struct
device.

>
> Second, what about a more generic bus_find_device_by_fwnode() ?

If you think that the above requirement warrants the inclusion of
bus_find_device_by_of_node, I can try implementing this in v2.

Thanks.

Regards,
Silesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Driver core: add bus_find_device_by_of_node
  2018-09-21  3:44   ` Silesh C V
@ 2018-09-21  9:17     ` Rafael J. Wysocki
  2018-09-21  9:45       ` Silesh C V
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2018-09-21  9:17 UTC (permalink / raw)
  To: svellattu
  Cc: Rafael J. Wysocki, Greg Kroah-Hartman, Linux Kernel Mailing List

On Fri, Sep 21, 2018 at 5:45 AM Silesh C V <svellattu@mvista.com> wrote:
>
> Hello Rafael,
>
> On Thu, Sep 20, 2018 at 1:06 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Thu, Sep 20, 2018 at 7:43 AM Silesh C V <svellattu@mvista.com> wrote:
> > >
> > > Similar to bus_find_device_by_name, but finds the device having a
> > > specific of_node.
> >
> > First, what do you need it for?  Please describe your use case in the changelog.
>
> This will be useful for drivers that do not register a platform_driver
> (but retrieve the "simple-bus" device_node using
> of_find_compatible_node etc.) but are still interested in the struct
> device.
>
> >
> > Second, what about a more generic bus_find_device_by_fwnode() ?
>
> If you think that the above requirement warrants the inclusion of
> bus_find_device_by_of_node, I can try implementing this in v2.

I'm not really sure what you mean, but if there is
bus_find_device_by_fwnode(), it will be useful not just for DT code,
but generally, and getting an of_node from fwnode is trivial.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Driver core: add bus_find_device_by_of_node
  2018-09-21  9:17     ` Rafael J. Wysocki
@ 2018-09-21  9:45       ` Silesh C V
  0 siblings, 0 replies; 5+ messages in thread
From: Silesh C V @ 2018-09-21  9:45 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Greg Kroah-Hartman, linux-kernel

Hello Rafael,

On Fri, Sep 21, 2018 at 2:47 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> >
> > >
> > > Second, what about a more generic bus_find_device_by_fwnode() ?
> >
> > If you think that the above requirement warrants the inclusion of
> > bus_find_device_by_of_node, I can try implementing this in v2.
>
> I'm not really sure what you mean, but if there is
> bus_find_device_by_fwnode(), it will be useful not just for DT code,
> but generally, and getting an of_node from fwnode is trivial.
>

OK. Will do this and send out a patch soon.

Thanks,
Silesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-21  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20  5:42 [PATCH] Driver core: add bus_find_device_by_of_node Silesh C V
2018-09-20  7:36 ` Rafael J. Wysocki
2018-09-21  3:44   ` Silesh C V
2018-09-21  9:17     ` Rafael J. Wysocki
2018-09-21  9:45       ` Silesh C V

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).