af9005-remote.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* DVB USB compliant Linux driver for the Afatech 9005
  2. * USB1.1 DVB-T receiver.
  3. *
  4. * Standard remote decode function
  5. *
  6. * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
  7. *
  8. * Thanks to Afatech who kindly provided information.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * see Documentation/dvb/README.dvb-usb for more information
  25. */
  26. #include "af9005.h"
  27. /* debug */
  28. static int dvb_usb_af9005_remote_debug;
  29. module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);
  30. MODULE_PARM_DESC(debug,
  31. "enable (1) or disable (0) debug messages."
  32. DVB_USB_DEBUG_STATUS);
  33. #define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)
  34. struct rc_map_table rc_map_af9005_table[] = {
  35. {0x01b7, KEY_POWER},
  36. {0x01a7, KEY_VOLUMEUP},
  37. {0x0187, KEY_CHANNELUP},
  38. {0x017f, KEY_MUTE},
  39. {0x01bf, KEY_VOLUMEDOWN},
  40. {0x013f, KEY_CHANNELDOWN},
  41. {0x01df, KEY_1},
  42. {0x015f, KEY_2},
  43. {0x019f, KEY_3},
  44. {0x011f, KEY_4},
  45. {0x01ef, KEY_5},
  46. {0x016f, KEY_6},
  47. {0x01af, KEY_7},
  48. {0x0127, KEY_8},
  49. {0x0107, KEY_9},
  50. {0x01cf, KEY_ZOOM},
  51. {0x014f, KEY_0},
  52. {0x018f, KEY_GOTO}, /* marked jump on the remote */
  53. {0x00bd, KEY_POWER},
  54. {0x007d, KEY_VOLUMEUP},
  55. {0x00fd, KEY_CHANNELUP},
  56. {0x009d, KEY_MUTE},
  57. {0x005d, KEY_VOLUMEDOWN},
  58. {0x00dd, KEY_CHANNELDOWN},
  59. {0x00ad, KEY_1},
  60. {0x006d, KEY_2},
  61. {0x00ed, KEY_3},
  62. {0x008d, KEY_4},
  63. {0x004d, KEY_5},
  64. {0x00cd, KEY_6},
  65. {0x00b5, KEY_7},
  66. {0x0075, KEY_8},
  67. {0x00f5, KEY_9},
  68. {0x0095, KEY_ZOOM},
  69. {0x0055, KEY_0},
  70. {0x00d5, KEY_GOTO}, /* marked jump on the remote */
  71. };
  72. int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);
  73. static int repeatable_keys[] = {
  74. KEY_VOLUMEUP,
  75. KEY_VOLUMEDOWN,
  76. KEY_CHANNELUP,
  77. KEY_CHANNELDOWN
  78. };
  79. int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
  80. int *state)
  81. {
  82. u16 mark, space;
  83. u32 result;
  84. u8 cust, dat, invdat;
  85. int i;
  86. if (len >= 6) {
  87. mark = (u16) (data[0] << 8) + data[1];
  88. space = (u16) (data[2] << 8) + data[3];
  89. if (space * 3 < mark) {
  90. for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {
  91. if (d->last_event == repeatable_keys[i]) {
  92. *state = REMOTE_KEY_REPEAT;
  93. *event = d->last_event;
  94. deb_decode("repeat key, event %x\n",
  95. *event);
  96. return 0;
  97. }
  98. }
  99. deb_decode("repeated key ignored (non repeatable)\n");
  100. return 0;
  101. } else if (len >= 33 * 4) { /*32 bits + start code */
  102. result = 0;
  103. for (i = 4; i < 4 + 32 * 4; i += 4) {
  104. result <<= 1;
  105. mark = (u16) (data[i] << 8) + data[i + 1];
  106. mark >>= 1;
  107. space = (u16) (data[i + 2] << 8) + data[i + 3];
  108. space >>= 1;
  109. if (mark * 2 > space)
  110. result += 1;
  111. }
  112. deb_decode("key pressed, raw value %x\n", result);
  113. if ((result & 0xff000000) != 0xfe000000) {
  114. deb_decode
  115. ("doesn't start with 0xfe, ignored\n");
  116. return 0;
  117. }
  118. cust = (result >> 16) & 0xff;
  119. dat = (result >> 8) & 0xff;
  120. invdat = (~result) & 0xff;
  121. if (dat != invdat) {
  122. deb_decode("code != inverted code\n");
  123. return 0;
  124. }
  125. for (i = 0; i < rc_map_af9005_table_size; i++) {
  126. if (rc5_custom(&rc_map_af9005_table[i]) == cust
  127. && rc5_data(&rc_map_af9005_table[i]) == dat) {
  128. *event = rc_map_af9005_table[i].keycode;
  129. *state = REMOTE_KEY_PRESSED;
  130. deb_decode
  131. ("key pressed, event %x\n", *event);
  132. return 0;
  133. }
  134. }
  135. deb_decode("not found in table\n");
  136. }
  137. }
  138. return 0;
  139. }
  140. EXPORT_SYMBOL(rc_map_af9005_table);
  141. EXPORT_SYMBOL(rc_map_af9005_table_size);
  142. EXPORT_SYMBOL(af9005_rc_decode);
  143. MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
  144. MODULE_DESCRIPTION
  145. ("Standard remote control decoder for Afatech 9005 DVB-T USB1.1 stick");
  146. MODULE_VERSION("1.0");
  147. MODULE_LICENSE("GPL");