img-ir-rc5.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * ImgTec IR Decoder setup for Philips RC-5 protocol.
  3. *
  4. * Copyright 2012-2014 Imagination Technologies Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include "img-ir-hw.h"
  12. /* Convert RC5 data to a scancode */
  13. static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
  14. struct img_ir_scancode_req *request)
  15. {
  16. unsigned int addr, cmd, tgl, start;
  17. /* Quirk in the decoder shifts everything by 2 to the left. */
  18. raw >>= 2;
  19. start = (raw >> 13) & 0x01;
  20. tgl = (raw >> 11) & 0x01;
  21. addr = (raw >> 6) & 0x1f;
  22. cmd = raw & 0x3f;
  23. /*
  24. * 12th bit is used to extend the command in extended RC5 and has
  25. * no effect on standard RC5.
  26. */
  27. cmd += ((raw >> 12) & 0x01) ? 0 : 0x40;
  28. if (!start)
  29. return -EINVAL;
  30. request->protocol = RC_PROTO_RC5;
  31. request->scancode = addr << 8 | cmd;
  32. request->toggle = tgl;
  33. return IMG_IR_SCANCODE;
  34. }
  35. /* Convert RC5 scancode to RC5 data filter */
  36. static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
  37. struct img_ir_filter *out, u64 protocols)
  38. {
  39. /* Not supported by the hw. */
  40. return -EINVAL;
  41. }
  42. /*
  43. * RC-5 decoder
  44. * see http://www.sbprojects.com/knowledge/ir/rc5.php
  45. */
  46. struct img_ir_decoder img_ir_rc5 = {
  47. .type = RC_PROTO_BIT_RC5,
  48. .control = {
  49. .bitoriend2 = 1,
  50. .code_type = IMG_IR_CODETYPE_BIPHASE,
  51. .decodend2 = 1,
  52. },
  53. /* main timings */
  54. .tolerance = 16,
  55. .unit = 888888, /* 1/36k*32=888.888microseconds */
  56. .timings = {
  57. /* 10 symbol */
  58. .s10 = {
  59. .pulse = { 1 },
  60. .space = { 1 },
  61. },
  62. /* 11 symbol */
  63. .s11 = {
  64. .pulse = { 1 },
  65. .space = { 1 },
  66. },
  67. /* free time */
  68. .ft = {
  69. .minlen = 14,
  70. .maxlen = 14,
  71. .ft_min = 5,
  72. },
  73. },
  74. /* scancode logic */
  75. .scancode = img_ir_rc5_scancode,
  76. .filter = img_ir_rc5_filter,
  77. };