15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
20 #include <linux/serio.h>
22 #include <linux/ctype.h>
25 #define DRIVER_DESC "Wacom W8001 serial touchscreen driver"
31 #define W8001_MAX_LENGTH 11
32 #define W8001_LEAD_MASK 0x80
33 #define W8001_LEAD_BYTE 0x80
34 #define W8001_TAB_MASK 0x40
35 #define W8001_TAB_BYTE 0x40
37 #define W8001_TOUCH_MASK (0x10 | W8001_LEAD_MASK)
38 #define W8001_TOUCH_BYTE (0x10 | W8001_LEAD_BYTE)
40 #define W8001_QUERY_PACKET 0x20
42 #define W8001_CMD_STOP '0'
43 #define W8001_CMD_START '1'
44 #define W8001_CMD_QUERY '*'
45 #define W8001_CMD_TOUCHQUERY '%'
48 #define W8001_PKTLEN_TOUCH93 5
49 #define W8001_PKTLEN_TOUCH9A 7
50 #define W8001_PKTLEN_TPCPEN 9
51 #define W8001_PKTLEN_TPCCTL 11
52 #define W8001_PKTLEN_TOUCH2FG 13
55 #define W8001_PEN_RESOLUTION 100
56 #define W8001_TOUCH_RESOLUTION 10
84 struct input_dev *
dev;
104 memset(coord, 0,
sizeof(*coord));
106 coord->
rdy = data[0] & 0x20;
107 coord->
tsw = data[0] & 0x01;
108 coord->
f1 = data[0] & 0x02;
109 coord->
f2 = data[0] & 0x04;
111 coord->
x = (data[1] & 0x7F) << 9;
112 coord->
x |= (data[2] & 0x7F) << 2;
113 coord->
x |= (data[6] & 0x60) >> 5;
115 coord->
y = (data[3] & 0x7F) << 9;
116 coord->
y |= (data[4] & 0x7F) << 2;
117 coord->
y |= (data[6] & 0x18) >> 3;
122 coord->
tilt_x = data[7] & 0x7F;
123 coord->
tilt_y = data[8] & 0x7F;
128 coord->
x = (data[1] << 7) | data[2];
129 coord->
y = (data[3] << 7) | data[4];
130 coord->
tsw = data[0] & 0x01;
133 static void scale_touch_coordinates(
struct w8001 *
w8001,
134 unsigned int *
x,
unsigned int *
y)
143 static void parse_multi_touch(
struct w8001 *w8001)
145 struct input_dev *
dev = w8001->
dev;
151 for (i = 0; i < 2; i++) {
152 bool touch = data[0] & (1 <<
i);
157 x = (data[6 * i + 1] << 7) | data[6 * i + 2];
158 y = (data[6 * i + 3] << 7) | data[6 * i + 4];
162 scale_touch_coordinates(w8001, &x, &y);
185 memset(query, 0,
sizeof(*query));
191 query->
x = data[3] << 9;
192 query->
x |= data[4] << 2;
193 query->
x |= (data[2] >> 5) & 0x3;
195 query->
y = data[5] << 9;
196 query->
y |= data[6] << 2;
197 query->
y |= (data[2] >> 3) & 0x3;
200 if (!query->
x && !query->
y) {
209 static void report_pen_events(
struct w8001 *w8001,
struct w8001_coord *coord)
211 struct input_dev *dev = w8001->
dev;
223 switch (w8001->
type) {
251 input_report_abs(dev,
ABS_X, coord->
x);
252 input_report_abs(dev,
ABS_Y, coord->
y);
256 input_report_key(dev, w8001->
type, coord->
rdy);
263 static void report_single_touch(
struct w8001 *w8001,
struct w8001_coord *coord)
265 struct input_dev *dev = w8001->
dev;
266 unsigned int x = coord->
x;
267 unsigned int y = coord->
y;
270 scale_touch_coordinates(w8001, &x, &y);
272 input_report_abs(dev,
ABS_X, x);
273 input_report_abs(dev,
ABS_Y, y);
283 unsigned char data,
unsigned int flags)
285 struct w8001 *w8001 = serio_get_drvdata(serio);
290 switch (w8001->
idx++) {
293 pr_debug(
"w8001: unsynchronized data: 0x%02x\n", data);
308 parse_single_touch(w8001->
data, &coord);
309 report_single_touch(w8001, &coord);
325 parse_pen_data(w8001->
data, &coord);
326 report_pen_events(w8001, &coord);
344 parse_multi_touch(w8001);
351 static int w8001_command(
struct w8001 *w8001,
unsigned char command,
359 rc = serio_write(w8001->
serio, command);
360 if (rc == 0 && wait_response) {
370 static int w8001_open(
struct input_dev *dev)
372 struct w8001 *w8001 = input_get_drvdata(dev);
377 static void w8001_close(
struct input_dev *dev)
379 struct w8001 *w8001 = input_get_drvdata(dev);
384 static int w8001_setup(
struct w8001 *w8001)
386 struct input_dev *dev = w8001->
dev;
411 parse_pen_data(w8001->
response, &coord);
415 input_set_abs_params(dev,
ABS_X, 0, coord.
x, 0, 0);
416 input_set_abs_params(dev,
ABS_Y, 0, coord.
y, 0, 0);
439 parse_touchquery(w8001->
response, &touch);
450 input_set_abs_params(dev,
ABS_X, 0, touch.x, 0, 0);
451 input_set_abs_params(dev,
ABS_Y, 0, touch.y, 0, 0);
452 input_abs_set_res(dev,
ABS_X, touch.panel_res);
453 input_abs_set_res(dev,
ABS_Y, touch.panel_res);
455 switch (touch.sensor_id) {
500 static void w8001_disconnect(
struct serio *serio)
502 struct w8001 *w8001 = serio_get_drvdata(serio);
506 input_unregister_device(w8001->
dev);
509 serio_set_drvdata(serio,
NULL);
518 static int w8001_connect(
struct serio *serio,
struct serio_driver *drv)
521 struct input_dev *input_dev;
524 w8001 = kzalloc(
sizeof(
struct w8001),
GFP_KERNEL);
525 input_dev = input_allocate_device();
526 if (!w8001 || !input_dev) {
531 w8001->
serio = serio;
532 w8001->
dev = input_dev;
536 serio_set_drvdata(serio, w8001);
541 err = w8001_setup(w8001);
545 input_dev->name = w8001->
name;
546 input_dev->phys = w8001->
phys;
547 input_dev->id.product = w8001->
id;
549 input_dev->id.vendor = 0x056a;
550 input_dev->id.version = 0x0100;
551 input_dev->dev.parent = &serio->
dev;
553 input_dev->open = w8001_open;
554 input_dev->close = w8001_close;
556 input_set_drvdata(input_dev, w8001);
558 err = input_register_device(w8001->
dev);
567 serio_set_drvdata(serio,
NULL);
569 input_free_device(input_dev);
591 .id_table = w8001_serio_ids,
592 .interrupt = w8001_interrupt,
593 .connect = w8001_connect,
594 .disconnect = w8001_disconnect,