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 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
678 dev->bus->dma_cleanup(dev); in really_probe()
679 device_unbind_cleanup(dev); in really_probe()
684 pinctrl_init_done(dev); in really_probe()
686 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
687 dev->pm_domain->sync(dev); in really_probe()
689 driver_bound(dev); in really_probe()
691 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
696 device_remove(dev); in really_probe()
698 driver_sysfs_remove(dev); in really_probe()
700 if (dev->bus) in really_probe()
701 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
702 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
703 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
704 dev->bus->dma_cleanup(dev); in really_probe()
706 device_links_no_driver(dev); in really_probe()
707 device_unbind_cleanup(dev); in really_probe()
715 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
721 ret = really_probe(dev, drv); in really_probe_debug()
729 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
787 static int __driver_probe_device(struct device_driver *drv, struct device *dev) in __driver_probe_device() argument
791 if (dev->p->dead || !device_is_registered(dev)) in __driver_probe_device()
793 if (dev->driver) in __driver_probe_device()
796 dev->can_match = true; in __driver_probe_device()
798 drv->bus->name, __func__, dev_name(dev), drv->name); in __driver_probe_device()
800 pm_runtime_get_suppliers(dev); in __driver_probe_device()
801 if (dev->parent) in __driver_probe_device()
802 pm_runtime_get_sync(dev->parent); in __driver_probe_device()
804 pm_runtime_barrier(dev); in __driver_probe_device()
806 ret = really_probe_debug(dev, drv); in __driver_probe_device()
808 ret = really_probe(dev, drv); in __driver_probe_device()
809 pm_request_idle(dev); in __driver_probe_device()
811 if (dev->parent) in __driver_probe_device()
812 pm_runtime_put(dev->parent); in __driver_probe_device()
814 pm_runtime_put_suppliers(dev); in __driver_probe_device()
832 static int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
838 ret = __driver_probe_device(drv, dev); in driver_probe_device()
840 driver_deferred_probe_add(dev); in driver_probe_device()
897 struct device *dev; member
932 struct device *dev = data->dev; in __device_attach_driver() local
936 ret = driver_match_device(drv, dev); in __device_attach_driver()
941 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
942 dev->can_match = true; in __device_attach_driver()
943 driver_deferred_probe_add(dev); in __device_attach_driver()
950 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
966 ret = driver_probe_device(drv, dev); in __device_attach_driver()
974 struct device *dev = _dev; in __device_attach_async_helper() local
976 .dev = dev, in __device_attach_async_helper()
981 device_lock(dev); in __device_attach_async_helper()
989 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
992 if (dev->parent) in __device_attach_async_helper()
993 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
995 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
996 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
998 pm_request_idle(dev); in __device_attach_async_helper()
1000 if (dev->parent) in __device_attach_async_helper()
1001 pm_runtime_put(dev->parent); in __device_attach_async_helper()
1003 device_unlock(dev); in __device_attach_async_helper()
1005 put_device(dev); in __device_attach_async_helper()
1008 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
1013 device_lock(dev); in __device_attach()
1014 if (dev->p->dead) { in __device_attach()
1016 } else if (dev->driver) { in __device_attach()
1017 if (device_is_bound(dev)) { in __device_attach()
1021 ret = device_bind_driver(dev); in __device_attach()
1025 dev->driver = NULL; in __device_attach()
1030 .dev = dev, in __device_attach()
1035 if (dev->parent) in __device_attach()
1036 pm_runtime_get_sync(dev->parent); in __device_attach()
1038 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
1048 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
1049 get_device(dev); in __device_attach()
1052 pm_request_idle(dev); in __device_attach()
1055 if (dev->parent) in __device_attach()
1056 pm_runtime_put(dev->parent); in __device_attach()
1059 device_unlock(dev); in __device_attach()
1061 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
1079 int device_attach(struct device *dev) in device_attach() argument
1081 return __device_attach(dev, false); in device_attach()
1085 void device_initial_probe(struct device *dev) in device_initial_probe() argument
1087 __device_attach(dev, true); in device_initial_probe()
1099 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
1101 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
1103 device_lock(dev); in __device_driver_lock()
1115 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1117 device_unlock(dev); in __device_driver_unlock()
1118 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1130 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1134 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1135 ret = __driver_probe_device(drv, dev); in device_driver_attach()
1136 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1149 struct device *dev = _dev; in __driver_attach_async_helper() local
1153 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1154 drv = dev->p->async_driver; in __driver_attach_async_helper()
1155 dev->p->async_driver = NULL; in __driver_attach_async_helper()
1156 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1157 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1159 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1161 put_device(dev); in __driver_attach_async_helper()
1164 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1180 ret = driver_match_device(drv, dev); in __driver_attach()
1185 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1186 dev->can_match = true; in __driver_attach()
1187 driver_deferred_probe_add(dev); in __driver_attach()
1194 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1210 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1211 device_lock(dev); in __driver_attach()
1212 if (!dev->driver && !dev->p->async_driver) { in __driver_attach()
1213 get_device(dev); in __driver_attach()
1214 dev->p->async_driver = drv; in __driver_attach()
1217 device_unlock(dev); in __driver_attach()
1219 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1223 __device_driver_lock(dev, dev->parent); in __driver_attach()
1224 driver_probe_device(drv, dev); in __driver_attach()
1225 __device_driver_unlock(dev, dev->parent); in __driver_attach()
1249 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1253 drv = dev->driver; in __device_release_driver()
1255 pm_runtime_get_sync(dev); in __device_release_driver()
1257 while (device_links_busy(dev)) { in __device_release_driver()
1258 __device_driver_unlock(dev, parent); in __device_release_driver()
1260 device_links_unbind_consumers(dev); in __device_release_driver()
1262 __device_driver_lock(dev, parent); in __device_release_driver()
1268 if (dev->driver != drv) { in __device_release_driver()
1269 pm_runtime_put(dev); in __device_release_driver()
1274 driver_sysfs_remove(dev); in __device_release_driver()
1276 if (dev->bus) in __device_release_driver()
1277 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1279 dev); in __device_release_driver()
1281 pm_runtime_put_sync(dev); in __device_release_driver()
1283 device_remove(dev); in __device_release_driver()
1285 if (dev->bus && dev->bus->dma_cleanup) in __device_release_driver()
1286 dev->bus->dma_cleanup(dev); in __device_release_driver()
1288 device_unbind_cleanup(dev); in __device_release_driver()
1289 device_links_driver_cleanup(dev); in __device_release_driver()
1291 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1292 device_pm_check_callbacks(dev); in __device_release_driver()
1293 if (dev->bus) in __device_release_driver()
1294 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1296 dev); in __device_release_driver()
1298 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1302 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1306 __device_driver_lock(dev, parent); in device_release_driver_internal()
1308 if (!drv || drv == dev->driver) in device_release_driver_internal()
1309 __device_release_driver(dev, parent); in device_release_driver_internal()
1311 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1325 void device_release_driver(struct device *dev) in device_release_driver() argument
1332 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1343 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1345 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1355 struct device *dev; in driver_detach() local
1369 dev = dev_prv->device; in driver_detach()
1370 get_device(dev); in driver_detach()
1372 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1373 put_device(dev); in driver_detach()