diff options
| author | Suzuki K Poulose <suzuki.poulose@arm.com> | 2019-07-23 18:18:34 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-30 07:07:42 -0400 |
| commit | 67843bbaf36eb087714f40e783ee78e99e9e4b86 (patch) | |
| tree | cd2b2839bd3510dfd05d2185346a57988fb93c8a /include/linux/device.h | |
| parent | cfba5de9b99f8bbb8b4ea11b3049784e78b8759b (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.h | 39 |
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 | ||
| 167 | int device_match_name(struct device *dev, const void *name); | 167 | int device_match_name(struct device *dev, const void *name); |
| 168 | int device_match_of_node(struct device *dev, const void *np); | 168 | int device_match_of_node(struct device *dev, const void *np); |
| 169 | int device_match_fwnode(struct device *dev, const void *fwnode); | ||
| 169 | 170 | ||
| 170 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | 171 | int 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 | */ | ||
| 208 | static inline struct device * | ||
| 209 | bus_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 | |||
| 201 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | 214 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
| 202 | struct device *hint); | 215 | struct device *hint); |
| 203 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 216 | int 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 | */ | ||
| 413 | static inline struct device * | ||
| 414 | driver_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 | |||
| 394 | void driver_deferred_probe_add(struct device *dev); | 420 | void driver_deferred_probe_add(struct device *dev); |
| 395 | int driver_deferred_probe_check_state(struct device *dev); | 421 | int driver_deferred_probe_check_state(struct device *dev); |
| 396 | int driver_deferred_probe_check_state_continue(struct device *dev); | 422 | int 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 | */ | ||
| 579 | static inline struct device * | ||
| 580 | class_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 | |||
| 547 | struct class_attribute { | 586 | struct 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, |
