diff options
Diffstat (limited to 'drivers/hid/hid-waltop.c')
-rw-r--r-- | drivers/hid/hid-waltop.c | 230 |
1 files changed, 194 insertions, 36 deletions
diff --git a/drivers/hid/hid-waltop.c b/drivers/hid/hid-waltop.c index 2cfd95c4467b..745e4e9a8cf2 100644 --- a/drivers/hid/hid-waltop.c +++ b/drivers/hid/hid-waltop.c | |||
@@ -502,28 +502,146 @@ static __u8 media_tablet_14_1_inch_rdesc_fixed[] = { | |||
502 | 0xC0 /* End Collection */ | 502 | 0xC0 /* End Collection */ |
503 | }; | 503 | }; |
504 | 504 | ||
505 | struct waltop_state { | 505 | /* |
506 | u8 pressure0; | 506 | * See Sirius Battery Free Tablet description, device and HID report descriptors |
507 | u8 pressure1; | 507 | * at |
508 | * http://sf.net/apps/mediawiki/digimend/?title=Waltop_Sirius_Battery_Free_Tablet | ||
509 | */ | ||
510 | |||
511 | /* Size of the original report descriptor of Sirius Battery Free Tablet */ | ||
512 | #define SIRIUS_BATTERY_FREE_TABLET_RDESC_ORIG_SIZE 335 | ||
513 | |||
514 | /* Fixed Sirius Battery Free Tablet descriptor */ | ||
515 | static __u8 sirius_battery_free_tablet_rdesc_fixed[] = { | ||
516 | 0x05, 0x0D, /* Usage Page (Digitizer), */ | ||
517 | 0x09, 0x02, /* Usage (Pen), */ | ||
518 | 0xA1, 0x01, /* Collection (Application), */ | ||
519 | 0x85, 0x10, /* Report ID (16), */ | ||
520 | 0x09, 0x20, /* Usage (Stylus), */ | ||
521 | 0xA0, /* Collection (Physical), */ | ||
522 | 0x95, 0x01, /* Report Count (1), */ | ||
523 | 0x15, 0x01, /* Logical Minimum (1), */ | ||
524 | 0x25, 0x03, /* Logical Maximum (3), */ | ||
525 | 0x75, 0x02, /* Report Size (2), */ | ||
526 | 0x09, 0x42, /* Usage (Tip Switch), */ | ||
527 | 0x09, 0x44, /* Usage (Barrel Switch), */ | ||
528 | 0x09, 0x46, /* Usage (Tablet Pick), */ | ||
529 | 0x80, /* Input, */ | ||
530 | 0x14, /* Logical Minimum (0), */ | ||
531 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
532 | 0x75, 0x01, /* Report Size (1), */ | ||
533 | 0x09, 0x3C, /* Usage (Invert), */ | ||
534 | 0x81, 0x02, /* Input (Variable), */ | ||
535 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
536 | 0x09, 0x32, /* Usage (In Range), */ | ||
537 | 0x81, 0x02, /* Input (Variable), */ | ||
538 | 0x95, 0x03, /* Report Count (3), */ | ||
539 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
540 | 0xA4, /* Push, */ | ||
541 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
542 | 0x55, 0xFD, /* Unit Exponent (-3), */ | ||
543 | 0x65, 0x13, /* Unit (Inch), */ | ||
544 | 0x34, /* Physical Minimum (0), */ | ||
545 | 0x14, /* Logical Minimum (0), */ | ||
546 | 0x75, 0x10, /* Report Size (16), */ | ||
547 | 0x95, 0x01, /* Report Count (1), */ | ||
548 | 0x46, 0x10, 0x27, /* Physical Maximum (10000), */ | ||
549 | 0x26, 0x20, 0x4E, /* Logical Maximum (20000), */ | ||
550 | 0x09, 0x30, /* Usage (X), */ | ||
551 | 0x81, 0x02, /* Input (Variable), */ | ||
552 | 0x46, 0x70, 0x17, /* Physical Maximum (6000), */ | ||
553 | 0x26, 0xE0, 0x2E, /* Logical Maximum (12000), */ | ||
554 | 0x09, 0x31, /* Usage (Y), */ | ||
555 | 0x81, 0x02, /* Input (Variable), */ | ||
556 | 0xB4, /* Pop, */ | ||
557 | 0x75, 0x10, /* Report Size (16), */ | ||
558 | 0x95, 0x01, /* Report Count (1), */ | ||
559 | 0x14, /* Logical Minimum (0), */ | ||
560 | 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ | ||
561 | 0x09, 0x30, /* Usage (Tip Pressure), */ | ||
562 | 0x81, 0x02, /* Input (Variable), */ | ||
563 | 0xA4, /* Push, */ | ||
564 | 0x55, 0xFE, /* Unit Exponent (-2), */ | ||
565 | 0x65, 0x12, /* Unit (Radians), */ | ||
566 | 0x35, 0x97, /* Physical Minimum (-105), */ | ||
567 | 0x45, 0x69, /* Physical Maximum (105), */ | ||
568 | 0x15, 0x97, /* Logical Minimum (-105), */ | ||
569 | 0x25, 0x69, /* Logical Maximum (105), */ | ||
570 | 0x75, 0x08, /* Report Size (8), */ | ||
571 | 0x95, 0x02, /* Report Count (2), */ | ||
572 | 0x09, 0x3D, /* Usage (X Tilt), */ | ||
573 | 0x09, 0x3E, /* Usage (Y Tilt), */ | ||
574 | 0x81, 0x02, /* Input (Variable), */ | ||
575 | 0xB4, /* Pop, */ | ||
576 | 0xC0, /* End Collection, */ | ||
577 | 0xC0, /* End Collection, */ | ||
578 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
579 | 0x09, 0x02, /* Usage (Mouse), */ | ||
580 | 0xA1, 0x01, /* Collection (Application), */ | ||
581 | 0x85, 0x01, /* Report ID (1), */ | ||
582 | 0x09, 0x01, /* Usage (Pointer), */ | ||
583 | 0xA0, /* Collection (Physical), */ | ||
584 | 0x75, 0x08, /* Report Size (8), */ | ||
585 | 0x95, 0x03, /* Report Count (3), */ | ||
586 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
587 | 0x09, 0x38, /* Usage (Wheel), */ | ||
588 | 0x15, 0xFF, /* Logical Minimum (-1), */ | ||
589 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
590 | 0x75, 0x08, /* Report Size (8), */ | ||
591 | 0x95, 0x01, /* Report Count (1), */ | ||
592 | 0x81, 0x06, /* Input (Variable, Relative), */ | ||
593 | 0x75, 0x08, /* Report Size (8), */ | ||
594 | 0x95, 0x03, /* Report Count (3), */ | ||
595 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
596 | 0xC0, /* End Collection, */ | ||
597 | 0xC0, /* End Collection, */ | ||
598 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
599 | 0x09, 0x06, /* Usage (Keyboard), */ | ||
600 | 0xA1, 0x01, /* Collection (Application), */ | ||
601 | 0x85, 0x0D, /* Report ID (13), */ | ||
602 | 0x05, 0x07, /* Usage Page (Keyboard), */ | ||
603 | 0x19, 0xE0, /* Usage Minimum (KB Leftcontrol), */ | ||
604 | 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */ | ||
605 | 0x14, /* Logical Minimum (0), */ | ||
606 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
607 | 0x75, 0x01, /* Report Size (1), */ | ||
608 | 0x95, 0x08, /* Report Count (8), */ | ||
609 | 0x81, 0x02, /* Input (Variable), */ | ||
610 | 0x75, 0x08, /* Report Size (8), */ | ||
611 | 0x95, 0x01, /* Report Count (1), */ | ||
612 | 0x81, 0x01, /* Input (Constant), */ | ||
613 | 0x18, /* Usage Minimum (None), */ | ||
614 | 0x29, 0x65, /* Usage Maximum (KB Application), */ | ||
615 | 0x14, /* Logical Minimum (0), */ | ||
616 | 0x25, 0x65, /* Logical Maximum (101), */ | ||
617 | 0x75, 0x08, /* Report Size (8), */ | ||
618 | 0x95, 0x05, /* Report Count (5), */ | ||
619 | 0x80, /* Input, */ | ||
620 | 0xC0, /* End Collection, */ | ||
621 | 0x05, 0x0C, /* Usage Page (Consumer), */ | ||
622 | 0x09, 0x01, /* Usage (Consumer Control), */ | ||
623 | 0xA1, 0x01, /* Collection (Application), */ | ||
624 | 0x85, 0x0C, /* Report ID (12), */ | ||
625 | 0x09, 0xE9, /* Usage (Volume Inc), */ | ||
626 | 0x09, 0xEA, /* Usage (Volume Dec), */ | ||
627 | 0x14, /* Logical Minimum (0), */ | ||
628 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
629 | 0x75, 0x01, /* Report Size (1), */ | ||
630 | 0x95, 0x02, /* Report Count (2), */ | ||
631 | 0x81, 0x02, /* Input (Variable), */ | ||
632 | 0x75, 0x06, /* Report Size (6), */ | ||
633 | 0x95, 0x01, /* Report Count (1), */ | ||
634 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
635 | 0x75, 0x10, /* Report Size (16), */ | ||
636 | 0x95, 0x03, /* Report Count (3), */ | ||
637 | 0x81, 0x03, /* Input (Constant, Variable), */ | ||
638 | 0xC0 /* End Collection */ | ||
508 | }; | 639 | }; |
509 | 640 | ||
510 | static int waltop_probe(struct hid_device *hdev, | 641 | static int waltop_probe(struct hid_device *hdev, |
511 | const struct hid_device_id *id) | 642 | const struct hid_device_id *id) |
512 | { | 643 | { |
513 | int ret; | 644 | int ret; |
514 | struct waltop_state *s; | ||
515 | |||
516 | s = kzalloc(sizeof(*s), GFP_KERNEL); | ||
517 | if (s == NULL) { | ||
518 | hid_err(hdev, "can't allocate device state\n"); | ||
519 | ret = -ENOMEM; | ||
520 | goto err; | ||
521 | } | ||
522 | |||
523 | s->pressure0 = 0; | ||
524 | s->pressure1 = 0; | ||
525 | |||
526 | hid_set_drvdata(hdev, s); | ||
527 | 645 | ||
528 | ret = hid_parse(hdev); | 646 | ret = hid_parse(hdev); |
529 | if (ret) { | 647 | if (ret) { |
@@ -539,7 +657,6 @@ static int waltop_probe(struct hid_device *hdev, | |||
539 | 657 | ||
540 | return 0; | 658 | return 0; |
541 | err: | 659 | err: |
542 | kfree(s); | ||
543 | return ret; | 660 | return ret; |
544 | } | 661 | } |
545 | 662 | ||
@@ -583,6 +700,12 @@ static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
583 | *rsize = sizeof(media_tablet_14_1_inch_rdesc_fixed); | 700 | *rsize = sizeof(media_tablet_14_1_inch_rdesc_fixed); |
584 | } | 701 | } |
585 | break; | 702 | break; |
703 | case USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET: | ||
704 | if (*rsize == SIRIUS_BATTERY_FREE_TABLET_RDESC_ORIG_SIZE) { | ||
705 | rdesc = sirius_battery_free_tablet_rdesc_fixed; | ||
706 | *rsize = sizeof(sirius_battery_free_tablet_rdesc_fixed); | ||
707 | } | ||
708 | break; | ||
586 | } | 709 | } |
587 | return rdesc; | 710 | return rdesc; |
588 | } | 711 | } |
@@ -590,39 +713,72 @@ static __u8 *waltop_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
590 | static int waltop_raw_event(struct hid_device *hdev, struct hid_report *report, | 713 | static int waltop_raw_event(struct hid_device *hdev, struct hid_report *report, |
591 | u8 *data, int size) | 714 | u8 *data, int size) |
592 | { | 715 | { |
593 | /* If this is a pen input report of a tablet with PID 0038 */ | 716 | /* If this is a pen input report */ |
594 | if (hdev->product == USB_DEVICE_ID_WALTOP_PID_0038 && | 717 | if (report->type == HID_INPUT_REPORT && report->id == 16 && size >= 8) { |
595 | report->type == HID_INPUT_REPORT && | ||
596 | report->id == 16 && | ||
597 | size == 8) { | ||
598 | struct waltop_state *s = hid_get_drvdata(hdev); | ||
599 | |||
600 | /* | 718 | /* |
601 | * Ignore maximum pressure reported when a barrel button is | 719 | * Ignore reported pressure when a barrel button is pressed, |
602 | * pressed. | 720 | * because it is rarely correct. |
603 | */ | 721 | */ |
604 | 722 | ||
605 | /* If a barrel button is pressed */ | 723 | /* If a barrel button is pressed */ |
606 | if ((data[1] & 0xF) > 1) { | 724 | if ((data[1] & 0xF) > 1) { |
607 | /* Use the last known pressure */ | 725 | /* Report zero pressure */ |
608 | data[6] = s->pressure0; | 726 | data[6] = 0; |
609 | data[7] = s->pressure1; | 727 | data[7] = 0; |
610 | } else { | ||
611 | /* Remember reported pressure */ | ||
612 | s->pressure0 = data[6]; | ||
613 | s->pressure1 = data[7]; | ||
614 | } | 728 | } |
615 | } | 729 | } |
616 | 730 | ||
731 | /* If this is a pen input report of Sirius Battery Free Tablet */ | ||
732 | if (hdev->product == USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET && | ||
733 | report->type == HID_INPUT_REPORT && | ||
734 | report->id == 16 && | ||
735 | size == 10) { | ||
736 | /* | ||
737 | * The tablet reports tilt as roughly sin(a)*21 (18 means 60 | ||
738 | * degrees). | ||
739 | * | ||
740 | * This array stores angles as radians * 100, corresponding to | ||
741 | * reported values up to 60 degrees, as expected by userspace. | ||
742 | */ | ||
743 | static const s8 tilt_to_radians[] = { | ||
744 | 0, 5, 10, 14, 19, 24, 29, 34, 40, 45, | ||
745 | 50, 56, 62, 68, 74, 81, 88, 96, 105 | ||
746 | }; | ||
747 | |||
748 | s8 tilt_x = (s8)data[8]; | ||
749 | s8 tilt_y = (s8)data[9]; | ||
750 | s8 sign_x = tilt_x >= 0 ? 1 : -1; | ||
751 | s8 sign_y = tilt_y >= 0 ? 1 : -1; | ||
752 | |||
753 | tilt_x *= sign_x; | ||
754 | tilt_y *= sign_y; | ||
755 | |||
756 | /* | ||
757 | * Reverse the Y Tilt direction to match the HID standard and | ||
758 | * userspace expectations. See HID Usage Tables v1.12 16.3.2 | ||
759 | * Tilt Orientation. | ||
760 | */ | ||
761 | sign_y *= -1; | ||
762 | |||
763 | /* | ||
764 | * This effectively clamps reported tilt to 60 degrees - the | ||
765 | * range expected by userspace | ||
766 | */ | ||
767 | if (tilt_x > ARRAY_SIZE(tilt_to_radians) - 1) | ||
768 | tilt_x = ARRAY_SIZE(tilt_to_radians) - 1; | ||
769 | if (tilt_y > ARRAY_SIZE(tilt_to_radians) - 1) | ||
770 | tilt_y = ARRAY_SIZE(tilt_to_radians) - 1; | ||
771 | |||
772 | data[8] = tilt_to_radians[tilt_x] * sign_x; | ||
773 | data[9] = tilt_to_radians[tilt_y] * sign_y; | ||
774 | } | ||
775 | |||
617 | return 0; | 776 | return 0; |
618 | } | 777 | } |
619 | 778 | ||
620 | static void waltop_remove(struct hid_device *hdev) | 779 | static void waltop_remove(struct hid_device *hdev) |
621 | { | 780 | { |
622 | struct waltop_state *s = hid_get_drvdata(hdev); | ||
623 | |||
624 | hid_hw_stop(hdev); | 781 | hid_hw_stop(hdev); |
625 | kfree(s); | ||
626 | } | 782 | } |
627 | 783 | ||
628 | static const struct hid_device_id waltop_devices[] = { | 784 | static const struct hid_device_id waltop_devices[] = { |
@@ -638,6 +794,8 @@ static const struct hid_device_id waltop_devices[] = { | |||
638 | USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, | 794 | USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, |
639 | { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, | 795 | { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, |
640 | USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, | 796 | USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, |
797 | { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, | ||
798 | USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) }, | ||
641 | { } | 799 | { } |
642 | }; | 800 | }; |
643 | MODULE_DEVICE_TABLE(hid, waltop_devices); | 801 | MODULE_DEVICE_TABLE(hid, waltop_devices); |