img-ir-hw.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * ImgTec IR Hardware Decoder found in PowerDown Controller.
  3. *
  4. * Copyright 2010-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. #ifndef _IMG_IR_HW_H_
  12. #define _IMG_IR_HW_H_
  13. #include <linux/kernel.h>
  14. #include <media/rc-core.h>
  15. /* constants */
  16. #define IMG_IR_CODETYPE_PULSELEN 0x0 /* Sony */
  17. #define IMG_IR_CODETYPE_PULSEDIST 0x1 /* NEC, Toshiba, Micom, Sharp */
  18. #define IMG_IR_CODETYPE_BIPHASE 0x2 /* RC-5/6 */
  19. #define IMG_IR_CODETYPE_2BITPULSEPOS 0x3 /* RC-MM */
  20. /* Timing information */
  21. /**
  22. * struct img_ir_control - Decoder control settings
  23. * @decoden: Primary decoder enable
  24. * @code_type: Decode type (see IMG_IR_CODETYPE_*)
  25. * @hdrtog: Detect header toggle symbol after leader symbol
  26. * @ldrdec: Don't discard leader if maximum width reached
  27. * @decodinpol: Decoder input polarity (1=active high)
  28. * @bitorien: Bit orientation (1=MSB first)
  29. * @d1validsel: Decoder 2 takes over if it detects valid data
  30. * @bitinv: Bit inversion switch (1=don't invert)
  31. * @decodend2: Secondary decoder enable (no leader symbol)
  32. * @bitoriend2: Bit orientation (1=MSB first)
  33. * @bitinvd2: Secondary decoder bit inversion switch (1=don't invert)
  34. */
  35. struct img_ir_control {
  36. unsigned decoden:1;
  37. unsigned code_type:2;
  38. unsigned hdrtog:1;
  39. unsigned ldrdec:1;
  40. unsigned decodinpol:1;
  41. unsigned bitorien:1;
  42. unsigned d1validsel:1;
  43. unsigned bitinv:1;
  44. unsigned decodend2:1;
  45. unsigned bitoriend2:1;
  46. unsigned bitinvd2:1;
  47. };
  48. /**
  49. * struct img_ir_timing_range - range of timing values
  50. * @min: Minimum timing value
  51. * @max: Maximum timing value (if < @min, this will be set to @min during
  52. * preprocessing step, so it is normally not explicitly initialised
  53. * and is taken care of by the tolerance)
  54. */
  55. struct img_ir_timing_range {
  56. u16 min;
  57. u16 max;
  58. };
  59. /**
  60. * struct img_ir_symbol_timing - timing data for a symbol
  61. * @pulse: Timing range for the length of the pulse in this symbol
  62. * @space: Timing range for the length of the space in this symbol
  63. */
  64. struct img_ir_symbol_timing {
  65. struct img_ir_timing_range pulse;
  66. struct img_ir_timing_range space;
  67. };
  68. /**
  69. * struct img_ir_free_timing - timing data for free time symbol
  70. * @minlen: Minimum number of bits of data
  71. * @maxlen: Maximum number of bits of data
  72. * @ft_min: Minimum free time after message
  73. */
  74. struct img_ir_free_timing {
  75. /* measured in bits */
  76. u8 minlen;
  77. u8 maxlen;
  78. u16 ft_min;
  79. };
  80. /**
  81. * struct img_ir_timings - Timing values.
  82. * @ldr: Leader symbol timing data
  83. * @s00: Zero symbol timing data for primary decoder
  84. * @s01: One symbol timing data for primary decoder
  85. * @s10: Zero symbol timing data for secondary (no leader symbol) decoder
  86. * @s11: One symbol timing data for secondary (no leader symbol) decoder
  87. * @ft: Free time symbol timing data
  88. */
  89. struct img_ir_timings {
  90. struct img_ir_symbol_timing ldr, s00, s01, s10, s11;
  91. struct img_ir_free_timing ft;
  92. };
  93. /**
  94. * struct img_ir_filter - Filter IR events.
  95. * @data: Data to match.
  96. * @mask: Mask of bits to compare.
  97. * @minlen: Additional minimum number of bits.
  98. * @maxlen: Additional maximum number of bits.
  99. */
  100. struct img_ir_filter {
  101. u64 data;
  102. u64 mask;
  103. u8 minlen;
  104. u8 maxlen;
  105. };
  106. /**
  107. * struct img_ir_timing_regvals - Calculated timing register values.
  108. * @ldr: Leader symbol timing register value
  109. * @s00: Zero symbol timing register value for primary decoder
  110. * @s01: One symbol timing register value for primary decoder
  111. * @s10: Zero symbol timing register value for secondary decoder
  112. * @s11: One symbol timing register value for secondary decoder
  113. * @ft: Free time symbol timing register value
  114. */
  115. struct img_ir_timing_regvals {
  116. u32 ldr, s00, s01, s10, s11, ft;
  117. };
  118. #define IMG_IR_SCANCODE 0 /* new scancode */
  119. #define IMG_IR_REPEATCODE 1 /* repeat the previous code */
  120. /**
  121. * struct img_ir_decoder - Decoder settings for an IR protocol.
  122. * @type: Protocol types bitmap.
  123. * @tolerance: Timing tolerance as a percentage (default 10%).
  124. * @unit: Unit of timings in nanoseconds (default 1 us).
  125. * @timings: Primary timings
  126. * @rtimings: Additional override timings while waiting for repeats.
  127. * @repeat: Maximum repeat interval (always in milliseconds).
  128. * @control: Control flags.
  129. *
  130. * @scancode: Pointer to function to convert the IR data into a scancode (it
  131. * must be safe to execute in interrupt context).
  132. * Returns IMG_IR_SCANCODE to emit new scancode.
  133. * Returns IMG_IR_REPEATCODE to repeat previous code.
  134. * Returns -errno (e.g. -EINVAL) on error.
  135. * @filter: Pointer to function to convert scancode filter to raw hardware
  136. * filter. The minlen and maxlen fields will have been initialised
  137. * to the maximum range.
  138. */
  139. struct img_ir_decoder {
  140. /* core description */
  141. u64 type;
  142. unsigned int tolerance;
  143. unsigned int unit;
  144. struct img_ir_timings timings;
  145. struct img_ir_timings rtimings;
  146. unsigned int repeat;
  147. struct img_ir_control control;
  148. /* scancode logic */
  149. int (*scancode)(int len, u64 raw, enum rc_type *protocol,
  150. u32 *scancode, u64 enabled_protocols);
  151. int (*filter)(const struct rc_scancode_filter *in,
  152. struct img_ir_filter *out, u64 protocols);
  153. };
  154. extern struct img_ir_decoder img_ir_nec;
  155. extern struct img_ir_decoder img_ir_jvc;
  156. extern struct img_ir_decoder img_ir_sony;
  157. extern struct img_ir_decoder img_ir_sharp;
  158. extern struct img_ir_decoder img_ir_sanyo;
  159. /**
  160. * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
  161. * @ctrl: Processed control register value.
  162. * @timings: Processed primary timings.
  163. * @rtimings: Processed repeat timings.
  164. */
  165. struct img_ir_reg_timings {
  166. u32 ctrl;
  167. struct img_ir_timing_regvals timings;
  168. struct img_ir_timing_regvals rtimings;
  169. };
  170. int img_ir_register_decoder(struct img_ir_decoder *dec);
  171. void img_ir_unregister_decoder(struct img_ir_decoder *dec);
  172. struct img_ir_priv;
  173. #ifdef CONFIG_IR_IMG_HW
  174. enum img_ir_mode {
  175. IMG_IR_M_NORMAL,
  176. IMG_IR_M_REPEATING,
  177. #ifdef CONFIG_PM_SLEEP
  178. IMG_IR_M_WAKE,
  179. #endif
  180. };
  181. /**
  182. * struct img_ir_priv_hw - Private driver data for hardware decoder.
  183. * @ct_quirks: Quirk bits for each code type.
  184. * @rdev: Remote control device
  185. * @clk_nb: Notifier block for clock notify events.
  186. * @end_timer: Timer until repeat timeout.
  187. * @decoder: Current decoder settings.
  188. * @enabled_protocols: Currently enabled protocols.
  189. * @clk_hz: Current core clock rate in Hz.
  190. * @reg_timings: Timing reg values for decoder at clock rate.
  191. * @flags: IMG_IR_F_*.
  192. * @filters: HW filters (derived from scancode filters).
  193. * @mode: Current decode mode.
  194. * @stopping: Indicates that decoder is being taken down and timers
  195. * should not be restarted.
  196. * @suspend_irqen: Saved IRQ enable mask over suspend.
  197. */
  198. struct img_ir_priv_hw {
  199. unsigned int ct_quirks[4];
  200. struct rc_dev *rdev;
  201. struct notifier_block clk_nb;
  202. struct timer_list end_timer;
  203. const struct img_ir_decoder *decoder;
  204. u64 enabled_protocols;
  205. unsigned long clk_hz;
  206. struct img_ir_reg_timings reg_timings;
  207. unsigned int flags;
  208. struct img_ir_filter filters[RC_FILTER_MAX];
  209. enum img_ir_mode mode;
  210. bool stopping;
  211. u32 suspend_irqen;
  212. };
  213. static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
  214. {
  215. return hw->rdev;
  216. };
  217. void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status);
  218. void img_ir_setup_hw(struct img_ir_priv *priv);
  219. int img_ir_probe_hw(struct img_ir_priv *priv);
  220. void img_ir_remove_hw(struct img_ir_priv *priv);
  221. #ifdef CONFIG_PM_SLEEP
  222. int img_ir_suspend(struct device *dev);
  223. int img_ir_resume(struct device *dev);
  224. #else
  225. #define img_ir_suspend NULL
  226. #define img_ir_resume NULL
  227. #endif
  228. #else
  229. struct img_ir_priv_hw {
  230. };
  231. static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
  232. {
  233. return false;
  234. };
  235. static inline void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status)
  236. {
  237. }
  238. static inline void img_ir_setup_hw(struct img_ir_priv *priv)
  239. {
  240. }
  241. static inline int img_ir_probe_hw(struct img_ir_priv *priv)
  242. {
  243. return -ENODEV;
  244. }
  245. static inline void img_ir_remove_hw(struct img_ir_priv *priv)
  246. {
  247. }
  248. #define img_ir_suspend NULL
  249. #define img_ir_resume NULL
  250. #endif /* CONFIG_IR_IMG_HW */
  251. #endif /* _IMG_IR_HW_H_ */