Lines Matching refs:dev
77 struct device *dev; in deferred_probe_work_func() local
94 typeof(*dev->p), deferred_probe); in deferred_probe_work_func()
95 dev = private->device; in deferred_probe_work_func()
98 get_device(dev); in deferred_probe_work_func()
112 device_pm_move_to_tail(dev); in deferred_probe_work_func()
114 dev_dbg(dev, "Retrying from deferred list\n"); in deferred_probe_work_func()
115 bus_probe_device(dev); in deferred_probe_work_func()
118 put_device(dev); in deferred_probe_work_func()
124 void driver_deferred_probe_add(struct device *dev) in driver_deferred_probe_add() argument
127 if (list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_add()
128 dev_dbg(dev, "Added to deferred list\n"); in driver_deferred_probe_add()
129 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list); in driver_deferred_probe_add()
134 void driver_deferred_probe_del(struct device *dev) in driver_deferred_probe_del() argument
137 if (!list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_del()
138 dev_dbg(dev, "Removed from deferred list\n"); in driver_deferred_probe_del()
139 list_del_init(&dev->p->deferred_probe); in driver_deferred_probe_del()
140 kfree(dev->p->deferred_probe_reason); in driver_deferred_probe_del()
141 dev->p->deferred_probe_reason = NULL; in driver_deferred_probe_del()
217 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf) in device_set_deferred_probe_reason() argument
219 const char *drv = dev_driver_string(dev); in device_set_deferred_probe_reason()
223 kfree(dev->p->deferred_probe_reason); in device_set_deferred_probe_reason()
224 dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf); in device_set_deferred_probe_reason()
275 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
278 dev_warn(dev, "ignoring dependency for device, assuming no driver\n"); in driver_deferred_probe_check_state()
283 dev_warn(dev, "deferred probe timeout, ignoring dependency\n"); in driver_deferred_probe_check_state()
352 bool device_is_bound(struct device *dev) in device_is_bound() argument
354 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
357 static void driver_bound(struct device *dev) in driver_bound() argument
359 if (device_is_bound(dev)) { in driver_bound()
361 __func__, kobject_name(&dev->kobj)); in driver_bound()
365 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
366 __func__, dev_name(dev)); in driver_bound()
368 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
369 device_links_driver_bound(dev); in driver_bound()
371 device_pm_check_callbacks(dev); in driver_bound()
377 driver_deferred_probe_del(dev); in driver_bound()
380 if (dev->bus) in driver_bound()
381 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_bound()
382 BUS_NOTIFY_BOUND_DRIVER, dev); in driver_bound()
384 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
387 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
390 device_lock(dev); in coredump_store()
391 dev->driver->coredump(dev); in coredump_store()
392 device_unlock(dev); in coredump_store()
398 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
402 if (dev->bus) in driver_sysfs_add()
403 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_sysfs_add()
404 BUS_NOTIFY_BIND_DRIVER, dev); in driver_sysfs_add()
406 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
407 kobject_name(&dev->kobj)); in driver_sysfs_add()
411 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
416 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump || in driver_sysfs_add()
417 !device_create_file(dev, &dev_attr_coredump)) in driver_sysfs_add()
420 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
423 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
424 kobject_name(&dev->kobj)); in driver_sysfs_add()
430 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
432 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
436 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
437 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
438 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
455 int device_bind_driver(struct device *dev) in device_bind_driver() argument
459 ret = driver_sysfs_add(dev); in device_bind_driver()
461 driver_bound(dev); in device_bind_driver()
462 else if (dev->bus) in device_bind_driver()
463 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in device_bind_driver()
464 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in device_bind_driver()
472 static void driver_deferred_probe_add_trigger(struct device *dev, in driver_deferred_probe_add_trigger() argument
475 driver_deferred_probe_add(dev); in driver_deferred_probe_add_trigger()
481 static ssize_t state_synced_show(struct device *dev, in state_synced_show() argument
486 device_lock(dev); in state_synced_show()
487 val = dev->state_synced; in state_synced_show()
488 device_unlock(dev); in state_synced_show()
494 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
507 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
508 driver_deferred_probe_add(dev); in really_probe()
512 ret = device_links_check_suppliers(dev); in really_probe()
514 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
520 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
521 if (!list_empty(&dev->devres_head)) { in really_probe()
522 dev_crit(dev, "Resources present before probing\n"); in really_probe()
528 dev->driver = drv; in really_probe()
531 ret = pinctrl_bind_pins(dev); in really_probe()
535 if (dev->bus->dma_configure) { in really_probe()
536 ret = dev->bus->dma_configure(dev); in really_probe()
541 if (driver_sysfs_add(dev)) { in really_probe()
543 __func__, dev_name(dev)); in really_probe()
547 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
548 ret = dev->pm_domain->activate(dev); in really_probe()
553 if (dev->bus->probe) { in really_probe()
554 ret = dev->bus->probe(dev); in really_probe()
558 ret = drv->probe(dev); in really_probe()
563 if (device_add_groups(dev, drv->dev_groups)) { in really_probe()
564 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
568 if (dev_has_sync_state(dev) && in really_probe()
569 device_create_file(dev, &dev_attr_state_synced)) { in really_probe()
570 dev_err(dev, "state_synced sysfs add failed\n"); in really_probe()
577 device_remove_file(dev, &dev_attr_state_synced); in really_probe()
578 device_remove_groups(dev, drv->dev_groups); in really_probe()
580 if (dev->bus->remove) in really_probe()
581 dev->bus->remove(dev); in really_probe()
583 drv->remove(dev); in really_probe()
585 devres_release_all(dev); in really_probe()
586 driver_sysfs_remove(dev); in really_probe()
587 dev->driver = NULL; in really_probe()
588 dev_set_drvdata(dev, NULL); in really_probe()
589 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
590 dev->pm_domain->dismiss(dev); in really_probe()
591 pm_runtime_reinit(dev); in really_probe()
596 pinctrl_init_done(dev); in really_probe()
598 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
599 dev->pm_domain->sync(dev); in really_probe()
601 driver_bound(dev); in really_probe()
604 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
608 device_remove_groups(dev, drv->dev_groups); in really_probe()
610 if (dev->bus->remove) in really_probe()
611 dev->bus->remove(dev); in really_probe()
613 drv->remove(dev); in really_probe()
615 if (dev->bus) in really_probe()
616 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
617 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
619 device_links_no_driver(dev); in really_probe()
620 devres_release_all(dev); in really_probe()
621 arch_teardown_dma_ops(dev); in really_probe()
622 driver_sysfs_remove(dev); in really_probe()
623 dev->driver = NULL; in really_probe()
624 dev_set_drvdata(dev, NULL); in really_probe()
625 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
626 dev->pm_domain->dismiss(dev); in really_probe()
627 pm_runtime_reinit(dev); in really_probe()
628 dev_pm_set_driver_flags(dev, 0); in really_probe()
633 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in really_probe()
634 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
639 drv->name, dev_name(dev), ret); in really_probe()
644 drv->name, dev_name(dev), ret); in really_probe()
660 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
666 ret = really_probe(dev, drv); in really_probe_debug()
669 dev_name(dev), ret, ktime_us_delta(rettime, calltime)); in really_probe_debug()
720 int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
724 if (!device_is_registered(dev)) in driver_probe_device()
728 drv->bus->name, __func__, dev_name(dev), drv->name); in driver_probe_device()
730 pm_runtime_get_suppliers(dev); in driver_probe_device()
731 if (dev->parent) in driver_probe_device()
732 pm_runtime_get_sync(dev->parent); in driver_probe_device()
734 pm_runtime_barrier(dev); in driver_probe_device()
736 ret = really_probe_debug(dev, drv); in driver_probe_device()
738 ret = really_probe(dev, drv); in driver_probe_device()
739 pm_request_idle(dev); in driver_probe_device()
741 if (dev->parent) in driver_probe_device()
742 pm_runtime_put(dev->parent); in driver_probe_device()
744 pm_runtime_put_suppliers(dev); in driver_probe_device()
785 struct device *dev; member
820 struct device *dev = data->dev; in __device_attach_driver() local
824 ret = driver_match_device(drv, dev); in __device_attach_driver()
829 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
830 driver_deferred_probe_add(dev); in __device_attach_driver()
832 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __device_attach_driver()
844 return driver_probe_device(drv, dev); in __device_attach_driver()
849 struct device *dev = _dev; in __device_attach_async_helper() local
851 .dev = dev, in __device_attach_async_helper()
856 device_lock(dev); in __device_attach_async_helper()
864 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
867 if (dev->parent) in __device_attach_async_helper()
868 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
870 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
871 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
873 pm_request_idle(dev); in __device_attach_async_helper()
875 if (dev->parent) in __device_attach_async_helper()
876 pm_runtime_put(dev->parent); in __device_attach_async_helper()
878 device_unlock(dev); in __device_attach_async_helper()
880 put_device(dev); in __device_attach_async_helper()
883 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
887 device_lock(dev); in __device_attach()
888 if (dev->p->dead) { in __device_attach()
890 } else if (dev->driver) { in __device_attach()
891 if (device_is_bound(dev)) { in __device_attach()
895 ret = device_bind_driver(dev); in __device_attach()
899 dev->driver = NULL; in __device_attach()
904 .dev = dev, in __device_attach()
909 if (dev->parent) in __device_attach()
910 pm_runtime_get_sync(dev->parent); in __device_attach()
912 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
922 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
923 get_device(dev); in __device_attach()
924 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
926 pm_request_idle(dev); in __device_attach()
929 if (dev->parent) in __device_attach()
930 pm_runtime_put(dev->parent); in __device_attach()
933 device_unlock(dev); in __device_attach()
951 int device_attach(struct device *dev) in device_attach() argument
953 return __device_attach(dev, false); in device_attach()
957 void device_initial_probe(struct device *dev) in device_initial_probe() argument
959 __device_attach(dev, true); in device_initial_probe()
971 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
973 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
975 device_lock(dev); in __device_driver_lock()
987 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
989 device_unlock(dev); in __device_driver_unlock()
990 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
1002 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
1006 __device_driver_lock(dev, dev->parent); in device_driver_attach()
1012 if (!dev->p->dead && !dev->driver) in device_driver_attach()
1013 ret = driver_probe_device(drv, dev); in device_driver_attach()
1015 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1022 struct device *dev = _dev; in __driver_attach_async_helper() local
1026 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1028 drv = dev->p->async_driver; in __driver_attach_async_helper()
1034 if (!dev->p->dead && !dev->driver) in __driver_attach_async_helper()
1035 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1037 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1039 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1041 put_device(dev); in __driver_attach_async_helper()
1044 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1059 ret = driver_match_device(drv, dev); in __driver_attach()
1064 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1065 driver_deferred_probe_add(dev); in __driver_attach()
1067 dev_dbg(dev, "Bus failed to match device: %d\n", ret); in __driver_attach()
1079 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1080 device_lock(dev); in __driver_attach()
1081 if (!dev->driver) { in __driver_attach()
1082 get_device(dev); in __driver_attach()
1083 dev->p->async_driver = drv; in __driver_attach()
1084 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1086 device_unlock(dev); in __driver_attach()
1090 device_driver_attach(drv, dev); in __driver_attach()
1114 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1118 drv = dev->driver; in __device_release_driver()
1120 pm_runtime_get_sync(dev); in __device_release_driver()
1122 while (device_links_busy(dev)) { in __device_release_driver()
1123 __device_driver_unlock(dev, parent); in __device_release_driver()
1125 device_links_unbind_consumers(dev); in __device_release_driver()
1127 __device_driver_lock(dev, parent); in __device_release_driver()
1133 if (dev->driver != drv) { in __device_release_driver()
1134 pm_runtime_put(dev); in __device_release_driver()
1139 driver_sysfs_remove(dev); in __device_release_driver()
1141 if (dev->bus) in __device_release_driver()
1142 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1144 dev); in __device_release_driver()
1146 pm_runtime_put_sync(dev); in __device_release_driver()
1148 device_remove_file(dev, &dev_attr_state_synced); in __device_release_driver()
1149 device_remove_groups(dev, drv->dev_groups); in __device_release_driver()
1151 if (dev->bus && dev->bus->remove) in __device_release_driver()
1152 dev->bus->remove(dev); in __device_release_driver()
1154 drv->remove(dev); in __device_release_driver()
1156 device_links_driver_cleanup(dev); in __device_release_driver()
1158 devres_release_all(dev); in __device_release_driver()
1159 arch_teardown_dma_ops(dev); in __device_release_driver()
1160 dev->driver = NULL; in __device_release_driver()
1161 dev_set_drvdata(dev, NULL); in __device_release_driver()
1162 if (dev->pm_domain && dev->pm_domain->dismiss) in __device_release_driver()
1163 dev->pm_domain->dismiss(dev); in __device_release_driver()
1164 pm_runtime_reinit(dev); in __device_release_driver()
1165 dev_pm_set_driver_flags(dev, 0); in __device_release_driver()
1167 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1168 device_pm_check_callbacks(dev); in __device_release_driver()
1169 if (dev->bus) in __device_release_driver()
1170 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1172 dev); in __device_release_driver()
1174 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1178 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1182 __device_driver_lock(dev, parent); in device_release_driver_internal()
1184 if (!drv || drv == dev->driver) in device_release_driver_internal()
1185 __device_release_driver(dev, parent); in device_release_driver_internal()
1187 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1201 void device_release_driver(struct device *dev) in device_release_driver() argument
1208 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1219 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1221 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1231 struct device *dev; in driver_detach() local
1245 dev = dev_prv->device; in driver_detach()
1246 get_device(dev); in driver_detach()
1248 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1249 put_device(dev); in driver_detach()