Lines Matching refs:dev
76 struct device *dev; in deferred_probe_work_func() local
93 typeof(*dev->p), deferred_probe); in deferred_probe_work_func()
94 dev = private->device; in deferred_probe_work_func()
97 get_device(dev); in deferred_probe_work_func()
111 device_pm_move_to_tail(dev); in deferred_probe_work_func()
113 dev_dbg(dev, "Retrying from deferred list\n"); in deferred_probe_work_func()
114 bus_probe_device(dev); in deferred_probe_work_func()
117 put_device(dev); in deferred_probe_work_func()
123 void driver_deferred_probe_add(struct device *dev) in driver_deferred_probe_add() argument
126 if (list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_add()
127 dev_dbg(dev, "Added to deferred list\n"); in driver_deferred_probe_add()
128 list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list); in driver_deferred_probe_add()
133 void driver_deferred_probe_del(struct device *dev) in driver_deferred_probe_del() argument
136 if (!list_empty(&dev->p->deferred_probe)) { in driver_deferred_probe_del()
137 dev_dbg(dev, "Removed from deferred list\n"); in driver_deferred_probe_del()
138 list_del_init(&dev->p->deferred_probe); in driver_deferred_probe_del()
238 static int __driver_deferred_probe_check_state(struct device *dev) in __driver_deferred_probe_check_state() argument
244 dev_WARN(dev, "deferred probe timeout, ignoring dependency"); in __driver_deferred_probe_check_state()
262 int driver_deferred_probe_check_state(struct device *dev) in driver_deferred_probe_check_state() argument
266 ret = __driver_deferred_probe_check_state(dev); in driver_deferred_probe_check_state()
270 dev_warn(dev, "ignoring dependency for device, assuming no driver"); in driver_deferred_probe_check_state()
290 int driver_deferred_probe_check_state_continue(struct device *dev) in driver_deferred_probe_check_state_continue() argument
294 ret = __driver_deferred_probe_check_state(dev); in driver_deferred_probe_check_state_continue()
362 bool device_is_bound(struct device *dev) in device_is_bound() argument
364 return dev->p && klist_node_attached(&dev->p->knode_driver); in device_is_bound()
367 static void driver_bound(struct device *dev) in driver_bound() argument
369 if (device_is_bound(dev)) { in driver_bound()
371 __func__, kobject_name(&dev->kobj)); in driver_bound()
375 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->driver->name, in driver_bound()
376 __func__, dev_name(dev)); in driver_bound()
378 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); in driver_bound()
379 device_links_driver_bound(dev); in driver_bound()
381 device_pm_check_callbacks(dev); in driver_bound()
387 driver_deferred_probe_del(dev); in driver_bound()
390 if (dev->bus) in driver_bound()
391 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_bound()
392 BUS_NOTIFY_BOUND_DRIVER, dev); in driver_bound()
394 kobject_uevent(&dev->kobj, KOBJ_BIND); in driver_bound()
397 static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, in coredump_store() argument
400 device_lock(dev); in coredump_store()
401 dev->driver->coredump(dev); in coredump_store()
402 device_unlock(dev); in coredump_store()
408 static int driver_sysfs_add(struct device *dev) in driver_sysfs_add() argument
412 if (dev->bus) in driver_sysfs_add()
413 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in driver_sysfs_add()
414 BUS_NOTIFY_BIND_DRIVER, dev); in driver_sysfs_add()
416 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj, in driver_sysfs_add()
417 kobject_name(&dev->kobj)); in driver_sysfs_add()
421 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj, in driver_sysfs_add()
426 if (!IS_ENABLED(CONFIG_DEV_COREDUMP) || !dev->driver->coredump || in driver_sysfs_add()
427 !device_create_file(dev, &dev_attr_coredump)) in driver_sysfs_add()
430 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_add()
433 sysfs_remove_link(&dev->driver->p->kobj, in driver_sysfs_add()
434 kobject_name(&dev->kobj)); in driver_sysfs_add()
440 static void driver_sysfs_remove(struct device *dev) in driver_sysfs_remove() argument
442 struct device_driver *drv = dev->driver; in driver_sysfs_remove()
446 device_remove_file(dev, &dev_attr_coredump); in driver_sysfs_remove()
447 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj)); in driver_sysfs_remove()
448 sysfs_remove_link(&dev->kobj, "driver"); in driver_sysfs_remove()
466 int device_bind_driver(struct device *dev) in device_bind_driver() argument
470 ret = driver_sysfs_add(dev); in device_bind_driver()
472 driver_bound(dev); in device_bind_driver()
473 else if (dev->bus) in device_bind_driver()
474 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in device_bind_driver()
475 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in device_bind_driver()
483 static void driver_deferred_probe_add_trigger(struct device *dev, in driver_deferred_probe_add_trigger() argument
486 driver_deferred_probe_add(dev); in driver_deferred_probe_add_trigger()
492 static int really_probe(struct device *dev, struct device_driver *drv) in really_probe() argument
505 dev_dbg(dev, "Driver %s force probe deferral\n", drv->name); in really_probe()
506 driver_deferred_probe_add(dev); in really_probe()
510 ret = device_links_check_suppliers(dev); in really_probe()
512 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
518 drv->bus->name, __func__, drv->name, dev_name(dev)); in really_probe()
519 WARN_ON(!list_empty(&dev->devres_head)); in really_probe()
522 dev->driver = drv; in really_probe()
525 ret = pinctrl_bind_pins(dev); in really_probe()
529 if (dev->bus->dma_configure) { in really_probe()
530 ret = dev->bus->dma_configure(dev); in really_probe()
535 if (driver_sysfs_add(dev)) { in really_probe()
537 __func__, dev_name(dev)); in really_probe()
541 if (dev->pm_domain && dev->pm_domain->activate) { in really_probe()
542 ret = dev->pm_domain->activate(dev); in really_probe()
547 if (dev->bus->probe) { in really_probe()
548 ret = dev->bus->probe(dev); in really_probe()
552 ret = drv->probe(dev); in really_probe()
557 if (device_add_groups(dev, drv->dev_groups)) { in really_probe()
558 dev_err(dev, "device_add_groups() failed\n"); in really_probe()
565 device_remove_groups(dev, drv->dev_groups); in really_probe()
567 if (dev->bus->remove) in really_probe()
568 dev->bus->remove(dev); in really_probe()
570 drv->remove(dev); in really_probe()
572 devres_release_all(dev); in really_probe()
573 driver_sysfs_remove(dev); in really_probe()
574 dev->driver = NULL; in really_probe()
575 dev_set_drvdata(dev, NULL); in really_probe()
576 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
577 dev->pm_domain->dismiss(dev); in really_probe()
578 pm_runtime_reinit(dev); in really_probe()
583 pinctrl_init_done(dev); in really_probe()
585 if (dev->pm_domain && dev->pm_domain->sync) in really_probe()
586 dev->pm_domain->sync(dev); in really_probe()
588 driver_bound(dev); in really_probe()
591 drv->bus->name, __func__, dev_name(dev), drv->name); in really_probe()
595 if (dev->bus->remove) in really_probe()
596 dev->bus->remove(dev); in really_probe()
598 drv->remove(dev); in really_probe()
600 if (dev->bus) in really_probe()
601 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in really_probe()
602 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); in really_probe()
604 device_links_no_driver(dev); in really_probe()
605 devres_release_all(dev); in really_probe()
606 arch_teardown_dma_ops(dev); in really_probe()
607 driver_sysfs_remove(dev); in really_probe()
608 dev->driver = NULL; in really_probe()
609 dev_set_drvdata(dev, NULL); in really_probe()
610 if (dev->pm_domain && dev->pm_domain->dismiss) in really_probe()
611 dev->pm_domain->dismiss(dev); in really_probe()
612 pm_runtime_reinit(dev); in really_probe()
613 dev_pm_set_driver_flags(dev, 0); in really_probe()
618 dev_dbg(dev, "Driver %s requests probe deferral\n", drv->name); in really_probe()
619 driver_deferred_probe_add_trigger(dev, local_trigger_count); in really_probe()
624 drv->name, dev_name(dev), ret); in really_probe()
630 drv->name, dev_name(dev), ret); in really_probe()
646 static int really_probe_debug(struct device *dev, struct device_driver *drv) in really_probe_debug() argument
652 ret = really_probe(dev, drv); in really_probe_debug()
656 dev_name(dev), ret, (s64) ktime_to_us(delta)); in really_probe_debug()
703 int driver_probe_device(struct device_driver *drv, struct device *dev) in driver_probe_device() argument
707 if (!device_is_registered(dev)) in driver_probe_device()
711 drv->bus->name, __func__, dev_name(dev), drv->name); in driver_probe_device()
713 pm_runtime_get_suppliers(dev); in driver_probe_device()
714 if (dev->parent) in driver_probe_device()
715 pm_runtime_get_sync(dev->parent); in driver_probe_device()
717 pm_runtime_barrier(dev); in driver_probe_device()
719 ret = really_probe_debug(dev, drv); in driver_probe_device()
721 ret = really_probe(dev, drv); in driver_probe_device()
722 pm_request_idle(dev); in driver_probe_device()
724 if (dev->parent) in driver_probe_device()
725 pm_runtime_put(dev->parent); in driver_probe_device()
727 pm_runtime_put_suppliers(dev); in driver_probe_device()
769 struct device *dev; member
804 struct device *dev = data->dev; in __device_attach_driver() local
808 ret = driver_match_device(drv, dev); in __device_attach_driver()
813 dev_dbg(dev, "Device match requests probe deferral\n"); in __device_attach_driver()
814 driver_deferred_probe_add(dev); in __device_attach_driver()
816 dev_dbg(dev, "Bus failed to match device: %d", ret); in __device_attach_driver()
828 return driver_probe_device(drv, dev); in __device_attach_driver()
833 struct device *dev = _dev; in __device_attach_async_helper() local
835 .dev = dev, in __device_attach_async_helper()
840 device_lock(dev); in __device_attach_async_helper()
848 if (dev->p->dead || dev->driver) in __device_attach_async_helper()
851 if (dev->parent) in __device_attach_async_helper()
852 pm_runtime_get_sync(dev->parent); in __device_attach_async_helper()
854 bus_for_each_drv(dev->bus, NULL, &data, __device_attach_driver); in __device_attach_async_helper()
855 dev_dbg(dev, "async probe completed\n"); in __device_attach_async_helper()
857 pm_request_idle(dev); in __device_attach_async_helper()
859 if (dev->parent) in __device_attach_async_helper()
860 pm_runtime_put(dev->parent); in __device_attach_async_helper()
862 device_unlock(dev); in __device_attach_async_helper()
864 put_device(dev); in __device_attach_async_helper()
867 static int __device_attach(struct device *dev, bool allow_async) in __device_attach() argument
871 device_lock(dev); in __device_attach()
872 if (dev->driver) { in __device_attach()
873 if (device_is_bound(dev)) { in __device_attach()
877 ret = device_bind_driver(dev); in __device_attach()
881 dev->driver = NULL; in __device_attach()
886 .dev = dev, in __device_attach()
891 if (dev->parent) in __device_attach()
892 pm_runtime_get_sync(dev->parent); in __device_attach()
894 ret = bus_for_each_drv(dev->bus, NULL, &data, in __device_attach()
904 dev_dbg(dev, "scheduling asynchronous probe\n"); in __device_attach()
905 get_device(dev); in __device_attach()
906 async_schedule_dev(__device_attach_async_helper, dev); in __device_attach()
908 pm_request_idle(dev); in __device_attach()
911 if (dev->parent) in __device_attach()
912 pm_runtime_put(dev->parent); in __device_attach()
915 device_unlock(dev); in __device_attach()
933 int device_attach(struct device *dev) in device_attach() argument
935 return __device_attach(dev, false); in device_attach()
939 void device_initial_probe(struct device *dev) in device_initial_probe() argument
941 __device_attach(dev, true); in device_initial_probe()
953 static void __device_driver_lock(struct device *dev, struct device *parent) in __device_driver_lock() argument
955 if (parent && dev->bus->need_parent_lock) in __device_driver_lock()
957 device_lock(dev); in __device_driver_lock()
969 static void __device_driver_unlock(struct device *dev, struct device *parent) in __device_driver_unlock() argument
971 device_unlock(dev); in __device_driver_unlock()
972 if (parent && dev->bus->need_parent_lock) in __device_driver_unlock()
984 int device_driver_attach(struct device_driver *drv, struct device *dev) in device_driver_attach() argument
988 __device_driver_lock(dev, dev->parent); in device_driver_attach()
994 if (!dev->p->dead && !dev->driver) in device_driver_attach()
995 ret = driver_probe_device(drv, dev); in device_driver_attach()
997 __device_driver_unlock(dev, dev->parent); in device_driver_attach()
1004 struct device *dev = _dev; in __driver_attach_async_helper() local
1008 __device_driver_lock(dev, dev->parent); in __driver_attach_async_helper()
1010 drv = dev->p->async_driver; in __driver_attach_async_helper()
1016 if (!dev->p->dead && !dev->driver) in __driver_attach_async_helper()
1017 ret = driver_probe_device(drv, dev); in __driver_attach_async_helper()
1019 __device_driver_unlock(dev, dev->parent); in __driver_attach_async_helper()
1021 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); in __driver_attach_async_helper()
1023 put_device(dev); in __driver_attach_async_helper()
1026 static int __driver_attach(struct device *dev, void *data) in __driver_attach() argument
1041 ret = driver_match_device(drv, dev); in __driver_attach()
1046 dev_dbg(dev, "Device match requests probe deferral\n"); in __driver_attach()
1047 driver_deferred_probe_add(dev); in __driver_attach()
1049 dev_dbg(dev, "Bus failed to match device: %d", ret); in __driver_attach()
1061 dev_dbg(dev, "probing driver %s asynchronously\n", drv->name); in __driver_attach()
1062 device_lock(dev); in __driver_attach()
1063 if (!dev->driver) { in __driver_attach()
1064 get_device(dev); in __driver_attach()
1065 dev->p->async_driver = drv; in __driver_attach()
1066 async_schedule_dev(__driver_attach_async_helper, dev); in __driver_attach()
1068 device_unlock(dev); in __driver_attach()
1072 device_driver_attach(drv, dev); in __driver_attach()
1096 static void __device_release_driver(struct device *dev, struct device *parent) in __device_release_driver() argument
1100 drv = dev->driver; in __device_release_driver()
1102 while (device_links_busy(dev)) { in __device_release_driver()
1103 __device_driver_unlock(dev, parent); in __device_release_driver()
1105 device_links_unbind_consumers(dev); in __device_release_driver()
1107 __device_driver_lock(dev, parent); in __device_release_driver()
1113 if (dev->driver != drv) in __device_release_driver()
1117 pm_runtime_get_sync(dev); in __device_release_driver()
1118 pm_runtime_clean_up_links(dev); in __device_release_driver()
1120 driver_sysfs_remove(dev); in __device_release_driver()
1122 if (dev->bus) in __device_release_driver()
1123 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1125 dev); in __device_release_driver()
1127 pm_runtime_put_sync(dev); in __device_release_driver()
1129 device_remove_groups(dev, drv->dev_groups); in __device_release_driver()
1131 if (dev->bus && dev->bus->remove) in __device_release_driver()
1132 dev->bus->remove(dev); in __device_release_driver()
1134 drv->remove(dev); in __device_release_driver()
1136 device_links_driver_cleanup(dev); in __device_release_driver()
1138 devres_release_all(dev); in __device_release_driver()
1139 arch_teardown_dma_ops(dev); in __device_release_driver()
1140 dev->driver = NULL; in __device_release_driver()
1141 dev_set_drvdata(dev, NULL); in __device_release_driver()
1142 if (dev->pm_domain && dev->pm_domain->dismiss) in __device_release_driver()
1143 dev->pm_domain->dismiss(dev); in __device_release_driver()
1144 pm_runtime_reinit(dev); in __device_release_driver()
1145 dev_pm_set_driver_flags(dev, 0); in __device_release_driver()
1147 klist_remove(&dev->p->knode_driver); in __device_release_driver()
1148 device_pm_check_callbacks(dev); in __device_release_driver()
1149 if (dev->bus) in __device_release_driver()
1150 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, in __device_release_driver()
1152 dev); in __device_release_driver()
1154 kobject_uevent(&dev->kobj, KOBJ_UNBIND); in __device_release_driver()
1158 void device_release_driver_internal(struct device *dev, in device_release_driver_internal() argument
1162 __device_driver_lock(dev, parent); in device_release_driver_internal()
1164 if (!drv || drv == dev->driver) in device_release_driver_internal()
1165 __device_release_driver(dev, parent); in device_release_driver_internal()
1167 __device_driver_unlock(dev, parent); in device_release_driver_internal()
1181 void device_release_driver(struct device *dev) in device_release_driver() argument
1188 device_release_driver_internal(dev, NULL, NULL); in device_release_driver()
1199 void device_driver_detach(struct device *dev) in device_driver_detach() argument
1201 device_release_driver_internal(dev, NULL, dev->parent); in device_driver_detach()
1211 struct device *dev; in driver_detach() local
1225 dev = dev_prv->device; in driver_detach()
1226 get_device(dev); in driver_detach()
1228 device_release_driver_internal(dev, drv, dev->parent); in driver_detach()
1229 put_device(dev); in driver_detach()