hid-samsung.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * Vendor specific report #4 has a size of 48 bit,
  25. * and therefore is not accepted when inspecting the descriptors.
  26. * As a workaround we reinterpret the report as:
  27. * Variable type, count 6, size 8 bit, log. maximum 255
  28. * The burden to reconstruct the data is moved into user space.
  29. */
  30. static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  31. unsigned int rsize)
  32. {
  33. if (rsize >= 182 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
  34. rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
  35. rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
  36. rdesc[182] == 0x40) {
  37. dev_info(&hdev->dev, "fixing up Samsung IrDA report "
  38. "descriptor\n");
  39. rdesc[176] = 0xff;
  40. rdesc[178] = 0x08;
  41. rdesc[180] = 0x06;
  42. rdesc[182] = 0x42;
  43. }
  44. }
  45. static int samsung_probe(struct hid_device *hdev,
  46. const struct hid_device_id *id)
  47. {
  48. int ret;
  49. ret = hid_parse(hdev);
  50. if (ret) {
  51. dev_err(&hdev->dev, "parse failed\n");
  52. goto err_free;
  53. }
  54. ret = hid_hw_start(hdev, (HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDINPUT) |
  55. HID_CONNECT_HIDDEV_FORCE);
  56. if (ret) {
  57. dev_err(&hdev->dev, "hw start failed\n");
  58. goto err_free;
  59. }
  60. return 0;
  61. err_free:
  62. return ret;
  63. }
  64. static const struct hid_device_id samsung_devices[] = {
  65. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  66. { }
  67. };
  68. MODULE_DEVICE_TABLE(hid, samsung_devices);
  69. static struct hid_driver samsung_driver = {
  70. .name = "samsung",
  71. .id_table = samsung_devices,
  72. .report_fixup = samsung_report_fixup,
  73. .probe = samsung_probe,
  74. };
  75. static int samsung_init(void)
  76. {
  77. return hid_register_driver(&samsung_driver);
  78. }
  79. static void samsung_exit(void)
  80. {
  81. hid_unregister_driver(&samsung_driver);
  82. }
  83. module_init(samsung_init);
  84. module_exit(samsung_exit);
  85. MODULE_LICENSE("GPL");
  86. HID_COMPAT_LOAD_DRIVER(samsung);