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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/stddef.h>
32 #include <linux/module.h>
33 #include <linux/serio.h>
34 #include <linux/errno.h>
35 #include <linux/sched.h>
36 #include <linux/slab.h>
37 #include <linux/workqueue.h>
38 #include <linux/mutex.h>
40 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41 MODULE_DESCRIPTION("Serio abstraction core");
42 MODULE_LICENSE("GPL");
45 * serio_mutex protects entire serio subsystem and is taken every time
46 * serio port or driver registered or unregistered.
48 static DEFINE_MUTEX(serio_mutex
);
50 static LIST_HEAD(serio_list
);
52 static struct bus_type serio_bus
;
54 static void serio_add_port(struct serio
*serio
);
55 static int serio_reconnect_port(struct serio
*serio
);
56 static void serio_disconnect_port(struct serio
*serio
);
57 static void serio_reconnect_subtree(struct serio
*serio
);
58 static void serio_attach_driver(struct serio_driver
*drv
);
60 static int serio_connect_driver(struct serio
*serio
, struct serio_driver
*drv
)
64 mutex_lock(&serio
->drv_mutex
);
65 retval
= drv
->connect(serio
, drv
);
66 mutex_unlock(&serio
->drv_mutex
);
71 static int serio_reconnect_driver(struct serio
*serio
)
75 mutex_lock(&serio
->drv_mutex
);
76 if (serio
->drv
&& serio
->drv
->reconnect
)
77 retval
= serio
->drv
->reconnect(serio
);
78 mutex_unlock(&serio
->drv_mutex
);
83 static void serio_disconnect_driver(struct serio
*serio
)
85 mutex_lock(&serio
->drv_mutex
);
87 serio
->drv
->disconnect(serio
);
88 mutex_unlock(&serio
->drv_mutex
);
91 static int serio_match_port(const struct serio_device_id
*ids
, struct serio
*serio
)
93 while (ids
->type
|| ids
->proto
) {
94 if ((ids
->type
== SERIO_ANY
|| ids
->type
== serio
->id
.type
) &&
95 (ids
->proto
== SERIO_ANY
|| ids
->proto
== serio
->id
.proto
) &&
96 (ids
->extra
== SERIO_ANY
|| ids
->extra
== serio
->id
.extra
) &&
97 (ids
->id
== SERIO_ANY
|| ids
->id
== serio
->id
.id
))
105 * Basic serio -> driver core mappings
108 static int serio_bind_driver(struct serio
*serio
, struct serio_driver
*drv
)
112 if (serio_match_port(drv
->id_table
, serio
)) {
114 serio
->dev
.driver
= &drv
->driver
;
115 if (serio_connect_driver(serio
, drv
)) {
116 serio
->dev
.driver
= NULL
;
120 error
= device_bind_driver(&serio
->dev
);
122 dev_warn(&serio
->dev
,
123 "device_bind_driver() failed for %s (%s) and %s, error: %d\n",
124 serio
->phys
, serio
->name
,
125 drv
->description
, error
);
126 serio_disconnect_driver(serio
);
127 serio
->dev
.driver
= NULL
;
134 static void serio_find_driver(struct serio
*serio
)
138 error
= device_attach(&serio
->dev
);
140 dev_warn(&serio
->dev
,
141 "device_attach() failed for %s (%s), error: %d\n",
142 serio
->phys
, serio
->name
, error
);
147 * Serio event processing.
150 enum serio_event_type
{
152 SERIO_RECONNECT_PORT
,
153 SERIO_RECONNECT_SUBTREE
,
159 enum serio_event_type type
;
161 struct module
*owner
;
162 struct list_head node
;
165 static DEFINE_SPINLOCK(serio_event_lock
); /* protects serio_event_list */
166 static LIST_HEAD(serio_event_list
);
168 static struct serio_event
*serio_get_event(void)
170 struct serio_event
*event
= NULL
;
173 spin_lock_irqsave(&serio_event_lock
, flags
);
175 if (!list_empty(&serio_event_list
)) {
176 event
= list_first_entry(&serio_event_list
,
177 struct serio_event
, node
);
178 list_del_init(&event
->node
);
181 spin_unlock_irqrestore(&serio_event_lock
, flags
);
185 static void serio_free_event(struct serio_event
*event
)
187 module_put(event
->owner
);
191 static void serio_remove_duplicate_events(struct serio_event
*event
)
193 struct serio_event
*e
, *next
;
196 spin_lock_irqsave(&serio_event_lock
, flags
);
198 list_for_each_entry_safe(e
, next
, &serio_event_list
, node
) {
199 if (event
->object
== e
->object
) {
201 * If this event is of different type we should not
202 * look further - we only suppress duplicate events
203 * that were sent back-to-back.
205 if (event
->type
!= e
->type
)
208 list_del_init(&e
->node
);
213 spin_unlock_irqrestore(&serio_event_lock
, flags
);
216 static void serio_handle_event(struct work_struct
*work
)
218 struct serio_event
*event
;
220 mutex_lock(&serio_mutex
);
222 while ((event
= serio_get_event())) {
224 switch (event
->type
) {
226 case SERIO_REGISTER_PORT
:
227 serio_add_port(event
->object
);
230 case SERIO_RECONNECT_PORT
:
231 serio_reconnect_port(event
->object
);
234 case SERIO_RESCAN_PORT
:
235 serio_disconnect_port(event
->object
);
236 serio_find_driver(event
->object
);
239 case SERIO_RECONNECT_SUBTREE
:
240 serio_reconnect_subtree(event
->object
);
243 case SERIO_ATTACH_DRIVER
:
244 serio_attach_driver(event
->object
);
248 serio_remove_duplicate_events(event
);
249 serio_free_event(event
);
252 mutex_unlock(&serio_mutex
);
255 static DECLARE_WORK(serio_event_work
, serio_handle_event
);
257 static int serio_queue_event(void *object
, struct module
*owner
,
258 enum serio_event_type event_type
)
261 struct serio_event
*event
;
264 spin_lock_irqsave(&serio_event_lock
, flags
);
267 * Scan event list for the other events for the same serio port,
268 * starting with the most recent one. If event is the same we
269 * do not need add new one. If event is of different type we
270 * need to add this event and should not look further because
271 * we need to preseve sequence of distinct events.
273 list_for_each_entry_reverse(event
, &serio_event_list
, node
) {
274 if (event
->object
== object
) {
275 if (event
->type
== event_type
)
281 event
= kmalloc(sizeof(struct serio_event
), GFP_ATOMIC
);
283 pr_err("Not enough memory to queue event %d\n", event_type
);
288 if (!try_module_get(owner
)) {
289 pr_warning("Can't get module reference, dropping event %d\n",
296 event
->type
= event_type
;
297 event
->object
= object
;
298 event
->owner
= owner
;
300 list_add_tail(&event
->node
, &serio_event_list
);
301 schedule_work(&serio_event_work
);
304 spin_unlock_irqrestore(&serio_event_lock
, flags
);
309 * Remove all events that have been submitted for a given
310 * object, be it serio port or driver.
312 static void serio_remove_pending_events(void *object
)
314 struct serio_event
*event
, *next
;
317 spin_lock_irqsave(&serio_event_lock
, flags
);
319 list_for_each_entry_safe(event
, next
, &serio_event_list
, node
) {
320 if (event
->object
== object
) {
321 list_del_init(&event
->node
);
322 serio_free_event(event
);
326 spin_unlock_irqrestore(&serio_event_lock
, flags
);
330 * Locate child serio port (if any) that has not been fully registered yet.
332 * Children are registered by driver's connect() handler so there can't be a
333 * grandchild pending registration together with a child.
335 static struct serio
*serio_get_pending_child(struct serio
*parent
)
337 struct serio_event
*event
;
338 struct serio
*serio
, *child
= NULL
;
341 spin_lock_irqsave(&serio_event_lock
, flags
);
343 list_for_each_entry(event
, &serio_event_list
, node
) {
344 if (event
->type
== SERIO_REGISTER_PORT
) {
345 serio
= event
->object
;
346 if (serio
->parent
== parent
) {
353 spin_unlock_irqrestore(&serio_event_lock
, flags
);
358 * Serio port operations
361 static ssize_t
serio_show_description(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
363 struct serio
*serio
= to_serio_port(dev
);
364 return sprintf(buf
, "%s\n", serio
->name
);
367 static ssize_t
serio_show_modalias(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
369 struct serio
*serio
= to_serio_port(dev
);
371 return sprintf(buf
, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
372 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
375 static ssize_t
serio_show_id_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
377 struct serio
*serio
= to_serio_port(dev
);
378 return sprintf(buf
, "%02x\n", serio
->id
.type
);
381 static ssize_t
serio_show_id_proto(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
383 struct serio
*serio
= to_serio_port(dev
);
384 return sprintf(buf
, "%02x\n", serio
->id
.proto
);
387 static ssize_t
serio_show_id_id(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
389 struct serio
*serio
= to_serio_port(dev
);
390 return sprintf(buf
, "%02x\n", serio
->id
.id
);
393 static ssize_t
serio_show_id_extra(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
395 struct serio
*serio
= to_serio_port(dev
);
396 return sprintf(buf
, "%02x\n", serio
->id
.extra
);
399 static DEVICE_ATTR(type
, S_IRUGO
, serio_show_id_type
, NULL
);
400 static DEVICE_ATTR(proto
, S_IRUGO
, serio_show_id_proto
, NULL
);
401 static DEVICE_ATTR(id
, S_IRUGO
, serio_show_id_id
, NULL
);
402 static DEVICE_ATTR(extra
, S_IRUGO
, serio_show_id_extra
, NULL
);
404 static struct attribute
*serio_device_id_attrs
[] = {
406 &dev_attr_proto
.attr
,
408 &dev_attr_extra
.attr
,
412 static struct attribute_group serio_id_attr_group
= {
414 .attrs
= serio_device_id_attrs
,
417 static const struct attribute_group
*serio_device_attr_groups
[] = {
418 &serio_id_attr_group
,
422 static ssize_t
serio_rebind_driver(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
424 struct serio
*serio
= to_serio_port(dev
);
425 struct device_driver
*drv
;
428 error
= mutex_lock_interruptible(&serio_mutex
);
432 if (!strncmp(buf
, "none", count
)) {
433 serio_disconnect_port(serio
);
434 } else if (!strncmp(buf
, "reconnect", count
)) {
435 serio_reconnect_subtree(serio
);
436 } else if (!strncmp(buf
, "rescan", count
)) {
437 serio_disconnect_port(serio
);
438 serio_find_driver(serio
);
439 } else if ((drv
= driver_find(buf
, &serio_bus
)) != NULL
) {
440 serio_disconnect_port(serio
);
441 error
= serio_bind_driver(serio
, to_serio_driver(drv
));
447 mutex_unlock(&serio_mutex
);
449 return error
? error
: count
;
452 static ssize_t
serio_show_bind_mode(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
454 struct serio
*serio
= to_serio_port(dev
);
455 return sprintf(buf
, "%s\n", serio
->manual_bind
? "manual" : "auto");
458 static ssize_t
serio_set_bind_mode(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
460 struct serio
*serio
= to_serio_port(dev
);
464 if (!strncmp(buf
, "manual", count
)) {
465 serio
->manual_bind
= true;
466 } else if (!strncmp(buf
, "auto", count
)) {
467 serio
->manual_bind
= false;
475 static struct device_attribute serio_device_attrs
[] = {
476 __ATTR(description
, S_IRUGO
, serio_show_description
, NULL
),
477 __ATTR(modalias
, S_IRUGO
, serio_show_modalias
, NULL
),
478 __ATTR(drvctl
, S_IWUSR
, NULL
, serio_rebind_driver
),
479 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
, serio_show_bind_mode
, serio_set_bind_mode
),
484 static void serio_release_port(struct device
*dev
)
486 struct serio
*serio
= to_serio_port(dev
);
489 module_put(THIS_MODULE
);
493 * Prepare serio port for registration.
495 static void serio_init_port(struct serio
*serio
)
497 static atomic_t serio_no
= ATOMIC_INIT(0);
499 __module_get(THIS_MODULE
);
501 INIT_LIST_HEAD(&serio
->node
);
502 INIT_LIST_HEAD(&serio
->child_node
);
503 INIT_LIST_HEAD(&serio
->children
);
504 spin_lock_init(&serio
->lock
);
505 mutex_init(&serio
->drv_mutex
);
506 device_initialize(&serio
->dev
);
507 dev_set_name(&serio
->dev
, "serio%ld",
508 (long)atomic_inc_return(&serio_no
) - 1);
509 serio
->dev
.bus
= &serio_bus
;
510 serio
->dev
.release
= serio_release_port
;
511 serio
->dev
.groups
= serio_device_attr_groups
;
513 serio
->dev
.parent
= &serio
->parent
->dev
;
514 serio
->depth
= serio
->parent
->depth
+ 1;
517 lockdep_set_subclass(&serio
->lock
, serio
->depth
);
521 * Complete serio port registration.
522 * Driver core will attempt to find appropriate driver for the port.
524 static void serio_add_port(struct serio
*serio
)
526 struct serio
*parent
= serio
->parent
;
530 serio_pause_rx(parent
);
531 list_add_tail(&serio
->child_node
, &parent
->children
);
532 serio_continue_rx(parent
);
535 list_add_tail(&serio
->node
, &serio_list
);
540 error
= device_add(&serio
->dev
);
543 "device_add() failed for %s (%s), error: %d\n",
544 serio
->phys
, serio
->name
, error
);
548 * serio_destroy_port() completes unregistration process and removes
549 * port from the system
551 static void serio_destroy_port(struct serio
*serio
)
555 while ((child
= serio_get_pending_child(serio
)) != NULL
) {
556 serio_remove_pending_events(child
);
557 put_device(&child
->dev
);
564 serio_pause_rx(serio
->parent
);
565 list_del_init(&serio
->child_node
);
566 serio_continue_rx(serio
->parent
);
567 serio
->parent
= NULL
;
570 if (device_is_registered(&serio
->dev
))
571 device_del(&serio
->dev
);
573 list_del_init(&serio
->node
);
574 serio_remove_pending_events(serio
);
575 put_device(&serio
->dev
);
579 * Reconnect serio port (re-initialize attached device).
580 * If reconnect fails (old device is no longer attached or
581 * there was no device to begin with) we do full rescan in
582 * hope of finding a driver for the port.
584 static int serio_reconnect_port(struct serio
*serio
)
586 int error
= serio_reconnect_driver(serio
);
589 serio_disconnect_port(serio
);
590 serio_find_driver(serio
);
597 * Reconnect serio port and all its children (re-initialize attached
600 static void serio_reconnect_subtree(struct serio
*root
)
602 struct serio
*s
= root
;
606 error
= serio_reconnect_port(s
);
609 * Reconnect was successful, move on to do the
612 if (!list_empty(&s
->children
)) {
613 s
= list_first_entry(&s
->children
,
614 struct serio
, child_node
);
620 * Either it was a leaf node or reconnect failed and it
621 * became a leaf node. Continue reconnecting starting with
622 * the next sibling of the parent node.
625 struct serio
*parent
= s
->parent
;
627 if (!list_is_last(&s
->child_node
, &parent
->children
)) {
628 s
= list_entry(s
->child_node
.next
,
629 struct serio
, child_node
);
639 * serio_disconnect_port() unbinds a port from its driver. As a side effect
640 * all children ports are unbound and destroyed.
642 static void serio_disconnect_port(struct serio
*serio
)
644 struct serio
*s
= serio
;
647 * Children ports should be disconnected and destroyed
648 * first; we travel the tree in depth-first order.
650 while (!list_empty(&serio
->children
)) {
653 while (!list_empty(&s
->children
))
654 s
= list_first_entry(&s
->children
,
655 struct serio
, child_node
);
658 * Prune this leaf node unless it is the one we
662 struct serio
*parent
= s
->parent
;
664 device_release_driver(&s
->dev
);
665 serio_destroy_port(s
);
672 * OK, no children left, now disconnect this port.
674 device_release_driver(&serio
->dev
);
677 void serio_rescan(struct serio
*serio
)
679 serio_queue_event(serio
, NULL
, SERIO_RESCAN_PORT
);
681 EXPORT_SYMBOL(serio_rescan
);
683 void serio_reconnect(struct serio
*serio
)
685 serio_queue_event(serio
, NULL
, SERIO_RECONNECT_SUBTREE
);
687 EXPORT_SYMBOL(serio_reconnect
);
690 * Submits register request to kseriod for subsequent execution.
691 * Note that port registration is always asynchronous.
693 void __serio_register_port(struct serio
*serio
, struct module
*owner
)
695 serio_init_port(serio
);
696 serio_queue_event(serio
, owner
, SERIO_REGISTER_PORT
);
698 EXPORT_SYMBOL(__serio_register_port
);
701 * Synchronously unregisters serio port.
703 void serio_unregister_port(struct serio
*serio
)
705 mutex_lock(&serio_mutex
);
706 serio_disconnect_port(serio
);
707 serio_destroy_port(serio
);
708 mutex_unlock(&serio_mutex
);
710 EXPORT_SYMBOL(serio_unregister_port
);
713 * Safely unregisters children ports if they are present.
715 void serio_unregister_child_port(struct serio
*serio
)
717 struct serio
*s
, *next
;
719 mutex_lock(&serio_mutex
);
720 list_for_each_entry_safe(s
, next
, &serio
->children
, child_node
) {
721 serio_disconnect_port(s
);
722 serio_destroy_port(s
);
724 mutex_unlock(&serio_mutex
);
726 EXPORT_SYMBOL(serio_unregister_child_port
);
730 * Serio driver operations
733 static ssize_t
serio_driver_show_description(struct device_driver
*drv
, char *buf
)
735 struct serio_driver
*driver
= to_serio_driver(drv
);
736 return sprintf(buf
, "%s\n", driver
->description
? driver
->description
: "(none)");
739 static ssize_t
serio_driver_show_bind_mode(struct device_driver
*drv
, char *buf
)
741 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
742 return sprintf(buf
, "%s\n", serio_drv
->manual_bind
? "manual" : "auto");
745 static ssize_t
serio_driver_set_bind_mode(struct device_driver
*drv
, const char *buf
, size_t count
)
747 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
751 if (!strncmp(buf
, "manual", count
)) {
752 serio_drv
->manual_bind
= true;
753 } else if (!strncmp(buf
, "auto", count
)) {
754 serio_drv
->manual_bind
= false;
763 static struct driver_attribute serio_driver_attrs
[] = {
764 __ATTR(description
, S_IRUGO
, serio_driver_show_description
, NULL
),
765 __ATTR(bind_mode
, S_IWUSR
| S_IRUGO
,
766 serio_driver_show_bind_mode
, serio_driver_set_bind_mode
),
770 static int serio_driver_probe(struct device
*dev
)
772 struct serio
*serio
= to_serio_port(dev
);
773 struct serio_driver
*drv
= to_serio_driver(dev
->driver
);
775 return serio_connect_driver(serio
, drv
);
778 static int serio_driver_remove(struct device
*dev
)
780 struct serio
*serio
= to_serio_port(dev
);
782 serio_disconnect_driver(serio
);
786 static void serio_cleanup(struct serio
*serio
)
788 mutex_lock(&serio
->drv_mutex
);
789 if (serio
->drv
&& serio
->drv
->cleanup
)
790 serio
->drv
->cleanup(serio
);
791 mutex_unlock(&serio
->drv_mutex
);
794 static void serio_shutdown(struct device
*dev
)
796 struct serio
*serio
= to_serio_port(dev
);
798 serio_cleanup(serio
);
801 static void serio_attach_driver(struct serio_driver
*drv
)
805 error
= driver_attach(&drv
->driver
);
807 pr_warning("driver_attach() failed for %s with error %d\n",
808 drv
->driver
.name
, error
);
811 int __serio_register_driver(struct serio_driver
*drv
, struct module
*owner
, const char *mod_name
)
813 bool manual_bind
= drv
->manual_bind
;
816 drv
->driver
.bus
= &serio_bus
;
817 drv
->driver
.owner
= owner
;
818 drv
->driver
.mod_name
= mod_name
;
821 * Temporarily disable automatic binding because probing
822 * takes long time and we are better off doing it in kseriod
824 drv
->manual_bind
= true;
826 error
= driver_register(&drv
->driver
);
828 pr_err("driver_register() failed for %s, error: %d\n",
829 drv
->driver
.name
, error
);
834 * Restore original bind mode and let kseriod bind the
835 * driver to free ports
838 drv
->manual_bind
= false;
839 error
= serio_queue_event(drv
, NULL
, SERIO_ATTACH_DRIVER
);
841 driver_unregister(&drv
->driver
);
848 EXPORT_SYMBOL(__serio_register_driver
);
850 void serio_unregister_driver(struct serio_driver
*drv
)
854 mutex_lock(&serio_mutex
);
856 drv
->manual_bind
= true; /* so serio_find_driver ignores it */
857 serio_remove_pending_events(drv
);
860 list_for_each_entry(serio
, &serio_list
, node
) {
861 if (serio
->drv
== drv
) {
862 serio_disconnect_port(serio
);
863 serio_find_driver(serio
);
864 /* we could've deleted some ports, restart */
869 driver_unregister(&drv
->driver
);
870 mutex_unlock(&serio_mutex
);
872 EXPORT_SYMBOL(serio_unregister_driver
);
874 static void serio_set_drv(struct serio
*serio
, struct serio_driver
*drv
)
876 serio_pause_rx(serio
);
878 serio_continue_rx(serio
);
881 static int serio_bus_match(struct device
*dev
, struct device_driver
*drv
)
883 struct serio
*serio
= to_serio_port(dev
);
884 struct serio_driver
*serio_drv
= to_serio_driver(drv
);
886 if (serio
->manual_bind
|| serio_drv
->manual_bind
)
889 return serio_match_port(serio_drv
->id_table
, serio
);
892 #ifdef CONFIG_HOTPLUG
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
);
914 SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
915 serio
->id
.type
, serio
->id
.proto
, serio
->id
.id
, serio
->id
.extra
);
919 #undef SERIO_ADD_UEVENT_VAR
923 static int serio_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
928 #endif /* CONFIG_HOTPLUG */
931 static int serio_suspend(struct device
*dev
)
933 struct serio
*serio
= to_serio_port(dev
);
935 serio_cleanup(serio
);
940 static int serio_resume(struct device
*dev
)
942 struct serio
*serio
= to_serio_port(dev
);
945 * Driver reconnect can take a while, so better let kseriod
948 serio_queue_event(serio
, NULL
, SERIO_RECONNECT_PORT
);
953 static const struct dev_pm_ops serio_pm_ops
= {
954 .suspend
= serio_suspend
,
955 .resume
= serio_resume
,
956 .poweroff
= serio_suspend
,
957 .restore
= serio_resume
,
959 #endif /* CONFIG_PM */
961 /* called from serio_driver->connect/disconnect methods under serio_mutex */
962 int serio_open(struct serio
*serio
, struct serio_driver
*drv
)
964 serio_set_drv(serio
, drv
);
966 if (serio
->open
&& serio
->open(serio
)) {
967 serio_set_drv(serio
, NULL
);
972 EXPORT_SYMBOL(serio_open
);
974 /* called from serio_driver->connect/disconnect methods under serio_mutex */
975 void serio_close(struct serio
*serio
)
980 serio_set_drv(serio
, NULL
);
982 EXPORT_SYMBOL(serio_close
);
984 irqreturn_t
serio_interrupt(struct serio
*serio
,
985 unsigned char data
, unsigned int dfl
)
988 irqreturn_t ret
= IRQ_NONE
;
990 spin_lock_irqsave(&serio
->lock
, flags
);
992 if (likely(serio
->drv
)) {
993 ret
= serio
->drv
->interrupt(serio
, data
, dfl
);
994 } else if (!dfl
&& device_is_registered(&serio
->dev
)) {
999 spin_unlock_irqrestore(&serio
->lock
, flags
);
1003 EXPORT_SYMBOL(serio_interrupt
);
1005 static struct bus_type serio_bus
= {
1007 .dev_attrs
= serio_device_attrs
,
1008 .drv_attrs
= serio_driver_attrs
,
1009 .match
= serio_bus_match
,
1010 .uevent
= serio_uevent
,
1011 .probe
= serio_driver_probe
,
1012 .remove
= serio_driver_remove
,
1013 .shutdown
= serio_shutdown
,
1015 .pm
= &serio_pm_ops
,
1019 static int __init
serio_init(void)
1023 error
= bus_register(&serio_bus
);
1025 pr_err("Failed to register serio bus, error: %d\n", error
);
1032 static void __exit
serio_exit(void)
1034 bus_unregister(&serio_bus
);
1037 * There should not be any outstanding events but work may
1038 * still be scheduled so simply cancel it.
1040 cancel_work_sync(&serio_event_work
);
1043 subsys_initcall(serio_init
);
1044 module_exit(serio_exit
);