Lines Matching refs:dev

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