History

Merge tag 'generic_lookup_helpers' into for-next

Generic Device Lookup Helpers Persistent tag for others to pull this branch from Based on patch series from Suzuki K Poulose <suzuki.poulose@arm.com> with Subject: [PATCH v3 0/7] drivers: Add generic device lookup helpers Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> * tag 'generic_lookup_helpers': platform: Add platform_find_device_by_driver() helper drivers: Add generic helper to match any device drivers: Introduce device lookup variants by ACPI_COMPANION device drivers: Introduce device lookup variants by device type drivers: Introduce device lookup variants by fwnode drivers: Introduce device lookup variants by of_node drivers: Introduce device lookup variants by name

Jacek Anaszewski committed 7 years ago

Commit be7fc2c2 parents af7b650 36f331348 files · +341 −383Browse files

Showing the changes to include/linux (2 of 48 files). Show all

Unified · Split

2 files
  1. include/linux/device.h +234 −3
  2. include/linux/platform_device.h +3 −0
include/linux/device.h+234−3
@@ -164,16 +164,100 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, · 163 unmodified lines
164164 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
165165 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
166166
167+int device_match_name(struct device *dev, const void *name);
167168 int device_match_of_node(struct device *dev, const void *np);
169+int device_match_fwnode(struct device *dev, const void *fwnode);
170+int device_match_devt(struct device *dev, const void *pdevt);
171+int device_match_acpi_dev(struct device *dev, const void *adev);
172+int device_match_any(struct device *dev, const void *unused);
168173
169174 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
170175 int (*fn)(struct device *dev, void *data));
171176 struct device *bus_find_device(struct bus_type *bus, struct device *start,
172177 const void *data,
173178 int (*match)(struct device *dev, const void *data));
174−struct device *bus_find_device_by_name(struct bus_type *bus,
175− struct device *start,
176− const char *name);
179+/**
180+ * bus_find_device_by_name - device iterator for locating a particular device
181+ * of a specific name.
182+ * @bus: bus type
183+ * @start: Device to begin with
184+ * @name: name of the device to match
185+ */
186+static inline struct device *bus_find_device_by_name(struct bus_type *bus,
187+ struct device *start,
188+ const char *name)
189+{
190+ return bus_find_device(bus, start, name, device_match_name);
191+}
192+
193+/**
194+ * bus_find_device_by_of_node : device iterator for locating a particular device
195+ * matching the of_node.
196+ * @bus: bus type
197+ * @np: of_node of the device to match.
198+ */
199+static inline struct device *
200+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
201+{
202+ return bus_find_device(bus, NULL, np, device_match_of_node);
203+}
204+
205+/**
206+ * bus_find_device_by_fwnode : device iterator for locating a particular device
207+ * matching the fwnode.
208+ * @bus: bus type
209+ * @fwnode: fwnode of the device to match.
210+ */
211+static inline struct device *
212+bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
213+{
214+ return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
215+}
216+
217+/**
218+ * bus_find_device_by_devt : device iterator for locating a particular device
219+ * matching the device type.
220+ * @bus: bus type
221+ * @devt: device type of the device to match.
222+ */
223+static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
224+ dev_t devt)
225+{
226+ return bus_find_device(bus, NULL, &devt, device_match_devt);
227+}
228+
229+/**
230+ * bus_find_next_device - Find the next device after a given device in a
231+ * given bus.
232+ */
233+static inline struct device *
234+bus_find_next_device(struct bus_type *bus,struct device *cur)
235+{
236+ return bus_find_device(bus, cur, NULL, device_match_any);
237+}
238+
239+#ifdef CONFIG_ACPI
240+struct acpi_device;
241+
242+/**
243+ * bus_find_device_by_acpi_dev : device iterator for locating a particular device
244+ * matching the ACPI COMPANION device.
245+ * @bus: bus type
246+ * @adev: ACPI COMPANION device to match.
247+ */
248+static inline struct device *
249+bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
250+{
251+ return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
252+}
253+#else
254+static inline struct device *
255+bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
256+{
257+ return NULL;
258+}
259+#endif
260+
177261 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
178262 struct device *hint);
179263 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -342,6 +426,83 @@ struct device *driver_find_device(struct device_driver *drv, · 162 unmodified lines
342426 struct device *start, const void *data,
343427 int (*match)(struct device *dev, const void *data));
344428
429+/**
430+ * driver_find_device_by_name - device iterator for locating a particular device
431+ * of a specific name.
432+ * @driver: the driver we're iterating
433+ * @name: name of the device to match
434+ */
435+static inline struct device *driver_find_device_by_name(struct device_driver *drv,
436+ const char *name)
437+{
438+ return driver_find_device(drv, NULL, name, device_match_name);
439+}
440+
441+/**
442+ * driver_find_device_by_of_node- device iterator for locating a particular device
443+ * by of_node pointer.
444+ * @driver: the driver we're iterating
445+ * @np: of_node pointer to match.
446+ */
447+static inline struct device *
448+driver_find_device_by_of_node(struct device_driver *drv,
449+ const struct device_node *np)
450+{
451+ return driver_find_device(drv, NULL, np, device_match_of_node);
452+}
453+
454+/**
455+ * driver_find_device_by_fwnode- device iterator for locating a particular device
456+ * by fwnode pointer.
457+ * @driver: the driver we're iterating
458+ * @fwnode: fwnode pointer to match.
459+ */
460+static inline struct device *
461+driver_find_device_by_fwnode(struct device_driver *drv,
462+ const struct fwnode_handle *fwnode)
463+{
464+ return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
465+}
466+
467+/**
468+ * driver_find_device_by_devt- device iterator for locating a particular device
469+ * by devt.
470+ * @driver: the driver we're iterating
471+ * @devt: devt pointer to match.
472+ */
473+static inline struct device *driver_find_device_by_devt(struct device_driver *drv,
474+ dev_t devt)
475+{
476+ return driver_find_device(drv, NULL, &devt, device_match_devt);
477+}
478+
479+static inline struct device *driver_find_next_device(struct device_driver *drv,
480+ struct device *start)
481+{
482+ return driver_find_device(drv, start, NULL, device_match_any);
483+}
484+
485+#ifdef CONFIG_ACPI
486+/**
487+ * driver_find_device_by_acpi_dev : device iterator for locating a particular
488+ * device matching the ACPI_COMPANION device.
489+ * @driver: the driver we're iterating
490+ * @adev: ACPI_COMPANION device to match.
491+ */
492+static inline struct device *
493+driver_find_device_by_acpi_dev(struct device_driver *drv,
494+ const struct acpi_device *adev)
495+{
496+ return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
497+}
498+#else
499+static inline struct device *
500+driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
501+{
502+ return NULL;
503+}
504+#endif
505+
345506 void driver_deferred_probe_add(struct device *dev);
346507 int driver_deferred_probe_check_state(struct device *dev);
347508 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -471,6 +632,76 @@ extern struct device *class_find_device(struct class *class, · 123 unmodified lines
471632 struct device *start, const void *data,
472633 int (*match)(struct device *, const void *));
473634
635+/**
636+ * class_find_device_by_name - device iterator for locating a particular device
637+ * of a specific name.
638+ * @class: class type
639+ * @name: name of the device to match
640+ */
641+static inline struct device *class_find_device_by_name(struct class *class,
642+ const char *name)
643+{
644+ return class_find_device(class, NULL, name, device_match_name);
645+}
646+
647+/**
648+ * class_find_device_by_of_node : device iterator for locating a particular device
649+ * matching the of_node.
650+ * @class: class type
651+ * @np: of_node of the device to match.
652+ */
653+static inline struct device *
654+class_find_device_by_of_node(struct class *class, const struct device_node *np)
655+{
656+ return class_find_device(class, NULL, np, device_match_of_node);
657+}
658+
659+/**
660+ * class_find_device_by_fwnode : device iterator for locating a particular device
661+ * matching the fwnode.
662+ * @class: class type
663+ * @fwnode: fwnode of the device to match.
664+ */
665+static inline struct device *
666+class_find_device_by_fwnode(struct class *class,
667+ const struct fwnode_handle *fwnode)
668+{
669+ return class_find_device(class, NULL, fwnode, device_match_fwnode);
670+}
671+
672+/**
673+ * class_find_device_by_devt : device iterator for locating a particular device
674+ * matching the device type.
675+ * @class: class type
676+ * @devt: device type of the device to match.
677+ */
678+static inline struct device *class_find_device_by_devt(struct class *class,
679+ dev_t devt)
680+{
681+ return class_find_device(class, NULL, &devt, device_match_devt);
682+}
683+
684+#ifdef CONFIG_ACPI
685+struct acpi_device;
686+/**
687+ * class_find_device_by_acpi_dev : device iterator for locating a particular
688+ * device matching the ACPI_COMPANION device.
689+ * @class: class type
690+ * @adev: ACPI_COMPANION device to match.
691+ */
692+static inline struct device *
693+class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
694+{
695+ return class_find_device(class, NULL, adev, device_match_acpi_dev);
696+}
697+#else
698+static inline struct device *
699+class_find_device_by_acpi_dev(struct class *class, const void *adev)
700+{
701+ return NULL;
702+}
703+#endif
704+
474705 struct class_attribute {
475706 struct attribute attr;
476707 ssize_t (*show)(struct class *class, struct class_attribute *attr,
include/linux/platform_device.h+3−0
@@ -51,6 +51,9 @@ extern struct device platform_bus; · 50 unmodified lines
5151 extern void arch_setup_pdev_archdata(struct platform_device *);
5252 extern struct resource *platform_get_resource(struct platform_device *,
5353 unsigned int, unsigned int);
54+extern struct device *
55+platform_find_device_by_driver(struct device *start,
56+ const struct device_driver *drv);
5457 extern void __iomem *
5558 devm_platform_ioremap_resource(struct platform_device *pdev,
5659 unsigned int index);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t