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>
38 #include <linux/freezer.h>
40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41 MODULE_DESCRIPTION("Serio abstraction core");
42 MODULE_LICENSE("GPL");
44 EXPORT_SYMBOL(serio_interrupt
);
45 EXPORT_SYMBOL(__serio_register_port
);
46 EXPORT_SYMBOL(serio_unregister_port
);
47 EXPORT_SYMBOL(serio_unregister_child_port
);
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_port(struct serio
*serio
);
66 static int serio_reconnect_port(struct serio
*serio
);
67 static void serio_disconnect_port(struct serio
*serio
);
68 static void serio_reconnect_chain(struct serio
*serio
);
69 static void serio_attach_driver(struct serio_driver
*drv
);
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 int serio_bind_driver(struct serio
*serio
, struct serio_driver
*drv
)
123 if (serio_match_port(drv
->id_table
, serio
)) {
125 serio
->dev
.driver
= &drv
->driver
;
126 if (serio_connect_driver(serio
, drv
)) {
127 serio
->dev
.driver
= NULL
;
131 error
= device_bind_driver(&serio
->dev
);
134 "serio: device_bind_driver() failed "
135 "for %s (%s) and %s, error: %d\n",
136 serio
->phys
, serio
->name
,
137 drv
->description
, error
);
138 serio_disconnect_driver(serio
);
139 serio
->dev
.driver
= NULL
;
146 static void serio_find_driver(struct serio
*serio
)
150 error
= device_attach(&serio
->dev
);
153 "serio: device_attach() failed for %s (%s), error: %d\n",
154 serio
->phys
, serio
->name
, error
);
159 * Serio event processing.
162 enum serio_event_type
{
164 SERIO_RECONNECT_PORT
,
165 SERIO_RECONNECT_CHAIN
,
171 enum serio_event_type type
;
173 struct module
*owner
;
174 struct list_head node
;
177 static DEFINE_SPINLOCK(serio_event_lock
); /* protects serio_event_list */
178 static LIST_HEAD(serio_event_list
);
179 static DECLARE_WAIT_QUEUE_HEAD(serio_wait
);
180 static struct task_struct
*serio_task
;
182 static int serio_queue_event(void *object
, struct module
*owner
,
183 enum serio_event_type event_type
)
186 struct serio_event
*event
;
189 spin_lock_irqsave(&serio_event_lock
, flags
);
192 * Scan event list for the other events for the same serio port,
193 * starting with the most recent one. If event is the same we
194 * do not need add new one. If event is of different type we
195 * need to add this event and should not look further because
196 * we need to preseve sequence of distinct events.
198 list_for_each_entry_reverse(event
, &serio_event_list
, node
) {
199 if (event
->object
== object
) {
200 if (event
->type
== event_type
)
206 event
= kmalloc(sizeof(struct serio_event
), GFP_ATOMIC
);
209 "serio: Not enough memory to queue event %d\n",
215 if (!try_module_get(owner
)) {
217 "serio: Can't get module reference, dropping event %d\n",
224 event
->type
= event_type
;
225 event
->object
= object
;
226 event
->owner
= owner
;
228 list_add_tail(&event
->node
, &serio_event_list
);
229 wake_up(&serio_wait
);
232 spin_unlock_irqrestore(&serio_event_lock
, flags
);
236 static void serio_free_event(struct serio_event
*event
)
238 module_put(event
->owner
);
242 static void serio_remove_duplicate_events(struct serio_event
*event
)
244 struct list_head
*node
, *next
;
245 struct serio_event
*e
;
248 spin_lock_irqsave(&serio_event_lock
, flags
);
250 list_for_each_safe(node
, next
, &serio_event_list
) {
251 e
= list_entry(node
, struct serio_event
, node
);
252 if (event
->object
== e
->object
) {
254 * If this event is of different type we should not
255 * look further - we only suppress duplicate events
256 * that were sent back-to-back.
258 if (event
->type
!= e
->type
)
266 spin_unlock_irqrestore(&serio_event_lock
, flags
);
270 static struct serio_event
*serio_get_event(void)
272 struct serio_event
*event
;
273 struct list_head
*node
;
276 spin_lock_irqsave(&serio_event_lock
, flags
);
278 if (list_empty(&serio_event_list
)) {
279 spin_unlock_irqrestore(&serio_event_lock
, flags
);
283 node
= serio_event_list
.next
;
284 event
= list_entry(node
, struct serio_event
, node
);
287 spin_unlock_irqrestore(&serio_event_lock
, flags
);
292 static void serio_handle_event(void)
294 struct serio_event
*event
;
296 mutex_lock(&serio_mutex
);
299 * Note that we handle only one event here to give swsusp
300 * a chance to freeze kseriod thread. Serio events should
301 * be pretty rare so we are not concerned about taking
304 if ((event
= serio_get_event())) {
306 switch (event
->type
) {
307 case SERIO_REGISTER_PORT
:
308 serio_add_port(event
->object
);
311 case SERIO_RECONNECT_PORT
:
312 serio_reconnect_port(event
->object
);
315 case SERIO_RESCAN_PORT
:
316 serio_disconnect_port(event
->object
);
317 serio_find_driver(event
->object
);
320 case SERIO_RECONNECT_CHAIN
:
321 serio_reconnect_chain(event
->object
);
324 case SERIO_ATTACH_DRIVER
:
325 serio_attach_driver(event
->object
);
332 serio_remove_duplicate_events(event
);
333 serio_free_event(event
);
336 mutex_unlock(&serio_mutex
);
340 * Remove all events that have been submitted for a given
341 * object, be it serio port or driver.
343 static void serio_remove_pending_events(void *object
)
345 struct list_head
*node
, *next
;
346 struct serio_event
*event
;
349 spin_lock_irqsave(&serio_event_lock
, flags
);
351 list_for_each_safe(node
, next
, &serio_event_list
) {
352 event
= list_entry(node
, struct serio_event
, node
);
353 if (event
->object
== object
) {
355 serio_free_event(event
);
359 spin_unlock_irqrestore(&serio_event_lock
, flags
);
363 * Destroy child serio port (if any) that has not been fully registered yet.
365 * Note that we rely on the fact that port can have only one child and therefore
366 * only one child registration request can be pending. Additionally, children
367 * are registered by driver's connect() handler so there can't be a grandchild
368 * pending registration together with a child.
370 static struct serio
*serio_get_pending_child(struct serio
*parent
)
372 struct serio_event
*event
;
373 struct serio
*serio
, *child
= NULL
;
376 spin_lock_irqsave(&serio_event_lock
, flags
);
378 list_for_each_entry(event
, &serio_event_list
, node
) {
379 if (event
->type
== SERIO_REGISTER_PORT
) {
380 serio
= event
->object
;
381 if (serio
->parent
== parent
) {
388 spin_unlock_irqrestore(&serio_event_lock
, flags
);
392 static int serio_thread(void *nothing
)
396 serio_handle_event();
397 wait_event_freezable(serio_wait
,
398 kthread_should_stop() || !list_empty(&serio_event_list
));
399 } while (!kthread_should_stop());
401 printk(KERN_DEBUG
"serio: kseriod exiting\n");
407 * Serio port operations
410 static ssize_t
serio_show_description(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
412 struct serio
*serio
= to_serio_port(dev
);
413 return sprintf(buf
, "%s\n", serio
->name
);
416 static ssize_t
serio_show_modalias(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
418 struct serio
*serio
= to_serio_port(dev
);
420 return sprintf(buf
, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
421 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
424 static ssize_t
serio_show_id_type(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
.type
);
430 static ssize_t
serio_show_id_proto(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
432 struct serio
*serio
= to_serio_port(dev
);
433 return sprintf(buf
, "%02x\n", serio
->id
.proto
);
436 static ssize_t
serio_show_id_id(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
438 struct serio
*serio
= to_serio_port(dev
);
439 return sprintf(buf
, "%02x\n", serio
->id
.id
);
442 static ssize_t
serio_show_id_extra(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
444 struct serio
*serio
= to_serio_port(dev
);
445 return sprintf(buf
, "%02x\n", serio
->id
.extra
);
448 static DEVICE_ATTR(type
, S_IRUGO
, serio_show_id_type
, NULL
);
449 static DEVICE_ATTR(proto
, S_IRUGO
, serio_show_id_proto
, NULL
);
450 static DEVICE_ATTR(id
, S_IRUGO
, serio_show_id_id
, NULL
);
451 static DEVICE_ATTR(extra
, S_IRUGO
, serio_show_id_extra
, NULL
);
453 static struct attribute
*serio_device_id_attrs
[] = {
455 &dev_attr_proto
.attr
,
457 &dev_attr_extra
.attr
,
461 static struct attribute_group serio_id_attr_group
= {
463 .attrs
= serio_device_id_attrs
,
466 static ssize_t
serio_rebind_driver(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
468 struct serio
*serio
= to_serio_port(dev
);
469 struct device_driver
*drv
;
472 error
= mutex_lock_interruptible(&serio_mutex
);
476 if (!strncmp(buf
, "none", count
)) {
477 serio_disconnect_port(serio
);
478 } else if (!strncmp(buf
, "reconnect", count
)) {
479 serio_reconnect_chain(serio
);
480 } else if (!strncmp(buf
, "rescan", count
)) {
481 serio_disconnect_port(serio
);
482 serio_find_driver(serio
);
483 } else if ((drv
= driver_find(buf
, &serio_bus
)) != NULL
) {
484 serio_disconnect_port(serio
);
485 error
= serio_bind_driver(serio
, to_serio_driver(drv
));
491 mutex_unlock(&serio_mutex
);
493 return error
? error
: count
;
496 static ssize_t
serio_show_bind_mode(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
498 struct serio
*serio
= to_serio_port(dev
);
499 return sprintf(buf
, "%s\n", serio
->manual_bind
? "manual" : "auto");
502 static ssize_t
serio_set_bind_mode(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
504 struct serio
*serio
= to_serio_port(dev
);
508 if (!strncmp(buf
, "manual", count
)) {
509 serio
->manual_bind
= 1;
510 } else if (!strncmp(buf
, "auto", count
)) {
511 serio
->manual_bind
= 0;
519 static struct device_attribute serio_device_attrs
[] = {
520 __ATTR(description
, S_IRUGO
, serio_show_description
, NULL
),
521 __ATTR(modalias
, S_IRUGO
, serio_show_modalias
, NULL
),
522 __ATTR(drvctl
, S_IWUSR
, NULL
, serio_rebind_driver
),
523 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
, serio_show_bind_mode
, serio_set_bind_mode
),
528 static void serio_release_port(struct device
*dev
)
530 struct serio
*serio
= to_serio_port(dev
);
533 module_put(THIS_MODULE
);
537 * Prepare serio port for registration.
539 static void serio_init_port(struct serio
*serio
)
541 static atomic_t serio_no
= ATOMIC_INIT(0);
543 __module_get(THIS_MODULE
);
545 INIT_LIST_HEAD(&serio
->node
);
546 spin_lock_init(&serio
->lock
);
547 mutex_init(&serio
->drv_mutex
);
548 device_initialize(&serio
->dev
);
549 snprintf(serio
->dev
.bus_id
, sizeof(serio
->dev
.bus_id
),
550 "serio%ld", (long)atomic_inc_return(&serio_no
) - 1);
551 serio
->dev
.bus
= &serio_bus
;
552 serio
->dev
.release
= serio_release_port
;
554 serio
->dev
.parent
= &serio
->parent
->dev
;
555 serio
->depth
= serio
->parent
->depth
+ 1;
558 lockdep_set_subclass(&serio
->lock
, serio
->depth
);
562 * Complete serio port registration.
563 * Driver core will attempt to find appropriate driver for the port.
565 static void serio_add_port(struct serio
*serio
)
570 serio_pause_rx(serio
->parent
);
571 serio
->parent
->child
= serio
;
572 serio_continue_rx(serio
->parent
);
575 list_add_tail(&serio
->node
, &serio_list
);
578 error
= device_add(&serio
->dev
);
581 "serio: device_add() failed for %s (%s), error: %d\n",
582 serio
->phys
, serio
->name
, error
);
584 serio
->registered
= 1;
585 error
= sysfs_create_group(&serio
->dev
.kobj
, &serio_id_attr_group
);
588 "serio: sysfs_create_group() failed for %s (%s), error: %d\n",
589 serio
->phys
, serio
->name
, error
);
594 * serio_destroy_port() completes deregistration process and removes
595 * port from the system
597 static void serio_destroy_port(struct serio
*serio
)
601 child
= serio_get_pending_child(serio
);
603 serio_remove_pending_events(child
);
604 put_device(&child
->dev
);
611 serio_pause_rx(serio
->parent
);
612 serio
->parent
->child
= NULL
;
613 serio_continue_rx(serio
->parent
);
614 serio
->parent
= NULL
;
617 if (serio
->registered
) {
618 sysfs_remove_group(&serio
->dev
.kobj
, &serio_id_attr_group
);
619 device_del(&serio
->dev
);
620 serio
->registered
= 0;
623 list_del_init(&serio
->node
);
624 serio_remove_pending_events(serio
);
625 put_device(&serio
->dev
);
629 * Reconnect serio port (re-initialize attached device).
630 * If reconnect fails (old device is no longer attached or
631 * there was no device to begin with) we do full rescan in
632 * hope of finding a driver for the port.
634 static int serio_reconnect_port(struct serio
*serio
)
636 int error
= serio_reconnect_driver(serio
);
639 serio_disconnect_port(serio
);
640 serio_find_driver(serio
);
647 * Reconnect serio port and all its children (re-initialize attached devices)
649 static void serio_reconnect_chain(struct serio
*serio
)
652 if (serio_reconnect_port(serio
)) {
653 /* Ok, old children are now gone, we are done */
656 serio
= serio
->child
;
661 * serio_disconnect_port() unbinds a port from its driver. As a side effect
662 * all child ports are unbound and destroyed.
664 static void serio_disconnect_port(struct serio
*serio
)
666 struct serio
*s
, *parent
;
670 * Children ports should be disconnected and destroyed
671 * first, staring with the leaf one, since we don't want
674 for (s
= serio
; s
->child
; s
= s
->child
)
680 device_release_driver(&s
->dev
);
681 serio_destroy_port(s
);
682 } while ((s
= parent
) != serio
);
686 * Ok, no children left, now disconnect this port
688 device_release_driver(&serio
->dev
);
691 void serio_rescan(struct serio
*serio
)
693 serio_queue_event(serio
, NULL
, SERIO_RESCAN_PORT
);
696 void serio_reconnect(struct serio
*serio
)
698 serio_queue_event(serio
, NULL
, SERIO_RECONNECT_CHAIN
);
702 * Submits register request to kseriod for subsequent execution.
703 * Note that port registration is always asynchronous.
705 void __serio_register_port(struct serio
*serio
, struct module
*owner
)
707 serio_init_port(serio
);
708 serio_queue_event(serio
, owner
, SERIO_REGISTER_PORT
);
712 * Synchronously unregisters serio port.
714 void serio_unregister_port(struct serio
*serio
)
716 mutex_lock(&serio_mutex
);
717 serio_disconnect_port(serio
);
718 serio_destroy_port(serio
);
719 mutex_unlock(&serio_mutex
);
723 * Safely unregisters child port if one is present.
725 void serio_unregister_child_port(struct serio
*serio
)
727 mutex_lock(&serio_mutex
);
729 serio_disconnect_port(serio
->child
);
730 serio_destroy_port(serio
->child
);
732 mutex_unlock(&serio_mutex
);
737 * Serio driver operations
740 static ssize_t
serio_driver_show_description(struct device_driver
*drv
, char *buf
)
742 struct serio_driver
*driver
= to_serio_driver(drv
);
743 return sprintf(buf
, "%s\n", driver
->description
? driver
->description
: "(none)");
746 static ssize_t
serio_driver_show_bind_mode(struct device_driver
*drv
, char *buf
)
748 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
749 return sprintf(buf
, "%s\n", serio_drv
->manual_bind
? "manual" : "auto");
752 static ssize_t
serio_driver_set_bind_mode(struct device_driver
*drv
, const char *buf
, size_t count
)
754 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
758 if (!strncmp(buf
, "manual", count
)) {
759 serio_drv
->manual_bind
= 1;
760 } else if (!strncmp(buf
, "auto", count
)) {
761 serio_drv
->manual_bind
= 0;
770 static struct driver_attribute serio_driver_attrs
[] = {
771 __ATTR(description
, S_IRUGO
, serio_driver_show_description
, NULL
),
772 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
,
773 serio_driver_show_bind_mode
, serio_driver_set_bind_mode
),
777 static int serio_driver_probe(struct device
*dev
)
779 struct serio
*serio
= to_serio_port(dev
);
780 struct serio_driver
*drv
= to_serio_driver(dev
->driver
);
782 return serio_connect_driver(serio
, drv
);
785 static int serio_driver_remove(struct device
*dev
)
787 struct serio
*serio
= to_serio_port(dev
);
789 serio_disconnect_driver(serio
);
793 static void serio_cleanup(struct serio
*serio
)
795 mutex_lock(&serio
->drv_mutex
);
796 if (serio
->drv
&& serio
->drv
->cleanup
)
797 serio
->drv
->cleanup(serio
);
798 mutex_unlock(&serio
->drv_mutex
);
801 static void serio_shutdown(struct device
*dev
)
803 struct serio
*serio
= to_serio_port(dev
);
805 serio_cleanup(serio
);
808 static void serio_attach_driver(struct serio_driver
*drv
)
812 error
= driver_attach(&drv
->driver
);
815 "serio: driver_attach() failed for %s with error %d\n",
816 drv
->driver
.name
, error
);
819 int __serio_register_driver(struct serio_driver
*drv
, struct module
*owner
, const char *mod_name
)
821 int manual_bind
= drv
->manual_bind
;
824 drv
->driver
.bus
= &serio_bus
;
825 drv
->driver
.owner
= owner
;
826 drv
->driver
.mod_name
= mod_name
;
829 * Temporarily disable automatic binding because probing
830 * takes long time and we are better off doing it in kseriod
832 drv
->manual_bind
= 1;
834 error
= driver_register(&drv
->driver
);
837 "serio: driver_register() failed for %s, error: %d\n",
838 drv
->driver
.name
, error
);
843 * Restore original bind mode and let kseriod bind the
844 * driver to free ports
847 drv
->manual_bind
= 0;
848 error
= serio_queue_event(drv
, NULL
, SERIO_ATTACH_DRIVER
);
850 driver_unregister(&drv
->driver
);
858 void serio_unregister_driver(struct serio_driver
*drv
)
862 mutex_lock(&serio_mutex
);
864 drv
->manual_bind
= 1; /* so serio_find_driver ignores it */
865 serio_remove_pending_events(drv
);
868 list_for_each_entry(serio
, &serio_list
, node
) {
869 if (serio
->drv
== drv
) {
870 serio_disconnect_port(serio
);
871 serio_find_driver(serio
);
872 /* we could've deleted some ports, restart */
877 driver_unregister(&drv
->driver
);
878 mutex_unlock(&serio_mutex
);
881 static void serio_set_drv(struct serio
*serio
, struct serio_driver
*drv
)
883 serio_pause_rx(serio
);
885 serio_continue_rx(serio
);
888 static int serio_bus_match(struct device
*dev
, struct device_driver
*drv
)
890 struct serio
*serio
= to_serio_port(dev
);
891 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
893 if (serio
->manual_bind
|| serio_drv
->manual_bind
)
896 return serio_match_port(serio_drv
->id_table
, serio
);
899 #ifdef CONFIG_HOTPLUG
901 #define SERIO_ADD_UEVENT_VAR(fmt, val...) \
903 int err = add_uevent_var(env, fmt, val); \
908 static int serio_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
915 serio
= to_serio_port(dev
);
917 SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio
->id
.type
);
918 SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio
->id
.proto
);
919 SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio
->id
.id
);
920 SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio
->id
.extra
);
921 SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
922 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
926 #undef SERIO_ADD_UEVENT_VAR
930 static int serio_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
935 #endif /* CONFIG_HOTPLUG */
938 static int serio_suspend(struct device
*dev
, pm_message_t state
)
940 if (dev
->power
.power_state
.event
!= state
.event
) {
941 if (state
.event
== PM_EVENT_SUSPEND
)
942 serio_cleanup(to_serio_port(dev
));
944 dev
->power
.power_state
= state
;
950 static int serio_resume(struct device
*dev
)
953 * Driver reconnect can take a while, so better let kseriod
956 if (dev
->power
.power_state
.event
!= PM_EVENT_ON
) {
957 dev
->power
.power_state
= PMSG_ON
;
958 serio_queue_event(to_serio_port(dev
), NULL
,
959 SERIO_RECONNECT_PORT
);
964 #endif /* CONFIG_PM */
966 /* called from serio_driver->connect/disconnect methods under serio_mutex */
967 int serio_open(struct serio
*serio
, struct serio_driver
*drv
)
969 serio_set_drv(serio
, drv
);
971 if (serio
->open
&& serio
->open(serio
)) {
972 serio_set_drv(serio
, NULL
);
978 /* called from serio_driver->connect/disconnect methods under serio_mutex */
979 void serio_close(struct serio
*serio
)
984 serio_set_drv(serio
, NULL
);
987 irqreturn_t
serio_interrupt(struct serio
*serio
,
988 unsigned char data
, unsigned int dfl
)
991 irqreturn_t ret
= IRQ_NONE
;
993 spin_lock_irqsave(&serio
->lock
, flags
);
995 if (likely(serio
->drv
)) {
996 ret
= serio
->drv
->interrupt(serio
, data
, dfl
);
997 } else if (!dfl
&& serio
->registered
) {
1002 spin_unlock_irqrestore(&serio
->lock
, flags
);
1007 static struct bus_type serio_bus
= {
1009 .dev_attrs
= serio_device_attrs
,
1010 .drv_attrs
= serio_driver_attrs
,
1011 .match
= serio_bus_match
,
1012 .uevent
= serio_uevent
,
1013 .probe
= serio_driver_probe
,
1014 .remove
= serio_driver_remove
,
1015 .shutdown
= serio_shutdown
,
1017 .suspend
= serio_suspend
,
1018 .resume
= serio_resume
,
1022 static int __init
serio_init(void)
1026 error
= bus_register(&serio_bus
);
1028 printk(KERN_ERR
"serio: failed to register serio bus, error: %d\n", error
);
1032 serio_task
= kthread_run(serio_thread
, NULL
, "kseriod");
1033 if (IS_ERR(serio_task
)) {
1034 bus_unregister(&serio_bus
);
1035 error
= PTR_ERR(serio_task
);
1036 printk(KERN_ERR
"serio: Failed to start kseriod, error: %d\n", error
);
1043 static void __exit
serio_exit(void)
1045 bus_unregister(&serio_bus
);
1046 kthread_stop(serio_task
);
1049 subsys_initcall(serio_init
);
1050 module_exit(serio_exit
);