img-ir-hw.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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_scancode_req - Scancode request data.
  122. * @protocol: Protocol code of received message (defaults to
  123. * RC_PROTO_UNKNOWN).
  124. * @scancode: Scan code of received message (must be written by
  125. * handler if IMG_IR_SCANCODE is returned).
  126. * @toggle: Toggle bit (defaults to 0).
  127. */
  128. struct img_ir_scancode_req {
  129. enum rc_proto protocol;
  130. u32 scancode;
  131. u8 toggle;
  132. };
  133. /**
  134. * struct img_ir_decoder - Decoder settings for an IR protocol.
  135. * @type: Protocol types bitmap.
  136. * @tolerance: Timing tolerance as a percentage (default 10%).
  137. * @unit: Unit of timings in nanoseconds (default 1 us).
  138. * @timings: Primary timings
  139. * @rtimings: Additional override timings while waiting for repeats.
  140. * @repeat: Maximum repeat interval (always in milliseconds).
  141. * @control: Control flags.
  142. *
  143. * @scancode: Pointer to function to convert the IR data into a scancode (it
  144. * must be safe to execute in interrupt context).
  145. * Returns IMG_IR_SCANCODE to emit new scancode.
  146. * Returns IMG_IR_REPEATCODE to repeat previous code.
  147. * Returns -errno (e.g. -EINVAL) on error.
  148. * @filter: Pointer to function to convert scancode filter to raw hardware
  149. * filter. The minlen and maxlen fields will have been initialised
  150. * to the maximum range.
  151. */
  152. struct img_ir_decoder {
  153. /* core description */
  154. u64 type;
  155. unsigned int tolerance;
  156. unsigned int unit;
  157. struct img_ir_timings timings;
  158. struct img_ir_timings rtimings;
  159. unsigned int repeat;
  160. struct img_ir_control control;
  161. /* scancode logic */
  162. int (*scancode)(int len, u64 raw, u64 enabled_protocols,
  163. struct img_ir_scancode_req *request);
  164. int (*filter)(const struct rc_scancode_filter *in,
  165. struct img_ir_filter *out, u64 protocols);
  166. };
  167. extern struct img_ir_decoder img_ir_nec;
  168. extern struct img_ir_decoder img_ir_jvc;
  169. extern struct img_ir_decoder img_ir_sony;
  170. extern struct img_ir_decoder img_ir_sharp;
  171. extern struct img_ir_decoder img_ir_sanyo;
  172. extern struct img_ir_decoder img_ir_rc5;
  173. extern struct img_ir_decoder img_ir_rc6;
  174. /**
  175. * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
  176. * @ctrl: Processed control register value.
  177. * @timings: Processed primary timings.
  178. * @rtimings: Processed repeat timings.
  179. */
  180. struct img_ir_reg_timings {
  181. u32 ctrl;
  182. struct img_ir_timing_regvals timings;
  183. struct img_ir_timing_regvals rtimings;
  184. };
  185. struct img_ir_priv;
  186. #ifdef CONFIG_IR_IMG_HW
  187. enum img_ir_mode {
  188. IMG_IR_M_NORMAL,
  189. IMG_IR_M_REPEATING,
  190. #ifdef CONFIG_PM_SLEEP
  191. IMG_IR_M_WAKE,
  192. #endif
  193. };
  194. /**
  195. * struct img_ir_priv_hw - Private driver data for hardware decoder.
  196. * @ct_quirks: Quirk bits for each code type.
  197. * @rdev: Remote control device
  198. * @clk_nb: Notifier block for clock notify events.
  199. * @end_timer: Timer until repeat timeout.
  200. * @suspend_timer: Timer to re-enable protocol.
  201. * @decoder: Current decoder settings.
  202. * @enabled_protocols: Currently enabled protocols.
  203. * @clk_hz: Current core clock rate in Hz.
  204. * @reg_timings: Timing reg values for decoder at clock rate.
  205. * @flags: IMG_IR_F_*.
  206. * @filters: HW filters (derived from scancode filters).
  207. * @mode: Current decode mode.
  208. * @stopping: Indicates that decoder is being taken down and timers
  209. * should not be restarted.
  210. * @suspend_irqen: Saved IRQ enable mask over suspend.
  211. * @quirk_suspend_irq: Saved IRQ enable mask over quirk suspend timer.
  212. */
  213. struct img_ir_priv_hw {
  214. unsigned int ct_quirks[4];
  215. struct rc_dev *rdev;
  216. struct notifier_block clk_nb;
  217. struct timer_list end_timer;
  218. struct timer_list suspend_timer;
  219. const struct img_ir_decoder *decoder;
  220. u64 enabled_protocols;
  221. unsigned long clk_hz;
  222. struct img_ir_reg_timings reg_timings;
  223. unsigned int flags;
  224. struct img_ir_filter filters[RC_FILTER_MAX];
  225. enum img_ir_mode mode;
  226. bool stopping;
  227. u32 suspend_irqen;
  228. u32 quirk_suspend_irq;
  229. };
  230. static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
  231. {
  232. return hw->rdev;
  233. };
  234. void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status);
  235. void img_ir_setup_hw(struct img_ir_priv *priv);
  236. int img_ir_probe_hw(struct img_ir_priv *priv);
  237. void img_ir_remove_hw(struct img_ir_priv *priv);
  238. #ifdef CONFIG_PM_SLEEP
  239. int img_ir_suspend(struct device *dev);
  240. int img_ir_resume(struct device *dev);
  241. #else
  242. #define img_ir_suspend NULL
  243. #define img_ir_resume NULL
  244. #endif
  245. #else
  246. struct img_ir_priv_hw {
  247. };
  248. static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
  249. {
  250. return false;
  251. };
  252. static inline void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status)
  253. {
  254. }
  255. static inline void img_ir_setup_hw(struct img_ir_priv *priv)
  256. {
  257. }
  258. static inline int img_ir_probe_hw(struct img_ir_priv *priv)
  259. {
  260. return -ENODEV;
  261. }
  262. static inline void img_ir_remove_hw(struct img_ir_priv *priv)
  263. {
  264. }
  265. #define img_ir_suspend NULL
  266. #define img_ir_resume NULL
  267. #endif /* CONFIG_IR_IMG_HW */
  268. #endif /* _IMG_IR_HW_H_ */