blob: e9647ebff1871ae6285e76785b0a5684d21b7c94 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Raw serio device providing access to a raw byte stream from underlying
4 * serio port. Closely emulates behavior of pre-2.6 /dev/psaux device
5 *
6 * Copyright (c) 2004 Dmitry Torokhov
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Dmitry Torokhovba538cd2011-10-10 18:30:03 -07009#include <linux/kref.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040010#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/slab.h>
12#include <linux/poll.h>
13#include <linux/module.h>
14#include <linux/serio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/major.h>
16#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/miscdevice.h>
18#include <linux/wait.h>
Arjan van de Venc4e32e92006-02-19 00:21:55 -050019#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#define DRIVER_DESC "Raw serio driver"
22
23MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
24MODULE_DESCRIPTION(DRIVER_DESC);
25MODULE_LICENSE("GPL");
26
27#define SERIO_RAW_QUEUE_LEN 64
28struct serio_raw {
29 unsigned char queue[SERIO_RAW_QUEUE_LEN];
30 unsigned int tail, head;
31
32 char name[16];
Dmitry Torokhovba538cd2011-10-10 18:30:03 -070033 struct kref kref;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct serio *serio;
35 struct miscdevice dev;
36 wait_queue_head_t wait;
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070037 struct list_head client_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 struct list_head node;
Dmitry Torokhov85f5b352011-10-10 18:31:04 -070039 bool dead;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070042struct serio_raw_client {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct fasync_struct *fasync;
44 struct serio_raw *serio_raw;
45 struct list_head node;
46};
47
Arjan van de Venc4e32e92006-02-19 00:21:55 -050048static DEFINE_MUTEX(serio_raw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static LIST_HEAD(serio_raw_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*********************************************************************
52 * Interface with userspace (file operations) *
53 *********************************************************************/
54
55static int serio_raw_fasync(int fd, struct file *file, int on)
56{
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070057 struct serio_raw_client *client = file->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070059 return fasync_helper(fd, file, on, &client->fasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
62static struct serio_raw *serio_raw_locate(int minor)
63{
64 struct serio_raw *serio_raw;
65
66 list_for_each_entry(serio_raw, &serio_raw_list, node) {
67 if (serio_raw->dev.minor == minor)
68 return serio_raw;
69 }
70
71 return NULL;
72}
73
74static int serio_raw_open(struct inode *inode, struct file *file)
75{
76 struct serio_raw *serio_raw;
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070077 struct serio_raw_client *client;
78 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Arjan van de Venc4e32e92006-02-19 00:21:55 -050080 retval = mutex_lock_interruptible(&serio_raw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 if (retval)
Thadeu Lima de Souza Cascardo77554b42010-03-09 20:38:47 -080082 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Thadeu Lima de Souza Cascardo77554b42010-03-09 20:38:47 -080084 serio_raw = serio_raw_locate(iminor(inode));
85 if (!serio_raw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 retval = -ENODEV;
87 goto out;
88 }
89
Dmitry Torokhov85f5b352011-10-10 18:31:04 -070090 if (serio_raw->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 retval = -ENODEV;
92 goto out;
93 }
94
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -070095 client = kzalloc(sizeof(struct serio_raw_client), GFP_KERNEL);
96 if (!client) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 retval = -ENOMEM;
98 goto out;
99 }
100
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700101 client->serio_raw = serio_raw;
102 file->private_data = client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Dmitry Torokhovba538cd2011-10-10 18:30:03 -0700104 kref_get(&serio_raw->kref);
Dmitry Torokhov843e7842011-10-10 18:30:26 -0700105
106 serio_pause_rx(serio_raw->serio);
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700107 list_add_tail(&client->node, &serio_raw->client_list);
Dmitry Torokhov843e7842011-10-10 18:30:26 -0700108 serio_continue_rx(serio_raw->serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110out:
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500111 mutex_unlock(&serio_raw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return retval;
113}
114
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700115static void serio_raw_free(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Dmitry Torokhovba538cd2011-10-10 18:30:03 -0700117 struct serio_raw *serio_raw =
118 container_of(kref, struct serio_raw, kref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Dmitry Torokhov85f5b352011-10-10 18:31:04 -0700120 put_device(&serio_raw->serio->dev);
Dmitry Torokhovba538cd2011-10-10 18:30:03 -0700121 kfree(serio_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124static int serio_raw_release(struct inode *inode, struct file *file)
125{
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700126 struct serio_raw_client *client = file->private_data;
127 struct serio_raw *serio_raw = client->serio_raw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700129 serio_pause_rx(serio_raw->serio);
130 list_del(&client->node);
131 serio_continue_rx(serio_raw->serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700133 kfree(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700135 kref_put(&serio_raw->kref, serio_raw_free);
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return 0;
138}
139
Dmitry Torokhov8c31eb02011-10-10 18:30:36 -0700140static bool serio_raw_fetch_byte(struct serio_raw *serio_raw, char *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Dmitry Torokhov8c31eb02011-10-10 18:30:36 -0700142 bool empty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Dmitry Torokhov843e7842011-10-10 18:30:26 -0700144 serio_pause_rx(serio_raw->serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 empty = serio_raw->head == serio_raw->tail;
147 if (!empty) {
148 *c = serio_raw->queue[serio_raw->tail];
149 serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN;
150 }
151
Dmitry Torokhov843e7842011-10-10 18:30:26 -0700152 serio_continue_rx(serio_raw->serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 return !empty;
155}
156
Dmitry Torokhov15a564d2011-10-10 18:30:56 -0700157static ssize_t serio_raw_read(struct file *file, char __user *buffer,
158 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700160 struct serio_raw_client *client = file->private_data;
161 struct serio_raw *serio_raw = client->serio_raw;
Andrew Morton4f179f72007-07-10 00:38:31 -0400162 char uninitialized_var(c);
Che-Liang Chiou7a0a27d2012-02-01 09:25:35 -0800163 ssize_t read = 0;
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700164 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700166 for (;;) {
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700167 if (serio_raw->dead)
168 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700170 if (serio_raw->head == serio_raw->tail &&
171 (file->f_flags & O_NONBLOCK))
172 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700174 if (count == 0)
Che-Liang Chiou7a0a27d2012-02-01 09:25:35 -0800175 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700177 while (read < count && serio_raw_fetch_byte(serio_raw, &c)) {
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700178 if (put_user(c, buffer++))
179 return -EFAULT;
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700180 read++;
181 }
182
183 if (read)
184 break;
185
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700186 if (!(file->f_flags & O_NONBLOCK)) {
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700187 error = wait_event_interruptible(serio_raw->wait,
188 serio_raw->head != serio_raw->tail ||
189 serio_raw->dead);
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700190 if (error)
191 return error;
192 }
193 }
Dmitry Torokhov486c8ab2012-04-20 22:33:08 -0700194
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700195 return read;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Dmitry Torokhov15a564d2011-10-10 18:30:56 -0700198static ssize_t serio_raw_write(struct file *file, const char __user *buffer,
199 size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700201 struct serio_raw_client *client = file->private_data;
202 struct serio_raw *serio_raw = client->serio_raw;
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700203 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 unsigned char c;
205
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500206 retval = mutex_lock_interruptible(&serio_raw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (retval)
208 return retval;
209
Dmitry Torokhov85f5b352011-10-10 18:31:04 -0700210 if (serio_raw->dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 retval = -ENODEV;
212 goto out;
213 }
214
215 if (count > 32)
216 count = 32;
217
218 while (count--) {
219 if (get_user(c, buffer++)) {
220 retval = -EFAULT;
221 goto out;
222 }
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700223
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700224 if (serio_write(serio_raw->serio, c)) {
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700225 /* Either signal error or partial write */
226 if (retval == 0)
227 retval = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 goto out;
229 }
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700230
231 retval++;
Che-Liang Chioud89c9bc2012-01-10 00:45:12 -0800232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234out:
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500235 mutex_unlock(&serio_raw_mutex);
Dmitry Torokhov46f49b72012-05-02 00:13:38 -0700236 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Al Viroafc9a422017-07-03 06:39:46 -0400239static __poll_t serio_raw_poll(struct file *file, poll_table *wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700241 struct serio_raw_client *client = file->private_data;
242 struct serio_raw *serio_raw = client->serio_raw;
Al Viroafc9a422017-07-03 06:39:46 -0400243 __poll_t mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700245 poll_wait(file, &serio_raw->wait, wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800247 mask = serio_raw->dead ? EPOLLHUP | EPOLLERR : EPOLLOUT | EPOLLWRNORM;
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700248 if (serio_raw->head != serio_raw->tail)
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800249 mask |= EPOLLIN | EPOLLRDNORM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Dmitry Torokhov0c62fbf2012-01-10 00:45:12 -0800251 return mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800254static const struct file_operations serio_raw_fops = {
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700255 .owner = THIS_MODULE,
256 .open = serio_raw_open,
257 .release = serio_raw_release,
258 .read = serio_raw_read,
259 .write = serio_raw_write,
260 .poll = serio_raw_poll,
261 .fasync = serio_raw_fasync,
262 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263};
264
265
266/*********************************************************************
Dmitry Torokhov15a564d2011-10-10 18:30:56 -0700267 * Interface with serio port *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 *********************************************************************/
269
270static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
David Howells7d12e782006-10-05 14:55:46 +0100271 unsigned int dfl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
273 struct serio_raw *serio_raw = serio_get_drvdata(serio);
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700274 struct serio_raw_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 unsigned int head = serio_raw->head;
276
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700277 /* we are holding serio->lock here so we are protected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 serio_raw->queue[head] = data;
279 head = (head + 1) % SERIO_RAW_QUEUE_LEN;
280 if (likely(head != serio_raw->tail)) {
281 serio_raw->head = head;
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700282 list_for_each_entry(client, &serio_raw->client_list, node)
283 kill_fasync(&client->fasync, SIGIO, POLL_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 wake_up_interruptible(&serio_raw->wait);
285 }
286
287 return IRQ_HANDLED;
288}
289
290static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
291{
Aniroop Mathur939ffb12014-12-03 14:27:42 -0800292 static atomic_t serio_raw_no = ATOMIC_INIT(-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct serio_raw *serio_raw;
294 int err;
295
Dmitry Torokhov15a564d2011-10-10 18:30:56 -0700296 serio_raw = kzalloc(sizeof(struct serio_raw), GFP_KERNEL);
297 if (!serio_raw) {
Dmitry Torokhov8d928472011-10-10 18:30:46 -0700298 dev_dbg(&serio->dev, "can't allocate memory for a device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return -ENOMEM;
300 }
301
Dmitry Torokhov15a564d2011-10-10 18:30:56 -0700302 snprintf(serio_raw->name, sizeof(serio_raw->name),
Aniroop Mathur939ffb12014-12-03 14:27:42 -0800303 "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no));
Dmitry Torokhovba538cd2011-10-10 18:30:03 -0700304 kref_init(&serio_raw->kref);
Dmitry Torokhov7c5bbb22011-10-10 18:30:14 -0700305 INIT_LIST_HEAD(&serio_raw->client_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 init_waitqueue_head(&serio_raw->wait);
307
Dmitry Torokhov85f5b352011-10-10 18:31:04 -0700308 serio_raw->serio = serio;
309 get_device(&serio->dev);
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 serio_set_drvdata(serio, serio_raw);
312
313 err = serio_open(serio, drv);
314 if (err)
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700315 goto err_free;
316
317 err = mutex_lock_killable(&serio_raw_mutex);
318 if (err)
319 goto err_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 list_add_tail(&serio_raw->node, &serio_raw_list);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700322 mutex_unlock(&serio_raw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 serio_raw->dev.minor = PSMOUSE_MINOR;
325 serio_raw->dev.name = serio_raw->name;
Greg Kroah-Hartman94fbcde2006-07-27 16:16:04 -0700326 serio_raw->dev.parent = &serio->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 serio_raw->dev.fops = &serio_raw_fops;
328
329 err = misc_register(&serio_raw->dev);
330 if (err) {
331 serio_raw->dev.minor = MISC_DYNAMIC_MINOR;
332 err = misc_register(&serio_raw->dev);
333 }
334
335 if (err) {
Dmitry Torokhov8d928472011-10-10 18:30:46 -0700336 dev_err(&serio->dev,
337 "failed to register raw access device for %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 serio->phys);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700339 goto err_unlink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
341
Dmitry Torokhov8d928472011-10-10 18:30:46 -0700342 dev_info(&serio->dev, "raw access enabled on %s (%s, minor %d)\n",
343 serio->phys, serio_raw->name, serio_raw->dev.minor);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700344 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700346err_unlink:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 list_del_init(&serio_raw->node);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700348err_close:
349 serio_close(serio);
350err_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 serio_set_drvdata(serio, NULL);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700352 kref_put(&serio_raw->kref, serio_raw_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return err;
354}
355
356static int serio_raw_reconnect(struct serio *serio)
357{
358 struct serio_raw *serio_raw = serio_get_drvdata(serio);
359 struct serio_driver *drv = serio->drv;
360
361 if (!drv || !serio_raw) {
Dmitry Torokhov8d928472011-10-10 18:30:46 -0700362 dev_dbg(&serio->dev,
363 "reconnect request, but serio is disconnected, ignoring...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return -1;
365 }
366
367 /*
368 * Nothing needs to be done here, we just need this method to
369 * keep the same device.
370 */
371 return 0;
372}
373
Dmitry Torokhov8c1c10d2011-10-10 18:31:30 -0700374/*
375 * Wake up users waiting for IO so they can disconnect from
376 * dead device.
377 */
378static void serio_raw_hangup(struct serio_raw *serio_raw)
379{
380 struct serio_raw_client *client;
381
382 serio_pause_rx(serio_raw->serio);
383 list_for_each_entry(client, &serio_raw->client_list, node)
384 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
385 serio_continue_rx(serio_raw->serio);
386
387 wake_up_interruptible(&serio_raw->wait);
388}
389
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391static void serio_raw_disconnect(struct serio *serio)
392{
Dmitry Torokhov8c1c10d2011-10-10 18:31:30 -0700393 struct serio_raw *serio_raw = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700395 misc_deregister(&serio_raw->dev);
396
Arjan van de Venc4e32e92006-02-19 00:21:55 -0500397 mutex_lock(&serio_raw_mutex);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700398 serio_raw->dead = true;
399 list_del_init(&serio_raw->node);
400 mutex_unlock(&serio_raw_mutex);
401
402 serio_raw_hangup(serio_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 serio_close(serio);
Dmitry Torokhov550eca72011-10-10 18:31:39 -0700405 kref_put(&serio_raw->kref, serio_raw_free);
Dmitry Torokhov8c1c10d2011-10-10 18:31:30 -0700406
407 serio_set_drvdata(serio, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Arvind Yadav0aea22b2017-08-18 17:10:24 -0700410static const struct serio_device_id serio_raw_serio_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 {
412 .type = SERIO_8042,
413 .proto = SERIO_ANY,
414 .id = SERIO_ANY,
415 .extra = SERIO_ANY,
416 },
Niels de Vosd19497e2008-09-04 22:20:11 -0400417 {
418 .type = SERIO_8042_XL,
419 .proto = SERIO_ANY,
420 .id = SERIO_ANY,
421 .extra = SERIO_ANY,
422 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 { 0 }
424};
425
426MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
427
428static struct serio_driver serio_raw_drv = {
429 .driver = {
430 .name = "serio_raw",
431 },
432 .description = DRIVER_DESC,
433 .id_table = serio_raw_serio_ids,
434 .interrupt = serio_raw_interrupt,
435 .connect = serio_raw_connect,
436 .reconnect = serio_raw_reconnect,
437 .disconnect = serio_raw_disconnect,
Dmitry Torokhov8c31eb02011-10-10 18:30:36 -0700438 .manual_bind = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439};
440
Axel Lin65ac9f72012-04-03 23:50:17 -0700441module_serio_driver(serio_raw_drv);