127
vsxxxaa_drop_bytes (struct vsxxxaa *mouse, int num)
127
static void vsxxxaa_drop_bytes(struct vsxxxaa *mouse, int num)
129
if (num >= mouse->count)
129
if (num >= mouse->count) {
130
130
mouse->count = 0;
132
memmove (mouse->buf, mouse->buf + num - 1, BUFLEN - num);
132
memmove(mouse->buf, mouse->buf + num - 1, BUFLEN - num);
133
133
mouse->count -= num;
138
vsxxxaa_queue_byte (struct vsxxxaa *mouse, unsigned char byte)
137
static void vsxxxaa_queue_byte(struct vsxxxaa *mouse, unsigned char byte)
140
139
if (mouse->count == BUFLEN) {
141
printk (KERN_ERR "%s on %s: Dropping a byte of full buffer.\n",
142
mouse->name, mouse->phys);
143
vsxxxaa_drop_bytes (mouse, 1);
140
printk(KERN_ERR "%s on %s: Dropping a byte of full buffer.\n",
141
mouse->name, mouse->phys);
142
vsxxxaa_drop_bytes(mouse, 1);
145
DBG (KERN_INFO "Queueing byte 0x%02x\n", byte);
145
DBG(KERN_INFO "Queueing byte 0x%02x\n", byte);
147
147
mouse->buf[mouse->count++] = byte;
151
vsxxxaa_detection_done (struct vsxxxaa *mouse)
150
static void vsxxxaa_detection_done(struct vsxxxaa *mouse)
153
152
switch (mouse->type) {
155
strlcpy (mouse->name, "DEC VSXXX-AA/-GA mouse",
156
sizeof (mouse->name));
160
strlcpy (mouse->name, "DEC VSXXX-AB digitizer",
161
sizeof (mouse->name));
165
snprintf (mouse->name, sizeof (mouse->name),
166
"unknown DEC pointer device (type = 0x%02x)",
154
strlcpy(mouse->name, "DEC VSXXX-AA/-GA mouse",
155
sizeof(mouse->name));
159
strlcpy(mouse->name, "DEC VSXXX-AB digitizer",
160
sizeof(mouse->name));
164
snprintf(mouse->name, sizeof(mouse->name),
165
"unknown DEC pointer device (type = 0x%02x)",
172
171
"Found %s version 0x%02x from country 0x%02x on port %s\n",
173
172
mouse->name, mouse->version, mouse->country, mouse->phys);
177
176
* Returns number of bytes to be dropped, 0 if packet is okay.
180
vsxxxaa_check_packet (struct vsxxxaa *mouse, int packet_len)
178
static int vsxxxaa_check_packet(struct vsxxxaa *mouse, int packet_len)
184
182
/* First byte must be a header byte */
185
if (!IS_HDR_BYTE (mouse->buf[0])) {
186
DBG ("vsck: len=%d, 1st=0x%02x\n", packet_len, mouse->buf[0]);
183
if (!IS_HDR_BYTE(mouse->buf[0])) {
184
DBG("vsck: len=%d, 1st=0x%02x\n", packet_len, mouse->buf[0]);
190
188
/* Check all following bytes */
191
if (packet_len > 1) {
192
for (i = 1; i < packet_len; i++) {
193
if (IS_HDR_BYTE (mouse->buf[i])) {
194
printk (KERN_ERR "Need to drop %d bytes "
195
"of a broken packet.\n",
197
DBG (KERN_INFO "check: len=%d, b[%d]=0x%02x\n",
198
packet_len, i, mouse->buf[i]);
189
for (i = 1; i < packet_len; i++) {
190
if (IS_HDR_BYTE(mouse->buf[i])) {
192
"Need to drop %d bytes of a broken packet.\n",
194
DBG(KERN_INFO "check: len=%d, b[%d]=0x%02x\n",
195
packet_len, i, mouse->buf[i]);
207
static __inline__ int
208
vsxxxaa_smells_like_packet (struct vsxxxaa *mouse, unsigned char type, size_t len)
203
static inline int vsxxxaa_smells_like_packet(struct vsxxxaa *mouse,
204
unsigned char type, size_t len)
210
return (mouse->count >= len) && MATCH_PACKET_TYPE (mouse->buf[0], type);
206
return mouse->count >= len && MATCH_PACKET_TYPE(mouse->buf[0], type);
214
vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse)
209
static void vsxxxaa_handle_REL_packet(struct vsxxxaa *mouse)
216
211
struct input_dev *dev = mouse->dev;
217
212
unsigned char *buf = mouse->buf;
232
227
* 0, bit 4 of byte 0 is direction.
234
229
dx = buf[1] & 0x7f;
235
dx *= ((buf[0] >> 4) & 0x01)? 1: -1;
230
dx *= ((buf[0] >> 4) & 0x01) ? 1 : -1;
238
233
* Low 7 bit of byte 2 are abs(dy), bit 7 is
239
234
* 0, bit 3 of byte 0 is direction.
241
236
dy = buf[2] & 0x7f;
242
dy *= ((buf[0] >> 3) & 0x01)? -1: 1;
237
dy *= ((buf[0] >> 3) & 0x01) ? -1 : 1;
245
240
* Get button state. It's the low three bits
246
241
* (for three buttons) of byte 0.
248
left = (buf[0] & 0x04)? 1: 0;
249
middle = (buf[0] & 0x02)? 1: 0;
250
right = (buf[0] & 0x01)? 1: 0;
252
vsxxxaa_drop_bytes (mouse, 3);
254
DBG (KERN_INFO "%s on %s: dx=%d, dy=%d, buttons=%s%s%s\n",
255
mouse->name, mouse->phys, dx, dy,
256
left? "L": "l", middle? "M": "m", right? "R": "r");
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",
250
mouse->name, mouse->phys, dx, dy,
251
left ? "L" : "l", middle ? "M" : "m", right ? "R" : "r");
259
254
* Report what we've found so far...
261
input_report_key (dev, BTN_LEFT, left);
262
input_report_key (dev, BTN_MIDDLE, middle);
263
input_report_key (dev, BTN_RIGHT, right);
264
input_report_key (dev, BTN_TOUCH, 0);
265
input_report_rel (dev, REL_X, dx);
266
input_report_rel (dev, REL_Y, dy);
256
input_report_key(dev, BTN_LEFT, left);
257
input_report_key(dev, BTN_MIDDLE, middle);
258
input_report_key(dev, BTN_RIGHT, right);
259
input_report_key(dev, BTN_TOUCH, 0);
260
input_report_rel(dev, REL_X, dx);
261
input_report_rel(dev, REL_Y, dy);
271
vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse)
265
static void vsxxxaa_handle_ABS_packet(struct vsxxxaa *mouse)
273
267
struct input_dev *dev = mouse->dev;
274
268
unsigned char *buf = mouse->buf;
297
291
* Get button state. It's bits <4..1> of byte 0.
299
left = (buf[0] & 0x02)? 1: 0;
300
middle = (buf[0] & 0x04)? 1: 0;
301
right = (buf[0] & 0x08)? 1: 0;
302
touch = (buf[0] & 0x10)? 1: 0;
304
vsxxxaa_drop_bytes (mouse, 5);
306
DBG (KERN_INFO "%s on %s: x=%d, y=%d, buttons=%s%s%s%s\n",
307
mouse->name, mouse->phys, x, y,
308
left? "L": "l", middle? "M": "m",
309
right? "R": "r", touch? "T": "t");
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",
301
mouse->name, mouse->phys, x, y,
302
left ? "L" : "l", middle ? "M" : "m",
303
right ? "R" : "r", touch ? "T" : "t");
312
306
* Report what we've found so far...
314
input_report_key (dev, BTN_LEFT, left);
315
input_report_key (dev, BTN_MIDDLE, middle);
316
input_report_key (dev, BTN_RIGHT, right);
317
input_report_key (dev, BTN_TOUCH, touch);
318
input_report_abs (dev, ABS_X, x);
319
input_report_abs (dev, ABS_Y, y);
308
input_report_key(dev, BTN_LEFT, left);
309
input_report_key(dev, BTN_MIDDLE, middle);
310
input_report_key(dev, BTN_RIGHT, right);
311
input_report_key(dev, BTN_TOUCH, touch);
312
input_report_abs(dev, ABS_X, x);
313
input_report_abs(dev, ABS_Y, y);
324
vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse)
317
static void vsxxxaa_handle_POR_packet(struct vsxxxaa *mouse)
326
319
struct input_dev *dev = mouse->dev;
327
320
unsigned char *buf = mouse->buf;
356
349
* (for three buttons) of byte 0. Maybe even the bit <3>
357
350
* has some meaning if a tablet is attached.
359
left = (buf[0] & 0x04)? 1: 0;
360
middle = (buf[0] & 0x02)? 1: 0;
361
right = (buf[0] & 0x01)? 1: 0;
352
left = buf[0] & 0x04;
353
middle = buf[0] & 0x02;
354
right = buf[0] & 0x01;
363
vsxxxaa_drop_bytes (mouse, 4);
364
vsxxxaa_detection_done (mouse);
356
vsxxxaa_drop_bytes(mouse, 4);
357
vsxxxaa_detection_done(mouse);
366
359
if (error <= 0x1f) {
367
360
/* No (serious) error. Report buttons */
368
input_report_key (dev, BTN_LEFT, left);
369
input_report_key (dev, BTN_MIDDLE, middle);
370
input_report_key (dev, BTN_RIGHT, right);
371
input_report_key (dev, BTN_TOUCH, 0);
361
input_report_key(dev, BTN_LEFT, left);
362
input_report_key(dev, BTN_MIDDLE, middle);
363
input_report_key(dev, BTN_RIGHT, right);
364
input_report_key(dev, BTN_TOUCH, 0);
375
printk (KERN_INFO "Your %s on %s reports error=0x%02x\n",
376
mouse->name, mouse->phys, error);
368
printk(KERN_INFO "Your %s on %s reports error=0x%02x\n",
369
mouse->name, mouse->phys, error);
409
402
* activity on the mouse.
411
404
while (mouse->count > 0 && !IS_HDR_BYTE(buf[0])) {
412
printk (KERN_ERR "%s on %s: Dropping a byte to regain "
413
"sync with mouse data stream...\n",
414
mouse->name, mouse->phys);
415
vsxxxaa_drop_bytes (mouse, 1);
405
printk(KERN_ERR "%s on %s: Dropping a byte to regain "
406
"sync with mouse data stream...\n",
407
mouse->name, mouse->phys);
408
vsxxxaa_drop_bytes(mouse, 1);
419
412
* Check for packets we know about.
422
if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_REL, 3)) {
423
/* Check for broken packet */
424
stray_bytes = vsxxxaa_check_packet (mouse, 3);
425
if (stray_bytes > 0) {
426
printk (KERN_ERR "Dropping %d bytes now...\n",
428
vsxxxaa_drop_bytes (mouse, stray_bytes);
432
vsxxxaa_handle_REL_packet (mouse);
433
continue; /* More to parse? */
436
if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_ABS, 5)) {
437
/* Check for broken packet */
438
stray_bytes = vsxxxaa_check_packet (mouse, 5);
439
if (stray_bytes > 0) {
440
printk (KERN_ERR "Dropping %d bytes now...\n",
442
vsxxxaa_drop_bytes (mouse, stray_bytes);
446
vsxxxaa_handle_ABS_packet (mouse);
447
continue; /* More to parse? */
450
if (vsxxxaa_smells_like_packet (mouse, VSXXXAA_PACKET_POR, 4)) {
451
/* Check for broken packet */
452
stray_bytes = vsxxxaa_check_packet (mouse, 4);
453
if (stray_bytes > 0) {
454
printk (KERN_ERR "Dropping %d bytes now...\n",
456
vsxxxaa_drop_bytes (mouse, stray_bytes);
460
vsxxxaa_handle_POR_packet (mouse);
461
continue; /* More to parse? */
464
break; /* No REL, ABS or POR packet found */
415
if (vsxxxaa_smells_like_packet(mouse, VSXXXAA_PACKET_REL, 3)) {
416
/* Check for broken packet */
417
stray_bytes = vsxxxaa_check_packet(mouse, 3);
419
vsxxxaa_handle_REL_packet(mouse);
421
} else if (vsxxxaa_smells_like_packet(mouse,
422
VSXXXAA_PACKET_ABS, 5)) {
423
/* Check for broken packet */
424
stray_bytes = vsxxxaa_check_packet(mouse, 5);
426
vsxxxaa_handle_ABS_packet(mouse);
428
} else if (vsxxxaa_smells_like_packet(mouse,
429
VSXXXAA_PACKET_POR, 4)) {
430
/* Check for broken packet */
431
stray_bytes = vsxxxaa_check_packet(mouse, 4);
433
vsxxxaa_handle_POR_packet(mouse);
436
break; /* No REL, ABS or POR packet found */
439
if (stray_bytes > 0) {
440
printk(KERN_ERR "Dropping %d bytes now...\n",
442
vsxxxaa_drop_bytes(mouse, stray_bytes);
469
vsxxxaa_interrupt (struct serio *serio, unsigned char data, unsigned int flags)
448
static irqreturn_t vsxxxaa_interrupt(struct serio *serio,
449
unsigned char data, unsigned int flags)
471
struct vsxxxaa *mouse = serio_get_drvdata (serio);
451
struct vsxxxaa *mouse = serio_get_drvdata(serio);
473
vsxxxaa_queue_byte (mouse, data);
474
vsxxxaa_parse_buffer (mouse);
453
vsxxxaa_queue_byte(mouse, data);
454
vsxxxaa_parse_buffer(mouse);
476
456
return IRQ_HANDLED;
480
vsxxxaa_disconnect (struct serio *serio)
459
static void vsxxxaa_disconnect(struct serio *serio)
482
struct vsxxxaa *mouse = serio_get_drvdata (serio);
461
struct vsxxxaa *mouse = serio_get_drvdata(serio);
485
serio_set_drvdata (serio, NULL);
486
input_unregister_device (mouse->dev);
464
serio_set_drvdata(serio, NULL);
465
input_unregister_device(mouse->dev);
491
vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
469
static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv)
493
471
struct vsxxxaa *mouse;
494
472
struct input_dev *input_dev;
495
473
int err = -ENOMEM;
497
mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL);
498
input_dev = input_allocate_device ();
475
mouse = kzalloc(sizeof(struct vsxxxaa), GFP_KERNEL);
476
input_dev = input_allocate_device();
499
477
if (!mouse || !input_dev)
502
480
mouse->dev = input_dev;
503
481
mouse->serio = serio;
504
strlcat (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
505
sizeof (mouse->name));
506
snprintf (mouse->phys, sizeof (mouse->phys), "%s/input0", serio->phys);
482
strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
483
sizeof(mouse->name));
484
snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys);
508
486
input_dev->name = mouse->name;
509
487
input_dev->phys = mouse->phys;
510
488
input_dev->id.bustype = BUS_RS232;
511
489
input_dev->dev.parent = &serio->dev;
513
set_bit (EV_KEY, input_dev->evbit); /* We have buttons */
514
set_bit (EV_REL, input_dev->evbit);
515
set_bit (EV_ABS, input_dev->evbit);
516
set_bit (BTN_LEFT, input_dev->keybit); /* We have 3 buttons */
517
set_bit (BTN_MIDDLE, input_dev->keybit);
518
set_bit (BTN_RIGHT, input_dev->keybit);
519
set_bit (BTN_TOUCH, input_dev->keybit); /* ...and Tablet */
520
set_bit (REL_X, input_dev->relbit);
521
set_bit (REL_Y, input_dev->relbit);
522
input_set_abs_params (input_dev, ABS_X, 0, 1023, 0, 0);
523
input_set_abs_params (input_dev, ABS_Y, 0, 1023, 0, 0);
525
serio_set_drvdata (serio, mouse);
527
err = serio_open (serio, drv);
491
__set_bit(EV_KEY, input_dev->evbit); /* We have buttons */
492
__set_bit(EV_REL, input_dev->evbit);
493
__set_bit(EV_ABS, input_dev->evbit);
494
__set_bit(BTN_LEFT, input_dev->keybit); /* We have 3 buttons */
495
__set_bit(BTN_MIDDLE, input_dev->keybit);
496
__set_bit(BTN_RIGHT, input_dev->keybit);
497
__set_bit(BTN_TOUCH, input_dev->keybit); /* ...and Tablet */
498
__set_bit(REL_X, input_dev->relbit);
499
__set_bit(REL_Y, input_dev->relbit);
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);
505
err = serio_open(serio, drv);