img-ir-sanyo.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * ImgTec IR Decoder setup for Sanyo 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. * From ir-sanyo-decoder.c:
  12. *
  13. * This protocol uses the NEC protocol timings. However, data is formatted as:
  14. * 13 bits Custom Code
  15. * 13 bits NOT(Custom Code)
  16. * 8 bits Key data
  17. * 8 bits NOT(Key data)
  18. *
  19. * According with LIRC, this protocol is used on Sanyo, Aiwa and Chinon
  20. * Information for this protocol is available at the Sanyo LC7461 datasheet.
  21. */
  22. #include "img-ir-hw.h"
  23. /* Convert Sanyo data to a scancode */
  24. static int img_ir_sanyo_scancode(int len, u64 raw, u64 enabled_protocols,
  25. struct img_ir_scancode_req *request)
  26. {
  27. unsigned int addr, addr_inv, data, data_inv;
  28. /* a repeat code has no data */
  29. if (!len)
  30. return IMG_IR_REPEATCODE;
  31. if (len != 42)
  32. return -EINVAL;
  33. addr = (raw >> 0) & 0x1fff;
  34. addr_inv = (raw >> 13) & 0x1fff;
  35. data = (raw >> 26) & 0xff;
  36. data_inv = (raw >> 34) & 0xff;
  37. /* Validate data */
  38. if ((data_inv ^ data) != 0xff)
  39. return -EINVAL;
  40. /* Validate address */
  41. if ((addr_inv ^ addr) != 0x1fff)
  42. return -EINVAL;
  43. /* Normal Sanyo */
  44. request->protocol = RC_PROTO_SANYO;
  45. request->scancode = addr << 8 | data;
  46. return IMG_IR_SCANCODE;
  47. }
  48. /* Convert Sanyo scancode to Sanyo data filter */
  49. static int img_ir_sanyo_filter(const struct rc_scancode_filter *in,
  50. struct img_ir_filter *out, u64 protocols)
  51. {
  52. unsigned int addr, addr_inv, data, data_inv;
  53. unsigned int addr_m, data_m;
  54. data = in->data & 0xff;
  55. data_m = in->mask & 0xff;
  56. data_inv = data ^ 0xff;
  57. if (in->data & 0xff700000)
  58. return -EINVAL;
  59. addr = (in->data >> 8) & 0x1fff;
  60. addr_m = (in->mask >> 8) & 0x1fff;
  61. addr_inv = addr ^ 0x1fff;
  62. out->data = (u64)data_inv << 34 |
  63. (u64)data << 26 |
  64. addr_inv << 13 |
  65. addr;
  66. out->mask = (u64)data_m << 34 |
  67. (u64)data_m << 26 |
  68. addr_m << 13 |
  69. addr_m;
  70. return 0;
  71. }
  72. /* Sanyo decoder */
  73. struct img_ir_decoder img_ir_sanyo = {
  74. .type = RC_PROTO_BIT_SANYO,
  75. .control = {
  76. .decoden = 1,
  77. .code_type = IMG_IR_CODETYPE_PULSEDIST,
  78. },
  79. /* main timings */
  80. .unit = 562500, /* 562.5 us */
  81. .timings = {
  82. /* leader symbol */
  83. .ldr = {
  84. .pulse = { 16 /* 9ms */ },
  85. .space = { 8 /* 4.5ms */ },
  86. },
  87. /* 0 symbol */
  88. .s00 = {
  89. .pulse = { 1 /* 562.5 us */ },
  90. .space = { 1 /* 562.5 us */ },
  91. },
  92. /* 1 symbol */
  93. .s01 = {
  94. .pulse = { 1 /* 562.5 us */ },
  95. .space = { 3 /* 1687.5 us */ },
  96. },
  97. /* free time */
  98. .ft = {
  99. .minlen = 42,
  100. .maxlen = 42,
  101. .ft_min = 10, /* 5.625 ms */
  102. },
  103. },
  104. /* repeat codes */
  105. .repeat = 108, /* 108 ms */
  106. .rtimings = {
  107. /* leader symbol */
  108. .ldr = {
  109. .space = { 4 /* 2.25 ms */ },
  110. },
  111. /* free time */
  112. .ft = {
  113. .minlen = 0, /* repeat code has no data */
  114. .maxlen = 0,
  115. },
  116. },
  117. /* scancode logic */
  118. .scancode = img_ir_sanyo_scancode,
  119. .filter = img_ir_sanyo_filter,
  120. };