hid-petalynx.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * HID driver for some petalynx "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. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/hid.h>
  18. #include <linux/module.h>
  19. #include "hid-ids.h"
  20. /* Petalynx Maxter Remote has maximum for consumer page set too low */
  21. static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  22. unsigned int *rsize)
  23. {
  24. if (*rsize >= 62 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
  25. rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
  26. rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
  27. hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
  28. rdesc[60] = 0xfa;
  29. rdesc[40] = 0xfa;
  30. }
  31. return rdesc;
  32. }
  33. #define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  34. EV_KEY, (c))
  35. static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  36. struct hid_field *field, struct hid_usage *usage,
  37. unsigned long **bit, int *max)
  38. {
  39. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) {
  40. switch (usage->hid & HID_USAGE) {
  41. case 0x05a: pl_map_key_clear(KEY_TEXT); break;
  42. case 0x05b: pl_map_key_clear(KEY_RED); break;
  43. case 0x05c: pl_map_key_clear(KEY_GREEN); break;
  44. case 0x05d: pl_map_key_clear(KEY_YELLOW); break;
  45. case 0x05e: pl_map_key_clear(KEY_BLUE); break;
  46. default:
  47. return 0;
  48. }
  49. return 1;
  50. }
  51. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
  52. switch (usage->hid & HID_USAGE) {
  53. case 0x0f6: pl_map_key_clear(KEY_NEXT); break;
  54. case 0x0fa: pl_map_key_clear(KEY_BACK); break;
  55. default:
  56. return 0;
  57. }
  58. return 1;
  59. }
  60. return 0;
  61. }
  62. static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
  63. {
  64. int ret;
  65. hdev->quirks |= HID_QUIRK_NOGET;
  66. ret = hid_parse(hdev);
  67. if (ret) {
  68. hid_err(hdev, "parse failed\n");
  69. goto err_free;
  70. }
  71. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  72. if (ret) {
  73. hid_err(hdev, "hw start failed\n");
  74. goto err_free;
  75. }
  76. return 0;
  77. err_free:
  78. return ret;
  79. }
  80. static const struct hid_device_id pl_devices[] = {
  81. { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  82. { }
  83. };
  84. MODULE_DEVICE_TABLE(hid, pl_devices);
  85. static struct hid_driver pl_driver = {
  86. .name = "petalynx",
  87. .id_table = pl_devices,
  88. .report_fixup = pl_report_fixup,
  89. .input_mapping = pl_input_mapping,
  90. .probe = pl_probe,
  91. };
  92. module_hid_driver(pl_driver);
  93. MODULE_LICENSE("GPL");