aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/device.h
diff options
context:
space:
mode:
authorSuzuki K Poulose <suzuki.poulose@arm.com>2019-07-23 18:18:34 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-07-30 07:07:42 -0400
commit67843bbaf36eb087714f40e783ee78e99e9e4b86 (patch)
treecd2b2839bd3510dfd05d2185346a57988fb93c8a /include/linux/device.h
parentcfba5de9b99f8bbb8b4ea11b3049784e78b8759b (diff)
drivers: Introduce device lookup variants by fwnode
Add a helper to match the firmware node handle of a device and provide wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation of duplicate custom match functions. Cc: "David S. Miller" <davem@davemloft.net> Cc: Doug Ledford <dledford@redhat.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: linux-usb@vger.kernel.org Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Ulf Hansson <ulf.hansson@linaro.org> Cc: Joe Perches <joe@perches.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Joerg Roedel <joro@8bytes.org> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Acked-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20190723221838.12024-4-suzuki.poulose@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/device.h')
-rw-r--r--include/linux/device.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index 29d8d7ad41e6..7133fc1c285d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
166 166
167int device_match_name(struct device *dev, const void *name); 167int device_match_name(struct device *dev, const void *name);
168int device_match_of_node(struct device *dev, const void *np); 168int device_match_of_node(struct device *dev, const void *np);
169int device_match_fwnode(struct device *dev, const void *fwnode);
169 170
170int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, 171int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
171 int (*fn)(struct device *dev, void *data)); 172 int (*fn)(struct device *dev, void *data));
@@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
198 return bus_find_device(bus, NULL, np, device_match_of_node); 199 return bus_find_device(bus, NULL, np, device_match_of_node);
199} 200}
200 201
202/**
203 * bus_find_device_by_fwnode : device iterator for locating a particular device
204 * matching the fwnode.
205 * @bus: bus type
206 * @fwnode: fwnode of the device to match.
207 */
208static inline struct device *
209bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
210{
211 return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
212}
213
201struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, 214struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
202 struct device *hint); 215 struct device *hint);
203int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, 216int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
391 return driver_find_device(drv, NULL, np, device_match_of_node); 404 return driver_find_device(drv, NULL, np, device_match_of_node);
392} 405}
393 406
407/**
408 * driver_find_device_by_fwnode- device iterator for locating a particular device
409 * by fwnode pointer.
410 * @driver: the driver we're iterating
411 * @fwnode: fwnode pointer to match.
412 */
413static inline struct device *
414driver_find_device_by_fwnode(struct device_driver *drv,
415 const struct fwnode_handle *fwnode)
416{
417 return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
418}
419
394void driver_deferred_probe_add(struct device *dev); 420void driver_deferred_probe_add(struct device *dev);
395int driver_deferred_probe_check_state(struct device *dev); 421int driver_deferred_probe_check_state(struct device *dev);
396int driver_deferred_probe_check_state_continue(struct device *dev); 422int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
544 return class_find_device(class, NULL, np, device_match_of_node); 570 return class_find_device(class, NULL, np, device_match_of_node);
545} 571}
546 572
573/**
574 * class_find_device_by_fwnode : device iterator for locating a particular device
575 * matching the fwnode.
576 * @class: class type
577 * @fwnode: fwnode of the device to match.
578 */
579static inline struct device *
580class_find_device_by_fwnode(struct class *class,
581 const struct fwnode_handle *fwnode)
582{
583 return class_find_device(class, NULL, fwnode, device_match_fwnode);
584}
585
547struct class_attribute { 586struct class_attribute {
548 struct attribute attr; 587 struct attribute attr;
549 ssize_t (*show)(struct class *class, struct class_attribute *attr, 588 ssize_t (*show)(struct class *class, struct class_attribute *attr,