1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * ImgTec IR Hardware Decoder found in PowerDown Controller.
5 * Copyright 2010-2014 Imagination Technologies Ltd.
11 #include <linux/kernel.h>
12 #include <media/rc-core.h>
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 */
22 /* Timing information */
25 * struct img_ir_control - Decoder control settings
26 * @decoden: Primary decoder enable
27 * @code_type: Decode type (see IMG_IR_CODETYPE_*)
28 * @hdrtog: Detect header toggle symbol after leader symbol
29 * @ldrdec: Don't discard leader if maximum width reached
30 * @decodinpol: Decoder input polarity (1=active high)
31 * @bitorien: Bit orientation (1=MSB first)
32 * @d1validsel: Decoder 2 takes over if it detects valid data
33 * @bitinv: Bit inversion switch (1=don't invert)
34 * @decodend2: Secondary decoder enable (no leader symbol)
35 * @bitoriend2: Bit orientation (1=MSB first)
36 * @bitinvd2: Secondary decoder bit inversion switch (1=don't invert)
38 struct img_ir_control
{
43 unsigned decodinpol
:1;
45 unsigned d1validsel
:1;
48 unsigned bitoriend2
:1;
53 * struct img_ir_timing_range - range of timing values
54 * @min: Minimum timing value
55 * @max: Maximum timing value (if < @min, this will be set to @min during
56 * preprocessing step, so it is normally not explicitly initialised
57 * and is taken care of by the tolerance)
59 struct img_ir_timing_range
{
65 * struct img_ir_symbol_timing - timing data for a symbol
66 * @pulse: Timing range for the length of the pulse in this symbol
67 * @space: Timing range for the length of the space in this symbol
69 struct img_ir_symbol_timing
{
70 struct img_ir_timing_range pulse
;
71 struct img_ir_timing_range space
;
75 * struct img_ir_free_timing - timing data for free time symbol
76 * @minlen: Minimum number of bits of data
77 * @maxlen: Maximum number of bits of data
78 * @ft_min: Minimum free time after message
80 struct img_ir_free_timing
{
81 /* measured in bits */
88 * struct img_ir_timings - Timing values.
89 * @ldr: Leader symbol timing data
90 * @s00: Zero symbol timing data for primary decoder
91 * @s01: One symbol timing data for primary decoder
92 * @s10: Zero symbol timing data for secondary (no leader symbol) decoder
93 * @s11: One symbol timing data for secondary (no leader symbol) decoder
94 * @ft: Free time symbol timing data
96 struct img_ir_timings
{
97 struct img_ir_symbol_timing ldr
, s00
, s01
, s10
, s11
;
98 struct img_ir_free_timing ft
;
102 * struct img_ir_filter - Filter IR events.
103 * @data: Data to match.
104 * @mask: Mask of bits to compare.
105 * @minlen: Additional minimum number of bits.
106 * @maxlen: Additional maximum number of bits.
108 struct img_ir_filter
{
116 * struct img_ir_timing_regvals - Calculated timing register values.
117 * @ldr: Leader symbol timing register value
118 * @s00: Zero symbol timing register value for primary decoder
119 * @s01: One symbol timing register value for primary decoder
120 * @s10: Zero symbol timing register value for secondary decoder
121 * @s11: One symbol timing register value for secondary decoder
122 * @ft: Free time symbol timing register value
124 struct img_ir_timing_regvals
{
125 u32 ldr
, s00
, s01
, s10
, s11
, ft
;
128 #define IMG_IR_SCANCODE 0 /* new scancode */
129 #define IMG_IR_REPEATCODE 1 /* repeat the previous code */
132 * struct img_ir_scancode_req - Scancode request data.
133 * @protocol: Protocol code of received message (defaults to
135 * @scancode: Scan code of received message (must be written by
136 * handler if IMG_IR_SCANCODE is returned).
137 * @toggle: Toggle bit (defaults to 0).
139 struct img_ir_scancode_req
{
140 enum rc_proto protocol
;
146 * struct img_ir_decoder - Decoder settings for an IR protocol.
147 * @type: Protocol types bitmap.
148 * @tolerance: Timing tolerance as a percentage (default 10%).
149 * @unit: Unit of timings in nanoseconds (default 1 us).
150 * @timings: Primary timings
151 * @rtimings: Additional override timings while waiting for repeats.
152 * @repeat: Maximum repeat interval (always in milliseconds).
153 * @control: Control flags.
155 * @scancode: Pointer to function to convert the IR data into a scancode (it
156 * must be safe to execute in interrupt context).
157 * Returns IMG_IR_SCANCODE to emit new scancode.
158 * Returns IMG_IR_REPEATCODE to repeat previous code.
159 * Returns -errno (e.g. -EINVAL) on error.
160 * @filter: Pointer to function to convert scancode filter to raw hardware
161 * filter. The minlen and maxlen fields will have been initialised
162 * to the maximum range.
164 struct img_ir_decoder
{
165 /* core description */
167 unsigned int tolerance
;
169 struct img_ir_timings timings
;
170 struct img_ir_timings rtimings
;
172 struct img_ir_control control
;
175 int (*scancode
)(int len
, u64 raw
, u64 enabled_protocols
,
176 struct img_ir_scancode_req
*request
);
177 int (*filter
)(const struct rc_scancode_filter
*in
,
178 struct img_ir_filter
*out
, u64 protocols
);
181 extern struct img_ir_decoder img_ir_nec
;
182 extern struct img_ir_decoder img_ir_jvc
;
183 extern struct img_ir_decoder img_ir_sony
;
184 extern struct img_ir_decoder img_ir_sharp
;
185 extern struct img_ir_decoder img_ir_sanyo
;
186 extern struct img_ir_decoder img_ir_rc5
;
187 extern struct img_ir_decoder img_ir_rc6
;
190 * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
191 * @ctrl: Processed control register value.
192 * @timings: Processed primary timings.
193 * @rtimings: Processed repeat timings.
195 struct img_ir_reg_timings
{
197 struct img_ir_timing_regvals timings
;
198 struct img_ir_timing_regvals rtimings
;
203 #ifdef CONFIG_IR_IMG_HW
208 #ifdef CONFIG_PM_SLEEP
214 * struct img_ir_priv_hw - Private driver data for hardware decoder.
215 * @ct_quirks: Quirk bits for each code type.
216 * @rdev: Remote control device
217 * @clk_nb: Notifier block for clock notify events.
218 * @end_timer: Timer until repeat timeout.
219 * @suspend_timer: Timer to re-enable protocol.
220 * @decoder: Current decoder settings.
221 * @enabled_protocols: Currently enabled protocols.
222 * @clk_hz: Current core clock rate in Hz.
223 * @reg_timings: Timing reg values for decoder at clock rate.
224 * @flags: IMG_IR_F_*.
225 * @filters: HW filters (derived from scancode filters).
226 * @mode: Current decode mode.
227 * @stopping: Indicates that decoder is being taken down and timers
228 * should not be restarted.
229 * @suspend_irqen: Saved IRQ enable mask over suspend.
230 * @quirk_suspend_irq: Saved IRQ enable mask over quirk suspend timer.
232 struct img_ir_priv_hw
{
233 unsigned int ct_quirks
[4];
235 struct notifier_block clk_nb
;
236 struct timer_list end_timer
;
237 struct timer_list suspend_timer
;
238 const struct img_ir_decoder
*decoder
;
239 u64 enabled_protocols
;
240 unsigned long clk_hz
;
241 struct img_ir_reg_timings reg_timings
;
243 struct img_ir_filter filters
[RC_FILTER_MAX
];
245 enum img_ir_mode mode
;
248 u32 quirk_suspend_irq
;
251 static inline bool img_ir_hw_enabled(struct img_ir_priv_hw
*hw
)
256 void img_ir_isr_hw(struct img_ir_priv
*priv
, u32 irq_status
);
257 void img_ir_setup_hw(struct img_ir_priv
*priv
);
258 int img_ir_probe_hw(struct img_ir_priv
*priv
);
259 void img_ir_remove_hw(struct img_ir_priv
*priv
);
261 #ifdef CONFIG_PM_SLEEP
262 int img_ir_suspend(struct device
*dev
);
263 int img_ir_resume(struct device
*dev
);
265 #define img_ir_suspend NULL
266 #define img_ir_resume NULL
271 struct img_ir_priv_hw
{
274 static inline bool img_ir_hw_enabled(struct img_ir_priv_hw
*hw
)
278 static inline void img_ir_isr_hw(struct img_ir_priv
*priv
, u32 irq_status
)
281 static inline void img_ir_setup_hw(struct img_ir_priv
*priv
)
284 static inline int img_ir_probe_hw(struct img_ir_priv
*priv
)
288 static inline void img_ir_remove_hw(struct img_ir_priv
*priv
)
292 #define img_ir_suspend NULL
293 #define img_ir_resume NULL
295 #endif /* CONFIG_IR_IMG_HW */
297 #endif /* _IMG_IR_HW_H_ */