blob: fbef35d2d76c78d23c89ea4a02e52f62cef79f47 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * $Id: tsdev.c,v 1.15 2002/04/10 16:50:19 jsimmons Exp $
3 *
4 * Copyright (c) 2001 "Crazy" james Simmons
5 *
6 * Compaq touchscreen protocol driver. The protocol emulated by this driver
7 * is obsolete; for new programs use the tslib library which can read directly
8 * from evdev and perform dejittering, variance filtering and calibration -
9 * all in user space, not at kernel level. The meaning of this driver is
10 * to allow usage of newer input drivers with old applications that use the
11 * old /dev/h3600_ts and /dev/h3600_tsraw devices.
12 *
13 * 09-Apr-2004: Andrew Zabolotny <zap@homelink.ru>
14 * Fixed to actually work, not just output random numbers.
15 * Added support for both h3600_ts and h3600_tsraw protocol
16 * emulation.
17 */
18
19/*
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 *
34 * Should you need to contact me, the author, you can do so either by
35 * e-mail - mail your message to <jsimmons@infradead.org>.
36 */
37
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -040038#define TSDEV_MINOR_BASE 128
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define TSDEV_MINORS 32
40/* First 16 devices are h3600_ts compatible; second 16 are h3600_tsraw */
41#define TSDEV_MINOR_MASK 15
42#define TSDEV_BUFFER_SIZE 64
43
44#include <linux/slab.h>
45#include <linux/poll.h>
46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/init.h>
49#include <linux/input.h>
50#include <linux/major.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/smp_lock.h>
52#include <linux/random.h>
53#include <linux/time.h>
54#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#ifndef CONFIG_INPUT_TSDEV_SCREEN_X
57#define CONFIG_INPUT_TSDEV_SCREEN_X 240
58#endif
59#ifndef CONFIG_INPUT_TSDEV_SCREEN_Y
60#define CONFIG_INPUT_TSDEV_SCREEN_Y 320
61#endif
62
63/* This driver emulates both protocols of the old h3600_ts and h3600_tsraw
64 * devices. The first one must output X/Y data in 'cooked' format, e.g.
65 * filtered, dejittered and calibrated. Second device just outputs raw
66 * data received from the hardware.
67 *
68 * This driver doesn't support filtering and dejittering; it supports only
69 * calibration. Filtering and dejittering must be done in the low-level
70 * driver, if needed, because it may gain additional benefits from knowing
71 * the low-level details, the nature of noise and so on.
72 *
73 * The driver precomputes a calibration matrix given the initial xres and
74 * yres values (quite innacurate for most touchscreens) that will result
75 * in a more or less expected range of output values. The driver supports
76 * the TS_SET_CAL ioctl, which will replace the calibration matrix with a
77 * new one, supposedly generated from the values taken from the raw device.
78 */
79
80MODULE_AUTHOR("James Simmons <jsimmons@transvirtual.com>");
81MODULE_DESCRIPTION("Input driver to touchscreen converter");
82MODULE_LICENSE("GPL");
83
84static int xres = CONFIG_INPUT_TSDEV_SCREEN_X;
85module_param(xres, uint, 0);
86MODULE_PARM_DESC(xres, "Horizontal screen resolution (can be negative for X-mirror)");
87
88static int yres = CONFIG_INPUT_TSDEV_SCREEN_Y;
89module_param(yres, uint, 0);
90MODULE_PARM_DESC(yres, "Vertical screen resolution (can be negative for Y-mirror)");
91
92/* From Compaq's Touch Screen Specification version 0.2 (draft) */
93struct ts_event {
94 short pressure;
95 short x;
96 short y;
97 short millisecs;
98};
99
100struct ts_calibration {
101 int xscale;
102 int xtrans;
103 int yscale;
104 int ytrans;
105 int xyswap;
106};
107
108struct tsdev {
109 int exist;
110 int open;
111 int minor;
112 char name[8];
113 wait_queue_head_t wait;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400114 struct list_head client_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 struct input_handle handle;
116 int x, y, pressure;
117 struct ts_calibration cal;
118};
119
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400120struct tsdev_client {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct fasync_struct *fasync;
122 struct list_head node;
123 struct tsdev *tsdev;
124 int head, tail;
125 struct ts_event event[TSDEV_BUFFER_SIZE];
126 int raw;
127};
128
129/* The following ioctl codes are defined ONLY for backward compatibility.
130 * Don't use tsdev for new developement; use the tslib library instead.
131 * Touchscreen calibration is a fully userspace task.
132 */
133/* Use 'f' as magic number */
134#define IOC_H3600_TS_MAGIC 'f'
135#define TS_GET_CAL _IOR(IOC_H3600_TS_MAGIC, 10, struct ts_calibration)
136#define TS_SET_CAL _IOW(IOC_H3600_TS_MAGIC, 11, struct ts_calibration)
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138static struct tsdev *tsdev_table[TSDEV_MINORS/2];
139
140static int tsdev_fasync(int fd, struct file *file, int on)
141{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400142 struct tsdev_client *client = file->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 int retval;
144
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400145 retval = fasync_helper(fd, file, on, &client->fasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return retval < 0 ? retval : 0;
147}
148
149static int tsdev_open(struct inode *inode, struct file *file)
150{
151 int i = iminor(inode) - TSDEV_MINOR_BASE;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400152 struct tsdev_client *client;
153 struct tsdev *tsdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Richard Purdieff141a02007-02-10 01:29:11 -0500155 printk(KERN_WARNING "tsdev (compaq touchscreen emulation) is scheduled "
156 "for removal.\nSee Documentation/feature-removal-schedule.txt "
157 "for details.\n");
158
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400159 if (i >= TSDEV_MINORS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return -ENODEV;
161
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400162 tsdev = tsdev_table[i & TSDEV_MINOR_MASK];
163 if (!tsdev || !tsdev->exist)
164 return -ENODEV;
165
166 client = kzalloc(sizeof(struct tsdev_client), GFP_KERNEL);
167 if (!client)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400170 client->tsdev = tsdev;
171 client->raw = (i >= TSDEV_MINORS / 2) ? 1 : 0;
172 list_add_tail(&client->node, &tsdev->client_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400174 if (!tsdev->open++ && tsdev->exist)
175 input_open_device(&tsdev->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400177 file->private_data = client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return 0;
179}
180
181static void tsdev_free(struct tsdev *tsdev)
182{
183 tsdev_table[tsdev->minor] = NULL;
184 kfree(tsdev);
185}
186
187static int tsdev_release(struct inode *inode, struct file *file)
188{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400189 struct tsdev_client *client = file->private_data;
190 struct tsdev *tsdev = client->tsdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 tsdev_fasync(-1, file, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400194 list_del(&client->node);
195 kfree(client);
196
197 if (!--tsdev->open) {
198 if (tsdev->exist)
199 input_close_device(&tsdev->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 else
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400201 tsdev_free(tsdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return 0;
205}
206
207static ssize_t tsdev_read(struct file *file, char __user *buffer, size_t count,
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400208 loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400210 struct tsdev_client *client = file->private_data;
211 struct tsdev *tsdev = client->tsdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 int retval = 0;
213
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400214 if (client->head == client->tail && tsdev->exist && (file->f_flags & O_NONBLOCK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 return -EAGAIN;
216
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400217 retval = wait_event_interruptible(tsdev->wait,
218 client->head != client->tail || !tsdev->exist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 if (retval)
220 return retval;
221
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400222 if (!tsdev->exist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return -ENODEV;
224
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400225 while (client->head != client->tail &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 retval + sizeof (struct ts_event) <= count) {
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400227 if (copy_to_user (buffer + retval, client->event + client->tail,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 sizeof (struct ts_event)))
229 return -EFAULT;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400230 client->tail = (client->tail + 1) & (TSDEV_BUFFER_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 retval += sizeof (struct ts_event);
232 }
233
234 return retval;
235}
236
237/* No kernel lock - fine */
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400238static unsigned int tsdev_poll(struct file *file, poll_table *wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400240 struct tsdev_client *client = file->private_data;
241 struct tsdev *tsdev = client->tsdev;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400242
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400243 poll_wait(file, &tsdev->wait, wait);
244 return ((client->head == client->tail) ? 0 : (POLLIN | POLLRDNORM)) |
245 (tsdev->exist ? 0 : (POLLHUP | POLLERR));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
248static int tsdev_ioctl(struct inode *inode, struct file *file,
249 unsigned int cmd, unsigned long arg)
250{
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400251 struct tsdev_client *client = file->private_data;
252 struct tsdev *tsdev = client->tsdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 int retval = 0;
254
255 switch (cmd) {
256 case TS_GET_CAL:
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400257 if (copy_to_user((void __user *)arg, &tsdev->cal,
258 sizeof (struct ts_calibration)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 retval = -EFAULT;
260 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case TS_SET_CAL:
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400263 if (copy_from_user(&tsdev->cal, (void __user *)arg,
264 sizeof (struct ts_calibration)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 retval = -EFAULT;
266 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 default:
269 retval = -EINVAL;
270 break;
271 }
272
273 return retval;
274}
275
Dmitry Torokhov66e66112006-09-14 01:31:59 -0400276static const struct file_operations tsdev_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .owner = THIS_MODULE,
278 .open = tsdev_open,
279 .release = tsdev_release,
280 .read = tsdev_read,
281 .poll = tsdev_poll,
282 .fasync = tsdev_fasync,
283 .ioctl = tsdev_ioctl,
284};
285
286static void tsdev_event(struct input_handle *handle, unsigned int type,
287 unsigned int code, int value)
288{
289 struct tsdev *tsdev = handle->private;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400290 struct tsdev_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 struct timeval time;
292
293 switch (type) {
294 case EV_ABS:
295 switch (code) {
296 case ABS_X:
297 tsdev->x = value;
298 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 case ABS_Y:
301 tsdev->y = value;
302 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 case ABS_PRESSURE:
305 if (value > handle->dev->absmax[ABS_PRESSURE])
306 value = handle->dev->absmax[ABS_PRESSURE];
307 value -= handle->dev->absmin[ABS_PRESSURE];
308 if (value < 0)
309 value = 0;
310 tsdev->pressure = value;
311 break;
312 }
313 break;
314
315 case EV_REL:
316 switch (code) {
317 case REL_X:
318 tsdev->x += value;
319 if (tsdev->x < 0)
320 tsdev->x = 0;
321 else if (tsdev->x > xres)
322 tsdev->x = xres;
323 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 case REL_Y:
326 tsdev->y += value;
327 if (tsdev->y < 0)
328 tsdev->y = 0;
329 else if (tsdev->y > yres)
330 tsdev->y = yres;
331 break;
332 }
333 break;
334
335 case EV_KEY:
336 if (code == BTN_TOUCH || code == BTN_MOUSE) {
337 switch (value) {
338 case 0:
339 tsdev->pressure = 0;
340 break;
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 case 1:
343 if (!tsdev->pressure)
344 tsdev->pressure = 1;
345 break;
346 }
347 }
348 break;
349 }
350
351 if (type != EV_SYN || code != SYN_REPORT)
352 return;
353
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400354 list_for_each_entry(client, &tsdev->client_list, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 int x, y, tmp;
356
357 do_gettimeofday(&time);
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400358 client->event[client->head].millisecs = time.tv_usec / 100;
359 client->event[client->head].pressure = tsdev->pressure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 x = tsdev->x;
362 y = tsdev->y;
363
364 /* Calibration */
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400365 if (!client->raw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 x = ((x * tsdev->cal.xscale) >> 8) + tsdev->cal.xtrans;
367 y = ((y * tsdev->cal.yscale) >> 8) + tsdev->cal.ytrans;
368 if (tsdev->cal.xyswap) {
369 tmp = x; x = y; y = tmp;
370 }
371 }
372
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400373 client->event[client->head].x = x;
374 client->event[client->head].y = y;
375 client->head = (client->head + 1) & (TSDEV_BUFFER_SIZE - 1);
376 kill_fasync(&client->fasync, SIGIO, POLL_IN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378 wake_up_interruptible(&tsdev->wait);
379}
380
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400381static int tsdev_connect(struct input_handler *handler, struct input_dev *dev,
382 const struct input_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
384 struct tsdev *tsdev;
Greg Kroah-Hartmanc9bcd582005-10-27 22:25:43 -0700385 struct class_device *cdev;
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400386 dev_t devt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 int minor, delta;
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400388 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400390 for (minor = 0; minor < TSDEV_MINORS / 2 && tsdev_table[minor]; minor++);
391 if (minor >= TSDEV_MINORS / 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 printk(KERN_ERR
393 "tsdev: You have way too many touchscreens\n");
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400394 return -ENFILE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
396
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400397 tsdev = kzalloc(sizeof(struct tsdev), GFP_KERNEL);
398 if (!tsdev)
399 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400401 INIT_LIST_HEAD(&tsdev->client_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 init_waitqueue_head(&tsdev->wait);
403
404 sprintf(tsdev->name, "ts%d", minor);
405
406 tsdev->exist = 1;
407 tsdev->minor = minor;
408 tsdev->handle.dev = dev;
409 tsdev->handle.name = tsdev->name;
410 tsdev->handle.handler = handler;
411 tsdev->handle.private = tsdev;
412
413 /* Precompute the rough calibration matrix */
414 delta = dev->absmax [ABS_X] - dev->absmin [ABS_X] + 1;
415 if (delta == 0)
416 delta = 1;
417 tsdev->cal.xscale = (xres << 8) / delta;
418 tsdev->cal.xtrans = - ((dev->absmin [ABS_X] * tsdev->cal.xscale) >> 8);
419
420 delta = dev->absmax [ABS_Y] - dev->absmin [ABS_Y] + 1;
421 if (delta == 0)
422 delta = 1;
423 tsdev->cal.yscale = (yres << 8) / delta;
424 tsdev->cal.ytrans = - ((dev->absmin [ABS_Y] * tsdev->cal.yscale) >> 8);
425
426 tsdev_table[minor] = tsdev;
427
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400428 devt = MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor),
429
430 cdev = class_device_create(&input_class, &dev->cdev, devt,
431 dev->cdev.dev, tsdev->name);
432 if (IS_ERR(cdev)) {
433 error = PTR_ERR(cdev);
434 goto err_free_tsdev;
435 }
Greg Kroah-Hartmanc9bcd582005-10-27 22:25:43 -0700436
437 /* temporary symlink to keep userspace happy */
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400438 error = sysfs_create_link(&input_class.subsys.kset.kobj,
439 &cdev->kobj, tsdev->name);
440 if (error)
441 goto err_cdev_destroy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400443 error = input_register_handle(&tsdev->handle);
444 if (error)
445 goto err_remove_link;
446
447 return 0;
448
449 err_remove_link:
450 sysfs_remove_link(&input_class.subsys.kset.kobj, tsdev->name);
451 err_cdev_destroy:
452 class_device_destroy(&input_class, devt);
453 err_free_tsdev:
454 tsdev_table[minor] = NULL;
455 kfree(tsdev);
456 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459static void tsdev_disconnect(struct input_handle *handle)
460{
461 struct tsdev *tsdev = handle->private;
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400462 struct tsdev_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Dmitry Torokhov5b2a0822007-04-12 01:29:46 -0400464 input_unregister_handle(handle);
465
Greg Kroah-Hartmanc9bcd582005-10-27 22:25:43 -0700466 sysfs_remove_link(&input_class.subsys.kset.kobj, tsdev->name);
Greg Kroah-Hartmanea9f2402005-10-27 22:25:43 -0700467 class_device_destroy(&input_class,
gregkh@suse.de12356862005-03-15 14:26:30 -0800468 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 tsdev->exist = 0;
470
471 if (tsdev->open) {
472 input_close_device(handle);
473 wake_up_interruptible(&tsdev->wait);
Dmitry Torokhovd0ffb9b2007-04-12 01:30:00 -0400474 list_for_each_entry(client, &tsdev->client_list, node)
475 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 } else
477 tsdev_free(tsdev);
478}
479
Dmitry Torokhov66e66112006-09-14 01:31:59 -0400480static const struct input_device_id tsdev_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 {
482 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_RELBIT,
483 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
484 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) },
485 .relbit = { BIT(REL_X) | BIT(REL_Y) },
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400486 }, /* A mouse like device, at least one button, two relative axes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 {
489 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
490 .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
491 .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
492 .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400493 }, /* A tablet like device, at least touch detection, two absolute axes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 {
496 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_ABSBIT,
497 .evbit = { BIT(EV_ABS) },
498 .absbit = { BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) },
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400499 }, /* A tablet like device with several gradations of pressure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Dmitry Torokhov1e0afb22006-06-26 01:48:47 -0400501 {} /* Terminating entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502};
503
504MODULE_DEVICE_TABLE(input, tsdev_ids);
505
506static struct input_handler tsdev_handler = {
507 .event = tsdev_event,
508 .connect = tsdev_connect,
509 .disconnect = tsdev_disconnect,
510 .fops = &tsdev_fops,
511 .minor = TSDEV_MINOR_BASE,
512 .name = "tsdev",
513 .id_table = tsdev_ids,
514};
515
516static int __init tsdev_init(void)
517{
Dmitry Torokhov4263cf02006-09-14 01:32:39 -0400518 return input_register_handler(&tsdev_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521static void __exit tsdev_exit(void)
522{
523 input_unregister_handler(&tsdev_handler);
524}
525
526module_init(tsdev_init);
527module_exit(tsdev_exit);