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()
290 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
293 dev_warn(dev, "ignoring dependency for device, assuming no driver\n"); in driver_deferred_probe_check_state()
298 dev_warn(dev, "deferred probe timeout, ignoring dependency\n"); in driver_deferred_probe_check_state()
388 bool device_is_bound(struct device *dev) in device_is_bound() argument
390 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
393 static void driver_bound(struct device *dev) in driver_bound() argument
395 if (device_is_bound(dev)) { in driver_bound()
397 __func__, kobject_name(&dev->kobj)); in driver_bound()
401 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
402 __func__, dev_name(dev)); in driver_bound()
404 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
405 device_links_driver_bound(dev); in driver_bound()
407 device_pm_check_callbacks(dev); in driver_bound()
413 driver_deferred_probe_del(dev); in driver_bound()
416 if (dev->bus) in driver_bound()
417 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_bound()
418 BUS_NOTIFY_BOUND_DRIVER, dev); in driver_bound()
420 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
423 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
426 device_lock(dev); in coredump_store()
427 dev->driver->coredump(dev); in coredump_store()
428 device_unlock(dev); in coredump_store()
434 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
438 if (dev->bus) in driver_sysfs_add()
439 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_sysfs_add()
440 BUS_NOTIFY_BIND_DRIVER, dev); in driver_sysfs_add()
442 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
443 kobject_name(&dev->kobj)); in driver_sysfs_add()
447 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
452 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump) in driver_sysfs_add()
455 ret = device_create_file(dev, &dev_attr_coredump); in driver_sysfs_add()
459 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
462 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
463 kobject_name(&dev->kobj)); in driver_sysfs_add()
469 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
471 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
475 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
476 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
477 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
496 int device_bind_driver(struct device *dev) in device_bind_driver() argument
500 ret = driver_sysfs_add(dev); in device_bind_driver()
502 device_links_force_bind(dev); in device_bind_driver()
503 driver_bound(dev); in device_bind_driver()
505 else if (dev->bus) in device_bind_driver()
506 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in device_bind_driver()
507 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in device_bind_driver()
515 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
520 device_lock(dev); in state_synced_show()
521 val = dev->state_synced; in state_synced_show()
522 device_unlock(dev); in state_synced_show()
528 static void device_unbind_cleanup(struct device *dev) in device_unbind_cleanup() argument
530 devres_release_all(dev); in device_unbind_cleanup()
531 arch_teardown_dma_ops(dev); in device_unbind_cleanup()
532 kfree(dev->dma_range_map); in device_unbind_cleanup()
533 dev->dma_range_map = NULL; in device_unbind_cleanup()
534 dev->driver = NULL; in device_unbind_cleanup()
535 dev_set_drvdata(dev, NULL); in device_unbind_cleanup()
536 if (dev->pm_domain && dev->pm_domain->dismiss) in device_unbind_cleanup()
537 dev->pm_domain->dismiss(dev); in device_unbind_cleanup()
538 pm_runtime_reinit(dev); in device_unbind_cleanup()
539 dev_pm_set_driver_flags(dev, 0); in device_unbind_cleanup()
542 static void device_remove(struct device *dev) in device_remove() argument
544 device_remove_file(dev, &dev_attr_state_synced); in device_remove()
545 device_remove_groups(dev, dev->driver->dev_groups); in device_remove()
547 if (dev->bus && dev->bus->remove) in device_remove()
548 dev->bus->remove(dev); in device_remove()
549 else if (dev->driver->remove) in device_remove()
550 dev->driver->remove(dev); in device_remove()
553 static int call_driver_probe(struct device *dev, struct device_driver *drv) in call_driver_probe() argument
557 if (dev->bus->probe) in call_driver_probe()
558 ret = dev->bus->probe(dev); in call_driver_probe()
560 ret = drv->probe(dev); in call_driver_probe()
567 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in call_driver_probe()
572 drv->name, dev_name(dev), ret); in call_driver_probe()
577 drv->name, dev_name(dev), ret); in call_driver_probe()
584 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
596 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
600 link_ret = device_links_check_suppliers(dev); in really_probe()
605 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
606 if (!list_empty(&dev->devres_head)) { in really_probe()
607 dev_crit(dev, "Resources present before probing\n"); in really_probe()
613 dev->driver = drv; in really_probe()
616 ret = pinctrl_bind_pins(dev); in really_probe()
620 if (dev->bus->dma_configure) { in really_probe()
621 ret = dev->bus->dma_configure(dev); in really_probe()
626 ret = driver_sysfs_add(dev); in really_probe()
629 __func__, dev_name(dev)); in really_probe()
633 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
634 ret = dev->pm_domain->activate(dev); in really_probe()
639 ret = call_driver_probe(dev, drv); in really_probe()
658 ret = device_add_groups(dev, drv->dev_groups); in really_probe()
660 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
664 if (dev_has_sync_state(dev)) { in really_probe()
665 ret = device_create_file(dev, &dev_attr_state_synced); in really_probe()
667 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
675 device_remove(dev); in really_probe()
676 driver_sysfs_remove(dev); in really_probe()
677 device_unbind_cleanup(dev); in really_probe()
682 pinctrl_init_done(dev); in really_probe()
684 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
685 dev->pm_domain->sync(dev); in really_probe()
687 driver_bound(dev); in really_probe()
689 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
694 device_remove(dev); in really_probe()
696 driver_sysfs_remove(dev); in really_probe()
698 if (dev->bus) in really_probe()
699 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
700 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
701 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
702 dev->bus->dma_cleanup(dev); in really_probe()
704 device_links_no_driver(dev); in really_probe()
705 device_unbind_cleanup(dev); in really_probe()
713 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
719 ret = really_probe(dev, drv); in really_probe_debug()
722 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
757 static int __driver_probe_device(struct device_driver *drv, struct device *dev) in __driver_probe_device() argument
761 if (dev->p->dead || !device_is_registered(dev)) in __driver_probe_device()
763 if (dev->driver) in __driver_probe_device()
766 dev->can_match = true; in __driver_probe_device()
768 drv->bus->name, __func__, dev_name(dev), drv->name); in __driver_probe_device()
770 pm_runtime_get_suppliers(dev); in __driver_probe_device()
771 if (dev->parent) in __driver_probe_device()
772 pm_runtime_get_sync(dev->parent); in __driver_probe_device()
774 pm_runtime_barrier(dev); in __driver_probe_device()
776 ret = really_probe_debug(dev, drv); in __driver_probe_device()
778 ret = really_probe(dev, drv); in __driver_probe_device()
779 pm_request_idle(dev); in __driver_probe_device()
781 if (dev->parent) in __driver_probe_device()
782 pm_runtime_put(dev->parent); in __driver_probe_device()
784 pm_runtime_put_suppliers(dev); in __driver_probe_device()
802 static int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
808 ret = __driver_probe_device(drv, dev); in driver_probe_device()
810 driver_deferred_probe_add(dev); in driver_probe_device()
867 struct device *dev; member
902 struct device *dev = data->dev; in __device_attach_driver() local
906 ret = driver_match_device(drv, dev); in __device_attach_driver()
911 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
912 dev->can_match = true; in __device_attach_driver()
913 driver_deferred_probe_add(dev); in __device_attach_driver()
920 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
936 ret = driver_probe_device(drv, dev); in __device_attach_driver()
944 struct device *dev = _dev; in __device_attach_async_helper() local
946 .dev = dev, in __device_attach_async_helper()
951 device_lock(dev); in __device_attach_async_helper()
959 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
962 if (dev->parent) in __device_attach_async_helper()
963 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
965 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
966 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
968 pm_request_idle(dev); in __device_attach_async_helper()
970 if (dev->parent) in __device_attach_async_helper()
971 pm_runtime_put(dev->parent); in __device_attach_async_helper()
973 device_unlock(dev); in __device_attach_async_helper()
975 put_device(dev); in __device_attach_async_helper()
978 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
983 device_lock(dev); in __device_attach()
984 if (dev->p->dead) { in __device_attach()
986 } else if (dev->driver) { in __device_attach()
987 if (device_is_bound(dev)) { in __device_attach()
991 ret = device_bind_driver(dev); in __device_attach()
995 dev->driver = NULL; in __device_attach()
1000 .dev = dev, in __device_attach()
1005 if (dev->parent) in __device_attach()
1006 pm_runtime_get_sync(dev->parent); in __device_attach()
1008 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
1018 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
1019 get_device(dev); in __device_attach()
1022 pm_request_idle(dev); in __device_attach()
1025 if (dev->parent) in __device_attach()
1026 pm_runtime_put(dev->parent); in __device_attach()
1029 device_unlock(dev); in __device_attach()
1031 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
1049 int device_attach(struct device *dev) in device_attach() argument
1051 return __device_attach(dev, false); in device_attach()
1055 void device_initial_probe(struct device *dev) in device_initial_probe() argument
1057 __device_attach(dev, true); in device_initial_probe()
1069 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
1071 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
1073 device_lock(dev); in __device_driver_lock()
1085 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1087 device_unlock(dev); in __device_driver_unlock()
1088 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1100 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1104 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1105 ret = __driver_probe_device(drv, dev); in device_driver_attach()
1106 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1119 struct device *dev = _dev; in __driver_attach_async_helper() local
1123 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1124 drv = dev->p->async_driver; in __driver_attach_async_helper()
1125 dev->p->async_driver = NULL; in __driver_attach_async_helper()
1126 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1127 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1129 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1131 put_device(dev); in __driver_attach_async_helper()
1134 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1150 ret = driver_match_device(drv, dev); in __driver_attach()
1155 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1156 dev->can_match = true; in __driver_attach()
1157 driver_deferred_probe_add(dev); in __driver_attach()
1164 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1180 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1181 device_lock(dev); in __driver_attach()
1182 if (!dev->driver && !dev->p->async_driver) { in __driver_attach()
1183 get_device(dev); in __driver_attach()
1184 dev->p->async_driver = drv; in __driver_attach()
1187 device_unlock(dev); in __driver_attach()
1189 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1193 __device_driver_lock(dev, dev->parent); in __driver_attach()
1194 driver_probe_device(drv, dev); in __driver_attach()
1195 __device_driver_unlock(dev, dev->parent); in __driver_attach()
1219 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1223 drv = dev->driver; in __device_release_driver()
1225 pm_runtime_get_sync(dev); in __device_release_driver()
1227 while (device_links_busy(dev)) { in __device_release_driver()
1228 __device_driver_unlock(dev, parent); in __device_release_driver()
1230 device_links_unbind_consumers(dev); in __device_release_driver()
1232 __device_driver_lock(dev, parent); in __device_release_driver()
1238 if (dev->driver != drv) { in __device_release_driver()
1239 pm_runtime_put(dev); in __device_release_driver()
1244 driver_sysfs_remove(dev); in __device_release_driver()
1246 if (dev->bus) in __device_release_driver()
1247 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1249 dev); in __device_release_driver()
1251 pm_runtime_put_sync(dev); in __device_release_driver()
1253 device_remove(dev); in __device_release_driver()
1255 if (dev->bus && dev->bus->dma_cleanup) in __device_release_driver()
1256 dev->bus->dma_cleanup(dev); in __device_release_driver()
1258 device_links_driver_cleanup(dev); in __device_release_driver()
1259 device_unbind_cleanup(dev); in __device_release_driver()
1261 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1262 device_pm_check_callbacks(dev); in __device_release_driver()
1263 if (dev->bus) in __device_release_driver()
1264 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1266 dev); in __device_release_driver()
1268 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1272 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1276 __device_driver_lock(dev, parent); in device_release_driver_internal()
1278 if (!drv || drv == dev->driver) in device_release_driver_internal()
1279 __device_release_driver(dev, parent); in device_release_driver_internal()
1281 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1295 void device_release_driver(struct device *dev) in device_release_driver() argument
1302 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1313 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1315 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1325 struct device *dev; in driver_detach() local
1339 dev = dev_prv->device; in driver_detach()
1340 get_device(dev); in driver_detach()
1342 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1343 put_device(dev); in driver_detach()