aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.com>2016-02-15 03:25:06 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2016-02-16 11:28:51 -0500
commit656b8035b0eebcac0172b24ca04e448c70dd047f (patch)
tree9310d64d29e0130957ef33362d34c46392f6b42f
parent17f29d36e4732b91ae299a163d34ed1954500f42 (diff)
ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()
Allow implementations of the match() callback in struct bus_type to return errors and if it's -EPROBE_DEFER then queue the device for deferred probing. This is useful to buses such as AMBA in which devices are registered before their matching information can be retrieved from the HW (typically because a clock driver hasn't probed yet). [changed if-else code structure, adjusted documentation to match the code, extended comments] Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--Documentation/driver-model/porting.txt6
-rw-r--r--drivers/base/dd.c24
-rw-r--r--include/linux/device.h7
3 files changed, 31 insertions, 6 deletions
diff --git a/Documentation/driver-model/porting.txt b/Documentation/driver-model/porting.txt
index 92d86f7271b4..453053f1661f 100644
--- a/Documentation/driver-model/porting.txt
+++ b/Documentation/driver-model/porting.txt
@@ -340,8 +340,10 @@ comparison:
340 340
341 int (*match)(struct device * dev, struct device_driver * drv); 341 int (*match)(struct device * dev, struct device_driver * drv);
342 342
343match should return '1' if the driver supports the device, and '0' 343match should return positive value if the driver supports the device,
344otherwise. 344and zero otherwise. It may also return error code (for example
345-EPROBE_DEFER) if determining that given driver supports the device is
346not possible.
345 347
346When a device is registered, the bus's list of drivers is iterated 348When a device is registered, the bus's list of drivers is iterated
347over. bus->match() is called for each one until a match is found. 349over. bus->match() is called for each one until a match is found.
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index c4da2df62e02..16688f50729c 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -560,6 +560,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
560 struct device_attach_data *data = _data; 560 struct device_attach_data *data = _data;
561 struct device *dev = data->dev; 561 struct device *dev = data->dev;
562 bool async_allowed; 562 bool async_allowed;
563 int ret;
563 564
564 /* 565 /*
565 * Check if device has already been claimed. This may 566 * Check if device has already been claimed. This may
@@ -570,8 +571,17 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
570 if (dev->driver) 571 if (dev->driver)
571 return -EBUSY; 572 return -EBUSY;
572 573
573 if (!driver_match_device(drv, dev)) 574 ret = driver_match_device(drv, dev);
575 if (ret == 0) {
576 /* no match */
574 return 0; 577 return 0;
578 } else if (ret == -EPROBE_DEFER) {
579 dev_dbg(dev, "Device match requests probe deferral\n");
580 driver_deferred_probe_add(dev);
581 } else if (ret < 0) {
582 dev_dbg(dev, "Bus failed to match device: %d", ret);
583 return ret;
584 } /* ret > 0 means positive match */
575 585
576 async_allowed = driver_allows_async_probing(drv); 586 async_allowed = driver_allows_async_probing(drv);
577 587
@@ -691,6 +701,7 @@ void device_initial_probe(struct device *dev)
691static int __driver_attach(struct device *dev, void *data) 701static int __driver_attach(struct device *dev, void *data)
692{ 702{
693 struct device_driver *drv = data; 703 struct device_driver *drv = data;
704 int ret;
694 705
695 /* 706 /*
696 * Lock device and try to bind to it. We drop the error 707 * Lock device and try to bind to it. We drop the error
@@ -702,8 +713,17 @@ static int __driver_attach(struct device *dev, void *data)
702 * is an error. 713 * is an error.
703 */ 714 */
704 715
705 if (!driver_match_device(drv, dev)) 716 ret = driver_match_device(drv, dev);
717 if (ret == 0) {
718 /* no match */
706 return 0; 719 return 0;
720 } else if (ret == -EPROBE_DEFER) {
721 dev_dbg(dev, "Device match requests probe deferral\n");
722 driver_deferred_probe_add(dev);
723 } else if (ret < 0) {
724 dev_dbg(dev, "Bus failed to match device: %d", ret);
725 return ret;
726 } /* ret > 0 means positive match */
707 727
708 if (dev->parent) /* Needed for USB */ 728 if (dev->parent) /* Needed for USB */
709 device_lock(dev->parent); 729 device_lock(dev->parent);
diff --git a/include/linux/device.h b/include/linux/device.h
index 6d6f1fec092f..8f2ec813d215 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -70,8 +70,11 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
70 * @dev_groups: Default attributes of the devices on the bus. 70 * @dev_groups: Default attributes of the devices on the bus.
71 * @drv_groups: Default attributes of the device drivers on the bus. 71 * @drv_groups: Default attributes of the device drivers on the bus.
72 * @match: Called, perhaps multiple times, whenever a new device or driver 72 * @match: Called, perhaps multiple times, whenever a new device or driver
73 * is added for this bus. It should return a nonzero value if the 73 * is added for this bus. It should return a positive value if the
74 * given device can be handled by the given driver. 74 * given device can be handled by the given driver and zero
75 * otherwise. It may also return error code if determining that
76 * the driver supports the device is not possible. In case of
77 * -EPROBE_DEFER it will queue the device for deferred probing.
75 * @uevent: Called when a device is added, removed, or a few other things 78 * @uevent: Called when a device is added, removed, or a few other things
76 * that generate uevents to add the environment variables. 79 * that generate uevents to add the environment variables.
77 * @probe: Called when a new device or driver add to this bus, and callback 80 * @probe: Called when a new device or driver add to this bus, and callback