80 #include <linux/module.h>
81 #include <linux/slab.h>
83 #include <linux/input.h>
84 #include <linux/serio.h>
87 #define DRIVER_DESC "Driver for DEC VSXXX-AA and -GA mice and VSXXX-AB tablet"
95 #define DBG(x...) printk(x)
97 #define DBG(x...) do {} while (0)
100 #define VSXXXAA_INTRO_MASK 0x80
101 #define VSXXXAA_INTRO_HEAD 0x80
102 #define IS_HDR_BYTE(x) \
103 (((x) & VSXXXAA_INTRO_MASK) == VSXXXAA_INTRO_HEAD)
105 #define VSXXXAA_PACKET_MASK 0xe0
106 #define VSXXXAA_PACKET_REL 0x80
107 #define VSXXXAA_PACKET_ABS 0xc0
108 #define VSXXXAA_PACKET_POR 0xa0
109 #define MATCH_PACKET_TYPE(data, type) \
110 (((data) & VSXXXAA_PACKET_MASK) == (type))
127 static void vsxxxaa_drop_bytes(
struct vsxxxaa *mouse,
int num)
129 if (num >= mouse->
count) {
137 static void vsxxxaa_queue_byte(
struct vsxxxaa *mouse,
unsigned char byte)
142 vsxxxaa_drop_bytes(mouse, 1);
150 static void vsxxxaa_detection_done(
struct vsxxxaa *mouse)
152 switch (mouse->
type) {
155 sizeof(mouse->
name));
160 sizeof(mouse->
name));
165 "unknown DEC pointer device (type = 0x%02x)",
171 "Found %s version 0x%02x from country 0x%02x on port %s\n",
178 static int vsxxxaa_check_packet(
struct vsxxxaa *mouse,
int packet_len)
184 DBG(
"vsck: len=%d, 1st=0x%02x\n", packet_len, mouse->
buf[0]);
189 for (i = 1; i < packet_len; i++) {
192 "Need to drop %d bytes of a broken packet.\n",
195 packet_len, i, mouse->
buf[i]);
203 static inline int vsxxxaa_smells_like_packet(
struct vsxxxaa *mouse,
204 unsigned char type,
size_t len)
209 static void vsxxxaa_handle_REL_packet(
struct vsxxxaa *mouse)
211 struct input_dev *
dev = mouse->
dev;
212 unsigned char *
buf = mouse->
buf;
230 dx *= ((buf[0] >> 4) & 0x01) ? 1 : -1;
237 dy *= ((buf[0] >> 3) & 0x01) ? -1 : 1;
243 left = buf[0] & 0x04;
244 middle = buf[0] & 0x02;
245 right = buf[0] & 0x01;
247 vsxxxaa_drop_bytes(mouse, 3);
249 DBG(
KERN_INFO "%s on %s: dx=%d, dy=%d, buttons=%s%s%s\n",
251 left ?
"L" :
"l", middle ?
"M" :
"m", right ?
"R" :
"r");
256 input_report_key(dev,
BTN_LEFT, left);
260 input_report_rel(dev,
REL_X, dx);
261 input_report_rel(dev,
REL_Y, dy);
265 static void vsxxxaa_handle_ABS_packet(
struct vsxxxaa *mouse)
267 struct input_dev *
dev = mouse->
dev;
268 unsigned char *
buf = mouse->
buf;
286 x = ((buf[2] & 0x3f) << 6) | (buf[1] & 0x3f);
287 y = ((buf[4] & 0x3f) << 6) | (buf[3] & 0x3f);
293 left = buf[0] & 0x02;
294 middle = buf[0] & 0x04;
295 right = buf[0] & 0x08;
296 touch = buf[0] & 0x10;
298 vsxxxaa_drop_bytes(mouse, 5);
300 DBG(
KERN_INFO "%s on %s: x=%d, y=%d, buttons=%s%s%s%s\n",
302 left ?
"L" :
"l", middle ?
"M" :
"m",
303 right ?
"R" :
"r", touch ?
"T" :
"t");
308 input_report_key(dev,
BTN_LEFT, left);
312 input_report_abs(dev,
ABS_X, x);
313 input_report_abs(dev,
ABS_Y, y);
317 static void vsxxxaa_handle_POR_packet(
struct vsxxxaa *mouse)
319 struct input_dev *
dev = mouse->
dev;
320 unsigned char *
buf = mouse->
buf;
342 mouse->
version = buf[0] & 0x0f;
343 mouse->
country = (buf[1] >> 4) & 0x07;
344 mouse->
type = buf[1] & 0x0f;
345 error = buf[2] & 0x7f;
352 left = buf[0] & 0x04;
353 middle = buf[0] & 0x02;
354 right = buf[0] & 0x01;
356 vsxxxaa_drop_bytes(mouse, 4);
357 vsxxxaa_detection_done(mouse);
361 input_report_key(dev,
BTN_LEFT, left);
378 "%s on %s: Forcing standard packet format, "
379 "incremental streaming mode and 72 samples/sec\n",
381 serio_write(mouse->
serio,
'S');
383 serio_write(mouse->
serio,
'R');
385 serio_write(mouse->
serio,
'L');
388 static void vsxxxaa_parse_buffer(
struct vsxxxaa *mouse)
390 unsigned char *buf = mouse->
buf;
406 "sync with mouse data stream...\n",
408 vsxxxaa_drop_bytes(mouse, 1);
417 stray_bytes = vsxxxaa_check_packet(mouse, 3);
419 vsxxxaa_handle_REL_packet(mouse);
421 }
else if (vsxxxaa_smells_like_packet(mouse,
424 stray_bytes = vsxxxaa_check_packet(mouse, 5);
426 vsxxxaa_handle_ABS_packet(mouse);
428 }
else if (vsxxxaa_smells_like_packet(mouse,
431 stray_bytes = vsxxxaa_check_packet(mouse, 4);
433 vsxxxaa_handle_POR_packet(mouse);
439 if (stray_bytes > 0) {
442 vsxxxaa_drop_bytes(mouse, stray_bytes);
451 struct vsxxxaa *mouse = serio_get_drvdata(serio);
453 vsxxxaa_queue_byte(mouse, data);
454 vsxxxaa_parse_buffer(mouse);
459 static void vsxxxaa_disconnect(
struct serio *
serio)
461 struct vsxxxaa *mouse = serio_get_drvdata(serio);
464 serio_set_drvdata(serio,
NULL);
465 input_unregister_device(mouse->
dev);
472 struct input_dev *input_dev;
476 input_dev = input_allocate_device();
477 if (!mouse || !input_dev)
480 mouse->
dev = input_dev;
481 mouse->
serio = serio;
482 strlcat(mouse->
name,
"DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
483 sizeof(mouse->
name));
486 input_dev->name = mouse->
name;
487 input_dev->phys = mouse->
phys;
489 input_dev->dev.parent = &serio->
dev;
500 input_set_abs_params(input_dev,
ABS_X, 0, 1023, 0, 0);
501 input_set_abs_params(input_dev,
ABS_Y, 0, 1023, 0, 0);
503 serio_set_drvdata(serio, mouse);
513 serio_write(serio,
'T');
515 err = input_register_device(input_dev);
522 fail2: serio_set_drvdata(serio,
NULL);
523 fail1: input_free_device(input_dev);
545 .id_table = vsxxaa_serio_ids,
546 .connect = vsxxxaa_connect,
547 .interrupt = vsxxxaa_interrupt,
548 .disconnect = vsxxxaa_disconnect,