hid-samsung.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * HID driver for some samsung "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. * Copyright (c) 2010 Don Prince <dhprince.devel@yahoo.co.uk>
  10. *
  11. *
  12. * This driver supports several HID devices:
  13. *
  14. * [0419:0001] Samsung IrDA remote controller (reports as Cypress USB Mouse).
  15. * various hid report fixups for different variants.
  16. *
  17. * [0419:0600] Creative Desktop Wireless 6000 keyboard/mouse combo
  18. * several key mappings used from the consumer usage page
  19. * deviate from the USB HUT 1.12 standard.
  20. *
  21. */
  22. /*
  23. * This program is free software; you can redistribute it and/or modify it
  24. * under the terms of the GNU General Public License as published by the Free
  25. * Software Foundation; either version 2 of the License, or (at your option)
  26. * any later version.
  27. */
  28. #include <linux/device.h>
  29. #include <linux/usb.h>
  30. #include <linux/hid.h>
  31. #include <linux/module.h>
  32. #include "hid-ids.h"
  33. /*
  34. * There are several variants for 0419:0001:
  35. *
  36. * 1. 184 byte report descriptor
  37. * Vendor specific report #4 has a size of 48 bit,
  38. * and therefore is not accepted when inspecting the descriptors.
  39. * As a workaround we reinterpret the report as:
  40. * Variable type, count 6, size 8 bit, log. maximum 255
  41. * The burden to reconstruct the data is moved into user space.
  42. *
  43. * 2. 203 byte report descriptor
  44. * Report #4 has an array field with logical range 0..18 instead of 1..15.
  45. *
  46. * 3. 135 byte report descriptor
  47. * Report #4 has an array field with logical range 0..17 instead of 1..14.
  48. *
  49. * 4. 171 byte report descriptor
  50. * Report #3 has an array field with logical range 0..1 instead of 1..3.
  51. */
  52. static inline void samsung_irda_dev_trace(struct hid_device *hdev,
  53. unsigned int rsize)
  54. {
  55. hid_info(hdev, "fixing up Samsung IrDA %d byte report descriptor\n",
  56. rsize);
  57. }
  58. static __u8 *samsung_irda_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  59. unsigned int *rsize)
  60. {
  61. if (*rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
  62. rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
  63. rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
  64. rdesc[182] == 0x40) {
  65. samsung_irda_dev_trace(hdev, 184);
  66. rdesc[176] = 0xff;
  67. rdesc[178] = 0x08;
  68. rdesc[180] = 0x06;
  69. rdesc[182] = 0x42;
  70. } else
  71. if (*rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
  72. rdesc[194] == 0x25 && rdesc[195] == 0x12) {
  73. samsung_irda_dev_trace(hdev, 203);
  74. rdesc[193] = 0x1;
  75. rdesc[195] = 0xf;
  76. } else
  77. if (*rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
  78. rdesc[126] == 0x25 && rdesc[127] == 0x11) {
  79. samsung_irda_dev_trace(hdev, 135);
  80. rdesc[125] = 0x1;
  81. rdesc[127] = 0xe;
  82. } else
  83. if (*rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
  84. rdesc[162] == 0x25 && rdesc[163] == 0x01) {
  85. samsung_irda_dev_trace(hdev, 171);
  86. rdesc[161] = 0x1;
  87. rdesc[163] = 0x3;
  88. }
  89. return rdesc;
  90. }
  91. #define samsung_kbd_mouse_map_key_clear(c) \
  92. hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
  93. static int samsung_kbd_mouse_input_mapping(struct hid_device *hdev,
  94. struct hid_input *hi, struct hid_field *field, struct hid_usage *usage,
  95. unsigned long **bit, int *max)
  96. {
  97. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  98. unsigned short ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
  99. if (1 != ifnum || HID_UP_CONSUMER != (usage->hid & HID_USAGE_PAGE))
  100. return 0;
  101. dbg_hid("samsung wireless keyboard/mouse input mapping event [0x%x]\n",
  102. usage->hid & HID_USAGE);
  103. switch (usage->hid & HID_USAGE) {
  104. /* report 2 */
  105. case 0x183: samsung_kbd_mouse_map_key_clear(KEY_MEDIA); break;
  106. case 0x195: samsung_kbd_mouse_map_key_clear(KEY_EMAIL); break;
  107. case 0x196: samsung_kbd_mouse_map_key_clear(KEY_CALC); break;
  108. case 0x197: samsung_kbd_mouse_map_key_clear(KEY_COMPUTER); break;
  109. case 0x22b: samsung_kbd_mouse_map_key_clear(KEY_SEARCH); break;
  110. case 0x22c: samsung_kbd_mouse_map_key_clear(KEY_WWW); break;
  111. case 0x22d: samsung_kbd_mouse_map_key_clear(KEY_BACK); break;
  112. case 0x22e: samsung_kbd_mouse_map_key_clear(KEY_FORWARD); break;
  113. case 0x22f: samsung_kbd_mouse_map_key_clear(KEY_FAVORITES); break;
  114. case 0x230: samsung_kbd_mouse_map_key_clear(KEY_REFRESH); break;
  115. case 0x231: samsung_kbd_mouse_map_key_clear(KEY_STOP); break;
  116. default:
  117. return 0;
  118. }
  119. return 1;
  120. }
  121. static __u8 *samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  122. unsigned int *rsize)
  123. {
  124. if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product)
  125. rdesc = samsung_irda_report_fixup(hdev, rdesc, rsize);
  126. return rdesc;
  127. }
  128. static int samsung_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  129. struct hid_field *field, struct hid_usage *usage,
  130. unsigned long **bit, int *max)
  131. {
  132. int ret = 0;
  133. if (USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE == hdev->product)
  134. ret = samsung_kbd_mouse_input_mapping(hdev,
  135. hi, field, usage, bit, max);
  136. return ret;
  137. }
  138. static int samsung_probe(struct hid_device *hdev,
  139. const struct hid_device_id *id)
  140. {
  141. int ret;
  142. unsigned int cmask = HID_CONNECT_DEFAULT;
  143. ret = hid_parse(hdev);
  144. if (ret) {
  145. hid_err(hdev, "parse failed\n");
  146. goto err_free;
  147. }
  148. if (USB_DEVICE_ID_SAMSUNG_IR_REMOTE == hdev->product) {
  149. if (hdev->rsize == 184) {
  150. /* disable hidinput, force hiddev */
  151. cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
  152. HID_CONNECT_HIDDEV_FORCE;
  153. }
  154. }
  155. ret = hid_hw_start(hdev, cmask);
  156. if (ret) {
  157. hid_err(hdev, "hw start failed\n");
  158. goto err_free;
  159. }
  160. return 0;
  161. err_free:
  162. return ret;
  163. }
  164. static const struct hid_device_id samsung_devices[] = {
  165. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  166. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
  167. { }
  168. };
  169. MODULE_DEVICE_TABLE(hid, samsung_devices);
  170. static struct hid_driver samsung_driver = {
  171. .name = "samsung",
  172. .id_table = samsung_devices,
  173. .report_fixup = samsung_report_fixup,
  174. .input_mapping = samsung_input_mapping,
  175. .probe = samsung_probe,
  176. };
  177. module_hid_driver(samsung_driver);
  178. MODULE_LICENSE("GPL");