hid-samsung.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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) 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/hid.h>
  19. #include <linux/module.h>
  20. #include "hid-ids.h"
  21. /*
  22. * Samsung IrDA remote controller (reports as Cypress USB Mouse).
  23. *
  24. * There are several variants for 0419:0001:
  25. *
  26. * 1. 184 byte report descriptor
  27. * Vendor specific report #4 has a size of 48 bit,
  28. * and therefore is not accepted when inspecting the descriptors.
  29. * As a workaround we reinterpret the report as:
  30. * Variable type, count 6, size 8 bit, log. maximum 255
  31. * The burden to reconstruct the data is moved into user space.
  32. *
  33. * 2. 203 byte report descriptor
  34. * Report #4 has an array field with logical range 0..18 instead of 1..15.
  35. *
  36. * 3. 135 byte report descriptor
  37. * Report #4 has an array field with logical range 0..17 instead of 1..14.
  38. *
  39. * 4. 171 byte report descriptor
  40. * Report #3 has an array field with logical range 0..1 instead of 1..3.
  41. */
  42. static inline void samsung_dev_trace(struct hid_device *hdev,
  43. unsigned int rsize)
  44. {
  45. dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report "
  46. "descriptor\n", rsize);
  47. }
  48. static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  49. unsigned int rsize)
  50. {
  51. if (rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
  52. rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
  53. rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
  54. rdesc[182] == 0x40) {
  55. samsung_dev_trace(hdev, 184);
  56. rdesc[176] = 0xff;
  57. rdesc[178] = 0x08;
  58. rdesc[180] = 0x06;
  59. rdesc[182] = 0x42;
  60. } else
  61. if (rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
  62. rdesc[194] == 0x25 && rdesc[195] == 0x12) {
  63. samsung_dev_trace(hdev, 203);
  64. rdesc[193] = 0x1;
  65. rdesc[195] = 0xf;
  66. } else
  67. if (rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
  68. rdesc[126] == 0x25 && rdesc[127] == 0x11) {
  69. samsung_dev_trace(hdev, 135);
  70. rdesc[125] = 0x1;
  71. rdesc[127] = 0xe;
  72. } else
  73. if (rsize == 171 && rdesc[160] == 0x15 && rdesc[161] == 0x0 &&
  74. rdesc[162] == 0x25 && rdesc[163] == 0x01) {
  75. samsung_dev_trace(hdev, 171);
  76. rdesc[161] = 0x1;
  77. rdesc[163] = 0x3;
  78. }
  79. }
  80. static int samsung_probe(struct hid_device *hdev,
  81. const struct hid_device_id *id)
  82. {
  83. int ret;
  84. unsigned int cmask = HID_CONNECT_DEFAULT;
  85. ret = hid_parse(hdev);
  86. if (ret) {
  87. dev_err(&hdev->dev, "parse failed\n");
  88. goto err_free;
  89. }
  90. if (hdev->rsize == 184) {
  91. /* disable hidinput, force hiddev */
  92. cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
  93. HID_CONNECT_HIDDEV_FORCE;
  94. }
  95. ret = hid_hw_start(hdev, cmask);
  96. if (ret) {
  97. dev_err(&hdev->dev, "hw start failed\n");
  98. goto err_free;
  99. }
  100. return 0;
  101. err_free:
  102. return ret;
  103. }
  104. static const struct hid_device_id samsung_devices[] = {
  105. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  106. { }
  107. };
  108. MODULE_DEVICE_TABLE(hid, samsung_devices);
  109. static struct hid_driver samsung_driver = {
  110. .name = "samsung",
  111. .id_table = samsung_devices,
  112. .report_fixup = samsung_report_fixup,
  113. .probe = samsung_probe,
  114. };
  115. static int __init samsung_init(void)
  116. {
  117. return hid_register_driver(&samsung_driver);
  118. }
  119. static void __exit samsung_exit(void)
  120. {
  121. hid_unregister_driver(&samsung_driver);
  122. }
  123. module_init(samsung_init);
  124. module_exit(samsung_exit);
  125. MODULE_LICENSE("GPL");