hid-a4tech.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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) 2007 Paul Walmsley
  9. * Copyright (c) 2008 Jiri Slaby
  10. */
  11. /*
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. #include <linux/device.h>
  18. #include <linux/input.h>
  19. #include <linux/hid.h>
  20. #include <linux/module.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 = kzalloc(sizeof(*a4), GFP_KERNEL);
  75. if (a4 == NULL) {
  76. dev_err(&hdev->dev, "can't alloc device descriptor\n");
  77. ret = -ENOMEM;
  78. goto err_free;
  79. }
  80. a4->quirks = id->driver_data;
  81. hid_set_drvdata(hdev, a4);
  82. ret = hid_parse(hdev);
  83. if (ret) {
  84. dev_err(&hdev->dev, "parse failed\n");
  85. goto err_free;
  86. }
  87. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  88. if (ret) {
  89. dev_err(&hdev->dev, "hw start failed\n");
  90. goto err_free;
  91. }
  92. return 0;
  93. err_free:
  94. kfree(a4);
  95. return ret;
  96. }
  97. static void a4_remove(struct hid_device *hdev)
  98. {
  99. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  100. hid_hw_stop(hdev);
  101. kfree(a4);
  102. }
  103. static const struct hid_device_id a4_devices[] = {
  104. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
  105. .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
  106. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
  107. .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
  108. { }
  109. };
  110. MODULE_DEVICE_TABLE(hid, a4_devices);
  111. static struct hid_driver a4_driver = {
  112. .name = "a4tech",
  113. .id_table = a4_devices,
  114. .input_mapped = a4_input_mapped,
  115. .event = a4_event,
  116. .probe = a4_probe,
  117. .remove = a4_remove,
  118. };
  119. static int a4_init(void)
  120. {
  121. return hid_register_driver(&a4_driver);
  122. }
  123. static void a4_exit(void)
  124. {
  125. hid_unregister_driver(&a4_driver);
  126. }
  127. module_init(a4_init);
  128. module_exit(a4_exit);
  129. MODULE_LICENSE("GPL");