firedtv-rc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * FireDTV driver (formerly known as FireSAT)
  3. *
  4. * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. */
  11. #include <linux/bitops.h>
  12. #include <linux/input.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <linux/workqueue.h>
  18. #include "firedtv.h"
  19. /* fixed table with older keycodes, geared towards MythTV */
  20. static const u16 oldtable[] = {
  21. /* code from device: 0x4501...0x451f */
  22. KEY_ESC,
  23. KEY_F9,
  24. KEY_1,
  25. KEY_2,
  26. KEY_3,
  27. KEY_4,
  28. KEY_5,
  29. KEY_6,
  30. KEY_7,
  31. KEY_8,
  32. KEY_9,
  33. KEY_I,
  34. KEY_0,
  35. KEY_ENTER,
  36. KEY_RED,
  37. KEY_UP,
  38. KEY_GREEN,
  39. KEY_F10,
  40. KEY_SPACE,
  41. KEY_F11,
  42. KEY_YELLOW,
  43. KEY_DOWN,
  44. KEY_BLUE,
  45. KEY_Z,
  46. KEY_P,
  47. KEY_PAGEDOWN,
  48. KEY_LEFT,
  49. KEY_W,
  50. KEY_RIGHT,
  51. KEY_P,
  52. KEY_M,
  53. /* code from device: 0x4540...0x4542 */
  54. KEY_R,
  55. KEY_V,
  56. KEY_C,
  57. };
  58. /* user-modifiable table for a remote as sold in 2008 */
  59. static const u16 keytable[] = {
  60. /* code from device: 0x0300...0x031f */
  61. [0x00] = KEY_POWER,
  62. [0x01] = KEY_SLEEP,
  63. [0x02] = KEY_STOP,
  64. [0x03] = KEY_OK,
  65. [0x04] = KEY_RIGHT,
  66. [0x05] = KEY_1,
  67. [0x06] = KEY_2,
  68. [0x07] = KEY_3,
  69. [0x08] = KEY_LEFT,
  70. [0x09] = KEY_4,
  71. [0x0a] = KEY_5,
  72. [0x0b] = KEY_6,
  73. [0x0c] = KEY_UP,
  74. [0x0d] = KEY_7,
  75. [0x0e] = KEY_8,
  76. [0x0f] = KEY_9,
  77. [0x10] = KEY_DOWN,
  78. [0x11] = KEY_TITLE, /* "OSD" - fixme */
  79. [0x12] = KEY_0,
  80. [0x13] = KEY_F20, /* "16:9" - fixme */
  81. [0x14] = KEY_SCREEN, /* "FULL" - fixme */
  82. [0x15] = KEY_MUTE,
  83. [0x16] = KEY_SUBTITLE,
  84. [0x17] = KEY_RECORD,
  85. [0x18] = KEY_TEXT,
  86. [0x19] = KEY_AUDIO,
  87. [0x1a] = KEY_RED,
  88. [0x1b] = KEY_PREVIOUS,
  89. [0x1c] = KEY_REWIND,
  90. [0x1d] = KEY_PLAYPAUSE,
  91. [0x1e] = KEY_NEXT,
  92. [0x1f] = KEY_VOLUMEUP,
  93. /* code from device: 0x0340...0x0354 */
  94. [0x20] = KEY_CHANNELUP,
  95. [0x21] = KEY_F21, /* "4:3" - fixme */
  96. [0x22] = KEY_TV,
  97. [0x23] = KEY_DVD,
  98. [0x24] = KEY_VCR,
  99. [0x25] = KEY_AUX,
  100. [0x26] = KEY_GREEN,
  101. [0x27] = KEY_YELLOW,
  102. [0x28] = KEY_BLUE,
  103. [0x29] = KEY_CHANNEL, /* "CH.LIST" */
  104. [0x2a] = KEY_VENDOR, /* "CI" - fixme */
  105. [0x2b] = KEY_VOLUMEDOWN,
  106. [0x2c] = KEY_CHANNELDOWN,
  107. [0x2d] = KEY_LAST,
  108. [0x2e] = KEY_INFO,
  109. [0x2f] = KEY_FORWARD,
  110. [0x30] = KEY_LIST,
  111. [0x31] = KEY_FAVORITES,
  112. [0x32] = KEY_MENU,
  113. [0x33] = KEY_EPG,
  114. [0x34] = KEY_EXIT,
  115. };
  116. int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
  117. {
  118. struct input_dev *idev;
  119. int i, err;
  120. idev = input_allocate_device();
  121. if (!idev)
  122. return -ENOMEM;
  123. fdtv->remote_ctrl_dev = idev;
  124. idev->name = "FireDTV remote control";
  125. idev->dev.parent = dev;
  126. idev->evbit[0] = BIT_MASK(EV_KEY);
  127. idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
  128. if (!idev->keycode) {
  129. err = -ENOMEM;
  130. goto fail;
  131. }
  132. idev->keycodesize = sizeof(keytable[0]);
  133. idev->keycodemax = ARRAY_SIZE(keytable);
  134. for (i = 0; i < ARRAY_SIZE(keytable); i++)
  135. set_bit(keytable[i], idev->keybit);
  136. err = input_register_device(idev);
  137. if (err)
  138. goto fail_free_keymap;
  139. return 0;
  140. fail_free_keymap:
  141. kfree(idev->keycode);
  142. fail:
  143. input_free_device(idev);
  144. return err;
  145. }
  146. void fdtv_unregister_rc(struct firedtv *fdtv)
  147. {
  148. cancel_work_sync(&fdtv->remote_ctrl_work);
  149. kfree(fdtv->remote_ctrl_dev->keycode);
  150. input_unregister_device(fdtv->remote_ctrl_dev);
  151. }
  152. void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
  153. {
  154. struct input_dev *idev = fdtv->remote_ctrl_dev;
  155. u16 *keycode = idev->keycode;
  156. if (code >= 0x0300 && code <= 0x031f)
  157. code = keycode[code - 0x0300];
  158. else if (code >= 0x0340 && code <= 0x0354)
  159. code = keycode[code - 0x0320];
  160. else if (code >= 0x4501 && code <= 0x451f)
  161. code = oldtable[code - 0x4501];
  162. else if (code >= 0x4540 && code <= 0x4542)
  163. code = oldtable[code - 0x4521];
  164. else {
  165. dev_dbg(fdtv->device,
  166. "invalid key code 0x%04x from remote control\n",
  167. code);
  168. return;
  169. }
  170. input_report_key(idev, code, 1);
  171. input_sync(idev);
  172. input_report_key(idev, code, 0);
  173. input_sync(idev);
  174. }