2 * Wacom W8001 penabled serial touchscreen driver
4 * Copyright (c) 2008 Jaya Kumar
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
10 * Layout based on Elo serial touchscreen driver by Vojtech Pavlik
13 #include <linux/errno.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/input.h>
18 #include <linux/serio.h>
19 #include <linux/init.h>
20 #include <linux/ctype.h>
22 #define DRIVER_DESC "Wacom W8001 serial touchscreen driver"
24 MODULE_AUTHOR("Jaya Kumar <jayakumar.lkml@gmail.com>");
25 MODULE_DESCRIPTION(DRIVER_DESC
);
26 MODULE_LICENSE("GPL");
28 #define W8001_MAX_LENGTH 11
29 #define W8001_LEAD_MASK 0x80
30 #define W8001_LEAD_BYTE 0x80
31 #define W8001_TAB_MASK 0x40
32 #define W8001_TAB_BYTE 0x40
34 #define W8001_QUERY_PACKET 0x20
36 #define W8001_CMD_START '1'
37 #define W8001_CMD_QUERY '*'
52 * Per-touchscreen data.
56 struct input_dev
*dev
;
58 struct completion cmd_done
;
61 unsigned char response_type
;
62 unsigned char response
[W8001_MAX_LENGTH
];
63 unsigned char data
[W8001_MAX_LENGTH
];
67 static void parse_data(u8
*data
, struct w8001_coord
*coord
)
69 memset(coord
, 0, sizeof(*coord
));
71 coord
->rdy
= data
[0] & 0x20;
72 coord
->tsw
= data
[0] & 0x01;
73 coord
->f1
= data
[0] & 0x02;
74 coord
->f2
= data
[0] & 0x04;
76 coord
->x
= (data
[1] & 0x7F) << 9;
77 coord
->x
|= (data
[2] & 0x7F) << 2;
78 coord
->x
|= (data
[6] & 0x60) >> 5;
80 coord
->y
= (data
[3] & 0x7F) << 9;
81 coord
->y
|= (data
[4] & 0x7F) << 2;
82 coord
->y
|= (data
[6] & 0x18) >> 3;
84 coord
->pen_pressure
= data
[5] & 0x7F;
85 coord
->pen_pressure
|= (data
[6] & 0x07) << 7 ;
87 coord
->tilt_x
= data
[7] & 0x7F;
88 coord
->tilt_y
= data
[8] & 0x7F;
91 static irqreturn_t
w8001_interrupt(struct serio
*serio
,
92 unsigned char data
, unsigned int flags
)
94 struct w8001
*w8001
= serio_get_drvdata(serio
);
95 struct input_dev
*dev
= w8001
->dev
;
96 struct w8001_coord coord
;
99 w8001
->data
[w8001
->idx
] = data
;
100 switch (w8001
->idx
++) {
102 if ((data
& W8001_LEAD_MASK
) != W8001_LEAD_BYTE
) {
103 pr_debug("w8001: unsynchronized data: 0x%02x\n", data
);
109 tmp
= w8001
->data
[0] & W8001_TAB_MASK
;
110 if (unlikely(tmp
== W8001_TAB_BYTE
))
114 parse_data(w8001
->data
, &coord
);
115 input_report_abs(dev
, ABS_X
, coord
.x
);
116 input_report_abs(dev
, ABS_Y
, coord
.y
);
117 input_report_abs(dev
, ABS_PRESSURE
, coord
.pen_pressure
);
118 input_report_key(dev
, BTN_TOUCH
, coord
.tsw
);
124 memcpy(w8001
->response
, w8001
->data
, W8001_MAX_LENGTH
);
125 w8001
->response_type
= W8001_QUERY_PACKET
;
126 complete(&w8001
->cmd_done
);
133 static int w8001_command(struct w8001
*w8001
, unsigned char command
,
138 w8001
->response_type
= 0;
139 init_completion(&w8001
->cmd_done
);
141 rc
= serio_write(w8001
->serio
, command
);
142 if (rc
== 0 && wait_response
) {
144 wait_for_completion_timeout(&w8001
->cmd_done
, HZ
);
145 if (w8001
->response_type
!= W8001_QUERY_PACKET
)
152 static int w8001_setup(struct w8001
*w8001
)
154 struct input_dev
*dev
= w8001
->dev
;
155 struct w8001_coord coord
;
158 error
= w8001_command(w8001
, W8001_CMD_QUERY
, true);
162 parse_data(w8001
->response
, &coord
);
164 input_set_abs_params(dev
, ABS_X
, 0, coord
.x
, 0, 0);
165 input_set_abs_params(dev
, ABS_Y
, 0, coord
.y
, 0, 0);
166 input_set_abs_params(dev
, ABS_PRESSURE
, 0, coord
.pen_pressure
, 0, 0);
167 input_set_abs_params(dev
, ABS_TILT_X
, 0, coord
.tilt_x
, 0, 0);
168 input_set_abs_params(dev
, ABS_TILT_Y
, 0, coord
.tilt_y
, 0, 0);
170 return w8001_command(w8001
, W8001_CMD_START
, false);
174 * w8001_disconnect() is the opposite of w8001_connect()
177 static void w8001_disconnect(struct serio
*serio
)
179 struct w8001
*w8001
= serio_get_drvdata(serio
);
181 input_get_device(w8001
->dev
);
182 input_unregister_device(w8001
->dev
);
184 serio_set_drvdata(serio
, NULL
);
185 input_put_device(w8001
->dev
);
190 * w8001_connect() is the routine that is called when someone adds a
191 * new serio device that supports the w8001 protocol and registers it as
195 static int w8001_connect(struct serio
*serio
, struct serio_driver
*drv
)
198 struct input_dev
*input_dev
;
201 w8001
= kzalloc(sizeof(struct w8001
), GFP_KERNEL
);
202 input_dev
= input_allocate_device();
203 if (!w8001
|| !input_dev
) {
208 w8001
->serio
= serio
;
209 w8001
->id
= serio
->id
.id
;
210 w8001
->dev
= input_dev
;
211 init_completion(&w8001
->cmd_done
);
212 snprintf(w8001
->phys
, sizeof(w8001
->phys
), "%s/input0", serio
->phys
);
214 input_dev
->name
= "Wacom W8001 Penabled Serial TouchScreen";
215 input_dev
->phys
= w8001
->phys
;
216 input_dev
->id
.bustype
= BUS_RS232
;
217 input_dev
->id
.vendor
= SERIO_W8001
;
218 input_dev
->id
.product
= w8001
->id
;
219 input_dev
->id
.version
= 0x0100;
220 input_dev
->dev
.parent
= &serio
->dev
;
222 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
223 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
225 serio_set_drvdata(serio
, w8001
);
226 err
= serio_open(serio
, drv
);
230 err
= w8001_setup(w8001
);
234 err
= input_register_device(w8001
->dev
);
243 serio_set_drvdata(serio
, NULL
);
245 input_free_device(input_dev
);
250 static struct serio_device_id w8001_serio_ids
[] = {
253 .proto
= SERIO_W8001
,
260 MODULE_DEVICE_TABLE(serio
, w8001_serio_ids
);
262 static struct serio_driver w8001_drv
= {
266 .description
= DRIVER_DESC
,
267 .id_table
= w8001_serio_ids
,
268 .interrupt
= w8001_interrupt
,
269 .connect
= w8001_connect
,
270 .disconnect
= w8001_disconnect
,
273 static int __init
w8001_init(void)
275 return serio_register_driver(&w8001_drv
);
278 static void __exit
w8001_exit(void)
280 serio_unregister_driver(&w8001_drv
);
283 module_init(w8001_init
);
284 module_exit(w8001_exit
);