Lines Matching refs:dev

77 	struct device *dev;
94 typeof(*dev->p), deferred_probe);
95 dev = private->device;
98 get_device(dev);
100 kfree(dev->p->deferred_probe_reason);
101 dev->p->deferred_probe_reason = NULL;
115 device_pm_move_to_tail(dev);
117 dev_dbg(dev, "Retrying from deferred list\n");
118 bus_probe_device(dev);
121 put_device(dev);
127 void driver_deferred_probe_add(struct device *dev)
130 if (list_empty(&dev->p->deferred_probe)) {
131 dev_dbg(dev, "Added to deferred list\n");
132 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
137 void driver_deferred_probe_del(struct device *dev)
140 if (!list_empty(&dev->p->deferred_probe)) {
141 dev_dbg(dev, "Removed from deferred list\n");
142 list_del_init(&dev->p->deferred_probe);
143 kfree(dev->p->deferred_probe_reason);
144 dev->p->deferred_probe_reason = NULL;
217 * @dev: the pointer to the struct device
220 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
222 const char *drv = dev_driver_string(dev);
226 kfree(dev->p->deferred_probe_reason);
227 dev->p->deferred_probe_reason = kasprintf(GFP_KERNEL, "%s: %pV", drv, vaf);
266 * @dev: device to check
277 int driver_deferred_probe_check_state(struct device *dev)
280 dev_warn(dev, "ignoring dependency for device, assuming no driver\n");
285 dev_warn(dev, "deferred probe timeout, ignoring dependency\n");
348 * @dev: device to check
355 bool device_is_bound(struct device *dev)
357 return dev->p && klist_node_attached(&dev->p->knode_driver);
360 static void driver_bound(struct device *dev)
362 if (device_is_bound(dev)) {
364 __func__, kobject_name(&dev->kobj));
368 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name,
369 __func__, dev_name(dev));
371 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
372 device_links_driver_bound(dev);
374 device_pm_check_callbacks(dev);
380 driver_deferred_probe_del(dev);
383 if (dev->bus)
384 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
385 BUS_NOTIFY_BOUND_DRIVER, dev);
387 kobject_uevent(&dev->kobj, KOBJ_BIND);
390 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr,
393 device_lock(dev);
394 dev->driver->coredump(dev);
395 device_unlock(dev);
401 static int driver_sysfs_add(struct device *dev)
405 if (dev->bus)
406 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
407 BUS_NOTIFY_BIND_DRIVER, dev);
409 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
410 kobject_name(&dev->kobj));
414 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
419 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump ||
420 !device_create_file(dev, &dev_attr_coredump))
423 sysfs_remove_link(&dev->kobj, "driver");
426 sysfs_remove_link(&dev->driver->p->kobj,
427 kobject_name(&dev->kobj));
433 static void driver_sysfs_remove(struct device *dev)
435 struct device_driver *drv = dev->driver;
439 device_remove_file(dev, &dev_attr_coredump);
440 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
441 sysfs_remove_link(&dev->kobj, "driver");
447 * @dev: device.
450 * Caller must have already set @dev->driver.
458 int device_bind_driver(struct device *dev)
462 ret = driver_sysfs_add(dev);
464 driver_bound(dev);
465 else if (dev->bus)
466 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
467 BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
475 static void driver_deferred_probe_add_trigger(struct device *dev,
478 driver_deferred_probe_add(dev);
484 static ssize_t state_synced_show(struct device *dev,
489 device_lock(dev);
490 val = dev->state_synced;
491 device_unlock(dev);
497 static int really_probe(struct device *dev, struct device_driver *drv)
510 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name);
511 driver_deferred_probe_add(dev);
515 ret = device_links_check_suppliers(dev);
517 driver_deferred_probe_add_trigger(dev, local_trigger_count);
523 drv->bus->name, __func__, drv->name, dev_name(dev));
524 if (!list_empty(&dev->devres_head)) {
525 dev_crit(dev, "Resources present before probing\n");
531 dev->driver = drv;
534 ret = pinctrl_bind_pins(dev);
538 if (dev->bus->dma_configure) {
539 ret = dev->bus->dma_configure(dev);
544 ret = driver_sysfs_add(dev);
547 __func__, dev_name(dev));
551 if (dev->pm_domain && dev->pm_domain->activate) {
552 ret = dev->pm_domain->activate(dev);
557 if (dev->bus->probe) {
558 ret = dev->bus->probe(dev);
562 ret = drv->probe(dev);
567 ret = device_add_groups(dev, drv->dev_groups);
569 dev_err(dev, "device_add_groups() failed\n");
573 if (dev_has_sync_state(dev)) {
574 ret = device_create_file(dev, &dev_attr_state_synced);
576 dev_err(dev, "state_synced sysfs add failed\n");
584 device_remove_file(dev, &dev_attr_state_synced);
585 device_remove_groups(dev, drv->dev_groups);
587 if (dev->bus->remove)
588 dev->bus->remove(dev);
590 drv->remove(dev);
592 devres_release_all(dev);
593 arch_teardown_dma_ops(dev);
594 kfree(dev->dma_range_map);
595 dev->dma_range_map = NULL;
596 driver_sysfs_remove(dev);
597 dev->driver = NULL;
598 dev_set_drvdata(dev, NULL);
599 if (dev->pm_domain && dev->pm_domain->dismiss)
600 dev->pm_domain->dismiss(dev);
601 pm_runtime_reinit(dev);
606 pinctrl_init_done(dev);
608 if (dev->pm_domain && dev->pm_domain->sync)
609 dev->pm_domain->sync(dev);
611 driver_bound(dev);
614 drv->bus->name, __func__, dev_name(dev), drv->name);
618 device_remove_groups(dev, drv->dev_groups);
620 if (dev->bus->remove)
621 dev->bus->remove(dev);
623 drv->remove(dev);
625 if (dev->bus)
626 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
627 BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
629 device_links_no_driver(dev);
630 devres_release_all(dev);
631 arch_teardown_dma_ops(dev);
632 kfree(dev->dma_range_map);
633 dev->dma_range_map = NULL;
634 driver_sysfs_remove(dev);
635 dev->driver = NULL;
636 dev_set_drvdata(dev, NULL);
637 if (dev->pm_domain && dev->pm_domain->dismiss)
638 dev->pm_domain->dismiss(dev);
639 pm_runtime_reinit(dev);
640 dev_pm_set_driver_flags(dev, 0);
645 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
646 driver_deferred_probe_add_trigger(dev, local_trigger_count);
651 drv->name, dev_name(dev), ret);
656 drv->name, dev_name(dev), ret);
672 static int really_probe_debug(struct device *dev, struct device_driver *drv)
678 ret = really_probe(dev, drv);
686 dev_name(dev), ret, ktime_us_delta(rettime, calltime));
724 * @dev: device to try to bind to the driver
729 * This function must be called with @dev lock held. When called for a
730 * USB interface, @dev->parent lock must be held as well.
734 int driver_probe_device(struct device_driver *drv, struct device *dev)
738 if (!device_is_registered(dev))
742 drv->bus->name, __func__, dev_name(dev), drv->name);
744 pm_runtime_get_suppliers(dev);
745 if (dev->parent)
746 pm_runtime_get_sync(dev->parent);
748 pm_runtime_barrier(dev);
750 ret = really_probe_debug(dev, drv);
752 ret = really_probe(dev, drv);
753 pm_request_idle(dev);
755 if (dev->parent)
756 pm_runtime_put(dev->parent);
758 pm_runtime_put_suppliers(dev);
799 struct device *dev;
834 struct device *dev = data->dev;
838 ret = driver_match_device(drv, dev);
843 dev_dbg(dev, "Device match requests probe deferral\n");
844 driver_deferred_probe_add(dev);
851 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
863 return driver_probe_device(drv, dev);
868 struct device *dev = _dev;
870 .dev = dev,
875 device_lock(dev);
883 if (dev->p->dead || dev->driver)
886 if (dev->parent)
887 pm_runtime_get_sync(dev->parent);
889 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver);
890 dev_dbg(dev, "async probe completed\n");
892 pm_request_idle(dev);
894 if (dev->parent)
895 pm_runtime_put(dev->parent);
897 device_unlock(dev);
899 put_device(dev);
902 static int __device_attach(struct device *dev, bool allow_async)
907 device_lock(dev);
908 if (dev->p->dead) {
910 } else if (dev->driver) {
911 if (device_is_bound(dev)) {
915 ret = device_bind_driver(dev);
919 dev->driver = NULL;
924 .dev = dev,
929 if (dev->parent)
930 pm_runtime_get_sync(dev->parent);
932 ret = bus_for_each_drv(dev->bus, NULL, &data,
942 dev_dbg(dev, "scheduling asynchronous probe\n");
943 get_device(dev);
946 pm_request_idle(dev);
949 if (dev->parent)
950 pm_runtime_put(dev->parent);
953 device_unlock(dev);
955 async_schedule_dev(__device_attach_async_helper, dev);
961 * @dev: device.
971 * When called for a USB interface, @dev->parent lock must be held.
973 int device_attach(struct device *dev)
975 return __device_attach(dev, false);
979 void device_initial_probe(struct device *dev)
981 __device_attach(dev, true);
985 * __device_driver_lock - acquire locks needed to manipulate dev->drv
986 * @dev: Device we will update driver info for
989 * This function will take the required locks for manipulating dev->drv.
990 * Normally this will just be the @dev lock, but when called for a USB
993 static void __device_driver_lock(struct device *dev, struct device *parent)
995 if (parent && dev->bus->need_parent_lock)
997 device_lock(dev);
1001 * __device_driver_unlock - release locks needed to manipulate dev->drv
1002 * @dev: Device we will update driver info for
1005 * This function will release the required locks for manipulating dev->drv.
1006 * Normally this will just be the the @dev lock, but when called for a
1009 static void __device_driver_unlock(struct device *dev, struct device *parent)
1011 device_unlock(dev);
1012 if (parent && dev->bus->need_parent_lock)
1019 * @dev: Device to attach it to
1021 * Manually attach driver to a device. Will acquire both @dev lock and
1022 * @dev->parent lock if needed.
1024 int device_driver_attach(struct device_driver *drv, struct device *dev)
1028 __device_driver_lock(dev, dev->parent);
1034 if (!dev->p->dead && !dev->driver)
1035 ret = driver_probe_device(drv, dev);
1037 __device_driver_unlock(dev, dev->parent);
1044 struct device *dev = _dev;
1048 __device_driver_lock(dev, dev->parent);
1050 drv = dev->p->async_driver;
1056 if (!dev->p->dead && !dev->driver)
1057 ret = driver_probe_device(drv, dev);
1059 __device_driver_unlock(dev, dev->parent);
1061 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret);
1063 put_device(dev);
1066 static int __driver_attach(struct device *dev, void *data)
1082 ret = driver_match_device(drv, dev);
1087 dev_dbg(dev, "Device match requests probe deferral\n");
1088 driver_deferred_probe_add(dev);
1095 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
1109 * that the dev->driver and async_driver fields are protected
1111 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);
1112 device_lock(dev);
1113 if (!dev->driver) {
1114 get_device(dev);
1115 dev->p->async_driver = drv;
1118 device_unlock(dev);
1120 async_schedule_dev(__driver_attach_async_helper, dev);
1124 device_driver_attach(drv, dev);
1135 * returns 0 and the @dev->driver is set, we've found a
1145 * __device_release_driver() must be called with @dev lock held.
1146 * When called for a USB interface, @dev->parent lock must be held as well.
1148 static void __device_release_driver(struct device *dev, struct device *parent)
1152 drv = dev->driver;
1154 pm_runtime_get_sync(dev);
1156 while (device_links_busy(dev)) {
1157 __device_driver_unlock(dev, parent);
1159 device_links_unbind_consumers(dev);
1161 __device_driver_lock(dev, parent);
1167 if (dev->driver != drv) {
1168 pm_runtime_put(dev);
1173 driver_sysfs_remove(dev);
1175 if (dev->bus)
1176 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1178 dev);
1180 pm_runtime_put_sync(dev);
1182 device_remove_file(dev, &dev_attr_state_synced);
1183 device_remove_groups(dev, drv->dev_groups);
1185 if (dev->bus && dev->bus->remove)
1186 dev->bus->remove(dev);
1188 drv->remove(dev);
1190 devres_release_all(dev);
1191 arch_teardown_dma_ops(dev);
1192 kfree(dev->dma_range_map);
1193 dev->dma_range_map = NULL;
1194 dev->driver = NULL;
1195 dev_set_drvdata(dev, NULL);
1196 if (dev->pm_domain && dev->pm_domain->dismiss)
1197 dev->pm_domain->dismiss(dev);
1198 pm_runtime_reinit(dev);
1199 dev_pm_set_driver_flags(dev, 0);
1201 device_links_driver_cleanup(dev);
1203 klist_remove(&dev->p->knode_driver);
1204 device_pm_check_callbacks(dev);
1205 if (dev->bus)
1206 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1208 dev);
1210 kobject_uevent(&dev->kobj, KOBJ_UNBIND);
1214 void device_release_driver_internal(struct device *dev,
1218 __device_driver_lock(dev, parent);
1220 if (!drv || drv == dev->driver)
1221 __device_release_driver(dev, parent);
1223 __device_driver_unlock(dev, parent);
1228 * @dev: device.
1231 * When called for a USB interface, @dev->parent lock must be held.
1233 * If this function is to be called with @dev->parent lock held, ensure that
1235 * acquired under the @dev->parent lock.
1237 void device_release_driver(struct device *dev)
1244 device_release_driver_internal(dev, NULL, NULL);
1250 * @dev: device to detach driver from
1252 * Detach driver from device. Will acquire both @dev lock and @dev->parent
1255 void device_driver_detach(struct device *dev)
1257 device_release_driver_internal(dev, NULL, dev->parent);
1267 struct device *dev;
1281 dev = dev_prv->device;
1282 get_device(dev);
1284 device_release_driver_internal(dev, drv, dev->parent);
1285 put_device(dev);