20 #include <linux/device.h>
22 #include <linux/module.h>
24 #include <linux/wait.h>
29 #include "power/power.h"
51 static LIST_HEAD(deferred_probe_pending_list);
52 static LIST_HEAD(deferred_probe_active_list);
75 while (!list_empty(&deferred_probe_active_list)) {
78 dev =
private->device;
79 list_del_init(&private->deferred_probe);
99 dev_dbg(dev,
"Retrying from deferred list\n");
108 static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
110 static void driver_deferred_probe_add(
struct device *dev)
113 if (list_empty(&dev->
p->deferred_probe)) {
114 dev_dbg(dev,
"Added to deferred list\n");
115 list_add_tail(&dev->
p->deferred_probe, &deferred_probe_pending_list);
123 if (!list_empty(&dev->
p->deferred_probe)) {
124 dev_dbg(dev,
"Removed from deferred list\n");
125 list_del_init(&dev->
p->deferred_probe);
130 static bool driver_deferred_probe_enable =
false;
138 static void driver_deferred_probe_trigger(
void)
140 if (!driver_deferred_probe_enable)
149 list_splice_tail_init(&deferred_probe_pending_list,
150 &deferred_probe_active_list);
157 queue_work(deferred_wq, &deferred_probe_work);
167 static int deferred_probe_initcall(
void)
173 driver_deferred_probe_enable =
true;
174 driver_deferred_probe_trigger();
179 static void driver_bound(
struct device *dev)
183 __func__, kobject_name(&dev->
kobj));
187 pr_debug(
"driver: '%s': %s: bound to device '%s'\n", dev_name(dev),
188 __func__, dev->
driver->name);
197 driver_deferred_probe_trigger();
204 static int driver_sysfs_add(
struct device *dev)
213 kobject_name(&dev->
kobj));
219 kobject_name(&dev->
kobj));
224 static void driver_sysfs_remove(
struct device *dev)
252 ret = driver_sysfs_add(dev);
267 pr_debug(
"bus: '%s': %s: probing driver %s with device %s\n",
268 drv->
bus->name, __func__, drv->
name, dev_name(dev));
272 if (driver_sysfs_add(dev)) {
274 __func__, dev_name(dev));
278 if (dev->
bus->probe) {
279 ret = dev->
bus->probe(dev);
282 }
else if (drv->
probe) {
283 ret = drv->
probe(dev);
290 pr_debug(
"bus: '%s': %s: bound device %s to driver %s\n",
291 drv->
bus->name, __func__, dev_name(dev), drv->
name);
296 driver_sysfs_remove(dev);
302 dev_info(dev,
"Driver %s requests probe deferral\n", drv->
name);
303 driver_deferred_probe_add(dev);
307 "%s: probe of %s failed with error %d\n",
308 drv->
name, dev_name(dev), ret);
310 pr_debug(
"%s: probe of %s rejects match %d\n",
311 drv->
name, dev_name(dev), ret);
332 pr_debug(
"%s: probe_count = %d\n", __func__,
366 if (!device_is_registered(dev))
369 pr_debug(
"bus: '%s': %s: matched device %s with driver %s\n",
370 drv->
bus->name, __func__, dev_name(dev), drv->
name);
373 ret = really_probe(dev, drv);
374 pm_runtime_idle(dev);
383 if (!driver_match_device(drv, dev))
422 pm_runtime_idle(dev);
430 static int __driver_attach(
struct device *dev,
void *data)
444 if (!driver_match_device(drv, dev))
454 device_unlock(dev->
parent);
478 static void __device_release_driver(
struct device *dev)
484 pm_runtime_get_sync(dev);
486 driver_sysfs_remove(dev);
493 pm_runtime_put_sync(dev);
495 if (dev->
bus && dev->
bus->remove)
496 dev->
bus->remove(dev);
526 __device_release_driver(dev);
541 spin_lock(&drv->
p->klist_devices.k_lock);
542 if (list_empty(&drv->
p->klist_devices.k_list)) {
543 spin_unlock(&drv->
p->klist_devices.k_lock);
546 dev_prv =
list_entry(drv->
p->klist_devices.k_list.prev,
548 knode_driver.n_node);
551 spin_unlock(&drv->
p->klist_devices.k_lock);
557 __device_release_driver(dev);
560 device_unlock(dev->
parent);
572 return dev->
p->driver_data;
586 dev->
p->driver_data =
data;