hid-a4tech.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * HID driver for some a4tech "special" devices
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2007 Jiri Kosina
  8. * Copyright (c) 2008 Jiri Slaby
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/input.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include "hid-ids.h"
  22. #define A4_2WHEEL_MOUSE_HACK_7 0x01
  23. #define A4_2WHEEL_MOUSE_HACK_B8 0x02
  24. struct a4tech_sc {
  25. unsigned long quirks;
  26. unsigned int hw_wheel;
  27. __s32 delayed_value;
  28. };
  29. static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  30. struct hid_field *field, struct hid_usage *usage,
  31. unsigned long **bit, int *max)
  32. {
  33. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  34. if (usage->type == EV_REL && usage->code == REL_WHEEL)
  35. set_bit(REL_HWHEEL, *bit);
  36. if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007)
  37. return -1;
  38. return 0;
  39. }
  40. static int a4_event(struct hid_device *hdev, struct hid_field *field,
  41. struct hid_usage *usage, __s32 value)
  42. {
  43. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  44. struct input_dev *input;
  45. if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
  46. !usage->type)
  47. return 0;
  48. input = field->hidinput->input;
  49. if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) {
  50. if (usage->type == EV_REL && usage->code == REL_WHEEL) {
  51. a4->delayed_value = value;
  52. return 1;
  53. }
  54. if (usage->hid == 0x000100b8) {
  55. input_event(input, EV_REL, value ? REL_HWHEEL :
  56. REL_WHEEL, a4->delayed_value);
  57. return 1;
  58. }
  59. }
  60. if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) {
  61. a4->hw_wheel = !!value;
  62. return 1;
  63. }
  64. if (usage->code == REL_WHEEL && a4->hw_wheel) {
  65. input_event(input, usage->type, REL_HWHEEL, value);
  66. return 1;
  67. }
  68. return 0;
  69. }
  70. static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
  71. {
  72. struct a4tech_sc *a4;
  73. int ret;
  74. a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
  75. if (a4 == NULL) {
  76. hid_err(hdev, "can't alloc device descriptor\n");
  77. return -ENOMEM;
  78. }
  79. a4->quirks = id->driver_data;
  80. hid_set_drvdata(hdev, a4);
  81. ret = hid_parse(hdev);
  82. if (ret) {
  83. hid_err(hdev, "parse failed\n");
  84. return ret;
  85. }
  86. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  87. if (ret) {
  88. hid_err(hdev, "hw start failed\n");
  89. return ret;
  90. }
  91. return 0;
  92. }
  93. static const struct hid_device_id a4_devices[] = {
  94. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
  95. .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
  96. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
  97. .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
  98. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649),
  99. .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
  100. { }
  101. };
  102. MODULE_DEVICE_TABLE(hid, a4_devices);
  103. static struct hid_driver a4_driver = {
  104. .name = "a4tech",
  105. .id_table = a4_devices,
  106. .input_mapped = a4_input_mapped,
  107. .event = a4_event,
  108. .probe = a4_probe,
  109. };
  110. module_hid_driver(a4_driver);
  111. MODULE_LICENSE("GPL");