2 * ImgTec IR Hardware Decoder found in PowerDown Controller.
4 * Copyright 2010-2014 Imagination Technologies Ltd.
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.
15 #include <linux/kernel.h>
16 #include <media/rc-core.h>
20 #define IMG_IR_CODETYPE_PULSELEN 0x0 /* Sony */
21 #define IMG_IR_CODETYPE_PULSEDIST 0x1 /* NEC, Toshiba, Micom, Sharp */
22 #define IMG_IR_CODETYPE_BIPHASE 0x2 /* RC-5/6 */
23 #define IMG_IR_CODETYPE_2BITPULSEPOS 0x3 /* RC-MM */
26 /* Timing information */
29 * struct img_ir_control - Decoder control settings
30 * @decoden: Primary decoder enable
31 * @code_type: Decode type (see IMG_IR_CODETYPE_*)
32 * @hdrtog: Detect header toggle symbol after leader symbol
33 * @ldrdec: Don't discard leader if maximum width reached
34 * @decodinpol: Decoder input polarity (1=active high)
35 * @bitorien: Bit orientation (1=MSB first)
36 * @d1validsel: Decoder 2 takes over if it detects valid data
37 * @bitinv: Bit inversion switch (1=don't invert)
38 * @decodend2: Secondary decoder enable (no leader symbol)
39 * @bitoriend2: Bit orientation (1=MSB first)
40 * @bitinvd2: Secondary decoder bit inversion switch (1=don't invert)
42 struct img_ir_control {
47 unsigned decodinpol:1;
49 unsigned d1validsel:1;
52 unsigned bitoriend2:1;
57 * struct img_ir_timing_range - range of timing values
58 * @min: Minimum timing value
59 * @max: Maximum timing value (if < @min, this will be set to @min during
60 * preprocessing step, so it is normally not explicitly initialised
61 * and is taken care of by the tolerance)
63 struct img_ir_timing_range {
69 * struct img_ir_symbol_timing - timing data for a symbol
70 * @pulse: Timing range for the length of the pulse in this symbol
71 * @space: Timing range for the length of the space in this symbol
73 struct img_ir_symbol_timing {
74 struct img_ir_timing_range pulse;
75 struct img_ir_timing_range space;
79 * struct img_ir_free_timing - timing data for free time symbol
80 * @minlen: Minimum number of bits of data
81 * @maxlen: Maximum number of bits of data
82 * @ft_min: Minimum free time after message
84 struct img_ir_free_timing {
85 /* measured in bits */
92 * struct img_ir_timings - Timing values.
93 * @ldr: Leader symbol timing data
94 * @s00: Zero symbol timing data for primary decoder
95 * @s01: One symbol timing data for primary decoder
96 * @s10: Zero symbol timing data for secondary (no leader symbol) decoder
97 * @s11: One symbol timing data for secondary (no leader symbol) decoder
98 * @ft: Free time symbol timing data
100 struct img_ir_timings {
101 struct img_ir_symbol_timing ldr, s00, s01, s10, s11;
102 struct img_ir_free_timing ft;
106 * struct img_ir_filter - Filter IR events.
107 * @data: Data to match.
108 * @mask: Mask of bits to compare.
109 * @minlen: Additional minimum number of bits.
110 * @maxlen: Additional maximum number of bits.
112 struct img_ir_filter {
120 * struct img_ir_timing_regvals - Calculated timing register values.
121 * @ldr: Leader symbol timing register value
122 * @s00: Zero symbol timing register value for primary decoder
123 * @s01: One symbol timing register value for primary decoder
124 * @s10: Zero symbol timing register value for secondary decoder
125 * @s11: One symbol timing register value for secondary decoder
126 * @ft: Free time symbol timing register value
128 struct img_ir_timing_regvals {
129 u32 ldr, s00, s01, s10, s11, ft;
132 #define IMG_IR_SCANCODE 0 /* new scancode */
133 #define IMG_IR_REPEATCODE 1 /* repeat the previous code */
136 * struct img_ir_decoder - Decoder settings for an IR protocol.
137 * @type: Protocol types bitmap.
138 * @tolerance: Timing tolerance as a percentage (default 10%).
139 * @unit: Unit of timings in nanoseconds (default 1 us).
140 * @timings: Primary timings
141 * @rtimings: Additional override timings while waiting for repeats.
142 * @repeat: Maximum repeat interval (always in milliseconds).
143 * @control: Control flags.
145 * @scancode: Pointer to function to convert the IR data into a scancode (it
146 * must be safe to execute in interrupt context).
147 * Returns IMG_IR_SCANCODE to emit new scancode.
148 * Returns IMG_IR_REPEATCODE to repeat previous code.
149 * Returns -errno (e.g. -EINVAL) on error.
150 * @filter: Pointer to function to convert scancode filter to raw hardware
151 * filter. The minlen and maxlen fields will have been initialised
152 * to the maximum range.
154 struct img_ir_decoder {
155 /* core description */
157 unsigned int tolerance;
159 struct img_ir_timings timings;
160 struct img_ir_timings rtimings;
162 struct img_ir_control control;
165 int (*scancode)(int len, u64 raw, enum rc_type *protocol,
166 u32 *scancode, u64 enabled_protocols);
167 int (*filter)(const struct rc_scancode_filter *in,
168 struct img_ir_filter *out, u64 protocols);
172 * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
173 * @ctrl: Processed control register value.
174 * @timings: Processed primary timings.
175 * @rtimings: Processed repeat timings.
177 struct img_ir_reg_timings {
179 struct img_ir_timing_regvals timings;
180 struct img_ir_timing_regvals rtimings;
183 int img_ir_register_decoder(struct img_ir_decoder *dec);
184 void img_ir_unregister_decoder(struct img_ir_decoder *dec);
188 #ifdef CONFIG_IR_IMG_HW
193 #ifdef CONFIG_PM_SLEEP
199 * struct img_ir_priv_hw - Private driver data for hardware decoder.
200 * @ct_quirks: Quirk bits for each code type.
201 * @rdev: Remote control device
202 * @clk_nb: Notifier block for clock notify events.
203 * @end_timer: Timer until repeat timeout.
204 * @decoder: Current decoder settings.
205 * @enabled_protocols: Currently enabled protocols.
206 * @clk_hz: Current core clock rate in Hz.
207 * @reg_timings: Timing reg values for decoder at clock rate.
208 * @flags: IMG_IR_F_*.
209 * @filters: HW filters (derived from scancode filters).
210 * @mode: Current decode mode.
211 * @suspend_irqen: Saved IRQ enable mask over suspend.
213 struct img_ir_priv_hw {
214 unsigned int ct_quirks[4];
216 struct notifier_block clk_nb;
217 struct timer_list end_timer;
218 const struct img_ir_decoder *decoder;
219 u64 enabled_protocols;
220 unsigned long clk_hz;
221 struct img_ir_reg_timings reg_timings;
223 struct img_ir_filter filters[RC_FILTER_MAX];
225 enum img_ir_mode mode;
229 static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
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);
239 #ifdef CONFIG_PM_SLEEP
240 int img_ir_suspend(struct device *dev);
241 int img_ir_resume(struct device *dev);
243 #define img_ir_suspend NULL
244 #define img_ir_resume NULL
249 struct img_ir_priv_hw {
252 static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
256 static inline void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status)
259 static inline void img_ir_setup_hw(struct img_ir_priv *priv)
262 static inline int img_ir_probe_hw(struct img_ir_priv *priv)
266 static inline void img_ir_remove_hw(struct img_ir_priv *priv)
270 #define img_ir_suspend NULL
271 #define img_ir_resume NULL
273 #endif /* CONFIG_IR_IMG_HW */
275 #endif /* _IMG_IR_HW_H_ */