2 * The Serio abstraction module
4 * Copyright (c) 1999-2004 Vojtech Pavlik
5 * Copyright (c) 2004 Dmitry Torokhov
6 * Copyright (c) 2003 Daniele Bellucci
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>
37 #include <linux/mutex.h>
39 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40 MODULE_DESCRIPTION("Serio abstraction core");
41 MODULE_LICENSE("GPL");
43 EXPORT_SYMBOL(serio_interrupt
);
44 EXPORT_SYMBOL(__serio_register_port
);
45 EXPORT_SYMBOL(serio_unregister_port
);
46 EXPORT_SYMBOL(serio_unregister_child_port
);
47 EXPORT_SYMBOL(__serio_unregister_port_delayed
);
48 EXPORT_SYMBOL(__serio_register_driver
);
49 EXPORT_SYMBOL(serio_unregister_driver
);
50 EXPORT_SYMBOL(serio_open
);
51 EXPORT_SYMBOL(serio_close
);
52 EXPORT_SYMBOL(serio_rescan
);
53 EXPORT_SYMBOL(serio_reconnect
);
56 * serio_mutex protects entire serio subsystem and is taken every time
57 * serio port or driver registrered or unregistered.
59 static DEFINE_MUTEX(serio_mutex
);
61 static LIST_HEAD(serio_list
);
63 static struct bus_type serio_bus
;
65 static void serio_add_driver(struct serio_driver
*drv
);
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
)
75 mutex_lock(&serio
->drv_mutex
);
76 retval
= drv
->connect(serio
, drv
);
77 mutex_unlock(&serio
->drv_mutex
);
82 static int serio_reconnect_driver(struct serio
*serio
)
86 mutex_lock(&serio
->drv_mutex
);
87 if (serio
->drv
&& serio
->drv
->reconnect
)
88 retval
= serio
->drv
->reconnect(serio
);
89 mutex_unlock(&serio
->drv_mutex
);
94 static void serio_disconnect_driver(struct serio
*serio
)
96 mutex_lock(&serio
->drv_mutex
);
98 serio
->drv
->disconnect(serio
);
99 mutex_unlock(&serio
->drv_mutex
);
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
))
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
;
129 device_bind_driver(&serio
->dev
);
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
)
146 down_write(&serio_bus
.subsys
.rwsem
);
147 error
= device_attach(&serio
->dev
);
150 "serio: device_attach() failed for %s (%s), error: %d\n",
151 serio
->phys
, serio
->name
, error
);
152 up_write(&serio_bus
.subsys
.rwsem
);
157 * Serio event processing.
160 enum serio_event_type
{
164 SERIO_UNREGISTER_PORT
,
165 SERIO_REGISTER_DRIVER
,
169 enum serio_event_type type
;
171 struct module
*owner
;
172 struct list_head node
;
175 static DEFINE_SPINLOCK(serio_event_lock
); /* protects serio_event_list */
176 static LIST_HEAD(serio_event_list
);
177 static DECLARE_WAIT_QUEUE_HEAD(serio_wait
);
178 static struct task_struct
*serio_task
;
180 static void serio_queue_event(void *object
, struct module
*owner
,
181 enum serio_event_type event_type
)
184 struct serio_event
*event
;
186 spin_lock_irqsave(&serio_event_lock
, flags
);
189 * Scan event list for the other events for the same serio port,
190 * starting with the most recent one. If event is the same we
191 * do not need add new one. If event is of different type we
192 * need to add this event and should not look further because
193 * we need to preseve sequence of distinct events.
195 list_for_each_entry_reverse(event
, &serio_event_list
, node
) {
196 if (event
->object
== object
) {
197 if (event
->type
== event_type
)
203 if ((event
= kmalloc(sizeof(struct serio_event
), GFP_ATOMIC
))) {
204 if (!try_module_get(owner
)) {
205 printk(KERN_WARNING
"serio: Can't get module reference, dropping event %d\n", event_type
);
210 event
->type
= event_type
;
211 event
->object
= object
;
212 event
->owner
= owner
;
214 list_add_tail(&event
->node
, &serio_event_list
);
215 wake_up(&serio_wait
);
217 printk(KERN_ERR
"serio: Not enough memory to queue event %d\n", event_type
);
220 spin_unlock_irqrestore(&serio_event_lock
, flags
);
223 static void serio_free_event(struct serio_event
*event
)
225 module_put(event
->owner
);
229 static void serio_remove_duplicate_events(struct serio_event
*event
)
231 struct list_head
*node
, *next
;
232 struct serio_event
*e
;
235 spin_lock_irqsave(&serio_event_lock
, flags
);
237 list_for_each_safe(node
, next
, &serio_event_list
) {
238 e
= list_entry(node
, struct serio_event
, node
);
239 if (event
->object
== e
->object
) {
241 * If this event is of different type we should not
242 * look further - we only suppress duplicate events
243 * that were sent back-to-back.
245 if (event
->type
!= e
->type
)
253 spin_unlock_irqrestore(&serio_event_lock
, flags
);
257 static struct serio_event
*serio_get_event(void)
259 struct serio_event
*event
;
260 struct list_head
*node
;
263 spin_lock_irqsave(&serio_event_lock
, flags
);
265 if (list_empty(&serio_event_list
)) {
266 spin_unlock_irqrestore(&serio_event_lock
, flags
);
270 node
= serio_event_list
.next
;
271 event
= list_entry(node
, struct serio_event
, node
);
274 spin_unlock_irqrestore(&serio_event_lock
, flags
);
279 static void serio_handle_event(void)
281 struct serio_event
*event
;
283 mutex_lock(&serio_mutex
);
286 * Note that we handle only one event here to give swsusp
287 * a chance to freeze kseriod thread. Serio events should
288 * be pretty rare so we are not concerned about taking
291 if ((event
= serio_get_event())) {
293 switch (event
->type
) {
294 case SERIO_REGISTER_PORT
:
295 serio_add_port(event
->object
);
298 case SERIO_UNREGISTER_PORT
:
299 serio_disconnect_port(event
->object
);
300 serio_destroy_port(event
->object
);
303 case SERIO_RECONNECT
:
304 serio_reconnect_port(event
->object
);
308 serio_disconnect_port(event
->object
);
309 serio_find_driver(event
->object
);
312 case SERIO_REGISTER_DRIVER
:
313 serio_add_driver(event
->object
);
320 serio_remove_duplicate_events(event
);
321 serio_free_event(event
);
324 mutex_unlock(&serio_mutex
);
328 * Remove all events that have been submitted for a given serio port.
330 static void serio_remove_pending_events(struct serio
*serio
)
332 struct list_head
*node
, *next
;
333 struct serio_event
*event
;
336 spin_lock_irqsave(&serio_event_lock
, flags
);
338 list_for_each_safe(node
, next
, &serio_event_list
) {
339 event
= list_entry(node
, struct serio_event
, node
);
340 if (event
->object
== serio
) {
342 serio_free_event(event
);
346 spin_unlock_irqrestore(&serio_event_lock
, flags
);
350 * Destroy child serio port (if any) that has not been fully registered yet.
352 * Note that we rely on the fact that port can have only one child and therefore
353 * only one child registration request can be pending. Additionally, children
354 * are registered by driver's connect() handler so there can't be a grandchild
355 * pending registration together with a child.
357 static struct serio
*serio_get_pending_child(struct serio
*parent
)
359 struct serio_event
*event
;
360 struct serio
*serio
, *child
= NULL
;
363 spin_lock_irqsave(&serio_event_lock
, flags
);
365 list_for_each_entry(event
, &serio_event_list
, node
) {
366 if (event
->type
== SERIO_REGISTER_PORT
) {
367 serio
= event
->object
;
368 if (serio
->parent
== parent
) {
375 spin_unlock_irqrestore(&serio_event_lock
, flags
);
379 static int serio_thread(void *nothing
)
382 serio_handle_event();
383 wait_event_interruptible(serio_wait
,
384 kthread_should_stop() || !list_empty(&serio_event_list
));
386 } while (!kthread_should_stop());
388 printk(KERN_DEBUG
"serio: kseriod exiting\n");
394 * Serio port operations
397 static ssize_t
serio_show_description(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
399 struct serio
*serio
= to_serio_port(dev
);
400 return sprintf(buf
, "%s\n", serio
->name
);
403 static ssize_t
serio_show_modalias(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
405 struct serio
*serio
= to_serio_port(dev
);
407 return sprintf(buf
, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
408 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
411 static ssize_t
serio_show_id_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
413 struct serio
*serio
= to_serio_port(dev
);
414 return sprintf(buf
, "%02x\n", serio
->id
.type
);
417 static ssize_t
serio_show_id_proto(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
419 struct serio
*serio
= to_serio_port(dev
);
420 return sprintf(buf
, "%02x\n", serio
->id
.proto
);
423 static ssize_t
serio_show_id_id(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
425 struct serio
*serio
= to_serio_port(dev
);
426 return sprintf(buf
, "%02x\n", serio
->id
.id
);
429 static ssize_t
serio_show_id_extra(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
431 struct serio
*serio
= to_serio_port(dev
);
432 return sprintf(buf
, "%02x\n", serio
->id
.extra
);
435 static DEVICE_ATTR(type
, S_IRUGO
, serio_show_id_type
, NULL
);
436 static DEVICE_ATTR(proto
, S_IRUGO
, serio_show_id_proto
, NULL
);
437 static DEVICE_ATTR(id
, S_IRUGO
, serio_show_id_id
, NULL
);
438 static DEVICE_ATTR(extra
, S_IRUGO
, serio_show_id_extra
, NULL
);
440 static struct attribute
*serio_device_id_attrs
[] = {
442 &dev_attr_proto
.attr
,
444 &dev_attr_extra
.attr
,
448 static struct attribute_group serio_id_attr_group
= {
450 .attrs
= serio_device_id_attrs
,
453 static ssize_t
serio_rebind_driver(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
455 struct serio
*serio
= to_serio_port(dev
);
456 struct device_driver
*drv
;
459 retval
= mutex_lock_interruptible(&serio_mutex
);
464 if (!strncmp(buf
, "none", count
)) {
465 serio_disconnect_port(serio
);
466 } else if (!strncmp(buf
, "reconnect", count
)) {
467 serio_reconnect_port(serio
);
468 } else if (!strncmp(buf
, "rescan", count
)) {
469 serio_disconnect_port(serio
);
470 serio_find_driver(serio
);
471 } else if ((drv
= driver_find(buf
, &serio_bus
)) != NULL
) {
472 serio_disconnect_port(serio
);
473 serio_bind_driver(serio
, to_serio_driver(drv
));
479 mutex_unlock(&serio_mutex
);
484 static ssize_t
serio_show_bind_mode(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
486 struct serio
*serio
= to_serio_port(dev
);
487 return sprintf(buf
, "%s\n", serio
->manual_bind
? "manual" : "auto");
490 static ssize_t
serio_set_bind_mode(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
492 struct serio
*serio
= to_serio_port(dev
);
496 if (!strncmp(buf
, "manual", count
)) {
497 serio
->manual_bind
= 1;
498 } else if (!strncmp(buf
, "auto", count
)) {
499 serio
->manual_bind
= 0;
507 static struct device_attribute serio_device_attrs
[] = {
508 __ATTR(description
, S_IRUGO
, serio_show_description
, NULL
),
509 __ATTR(modalias
, S_IRUGO
, serio_show_modalias
, NULL
),
510 __ATTR(drvctl
, S_IWUSR
, NULL
, serio_rebind_driver
),
511 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
, serio_show_bind_mode
, serio_set_bind_mode
),
516 static void serio_release_port(struct device
*dev
)
518 struct serio
*serio
= to_serio_port(dev
);
521 module_put(THIS_MODULE
);
525 * Prepare serio port for registration.
527 static void serio_init_port(struct serio
*serio
)
529 static atomic_t serio_no
= ATOMIC_INIT(0);
531 __module_get(THIS_MODULE
);
533 INIT_LIST_HEAD(&serio
->node
);
534 spin_lock_init(&serio
->lock
);
535 mutex_init(&serio
->drv_mutex
);
536 device_initialize(&serio
->dev
);
537 snprintf(serio
->dev
.bus_id
, sizeof(serio
->dev
.bus_id
),
538 "serio%ld", (long)atomic_inc_return(&serio_no
) - 1);
539 serio
->dev
.bus
= &serio_bus
;
540 serio
->dev
.release
= serio_release_port
;
542 serio
->dev
.parent
= &serio
->parent
->dev
;
546 * Complete serio port registration.
547 * Driver core will attempt to find appropriate driver for the port.
549 static void serio_add_port(struct serio
*serio
)
554 serio_pause_rx(serio
->parent
);
555 serio
->parent
->child
= serio
;
556 serio_continue_rx(serio
->parent
);
559 list_add_tail(&serio
->node
, &serio_list
);
562 error
= device_add(&serio
->dev
);
565 "serio: device_add() failed for %s (%s), error: %d\n",
566 serio
->phys
, serio
->name
, error
);
568 serio
->registered
= 1;
569 error
= sysfs_create_group(&serio
->dev
.kobj
, &serio_id_attr_group
);
572 "serio: sysfs_create_group() failed for %s (%s), error: %d\n",
573 serio
->phys
, serio
->name
, error
);
578 * serio_destroy_port() completes deregistration process and removes
579 * port from the system
581 static void serio_destroy_port(struct serio
*serio
)
585 child
= serio_get_pending_child(serio
);
587 serio_remove_pending_events(child
);
588 put_device(&child
->dev
);
595 serio_pause_rx(serio
->parent
);
596 serio
->parent
->child
= NULL
;
597 serio_continue_rx(serio
->parent
);
598 serio
->parent
= NULL
;
601 if (serio
->registered
) {
602 sysfs_remove_group(&serio
->dev
.kobj
, &serio_id_attr_group
);
603 device_del(&serio
->dev
);
604 serio
->registered
= 0;
607 list_del_init(&serio
->node
);
608 serio_remove_pending_events(serio
);
609 put_device(&serio
->dev
);
613 * Reconnect serio port and all its children (re-initialize attached devices)
615 static void serio_reconnect_port(struct serio
*serio
)
618 if (serio_reconnect_driver(serio
)) {
619 serio_disconnect_port(serio
);
620 serio_find_driver(serio
);
621 /* Ok, old children are now gone, we are done */
624 serio
= serio
->child
;
629 * serio_disconnect_port() unbinds a port from its driver. As a side effect
630 * all child ports are unbound and destroyed.
632 static void serio_disconnect_port(struct serio
*serio
)
634 struct serio
*s
, *parent
;
638 * Children ports should be disconnected and destroyed
639 * first, staring with the leaf one, since we don't want
642 for (s
= serio
; s
->child
; s
= s
->child
)
648 serio_release_driver(s
);
649 serio_destroy_port(s
);
650 } while ((s
= parent
) != serio
);
654 * Ok, no children left, now disconnect this port
656 serio_release_driver(serio
);
659 void serio_rescan(struct serio
*serio
)
661 serio_queue_event(serio
, NULL
, SERIO_RESCAN
);
664 void serio_reconnect(struct serio
*serio
)
666 serio_queue_event(serio
, NULL
, SERIO_RECONNECT
);
670 * Submits register request to kseriod for subsequent execution.
671 * Note that port registration is always asynchronous.
673 void __serio_register_port(struct serio
*serio
, struct module
*owner
)
675 serio_init_port(serio
);
676 serio_queue_event(serio
, owner
, SERIO_REGISTER_PORT
);
680 * Synchronously unregisters serio port.
682 void serio_unregister_port(struct serio
*serio
)
684 mutex_lock(&serio_mutex
);
685 serio_disconnect_port(serio
);
686 serio_destroy_port(serio
);
687 mutex_unlock(&serio_mutex
);
691 * Safely unregisters child port if one is present.
693 void serio_unregister_child_port(struct serio
*serio
)
695 mutex_lock(&serio_mutex
);
697 serio_disconnect_port(serio
->child
);
698 serio_destroy_port(serio
->child
);
700 mutex_unlock(&serio_mutex
);
704 * Submits register request to kseriod for subsequent execution.
705 * Can be used when it is not obvious whether the serio_mutex is
706 * taken or not and when delayed execution is feasible.
708 void __serio_unregister_port_delayed(struct serio
*serio
, struct module
*owner
)
710 serio_queue_event(serio
, owner
, SERIO_UNREGISTER_PORT
);
715 * Serio driver operations
718 static ssize_t
serio_driver_show_description(struct device_driver
*drv
, char *buf
)
720 struct serio_driver
*driver
= to_serio_driver(drv
);
721 return sprintf(buf
, "%s\n", driver
->description
? driver
->description
: "(none)");
724 static ssize_t
serio_driver_show_bind_mode(struct device_driver
*drv
, char *buf
)
726 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
727 return sprintf(buf
, "%s\n", serio_drv
->manual_bind
? "manual" : "auto");
730 static ssize_t
serio_driver_set_bind_mode(struct device_driver
*drv
, const char *buf
, size_t count
)
732 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
736 if (!strncmp(buf
, "manual", count
)) {
737 serio_drv
->manual_bind
= 1;
738 } else if (!strncmp(buf
, "auto", count
)) {
739 serio_drv
->manual_bind
= 0;
748 static struct driver_attribute serio_driver_attrs
[] = {
749 __ATTR(description
, S_IRUGO
, serio_driver_show_description
, NULL
),
750 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
,
751 serio_driver_show_bind_mode
, serio_driver_set_bind_mode
),
755 static int serio_driver_probe(struct device
*dev
)
757 struct serio
*serio
= to_serio_port(dev
);
758 struct serio_driver
*drv
= to_serio_driver(dev
->driver
);
760 return serio_connect_driver(serio
, drv
);
763 static int serio_driver_remove(struct device
*dev
)
765 struct serio
*serio
= to_serio_port(dev
);
767 serio_disconnect_driver(serio
);
771 static struct bus_type serio_bus
= {
773 .probe
= serio_driver_probe
,
774 .remove
= serio_driver_remove
,
777 static void serio_add_driver(struct serio_driver
*drv
)
781 error
= driver_register(&drv
->driver
);
784 "serio: driver_register() failed for %s, error: %d\n",
785 drv
->driver
.name
, error
);
788 void __serio_register_driver(struct serio_driver
*drv
, struct module
*owner
)
790 drv
->driver
.bus
= &serio_bus
;
792 serio_queue_event(drv
, owner
, SERIO_REGISTER_DRIVER
);
795 void serio_unregister_driver(struct serio_driver
*drv
)
799 mutex_lock(&serio_mutex
);
800 drv
->manual_bind
= 1; /* so serio_find_driver ignores it */
803 list_for_each_entry(serio
, &serio_list
, node
) {
804 if (serio
->drv
== drv
) {
805 serio_disconnect_port(serio
);
806 serio_find_driver(serio
);
807 /* we could've deleted some ports, restart */
812 driver_unregister(&drv
->driver
);
813 mutex_unlock(&serio_mutex
);
816 static void serio_set_drv(struct serio
*serio
, struct serio_driver
*drv
)
818 serio_pause_rx(serio
);
820 serio_continue_rx(serio
);
823 static int serio_bus_match(struct device
*dev
, struct device_driver
*drv
)
825 struct serio
*serio
= to_serio_port(dev
);
826 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
828 if (serio
->manual_bind
|| serio_drv
->manual_bind
)
831 return serio_match_port(serio_drv
->id_table
, serio
);
834 #ifdef CONFIG_HOTPLUG
836 #define SERIO_ADD_UEVENT_VAR(fmt, val...) \
838 int err = add_uevent_var(envp, num_envp, &i, \
839 buffer, buffer_size, &len, \
845 static int serio_uevent(struct device
*dev
, char **envp
, int num_envp
, char *buffer
, int buffer_size
)
854 serio
= to_serio_port(dev
);
856 SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio
->id
.type
);
857 SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio
->id
.proto
);
858 SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio
->id
.id
);
859 SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio
->id
.extra
);
860 SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
861 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
866 #undef SERIO_ADD_UEVENT_VAR
870 static int serio_uevent(struct device
*dev
, char **envp
, int num_envp
, char *buffer
, int buffer_size
)
875 #endif /* CONFIG_HOTPLUG */
877 static int serio_resume(struct device
*dev
)
879 struct serio
*serio
= to_serio_port(dev
);
881 if (serio_reconnect_driver(serio
)) {
883 * Driver re-probing can take a while, so better let kseriod
892 /* called from serio_driver->connect/disconnect methods under serio_mutex */
893 int serio_open(struct serio
*serio
, struct serio_driver
*drv
)
895 serio_set_drv(serio
, drv
);
897 if (serio
->open
&& serio
->open(serio
)) {
898 serio_set_drv(serio
, NULL
);
904 /* called from serio_driver->connect/disconnect methods under serio_mutex */
905 void serio_close(struct serio
*serio
)
910 serio_set_drv(serio
, NULL
);
913 irqreturn_t
serio_interrupt(struct serio
*serio
,
914 unsigned char data
, unsigned int dfl
, struct pt_regs
*regs
)
917 irqreturn_t ret
= IRQ_NONE
;
919 spin_lock_irqsave(&serio
->lock
, flags
);
921 if (likely(serio
->drv
)) {
922 ret
= serio
->drv
->interrupt(serio
, data
, dfl
, regs
);
923 } else if (!dfl
&& serio
->registered
) {
928 spin_unlock_irqrestore(&serio
->lock
, flags
);
933 static int __init
serio_init(void)
937 serio_bus
.dev_attrs
= serio_device_attrs
;
938 serio_bus
.drv_attrs
= serio_driver_attrs
;
939 serio_bus
.match
= serio_bus_match
;
940 serio_bus
.uevent
= serio_uevent
;
941 serio_bus
.resume
= serio_resume
;
942 error
= bus_register(&serio_bus
);
944 printk(KERN_ERR
"serio: failed to register serio bus, error: %d\n", error
);
948 serio_task
= kthread_run(serio_thread
, NULL
, "kseriod");
949 if (IS_ERR(serio_task
)) {
950 bus_unregister(&serio_bus
);
951 error
= PTR_ERR(serio_task
);
952 printk(KERN_ERR
"serio: Failed to start kseriod, error: %d\n", error
);
959 static void __exit
serio_exit(void)
961 bus_unregister(&serio_bus
);
962 kthread_stop(serio_task
);
965 subsys_initcall(serio_init
);
966 module_exit(serio_exit
);