img-ir-sharp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * ImgTec IR Decoder setup for Sharp 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 Sharp data to a scancode */
  13. static int img_ir_sharp_scancode(int len, u64 raw, u64 enabled_protocols,
  14. struct img_ir_scancode_req *request)
  15. {
  16. unsigned int addr, cmd, exp, chk;
  17. if (len != 15)
  18. return -EINVAL;
  19. addr = (raw >> 0) & 0x1f;
  20. cmd = (raw >> 5) & 0xff;
  21. exp = (raw >> 13) & 0x1;
  22. chk = (raw >> 14) & 0x1;
  23. /* validate data */
  24. if (!exp)
  25. return -EINVAL;
  26. if (chk)
  27. /* probably the second half of the message */
  28. return -EINVAL;
  29. request->protocol = RC_PROTO_SHARP;
  30. request->scancode = addr << 8 | cmd;
  31. return IMG_IR_SCANCODE;
  32. }
  33. /* Convert Sharp scancode to Sharp data filter */
  34. static int img_ir_sharp_filter(const struct rc_scancode_filter *in,
  35. struct img_ir_filter *out, u64 protocols)
  36. {
  37. unsigned int addr, cmd, exp = 0, chk = 0;
  38. unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0;
  39. addr = (in->data >> 8) & 0x1f;
  40. addr_m = (in->mask >> 8) & 0x1f;
  41. cmd = (in->data >> 0) & 0xff;
  42. cmd_m = (in->mask >> 0) & 0xff;
  43. if (cmd_m) {
  44. /* if filtering commands, we can only match the first part */
  45. exp = 1;
  46. exp_m = 1;
  47. chk = 0;
  48. chk_m = 1;
  49. }
  50. out->data = addr |
  51. cmd << 5 |
  52. exp << 13 |
  53. chk << 14;
  54. out->mask = addr_m |
  55. cmd_m << 5 |
  56. exp_m << 13 |
  57. chk_m << 14;
  58. return 0;
  59. }
  60. /*
  61. * Sharp decoder
  62. * See also http://www.sbprojects.com/knowledge/ir/sharp.php
  63. */
  64. struct img_ir_decoder img_ir_sharp = {
  65. .type = RC_PROTO_BIT_SHARP,
  66. .control = {
  67. .decoden = 0,
  68. .decodend2 = 1,
  69. .code_type = IMG_IR_CODETYPE_PULSEDIST,
  70. .d1validsel = 1,
  71. },
  72. /* main timings */
  73. .tolerance = 20, /* 20% */
  74. .timings = {
  75. /* 0 symbol */
  76. .s10 = {
  77. .pulse = { 320 /* 320 us */ },
  78. .space = { 680 /* 1 ms period */ },
  79. },
  80. /* 1 symbol */
  81. .s11 = {
  82. .pulse = { 320 /* 320 us */ },
  83. .space = { 1680 /* 2 ms period */ },
  84. },
  85. /* free time */
  86. .ft = {
  87. .minlen = 15,
  88. .maxlen = 15,
  89. .ft_min = 5000, /* 5 ms */
  90. },
  91. },
  92. /* scancode logic */
  93. .scancode = img_ir_sharp_scancode,
  94. .filter = img_ir_sharp_filter,
  95. };