aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet/wacom_sys.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/tablet/wacom_sys.c')
-rw-r--r--drivers/input/tablet/wacom_sys.c231
1 files changed, 158 insertions, 73 deletions
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index ea30c983a33e..072f33b3b2b0 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/input/tablet/wacom_sys.c 2 * drivers/input/tablet/wacom_sys.c
3 * 3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - system specific code 4 * USB Wacom tablet support - system specific code
5 */ 5 */
6 6
7/* 7/*
@@ -209,6 +209,7 @@ void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
209 input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) | 209 input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
210 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); 210 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
211 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) | 211 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
212 BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) |
212 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2); 213 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2);
213 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0); 214 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
214} 215}
@@ -256,6 +257,7 @@ void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
256 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) | 257 BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) |
257 BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA); 258 BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
258 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) | 259 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
260 BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) |
259 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) | 261 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) |
260 BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) | 262 BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) |
261 BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2); 263 BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2);
@@ -269,7 +271,8 @@ void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
269 271
270void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 272void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
271{ 273{
272 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_STYLUS2); 274 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) |
275 BIT_MASK(BTN_STYLUS) | BIT_MASK(BTN_STYLUS2);
273} 276}
274 277
275void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 278void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
@@ -277,12 +280,32 @@ void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
277 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER); 280 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER);
278} 281}
279 282
283void input_dev_tpc(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
284{
285 if (wacom_wac->features->device_type == BTN_TOOL_DOUBLETAP ||
286 wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) {
287 input_set_abs_params(input_dev, ABS_RX, 0, wacom_wac->features->x_phy, 0, 0);
288 input_set_abs_params(input_dev, ABS_RY, 0, wacom_wac->features->y_phy, 0, 0);
289 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP);
290 }
291}
292
293void input_dev_tpc2fg(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
294{
295 if (wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) {
296 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_TRIPLETAP);
297 input_dev->evbit[0] |= BIT_MASK(EV_MSC);
298 input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
299 }
300}
301
280static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, 302static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
281 struct wacom_wac *wacom_wac) 303 struct wacom_features *features)
282{ 304{
283 struct usb_device *dev = interface_to_usbdev(intf); 305 struct usb_device *dev = interface_to_usbdev(intf);
284 struct wacom_features *features = wacom_wac->features; 306 char limit = 0;
285 char limit = 0, result = 0; 307 /* result has to be defined as int for some devices */
308 int result = 0;
286 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0; 309 int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
287 unsigned char *report; 310 unsigned char *report;
288 311
@@ -328,13 +351,24 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
328 case HID_USAGE_X: 351 case HID_USAGE_X:
329 if (usage == WCM_DESKTOP) { 352 if (usage == WCM_DESKTOP) {
330 if (finger) { 353 if (finger) {
331 features->touch_x_max = 354 features->device_type = BTN_TOOL_DOUBLETAP;
332 features->touch_y_max = 355 if (features->type == TABLETPC2FG) {
333 wacom_le16_to_cpu(&report[i + 3]); 356 /* need to reset back */
357 features->pktlen = WACOM_PKGLEN_TPC2FG;
358 features->device_type = BTN_TOOL_TRIPLETAP;
359 }
334 features->x_max = 360 features->x_max =
361 wacom_le16_to_cpu(&report[i + 3]);
362 features->x_phy =
335 wacom_le16_to_cpu(&report[i + 6]); 363 wacom_le16_to_cpu(&report[i + 6]);
336 i += 7; 364 features->unit = report[i + 9];
365 features->unitExpo = report[i + 11];
366 i += 12;
337 } else if (pen) { 367 } else if (pen) {
368 /* penabled only accepts exact bytes of data */
369 if (features->type == TABLETPC2FG)
370 features->pktlen = WACOM_PKGLEN_PENABLED;
371 features->device_type = BTN_TOOL_PEN;
338 features->x_max = 372 features->x_max =
339 wacom_le16_to_cpu(&report[i + 3]); 373 wacom_le16_to_cpu(&report[i + 3]);
340 i += 4; 374 i += 4;
@@ -350,10 +384,35 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
350 break; 384 break;
351 385
352 case HID_USAGE_Y: 386 case HID_USAGE_Y:
353 if (usage == WCM_DESKTOP) 387 if (usage == WCM_DESKTOP) {
354 features->y_max = 388 if (finger) {
355 wacom_le16_to_cpu(&report[i + 3]); 389 features->device_type = BTN_TOOL_DOUBLETAP;
356 i += 4; 390 if (features->type == TABLETPC2FG) {
391 /* need to reset back */
392 features->pktlen = WACOM_PKGLEN_TPC2FG;
393 features->device_type = BTN_TOOL_TRIPLETAP;
394 features->y_max =
395 wacom_le16_to_cpu(&report[i + 3]);
396 features->y_phy =
397 wacom_le16_to_cpu(&report[i + 6]);
398 i += 7;
399 } else {
400 features->y_max =
401 features->x_max;
402 features->y_phy =
403 wacom_le16_to_cpu(&report[i + 3]);
404 i += 4;
405 }
406 } else if (pen) {
407 /* penabled only accepts exact bytes of data */
408 if (features->type == TABLETPC2FG)
409 features->pktlen = WACOM_PKGLEN_PENABLED;
410 features->device_type = BTN_TOOL_PEN;
411 features->y_max =
412 wacom_le16_to_cpu(&report[i + 3]);
413 i += 4;
414 }
415 }
357 break; 416 break;
358 417
359 case HID_USAGE_FINGER: 418 case HID_USAGE_FINGER:
@@ -376,7 +435,7 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
376 break; 435 break;
377 436
378 case HID_COLLECTION: 437 case HID_COLLECTION:
379 /* reset UsagePage ans Finger */ 438 /* reset UsagePage and Finger */
380 finger = usage = 0; 439 finger = usage = 0;
381 break; 440 break;
382 } 441 }
@@ -388,43 +447,92 @@ static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hi
388 return result; 447 return result;
389} 448}
390 449
391static int wacom_query_tablet_data(struct usb_interface *intf) 450static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
392{ 451{
393 unsigned char *rep_data; 452 unsigned char *rep_data;
394 int limit = 0; 453 int limit = 0, report_id = 2;
395 int error; 454 int error = -ENOMEM;
396 455
397 rep_data = kmalloc(2, GFP_KERNEL); 456 rep_data = kmalloc(2, GFP_KERNEL);
398 if (!rep_data) 457 if (!rep_data)
399 return -ENOMEM; 458 return error;
400 459
401 do { 460 /* ask to report tablet data if it is 2FGT or not a Tablet PC */
402 rep_data[0] = 2; 461 if (features->device_type == BTN_TOOL_TRIPLETAP) {
403 rep_data[1] = 2; 462 do {
404 error = usb_set_report(intf, WAC_HID_FEATURE_REPORT, 463 rep_data[0] = 3;
405 2, rep_data, 2); 464 rep_data[1] = 4;
406 if (error >= 0) 465 report_id = 3;
407 error = usb_get_report(intf, 466 error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
408 WAC_HID_FEATURE_REPORT, 2, 467 report_id, rep_data, 2);
409 rep_data, 2); 468 if (error >= 0)
410 } while ((error < 0 || rep_data[1] != 2) && limit++ < 5); 469 error = usb_get_report(intf,
470 WAC_HID_FEATURE_REPORT, report_id,
471 rep_data, 3);
472 } while ((error < 0 || rep_data[1] != 4) && limit++ < 5);
473 } else if (features->type != TABLETPC && features->type != TABLETPC2FG) {
474 do {
475 rep_data[0] = 2;
476 rep_data[1] = 2;
477 error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
478 report_id, rep_data, 2);
479 if (error >= 0)
480 error = usb_get_report(intf,
481 WAC_HID_FEATURE_REPORT, report_id,
482 rep_data, 2);
483 } while ((error < 0 || rep_data[1] != 2) && limit++ < 5);
484 }
411 485
412 kfree(rep_data); 486 kfree(rep_data);
413 487
414 return error < 0 ? error : 0; 488 return error < 0 ? error : 0;
415} 489}
416 490
491static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
492 struct wacom_features *features)
493{
494 int error = 0;
495 struct usb_host_interface *interface = intf->cur_altsetting;
496 struct hid_descriptor *hid_desc;
497
498 /* default device to penabled */
499 features->device_type = BTN_TOOL_PEN;
500
501 /* only Tablet PCs need to retrieve the info */
502 if ((features->type != TABLETPC) && (features->type != TABLETPC2FG))
503 goto out;
504
505 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
506 if (usb_get_extra_descriptor(&interface->endpoint[0],
507 HID_DEVICET_REPORT, &hid_desc)) {
508 printk("wacom: can not retrieve extra class descriptor\n");
509 error = 1;
510 goto out;
511 }
512 }
513 error = wacom_parse_hid(intf, hid_desc, features);
514 if (error)
515 goto out;
516
517 /* touch device found but size is not defined. use default */
518 if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) {
519 features->x_max = 1023;
520 features->y_max = 1023;
521 }
522
523 out:
524 return error;
525}
526
417static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) 527static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
418{ 528{
419 struct usb_device *dev = interface_to_usbdev(intf); 529 struct usb_device *dev = interface_to_usbdev(intf);
420 struct usb_host_interface *interface = intf->cur_altsetting;
421 struct usb_endpoint_descriptor *endpoint; 530 struct usb_endpoint_descriptor *endpoint;
422 struct wacom *wacom; 531 struct wacom *wacom;
423 struct wacom_wac *wacom_wac; 532 struct wacom_wac *wacom_wac;
424 struct wacom_features *features; 533 struct wacom_features *features;
425 struct input_dev *input_dev; 534 struct input_dev *input_dev;
426 int error = -ENOMEM; 535 int error = -ENOMEM;
427 struct hid_descriptor *hid_desc;
428 536
429 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); 537 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
430 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL); 538 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
@@ -432,7 +540,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
432 if (!wacom || !input_dev || !wacom_wac) 540 if (!wacom || !input_dev || !wacom_wac)
433 goto fail1; 541 goto fail1;
434 542
435 wacom_wac->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma); 543 wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX, GFP_KERNEL, &wacom->data_dma);
436 if (!wacom_wac->data) 544 if (!wacom_wac->data)
437 goto fail1; 545 goto fail1;
438 546
@@ -448,7 +556,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
448 strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); 556 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
449 557
450 wacom_wac->features = features = get_wacom_feature(id); 558 wacom_wac->features = features = get_wacom_feature(id);
451 BUG_ON(features->pktlen > 10); 559 BUG_ON(features->pktlen > WACOM_PKGLEN_MAX);
452 560
453 input_dev->name = wacom_wac->features->name; 561 input_dev->name = wacom_wac->features->name;
454 wacom->wacom_wac = wacom_wac; 562 wacom->wacom_wac = wacom_wac;
@@ -463,47 +571,24 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
463 571
464 endpoint = &intf->cur_altsetting->endpoint[0].desc; 572 endpoint = &intf->cur_altsetting->endpoint[0].desc;
465 573
466 /* Initialize touch_x_max and touch_y_max in case it is not defined */ 574 /* Retrieve the physical and logical size for OEM devices */
467 if (wacom_wac->features->type == TABLETPC) { 575 error = wacom_retrieve_hid_descriptor(intf, features);
468 features->touch_x_max = 1023; 576 if (error)
469 features->touch_y_max = 1023; 577 goto fail2;
470 } else {
471 features->touch_x_max = 0;
472 features->touch_y_max = 0;
473 }
474
475 /* TabletPC need to retrieve the physical and logical maximum from report descriptor */
476 if (wacom_wac->features->type == TABLETPC) {
477 if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
478 if (usb_get_extra_descriptor(&interface->endpoint[0],
479 HID_DEVICET_REPORT, &hid_desc)) {
480 printk("wacom: can not retrive extra class descriptor\n");
481 goto fail2;
482 }
483 }
484 error = wacom_parse_hid(intf, hid_desc, wacom_wac);
485 if (error)
486 goto fail2;
487 }
488 578
489 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 579 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
490 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) | 580 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH);
491 BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_STYLUS); 581
492 input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0); 582 input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);
493 input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0); 583 input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);
494 input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0); 584 input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);
495 if (features->type == TABLETPC) {
496 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP);
497 input_set_abs_params(input_dev, ABS_RX, 0, features->touch_x_max, 4, 0);
498 input_set_abs_params(input_dev, ABS_RY, 0, features->touch_y_max, 4, 0);
499 }
500 input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); 585 input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
501 586
502 wacom_init_input_dev(input_dev, wacom_wac); 587 wacom_init_input_dev(input_dev, wacom_wac);
503 588
504 usb_fill_int_urb(wacom->irq, dev, 589 usb_fill_int_urb(wacom->irq, dev,
505 usb_rcvintpipe(dev, endpoint->bEndpointAddress), 590 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
506 wacom_wac->data, wacom_wac->features->pktlen, 591 wacom_wac->data, features->pktlen,
507 wacom_sys_irq, wacom, endpoint->bInterval); 592 wacom_sys_irq, wacom, endpoint->bInterval);
508 wacom->irq->transfer_dma = wacom->data_dma; 593 wacom->irq->transfer_dma = wacom->data_dma;
509 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 594 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@@ -512,18 +597,14 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
512 if (error) 597 if (error)
513 goto fail3; 598 goto fail3;
514 599
515 /* 600 /* Note that if query fails it is not a hard failure */
516 * Ask the tablet to report tablet data if it is not a Tablet PC. 601 wacom_query_tablet_data(intf, features);
517 * Note that if query fails it is not a hard failure.
518 */
519 if (wacom_wac->features->type != TABLETPC)
520 wacom_query_tablet_data(intf);
521 602
522 usb_set_intfdata(intf, wacom); 603 usb_set_intfdata(intf, wacom);
523 return 0; 604 return 0;
524 605
525 fail3: usb_free_urb(wacom->irq); 606 fail3: usb_free_urb(wacom->irq);
526 fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma); 607 fail2: usb_buffer_free(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
527 fail1: input_free_device(input_dev); 608 fail1: input_free_device(input_dev);
528 kfree(wacom); 609 kfree(wacom);
529 kfree(wacom_wac); 610 kfree(wacom_wac);
@@ -539,7 +620,7 @@ static void wacom_disconnect(struct usb_interface *intf)
539 usb_kill_urb(wacom->irq); 620 usb_kill_urb(wacom->irq);
540 input_unregister_device(wacom->dev); 621 input_unregister_device(wacom->dev);
541 usb_free_urb(wacom->irq); 622 usb_free_urb(wacom->irq);
542 usb_buffer_free(interface_to_usbdev(intf), 10, 623 usb_buffer_free(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
543 wacom->wacom_wac->data, wacom->data_dma); 624 wacom->wacom_wac->data, wacom->data_dma);
544 kfree(wacom->wacom_wac); 625 kfree(wacom->wacom_wac);
545 kfree(wacom); 626 kfree(wacom);
@@ -559,12 +640,16 @@ static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
559static int wacom_resume(struct usb_interface *intf) 640static int wacom_resume(struct usb_interface *intf)
560{ 641{
561 struct wacom *wacom = usb_get_intfdata(intf); 642 struct wacom *wacom = usb_get_intfdata(intf);
643 struct wacom_features *features = wacom->wacom_wac->features;
562 int rv; 644 int rv;
563 645
564 mutex_lock(&wacom->lock); 646 mutex_lock(&wacom->lock);
565 if (wacom->open) 647 if (wacom->open) {
566 rv = usb_submit_urb(wacom->irq, GFP_NOIO); 648 rv = usb_submit_urb(wacom->irq, GFP_NOIO);
567 else 649 /* switch to wacom mode if needed */
650 if (!wacom_retrieve_hid_descriptor(intf, features))
651 wacom_query_tablet_data(intf, features);
652 } else
568 rv = 0; 653 rv = 0;
569 mutex_unlock(&wacom->lock); 654 mutex_unlock(&wacom->lock);
570 655