Lines Matching refs:dev
73 static void __device_set_deferred_probe_reason(const struct device *dev, char *reason)
75 kfree(dev->p->deferred_probe_reason);
76 dev->p->deferred_probe_reason = reason;
84 struct device *dev;
101 typeof(*dev->p), deferred_probe);
102 dev = private->device;
105 get_device(dev);
107 __device_set_deferred_probe_reason(dev, NULL);
121 device_pm_move_to_tail(dev);
123 dev_dbg(dev, "Retrying from deferred list\n");
124 bus_probe_device(dev);
127 put_device(dev);
133 void driver_deferred_probe_add(struct device *dev)
135 if (!dev->can_match)
139 if (list_empty(&dev->p->deferred_probe)) {
140 dev_dbg(dev, "Added to deferred list\n");
141 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
146 void driver_deferred_probe_del(struct device *dev)
149 if (!list_empty(&dev->p->deferred_probe)) {
150 dev_dbg(dev, "Removed from deferred list\n");
151 list_del_init(&dev->p->deferred_probe);
152 __device_set_deferred_probe_reason(dev, NULL);
225 * @dev: the pointer to the struct device
228 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf)
230 const char *drv = dev_driver_string(dev);
236 __device_set_deferred_probe_reason(dev, reason);
278 * @dev: device to check
289 int driver_deferred_probe_check_state(struct device *dev)
292 dev_warn(dev, "ignoring dependency for device, assuming no driver\n");
297 dev_warn(dev, "deferred probe timeout, ignoring dependency\n");
386 * @dev: device to check
393 bool device_is_bound(struct device *dev)
395 return dev->p && klist_node_attached(&dev->p->knode_driver);
399 static void driver_bound(struct device *dev)
401 if (device_is_bound(dev)) {
402 dev_warn(dev, "%s: device already bound\n", __func__);
406 dev_dbg(dev, "driver: '%s': %s: bound to device\n", dev->driver->name,
409 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
410 device_links_driver_bound(dev);
412 device_pm_check_callbacks(dev);
418 driver_deferred_probe_del(dev);
421 bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER);
422 kobject_uevent(&dev->kobj, KOBJ_BIND);
425 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr,
428 device_lock(dev);
429 dev->driver->coredump(dev);
430 device_unlock(dev);
436 static int driver_sysfs_add(struct device *dev)
440 bus_notify(dev, BUS_NOTIFY_BIND_DRIVER);
442 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
443 kobject_name(&dev->kobj));
447 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
452 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump)
455 ret = device_create_file(dev, &dev_attr_coredump);
459 sysfs_remove_link(&dev->kobj, "driver");
462 sysfs_remove_link(&dev->driver->p->kobj,
463 kobject_name(&dev->kobj));
469 static void driver_sysfs_remove(struct device *dev)
471 struct device_driver *drv = dev->driver;
475 device_remove_file(dev, &dev_attr_coredump);
476 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
477 sysfs_remove_link(&dev->kobj, "driver");
483 * @dev: device.
486 * Caller must have already set @dev->driver.
496 int device_bind_driver(struct device *dev)
500 ret = driver_sysfs_add(dev);
502 device_links_force_bind(dev);
503 driver_bound(dev);
506 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
514 static ssize_t state_synced_store(struct device *dev,
523 device_lock(dev);
524 if (!dev->state_synced) {
525 dev->state_synced = true;
526 dev_sync_state(dev);
530 device_unlock(dev);
535 static ssize_t state_synced_show(struct device *dev,
540 device_lock(dev);
541 val = dev->state_synced;
542 device_unlock(dev);
548 static void device_unbind_cleanup(struct device *dev)
550 devres_release_all(dev);
551 arch_teardown_dma_ops(dev);
552 kfree(dev->dma_range_map);
553 dev->dma_range_map = NULL;
554 device_set_driver(dev, NULL);
555 dev_set_drvdata(dev, NULL);
556 dev_pm_domain_detach(dev, dev->power.detach_power_off);
557 if (dev->pm_domain && dev->pm_domain->dismiss)
558 dev->pm_domain->dismiss(dev);
559 pm_runtime_reinit(dev);
560 dev_pm_set_driver_flags(dev, 0);
563 static void device_remove(struct device *dev)
565 device_remove_file(dev, &dev_attr_state_synced);
566 device_remove_groups(dev, dev->driver->dev_groups);
568 if (dev->bus && dev->bus->remove)
569 dev->bus->remove(dev);
570 else if (dev->driver->remove)
571 dev->driver->remove(dev);
574 static int call_driver_probe(struct device *dev, const struct device_driver *drv)
578 if (dev->bus->probe)
579 ret = dev->bus->probe(dev);
581 ret = drv->probe(dev);
588 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name);
592 dev_dbg(dev, "probe with driver %s rejects match %d\n",
597 dev_err(dev, "probe with driver %s failed with error %d\n",
605 static int really_probe(struct device *dev, const struct device_driver *drv)
617 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name);
621 link_ret = device_links_check_suppliers(dev);
625 dev_dbg(dev, "bus: '%s': %s: probing driver %s with device\n",
627 if (!list_empty(&dev->devres_head)) {
628 dev_crit(dev, "Resources present before probing\n");
634 device_set_driver(dev, drv);
637 ret = pinctrl_bind_pins(dev);
641 if (dev->bus->dma_configure) {
642 ret = dev->bus->dma_configure(dev);
647 ret = driver_sysfs_add(dev);
649 dev_err(dev, "%s: driver_sysfs_add failed\n", __func__);
653 if (dev->pm_domain && dev->pm_domain->activate) {
654 ret = dev->pm_domain->activate(dev);
659 ret = call_driver_probe(dev, drv);
678 ret = device_add_groups(dev, drv->dev_groups);
680 dev_err(dev, "device_add_groups() failed\n");
684 if (dev_has_sync_state(dev)) {
685 ret = device_create_file(dev, &dev_attr_state_synced);
687 dev_err(dev, "state_synced sysfs add failed\n");
695 device_remove(dev);
696 driver_sysfs_remove(dev);
697 if (dev->bus && dev->bus->dma_cleanup)
698 dev->bus->dma_cleanup(dev);
699 device_unbind_cleanup(dev);
704 pinctrl_init_done(dev);
706 if (dev->pm_domain && dev->pm_domain->sync)
707 dev->pm_domain->sync(dev);
709 driver_bound(dev);
710 dev_dbg(dev, "bus: '%s': %s: bound device to driver %s\n",
716 device_remove(dev);
718 driver_sysfs_remove(dev);
720 bus_notify(dev, BUS_NOTIFY_DRIVER_NOT_BOUND);
721 if (dev->bus && dev->bus->dma_cleanup)
722 dev->bus->dma_cleanup(dev);
724 device_links_no_driver(dev);
725 device_unbind_cleanup(dev);
733 static int really_probe_debug(struct device *dev, const struct device_driver *drv)
739 ret = really_probe(dev, drv);
747 dev_name(dev), ret, ktime_us_delta(rettime, calltime));
780 static int __driver_probe_device(const struct device_driver *drv, struct device *dev)
784 if (dev->p->dead || !device_is_registered(dev))
786 if (dev->driver)
789 dev->can_match = true;
790 dev_dbg(dev, "bus: '%s': %s: matched device with driver %s\n",
793 pm_runtime_get_suppliers(dev);
794 if (dev->parent)
795 pm_runtime_get_sync(dev->parent);
797 pm_runtime_barrier(dev);
799 ret = really_probe_debug(dev, drv);
801 ret = really_probe(dev, drv);
802 pm_request_idle(dev);
804 if (dev->parent)
805 pm_runtime_put(dev->parent);
807 pm_runtime_put_suppliers(dev);
814 * @dev: device to try to bind to the driver
820 * This function must be called with @dev lock held. When called for a
821 * USB interface, @dev->parent lock must be held as well.
825 static int driver_probe_device(const struct device_driver *drv, struct device *dev)
831 ret = __driver_probe_device(drv, dev);
833 driver_deferred_probe_add(dev);
890 struct device *dev;
925 struct device *dev = data->dev;
929 ret = driver_match_device(drv, dev);
934 dev_dbg(dev, "Device match requests probe deferral\n");
935 dev->can_match = true;
936 driver_deferred_probe_add(dev);
943 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
959 ret = driver_probe_device(drv, dev);
967 struct device *dev = _dev;
969 .dev = dev,
974 device_lock(dev);
982 if (dev->p->dead || dev->driver)
985 if (dev->parent)
986 pm_runtime_get_sync(dev->parent);
988 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver);
989 dev_dbg(dev, "async probe completed\n");
991 pm_request_idle(dev);
993 if (dev->parent)
994 pm_runtime_put(dev->parent);
996 device_unlock(dev);
998 put_device(dev);
1001 static int __device_attach(struct device *dev, bool allow_async)
1006 device_lock(dev);
1007 if (dev->p->dead) {
1009 } else if (dev->driver) {
1010 if (device_is_bound(dev)) {
1014 ret = device_bind_driver(dev);
1018 device_set_driver(dev, NULL);
1023 .dev = dev,
1028 if (dev->parent)
1029 pm_runtime_get_sync(dev->parent);
1031 ret = bus_for_each_drv(dev->bus, NULL, &data,
1041 dev_dbg(dev, "scheduling asynchronous probe\n");
1042 get_device(dev);
1045 pm_request_idle(dev);
1048 if (dev->parent)
1049 pm_runtime_put(dev->parent);
1052 device_unlock(dev);
1054 async_schedule_dev(__device_attach_async_helper, dev);
1060 * @dev: device.
1070 * When called for a USB interface, @dev->parent lock must be held.
1072 int device_attach(struct device *dev)
1074 return __device_attach(dev, false);
1078 void device_initial_probe(struct device *dev)
1080 __device_attach(dev, true);
1084 * __device_driver_lock - acquire locks needed to manipulate dev->drv
1085 * @dev: Device we will update driver info for
1088 * This function will take the required locks for manipulating dev->drv.
1089 * Normally this will just be the @dev lock, but when called for a USB
1092 static void __device_driver_lock(struct device *dev, struct device *parent)
1094 if (parent && dev->bus->need_parent_lock)
1096 device_lock(dev);
1100 * __device_driver_unlock - release locks needed to manipulate dev->drv
1101 * @dev: Device we will update driver info for
1104 * This function will release the required locks for manipulating dev->drv.
1105 * Normally this will just be the @dev lock, but when called for a
1108 static void __device_driver_unlock(struct device *dev, struct device *parent)
1110 device_unlock(dev);
1111 if (parent && dev->bus->need_parent_lock)
1118 * @dev: Device to attach it to
1120 * Manually attach driver to a device. Will acquire both @dev lock and
1121 * @dev->parent lock if needed. Returns 0 on success, -ERR on failure.
1123 int device_driver_attach(const struct device_driver *drv, struct device *dev)
1127 __device_driver_lock(dev, dev->parent);
1128 ret = __driver_probe_device(drv, dev);
1129 __device_driver_unlock(dev, dev->parent);
1142 struct device *dev = _dev;
1146 __device_driver_lock(dev, dev->parent);
1147 drv = dev->p->async_driver;
1148 dev->p->async_driver = NULL;
1149 ret = driver_probe_device(drv, dev);
1150 __device_driver_unlock(dev, dev->parent);
1152 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret);
1154 put_device(dev);
1157 static int __driver_attach(struct device *dev, void *data)
1173 ret = driver_match_device(drv, dev);
1178 dev_dbg(dev, "Device match requests probe deferral\n");
1179 dev->can_match = true;
1180 driver_deferred_probe_add(dev);
1187 dev_dbg(dev, "Bus failed to match device: %d\n", ret);
1201 * that the dev->driver and async_driver fields are protected
1203 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name);
1204 device_lock(dev);
1205 if (!dev->driver && !dev->p->async_driver) {
1206 get_device(dev);
1207 dev->p->async_driver = drv;
1210 device_unlock(dev);
1212 async_schedule_dev(__driver_attach_async_helper, dev);
1216 __device_driver_lock(dev, dev->parent);
1217 driver_probe_device(drv, dev);
1218 __device_driver_unlock(dev, dev->parent);
1229 * returns 0 and the @dev->driver is set, we've found a
1240 * __device_release_driver() must be called with @dev lock held.
1241 * When called for a USB interface, @dev->parent lock must be held as well.
1243 static void __device_release_driver(struct device *dev, struct device *parent)
1247 drv = dev->driver;
1249 pm_runtime_get_sync(dev);
1251 while (device_links_busy(dev)) {
1252 __device_driver_unlock(dev, parent);
1254 device_links_unbind_consumers(dev);
1256 __device_driver_lock(dev, parent);
1262 if (dev->driver != drv) {
1263 pm_runtime_put(dev);
1268 driver_sysfs_remove(dev);
1270 bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER);
1272 pm_runtime_put_sync(dev);
1274 device_remove(dev);
1276 if (dev->bus && dev->bus->dma_cleanup)
1277 dev->bus->dma_cleanup(dev);
1279 device_unbind_cleanup(dev);
1280 device_links_driver_cleanup(dev);
1282 klist_remove(&dev->p->knode_driver);
1283 device_pm_check_callbacks(dev);
1285 bus_notify(dev, BUS_NOTIFY_UNBOUND_DRIVER);
1286 kobject_uevent(&dev->kobj, KOBJ_UNBIND);
1290 void device_release_driver_internal(struct device *dev,
1294 __device_driver_lock(dev, parent);
1296 if (!drv || drv == dev->driver)
1297 __device_release_driver(dev, parent);
1299 __device_driver_unlock(dev, parent);
1304 * @dev: device.
1307 * When called for a USB interface, @dev->parent lock must be held.
1309 * If this function is to be called with @dev->parent lock held, ensure that
1311 * acquired under the @dev->parent lock.
1313 void device_release_driver(struct device *dev)
1320 device_release_driver_internal(dev, NULL, NULL);
1326 * @dev: device to detach driver from
1328 * Detach driver from device. Will acquire both @dev lock and @dev->parent
1331 void device_driver_detach(struct device *dev)
1333 device_release_driver_internal(dev, NULL, dev->parent);
1343 struct device *dev;
1357 dev = dev_prv->device;
1358 get_device(dev);
1360 device_release_driver_internal(dev, drv, dev->parent);
1361 put_device(dev);