Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Raw serio device providing access to a raw byte stream from underlying |
| 3 | * serio port. Closely emulates behavior of pre-2.6 /dev/psaux device |
| 4 | * |
| 5 | * Copyright (c) 2004 Dmitry Torokhov |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | */ |
| 11 | |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 12 | #include <linux/kref.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 13 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/slab.h> |
| 15 | #include <linux/poll.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/serio.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/major.h> |
| 20 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/miscdevice.h> |
| 22 | #include <linux/wait.h> |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #define DRIVER_DESC "Raw serio driver" |
| 26 | |
| 27 | MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); |
| 28 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
| 31 | #define SERIO_RAW_QUEUE_LEN 64 |
| 32 | struct serio_raw { |
| 33 | unsigned char queue[SERIO_RAW_QUEUE_LEN]; |
| 34 | unsigned int tail, head; |
| 35 | |
| 36 | char name[16]; |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 37 | struct kref kref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | struct serio *serio; |
| 39 | struct miscdevice dev; |
| 40 | wait_queue_head_t wait; |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 41 | struct list_head client_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | struct list_head node; |
| 43 | }; |
| 44 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 45 | struct serio_raw_client { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct fasync_struct *fasync; |
| 47 | struct serio_raw *serio_raw; |
| 48 | struct list_head node; |
| 49 | }; |
| 50 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 51 | static DEFINE_MUTEX(serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static LIST_HEAD(serio_raw_list); |
| 53 | static unsigned int serio_raw_no; |
| 54 | |
| 55 | /********************************************************************* |
| 56 | * Interface with userspace (file operations) * |
| 57 | *********************************************************************/ |
| 58 | |
| 59 | static int serio_raw_fasync(int fd, struct file *file, int on) |
| 60 | { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 61 | struct serio_raw_client *client = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 63 | return fasync_helper(fd, file, on, &client->fasync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static struct serio_raw *serio_raw_locate(int minor) |
| 67 | { |
| 68 | struct serio_raw *serio_raw; |
| 69 | |
| 70 | list_for_each_entry(serio_raw, &serio_raw_list, node) { |
| 71 | if (serio_raw->dev.minor == minor) |
| 72 | return serio_raw; |
| 73 | } |
| 74 | |
| 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | static int serio_raw_open(struct inode *inode, struct file *file) |
| 79 | { |
| 80 | struct serio_raw *serio_raw; |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 81 | struct serio_raw_client *client; |
| 82 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 84 | retval = mutex_lock_interruptible(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (retval) |
Thadeu Lima de Souza Cascardo | 77554b4 | 2010-03-09 20:38:47 -0800 | [diff] [blame] | 86 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Thadeu Lima de Souza Cascardo | 77554b4 | 2010-03-09 20:38:47 -0800 | [diff] [blame] | 88 | serio_raw = serio_raw_locate(iminor(inode)); |
| 89 | if (!serio_raw) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | retval = -ENODEV; |
| 91 | goto out; |
| 92 | } |
| 93 | |
| 94 | if (!serio_raw->serio) { |
| 95 | retval = -ENODEV; |
| 96 | goto out; |
| 97 | } |
| 98 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 99 | client = kzalloc(sizeof(struct serio_raw_client), GFP_KERNEL); |
| 100 | if (!client) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | retval = -ENOMEM; |
| 102 | goto out; |
| 103 | } |
| 104 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 105 | client->serio_raw = serio_raw; |
| 106 | file->private_data = client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 108 | kref_get(&serio_raw->kref); |
Dmitry Torokhov | 843e784 | 2011-10-10 18:30:26 -0700 | [diff] [blame] | 109 | |
| 110 | serio_pause_rx(serio_raw->serio); |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 111 | list_add_tail(&client->node, &serio_raw->client_list); |
Dmitry Torokhov | 843e784 | 2011-10-10 18:30:26 -0700 | [diff] [blame] | 112 | serio_continue_rx(serio_raw->serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | out: |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 115 | mutex_unlock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return retval; |
| 117 | } |
| 118 | |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 119 | static void serio_raw_cleanup(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 121 | struct serio_raw *serio_raw = |
| 122 | container_of(kref, struct serio_raw, kref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 124 | misc_deregister(&serio_raw->dev); |
| 125 | list_del_init(&serio_raw->node); |
| 126 | kfree(serio_raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static int serio_raw_release(struct inode *inode, struct file *file) |
| 130 | { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 131 | struct serio_raw_client *client = file->private_data; |
| 132 | struct serio_raw *serio_raw = client->serio_raw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 134 | mutex_lock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 136 | kref_put(&serio_raw->kref, serio_raw_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 138 | mutex_unlock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Dmitry Torokhov | 8c31eb0 | 2011-10-10 18:30:36 -0700 | [diff] [blame] | 142 | static bool serio_raw_fetch_byte(struct serio_raw *serio_raw, char *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Dmitry Torokhov | 8c31eb0 | 2011-10-10 18:30:36 -0700 | [diff] [blame] | 144 | bool empty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Dmitry Torokhov | 843e784 | 2011-10-10 18:30:26 -0700 | [diff] [blame] | 146 | serio_pause_rx(serio_raw->serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | empty = serio_raw->head == serio_raw->tail; |
| 149 | if (!empty) { |
| 150 | *c = serio_raw->queue[serio_raw->tail]; |
| 151 | serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; |
| 152 | } |
| 153 | |
Dmitry Torokhov | 843e784 | 2011-10-10 18:30:26 -0700 | [diff] [blame] | 154 | serio_continue_rx(serio_raw->serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | return !empty; |
| 157 | } |
| 158 | |
| 159 | static ssize_t serio_raw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
| 160 | { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 161 | struct serio_raw_client *client = file->private_data; |
| 162 | struct serio_raw *serio_raw = client->serio_raw; |
Andrew Morton | 4f179f7 | 2007-07-10 00:38:31 -0400 | [diff] [blame] | 163 | char uninitialized_var(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | ssize_t retval = 0; |
| 165 | |
| 166 | if (!serio_raw->serio) |
| 167 | return -ENODEV; |
| 168 | |
| 169 | if (serio_raw->head == serio_raw->tail && (file->f_flags & O_NONBLOCK)) |
| 170 | return -EAGAIN; |
| 171 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 172 | retval = wait_event_interruptible(serio_raw->wait, |
| 173 | serio_raw->head != serio_raw->tail || |
| 174 | !serio_raw->serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (retval) |
| 176 | return retval; |
| 177 | |
| 178 | if (!serio_raw->serio) |
| 179 | return -ENODEV; |
| 180 | |
| 181 | while (retval < count && serio_raw_fetch_byte(serio_raw, &c)) { |
| 182 | if (put_user(c, buffer++)) |
| 183 | return -EFAULT; |
| 184 | retval++; |
| 185 | } |
| 186 | |
| 187 | return retval; |
| 188 | } |
| 189 | |
| 190 | static ssize_t serio_raw_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) |
| 191 | { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 192 | struct serio_raw_client *client = file->private_data; |
| 193 | struct serio_raw *serio_raw = client->serio_raw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | ssize_t written = 0; |
| 195 | int retval; |
| 196 | unsigned char c; |
| 197 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 198 | retval = mutex_lock_interruptible(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (retval) |
| 200 | return retval; |
| 201 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 202 | if (!serio_raw->serio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | retval = -ENODEV; |
| 204 | goto out; |
| 205 | } |
| 206 | |
| 207 | if (count > 32) |
| 208 | count = 32; |
| 209 | |
| 210 | while (count--) { |
| 211 | if (get_user(c, buffer++)) { |
| 212 | retval = -EFAULT; |
| 213 | goto out; |
| 214 | } |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 215 | if (serio_write(serio_raw->serio, c)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | retval = -EIO; |
| 217 | goto out; |
| 218 | } |
| 219 | written++; |
| 220 | }; |
| 221 | |
| 222 | out: |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 223 | mutex_unlock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return written; |
| 225 | } |
| 226 | |
| 227 | static unsigned int serio_raw_poll(struct file *file, poll_table *wait) |
| 228 | { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 229 | struct serio_raw_client *client = file->private_data; |
| 230 | struct serio_raw *serio_raw = client->serio_raw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 232 | poll_wait(file, &serio_raw->wait, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 234 | if (serio_raw->head != serio_raw->tail) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return POLLIN | POLLRDNORM; |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 240 | static const struct file_operations serio_raw_fops = { |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 241 | .owner = THIS_MODULE, |
| 242 | .open = serio_raw_open, |
| 243 | .release = serio_raw_release, |
| 244 | .read = serio_raw_read, |
| 245 | .write = serio_raw_write, |
| 246 | .poll = serio_raw_poll, |
| 247 | .fasync = serio_raw_fasync, |
| 248 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | |
| 252 | /********************************************************************* |
| 253 | * Interface with serio port * |
| 254 | *********************************************************************/ |
| 255 | |
| 256 | static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 257 | unsigned int dfl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | struct serio_raw *serio_raw = serio_get_drvdata(serio); |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 260 | struct serio_raw_client *client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | unsigned int head = serio_raw->head; |
| 262 | |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 263 | /* we are holding serio->lock here so we are protected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | serio_raw->queue[head] = data; |
| 265 | head = (head + 1) % SERIO_RAW_QUEUE_LEN; |
| 266 | if (likely(head != serio_raw->tail)) { |
| 267 | serio_raw->head = head; |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 268 | list_for_each_entry(client, &serio_raw->client_list, node) |
| 269 | kill_fasync(&client->fasync, SIGIO, POLL_IN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | wake_up_interruptible(&serio_raw->wait); |
| 271 | } |
| 272 | |
| 273 | return IRQ_HANDLED; |
| 274 | } |
| 275 | |
| 276 | static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) |
| 277 | { |
| 278 | struct serio_raw *serio_raw; |
| 279 | int err; |
| 280 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 281 | if (!(serio_raw = kzalloc(sizeof(struct serio_raw), GFP_KERNEL))) { |
Dmitry Torokhov | 8d92847 | 2011-10-10 18:30:46 -0700 | [diff] [blame^] | 282 | dev_dbg(&serio->dev, "can't allocate memory for a device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | return -ENOMEM; |
| 284 | } |
| 285 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 286 | mutex_lock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | snprintf(serio_raw->name, sizeof(serio_raw->name), "serio_raw%d", serio_raw_no++); |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 289 | kref_init(&serio_raw->kref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | serio_raw->serio = serio; |
Dmitry Torokhov | 7c5bbb2 | 2011-10-10 18:30:14 -0700 | [diff] [blame] | 291 | INIT_LIST_HEAD(&serio_raw->client_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | init_waitqueue_head(&serio_raw->wait); |
| 293 | |
| 294 | serio_set_drvdata(serio, serio_raw); |
| 295 | |
| 296 | err = serio_open(serio, drv); |
| 297 | if (err) |
| 298 | goto out_free; |
| 299 | |
| 300 | list_add_tail(&serio_raw->node, &serio_raw_list); |
| 301 | |
| 302 | serio_raw->dev.minor = PSMOUSE_MINOR; |
| 303 | serio_raw->dev.name = serio_raw->name; |
Greg Kroah-Hartman | 94fbcde | 2006-07-27 16:16:04 -0700 | [diff] [blame] | 304 | serio_raw->dev.parent = &serio->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | serio_raw->dev.fops = &serio_raw_fops; |
| 306 | |
| 307 | err = misc_register(&serio_raw->dev); |
| 308 | if (err) { |
| 309 | serio_raw->dev.minor = MISC_DYNAMIC_MINOR; |
| 310 | err = misc_register(&serio_raw->dev); |
| 311 | } |
| 312 | |
| 313 | if (err) { |
Dmitry Torokhov | 8d92847 | 2011-10-10 18:30:46 -0700 | [diff] [blame^] | 314 | dev_err(&serio->dev, |
| 315 | "failed to register raw access device for %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | serio->phys); |
| 317 | goto out_close; |
| 318 | } |
| 319 | |
Dmitry Torokhov | 8d92847 | 2011-10-10 18:30:46 -0700 | [diff] [blame^] | 320 | dev_info(&serio->dev, "raw access enabled on %s (%s, minor %d)\n", |
| 321 | serio->phys, serio_raw->name, serio_raw->dev.minor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | goto out; |
| 323 | |
| 324 | out_close: |
| 325 | serio_close(serio); |
| 326 | list_del_init(&serio_raw->node); |
| 327 | out_free: |
| 328 | serio_set_drvdata(serio, NULL); |
| 329 | kfree(serio_raw); |
| 330 | out: |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 331 | mutex_unlock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | return err; |
| 333 | } |
| 334 | |
| 335 | static int serio_raw_reconnect(struct serio *serio) |
| 336 | { |
| 337 | struct serio_raw *serio_raw = serio_get_drvdata(serio); |
| 338 | struct serio_driver *drv = serio->drv; |
| 339 | |
| 340 | if (!drv || !serio_raw) { |
Dmitry Torokhov | 8d92847 | 2011-10-10 18:30:46 -0700 | [diff] [blame^] | 341 | dev_dbg(&serio->dev, |
| 342 | "reconnect request, but serio is disconnected, ignoring...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return -1; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Nothing needs to be done here, we just need this method to |
| 348 | * keep the same device. |
| 349 | */ |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static void serio_raw_disconnect(struct serio *serio) |
| 354 | { |
| 355 | struct serio_raw *serio_raw; |
| 356 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 357 | mutex_lock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | serio_raw = serio_get_drvdata(serio); |
| 360 | |
| 361 | serio_close(serio); |
| 362 | serio_set_drvdata(serio, NULL); |
| 363 | |
| 364 | serio_raw->serio = NULL; |
Dmitry Torokhov | ba538cd | 2011-10-10 18:30:03 -0700 | [diff] [blame] | 365 | wake_up_interruptible(&serio_raw->wait); |
| 366 | kref_put(&serio_raw->kref, serio_raw_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 368 | mutex_unlock(&serio_raw_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static struct serio_device_id serio_raw_serio_ids[] = { |
| 372 | { |
| 373 | .type = SERIO_8042, |
| 374 | .proto = SERIO_ANY, |
| 375 | .id = SERIO_ANY, |
| 376 | .extra = SERIO_ANY, |
| 377 | }, |
Niels de Vos | d19497e | 2008-09-04 22:20:11 -0400 | [diff] [blame] | 378 | { |
| 379 | .type = SERIO_8042_XL, |
| 380 | .proto = SERIO_ANY, |
| 381 | .id = SERIO_ANY, |
| 382 | .extra = SERIO_ANY, |
| 383 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { 0 } |
| 385 | }; |
| 386 | |
| 387 | MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids); |
| 388 | |
| 389 | static struct serio_driver serio_raw_drv = { |
| 390 | .driver = { |
| 391 | .name = "serio_raw", |
| 392 | }, |
| 393 | .description = DRIVER_DESC, |
| 394 | .id_table = serio_raw_serio_ids, |
| 395 | .interrupt = serio_raw_interrupt, |
| 396 | .connect = serio_raw_connect, |
| 397 | .reconnect = serio_raw_reconnect, |
| 398 | .disconnect = serio_raw_disconnect, |
Dmitry Torokhov | 8c31eb0 | 2011-10-10 18:30:36 -0700 | [diff] [blame] | 399 | .manual_bind = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | static int __init serio_raw_init(void) |
| 403 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 404 | return serio_register_driver(&serio_raw_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void __exit serio_raw_exit(void) |
| 408 | { |
| 409 | serio_unregister_driver(&serio_raw_drv); |
| 410 | } |
| 411 | |
| 412 | module_init(serio_raw_init); |
| 413 | module_exit(serio_raw_exit); |