Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * The Serio abstraction module |
| 3 | * |
| 4 | * Copyright (c) 1999-2004 Vojtech Pavlik |
| 5 | * Copyright (c) 2004 Dmitry Torokhov |
| 6 | * Copyright (c) 2003 Daniele Bellucci |
| 7 | */ |
| 8 | |
| 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. |
| 14 | * |
| 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. |
| 19 | * |
| 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 |
| 23 | * |
| 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 |
| 27 | */ |
| 28 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 29 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/stddef.h> |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/serio.h> |
| 34 | #include <linux/errno.h> |
| 35 | #include <linux/wait.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/slab.h> |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 38 | #include <linux/kthread.h> |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 39 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 42 | MODULE_DESCRIPTION("Serio abstraction core"); |
| 43 | MODULE_LICENSE("GPL"); |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 46 | * serio_mutex protects entire serio subsystem and is taken every time |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * serio port or driver registrered or unregistered. |
| 48 | */ |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 49 | static DEFINE_MUTEX(serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | static LIST_HEAD(serio_list); |
| 52 | |
Russell King | 30226f8 | 2006-01-05 14:38:53 +0000 | [diff] [blame] | 53 | static struct bus_type serio_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | static void serio_add_port(struct serio *serio); |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 56 | static int serio_reconnect_port(struct serio *serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | static void serio_disconnect_port(struct serio *serio); |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 58 | static void serio_reconnect_chain(struct serio *serio); |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 59 | static void serio_attach_driver(struct serio_driver *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 61 | static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) |
| 62 | { |
| 63 | int retval; |
| 64 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 65 | mutex_lock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 66 | retval = drv->connect(serio, drv); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 67 | mutex_unlock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 68 | |
| 69 | return retval; |
| 70 | } |
| 71 | |
| 72 | static int serio_reconnect_driver(struct serio *serio) |
| 73 | { |
| 74 | int retval = -1; |
| 75 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 76 | mutex_lock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 77 | if (serio->drv && serio->drv->reconnect) |
| 78 | retval = serio->drv->reconnect(serio); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 79 | mutex_unlock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 80 | |
| 81 | return retval; |
| 82 | } |
| 83 | |
| 84 | static void serio_disconnect_driver(struct serio *serio) |
| 85 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 86 | mutex_lock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 87 | if (serio->drv) |
| 88 | serio->drv->disconnect(serio); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 89 | mutex_unlock(&serio->drv_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) |
| 93 | { |
| 94 | while (ids->type || ids->proto) { |
| 95 | if ((ids->type == SERIO_ANY || ids->type == serio->id.type) && |
| 96 | (ids->proto == SERIO_ANY || ids->proto == serio->id.proto) && |
| 97 | (ids->extra == SERIO_ANY || ids->extra == serio->id.extra) && |
| 98 | (ids->id == SERIO_ANY || ids->id == serio->id.id)) |
| 99 | return 1; |
| 100 | ids++; |
| 101 | } |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Basic serio -> driver core mappings |
| 107 | */ |
| 108 | |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 109 | static int serio_bind_driver(struct serio *serio, struct serio_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Dmitry Torokhov | 0a66045 | 2006-10-12 01:06:23 -0400 | [diff] [blame] | 111 | int error; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | if (serio_match_port(drv->id_table, serio)) { |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | serio->dev.driver = &drv->driver; |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 116 | if (serio_connect_driver(serio, drv)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | serio->dev.driver = NULL; |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 118 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 120 | |
Dmitry Torokhov | 0a66045 | 2006-10-12 01:06:23 -0400 | [diff] [blame] | 121 | error = device_bind_driver(&serio->dev); |
| 122 | if (error) { |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 123 | dev_warn(&serio->dev, |
| 124 | "device_bind_driver() failed for %s (%s) and %s, error: %d\n", |
| 125 | serio->phys, serio->name, |
| 126 | drv->description, error); |
Dmitry Torokhov | 0a66045 | 2006-10-12 01:06:23 -0400 | [diff] [blame] | 127 | serio_disconnect_driver(serio); |
| 128 | serio->dev.driver = NULL; |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 129 | return error; |
Dmitry Torokhov | 0a66045 | 2006-10-12 01:06:23 -0400 | [diff] [blame] | 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 132 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static void serio_find_driver(struct serio *serio) |
| 136 | { |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 137 | int error; |
| 138 | |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 139 | error = device_attach(&serio->dev); |
| 140 | if (error < 0) |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 141 | dev_warn(&serio->dev, |
| 142 | "device_attach() failed for %s (%s), error: %d\n", |
| 143 | serio->phys, serio->name, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
| 147 | /* |
| 148 | * Serio event processing. |
| 149 | */ |
| 150 | |
| 151 | enum serio_event_type { |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 152 | SERIO_RESCAN_PORT, |
| 153 | SERIO_RECONNECT_PORT, |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 154 | SERIO_RECONNECT_CHAIN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | SERIO_REGISTER_PORT, |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 156 | SERIO_ATTACH_DRIVER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | struct serio_event { |
| 160 | enum serio_event_type type; |
| 161 | void *object; |
| 162 | struct module *owner; |
| 163 | struct list_head node; |
| 164 | }; |
| 165 | |
| 166 | static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */ |
| 167 | static LIST_HEAD(serio_event_list); |
| 168 | static DECLARE_WAIT_QUEUE_HEAD(serio_wait); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 169 | static struct task_struct *serio_task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 171 | static int serio_queue_event(void *object, struct module *owner, |
| 172 | enum serio_event_type event_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
| 174 | unsigned long flags; |
| 175 | struct serio_event *event; |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 176 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | spin_lock_irqsave(&serio_event_lock, flags); |
| 179 | |
| 180 | /* |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 181 | * Scan event list for the other events for the same serio port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | * starting with the most recent one. If event is the same we |
| 183 | * do not need add new one. If event is of different type we |
| 184 | * need to add this event and should not look further because |
| 185 | * we need to preseve sequence of distinct events. |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 186 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | list_for_each_entry_reverse(event, &serio_event_list, node) { |
| 188 | if (event->object == object) { |
| 189 | if (event->type == event_type) |
| 190 | goto out; |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 195 | event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC); |
| 196 | if (!event) { |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 197 | pr_err("Not enough memory to queue event %d\n", event_type); |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 198 | retval = -ENOMEM; |
| 199 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 201 | |
| 202 | if (!try_module_get(owner)) { |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 203 | pr_warning("Can't get module reference, dropping event %d\n", |
| 204 | event_type); |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 205 | kfree(event); |
| 206 | retval = -EINVAL; |
| 207 | goto out; |
| 208 | } |
| 209 | |
| 210 | event->type = event_type; |
| 211 | event->object = object; |
| 212 | event->owner = owner; |
| 213 | |
| 214 | list_add_tail(&event->node, &serio_event_list); |
| 215 | wake_up(&serio_wait); |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | out: |
| 218 | spin_unlock_irqrestore(&serio_event_lock, flags); |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 219 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void serio_free_event(struct serio_event *event) |
| 223 | { |
| 224 | module_put(event->owner); |
| 225 | kfree(event); |
| 226 | } |
| 227 | |
| 228 | static void serio_remove_duplicate_events(struct serio_event *event) |
| 229 | { |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 230 | struct serio_event *e, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | unsigned long flags; |
| 232 | |
| 233 | spin_lock_irqsave(&serio_event_lock, flags); |
| 234 | |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 235 | list_for_each_entry_safe(e, next, &serio_event_list, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | if (event->object == e->object) { |
| 237 | /* |
| 238 | * If this event is of different type we should not |
| 239 | * look further - we only suppress duplicate events |
| 240 | * that were sent back-to-back. |
| 241 | */ |
| 242 | if (event->type != e->type) |
| 243 | break; |
| 244 | |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 245 | list_del_init(&e->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | serio_free_event(e); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | spin_unlock_irqrestore(&serio_event_lock, flags); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | static struct serio_event *serio_get_event(void) |
| 255 | { |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 256 | struct serio_event *event = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | unsigned long flags; |
| 258 | |
| 259 | spin_lock_irqsave(&serio_event_lock, flags); |
| 260 | |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 261 | if (!list_empty(&serio_event_list)) { |
| 262 | event = list_first_entry(&serio_event_list, |
| 263 | struct serio_event, node); |
| 264 | list_del_init(&event->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | spin_unlock_irqrestore(&serio_event_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return event; |
| 269 | } |
| 270 | |
Dmitry Torokhov | 9e50afd | 2005-11-20 00:56:43 -0500 | [diff] [blame] | 271 | static void serio_handle_event(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
| 273 | struct serio_event *event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 275 | mutex_lock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Dmitry Torokhov | ea486e6 | 2009-12-24 21:40:43 -0800 | [diff] [blame] | 277 | while ((event = serio_get_event())) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | switch (event->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 281 | case SERIO_REGISTER_PORT: |
| 282 | serio_add_port(event->object); |
| 283 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 285 | case SERIO_RECONNECT_PORT: |
| 286 | serio_reconnect_port(event->object); |
| 287 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 289 | case SERIO_RESCAN_PORT: |
| 290 | serio_disconnect_port(event->object); |
| 291 | serio_find_driver(event->object); |
| 292 | break; |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 293 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 294 | case SERIO_RECONNECT_CHAIN: |
| 295 | serio_reconnect_chain(event->object); |
| 296 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 298 | case SERIO_ATTACH_DRIVER: |
| 299 | serio_attach_driver(event->object); |
| 300 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | serio_remove_duplicate_events(event); |
| 304 | serio_free_event(event); |
| 305 | } |
| 306 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 307 | mutex_unlock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* |
Dmitry Torokhov | e8ef434 | 2008-06-02 00:41:57 -0400 | [diff] [blame] | 311 | * Remove all events that have been submitted for a given |
| 312 | * object, be it serio port or driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | */ |
Dmitry Torokhov | e8ef434 | 2008-06-02 00:41:57 -0400 | [diff] [blame] | 314 | static void serio_remove_pending_events(void *object) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 316 | struct serio_event *event, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | unsigned long flags; |
| 318 | |
| 319 | spin_lock_irqsave(&serio_event_lock, flags); |
| 320 | |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 321 | list_for_each_entry_safe(event, next, &serio_event_list, node) { |
Dmitry Torokhov | e8ef434 | 2008-06-02 00:41:57 -0400 | [diff] [blame] | 322 | if (event->object == object) { |
Dmitry Torokhov | 4516c81 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 323 | list_del_init(&event->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | serio_free_event(event); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | spin_unlock_irqrestore(&serio_event_lock, flags); |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * Destroy child serio port (if any) that has not been fully registered yet. |
| 333 | * |
| 334 | * Note that we rely on the fact that port can have only one child and therefore |
| 335 | * only one child registration request can be pending. Additionally, children |
| 336 | * are registered by driver's connect() handler so there can't be a grandchild |
| 337 | * pending registration together with a child. |
| 338 | */ |
| 339 | static struct serio *serio_get_pending_child(struct serio *parent) |
| 340 | { |
| 341 | struct serio_event *event; |
| 342 | struct serio *serio, *child = NULL; |
| 343 | unsigned long flags; |
| 344 | |
| 345 | spin_lock_irqsave(&serio_event_lock, flags); |
| 346 | |
| 347 | list_for_each_entry(event, &serio_event_list, node) { |
| 348 | if (event->type == SERIO_REGISTER_PORT) { |
| 349 | serio = event->object; |
| 350 | if (serio->parent == parent) { |
| 351 | child = serio; |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | spin_unlock_irqrestore(&serio_event_lock, flags); |
| 358 | return child; |
| 359 | } |
| 360 | |
| 361 | static int serio_thread(void *nothing) |
| 362 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | do { |
Dmitry Torokhov | 9e50afd | 2005-11-20 00:56:43 -0500 | [diff] [blame] | 364 | serio_handle_event(); |
Dmitry Torokhov | ea486e6 | 2009-12-24 21:40:43 -0800 | [diff] [blame] | 365 | wait_event_interruptible(serio_wait, |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 366 | kthread_should_stop() || !list_empty(&serio_event_list)); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 367 | } while (!kthread_should_stop()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 369 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | |
| 373 | /* |
| 374 | * Serio port operations |
| 375 | */ |
| 376 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 377 | static ssize_t serio_show_description(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
| 379 | struct serio *serio = to_serio_port(dev); |
| 380 | return sprintf(buf, "%s\n", serio->name); |
| 381 | } |
| 382 | |
Dmitry Torokhov | ae87dff | 2005-06-30 00:48:34 -0500 | [diff] [blame] | 383 | static ssize_t serio_show_modalias(struct device *dev, struct device_attribute *attr, char *buf) |
| 384 | { |
| 385 | struct serio *serio = to_serio_port(dev); |
| 386 | |
| 387 | return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n", |
| 388 | serio->id.type, serio->id.proto, serio->id.id, serio->id.extra); |
| 389 | } |
| 390 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 391 | static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
| 393 | struct serio *serio = to_serio_port(dev); |
| 394 | return sprintf(buf, "%02x\n", serio->id.type); |
| 395 | } |
| 396 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 397 | static ssize_t serio_show_id_proto(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
| 399 | struct serio *serio = to_serio_port(dev); |
| 400 | return sprintf(buf, "%02x\n", serio->id.proto); |
| 401 | } |
| 402 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 403 | static ssize_t serio_show_id_id(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
| 405 | struct serio *serio = to_serio_port(dev); |
| 406 | return sprintf(buf, "%02x\n", serio->id.id); |
| 407 | } |
| 408 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 409 | static ssize_t serio_show_id_extra(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
| 411 | struct serio *serio = to_serio_port(dev); |
| 412 | return sprintf(buf, "%02x\n", serio->id.extra); |
| 413 | } |
| 414 | |
Dmitry Torokhov | baae956 | 2005-05-16 21:53:09 -0700 | [diff] [blame] | 415 | static DEVICE_ATTR(type, S_IRUGO, serio_show_id_type, NULL); |
| 416 | static DEVICE_ATTR(proto, S_IRUGO, serio_show_id_proto, NULL); |
| 417 | static DEVICE_ATTR(id, S_IRUGO, serio_show_id_id, NULL); |
| 418 | static DEVICE_ATTR(extra, S_IRUGO, serio_show_id_extra, NULL); |
| 419 | |
| 420 | static struct attribute *serio_device_id_attrs[] = { |
| 421 | &dev_attr_type.attr, |
| 422 | &dev_attr_proto.attr, |
| 423 | &dev_attr_id.attr, |
| 424 | &dev_attr_extra.attr, |
| 425 | NULL |
| 426 | }; |
| 427 | |
| 428 | static struct attribute_group serio_id_attr_group = { |
| 429 | .name = "id", |
| 430 | .attrs = serio_device_id_attrs, |
| 431 | }; |
| 432 | |
Dmitry Torokhov | 386d877 | 2010-01-05 17:56:03 -0800 | [diff] [blame] | 433 | static const struct attribute_group *serio_device_attr_groups[] = { |
| 434 | &serio_id_attr_group, |
| 435 | NULL |
| 436 | }; |
| 437 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 438 | static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
| 440 | struct serio *serio = to_serio_port(dev); |
| 441 | struct device_driver *drv; |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 442 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 444 | error = mutex_lock_interruptible(&serio_mutex); |
| 445 | if (error) |
| 446 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (!strncmp(buf, "none", count)) { |
| 449 | serio_disconnect_port(serio); |
| 450 | } else if (!strncmp(buf, "reconnect", count)) { |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 451 | serio_reconnect_chain(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } else if (!strncmp(buf, "rescan", count)) { |
| 453 | serio_disconnect_port(serio); |
| 454 | serio_find_driver(serio); |
| 455 | } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { |
| 456 | serio_disconnect_port(serio); |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 457 | error = serio_bind_driver(serio, to_serio_driver(drv)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | put_driver(drv); |
| 459 | } else { |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 460 | error = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 463 | mutex_unlock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 465 | return error ? error : count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 468 | static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
| 470 | struct serio *serio = to_serio_port(dev); |
| 471 | return sprintf(buf, "%s\n", serio->manual_bind ? "manual" : "auto"); |
| 472 | } |
| 473 | |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 474 | static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
| 476 | struct serio *serio = to_serio_port(dev); |
| 477 | int retval; |
| 478 | |
| 479 | retval = count; |
| 480 | if (!strncmp(buf, "manual", count)) { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 481 | serio->manual_bind = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } else if (!strncmp(buf, "auto", count)) { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 483 | serio->manual_bind = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } else { |
| 485 | retval = -EINVAL; |
| 486 | } |
| 487 | |
| 488 | return retval; |
| 489 | } |
| 490 | |
| 491 | static struct device_attribute serio_device_attrs[] = { |
| 492 | __ATTR(description, S_IRUGO, serio_show_description, NULL), |
Dmitry Torokhov | ae87dff | 2005-06-30 00:48:34 -0500 | [diff] [blame] | 493 | __ATTR(modalias, S_IRUGO, serio_show_modalias, NULL), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver), |
| 495 | __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode), |
| 496 | __ATTR_NULL |
| 497 | }; |
| 498 | |
| 499 | |
| 500 | static void serio_release_port(struct device *dev) |
| 501 | { |
| 502 | struct serio *serio = to_serio_port(dev); |
| 503 | |
| 504 | kfree(serio); |
| 505 | module_put(THIS_MODULE); |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | * Prepare serio port for registration. |
| 510 | */ |
| 511 | static void serio_init_port(struct serio *serio) |
| 512 | { |
| 513 | static atomic_t serio_no = ATOMIC_INIT(0); |
| 514 | |
| 515 | __module_get(THIS_MODULE); |
| 516 | |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 517 | INIT_LIST_HEAD(&serio->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | spin_lock_init(&serio->lock); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 519 | mutex_init(&serio->drv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | device_initialize(&serio->dev); |
Kay Sievers | a6c2490 | 2008-10-30 00:07:50 -0400 | [diff] [blame] | 521 | dev_set_name(&serio->dev, "serio%ld", |
| 522 | (long)atomic_inc_return(&serio_no) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | serio->dev.bus = &serio_bus; |
| 524 | serio->dev.release = serio_release_port; |
Dmitry Torokhov | 386d877 | 2010-01-05 17:56:03 -0800 | [diff] [blame] | 525 | serio->dev.groups = serio_device_attr_groups; |
Jiri Kosina | 88aa010 | 2006-10-11 01:45:31 -0400 | [diff] [blame] | 526 | if (serio->parent) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | serio->dev.parent = &serio->parent->dev; |
Jiri Kosina | 88aa010 | 2006-10-11 01:45:31 -0400 | [diff] [blame] | 528 | serio->depth = serio->parent->depth + 1; |
| 529 | } else |
| 530 | serio->depth = 0; |
| 531 | lockdep_set_subclass(&serio->lock, serio->depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Complete serio port registration. |
| 536 | * Driver core will attempt to find appropriate driver for the port. |
| 537 | */ |
| 538 | static void serio_add_port(struct serio *serio) |
| 539 | { |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 540 | int error; |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (serio->parent) { |
| 543 | serio_pause_rx(serio->parent); |
| 544 | serio->parent->child = serio; |
| 545 | serio_continue_rx(serio->parent); |
| 546 | } |
| 547 | |
| 548 | list_add_tail(&serio->node, &serio_list); |
Dmitry Torokhov | 386d877 | 2010-01-05 17:56:03 -0800 | [diff] [blame] | 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | if (serio->start) |
| 551 | serio->start(serio); |
Dmitry Torokhov | 386d877 | 2010-01-05 17:56:03 -0800 | [diff] [blame] | 552 | |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 553 | error = device_add(&serio->dev); |
| 554 | if (error) |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 555 | dev_err(&serio->dev, |
| 556 | "device_add() failed for %s (%s), error: %d\n", |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 557 | serio->phys, serio->name, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* |
| 561 | * serio_destroy_port() completes deregistration process and removes |
| 562 | * port from the system |
| 563 | */ |
| 564 | static void serio_destroy_port(struct serio *serio) |
| 565 | { |
| 566 | struct serio *child; |
| 567 | |
| 568 | child = serio_get_pending_child(serio); |
| 569 | if (child) { |
| 570 | serio_remove_pending_events(child); |
| 571 | put_device(&child->dev); |
| 572 | } |
| 573 | |
| 574 | if (serio->stop) |
| 575 | serio->stop(serio); |
| 576 | |
| 577 | if (serio->parent) { |
| 578 | serio_pause_rx(serio->parent); |
| 579 | serio->parent->child = NULL; |
| 580 | serio_continue_rx(serio->parent); |
| 581 | serio->parent = NULL; |
| 582 | } |
| 583 | |
Dmitry Torokhov | ddf1ffb | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 584 | if (device_is_registered(&serio->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | device_del(&serio->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 587 | list_del_init(&serio->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | serio_remove_pending_events(serio); |
| 589 | put_device(&serio->dev); |
| 590 | } |
| 591 | |
| 592 | /* |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 593 | * Reconnect serio port (re-initialize attached device). |
| 594 | * If reconnect fails (old device is no longer attached or |
| 595 | * there was no device to begin with) we do full rescan in |
| 596 | * hope of finding a driver for the port. |
| 597 | */ |
| 598 | static int serio_reconnect_port(struct serio *serio) |
| 599 | { |
| 600 | int error = serio_reconnect_driver(serio); |
| 601 | |
| 602 | if (error) { |
| 603 | serio_disconnect_port(serio); |
| 604 | serio_find_driver(serio); |
| 605 | } |
| 606 | |
| 607 | return error; |
| 608 | } |
| 609 | |
| 610 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | * Reconnect serio port and all its children (re-initialize attached devices) |
| 612 | */ |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 613 | static void serio_reconnect_chain(struct serio *serio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
| 615 | do { |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 616 | if (serio_reconnect_port(serio)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* Ok, old children are now gone, we are done */ |
| 618 | break; |
| 619 | } |
| 620 | serio = serio->child; |
| 621 | } while (serio); |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * serio_disconnect_port() unbinds a port from its driver. As a side effect |
| 626 | * all child ports are unbound and destroyed. |
| 627 | */ |
| 628 | static void serio_disconnect_port(struct serio *serio) |
| 629 | { |
| 630 | struct serio *s, *parent; |
| 631 | |
| 632 | if (serio->child) { |
| 633 | /* |
| 634 | * Children ports should be disconnected and destroyed |
| 635 | * first, staring with the leaf one, since we don't want |
| 636 | * to do recursion |
| 637 | */ |
| 638 | for (s = serio; s->child; s = s->child) |
| 639 | /* empty */; |
| 640 | |
| 641 | do { |
| 642 | parent = s->parent; |
| 643 | |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 644 | device_release_driver(&s->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | serio_destroy_port(s); |
| 646 | } while ((s = parent) != serio); |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * Ok, no children left, now disconnect this port |
| 651 | */ |
Dmitry Torokhov | 70f256f | 2007-04-10 00:40:27 -0400 | [diff] [blame] | 652 | device_release_driver(&serio->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | void serio_rescan(struct serio *serio) |
| 656 | { |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 657 | serio_queue_event(serio, NULL, SERIO_RESCAN_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 659 | EXPORT_SYMBOL(serio_rescan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | void serio_reconnect(struct serio *serio) |
| 662 | { |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 663 | serio_queue_event(serio, NULL, SERIO_RECONNECT_CHAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 665 | EXPORT_SYMBOL(serio_reconnect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | /* |
| 668 | * Submits register request to kseriod for subsequent execution. |
| 669 | * Note that port registration is always asynchronous. |
| 670 | */ |
| 671 | void __serio_register_port(struct serio *serio, struct module *owner) |
| 672 | { |
| 673 | serio_init_port(serio); |
| 674 | serio_queue_event(serio, owner, SERIO_REGISTER_PORT); |
| 675 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 676 | EXPORT_SYMBOL(__serio_register_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | /* |
| 679 | * Synchronously unregisters serio port. |
| 680 | */ |
| 681 | void serio_unregister_port(struct serio *serio) |
| 682 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 683 | mutex_lock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | serio_disconnect_port(serio); |
| 685 | serio_destroy_port(serio); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 686 | mutex_unlock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 688 | EXPORT_SYMBOL(serio_unregister_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | /* |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 691 | * Safely unregisters child port if one is present. |
| 692 | */ |
| 693 | void serio_unregister_child_port(struct serio *serio) |
| 694 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 695 | mutex_lock(&serio_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 696 | if (serio->child) { |
| 697 | serio_disconnect_port(serio->child); |
| 698 | serio_destroy_port(serio->child); |
| 699 | } |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 700 | mutex_unlock(&serio_mutex); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 701 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 702 | EXPORT_SYMBOL(serio_unregister_child_port); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | /* |
| 706 | * Serio driver operations |
| 707 | */ |
| 708 | |
| 709 | static ssize_t serio_driver_show_description(struct device_driver *drv, char *buf) |
| 710 | { |
| 711 | struct serio_driver *driver = to_serio_driver(drv); |
| 712 | return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)"); |
| 713 | } |
| 714 | |
| 715 | static ssize_t serio_driver_show_bind_mode(struct device_driver *drv, char *buf) |
| 716 | { |
| 717 | struct serio_driver *serio_drv = to_serio_driver(drv); |
| 718 | return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto"); |
| 719 | } |
| 720 | |
| 721 | static ssize_t serio_driver_set_bind_mode(struct device_driver *drv, const char *buf, size_t count) |
| 722 | { |
| 723 | struct serio_driver *serio_drv = to_serio_driver(drv); |
| 724 | int retval; |
| 725 | |
| 726 | retval = count; |
| 727 | if (!strncmp(buf, "manual", count)) { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 728 | serio_drv->manual_bind = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } else if (!strncmp(buf, "auto", count)) { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 730 | serio_drv->manual_bind = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } else { |
| 732 | retval = -EINVAL; |
| 733 | } |
| 734 | |
| 735 | return retval; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | static struct driver_attribute serio_driver_attrs[] = { |
| 740 | __ATTR(description, S_IRUGO, serio_driver_show_description, NULL), |
| 741 | __ATTR(bind_mode, S_IWUSR | S_IRUGO, |
| 742 | serio_driver_show_bind_mode, serio_driver_set_bind_mode), |
| 743 | __ATTR_NULL |
| 744 | }; |
| 745 | |
| 746 | static int serio_driver_probe(struct device *dev) |
| 747 | { |
| 748 | struct serio *serio = to_serio_port(dev); |
| 749 | struct serio_driver *drv = to_serio_driver(dev->driver); |
| 750 | |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 751 | return serio_connect_driver(serio, drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static int serio_driver_remove(struct device *dev) |
| 755 | { |
| 756 | struct serio *serio = to_serio_port(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 758 | serio_disconnect_driver(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | return 0; |
| 760 | } |
| 761 | |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 762 | static void serio_cleanup(struct serio *serio) |
| 763 | { |
Dmitry Torokhov | 33143ea | 2007-06-29 01:06:35 -0400 | [diff] [blame] | 764 | mutex_lock(&serio->drv_mutex); |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 765 | if (serio->drv && serio->drv->cleanup) |
| 766 | serio->drv->cleanup(serio); |
Dmitry Torokhov | 33143ea | 2007-06-29 01:06:35 -0400 | [diff] [blame] | 767 | mutex_unlock(&serio->drv_mutex); |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | static void serio_shutdown(struct device *dev) |
| 771 | { |
| 772 | struct serio *serio = to_serio_port(dev); |
| 773 | |
| 774 | serio_cleanup(serio); |
| 775 | } |
| 776 | |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 777 | static void serio_attach_driver(struct serio_driver *drv) |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 778 | { |
| 779 | int error; |
| 780 | |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 781 | error = driver_attach(&drv->driver); |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 782 | if (error) |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 783 | pr_warning("driver_attach() failed for %s with error %d\n", |
| 784 | drv->driver.name, error); |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 785 | } |
| 786 | |
Greg Kroah-Hartman | 4b31562 | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 787 | int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 789 | bool manual_bind = drv->manual_bind; |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 790 | int error; |
| 791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | drv->driver.bus = &serio_bus; |
Greg Kroah-Hartman | 4b31562 | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 793 | drv->driver.owner = owner; |
| 794 | drv->driver.mod_name = mod_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 796 | /* |
| 797 | * Temporarily disable automatic binding because probing |
| 798 | * takes long time and we are better off doing it in kseriod |
| 799 | */ |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 800 | drv->manual_bind = true; |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 801 | |
| 802 | error = driver_register(&drv->driver); |
| 803 | if (error) { |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 804 | pr_err("driver_register() failed for %s, error: %d\n", |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 805 | drv->driver.name, error); |
| 806 | return error; |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Restore original bind mode and let kseriod bind the |
| 811 | * driver to free ports |
| 812 | */ |
| 813 | if (!manual_bind) { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 814 | drv->manual_bind = false; |
Dmitry Torokhov | ed7b1f6 | 2006-11-23 23:34:49 -0500 | [diff] [blame] | 815 | error = serio_queue_event(drv, NULL, SERIO_ATTACH_DRIVER); |
| 816 | if (error) { |
| 817 | driver_unregister(&drv->driver); |
| 818 | return error; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 824 | EXPORT_SYMBOL(__serio_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
| 826 | void serio_unregister_driver(struct serio_driver *drv) |
| 827 | { |
| 828 | struct serio *serio; |
| 829 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 830 | mutex_lock(&serio_mutex); |
Dmitry Torokhov | e8ef434 | 2008-06-02 00:41:57 -0400 | [diff] [blame] | 831 | |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 832 | drv->manual_bind = true; /* so serio_find_driver ignores it */ |
Dmitry Torokhov | e8ef434 | 2008-06-02 00:41:57 -0400 | [diff] [blame] | 833 | serio_remove_pending_events(drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | start_over: |
| 836 | list_for_each_entry(serio, &serio_list, node) { |
| 837 | if (serio->drv == drv) { |
| 838 | serio_disconnect_port(serio); |
| 839 | serio_find_driver(serio); |
| 840 | /* we could've deleted some ports, restart */ |
| 841 | goto start_over; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | driver_unregister(&drv->driver); |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 846 | mutex_unlock(&serio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 848 | EXPORT_SYMBOL(serio_unregister_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | static void serio_set_drv(struct serio *serio, struct serio_driver *drv) |
| 851 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | serio_pause_rx(serio); |
| 853 | serio->drv = drv; |
| 854 | serio_continue_rx(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static int serio_bus_match(struct device *dev, struct device_driver *drv) |
| 858 | { |
| 859 | struct serio *serio = to_serio_port(dev); |
| 860 | struct serio_driver *serio_drv = to_serio_driver(drv); |
| 861 | |
| 862 | if (serio->manual_bind || serio_drv->manual_bind) |
| 863 | return 0; |
| 864 | |
| 865 | return serio_match_port(serio_drv->id_table, serio); |
| 866 | } |
| 867 | |
| 868 | #ifdef CONFIG_HOTPLUG |
| 869 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 870 | #define SERIO_ADD_UEVENT_VAR(fmt, val...) \ |
Dmitry Torokhov | ae87dff | 2005-06-30 00:48:34 -0500 | [diff] [blame] | 871 | do { \ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 872 | int err = add_uevent_var(env, fmt, val); \ |
Dmitry Torokhov | ae87dff | 2005-06-30 00:48:34 -0500 | [diff] [blame] | 873 | if (err) \ |
| 874 | return err; \ |
| 875 | } while (0) |
| 876 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 877 | static int serio_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
| 879 | struct serio *serio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | if (!dev) |
| 882 | return -ENODEV; |
| 883 | |
| 884 | serio = to_serio_port(dev); |
| 885 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 886 | SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio->id.type); |
| 887 | SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio->id.proto); |
| 888 | SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio->id.id); |
| 889 | SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio->id.extra); |
| 890 | SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X", |
Dmitry Torokhov | ae87dff | 2005-06-30 00:48:34 -0500 | [diff] [blame] | 891 | serio->id.type, serio->id.proto, serio->id.id, serio->id.extra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | return 0; |
| 894 | } |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 895 | #undef SERIO_ADD_UEVENT_VAR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | #else |
| 898 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 899 | static int serio_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
| 901 | return -ENODEV; |
| 902 | } |
| 903 | |
| 904 | #endif /* CONFIG_HOTPLUG */ |
| 905 | |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 906 | #ifdef CONFIG_PM |
Dmitry Torokhov | 633aae2 | 2009-07-22 21:51:36 -0700 | [diff] [blame] | 907 | static int serio_suspend(struct device *dev) |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 908 | { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 909 | struct serio *serio = to_serio_port(dev); |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 910 | |
Dmitry Torokhov | 633aae2 | 2009-07-22 21:51:36 -0700 | [diff] [blame] | 911 | serio_cleanup(serio); |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 912 | |
| 913 | return 0; |
| 914 | } |
| 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | static int serio_resume(struct device *dev) |
| 917 | { |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 918 | struct serio *serio = to_serio_port(dev); |
| 919 | |
Shaohua Li | 6aabcdf | 2008-07-03 10:45:38 -0400 | [diff] [blame] | 920 | /* |
| 921 | * Driver reconnect can take a while, so better let kseriod |
| 922 | * deal with it. |
| 923 | */ |
Dmitry Torokhov | 633aae2 | 2009-07-22 21:51:36 -0700 | [diff] [blame] | 924 | serio_queue_event(serio, NULL, SERIO_RECONNECT_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | return 0; |
| 927 | } |
Dmitry Torokhov | 633aae2 | 2009-07-22 21:51:36 -0700 | [diff] [blame] | 928 | |
| 929 | static const struct dev_pm_ops serio_pm_ops = { |
| 930 | .suspend = serio_suspend, |
| 931 | .resume = serio_resume, |
| 932 | .poweroff = serio_suspend, |
| 933 | .restore = serio_resume, |
| 934 | }; |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 935 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 937 | /* called from serio_driver->connect/disconnect methods under serio_mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | int serio_open(struct serio *serio, struct serio_driver *drv) |
| 939 | { |
| 940 | serio_set_drv(serio, drv); |
| 941 | |
| 942 | if (serio->open && serio->open(serio)) { |
| 943 | serio_set_drv(serio, NULL); |
| 944 | return -1; |
| 945 | } |
| 946 | return 0; |
| 947 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 948 | EXPORT_SYMBOL(serio_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 950 | /* called from serio_driver->connect/disconnect methods under serio_mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | void serio_close(struct serio *serio) |
| 952 | { |
| 953 | if (serio->close) |
| 954 | serio->close(serio); |
| 955 | |
| 956 | serio_set_drv(serio, NULL); |
| 957 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 958 | EXPORT_SYMBOL(serio_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
| 960 | irqreturn_t serio_interrupt(struct serio *serio, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 961 | unsigned char data, unsigned int dfl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
| 963 | unsigned long flags; |
| 964 | irqreturn_t ret = IRQ_NONE; |
| 965 | |
| 966 | spin_lock_irqsave(&serio->lock, flags); |
| 967 | |
| 968 | if (likely(serio->drv)) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 969 | ret = serio->drv->interrupt(serio, data, dfl); |
Dmitry Torokhov | ddf1ffb | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 970 | } else if (!dfl && device_is_registered(&serio->dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | serio_rescan(serio); |
| 972 | ret = IRQ_HANDLED; |
| 973 | } |
| 974 | |
| 975 | spin_unlock_irqrestore(&serio->lock, flags); |
| 976 | |
| 977 | return ret; |
| 978 | } |
Dmitry Torokhov | 89b09b9 | 2009-04-17 20:12:34 -0700 | [diff] [blame] | 979 | EXPORT_SYMBOL(serio_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Marton Nemeth | 1ea2a69 | 2006-11-02 23:27:21 -0500 | [diff] [blame] | 981 | static struct bus_type serio_bus = { |
| 982 | .name = "serio", |
| 983 | .dev_attrs = serio_device_attrs, |
| 984 | .drv_attrs = serio_driver_attrs, |
| 985 | .match = serio_bus_match, |
| 986 | .uevent = serio_uevent, |
| 987 | .probe = serio_driver_probe, |
| 988 | .remove = serio_driver_remove, |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 989 | .shutdown = serio_shutdown, |
| 990 | #ifdef CONFIG_PM |
Dmitry Torokhov | 633aae2 | 2009-07-22 21:51:36 -0700 | [diff] [blame] | 991 | .pm = &serio_pm_ops, |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 992 | #endif |
Marton Nemeth | 1ea2a69 | 2006-11-02 23:27:21 -0500 | [diff] [blame] | 993 | }; |
| 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | static int __init serio_init(void) |
| 996 | { |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 997 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 999 | error = bus_register(&serio_bus); |
| 1000 | if (error) { |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 1001 | pr_err("Failed to register serio bus, error: %d\n", error); |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 1002 | return error; |
| 1003 | } |
| 1004 | |
| 1005 | serio_task = kthread_run(serio_thread, NULL, "kseriod"); |
| 1006 | if (IS_ERR(serio_task)) { |
| 1007 | bus_unregister(&serio_bus); |
| 1008 | error = PTR_ERR(serio_task); |
Dmitry Torokhov | cac9169 | 2010-01-05 17:56:04 -0800 | [diff] [blame] | 1009 | pr_err("Failed to start kseriod, error: %d\n", error); |
Randy Dunlap | 73b59a3 | 2006-07-19 01:14:55 -0400 | [diff] [blame] | 1010 | return error; |
| 1011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static void __exit serio_exit(void) |
| 1017 | { |
| 1018 | bus_unregister(&serio_bus); |
Linus Torvalds | 3c803e8 | 2005-06-27 17:49:45 -0700 | [diff] [blame] | 1019 | kthread_stop(serio_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Dmitry Torokhov | 51c38f9 | 2006-02-19 00:22:51 -0500 | [diff] [blame] | 1022 | subsys_initcall(serio_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | module_exit(serio_exit); |