hid-twinhan.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * HID driver for TwinHan IR remote control
  3. *
  4. * Based on hid-gyration.c
  5. *
  6. * Copyright (c) 2009 Bruno Prémont <bonbons@linux-vserver.org>
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/input.h>
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include "hid-ids.h"
  18. /* Remote control key layout + listing:
  19. *
  20. * Full Screen Power
  21. * KEY_SCREEN KEY_POWER2
  22. *
  23. * 1 2 3
  24. * KEY_NUMERIC_1 KEY_NUMERIC_2 KEY_NUMERIC_3
  25. *
  26. * 4 5 6
  27. * KEY_NUMERIC_4 KEY_NUMERIC_5 KEY_NUMERIC_6
  28. *
  29. * 7 8 9
  30. * KEY_NUMERIC_7 KEY_NUMERIC_8 KEY_NUMERIC_9
  31. *
  32. * REC 0 Favorite
  33. * KEY_RECORD KEY_NUMERIC_0 KEY_FAVORITES
  34. *
  35. * Rewind Forward
  36. * KEY_REWIND CH+ KEY_FORWARD
  37. * KEY_CHANNELUP
  38. *
  39. * VOL- > VOL+
  40. * KEY_VOLUMEDOWN KEY_PLAY KEY_VOLUMEUP
  41. *
  42. * CH-
  43. * KEY_CHANNELDOWN
  44. * Recall Stop
  45. * KEY_RESTART KEY_STOP
  46. *
  47. * Timeshift/Pause Mute Cancel
  48. * KEY_PAUSE KEY_MUTE KEY_CANCEL
  49. *
  50. * Capture Preview EPG
  51. * KEY_PRINT KEY_PROGRAM KEY_EPG
  52. *
  53. * Record List Tab Teletext
  54. * KEY_LIST KEY_TAB KEY_TEXT
  55. */
  56. #define th_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  57. EV_KEY, (c))
  58. static int twinhan_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  59. struct hid_field *field, struct hid_usage *usage,
  60. unsigned long **bit, int *max)
  61. {
  62. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_KEYBOARD)
  63. return 0;
  64. switch (usage->hid & HID_USAGE) {
  65. /* Map all keys from Twinhan Remote */
  66. case 0x004: th_map_key_clear(KEY_TEXT); break;
  67. case 0x006: th_map_key_clear(KEY_RESTART); break;
  68. case 0x008: th_map_key_clear(KEY_EPG); break;
  69. case 0x00c: th_map_key_clear(KEY_REWIND); break;
  70. case 0x00e: th_map_key_clear(KEY_PROGRAM); break;
  71. case 0x00f: th_map_key_clear(KEY_LIST); break;
  72. case 0x010: th_map_key_clear(KEY_MUTE); break;
  73. case 0x011: th_map_key_clear(KEY_FORWARD); break;
  74. case 0x013: th_map_key_clear(KEY_PRINT); break;
  75. case 0x017: th_map_key_clear(KEY_PAUSE); break;
  76. case 0x019: th_map_key_clear(KEY_FAVORITES); break;
  77. case 0x01d: th_map_key_clear(KEY_SCREEN); break;
  78. case 0x01e: th_map_key_clear(KEY_NUMERIC_1); break;
  79. case 0x01f: th_map_key_clear(KEY_NUMERIC_2); break;
  80. case 0x020: th_map_key_clear(KEY_NUMERIC_3); break;
  81. case 0x021: th_map_key_clear(KEY_NUMERIC_4); break;
  82. case 0x022: th_map_key_clear(KEY_NUMERIC_5); break;
  83. case 0x023: th_map_key_clear(KEY_NUMERIC_6); break;
  84. case 0x024: th_map_key_clear(KEY_NUMERIC_7); break;
  85. case 0x025: th_map_key_clear(KEY_NUMERIC_8); break;
  86. case 0x026: th_map_key_clear(KEY_NUMERIC_9); break;
  87. case 0x027: th_map_key_clear(KEY_NUMERIC_0); break;
  88. case 0x028: th_map_key_clear(KEY_PLAY); break;
  89. case 0x029: th_map_key_clear(KEY_CANCEL); break;
  90. case 0x02b: th_map_key_clear(KEY_TAB); break;
  91. /* Power = 0x0e0 + 0x0e1 + 0x0e2 + 0x03f */
  92. case 0x03f: th_map_key_clear(KEY_POWER2); break;
  93. case 0x04a: th_map_key_clear(KEY_RECORD); break;
  94. case 0x04b: th_map_key_clear(KEY_CHANNELUP); break;
  95. case 0x04d: th_map_key_clear(KEY_STOP); break;
  96. case 0x04e: th_map_key_clear(KEY_CHANNELDOWN); break;
  97. /* Volume down = 0x0e1 + 0x051 */
  98. case 0x051: th_map_key_clear(KEY_VOLUMEDOWN); break;
  99. /* Volume up = 0x0e1 + 0x052 */
  100. case 0x052: th_map_key_clear(KEY_VOLUMEUP); break;
  101. /* Kill the extra keys used for multi-key "power" and "volume" keys
  102. * as well as continuously to release CTRL,ALT,META,... keys */
  103. case 0x0e0:
  104. case 0x0e1:
  105. case 0x0e2:
  106. case 0x0e3:
  107. case 0x0e4:
  108. case 0x0e5:
  109. case 0x0e6:
  110. case 0x0e7:
  111. default:
  112. return -1;
  113. }
  114. return 1;
  115. }
  116. static const struct hid_device_id twinhan_devices[] = {
  117. { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
  118. { }
  119. };
  120. MODULE_DEVICE_TABLE(hid, twinhan_devices);
  121. static struct hid_driver twinhan_driver = {
  122. .name = "twinhan",
  123. .id_table = twinhan_devices,
  124. .input_mapping = twinhan_input_mapping,
  125. };
  126. module_hid_driver(twinhan_driver);
  127. MODULE_LICENSE("GPL");