hid-a4tech.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <linux/slab.h>
  22. #include "hid-ids.h"
  23. #define A4_2WHEEL_MOUSE_HACK_7 0x01
  24. #define A4_2WHEEL_MOUSE_HACK_B8 0x02
  25. struct a4tech_sc {
  26. unsigned long quirks;
  27. unsigned int hw_wheel;
  28. __s32 delayed_value;
  29. };
  30. static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  31. struct hid_field *field, struct hid_usage *usage,
  32. unsigned long **bit, int *max)
  33. {
  34. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  35. if (usage->type == EV_REL && usage->code == REL_WHEEL)
  36. set_bit(REL_HWHEEL, *bit);
  37. if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007)
  38. return -1;
  39. return 0;
  40. }
  41. static int a4_event(struct hid_device *hdev, struct hid_field *field,
  42. struct hid_usage *usage, __s32 value)
  43. {
  44. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  45. struct input_dev *input;
  46. if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
  47. !usage->type)
  48. return 0;
  49. input = field->hidinput->input;
  50. if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) {
  51. if (usage->type == EV_REL && usage->code == REL_WHEEL) {
  52. a4->delayed_value = value;
  53. return 1;
  54. }
  55. if (usage->hid == 0x000100b8) {
  56. input_event(input, EV_REL, value ? REL_HWHEEL :
  57. REL_WHEEL, a4->delayed_value);
  58. return 1;
  59. }
  60. }
  61. if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) {
  62. a4->hw_wheel = !!value;
  63. return 1;
  64. }
  65. if (usage->code == REL_WHEEL && a4->hw_wheel) {
  66. input_event(input, usage->type, REL_HWHEEL, value);
  67. return 1;
  68. }
  69. return 0;
  70. }
  71. static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
  72. {
  73. struct a4tech_sc *a4;
  74. int ret;
  75. a4 = kzalloc(sizeof(*a4), GFP_KERNEL);
  76. if (a4 == NULL) {
  77. hid_err(hdev, "can't alloc device descriptor\n");
  78. ret = -ENOMEM;
  79. goto err_free;
  80. }
  81. a4->quirks = id->driver_data;
  82. hid_set_drvdata(hdev, a4);
  83. ret = hid_parse(hdev);
  84. if (ret) {
  85. hid_err(hdev, "parse failed\n");
  86. goto err_free;
  87. }
  88. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  89. if (ret) {
  90. hid_err(hdev, "hw start failed\n");
  91. goto err_free;
  92. }
  93. return 0;
  94. err_free:
  95. kfree(a4);
  96. return ret;
  97. }
  98. static void a4_remove(struct hid_device *hdev)
  99. {
  100. struct a4tech_sc *a4 = hid_get_drvdata(hdev);
  101. hid_hw_stop(hdev);
  102. kfree(a4);
  103. }
  104. static const struct hid_device_id a4_devices[] = {
  105. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
  106. .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
  107. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
  108. .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
  109. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649),
  110. .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
  111. { }
  112. };
  113. MODULE_DEVICE_TABLE(hid, a4_devices);
  114. static struct hid_driver a4_driver = {
  115. .name = "a4tech",
  116. .id_table = a4_devices,
  117. .input_mapped = a4_input_mapped,
  118. .event = a4_event,
  119. .probe = a4_probe,
  120. .remove = a4_remove,
  121. };
  122. static int __init a4_init(void)
  123. {
  124. return hid_register_driver(&a4_driver);
  125. }
  126. static void __exit a4_exit(void)
  127. {
  128. hid_unregister_driver(&a4_driver);
  129. }
  130. module_init(a4_init);
  131. module_exit(a4_exit);
  132. MODULE_LICENSE("GPL");