Input: make serio and gameport more swsusp friendly
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / input / serio / serio.c
blobfbb69ef6a77b0a6a8659ec5b19b107bb32812040
1 /*
2 * The Serio abstraction module
4 * Copyright (c) 1999-2004 Vojtech Pavlik
5 * Copyright (c) 2004 Dmitry Torokhov
6 * Copyright (c) 2003 Daniele Bellucci
7 */
9 /*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
29 #include <linux/stddef.h>
30 #include <linux/module.h>
31 #include <linux/serio.h>
32 #include <linux/errno.h>
33 #include <linux/wait.h>
34 #include <linux/sched.h>
35 #include <linux/slab.h>
36 #include <linux/kthread.h>
38 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39 MODULE_DESCRIPTION("Serio abstraction core");
40 MODULE_LICENSE("GPL");
42 EXPORT_SYMBOL(serio_interrupt);
43 EXPORT_SYMBOL(__serio_register_port);
44 EXPORT_SYMBOL(serio_unregister_port);
45 EXPORT_SYMBOL(serio_unregister_child_port);
46 EXPORT_SYMBOL(__serio_unregister_port_delayed);
47 EXPORT_SYMBOL(__serio_register_driver);
48 EXPORT_SYMBOL(serio_unregister_driver);
49 EXPORT_SYMBOL(serio_open);
50 EXPORT_SYMBOL(serio_close);
51 EXPORT_SYMBOL(serio_rescan);
52 EXPORT_SYMBOL(serio_reconnect);
55 * serio_sem protects entire serio subsystem and is taken every time
56 * serio port or driver registrered or unregistered.
58 static DECLARE_MUTEX(serio_sem);
60 static LIST_HEAD(serio_list);
62 static struct bus_type serio_bus = {
63 .name = "serio",
66 static void serio_add_port(struct serio *serio);
67 static void serio_destroy_port(struct serio *serio);
68 static void serio_reconnect_port(struct serio *serio);
69 static void serio_disconnect_port(struct serio *serio);
71 static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
73 int retval;
75 down(&serio->drv_sem);
76 retval = drv->connect(serio, drv);
77 up(&serio->drv_sem);
79 return retval;
82 static int serio_reconnect_driver(struct serio *serio)
84 int retval = -1;
86 down(&serio->drv_sem);
87 if (serio->drv && serio->drv->reconnect)
88 retval = serio->drv->reconnect(serio);
89 up(&serio->drv_sem);
91 return retval;
94 static void serio_disconnect_driver(struct serio *serio)
96 down(&serio->drv_sem);
97 if (serio->drv)
98 serio->drv->disconnect(serio);
99 up(&serio->drv_sem);
102 static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
104 while (ids->type || ids->proto) {
105 if ((ids->type == SERIO_ANY || ids->type == serio->id.type) &&
106 (ids->proto == SERIO_ANY || ids->proto == serio->id.proto) &&
107 (ids->extra == SERIO_ANY || ids->extra == serio->id.extra) &&
108 (ids->id == SERIO_ANY || ids->id == serio->id.id))
109 return 1;
110 ids++;
112 return 0;
116 * Basic serio -> driver core mappings
119 static void serio_bind_driver(struct serio *serio, struct serio_driver *drv)
121 down_write(&serio_bus.subsys.rwsem);
123 if (serio_match_port(drv->id_table, serio)) {
124 serio->dev.driver = &drv->driver;
125 if (serio_connect_driver(serio, drv)) {
126 serio->dev.driver = NULL;
127 goto out;
129 device_bind_driver(&serio->dev);
131 out:
132 up_write(&serio_bus.subsys.rwsem);
135 static void serio_release_driver(struct serio *serio)
137 down_write(&serio_bus.subsys.rwsem);
138 device_release_driver(&serio->dev);
139 up_write(&serio_bus.subsys.rwsem);
142 static void serio_find_driver(struct serio *serio)
144 down_write(&serio_bus.subsys.rwsem);
145 device_attach(&serio->dev);
146 up_write(&serio_bus.subsys.rwsem);
151 * Serio event processing.
154 enum serio_event_type {
155 SERIO_RESCAN,
156 SERIO_RECONNECT,
157 SERIO_REGISTER_PORT,
158 SERIO_UNREGISTER_PORT,
159 SERIO_REGISTER_DRIVER,
162 struct serio_event {
163 enum serio_event_type type;
164 void *object;
165 struct module *owner;
166 struct list_head node;
169 static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */
170 static LIST_HEAD(serio_event_list);
171 static DECLARE_WAIT_QUEUE_HEAD(serio_wait);
172 static struct task_struct *serio_task;
174 static void serio_queue_event(void *object, struct module *owner,
175 enum serio_event_type event_type)
177 unsigned long flags;
178 struct serio_event *event;
180 spin_lock_irqsave(&serio_event_lock, flags);
183 * Scan event list for the other events for the same serio port,
184 * starting with the most recent one. If event is the same we
185 * do not need add new one. If event is of different type we
186 * need to add this event and should not look further because
187 * we need to preseve sequence of distinct events.
189 list_for_each_entry_reverse(event, &serio_event_list, node) {
190 if (event->object == object) {
191 if (event->type == event_type)
192 goto out;
193 break;
197 if ((event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC))) {
198 if (!try_module_get(owner)) {
199 printk(KERN_WARNING "serio: Can't get module reference, dropping event %d\n", event_type);
200 goto out;
203 event->type = event_type;
204 event->object = object;
205 event->owner = owner;
207 list_add_tail(&event->node, &serio_event_list);
208 wake_up(&serio_wait);
209 } else {
210 printk(KERN_ERR "serio: Not enough memory to queue event %d\n", event_type);
212 out:
213 spin_unlock_irqrestore(&serio_event_lock, flags);
216 static void serio_free_event(struct serio_event *event)
218 module_put(event->owner);
219 kfree(event);
222 static void serio_remove_duplicate_events(struct serio_event *event)
224 struct list_head *node, *next;
225 struct serio_event *e;
226 unsigned long flags;
228 spin_lock_irqsave(&serio_event_lock, flags);
230 list_for_each_safe(node, next, &serio_event_list) {
231 e = list_entry(node, struct serio_event, node);
232 if (event->object == e->object) {
234 * If this event is of different type we should not
235 * look further - we only suppress duplicate events
236 * that were sent back-to-back.
238 if (event->type != e->type)
239 break;
241 list_del_init(node);
242 serio_free_event(e);
246 spin_unlock_irqrestore(&serio_event_lock, flags);
250 static struct serio_event *serio_get_event(void)
252 struct serio_event *event;
253 struct list_head *node;
254 unsigned long flags;
256 spin_lock_irqsave(&serio_event_lock, flags);
258 if (list_empty(&serio_event_list)) {
259 spin_unlock_irqrestore(&serio_event_lock, flags);
260 return NULL;
263 node = serio_event_list.next;
264 event = list_entry(node, struct serio_event, node);
265 list_del_init(node);
267 spin_unlock_irqrestore(&serio_event_lock, flags);
269 return event;
272 static void serio_handle_event(void)
274 struct serio_event *event;
275 struct serio_driver *serio_drv;
277 down(&serio_sem);
280 * Note that we handle only one event here to give swsusp
281 * a chance to freeze kseriod thread. Serio events should
282 * be pretty rare so we are not concerned about taking
283 * performance hit.
285 if ((event = serio_get_event())) {
287 switch (event->type) {
288 case SERIO_REGISTER_PORT:
289 serio_add_port(event->object);
290 break;
292 case SERIO_UNREGISTER_PORT:
293 serio_disconnect_port(event->object);
294 serio_destroy_port(event->object);
295 break;
297 case SERIO_RECONNECT:
298 serio_reconnect_port(event->object);
299 break;
301 case SERIO_RESCAN:
302 serio_disconnect_port(event->object);
303 serio_find_driver(event->object);
304 break;
306 case SERIO_REGISTER_DRIVER:
307 serio_drv = event->object;
308 driver_register(&serio_drv->driver);
309 break;
311 default:
312 break;
315 serio_remove_duplicate_events(event);
316 serio_free_event(event);
319 up(&serio_sem);
323 * Remove all events that have been submitted for a given serio port.
325 static void serio_remove_pending_events(struct serio *serio)
327 struct list_head *node, *next;
328 struct serio_event *event;
329 unsigned long flags;
331 spin_lock_irqsave(&serio_event_lock, flags);
333 list_for_each_safe(node, next, &serio_event_list) {
334 event = list_entry(node, struct serio_event, node);
335 if (event->object == serio) {
336 list_del_init(node);
337 serio_free_event(event);
341 spin_unlock_irqrestore(&serio_event_lock, flags);
345 * Destroy child serio port (if any) that has not been fully registered yet.
347 * Note that we rely on the fact that port can have only one child and therefore
348 * only one child registration request can be pending. Additionally, children
349 * are registered by driver's connect() handler so there can't be a grandchild
350 * pending registration together with a child.
352 static struct serio *serio_get_pending_child(struct serio *parent)
354 struct serio_event *event;
355 struct serio *serio, *child = NULL;
356 unsigned long flags;
358 spin_lock_irqsave(&serio_event_lock, flags);
360 list_for_each_entry(event, &serio_event_list, node) {
361 if (event->type == SERIO_REGISTER_PORT) {
362 serio = event->object;
363 if (serio->parent == parent) {
364 child = serio;
365 break;
370 spin_unlock_irqrestore(&serio_event_lock, flags);
371 return child;
374 static int serio_thread(void *nothing)
376 do {
377 serio_handle_event();
378 wait_event_interruptible(serio_wait,
379 kthread_should_stop() || !list_empty(&serio_event_list));
380 try_to_freeze();
381 } while (!kthread_should_stop());
383 printk(KERN_DEBUG "serio: kseriod exiting\n");
384 return 0;
389 * Serio port operations
392 static ssize_t serio_show_description(struct device *dev, struct device_attribute *attr, char *buf)
394 struct serio *serio = to_serio_port(dev);
395 return sprintf(buf, "%s\n", serio->name);
398 static ssize_t serio_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
400 struct serio *serio = to_serio_port(dev);
402 return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
403 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
406 static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf)
408 struct serio *serio = to_serio_port(dev);
409 return sprintf(buf, "%02x\n", serio->id.type);
412 static ssize_t serio_show_id_proto(struct device *dev, struct device_attribute *attr, char *buf)
414 struct serio *serio = to_serio_port(dev);
415 return sprintf(buf, "%02x\n", serio->id.proto);
418 static ssize_t serio_show_id_id(struct device *dev, struct device_attribute *attr, char *buf)
420 struct serio *serio = to_serio_port(dev);
421 return sprintf(buf, "%02x\n", serio->id.id);
424 static ssize_t serio_show_id_extra(struct device *dev, struct device_attribute *attr, char *buf)
426 struct serio *serio = to_serio_port(dev);
427 return sprintf(buf, "%02x\n", serio->id.extra);
430 static DEVICE_ATTR(type, S_IRUGO, serio_show_id_type, NULL);
431 static DEVICE_ATTR(proto, S_IRUGO, serio_show_id_proto, NULL);
432 static DEVICE_ATTR(id, S_IRUGO, serio_show_id_id, NULL);
433 static DEVICE_ATTR(extra, S_IRUGO, serio_show_id_extra, NULL);
435 static struct attribute *serio_device_id_attrs[] = {
436 &dev_attr_type.attr,
437 &dev_attr_proto.attr,
438 &dev_attr_id.attr,
439 &dev_attr_extra.attr,
440 NULL
443 static struct attribute_group serio_id_attr_group = {
444 .name = "id",
445 .attrs = serio_device_id_attrs,
448 static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
450 struct serio *serio = to_serio_port(dev);
451 struct device_driver *drv;
452 int retval;
454 retval = down_interruptible(&serio_sem);
455 if (retval)
456 return retval;
458 retval = count;
459 if (!strncmp(buf, "none", count)) {
460 serio_disconnect_port(serio);
461 } else if (!strncmp(buf, "reconnect", count)) {
462 serio_reconnect_port(serio);
463 } else if (!strncmp(buf, "rescan", count)) {
464 serio_disconnect_port(serio);
465 serio_find_driver(serio);
466 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
467 serio_disconnect_port(serio);
468 serio_bind_driver(serio, to_serio_driver(drv));
469 put_driver(drv);
470 } else {
471 retval = -EINVAL;
474 up(&serio_sem);
476 return retval;
479 static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf)
481 struct serio *serio = to_serio_port(dev);
482 return sprintf(buf, "%s\n", serio->manual_bind ? "manual" : "auto");
485 static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
487 struct serio *serio = to_serio_port(dev);
488 int retval;
490 retval = count;
491 if (!strncmp(buf, "manual", count)) {
492 serio->manual_bind = 1;
493 } else if (!strncmp(buf, "auto", count)) {
494 serio->manual_bind = 0;
495 } else {
496 retval = -EINVAL;
499 return retval;
502 static struct device_attribute serio_device_attrs[] = {
503 __ATTR(description, S_IRUGO, serio_show_description, NULL),
504 __ATTR(modalias, S_IRUGO, serio_show_modalias, NULL),
505 __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver),
506 __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode),
507 __ATTR_NULL
511 static void serio_release_port(struct device *dev)
513 struct serio *serio = to_serio_port(dev);
515 kfree(serio);
516 module_put(THIS_MODULE);
520 * Prepare serio port for registration.
522 static void serio_init_port(struct serio *serio)
524 static atomic_t serio_no = ATOMIC_INIT(0);
526 __module_get(THIS_MODULE);
528 spin_lock_init(&serio->lock);
529 init_MUTEX(&serio->drv_sem);
530 device_initialize(&serio->dev);
531 snprintf(serio->dev.bus_id, sizeof(serio->dev.bus_id),
532 "serio%ld", (long)atomic_inc_return(&serio_no) - 1);
533 serio->dev.bus = &serio_bus;
534 serio->dev.release = serio_release_port;
535 if (serio->parent)
536 serio->dev.parent = &serio->parent->dev;
540 * Complete serio port registration.
541 * Driver core will attempt to find appropriate driver for the port.
543 static void serio_add_port(struct serio *serio)
545 if (serio->parent) {
546 serio_pause_rx(serio->parent);
547 serio->parent->child = serio;
548 serio_continue_rx(serio->parent);
551 list_add_tail(&serio->node, &serio_list);
552 if (serio->start)
553 serio->start(serio);
554 device_add(&serio->dev);
555 sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group);
556 serio->registered = 1;
560 * serio_destroy_port() completes deregistration process and removes
561 * port from the system
563 static void serio_destroy_port(struct serio *serio)
565 struct serio *child;
567 child = serio_get_pending_child(serio);
568 if (child) {
569 serio_remove_pending_events(child);
570 put_device(&child->dev);
573 if (serio->stop)
574 serio->stop(serio);
576 if (serio->parent) {
577 serio_pause_rx(serio->parent);
578 serio->parent->child = NULL;
579 serio_continue_rx(serio->parent);
580 serio->parent = NULL;
583 if (serio->registered) {
584 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group);
585 device_del(&serio->dev);
586 list_del_init(&serio->node);
587 serio->registered = 0;
590 serio_remove_pending_events(serio);
591 put_device(&serio->dev);
595 * Reconnect serio port and all its children (re-initialize attached devices)
597 static void serio_reconnect_port(struct serio *serio)
599 do {
600 if (serio_reconnect_driver(serio)) {
601 serio_disconnect_port(serio);
602 serio_find_driver(serio);
603 /* Ok, old children are now gone, we are done */
604 break;
606 serio = serio->child;
607 } while (serio);
611 * serio_disconnect_port() unbinds a port from its driver. As a side effect
612 * all child ports are unbound and destroyed.
614 static void serio_disconnect_port(struct serio *serio)
616 struct serio *s, *parent;
618 if (serio->child) {
620 * Children ports should be disconnected and destroyed
621 * first, staring with the leaf one, since we don't want
622 * to do recursion
624 for (s = serio; s->child; s = s->child)
625 /* empty */;
627 do {
628 parent = s->parent;
630 serio_release_driver(s);
631 serio_destroy_port(s);
632 } while ((s = parent) != serio);
636 * Ok, no children left, now disconnect this port
638 serio_release_driver(serio);
641 void serio_rescan(struct serio *serio)
643 serio_queue_event(serio, NULL, SERIO_RESCAN);
646 void serio_reconnect(struct serio *serio)
648 serio_queue_event(serio, NULL, SERIO_RECONNECT);
652 * Submits register request to kseriod for subsequent execution.
653 * Note that port registration is always asynchronous.
655 void __serio_register_port(struct serio *serio, struct module *owner)
657 serio_init_port(serio);
658 serio_queue_event(serio, owner, SERIO_REGISTER_PORT);
662 * Synchronously unregisters serio port.
664 void serio_unregister_port(struct serio *serio)
666 down(&serio_sem);
667 serio_disconnect_port(serio);
668 serio_destroy_port(serio);
669 up(&serio_sem);
673 * Safely unregisters child port if one is present.
675 void serio_unregister_child_port(struct serio *serio)
677 down(&serio_sem);
678 if (serio->child) {
679 serio_disconnect_port(serio->child);
680 serio_destroy_port(serio->child);
682 up(&serio_sem);
686 * Submits register request to kseriod for subsequent execution.
687 * Can be used when it is not obvious whether the serio_sem is
688 * taken or not and when delayed execution is feasible.
690 void __serio_unregister_port_delayed(struct serio *serio, struct module *owner)
692 serio_queue_event(serio, owner, SERIO_UNREGISTER_PORT);
697 * Serio driver operations
700 static ssize_t serio_driver_show_description(struct device_driver *drv, char *buf)
702 struct serio_driver *driver = to_serio_driver(drv);
703 return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)");
706 static ssize_t serio_driver_show_bind_mode(struct device_driver *drv, char *buf)
708 struct serio_driver *serio_drv = to_serio_driver(drv);
709 return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto");
712 static ssize_t serio_driver_set_bind_mode(struct device_driver *drv, const char *buf, size_t count)
714 struct serio_driver *serio_drv = to_serio_driver(drv);
715 int retval;
717 retval = count;
718 if (!strncmp(buf, "manual", count)) {
719 serio_drv->manual_bind = 1;
720 } else if (!strncmp(buf, "auto", count)) {
721 serio_drv->manual_bind = 0;
722 } else {
723 retval = -EINVAL;
726 return retval;
730 static struct driver_attribute serio_driver_attrs[] = {
731 __ATTR(description, S_IRUGO, serio_driver_show_description, NULL),
732 __ATTR(bind_mode, S_IWUSR | S_IRUGO,
733 serio_driver_show_bind_mode, serio_driver_set_bind_mode),
734 __ATTR_NULL
737 static int serio_driver_probe(struct device *dev)
739 struct serio *serio = to_serio_port(dev);
740 struct serio_driver *drv = to_serio_driver(dev->driver);
742 return serio_connect_driver(serio, drv);
745 static int serio_driver_remove(struct device *dev)
747 struct serio *serio = to_serio_port(dev);
749 serio_disconnect_driver(serio);
750 return 0;
753 void __serio_register_driver(struct serio_driver *drv, struct module *owner)
755 drv->driver.bus = &serio_bus;
756 drv->driver.probe = serio_driver_probe;
757 drv->driver.remove = serio_driver_remove;
759 serio_queue_event(drv, owner, SERIO_REGISTER_DRIVER);
762 void serio_unregister_driver(struct serio_driver *drv)
764 struct serio *serio;
766 down(&serio_sem);
767 drv->manual_bind = 1; /* so serio_find_driver ignores it */
769 start_over:
770 list_for_each_entry(serio, &serio_list, node) {
771 if (serio->drv == drv) {
772 serio_disconnect_port(serio);
773 serio_find_driver(serio);
774 /* we could've deleted some ports, restart */
775 goto start_over;
779 driver_unregister(&drv->driver);
780 up(&serio_sem);
783 static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
785 serio_pause_rx(serio);
786 serio->drv = drv;
787 serio_continue_rx(serio);
790 static int serio_bus_match(struct device *dev, struct device_driver *drv)
792 struct serio *serio = to_serio_port(dev);
793 struct serio_driver *serio_drv = to_serio_driver(drv);
795 if (serio->manual_bind || serio_drv->manual_bind)
796 return 0;
798 return serio_match_port(serio_drv->id_table, serio);
801 #ifdef CONFIG_HOTPLUG
803 #define SERIO_ADD_HOTPLUG_VAR(fmt, val...) \
804 do { \
805 int err = add_hotplug_env_var(envp, num_envp, &i, \
806 buffer, buffer_size, &len, \
807 fmt, val); \
808 if (err) \
809 return err; \
810 } while (0)
812 static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
814 struct serio *serio;
815 int i = 0;
816 int len = 0;
818 if (!dev)
819 return -ENODEV;
821 serio = to_serio_port(dev);
823 SERIO_ADD_HOTPLUG_VAR("SERIO_TYPE=%02x", serio->id.type);
824 SERIO_ADD_HOTPLUG_VAR("SERIO_PROTO=%02x", serio->id.proto);
825 SERIO_ADD_HOTPLUG_VAR("SERIO_ID=%02x", serio->id.id);
826 SERIO_ADD_HOTPLUG_VAR("SERIO_EXTRA=%02x", serio->id.extra);
827 SERIO_ADD_HOTPLUG_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
828 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
829 envp[i] = NULL;
831 return 0;
833 #undef SERIO_ADD_HOTPLUG_VAR
835 #else
837 static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
839 return -ENODEV;
842 #endif /* CONFIG_HOTPLUG */
844 static int serio_resume(struct device *dev)
846 struct serio *serio = to_serio_port(dev);
848 if (serio_reconnect_driver(serio)) {
850 * Driver re-probing can take a while, so better let kseriod
851 * deal with it.
853 serio_rescan(serio);
856 return 0;
859 /* called from serio_driver->connect/disconnect methods under serio_sem */
860 int serio_open(struct serio *serio, struct serio_driver *drv)
862 serio_set_drv(serio, drv);
864 if (serio->open && serio->open(serio)) {
865 serio_set_drv(serio, NULL);
866 return -1;
868 return 0;
871 /* called from serio_driver->connect/disconnect methods under serio_sem */
872 void serio_close(struct serio *serio)
874 if (serio->close)
875 serio->close(serio);
877 serio_set_drv(serio, NULL);
880 irqreturn_t serio_interrupt(struct serio *serio,
881 unsigned char data, unsigned int dfl, struct pt_regs *regs)
883 unsigned long flags;
884 irqreturn_t ret = IRQ_NONE;
886 spin_lock_irqsave(&serio->lock, flags);
888 if (likely(serio->drv)) {
889 ret = serio->drv->interrupt(serio, data, dfl, regs);
890 } else if (!dfl && serio->registered) {
891 serio_rescan(serio);
892 ret = IRQ_HANDLED;
895 spin_unlock_irqrestore(&serio->lock, flags);
897 return ret;
900 static int __init serio_init(void)
902 serio_task = kthread_run(serio_thread, NULL, "kseriod");
903 if (IS_ERR(serio_task)) {
904 printk(KERN_ERR "serio: Failed to start kseriod\n");
905 return PTR_ERR(serio_task);
908 serio_bus.dev_attrs = serio_device_attrs;
909 serio_bus.drv_attrs = serio_driver_attrs;
910 serio_bus.match = serio_bus_match;
911 serio_bus.hotplug = serio_hotplug;
912 serio_bus.resume = serio_resume;
913 bus_register(&serio_bus);
915 return 0;
918 static void __exit serio_exit(void)
920 bus_unregister(&serio_bus);
921 kthread_stop(serio_task);
924 module_init(serio_init);
925 module_exit(serio_exit);