hid-samsung.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  40. unsigned int rsize)
  41. {
  42. if (rsize == 184 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
  43. rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
  44. rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
  45. rdesc[182] == 0x40) {
  46. dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report "
  47. "descriptor\n", 184);
  48. rdesc[176] = 0xff;
  49. rdesc[178] = 0x08;
  50. rdesc[180] = 0x06;
  51. rdesc[182] = 0x42;
  52. } else
  53. if (rsize == 203 && rdesc[192] == 0x15 && rdesc[193] == 0x0 &&
  54. rdesc[194] == 0x25 && rdesc[195] == 0x12) {
  55. dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report "
  56. "descriptor\n", 203);
  57. rdesc[193] = 0x1;
  58. rdesc[195] = 0xf;
  59. } else
  60. if (rsize == 135 && rdesc[124] == 0x15 && rdesc[125] == 0x0 &&
  61. rdesc[126] == 0x25 && rdesc[127] == 0x11) {
  62. dev_info(&hdev->dev, "fixing up Samsung IrDA %d byte report "
  63. "descriptor\n", 135);
  64. rdesc[125] = 0x1;
  65. rdesc[127] = 0xe;
  66. }
  67. }
  68. static int samsung_probe(struct hid_device *hdev,
  69. const struct hid_device_id *id)
  70. {
  71. int ret;
  72. unsigned int cmask = HID_CONNECT_DEFAULT;
  73. ret = hid_parse(hdev);
  74. if (ret) {
  75. dev_err(&hdev->dev, "parse failed\n");
  76. goto err_free;
  77. }
  78. if (hdev->rsize == 184) {
  79. /* disable hidinput, force hiddev */
  80. cmask = (cmask & ~HID_CONNECT_HIDINPUT) |
  81. HID_CONNECT_HIDDEV_FORCE;
  82. }
  83. ret = hid_hw_start(hdev, cmask);
  84. if (ret) {
  85. dev_err(&hdev->dev, "hw start failed\n");
  86. goto err_free;
  87. }
  88. return 0;
  89. err_free:
  90. return ret;
  91. }
  92. static const struct hid_device_id samsung_devices[] = {
  93. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  94. { }
  95. };
  96. MODULE_DEVICE_TABLE(hid, samsung_devices);
  97. static struct hid_driver samsung_driver = {
  98. .name = "samsung",
  99. .id_table = samsung_devices,
  100. .report_fixup = samsung_report_fixup,
  101. .probe = samsung_probe,
  102. };
  103. static int __init samsung_init(void)
  104. {
  105. return hid_register_driver(&samsung_driver);
  106. }
  107. static void __exit samsung_exit(void)
  108. {
  109. hid_unregister_driver(&samsung_driver);
  110. }
  111. module_init(samsung_init);
  112. module_exit(samsung_exit);
  113. MODULE_LICENSE("GPL");