Lines Matching +full:drv +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 1999-2004 Vojtech Pavlik
40 static void serio_attach_driver(struct serio_driver *drv);
42 static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) in serio_connect_driver() argument
46 mutex_lock(&serio->drv_mutex); in serio_connect_driver()
47 retval = drv->connect(serio, drv); in serio_connect_driver()
48 mutex_unlock(&serio->drv_mutex); in serio_connect_driver()
55 int retval = -1; in serio_reconnect_driver()
57 mutex_lock(&serio->drv_mutex); in serio_reconnect_driver()
58 if (serio->drv && serio->drv->reconnect) in serio_reconnect_driver()
59 retval = serio->drv->reconnect(serio); in serio_reconnect_driver()
60 mutex_unlock(&serio->drv_mutex); in serio_reconnect_driver()
67 mutex_lock(&serio->drv_mutex); in serio_disconnect_driver()
68 if (serio->drv) in serio_disconnect_driver()
69 serio->drv->disconnect(serio); in serio_disconnect_driver()
70 mutex_unlock(&serio->drv_mutex); in serio_disconnect_driver()
75 while (ids->type || ids->proto) { in serio_match_port()
76 if ((ids->type == SERIO_ANY || ids->type == serio->id.type) && in serio_match_port()
77 (ids->proto == SERIO_ANY || ids->proto == serio->id.proto) && in serio_match_port()
78 (ids->extra == SERIO_ANY || ids->extra == serio->id.extra) && in serio_match_port()
79 (ids->id == SERIO_ANY || ids->id == serio->id.id)) in serio_match_port()
87 * Basic serio -> driver core mappings
90 static int serio_bind_driver(struct serio *serio, struct serio_driver *drv) in serio_bind_driver() argument
94 if (serio_match_port(drv->id_table, serio)) { in serio_bind_driver()
96 serio->dev.driver = &drv->driver; in serio_bind_driver()
97 if (serio_connect_driver(serio, drv)) { in serio_bind_driver()
98 serio->dev.driver = NULL; in serio_bind_driver()
99 return -ENODEV; in serio_bind_driver()
102 error = device_bind_driver(&serio->dev); in serio_bind_driver()
104 dev_warn(&serio->dev, in serio_bind_driver()
106 serio->phys, serio->name, in serio_bind_driver()
107 drv->description, error); in serio_bind_driver()
109 serio->dev.driver = NULL; in serio_bind_driver()
120 error = device_attach(&serio->dev); in serio_find_driver()
121 if (error < 0 && error != -EPROBE_DEFER) in serio_find_driver()
122 dev_warn(&serio->dev, in serio_find_driver()
124 serio->phys, serio->name, error); in serio_find_driver()
160 list_del_init(&event->node); in serio_get_event()
169 module_put(event->owner); in serio_free_event()
182 if (object == e->object) { in serio_remove_duplicate_events()
185 * look further - we only suppress duplicate events in serio_remove_duplicate_events()
186 * that were sent back-to-back. in serio_remove_duplicate_events()
188 if (type != e->type) in serio_remove_duplicate_events()
191 list_del_init(&e->node); in serio_remove_duplicate_events()
207 switch (event->type) { in serio_handle_event()
210 serio_add_port(event->object); in serio_handle_event()
214 serio_reconnect_port(event->object); in serio_handle_event()
218 serio_disconnect_port(event->object); in serio_handle_event()
219 serio_find_driver(event->object); in serio_handle_event()
223 serio_reconnect_subtree(event->object); in serio_handle_event()
227 serio_attach_driver(event->object); in serio_handle_event()
231 serio_remove_duplicate_events(event->object, event->type); in serio_handle_event()
257 if (event->object == object) { in serio_queue_event()
258 if (event->type == event_type) in serio_queue_event()
267 retval = -ENOMEM; in serio_queue_event()
275 retval = -EINVAL; in serio_queue_event()
279 event->type = event_type; in serio_queue_event()
280 event->object = object; in serio_queue_event()
281 event->owner = owner; in serio_queue_event()
283 list_add_tail(&event->node, &serio_event_list); in serio_queue_event()
303 if (event->object == object) { in serio_remove_pending_events()
304 list_del_init(&event->node); in serio_remove_pending_events()
327 if (event->type == SERIO_REGISTER_PORT) { in serio_get_pending_child()
328 serio = event->object; in serio_get_pending_child()
329 if (serio->parent == parent) { in serio_get_pending_child()
347 return sprintf(buf, "%s\n", serio->name); in serio_show_description()
355 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra); in modalias_show()
361 return sprintf(buf, "%02x\n", serio->id.type); in type_show()
367 return sprintf(buf, "%02x\n", serio->id.proto); in proto_show()
373 return sprintf(buf, "%02x\n", serio->id.id); in id_show()
379 return sprintf(buf, "%02x\n", serio->id.extra); in extra_show()
385 struct device_driver *drv; in drvctl_store() local
400 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { in drvctl_store()
402 error = serio_bind_driver(serio, to_serio_driver(drv)); in drvctl_store()
405 error = -EINVAL; in drvctl_store()
416 return sprintf(buf, "%s\n", serio->manual_bind ? "manual" : "auto"); in serio_show_bind_mode()
426 serio->manual_bind = true; in serio_set_bind_mode()
428 serio->manual_bind = false; in serio_set_bind_mode()
430 retval = -EINVAL; in serio_set_bind_mode()
440 return sprintf(buf, "%s\n", serio->firmware_id); in firmware_id_show()
445 static DEVICE_ATTR_RO(id);
457 .name = "id",
499 static atomic_t serio_no = ATOMIC_INIT(-1); in serio_init_port()
503 INIT_LIST_HEAD(&serio->node); in serio_init_port()
504 INIT_LIST_HEAD(&serio->child_node); in serio_init_port()
505 INIT_LIST_HEAD(&serio->children); in serio_init_port()
506 spin_lock_init(&serio->lock); in serio_init_port()
507 mutex_init(&serio->drv_mutex); in serio_init_port()
508 device_initialize(&serio->dev); in serio_init_port()
509 dev_set_name(&serio->dev, "serio%lu", in serio_init_port()
511 serio->dev.bus = &serio_bus; in serio_init_port()
512 serio->dev.release = serio_release_port; in serio_init_port()
513 serio->dev.groups = serio_device_attr_groups; in serio_init_port()
514 if (serio->parent) { in serio_init_port()
515 serio->dev.parent = &serio->parent->dev; in serio_init_port()
516 serio->depth = serio->parent->depth + 1; in serio_init_port()
518 serio->depth = 0; in serio_init_port()
519 lockdep_set_subclass(&serio->lock, serio->depth); in serio_init_port()
528 struct serio *parent = serio->parent; in serio_add_port()
533 list_add_tail(&serio->child_node, &parent->children); in serio_add_port()
537 list_add_tail(&serio->node, &serio_list); in serio_add_port()
539 if (serio->start) in serio_add_port()
540 serio->start(serio); in serio_add_port()
542 error = device_add(&serio->dev); in serio_add_port()
544 dev_err(&serio->dev, in serio_add_port()
546 serio->phys, serio->name, error); in serio_add_port()
559 put_device(&child->dev); in serio_destroy_port()
562 if (serio->stop) in serio_destroy_port()
563 serio->stop(serio); in serio_destroy_port()
565 if (serio->parent) { in serio_destroy_port()
566 serio_pause_rx(serio->parent); in serio_destroy_port()
567 list_del_init(&serio->child_node); in serio_destroy_port()
568 serio_continue_rx(serio->parent); in serio_destroy_port()
569 serio->parent = NULL; in serio_destroy_port()
572 if (device_is_registered(&serio->dev)) in serio_destroy_port()
573 device_del(&serio->dev); in serio_destroy_port()
575 list_del_init(&serio->node); in serio_destroy_port()
577 put_device(&serio->dev); in serio_destroy_port()
581 * Reconnect serio port (re-initialize attached device).
599 * Reconnect serio port and all its children (re-initialize attached
614 if (!list_empty(&s->children)) { in serio_reconnect_subtree()
615 s = list_first_entry(&s->children, in serio_reconnect_subtree()
627 struct serio *parent = s->parent; in serio_reconnect_subtree()
629 if (!list_is_last(&s->child_node, &parent->children)) { in serio_reconnect_subtree()
630 s = list_entry(s->child_node.next, in serio_reconnect_subtree()
650 * first; we travel the tree in depth-first order. in serio_disconnect_port()
652 while (!list_empty(&serio->children)) { in serio_disconnect_port()
655 while (!list_empty(&s->children)) in serio_disconnect_port()
656 s = list_first_entry(&s->children, in serio_disconnect_port()
664 struct serio *parent = s->parent; in serio_disconnect_port()
666 device_release_driver(&s->dev); in serio_disconnect_port()
676 device_release_driver(&serio->dev); in serio_disconnect_port()
722 list_for_each_entry_safe(s, next, &serio->children, child_node) { in serio_unregister_child_port()
735 static ssize_t description_show(struct device_driver *drv, char *buf) in description_show() argument
737 struct serio_driver *driver = to_serio_driver(drv); in description_show()
738 return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)"); in description_show()
742 static ssize_t bind_mode_show(struct device_driver *drv, char *buf) in bind_mode_show() argument
744 struct serio_driver *serio_drv = to_serio_driver(drv); in bind_mode_show()
745 return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto"); in bind_mode_show()
748 static ssize_t bind_mode_store(struct device_driver *drv, const char *buf, size_t count) in bind_mode_store() argument
750 struct serio_driver *serio_drv = to_serio_driver(drv); in bind_mode_store()
755 serio_drv->manual_bind = true; in bind_mode_store()
757 serio_drv->manual_bind = false; in bind_mode_store()
759 retval = -EINVAL; in bind_mode_store()
776 struct serio_driver *drv = to_serio_driver(dev->driver); in serio_driver_probe() local
778 return serio_connect_driver(serio, drv); in serio_driver_probe()
791 mutex_lock(&serio->drv_mutex); in serio_cleanup()
792 if (serio->drv && serio->drv->cleanup) in serio_cleanup()
793 serio->drv->cleanup(serio); in serio_cleanup()
794 mutex_unlock(&serio->drv_mutex); in serio_cleanup()
804 static void serio_attach_driver(struct serio_driver *drv) in serio_attach_driver() argument
808 error = driver_attach(&drv->driver); in serio_attach_driver()
811 drv->driver.name, error); in serio_attach_driver()
814 int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name) in __serio_register_driver() argument
816 bool manual_bind = drv->manual_bind; in __serio_register_driver()
819 drv->driver.bus = &serio_bus; in __serio_register_driver()
820 drv->driver.owner = owner; in __serio_register_driver()
821 drv->driver.mod_name = mod_name; in __serio_register_driver()
827 drv->manual_bind = true; in __serio_register_driver()
829 error = driver_register(&drv->driver); in __serio_register_driver()
832 drv->driver.name, error); in __serio_register_driver()
841 drv->manual_bind = false; in __serio_register_driver()
842 error = serio_queue_event(drv, NULL, SERIO_ATTACH_DRIVER); in __serio_register_driver()
844 driver_unregister(&drv->driver); in __serio_register_driver()
853 void serio_unregister_driver(struct serio_driver *drv) in serio_unregister_driver() argument
859 drv->manual_bind = true; /* so serio_find_driver ignores it */ in serio_unregister_driver()
860 serio_remove_pending_events(drv); in serio_unregister_driver()
864 if (serio->drv == drv) { in serio_unregister_driver()
872 driver_unregister(&drv->driver); in serio_unregister_driver()
877 static void serio_set_drv(struct serio *serio, struct serio_driver *drv) in serio_set_drv() argument
880 serio->drv = drv; in serio_set_drv()
884 static int serio_bus_match(struct device *dev, struct device_driver *drv) in serio_bus_match() argument
887 struct serio_driver *serio_drv = to_serio_driver(drv); in serio_bus_match()
889 if (serio->manual_bind || serio_drv->manual_bind) in serio_bus_match()
892 return serio_match_port(serio_drv->id_table, serio); in serio_bus_match()
907 return -ENODEV; in serio_uevent()
911 SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio->id.type); in serio_uevent()
912 SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio->id.proto); in serio_uevent()
913 SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio->id.id); in serio_uevent()
914 SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio->id.extra); in serio_uevent()
917 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra); in serio_uevent()
919 if (serio->firmware_id[0]) in serio_uevent()
921 serio->firmware_id); in serio_uevent()
940 int error = -ENOENT; in serio_resume()
942 mutex_lock(&serio->drv_mutex); in serio_resume()
943 if (serio->drv && serio->drv->fast_reconnect) { in serio_resume()
944 error = serio->drv->fast_reconnect(serio); in serio_resume()
945 if (error && error != -ENOENT) in serio_resume()
949 mutex_unlock(&serio->drv_mutex); in serio_resume()
970 /* called from serio_driver->connect/disconnect methods under serio_mutex */
971 int serio_open(struct serio *serio, struct serio_driver *drv) in serio_open() argument
973 serio_set_drv(serio, drv); in serio_open()
975 if (serio->open && serio->open(serio)) { in serio_open()
977 return -1; in serio_open()
983 /* called from serio_driver->connect/disconnect methods under serio_mutex */
986 if (serio->close) in serio_close()
987 serio->close(serio); in serio_close()
999 spin_lock_irqsave(&serio->lock, flags); in serio_interrupt()
1001 if (likely(serio->drv)) { in serio_interrupt()
1002 ret = serio->drv->interrupt(serio, data, dfl); in serio_interrupt()
1003 } else if (!dfl && device_is_registered(&serio->dev)) { in serio_interrupt()
1008 spin_unlock_irqrestore(&serio->lock, flags); in serio_interrupt()