hid-petalynx.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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) 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. /* Petalynx Maxter Remote has maximum for consumer page set too low */
  22. static __u8 *pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  23. unsigned int *rsize)
  24. {
  25. if (*rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
  26. rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
  27. rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
  28. hid_info(hdev, "fixing up Petalynx Maxter Remote report descriptor\n");
  29. rdesc[60] = 0xfa;
  30. rdesc[40] = 0xfa;
  31. }
  32. return rdesc;
  33. }
  34. #define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  35. EV_KEY, (c))
  36. static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  37. struct hid_field *field, struct hid_usage *usage,
  38. unsigned long **bit, int *max)
  39. {
  40. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) {
  41. switch (usage->hid & HID_USAGE) {
  42. case 0x05a: pl_map_key_clear(KEY_TEXT); break;
  43. case 0x05b: pl_map_key_clear(KEY_RED); break;
  44. case 0x05c: pl_map_key_clear(KEY_GREEN); break;
  45. case 0x05d: pl_map_key_clear(KEY_YELLOW); break;
  46. case 0x05e: pl_map_key_clear(KEY_BLUE); break;
  47. default:
  48. return 0;
  49. }
  50. return 1;
  51. }
  52. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
  53. switch (usage->hid & HID_USAGE) {
  54. case 0x0f6: pl_map_key_clear(KEY_NEXT); break;
  55. case 0x0fa: pl_map_key_clear(KEY_BACK); break;
  56. default:
  57. return 0;
  58. }
  59. return 1;
  60. }
  61. return 0;
  62. }
  63. static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
  64. {
  65. int ret;
  66. hdev->quirks |= HID_QUIRK_NOGET;
  67. ret = hid_parse(hdev);
  68. if (ret) {
  69. hid_err(hdev, "parse failed\n");
  70. goto err_free;
  71. }
  72. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  73. if (ret) {
  74. hid_err(hdev, "hw start failed\n");
  75. goto err_free;
  76. }
  77. return 0;
  78. err_free:
  79. return ret;
  80. }
  81. static const struct hid_device_id pl_devices[] = {
  82. { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  83. { }
  84. };
  85. MODULE_DEVICE_TABLE(hid, pl_devices);
  86. static struct hid_driver pl_driver = {
  87. .name = "petalynx",
  88. .id_table = pl_devices,
  89. .report_fixup = pl_report_fixup,
  90. .input_mapping = pl_input_mapping,
  91. .probe = pl_probe,
  92. };
  93. static int __init pl_init(void)
  94. {
  95. return hid_register_driver(&pl_driver);
  96. }
  97. static void __exit pl_exit(void)
  98. {
  99. hid_unregister_driver(&pl_driver);
  100. }
  101. module_init(pl_init);
  102. module_exit(pl_exit);
  103. MODULE_LICENSE("GPL");