Lines Matching refs:dev

72 static void __device_set_deferred_probe_reason(const struct device *dev, char *reason)  in __device_set_deferred_probe_reason()  argument
74 kfree(dev->p->deferred_probe_reason); in __device_set_deferred_probe_reason()
75 dev->p->deferred_probe_reason = reason; in __device_set_deferred_probe_reason()
83 struct device *dev; in deferred_probe_work_func() local
100 typeof(*dev->p), deferred_probe); in deferred_probe_work_func()
101 dev = private->device; in deferred_probe_work_func()
104 get_device(dev); in deferred_probe_work_func()
106 __device_set_deferred_probe_reason(dev, NULL); in deferred_probe_work_func()
120 device_pm_move_to_tail(dev); in deferred_probe_work_func()
122 dev_dbg(dev, "Retrying from deferred list\n"); in deferred_probe_work_func()
123 bus_probe_device(dev); in deferred_probe_work_func()
126 put_device(dev); in deferred_probe_work_func()
132 void driver_deferred_probe_add(struct device *dev) in driver_deferred_probe_add() argument
134 if (!dev->can_match) in driver_deferred_probe_add()
138 if (list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_add()
139 dev_dbg(dev, "Added to deferred list\n"); in driver_deferred_probe_add()
140 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list); in driver_deferred_probe_add()
145 void driver_deferred_probe_del(struct device *dev) in driver_deferred_probe_del() argument
148 if (!list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_del()
149 dev_dbg(dev, "Removed from deferred list\n"); in driver_deferred_probe_del()
150 list_del_init(&dev->p->deferred_probe); in driver_deferred_probe_del()
151 __device_set_deferred_probe_reason(dev, NULL); in driver_deferred_probe_del()
227 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf) in device_set_deferred_probe_reason() argument
229 const char *drv = dev_driver_string(dev); in device_set_deferred_probe_reason()
235 __device_set_deferred_probe_reason(dev, reason); in device_set_deferred_probe_reason()
288 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
291 dev_warn(dev, "ignoring dependency for device, assuming no driver\n"); in driver_deferred_probe_check_state()
296 dev_warn(dev, "deferred probe timeout, ignoring dependency\n"); in driver_deferred_probe_check_state()
386 bool device_is_bound(struct device *dev) in device_is_bound() argument
388 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
391 static void driver_bound(struct device *dev) in driver_bound() argument
393 if (device_is_bound(dev)) { in driver_bound()
395 __func__, kobject_name(&dev->kobj)); in driver_bound()
399 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
400 __func__, dev_name(dev)); in driver_bound()
402 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
403 device_links_driver_bound(dev); in driver_bound()
405 device_pm_check_callbacks(dev); in driver_bound()
411 driver_deferred_probe_del(dev); in driver_bound()
414 bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER); in driver_bound()
415 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
418 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
421 device_lock(dev); in coredump_store()
422 dev->driver->coredump(dev); in coredump_store()
423 device_unlock(dev); in coredump_store()
429 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
433 bus_notify(dev, BUS_NOTIFY_BIND_DRIVER); in driver_sysfs_add()
435 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
436 kobject_name(&dev->kobj)); in driver_sysfs_add()
440 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
445 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump) in driver_sysfs_add()
448 ret = device_create_file(dev, &dev_attr_coredump); in driver_sysfs_add()
452 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
455 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
456 kobject_name(&dev->kobj)); in driver_sysfs_add()
462 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
464 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
468 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
469 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
470 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
489 int device_bind_driver(struct device *dev) in device_bind_driver() argument
493 ret = driver_sysfs_add(dev); in device_bind_driver()
495 device_links_force_bind(dev); in device_bind_driver()
496 driver_bound(dev); in device_bind_driver()
499 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); in device_bind_driver()
507 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
512 device_lock(dev); in state_synced_show()
513 val = dev->state_synced; in state_synced_show()
514 device_unlock(dev); in state_synced_show()
520 static void device_unbind_cleanup(struct device *dev) in device_unbind_cleanup() argument
522 devres_release_all(dev); in device_unbind_cleanup()
523 arch_teardown_dma_ops(dev); in device_unbind_cleanup()
524 kfree(dev->dma_range_map); in device_unbind_cleanup()
525 dev->dma_range_map = NULL; in device_unbind_cleanup()
526 dev->driver = NULL; in device_unbind_cleanup()
527 dev_set_drvdata(dev, NULL); in device_unbind_cleanup()
528 if (dev->pm_domain && dev->pm_domain->dismiss) in device_unbind_cleanup()
529 dev->pm_domain->dismiss(dev); in device_unbind_cleanup()
530 pm_runtime_reinit(dev); in device_unbind_cleanup()
531 dev_pm_set_driver_flags(dev, 0); in device_unbind_cleanup()
534 static void device_remove(struct device *dev) in device_remove() argument
536 device_remove_file(dev, &dev_attr_state_synced); in device_remove()
537 device_remove_groups(dev, dev->driver->dev_groups); in device_remove()
539 if (dev->bus && dev->bus->remove) in device_remove()
540 dev->bus->remove(dev); in device_remove()
541 else if (dev->driver->remove) in device_remove()
542 dev->driver->remove(dev); in device_remove()
545 static int call_driver_probe(struct device *dev, struct device_driver *drv) in call_driver_probe() argument
549 if (dev->bus->probe) in call_driver_probe()
550 ret = dev->bus->probe(dev); in call_driver_probe()
552 ret = drv->probe(dev); in call_driver_probe()
559 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in call_driver_probe()
564 drv->name, dev_name(dev), ret); in call_driver_probe()
569 drv->name, dev_name(dev), ret); in call_driver_probe()
576 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
588 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
592 link_ret = device_links_check_suppliers(dev); in really_probe()
597 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
598 if (!list_empty(&dev->devres_head)) { in really_probe()
599 dev_crit(dev, "Resources present before probing\n"); in really_probe()
605 dev->driver = drv; in really_probe()
608 ret = pinctrl_bind_pins(dev); in really_probe()
612 if (dev->bus->dma_configure) { in really_probe()
613 ret = dev->bus->dma_configure(dev); in really_probe()
618 ret = driver_sysfs_add(dev); in really_probe()
621 __func__, dev_name(dev)); in really_probe()
625 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
626 ret = dev->pm_domain->activate(dev); in really_probe()
631 ret = call_driver_probe(dev, drv); in really_probe()
650 ret = device_add_groups(dev, drv->dev_groups); in really_probe()
652 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
656 if (dev_has_sync_state(dev)) { in really_probe()
657 ret = device_create_file(dev, &dev_attr_state_synced); in really_probe()
659 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
667 device_remove(dev); in really_probe()
668 driver_sysfs_remove(dev); in really_probe()
669 device_unbind_cleanup(dev); in really_probe()
674 pinctrl_init_done(dev); in really_probe()
676 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
677 dev->pm_domain->sync(dev); in really_probe()
679 driver_bound(dev); in really_probe()
681 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
686 device_remove(dev); in really_probe()
688 driver_sysfs_remove(dev); in really_probe()
690 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); in really_probe()
691 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
692 dev->bus->dma_cleanup(dev); in really_probe()
694 device_links_no_driver(dev); in really_probe()
695 device_unbind_cleanup(dev); in really_probe()
703 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
709 ret = really_probe(dev, drv); in really_probe_debug()
712 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
747 static int __driver_probe_device(struct device_driver *drv, struct device *dev) in __driver_probe_device() argument
751 if (dev->p->dead || !device_is_registered(dev)) in __driver_probe_device()
753 if (dev->driver) in __driver_probe_device()
756 dev->can_match = true; in __driver_probe_device()
758 drv->bus->name, __func__, dev_name(dev), drv->name); in __driver_probe_device()
760 pm_runtime_get_suppliers(dev); in __driver_probe_device()
761 if (dev->parent) in __driver_probe_device()
762 pm_runtime_get_sync(dev->parent); in __driver_probe_device()
764 pm_runtime_barrier(dev); in __driver_probe_device()
766 ret = really_probe_debug(dev, drv); in __driver_probe_device()
768 ret = really_probe(dev, drv); in __driver_probe_device()
769 pm_request_idle(dev); in __driver_probe_device()
771 if (dev->parent) in __driver_probe_device()
772 pm_runtime_put(dev->parent); in __driver_probe_device()
774 pm_runtime_put_suppliers(dev); in __driver_probe_device()
792 static int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
798 ret = __driver_probe_device(drv, dev); in driver_probe_device()
800 driver_deferred_probe_add(dev); in driver_probe_device()
857 struct device *dev; member
892 struct device *dev = data->dev; in __device_attach_driver() local
896 ret = driver_match_device(drv, dev); in __device_attach_driver()
901 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
902 dev->can_match = true; in __device_attach_driver()
903 driver_deferred_probe_add(dev); in __device_attach_driver()
910 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
926 ret = driver_probe_device(drv, dev); in __device_attach_driver()
934 struct device *dev = _dev; in __device_attach_async_helper() local
936 .dev = dev, in __device_attach_async_helper()
941 device_lock(dev); in __device_attach_async_helper()
949 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
952 if (dev->parent) in __device_attach_async_helper()
953 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
955 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
956 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
958 pm_request_idle(dev); in __device_attach_async_helper()
960 if (dev->parent) in __device_attach_async_helper()
961 pm_runtime_put(dev->parent); in __device_attach_async_helper()
963 device_unlock(dev); in __device_attach_async_helper()
965 put_device(dev); in __device_attach_async_helper()
968 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
973 device_lock(dev); in __device_attach()
974 if (dev->p->dead) { in __device_attach()
976 } else if (dev->driver) { in __device_attach()
977 if (device_is_bound(dev)) { in __device_attach()
981 ret = device_bind_driver(dev); in __device_attach()
985 dev->driver = NULL; in __device_attach()
990 .dev = dev, in __device_attach()
995 if (dev->parent) in __device_attach()
996 pm_runtime_get_sync(dev->parent); in __device_attach()
998 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
1008 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
1009 get_device(dev); in __device_attach()
1012 pm_request_idle(dev); in __device_attach()
1015 if (dev->parent) in __device_attach()
1016 pm_runtime_put(dev->parent); in __device_attach()
1019 device_unlock(dev); in __device_attach()
1021 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
1039 int device_attach(struct device *dev) in device_attach() argument
1041 return __device_attach(dev, false); in device_attach()
1045 void device_initial_probe(struct device *dev) in device_initial_probe() argument
1047 __device_attach(dev, true); in device_initial_probe()
1059 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
1061 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
1063 device_lock(dev); in __device_driver_lock()
1075 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1077 device_unlock(dev); in __device_driver_unlock()
1078 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1090 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1094 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1095 ret = __driver_probe_device(drv, dev); in device_driver_attach()
1096 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1109 struct device *dev = _dev; in __driver_attach_async_helper() local
1113 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1114 drv = dev->p->async_driver; in __driver_attach_async_helper()
1115 dev->p->async_driver = NULL; in __driver_attach_async_helper()
1116 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1117 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1119 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1121 put_device(dev); in __driver_attach_async_helper()
1124 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1140 ret = driver_match_device(drv, dev); in __driver_attach()
1145 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1146 dev->can_match = true; in __driver_attach()
1147 driver_deferred_probe_add(dev); in __driver_attach()
1154 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1170 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1171 device_lock(dev); in __driver_attach()
1172 if (!dev->driver && !dev->p->async_driver) { in __driver_attach()
1173 get_device(dev); in __driver_attach()
1174 dev->p->async_driver = drv; in __driver_attach()
1177 device_unlock(dev); in __driver_attach()
1179 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1183 __device_driver_lock(dev, dev->parent); in __driver_attach()
1184 driver_probe_device(drv, dev); in __driver_attach()
1185 __device_driver_unlock(dev, dev->parent); in __driver_attach()
1209 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1213 drv = dev->driver; in __device_release_driver()
1215 pm_runtime_get_sync(dev); in __device_release_driver()
1217 while (device_links_busy(dev)) { in __device_release_driver()
1218 __device_driver_unlock(dev, parent); in __device_release_driver()
1220 device_links_unbind_consumers(dev); in __device_release_driver()
1222 __device_driver_lock(dev, parent); in __device_release_driver()
1228 if (dev->driver != drv) { in __device_release_driver()
1229 pm_runtime_put(dev); in __device_release_driver()
1234 driver_sysfs_remove(dev); in __device_release_driver()
1236 bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER); in __device_release_driver()
1238 pm_runtime_put_sync(dev); in __device_release_driver()
1240 device_remove(dev); in __device_release_driver()
1242 if (dev->bus && dev->bus->dma_cleanup) in __device_release_driver()
1243 dev->bus->dma_cleanup(dev); in __device_release_driver()
1245 device_links_driver_cleanup(dev); in __device_release_driver()
1246 device_unbind_cleanup(dev); in __device_release_driver()
1248 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1249 device_pm_check_callbacks(dev); in __device_release_driver()
1251 bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER); in __device_release_driver()
1252 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1256 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1260 __device_driver_lock(dev, parent); in device_release_driver_internal()
1262 if (!drv || drv == dev->driver) in device_release_driver_internal()
1263 __device_release_driver(dev, parent); in device_release_driver_internal()
1265 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1279 void device_release_driver(struct device *dev) in device_release_driver() argument
1286 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1297 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1299 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1309 struct device *dev; in driver_detach() local
1323 dev = dev_prv->device; in driver_detach()
1324 get_device(dev); in driver_detach()
1326 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1327 put_device(dev); in driver_detach()