af9005-remote.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* DVB USB compliant Linux driver for the Afatech 9005
  3. * USB1.1 DVB-T receiver.
  4. *
  5. * Standard remote decode function
  6. *
  7. * Copyright (C) 2007 Luca Olivetti ([email protected])
  8. *
  9. * Thanks to Afatech who kindly provided information.
  10. *
  11. * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
  12. */
  13. #include "af9005.h"
  14. /* debug */
  15. static int dvb_usb_af9005_remote_debug;
  16. module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);
  17. MODULE_PARM_DESC(debug,
  18. "enable (1) or disable (0) debug messages."
  19. DVB_USB_DEBUG_STATUS);
  20. #define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)
  21. struct rc_map_table rc_map_af9005_table[] = {
  22. {0x01b7, KEY_POWER},
  23. {0x01a7, KEY_VOLUMEUP},
  24. {0x0187, KEY_CHANNELUP},
  25. {0x017f, KEY_MUTE},
  26. {0x01bf, KEY_VOLUMEDOWN},
  27. {0x013f, KEY_CHANNELDOWN},
  28. {0x01df, KEY_1},
  29. {0x015f, KEY_2},
  30. {0x019f, KEY_3},
  31. {0x011f, KEY_4},
  32. {0x01ef, KEY_5},
  33. {0x016f, KEY_6},
  34. {0x01af, KEY_7},
  35. {0x0127, KEY_8},
  36. {0x0107, KEY_9},
  37. {0x01cf, KEY_ZOOM},
  38. {0x014f, KEY_0},
  39. {0x018f, KEY_GOTO}, /* marked jump on the remote */
  40. {0x00bd, KEY_POWER},
  41. {0x007d, KEY_VOLUMEUP},
  42. {0x00fd, KEY_CHANNELUP},
  43. {0x009d, KEY_MUTE},
  44. {0x005d, KEY_VOLUMEDOWN},
  45. {0x00dd, KEY_CHANNELDOWN},
  46. {0x00ad, KEY_1},
  47. {0x006d, KEY_2},
  48. {0x00ed, KEY_3},
  49. {0x008d, KEY_4},
  50. {0x004d, KEY_5},
  51. {0x00cd, KEY_6},
  52. {0x00b5, KEY_7},
  53. {0x0075, KEY_8},
  54. {0x00f5, KEY_9},
  55. {0x0095, KEY_ZOOM},
  56. {0x0055, KEY_0},
  57. {0x00d5, KEY_GOTO}, /* marked jump on the remote */
  58. };
  59. int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);
  60. static int repeatable_keys[] = {
  61. KEY_VOLUMEUP,
  62. KEY_VOLUMEDOWN,
  63. KEY_CHANNELUP,
  64. KEY_CHANNELDOWN
  65. };
  66. int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
  67. int *state)
  68. {
  69. u16 mark, space;
  70. u32 result;
  71. u8 cust, dat, invdat;
  72. int i;
  73. if (len >= 6) {
  74. mark = (u16) (data[0] << 8) + data[1];
  75. space = (u16) (data[2] << 8) + data[3];
  76. if (space * 3 < mark) {
  77. for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {
  78. if (d->last_event == repeatable_keys[i]) {
  79. *state = REMOTE_KEY_REPEAT;
  80. *event = d->last_event;
  81. deb_decode("repeat key, event %x\n",
  82. *event);
  83. return 0;
  84. }
  85. }
  86. deb_decode("repeated key ignored (non repeatable)\n");
  87. return 0;
  88. } else if (len >= 33 * 4) { /*32 bits + start code */
  89. result = 0;
  90. for (i = 4; i < 4 + 32 * 4; i += 4) {
  91. result <<= 1;
  92. mark = (u16) (data[i] << 8) + data[i + 1];
  93. mark >>= 1;
  94. space = (u16) (data[i + 2] << 8) + data[i + 3];
  95. space >>= 1;
  96. if (mark * 2 > space)
  97. result += 1;
  98. }
  99. deb_decode("key pressed, raw value %x\n", result);
  100. if ((result & 0xff000000) != 0xfe000000) {
  101. deb_decode
  102. ("doesn't start with 0xfe, ignored\n");
  103. return 0;
  104. }
  105. cust = (result >> 16) & 0xff;
  106. dat = (result >> 8) & 0xff;
  107. invdat = (~result) & 0xff;
  108. if (dat != invdat) {
  109. deb_decode("code != inverted code\n");
  110. return 0;
  111. }
  112. for (i = 0; i < rc_map_af9005_table_size; i++) {
  113. if (rc5_custom(&rc_map_af9005_table[i]) == cust
  114. && rc5_data(&rc_map_af9005_table[i]) == dat) {
  115. *event = rc_map_af9005_table[i].keycode;
  116. *state = REMOTE_KEY_PRESSED;
  117. deb_decode
  118. ("key pressed, event %x\n", *event);
  119. return 0;
  120. }
  121. }
  122. deb_decode("not found in table\n");
  123. }
  124. }
  125. return 0;
  126. }
  127. EXPORT_SYMBOL(rc_map_af9005_table);
  128. EXPORT_SYMBOL(rc_map_af9005_table_size);
  129. EXPORT_SYMBOL(af9005_rc_decode);
  130. MODULE_AUTHOR("Luca Olivetti <[email protected]>");
  131. MODULE_DESCRIPTION
  132. ("Standard remote control decoder for Afatech 9005 DVB-T USB1.1 stick");
  133. MODULE_VERSION("1.0");
  134. MODULE_LICENSE("GPL");