Lines Matching refs:dev

71 static void __device_set_deferred_probe_reason(const struct device *dev, char *reason)  in __device_set_deferred_probe_reason()  argument
73 kfree(dev->p->deferred_probe_reason); in __device_set_deferred_probe_reason()
74 dev->p->deferred_probe_reason = reason; in __device_set_deferred_probe_reason()
82 struct device *dev; in deferred_probe_work_func() local
99 typeof(*dev->p), deferred_probe); in deferred_probe_work_func()
100 dev = private->device; in deferred_probe_work_func()
103 get_device(dev); in deferred_probe_work_func()
105 __device_set_deferred_probe_reason(dev, NULL); in deferred_probe_work_func()
119 device_pm_move_to_tail(dev); in deferred_probe_work_func()
121 dev_dbg(dev, "Retrying from deferred list\n"); in deferred_probe_work_func()
122 bus_probe_device(dev); in deferred_probe_work_func()
125 put_device(dev); in deferred_probe_work_func()
131 void driver_deferred_probe_add(struct device *dev) in driver_deferred_probe_add() argument
133 if (!dev->can_match) in driver_deferred_probe_add()
137 if (list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_add()
138 dev_dbg(dev, "Added to deferred list\n"); in driver_deferred_probe_add()
139 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list); in driver_deferred_probe_add()
144 void driver_deferred_probe_del(struct device *dev) in driver_deferred_probe_del() argument
147 if (!list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_del()
148 dev_dbg(dev, "Removed from deferred list\n"); in driver_deferred_probe_del()
149 list_del_init(&dev->p->deferred_probe); in driver_deferred_probe_del()
150 __device_set_deferred_probe_reason(dev, NULL); in driver_deferred_probe_del()
226 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf) in device_set_deferred_probe_reason() argument
228 const char *drv = dev_driver_string(dev); in device_set_deferred_probe_reason()
234 __device_set_deferred_probe_reason(dev, reason); in device_set_deferred_probe_reason()
285 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
288 dev_warn(dev, "ignoring dependency for device, assuming no driver\n"); in driver_deferred_probe_check_state()
293 dev_warn(dev, "deferred probe timeout, ignoring dependency\n"); in driver_deferred_probe_check_state()
369 bool device_is_bound(struct device *dev) in device_is_bound() argument
371 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
374 static void driver_bound(struct device *dev) in driver_bound() argument
376 if (device_is_bound(dev)) { in driver_bound()
378 __func__, kobject_name(&dev->kobj)); in driver_bound()
382 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
383 __func__, dev_name(dev)); in driver_bound()
385 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
386 device_links_driver_bound(dev); in driver_bound()
388 device_pm_check_callbacks(dev); in driver_bound()
394 driver_deferred_probe_del(dev); in driver_bound()
397 if (dev->bus) in driver_bound()
398 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_bound()
399 BUS_NOTIFY_BOUND_DRIVER, dev); in driver_bound()
401 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
404 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
407 device_lock(dev); in coredump_store()
408 dev->driver->coredump(dev); in coredump_store()
409 device_unlock(dev); in coredump_store()
415 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
419 if (dev->bus) in driver_sysfs_add()
420 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_sysfs_add()
421 BUS_NOTIFY_BIND_DRIVER, dev); in driver_sysfs_add()
423 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
424 kobject_name(&dev->kobj)); in driver_sysfs_add()
428 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
433 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump) in driver_sysfs_add()
436 ret = device_create_file(dev, &dev_attr_coredump); in driver_sysfs_add()
440 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
443 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
444 kobject_name(&dev->kobj)); in driver_sysfs_add()
450 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
452 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
456 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
457 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
458 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
477 int device_bind_driver(struct device *dev) in device_bind_driver() argument
481 ret = driver_sysfs_add(dev); in device_bind_driver()
483 device_links_force_bind(dev); in device_bind_driver()
484 driver_bound(dev); in device_bind_driver()
486 else if (dev->bus) in device_bind_driver()
487 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in device_bind_driver()
488 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in device_bind_driver()
496 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
501 device_lock(dev); in state_synced_show()
502 val = dev->state_synced; in state_synced_show()
503 device_unlock(dev); in state_synced_show()
510 static int call_driver_probe(struct device *dev, struct device_driver *drv) in call_driver_probe() argument
514 if (dev->bus->probe) in call_driver_probe()
515 ret = dev->bus->probe(dev); in call_driver_probe()
517 ret = drv->probe(dev); in call_driver_probe()
524 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in call_driver_probe()
529 drv->name, dev_name(dev), ret); in call_driver_probe()
534 drv->name, dev_name(dev), ret); in call_driver_probe()
541 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
553 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
557 ret = device_links_check_suppliers(dev); in really_probe()
562 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
563 if (!list_empty(&dev->devres_head)) { in really_probe()
564 dev_crit(dev, "Resources present before probing\n"); in really_probe()
570 dev->driver = drv; in really_probe()
573 ret = pinctrl_bind_pins(dev); in really_probe()
577 if (dev->bus->dma_configure) { in really_probe()
578 ret = dev->bus->dma_configure(dev); in really_probe()
583 ret = driver_sysfs_add(dev); in really_probe()
586 __func__, dev_name(dev)); in really_probe()
590 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
591 ret = dev->pm_domain->activate(dev); in really_probe()
596 ret = call_driver_probe(dev, drv); in really_probe()
606 ret = device_add_groups(dev, drv->dev_groups); in really_probe()
608 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
612 if (dev_has_sync_state(dev)) { in really_probe()
613 ret = device_create_file(dev, &dev_attr_state_synced); in really_probe()
615 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
623 device_remove_file(dev, &dev_attr_state_synced); in really_probe()
624 device_remove_groups(dev, drv->dev_groups); in really_probe()
626 if (dev->bus->remove) in really_probe()
627 dev->bus->remove(dev); in really_probe()
629 drv->remove(dev); in really_probe()
631 devres_release_all(dev); in really_probe()
632 driver_sysfs_remove(dev); in really_probe()
633 dev->driver = NULL; in really_probe()
634 dev_set_drvdata(dev, NULL); in really_probe()
635 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
636 dev->pm_domain->dismiss(dev); in really_probe()
637 pm_runtime_reinit(dev); in really_probe()
642 pinctrl_init_done(dev); in really_probe()
644 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
645 dev->pm_domain->sync(dev); in really_probe()
647 driver_bound(dev); in really_probe()
649 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
653 device_remove_groups(dev, drv->dev_groups); in really_probe()
655 if (dev->bus->remove) in really_probe()
656 dev->bus->remove(dev); in really_probe()
658 drv->remove(dev); in really_probe()
660 if (dev->bus) in really_probe()
661 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
662 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
664 device_links_no_driver(dev); in really_probe()
665 devres_release_all(dev); in really_probe()
666 arch_teardown_dma_ops(dev); in really_probe()
667 kfree(dev->dma_range_map); in really_probe()
668 dev->dma_range_map = NULL; in really_probe()
669 driver_sysfs_remove(dev); in really_probe()
670 dev->driver = NULL; in really_probe()
671 dev_set_drvdata(dev, NULL); in really_probe()
672 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
673 dev->pm_domain->dismiss(dev); in really_probe()
674 pm_runtime_reinit(dev); in really_probe()
675 dev_pm_set_driver_flags(dev, 0); in really_probe()
683 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
689 ret = really_probe(dev, drv); in really_probe_debug()
692 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
730 static int __driver_probe_device(struct device_driver *drv, struct device *dev) in __driver_probe_device() argument
734 if (dev->p->dead || !device_is_registered(dev)) in __driver_probe_device()
736 if (dev->driver) in __driver_probe_device()
739 dev->can_match = true; in __driver_probe_device()
741 drv->bus->name, __func__, dev_name(dev), drv->name); in __driver_probe_device()
743 pm_runtime_get_suppliers(dev); in __driver_probe_device()
744 if (dev->parent) in __driver_probe_device()
745 pm_runtime_get_sync(dev->parent); in __driver_probe_device()
747 pm_runtime_barrier(dev); in __driver_probe_device()
749 ret = really_probe_debug(dev, drv); in __driver_probe_device()
751 ret = really_probe(dev, drv); in __driver_probe_device()
752 pm_request_idle(dev); in __driver_probe_device()
754 if (dev->parent) in __driver_probe_device()
755 pm_runtime_put(dev->parent); in __driver_probe_device()
757 pm_runtime_put_suppliers(dev); in __driver_probe_device()
775 static int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
781 ret = __driver_probe_device(drv, dev); in driver_probe_device()
783 driver_deferred_probe_add(dev); in driver_probe_device()
834 struct device *dev; member
869 struct device *dev = data->dev; in __device_attach_driver() local
873 ret = driver_match_device(drv, dev); in __device_attach_driver()
878 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
879 dev->can_match = true; in __device_attach_driver()
880 driver_deferred_probe_add(dev); in __device_attach_driver()
882 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
898 ret = driver_probe_device(drv, dev); in __device_attach_driver()
906 struct device *dev = _dev; in __device_attach_async_helper() local
908 .dev = dev, in __device_attach_async_helper()
913 device_lock(dev); in __device_attach_async_helper()
921 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
924 if (dev->parent) in __device_attach_async_helper()
925 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
927 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
928 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
930 pm_request_idle(dev); in __device_attach_async_helper()
932 if (dev->parent) in __device_attach_async_helper()
933 pm_runtime_put(dev->parent); in __device_attach_async_helper()
935 device_unlock(dev); in __device_attach_async_helper()
937 put_device(dev); in __device_attach_async_helper()
940 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
944 device_lock(dev); in __device_attach()
945 if (dev->p->dead) { in __device_attach()
947 } else if (dev->driver) { in __device_attach()
948 if (device_is_bound(dev)) { in __device_attach()
952 ret = device_bind_driver(dev); in __device_attach()
956 dev->driver = NULL; in __device_attach()
961 .dev = dev, in __device_attach()
966 if (dev->parent) in __device_attach()
967 pm_runtime_get_sync(dev->parent); in __device_attach()
969 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
979 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
980 get_device(dev); in __device_attach()
981 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
983 pm_request_idle(dev); in __device_attach()
986 if (dev->parent) in __device_attach()
987 pm_runtime_put(dev->parent); in __device_attach()
990 device_unlock(dev); in __device_attach()
1008 int device_attach(struct device *dev) in device_attach() argument
1010 return __device_attach(dev, false); in device_attach()
1014 void device_initial_probe(struct device *dev) in device_initial_probe() argument
1016 __device_attach(dev, true); in device_initial_probe()
1028 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
1030 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
1032 device_lock(dev); in __device_driver_lock()
1044 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1046 device_unlock(dev); in __device_driver_unlock()
1047 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1059 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1063 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1064 ret = __driver_probe_device(drv, dev); in device_driver_attach()
1065 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1078 struct device *dev = _dev; in __driver_attach_async_helper() local
1082 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1083 drv = dev->p->async_driver; in __driver_attach_async_helper()
1084 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1085 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1087 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1089 put_device(dev); in __driver_attach_async_helper()
1092 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1107 ret = driver_match_device(drv, dev); in __driver_attach()
1112 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1113 dev->can_match = true; in __driver_attach()
1114 driver_deferred_probe_add(dev); in __driver_attach()
1116 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1128 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1129 device_lock(dev); in __driver_attach()
1130 if (!dev->driver) { in __driver_attach()
1131 get_device(dev); in __driver_attach()
1132 dev->p->async_driver = drv; in __driver_attach()
1133 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1135 device_unlock(dev); in __driver_attach()
1139 __device_driver_lock(dev, dev->parent); in __driver_attach()
1140 driver_probe_device(drv, dev); in __driver_attach()
1141 __device_driver_unlock(dev, dev->parent); in __driver_attach()
1165 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1169 drv = dev->driver; in __device_release_driver()
1171 pm_runtime_get_sync(dev); in __device_release_driver()
1173 while (device_links_busy(dev)) { in __device_release_driver()
1174 __device_driver_unlock(dev, parent); in __device_release_driver()
1176 device_links_unbind_consumers(dev); in __device_release_driver()
1178 __device_driver_lock(dev, parent); in __device_release_driver()
1184 if (dev->driver != drv) { in __device_release_driver()
1185 pm_runtime_put(dev); in __device_release_driver()
1190 driver_sysfs_remove(dev); in __device_release_driver()
1192 if (dev->bus) in __device_release_driver()
1193 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1195 dev); in __device_release_driver()
1197 pm_runtime_put_sync(dev); in __device_release_driver()
1199 device_remove_file(dev, &dev_attr_state_synced); in __device_release_driver()
1200 device_remove_groups(dev, drv->dev_groups); in __device_release_driver()
1202 if (dev->bus && dev->bus->remove) in __device_release_driver()
1203 dev->bus->remove(dev); in __device_release_driver()
1205 drv->remove(dev); in __device_release_driver()
1207 device_links_driver_cleanup(dev); in __device_release_driver()
1209 devres_release_all(dev); in __device_release_driver()
1210 arch_teardown_dma_ops(dev); in __device_release_driver()
1211 dev->driver = NULL; in __device_release_driver()
1212 dev_set_drvdata(dev, NULL); in __device_release_driver()
1213 if (dev->pm_domain && dev->pm_domain->dismiss) in __device_release_driver()
1214 dev->pm_domain->dismiss(dev); in __device_release_driver()
1215 pm_runtime_reinit(dev); in __device_release_driver()
1216 dev_pm_set_driver_flags(dev, 0); in __device_release_driver()
1218 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1219 device_pm_check_callbacks(dev); in __device_release_driver()
1220 if (dev->bus) in __device_release_driver()
1221 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1223 dev); in __device_release_driver()
1225 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1229 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1233 __device_driver_lock(dev, parent); in device_release_driver_internal()
1235 if (!drv || drv == dev->driver) in device_release_driver_internal()
1236 __device_release_driver(dev, parent); in device_release_driver_internal()
1238 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1252 void device_release_driver(struct device *dev) in device_release_driver() argument
1259 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1270 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1272 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1282 struct device *dev; in driver_detach() local
1296 dev = dev_prv->device; in driver_detach()
1297 get_device(dev); in driver_detach()
1299 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1300 put_device(dev); in driver_detach()