Lines Matching refs:dev

72 static void __device_set_deferred_probe_reason(const struct device *dev, char *reason)
74 kfree(dev->p->deferred_probe_reason);
75 dev->p->deferred_probe_reason = reason;
83 struct device *dev;
100 typeof(*dev->p), deferred_probe);
101 dev = private->device;
104 get_device(dev);
106 __device_set_deferred_probe_reason(dev, NULL);
120 device_pm_move_to_tail(dev);
122 dev_dbg(dev, "Retrying from deferred list\n");
123 bus_probe_device(dev);
126 put_device(dev);
132 void driver_deferred_probe_add(struct device *dev)
134 if (!dev->can_match)
138 if (list_empty(&dev->p->deferred_probe)) {
139 dev_dbg(dev, "Added to deferred list\n");
140 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
145 void driver_deferred_probe_del(struct device *dev)
148 if (!list_empty(&dev->p->deferred_probe)) {
149 dev_dbg(dev, "Removed from deferred list\n");
150 list_del_init(&dev->p->deferred_probe);
151 __device_set_deferred_probe_reason(dev, NULL);
224 * @dev: the pointer to the struct device
227 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
229 const char *drv = dev_driver_string(dev);
235 __device_set_deferred_probe_reason(dev, reason);
277 * @dev: device to check
288 int driver_deferred_probe_check_state(struct device *dev)
291 dev_warn(dev, "ignoring dependency for device, assuming no driver\n");
296 dev_warn(dev, "deferred probe timeout, ignoring dependency\n");
385 * @dev: device to check
392 bool device_is_bound(struct device *dev)
394 return dev->p && klist_node_attached(&dev->p->knode_driver);
397 static void driver_bound(struct device *dev)
399 if (device_is_bound(dev)) {
401 __func__, kobject_name(&dev->kobj));
405 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name,
406 __func__, dev_name(dev));
408 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
409 device_links_driver_bound(dev);
411 device_pm_check_callbacks(dev);
417 driver_deferred_probe_del(dev);
420 bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER);
421 kobject_uevent(&dev->kobj, KOBJ_BIND);
424 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr,
427 device_lock(dev);
428 dev->driver->coredump(dev);
429 device_unlock(dev);
435 static int driver_sysfs_add(struct device *dev)
439 bus_notify(dev, BUS_NOTIFY_BIND_DRIVER);
441 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
442 kobject_name(&dev->kobj));
446 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
451 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
454 ret = device_create_file(dev, &dev_attr_coredump);
458 sysfs_remove_link(&dev->kobj, "driver");
461 sysfs_remove_link(&dev->driver->p->kobj,
462 kobject_name(&dev->kobj));
468 static void driver_sysfs_remove(struct device *dev)
470 struct device_driver *drv = dev->driver;
474 device_remove_file(dev, &dev_attr_coredump);
475 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
476 sysfs_remove_link(&dev->kobj, "driver");
482 * @dev: device.
485 * Caller must have already set @dev->driver.
495 int device_bind_driver(struct device *dev)
499 ret = driver_sysfs_add(dev);
501 device_links_force_bind(dev);
502 driver_bound(dev);
505 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
513 static ssize_t state_synced_store(struct device *dev,
522 device_lock(dev);
523 if (!dev->state_synced) {
524 dev->state_synced = true;
525 dev_sync_state(dev);
529 device_unlock(dev);
534 static ssize_t state_synced_show(struct device *dev,
539 device_lock(dev);
540 val = dev->state_synced;
541 device_unlock(dev);
547 static void device_unbind_cleanup(struct device *dev)
549 devres_release_all(dev);
550 arch_teardown_dma_ops(dev);
551 kfree(dev->dma_range_map);
552 dev->dma_range_map = NULL;
553 dev->driver = NULL;
554 dev_set_drvdata(dev, NULL);
555 if (dev->pm_domain && dev->pm_domain->dismiss)
556 dev->pm_domain->dismiss(dev);
557 pm_runtime_reinit(dev);
558 dev_pm_set_driver_flags(dev, 0);
561 static void device_remove(struct device *dev)
563 device_remove_file(dev, &dev_attr_state_synced);
564 device_remove_groups(dev, dev->driver->dev_groups);
566 if (dev->bus && dev->bus->remove)
567 dev->bus->remove(dev);
568 else if (dev->driver->remove)
569 dev->driver->remove(dev);
572 static int call_driver_probe(struct device *dev, struct device_driver *drv)
576 if (dev->bus->probe)
577 ret = dev->bus->probe(dev);
579 ret = drv->probe(dev);
586 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
591 drv->name, dev_name(dev), ret);
596 drv->name, dev_name(dev), ret);
603 static int really_probe(struct device *dev, struct device_driver *drv)
615 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name);
619 link_ret = device_links_check_suppliers(dev);
624 drv->bus->name, __func__, drv->name, dev_name(dev));
625 if (!list_empty(&dev->devres_head)) {
626 dev_crit(dev, "Resources present before probing\n");
632 dev->driver = drv;
635 ret = pinctrl_bind_pins(dev);
639 if (dev->bus->dma_configure) {
640 ret = dev->bus->dma_configure(dev);
645 ret = driver_sysfs_add(dev);
648 __func__, dev_name(dev));
652 if (dev->pm_domain && dev->pm_domain->activate) {
653 ret = dev->pm_domain->activate(dev);
658 ret = call_driver_probe(dev, drv);
677 ret = device_add_groups(dev, drv->dev_groups);
679 dev_err(dev, "device_add_groups() failed\n");
683 if (dev_has_sync_state(dev)) {
684 ret = device_create_file(dev, &dev_attr_state_synced);
686 dev_err(dev, "state_synced sysfs add failed\n");
694 device_remove(dev);
695 driver_sysfs_remove(dev);
696 if (dev->bus && dev->bus->dma_cleanup)
697 dev->bus->dma_cleanup(dev);
698 device_unbind_cleanup(dev);
703 pinctrl_init_done(dev);
705 if (dev->pm_domain && dev->pm_domain->sync)
706 dev->pm_domain->sync(dev);
708 driver_bound(dev);
710 drv->bus->name, __func__, dev_name(dev), drv->name);
715 device_remove(dev);
717 driver_sysfs_remove(dev);
719 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
720 if (dev->bus && dev->bus->dma_cleanup)
721 dev->bus->dma_cleanup(dev);
723 device_links_no_driver(dev);
724 device_unbind_cleanup(dev);
732 static int really_probe_debug(struct device *dev, struct device_driver *drv)
738 ret = really_probe(dev, drv);
746 dev_name(dev), ret, ktime_us_delta(rettime, calltime));
779 static int __driver_probe_device(struct device_driver *drv, struct device *dev)
783 if (dev->p->dead || !device_is_registered(dev))
785 if (dev->driver)
788 dev->can_match = true;
790 drv->bus->name, __func__, dev_name(dev), drv->name);
792 pm_runtime_get_suppliers(dev);
793 if (dev->parent)
794 pm_runtime_get_sync(dev->parent);
796 pm_runtime_barrier(dev);
798 ret = really_probe_debug(dev, drv);
800 ret = really_probe(dev, drv);
801 pm_request_idle(dev);
803 if (dev->parent)
804 pm_runtime_put(dev->parent);
806 pm_runtime_put_suppliers(dev);
813 * @dev: device to try to bind to the driver
819 * This function must be called with @dev lock held. When called for a
820 * USB interface, @dev->parent lock must be held as well.
824 static int driver_probe_device(struct device_driver *drv, struct device *dev)
830 ret = __driver_probe_device(drv, dev);
832 driver_deferred_probe_add(dev);
889 struct device *dev;
924 struct device *dev = data->dev;
928 ret = driver_match_device(drv, dev);
933 dev_dbg(dev, "Device match requests probe deferral\n");
934 dev->can_match = true;
935 driver_deferred_probe_add(dev);
942 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
958 ret = driver_probe_device(drv, dev);
966 struct device *dev = _dev;
968 .dev = dev,
973 device_lock(dev);
981 if (dev->p->dead || dev->driver)
984 if (dev->parent)
985 pm_runtime_get_sync(dev->parent);
987 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver);
988 dev_dbg(dev, "async probe completed\n");
990 pm_request_idle(dev);
992 if (dev->parent)
993 pm_runtime_put(dev->parent);
995 device_unlock(dev);
997 put_device(dev);
1000 static int __device_attach(struct device *dev, bool allow_async)
1005 device_lock(dev);
1006 if (dev->p->dead) {
1008 } else if (dev->driver) {
1009 if (device_is_bound(dev)) {
1013 ret = device_bind_driver(dev);
1017 dev->driver = NULL;
1022 .dev = dev,
1027 if (dev->parent)
1028 pm_runtime_get_sync(dev->parent);
1030 ret = bus_for_each_drv(dev->bus, NULL, &data,
1040 dev_dbg(dev, "scheduling asynchronous probe\n");
1041 get_device(dev);
1044 pm_request_idle(dev);
1047 if (dev->parent)
1048 pm_runtime_put(dev->parent);
1051 device_unlock(dev);
1053 async_schedule_dev(__device_attach_async_helper, dev);
1059 * @dev: device.
1069 * When called for a USB interface, @dev->parent lock must be held.
1071 int device_attach(struct device *dev)
1073 return __device_attach(dev, false);
1077 void device_initial_probe(struct device *dev)
1079 __device_attach(dev, true);
1083 * __device_driver_lock - acquire locks needed to manipulate dev->drv
1084 * @dev: Device we will update driver info for
1087 * This function will take the required locks for manipulating dev->drv.
1088 * Normally this will just be the @dev lock, but when called for a USB
1091 static void __device_driver_lock(struct device *dev, struct device *parent)
1093 if (parent && dev->bus->need_parent_lock)
1095 device_lock(dev);
1099 * __device_driver_unlock - release locks needed to manipulate dev->drv
1100 * @dev: Device we will update driver info for
1103 * This function will release the required locks for manipulating dev->drv.
1104 * Normally this will just be the @dev lock, but when called for a
1107 static void __device_driver_unlock(struct device *dev, struct device *parent)
1109 device_unlock(dev);
1110 if (parent && dev->bus->need_parent_lock)
1117 * @dev: Device to attach it to
1119 * Manually attach driver to a device. Will acquire both @dev lock and
1120 * @dev->parent lock if needed. Returns 0 on success, -ERR on failure.
1122 int device_driver_attach(struct device_driver *drv, struct device *dev)
1126 __device_driver_lock(dev, dev->parent);
1127 ret = __driver_probe_device(drv, dev);
1128 __device_driver_unlock(dev, dev->parent);
1141 struct device *dev = _dev;
1145 __device_driver_lock(dev, dev->parent);
1146 drv = dev->p->async_driver;
1147 dev->p->async_driver = NULL;
1148 ret = driver_probe_device(drv, dev);
1149 __device_driver_unlock(dev, dev->parent);
1151 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret);
1153 put_device(dev);
1156 static int __driver_attach(struct device *dev, void *data)
1172 ret = driver_match_device(drv, dev);
1177 dev_dbg(dev, "Device match requests probe deferral\n");
1178 dev->can_match = true;
1179 driver_deferred_probe_add(dev);
1186 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
1200 * that the dev->driver and async_driver fields are protected
1202 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);
1203 device_lock(dev);
1204 if (!dev->driver && !dev->p->async_driver) {
1205 get_device(dev);
1206 dev->p->async_driver = drv;
1209 device_unlock(dev);
1211 async_schedule_dev(__driver_attach_async_helper, dev);
1215 __device_driver_lock(dev, dev->parent);
1216 driver_probe_device(drv, dev);
1217 __device_driver_unlock(dev, dev->parent);
1228 * returns 0 and the @dev->driver is set, we've found a
1238 * __device_release_driver() must be called with @dev lock held.
1239 * When called for a USB interface, @dev->parent lock must be held as well.
1241 static void __device_release_driver(struct device *dev, struct device *parent)
1245 drv = dev->driver;
1247 pm_runtime_get_sync(dev);
1249 while (device_links_busy(dev)) {
1250 __device_driver_unlock(dev, parent);
1252 device_links_unbind_consumers(dev);
1254 __device_driver_lock(dev, parent);
1260 if (dev->driver != drv) {
1261 pm_runtime_put(dev);
1266 driver_sysfs_remove(dev);
1268 bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER);
1270 pm_runtime_put_sync(dev);
1272 device_remove(dev);
1274 if (dev->bus && dev->bus->dma_cleanup)
1275 dev->bus->dma_cleanup(dev);
1277 device_unbind_cleanup(dev);
1278 device_links_driver_cleanup(dev);
1280 klist_remove(&dev->p->knode_driver);
1281 device_pm_check_callbacks(dev);
1283 bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER);
1284 kobject_uevent(&dev->kobj, KOBJ_UNBIND);
1288 void device_release_driver_internal(struct device *dev,
1292 __device_driver_lock(dev, parent);
1294 if (!drv || drv == dev->driver)
1295 __device_release_driver(dev, parent);
1297 __device_driver_unlock(dev, parent);
1302 * @dev: device.
1305 * When called for a USB interface, @dev->parent lock must be held.
1307 * If this function is to be called with @dev->parent lock held, ensure that
1309 * acquired under the @dev->parent lock.
1311 void device_release_driver(struct device *dev)
1318 device_release_driver_internal(dev, NULL, NULL);
1324 * @dev: device to detach driver from
1326 * Detach driver from device. Will acquire both @dev lock and @dev->parent
1329 void device_driver_detach(struct device *dev)
1331 device_release_driver_internal(dev, NULL, dev->parent);
1341 struct device *dev;
1355 dev = dev_prv->device;
1356 get_device(dev);
1358 device_release_driver_internal(dev, drv, dev->parent);
1359 put_device(dev);