diff options
| author | Suzuki K Poulose <suzuki.poulose@arm.com> | 2019-07-23 18:18:32 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-07-30 07:07:41 -0400 |
| commit | 6cda08a20dbde45b021091230c8a359fa08c5103 (patch) | |
| tree | 6017a1b2e4a83b7fd330d404691e33da0df2726a /include/linux/device.h | |
| parent | 5f9e832c137075045d15cd6899ab0505cfb2ca4b (diff) | |
drivers: Introduce device lookup variants by name
Add a helper to match the device name for device lookup. Also
reuse this generic exported helper for the existing bus_find_device_by_name().
and add similar variants for driver/class.
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>
Cc: linux-leds@vger.kernel.org
Cc: linux-rtc@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: linux-wpan@vger.kernel.org
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Stefan Schmidt <stefan@datenfreihafen.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20190723221838.12024-2-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 | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index c330b75c6c57..3ba376b8b456 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
| @@ -164,6 +164,7 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, | |||
| 164 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); | 164 | struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); |
| 165 | void subsys_dev_iter_exit(struct subsys_dev_iter *iter); | 165 | 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_of_node(struct device *dev, const void *np); | 168 | int device_match_of_node(struct device *dev, const void *np); |
| 168 | 169 | ||
| 169 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | 170 | int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, |
| @@ -171,9 +172,20 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, | |||
| 171 | struct device *bus_find_device(struct bus_type *bus, struct device *start, | 172 | struct device *bus_find_device(struct bus_type *bus, struct device *start, |
| 172 | const void *data, | 173 | const void *data, |
| 173 | int (*match)(struct device *dev, const void *data)); | 174 | int (*match)(struct device *dev, const void *data)); |
| 174 | struct device *bus_find_device_by_name(struct bus_type *bus, | 175 | /** |
| 175 | struct device *start, | 176 | * bus_find_device_by_name - device iterator for locating a particular device |
| 176 | const char *name); | 177 | * of a specific name. |
| 178 | * @bus: bus type | ||
| 179 | * @start: Device to begin with | ||
| 180 | * @name: name of the device to match | ||
| 181 | */ | ||
| 182 | static inline struct device *bus_find_device_by_name(struct bus_type *bus, | ||
| 183 | struct device *start, | ||
| 184 | const char *name) | ||
| 185 | { | ||
| 186 | return bus_find_device(bus, start, name, device_match_name); | ||
| 187 | } | ||
| 188 | |||
| 177 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, | 189 | struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, |
| 178 | struct device *hint); | 190 | struct device *hint); |
| 179 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, | 191 | int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, |
| @@ -342,6 +354,18 @@ struct device *driver_find_device(struct device_driver *drv, | |||
| 342 | struct device *start, const void *data, | 354 | struct device *start, const void *data, |
| 343 | int (*match)(struct device *dev, const void *data)); | 355 | int (*match)(struct device *dev, const void *data)); |
| 344 | 356 | ||
| 357 | /** | ||
| 358 | * driver_find_device_by_name - device iterator for locating a particular device | ||
| 359 | * of a specific name. | ||
| 360 | * @driver: the driver we're iterating | ||
| 361 | * @name: name of the device to match | ||
| 362 | */ | ||
| 363 | static inline struct device *driver_find_device_by_name(struct device_driver *drv, | ||
| 364 | const char *name) | ||
| 365 | { | ||
| 366 | return driver_find_device(drv, NULL, name, device_match_name); | ||
| 367 | } | ||
| 368 | |||
| 345 | void driver_deferred_probe_add(struct device *dev); | 369 | void driver_deferred_probe_add(struct device *dev); |
| 346 | int driver_deferred_probe_check_state(struct device *dev); | 370 | int driver_deferred_probe_check_state(struct device *dev); |
| 347 | int driver_deferred_probe_check_state_continue(struct device *dev); | 371 | int driver_deferred_probe_check_state_continue(struct device *dev); |
| @@ -471,6 +495,18 @@ extern struct device *class_find_device(struct class *class, | |||
| 471 | struct device *start, const void *data, | 495 | struct device *start, const void *data, |
| 472 | int (*match)(struct device *, const void *)); | 496 | int (*match)(struct device *, const void *)); |
| 473 | 497 | ||
| 498 | /** | ||
| 499 | * class_find_device_by_name - device iterator for locating a particular device | ||
| 500 | * of a specific name. | ||
| 501 | * @class: class type | ||
| 502 | * @name: name of the device to match | ||
| 503 | */ | ||
| 504 | static inline struct device *class_find_device_by_name(struct class *class, | ||
| 505 | const char *name) | ||
| 506 | { | ||
| 507 | return class_find_device(class, NULL, name, device_match_name); | ||
| 508 | } | ||
| 509 | |||
| 474 | struct class_attribute { | 510 | struct class_attribute { |
| 475 | struct attribute attr; | 511 | struct attribute attr; |
| 476 | ssize_t (*show)(struct class *class, struct class_attribute *attr, | 512 | ssize_t (*show)(struct class *class, struct class_attribute *attr, |
