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()
392 bool device_is_bound(struct device *dev) in device_is_bound() argument
394 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
397 static void driver_bound(struct device *dev) in driver_bound() argument
399 if (device_is_bound(dev)) { in driver_bound()
401 __func__, kobject_name(&dev->kobj)); in driver_bound()
405 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
406 __func__, dev_name(dev)); in driver_bound()
408 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
409 device_links_driver_bound(dev); in driver_bound()
411 device_pm_check_callbacks(dev); in driver_bound()
417 driver_deferred_probe_del(dev); in driver_bound()
420 bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER); in driver_bound()
421 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
424 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
427 device_lock(dev); in coredump_store()
428 dev->driver->coredump(dev); in coredump_store()
429 device_unlock(dev); in coredump_store()
435 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
439 bus_notify(dev, BUS_NOTIFY_BIND_DRIVER); in driver_sysfs_add()
441 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
442 kobject_name(&dev->kobj)); in driver_sysfs_add()
446 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
451 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump) in driver_sysfs_add()
454 ret = device_create_file(dev, &dev_attr_coredump); in driver_sysfs_add()
458 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
461 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
462 kobject_name(&dev->kobj)); in driver_sysfs_add()
468 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
470 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
474 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
475 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
476 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
495 int device_bind_driver(struct device *dev) in device_bind_driver() argument
499 ret = driver_sysfs_add(dev); in device_bind_driver()
501 device_links_force_bind(dev); in device_bind_driver()
502 driver_bound(dev); in device_bind_driver()
505 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); in device_bind_driver()
513 static ssize_t state_synced_store(struct device *dev, in state_synced_store() argument
522 device_lock(dev); in state_synced_store()
523 if (!dev->state_synced) { in state_synced_store()
524 dev->state_synced = true; in state_synced_store()
525 dev_sync_state(dev); in state_synced_store()
529 device_unlock(dev); in state_synced_store()
534 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
539 device_lock(dev); in state_synced_show()
540 val = dev->state_synced; in state_synced_show()
541 device_unlock(dev); in state_synced_show()
547 static void device_unbind_cleanup(struct device *dev) in device_unbind_cleanup() argument
549 devres_release_all(dev); in device_unbind_cleanup()
550 arch_teardown_dma_ops(dev); in device_unbind_cleanup()
551 kfree(dev->dma_range_map); in device_unbind_cleanup()
552 dev->dma_range_map = NULL; in device_unbind_cleanup()
553 dev->driver = NULL; in device_unbind_cleanup()
554 dev_set_drvdata(dev, NULL); in device_unbind_cleanup()
555 if (dev->pm_domain && dev->pm_domain->dismiss) in device_unbind_cleanup()
556 dev->pm_domain->dismiss(dev); in device_unbind_cleanup()
557 pm_runtime_reinit(dev); in device_unbind_cleanup()
558 dev_pm_set_driver_flags(dev, 0); in device_unbind_cleanup()
561 static void device_remove(struct device *dev) in device_remove() argument
563 device_remove_file(dev, &dev_attr_state_synced); in device_remove()
564 device_remove_groups(dev, dev->driver->dev_groups); in device_remove()
566 if (dev->bus && dev->bus->remove) in device_remove()
567 dev->bus->remove(dev); in device_remove()
568 else if (dev->driver->remove) in device_remove()
569 dev->driver->remove(dev); in device_remove()
572 static int call_driver_probe(struct device *dev, struct device_driver *drv) in call_driver_probe() argument
576 if (dev->bus->probe) in call_driver_probe()
577 ret = dev->bus->probe(dev); in call_driver_probe()
579 ret = drv->probe(dev); in call_driver_probe()
586 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in call_driver_probe()
591 drv->name, dev_name(dev), ret); in call_driver_probe()
596 drv->name, dev_name(dev), ret); in call_driver_probe()
603 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
615 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
619 link_ret = device_links_check_suppliers(dev); in really_probe()
624 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
625 if (!list_empty(&dev->devres_head)) { in really_probe()
626 dev_crit(dev, "Resources present before probing\n"); in really_probe()
632 dev->driver = drv; in really_probe()
635 ret = pinctrl_bind_pins(dev); in really_probe()
639 if (dev->bus->dma_configure) { in really_probe()
640 ret = dev->bus->dma_configure(dev); in really_probe()
645 ret = driver_sysfs_add(dev); in really_probe()
648 __func__, dev_name(dev)); in really_probe()
652 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
653 ret = dev->pm_domain->activate(dev); in really_probe()
658 ret = call_driver_probe(dev, drv); in really_probe()
677 ret = device_add_groups(dev, drv->dev_groups); in really_probe()
679 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
683 if (dev_has_sync_state(dev)) { in really_probe()
684 ret = device_create_file(dev, &dev_attr_state_synced); in really_probe()
686 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
694 device_remove(dev); in really_probe()
695 driver_sysfs_remove(dev); in really_probe()
696 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
697 dev->bus->dma_cleanup(dev); in really_probe()
698 device_unbind_cleanup(dev); in really_probe()
703 pinctrl_init_done(dev); in really_probe()
705 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
706 dev->pm_domain->sync(dev); in really_probe()
708 driver_bound(dev); in really_probe()
710 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
715 device_remove(dev); in really_probe()
717 driver_sysfs_remove(dev); in really_probe()
719 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND); in really_probe()
720 if (dev->bus && dev->bus->dma_cleanup) in really_probe()
721 dev->bus->dma_cleanup(dev); in really_probe()
723 device_links_no_driver(dev); in really_probe()
724 device_unbind_cleanup(dev); in really_probe()
732 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
738 ret = really_probe(dev, drv); in really_probe_debug()
746 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
779 static int __driver_probe_device(struct device_driver *drv, struct device *dev) in __driver_probe_device() argument
783 if (dev->p->dead || !device_is_registered(dev)) in __driver_probe_device()
785 if (dev->driver) in __driver_probe_device()
788 dev->can_match = true; in __driver_probe_device()
790 drv->bus->name, __func__, dev_name(dev), drv->name); in __driver_probe_device()
792 pm_runtime_get_suppliers(dev); in __driver_probe_device()
793 if (dev->parent) in __driver_probe_device()
794 pm_runtime_get_sync(dev->parent); in __driver_probe_device()
796 pm_runtime_barrier(dev); in __driver_probe_device()
798 ret = really_probe_debug(dev, drv); in __driver_probe_device()
800 ret = really_probe(dev, drv); in __driver_probe_device()
801 pm_request_idle(dev); in __driver_probe_device()
803 if (dev->parent) in __driver_probe_device()
804 pm_runtime_put(dev->parent); in __driver_probe_device()
806 pm_runtime_put_suppliers(dev); in __driver_probe_device()
824 static int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
830 ret = __driver_probe_device(drv, dev); in driver_probe_device()
832 driver_deferred_probe_add(dev); in driver_probe_device()
889 struct device *dev; member
924 struct device *dev = data->dev; in __device_attach_driver() local
928 ret = driver_match_device(drv, dev); in __device_attach_driver()
933 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
934 dev->can_match = true; in __device_attach_driver()
935 driver_deferred_probe_add(dev); in __device_attach_driver()
942 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
958 ret = driver_probe_device(drv, dev); in __device_attach_driver()
966 struct device *dev = _dev; in __device_attach_async_helper() local
968 .dev = dev, in __device_attach_async_helper()
973 device_lock(dev); in __device_attach_async_helper()
981 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
984 if (dev->parent) in __device_attach_async_helper()
985 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
987 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
988 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
990 pm_request_idle(dev); in __device_attach_async_helper()
992 if (dev->parent) in __device_attach_async_helper()
993 pm_runtime_put(dev->parent); in __device_attach_async_helper()
995 device_unlock(dev); in __device_attach_async_helper()
997 put_device(dev); in __device_attach_async_helper()
1000 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
1005 device_lock(dev); in __device_attach()
1006 if (dev->p->dead) { in __device_attach()
1008 } else if (dev->driver) { in __device_attach()
1009 if (device_is_bound(dev)) { in __device_attach()
1013 ret = device_bind_driver(dev); in __device_attach()
1017 dev->driver = NULL; in __device_attach()
1022 .dev = dev, in __device_attach()
1027 if (dev->parent) in __device_attach()
1028 pm_runtime_get_sync(dev->parent); in __device_attach()
1030 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
1040 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
1041 get_device(dev); in __device_attach()
1044 pm_request_idle(dev); in __device_attach()
1047 if (dev->parent) in __device_attach()
1048 pm_runtime_put(dev->parent); in __device_attach()
1051 device_unlock(dev); in __device_attach()
1053 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
1071 int device_attach(struct device *dev) in device_attach() argument
1073 return __device_attach(dev, false); in device_attach()
1077 void device_initial_probe(struct device *dev) in device_initial_probe() argument
1079 __device_attach(dev, true); in device_initial_probe()
1091 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
1093 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
1095 device_lock(dev); in __device_driver_lock()
1107 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
1109 device_unlock(dev); in __device_driver_unlock()
1110 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1122 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1126 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1127 ret = __driver_probe_device(drv, dev); in device_driver_attach()
1128 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1141 struct device *dev = _dev; in __driver_attach_async_helper() local
1145 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1146 drv = dev->p->async_driver; in __driver_attach_async_helper()
1147 dev->p->async_driver = NULL; in __driver_attach_async_helper()
1148 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1149 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1151 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1153 put_device(dev); in __driver_attach_async_helper()
1156 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1172 ret = driver_match_device(drv, dev); in __driver_attach()
1177 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1178 dev->can_match = true; in __driver_attach()
1179 driver_deferred_probe_add(dev); in __driver_attach()
1186 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1202 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1203 device_lock(dev); in __driver_attach()
1204 if (!dev->driver && !dev->p->async_driver) { in __driver_attach()
1205 get_device(dev); in __driver_attach()
1206 dev->p->async_driver = drv; in __driver_attach()
1209 device_unlock(dev); in __driver_attach()
1211 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1215 __device_driver_lock(dev, dev->parent); in __driver_attach()
1216 driver_probe_device(drv, dev); in __driver_attach()
1217 __device_driver_unlock(dev, dev->parent); in __driver_attach()
1241 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1245 drv = dev->driver; in __device_release_driver()
1247 pm_runtime_get_sync(dev); in __device_release_driver()
1249 while (device_links_busy(dev)) { in __device_release_driver()
1250 __device_driver_unlock(dev, parent); in __device_release_driver()
1252 device_links_unbind_consumers(dev); in __device_release_driver()
1254 __device_driver_lock(dev, parent); in __device_release_driver()
1260 if (dev->driver != drv) { in __device_release_driver()
1261 pm_runtime_put(dev); in __device_release_driver()
1266 driver_sysfs_remove(dev); in __device_release_driver()
1268 bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER); in __device_release_driver()
1270 pm_runtime_put_sync(dev); in __device_release_driver()
1272 device_remove(dev); in __device_release_driver()
1274 if (dev->bus && dev->bus->dma_cleanup) in __device_release_driver()
1275 dev->bus->dma_cleanup(dev); in __device_release_driver()
1277 device_unbind_cleanup(dev); in __device_release_driver()
1278 device_links_driver_cleanup(dev); in __device_release_driver()
1280 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1281 device_pm_check_callbacks(dev); in __device_release_driver()
1283 bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER); in __device_release_driver()
1284 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1288 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1292 __device_driver_lock(dev, parent); in device_release_driver_internal()
1294 if (!drv || drv == dev->driver) in device_release_driver_internal()
1295 __device_release_driver(dev, parent); in device_release_driver_internal()
1297 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1311 void device_release_driver(struct device *dev) in device_release_driver() argument
1318 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1329 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1331 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1341 struct device *dev; in driver_detach() local
1355 dev = dev_prv->device; in driver_detach()
1356 get_device(dev); in driver_detach()
1358 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1359 put_device(dev); in driver_detach()