1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * The Serio abstraction module
5 * Copyright (c) 1999-2004 Vojtech Pavlik
6 * Copyright (c) 2004 Dmitry Torokhov
7 * Copyright (c) 2003 Daniele Bellucci
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/stddef.h>
16 #include <linux/module.h>
17 #include <linux/serio.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/workqueue.h>
22 #include <linux/mutex.h>
24 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
25 MODULE_DESCRIPTION("Serio abstraction core");
26 MODULE_LICENSE("GPL");
29 * serio_mutex protects entire serio subsystem and is taken every time
30 * serio port or driver registered or unregistered.
32 static DEFINE_MUTEX(serio_mutex);
34 static LIST_HEAD(serio_list);
36 static void serio_add_port(struct serio *serio);
37 static int serio_reconnect_port(struct serio *serio);
38 static void serio_disconnect_port(struct serio *serio);
39 static void serio_reconnect_subtree(struct serio *serio);
40 static void serio_attach_driver(struct serio_driver *drv);
42 static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
46 mutex_lock(&serio->drv_mutex);
47 retval = drv->connect(serio, drv);
48 mutex_unlock(&serio->drv_mutex);
53 static int serio_reconnect_driver(struct serio *serio)
57 mutex_lock(&serio->drv_mutex);
58 if (serio->drv && serio->drv->reconnect)
59 retval = serio->drv->reconnect(serio);
60 mutex_unlock(&serio->drv_mutex);
65 static void serio_disconnect_driver(struct serio *serio)
67 mutex_lock(&serio->drv_mutex);
69 serio->drv->disconnect(serio);
70 mutex_unlock(&serio->drv_mutex);
73 static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
75 while (ids->type || ids->proto) {
76 if ((ids->type == SERIO_ANY || ids->type == serio->id.type) &&
77 (ids->proto == SERIO_ANY || ids->proto == serio->id.proto) &&
78 (ids->extra == SERIO_ANY || ids->extra == serio->id.extra) &&
79 (ids->id == SERIO_ANY || ids->id == serio->id.id))
87 * Basic serio -> driver core mappings
90 static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
94 if (serio_match_port(drv->id_table, serio)) {
96 serio->dev.driver = &drv->driver;
97 if (serio_connect_driver(serio, drv)) {
98 serio->dev.driver = NULL;
102 error = device_bind_driver(&serio->dev);
104 dev_warn(&serio->dev,
105 "device_bind_driver() failed for %s (%s) and %s, error: %d\n",
106 serio->phys, serio->name,
107 drv->description, error);
108 serio_disconnect_driver(serio);
109 serio->dev.driver = NULL;
116 static void serio_find_driver(struct serio *serio)
120 error = device_attach(&serio->dev);
121 if (error < 0 && error != -EPROBE_DEFER)
122 dev_warn(&serio->dev,
123 "device_attach() failed for %s (%s), error: %d\n",
124 serio->phys, serio->name, error);
129 * Serio event processing.
132 enum serio_event_type {
134 SERIO_RECONNECT_PORT,
135 SERIO_RECONNECT_SUBTREE,
141 enum serio_event_type type;
143 struct module *owner;
144 struct list_head node;
147 static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */
148 static LIST_HEAD(serio_event_list);
150 static struct serio_event *serio_get_event(void)
152 struct serio_event *event = NULL;
155 spin_lock_irqsave(&serio_event_lock, flags);
157 if (!list_empty(&serio_event_list)) {
158 event = list_first_entry(&serio_event_list,
159 struct serio_event, node);
160 list_del_init(&event->node);
163 spin_unlock_irqrestore(&serio_event_lock, flags);
167 static void serio_free_event(struct serio_event *event)
169 module_put(event->owner);
173 static void serio_remove_duplicate_events(void *object,
174 enum serio_event_type type)
176 struct serio_event *e, *next;
179 spin_lock_irqsave(&serio_event_lock, flags);
181 list_for_each_entry_safe(e, next, &serio_event_list, node) {
182 if (object == e->object) {
184 * If this event is of different type we should not
185 * look further - we only suppress duplicate events
186 * that were sent back-to-back.
191 list_del_init(&e->node);
196 spin_unlock_irqrestore(&serio_event_lock, flags);
199 static void serio_handle_event(struct work_struct *work)
201 struct serio_event *event;
203 mutex_lock(&serio_mutex);
205 while ((event = serio_get_event())) {
207 switch (event->type) {
209 case SERIO_REGISTER_PORT:
210 serio_add_port(event->object);
213 case SERIO_RECONNECT_PORT:
214 serio_reconnect_port(event->object);
217 case SERIO_RESCAN_PORT:
218 serio_disconnect_port(event->object);
219 serio_find_driver(event->object);
222 case SERIO_RECONNECT_SUBTREE:
223 serio_reconnect_subtree(event->object);
226 case SERIO_ATTACH_DRIVER:
227 serio_attach_driver(event->object);
231 serio_remove_duplicate_events(event->object, event->type);
232 serio_free_event(event);
235 mutex_unlock(&serio_mutex);
238 static DECLARE_WORK(serio_event_work, serio_handle_event);
240 static int serio_queue_event(void *object, struct module *owner,
241 enum serio_event_type event_type)
244 struct serio_event *event;
247 spin_lock_irqsave(&serio_event_lock, flags);
250 * Scan event list for the other events for the same serio port,
251 * starting with the most recent one. If event is the same we
252 * do not need add new one. If event is of different type we
253 * need to add this event and should not look further because
254 * we need to preseve sequence of distinct events.
256 list_for_each_entry_reverse(event, &serio_event_list, node) {
257 if (event->object == object) {
258 if (event->type == event_type)
264 event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC);
266 pr_err("Not enough memory to queue event %d\n", event_type);
271 if (!try_module_get(owner)) {
272 pr_warn("Can't get module reference, dropping event %d\n",
279 event->type = event_type;
280 event->object = object;
281 event->owner = owner;
283 list_add_tail(&event->node, &serio_event_list);
284 queue_work(system_long_wq, &serio_event_work);
287 spin_unlock_irqrestore(&serio_event_lock, flags);
292 * Remove all events that have been submitted for a given
293 * object, be it serio port or driver.
295 static void serio_remove_pending_events(void *object)
297 struct serio_event *event, *next;
300 spin_lock_irqsave(&serio_event_lock, flags);
302 list_for_each_entry_safe(event, next, &serio_event_list, node) {
303 if (event->object == object) {
304 list_del_init(&event->node);
305 serio_free_event(event);
309 spin_unlock_irqrestore(&serio_event_lock, flags);
313 * Locate child serio port (if any) that has not been fully registered yet.
315 * Children are registered by driver's connect() handler so there can't be a
316 * grandchild pending registration together with a child.
318 static struct serio *serio_get_pending_child(struct serio *parent)
320 struct serio_event *event;
321 struct serio *serio, *child = NULL;
324 spin_lock_irqsave(&serio_event_lock, flags);
326 list_for_each_entry(event, &serio_event_list, node) {
327 if (event->type == SERIO_REGISTER_PORT) {
328 serio = event->object;
329 if (serio->parent == parent) {
336 spin_unlock_irqrestore(&serio_event_lock, flags);
341 * Serio port operations
344 static ssize_t serio_show_description(struct device *dev, struct device_attribute *attr, char *buf)
346 struct serio *serio = to_serio_port(dev);
347 return sprintf(buf, "%s\n", serio->name);
350 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
352 struct serio *serio = to_serio_port(dev);
354 return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
355 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
358 static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf)
360 struct serio *serio = to_serio_port(dev);
361 return sprintf(buf, "%02x\n", serio->id.type);
364 static ssize_t proto_show(struct device *dev, struct device_attribute *attr, char *buf)
366 struct serio *serio = to_serio_port(dev);
367 return sprintf(buf, "%02x\n", serio->id.proto);
370 static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
372 struct serio *serio = to_serio_port(dev);
373 return sprintf(buf, "%02x\n", serio->id.id);
376 static ssize_t extra_show(struct device *dev, struct device_attribute *attr, char *buf)
378 struct serio *serio = to_serio_port(dev);
379 return sprintf(buf, "%02x\n", serio->id.extra);
382 static ssize_t drvctl_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
384 struct serio *serio = to_serio_port(dev);
385 struct device_driver *drv;
388 error = mutex_lock_interruptible(&serio_mutex);
392 if (!strncmp(buf, "none", count)) {
393 serio_disconnect_port(serio);
394 } else if (!strncmp(buf, "reconnect", count)) {
395 serio_reconnect_subtree(serio);
396 } else if (!strncmp(buf, "rescan", count)) {
397 serio_disconnect_port(serio);
398 serio_find_driver(serio);
399 serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT);
400 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
401 serio_disconnect_port(serio);
402 error = serio_bind_driver(serio, to_serio_driver(drv));
403 serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT);
408 mutex_unlock(&serio_mutex);
410 return error ? error : count;
413 static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf)
415 struct serio *serio = to_serio_port(dev);
416 return sprintf(buf, "%s\n", serio->manual_bind ? "manual" : "auto");
419 static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
421 struct serio *serio = to_serio_port(dev);
425 if (!strncmp(buf, "manual", count)) {
426 serio->manual_bind = true;
427 } else if (!strncmp(buf, "auto", count)) {
428 serio->manual_bind = false;
436 static ssize_t firmware_id_show(struct device *dev, struct device_attribute *attr, char *buf)
438 struct serio *serio = to_serio_port(dev);
440 return sprintf(buf, "%s\n", serio->firmware_id);
443 static DEVICE_ATTR_RO(type);
444 static DEVICE_ATTR_RO(proto);
445 static DEVICE_ATTR_RO(id);
446 static DEVICE_ATTR_RO(extra);
448 static struct attribute *serio_device_id_attrs[] = {
450 &dev_attr_proto.attr,
452 &dev_attr_extra.attr,
456 static const struct attribute_group serio_id_attr_group = {
458 .attrs = serio_device_id_attrs,
461 static DEVICE_ATTR_RO(modalias);
462 static DEVICE_ATTR_WO(drvctl);
463 static DEVICE_ATTR(description, S_IRUGO, serio_show_description, NULL);
464 static DEVICE_ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode);
465 static DEVICE_ATTR_RO(firmware_id);
467 static struct attribute *serio_device_attrs[] = {
468 &dev_attr_modalias.attr,
469 &dev_attr_description.attr,
470 &dev_attr_drvctl.attr,
471 &dev_attr_bind_mode.attr,
472 &dev_attr_firmware_id.attr,
476 static const struct attribute_group serio_device_attr_group = {
477 .attrs = serio_device_attrs,
480 static const struct attribute_group *serio_device_attr_groups[] = {
481 &serio_id_attr_group,
482 &serio_device_attr_group,
486 static void serio_release_port(struct device *dev)
488 struct serio *serio = to_serio_port(dev);
491 module_put(THIS_MODULE);
495 * Prepare serio port for registration.
497 static void serio_init_port(struct serio *serio)
499 static atomic_t serio_no = ATOMIC_INIT(-1);
501 __module_get(THIS_MODULE);
503 INIT_LIST_HEAD(&serio->node);
504 INIT_LIST_HEAD(&serio->child_node);
505 INIT_LIST_HEAD(&serio->children);
506 spin_lock_init(&serio->lock);
507 mutex_init(&serio->drv_mutex);
508 device_initialize(&serio->dev);
509 dev_set_name(&serio->dev, "serio%lu",
510 (unsigned long)atomic_inc_return(&serio_no));
511 serio->dev.bus = &serio_bus;
512 serio->dev.release = serio_release_port;
513 serio->dev.groups = serio_device_attr_groups;
515 serio->dev.parent = &serio->parent->dev;
516 serio->depth = serio->parent->depth + 1;
519 lockdep_set_subclass(&serio->lock, serio->depth);
523 * Complete serio port registration.
524 * Driver core will attempt to find appropriate driver for the port.
526 static void serio_add_port(struct serio *serio)
528 struct serio *parent = serio->parent;
532 serio_pause_rx(parent);
533 list_add_tail(&serio->child_node, &parent->children);
534 serio_continue_rx(parent);
537 list_add_tail(&serio->node, &serio_list);
542 error = device_add(&serio->dev);
545 "device_add() failed for %s (%s), error: %d\n",
546 serio->phys, serio->name, error);
550 * serio_destroy_port() completes unregistration process and removes
551 * port from the system
553 static void serio_destroy_port(struct serio *serio)
557 while ((child = serio_get_pending_child(serio)) != NULL) {
558 serio_remove_pending_events(child);
559 put_device(&child->dev);
566 serio_pause_rx(serio->parent);
567 list_del_init(&serio->child_node);
568 serio_continue_rx(serio->parent);
569 serio->parent = NULL;
572 if (device_is_registered(&serio->dev))
573 device_del(&serio->dev);
575 list_del_init(&serio->node);
576 serio_remove_pending_events(serio);
577 put_device(&serio->dev);
581 * Reconnect serio port (re-initialize attached device).
582 * If reconnect fails (old device is no longer attached or
583 * there was no device to begin with) we do full rescan in
584 * hope of finding a driver for the port.
586 static int serio_reconnect_port(struct serio *serio)
588 int error = serio_reconnect_driver(serio);
591 serio_disconnect_port(serio);
592 serio_find_driver(serio);
599 * Reconnect serio port and all its children (re-initialize attached
602 static void serio_reconnect_subtree(struct serio *root)
604 struct serio *s = root;
608 error = serio_reconnect_port(s);
611 * Reconnect was successful, move on to do the
614 if (!list_empty(&s->children)) {
615 s = list_first_entry(&s->children,
616 struct serio, child_node);
622 * Either it was a leaf node or reconnect failed and it
623 * became a leaf node. Continue reconnecting starting with
624 * the next sibling of the parent node.
627 struct serio *parent = s->parent;
629 if (!list_is_last(&s->child_node, &parent->children)) {
630 s = list_entry(s->child_node.next,
631 struct serio, child_node);
641 * serio_disconnect_port() unbinds a port from its driver. As a side effect
642 * all children ports are unbound and destroyed.
644 static void serio_disconnect_port(struct serio *serio)
646 struct serio *s = serio;
649 * Children ports should be disconnected and destroyed
650 * first; we travel the tree in depth-first order.
652 while (!list_empty(&serio->children)) {
655 while (!list_empty(&s->children))
656 s = list_first_entry(&s->children,
657 struct serio, child_node);
660 * Prune this leaf node unless it is the one we
664 struct serio *parent = s->parent;
666 device_release_driver(&s->dev);
667 serio_destroy_port(s);
674 * OK, no children left, now disconnect this port.
676 device_release_driver(&serio->dev);
679 void serio_rescan(struct serio *serio)
681 serio_queue_event(serio, NULL, SERIO_RESCAN_PORT);
683 EXPORT_SYMBOL(serio_rescan);
685 void serio_reconnect(struct serio *serio)
687 serio_queue_event(serio, NULL, SERIO_RECONNECT_SUBTREE);
689 EXPORT_SYMBOL(serio_reconnect);
692 * Submits register request to kseriod for subsequent execution.
693 * Note that port registration is always asynchronous.
695 void __serio_register_port(struct serio *serio, struct module *owner)
697 serio_init_port(serio);
698 serio_queue_event(serio, owner, SERIO_REGISTER_PORT);
700 EXPORT_SYMBOL(__serio_register_port);
703 * Synchronously unregisters serio port.
705 void serio_unregister_port(struct serio *serio)
707 mutex_lock(&serio_mutex);
708 serio_disconnect_port(serio);
709 serio_destroy_port(serio);
710 mutex_unlock(&serio_mutex);
712 EXPORT_SYMBOL(serio_unregister_port);
715 * Safely unregisters children ports if they are present.
717 void serio_unregister_child_port(struct serio *serio)
719 struct serio *s, *next;
721 mutex_lock(&serio_mutex);
722 list_for_each_entry_safe(s, next, &serio->children, child_node) {
723 serio_disconnect_port(s);
724 serio_destroy_port(s);
726 mutex_unlock(&serio_mutex);
728 EXPORT_SYMBOL(serio_unregister_child_port);
732 * Serio driver operations
735 static ssize_t description_show(struct device_driver *drv, char *buf)
737 struct serio_driver *driver = to_serio_driver(drv);
738 return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)");
740 static DRIVER_ATTR_RO(description);
742 static ssize_t bind_mode_show(struct device_driver *drv, char *buf)
744 struct serio_driver *serio_drv = to_serio_driver(drv);
745 return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto");
748 static ssize_t bind_mode_store(struct device_driver *drv, const char *buf, size_t count)
750 struct serio_driver *serio_drv = to_serio_driver(drv);
754 if (!strncmp(buf, "manual", count)) {
755 serio_drv->manual_bind = true;
756 } else if (!strncmp(buf, "auto", count)) {
757 serio_drv->manual_bind = false;
764 static DRIVER_ATTR_RW(bind_mode);
766 static struct attribute *serio_driver_attrs[] = {
767 &driver_attr_description.attr,
768 &driver_attr_bind_mode.attr,
771 ATTRIBUTE_GROUPS(serio_driver);
773 static int serio_driver_probe(struct device *dev)
775 struct serio *serio = to_serio_port(dev);
776 struct serio_driver *drv = to_serio_driver(dev->driver);
778 return serio_connect_driver(serio, drv);
781 static void serio_driver_remove(struct device *dev)
783 struct serio *serio = to_serio_port(dev);
785 serio_disconnect_driver(serio);
788 static void serio_cleanup(struct serio *serio)
790 mutex_lock(&serio->drv_mutex);
791 if (serio->drv && serio->drv->cleanup)
792 serio->drv->cleanup(serio);
793 mutex_unlock(&serio->drv_mutex);
796 static void serio_shutdown(struct device *dev)
798 struct serio *serio = to_serio_port(dev);
800 serio_cleanup(serio);
803 static void serio_attach_driver(struct serio_driver *drv)
807 error = driver_attach(&drv->driver);
809 pr_warn("driver_attach() failed for %s with error %d\n",
810 drv->driver.name, error);
813 int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name)
815 bool manual_bind = drv->manual_bind;
818 drv->driver.bus = &serio_bus;
819 drv->driver.owner = owner;
820 drv->driver.mod_name = mod_name;
823 * Temporarily disable automatic binding because probing
824 * takes long time and we are better off doing it in kseriod
826 drv->manual_bind = true;
828 error = driver_register(&drv->driver);
830 pr_err("driver_register() failed for %s, error: %d\n",
831 drv->driver.name, error);
836 * Restore original bind mode and let kseriod bind the
837 * driver to free ports
840 drv->manual_bind = false;
841 error = serio_queue_event(drv, NULL, SERIO_ATTACH_DRIVER);
843 driver_unregister(&drv->driver);
850 EXPORT_SYMBOL(__serio_register_driver);
852 void serio_unregister_driver(struct serio_driver *drv)
856 mutex_lock(&serio_mutex);
858 drv->manual_bind = true; /* so serio_find_driver ignores it */
859 serio_remove_pending_events(drv);
862 list_for_each_entry(serio, &serio_list, node) {
863 if (serio->drv == drv) {
864 serio_disconnect_port(serio);
865 serio_find_driver(serio);
866 /* we could've deleted some ports, restart */
871 driver_unregister(&drv->driver);
872 mutex_unlock(&serio_mutex);
874 EXPORT_SYMBOL(serio_unregister_driver);
876 static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
878 serio_pause_rx(serio);
880 serio_continue_rx(serio);
883 static int serio_bus_match(struct device *dev, struct device_driver *drv)
885 struct serio *serio = to_serio_port(dev);
886 struct serio_driver *serio_drv = to_serio_driver(drv);
888 if (serio->manual_bind || serio_drv->manual_bind)
891 return serio_match_port(serio_drv->id_table, serio);
894 #define SERIO_ADD_UEVENT_VAR(fmt, val...) \
896 int err = add_uevent_var(env, fmt, val); \
901 static int serio_uevent(struct device *dev, struct kobj_uevent_env *env)
908 serio = to_serio_port(dev);
910 SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio->id.type);
911 SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio->id.proto);
912 SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio->id.id);
913 SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio->id.extra);
915 SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
916 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
918 if (serio->firmware_id[0])
919 SERIO_ADD_UEVENT_VAR("SERIO_FIRMWARE_ID=%s",
924 #undef SERIO_ADD_UEVENT_VAR
927 static int serio_suspend(struct device *dev)
929 struct serio *serio = to_serio_port(dev);
931 serio_cleanup(serio);
936 static int serio_resume(struct device *dev)
938 struct serio *serio = to_serio_port(dev);
941 mutex_lock(&serio->drv_mutex);
942 if (serio->drv && serio->drv->fast_reconnect) {
943 error = serio->drv->fast_reconnect(serio);
944 if (error && error != -ENOENT)
945 dev_warn(dev, "fast reconnect failed with error %d\n",
948 mutex_unlock(&serio->drv_mutex);
952 * Driver reconnect can take a while, so better let
953 * kseriod deal with it.
955 serio_queue_event(serio, NULL, SERIO_RECONNECT_PORT);
961 static const struct dev_pm_ops serio_pm_ops = {
962 .suspend = serio_suspend,
963 .resume = serio_resume,
964 .poweroff = serio_suspend,
965 .restore = serio_resume,
967 #endif /* CONFIG_PM */
969 /* called from serio_driver->connect/disconnect methods under serio_mutex */
970 int serio_open(struct serio *serio, struct serio_driver *drv)
972 serio_set_drv(serio, drv);
974 if (serio->open && serio->open(serio)) {
975 serio_set_drv(serio, NULL);
980 EXPORT_SYMBOL(serio_open);
982 /* called from serio_driver->connect/disconnect methods under serio_mutex */
983 void serio_close(struct serio *serio)
988 serio_set_drv(serio, NULL);
990 EXPORT_SYMBOL(serio_close);
992 irqreturn_t serio_interrupt(struct serio *serio,
993 unsigned char data, unsigned int dfl)
996 irqreturn_t ret = IRQ_NONE;
998 spin_lock_irqsave(&serio->lock, flags);
1000 if (likely(serio->drv)) {
1001 ret = serio->drv->interrupt(serio, data, dfl);
1002 } else if (!dfl && device_is_registered(&serio->dev)) {
1003 serio_rescan(serio);
1007 spin_unlock_irqrestore(&serio->lock, flags);
1011 EXPORT_SYMBOL(serio_interrupt);
1013 struct bus_type serio_bus = {
1015 .drv_groups = serio_driver_groups,
1016 .match = serio_bus_match,
1017 .uevent = serio_uevent,
1018 .probe = serio_driver_probe,
1019 .remove = serio_driver_remove,
1020 .shutdown = serio_shutdown,
1022 .pm = &serio_pm_ops,
1025 EXPORT_SYMBOL(serio_bus);
1027 static int __init serio_init(void)
1031 error = bus_register(&serio_bus);
1033 pr_err("Failed to register serio bus, error: %d\n", error);
1040 static void __exit serio_exit(void)
1042 bus_unregister(&serio_bus);
1045 * There should not be any outstanding events but work may
1046 * still be scheduled so simply cancel it.
1048 cancel_work_sync(&serio_event_work);
1051 subsys_initcall(serio_init);
1052 module_exit(serio_exit);