1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _RC_CORE_PRIV
17#define _RC_CORE_PRIV
18
19
20#define MAX_IR_EVENT_SIZE 512
21
22#include <linux/slab.h>
23#include <media/rc-core.h>
24
25struct ir_raw_handler {
26 struct list_head list;
27
28 u64 protocols;
29 int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
30 int (*encode)(enum rc_proto protocol, u32 scancode,
31 struct ir_raw_event *events, unsigned int max);
32
33
34 int (*raw_register)(struct rc_dev *dev);
35 int (*raw_unregister)(struct rc_dev *dev);
36};
37
38struct ir_raw_event_ctrl {
39 struct list_head list;
40 struct task_struct *thread;
41
42 DECLARE_KFIFO(kfifo, struct ir_raw_event, MAX_IR_EVENT_SIZE);
43 ktime_t last_event;
44 struct rc_dev *dev;
45
46 struct timer_list edge_handle;
47
48
49 struct ir_raw_event prev_ev;
50 struct ir_raw_event this_ev;
51 struct nec_dec {
52 int state;
53 unsigned count;
54 u32 bits;
55 bool is_nec_x;
56 bool necx_repeat;
57 } nec;
58 struct rc5_dec {
59 int state;
60 u32 bits;
61 unsigned count;
62 bool is_rc5x;
63 } rc5;
64 struct rc6_dec {
65 int state;
66 u8 header;
67 u32 body;
68 bool toggle;
69 unsigned count;
70 unsigned wanted_bits;
71 } rc6;
72 struct sony_dec {
73 int state;
74 u32 bits;
75 unsigned count;
76 } sony;
77 struct jvc_dec {
78 int state;
79 u16 bits;
80 u16 old_bits;
81 unsigned count;
82 bool first;
83 bool toggle;
84 } jvc;
85 struct sanyo_dec {
86 int state;
87 unsigned count;
88 u64 bits;
89 } sanyo;
90 struct sharp_dec {
91 int state;
92 unsigned count;
93 u32 bits;
94 unsigned int pulse_len;
95 } sharp;
96 struct mce_kbd_dec {
97 struct input_dev *idev;
98 struct timer_list rx_timeout;
99 char name[64];
100 char phys[64];
101 int state;
102 u8 header;
103 u32 body;
104 unsigned count;
105 unsigned wanted_bits;
106 } mce_kbd;
107 struct lirc_codec {
108 struct rc_dev *dev;
109 struct lirc_driver *drv;
110 int carrier_low;
111
112 ktime_t gap_start;
113 u64 gap_duration;
114 bool gap;
115 bool send_timeout_reports;
116
117 } lirc;
118 struct xmp_dec {
119 int state;
120 unsigned count;
121 u32 durations[16];
122 } xmp;
123};
124
125
126static inline bool geq_margin(unsigned d1, unsigned d2, unsigned margin)
127{
128 return d1 > (d2 - margin);
129}
130
131static inline bool eq_margin(unsigned d1, unsigned d2, unsigned margin)
132{
133 return ((d1 > (d2 - margin)) && (d1 < (d2 + margin)));
134}
135
136static inline bool is_transition(struct ir_raw_event *x, struct ir_raw_event *y)
137{
138 return x->pulse != y->pulse;
139}
140
141static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration)
142{
143 if (duration > ev->duration)
144 ev->duration = 0;
145 else
146 ev->duration -= duration;
147}
148
149
150static inline bool is_timing_event(struct ir_raw_event ev)
151{
152 return !ev.carrier_report && !ev.reset;
153}
154
155#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
156#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
157
158
159
160static inline void init_ir_raw_event_duration(struct ir_raw_event *ev,
161 unsigned int pulse,
162 u32 duration)
163{
164 init_ir_raw_event(ev);
165 ev->duration = duration;
166 ev->pulse = pulse;
167}
168
169
170
171
172
173
174
175
176
177
178
179struct ir_raw_timings_manchester {
180 unsigned int leader;
181 unsigned int pulse_space_start:1;
182 unsigned int clock;
183 unsigned int invert:1;
184 unsigned int trailer_space;
185};
186
187int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
188 const struct ir_raw_timings_manchester *timings,
189 unsigned int n, u64 data);
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204static inline int ir_raw_gen_pulse_space(struct ir_raw_event **ev,
205 unsigned int *max,
206 unsigned int pulse_width,
207 unsigned int space_width)
208{
209 if (!*max)
210 return -ENOBUFS;
211 init_ir_raw_event_duration((*ev)++, 1, pulse_width);
212 if (!--*max)
213 return -ENOBUFS;
214 init_ir_raw_event_duration((*ev)++, 0, space_width);
215 --*max;
216 return 0;
217}
218
219
220
221
222
223
224
225
226
227
228
229struct ir_raw_timings_pd {
230 unsigned int header_pulse;
231 unsigned int header_space;
232 unsigned int bit_pulse;
233 unsigned int bit_space[2];
234 unsigned int trailer_pulse;
235 unsigned int trailer_space;
236 unsigned int msb_first:1;
237};
238
239int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int max,
240 const struct ir_raw_timings_pd *timings,
241 unsigned int n, u64 data);
242
243
244
245
246
247
248
249
250
251struct ir_raw_timings_pl {
252 unsigned int header_pulse;
253 unsigned int bit_space;
254 unsigned int bit_pulse[2];
255 unsigned int trailer_space;
256 unsigned int msb_first:1;
257};
258
259int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max,
260 const struct ir_raw_timings_pl *timings,
261 unsigned int n, u64 data);
262
263
264
265
266u64 ir_raw_get_allowed_protocols(void);
267int ir_raw_event_prepare(struct rc_dev *dev);
268int ir_raw_event_register(struct rc_dev *dev);
269void ir_raw_event_free(struct rc_dev *dev);
270void ir_raw_event_unregister(struct rc_dev *dev);
271int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
272void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
273void ir_raw_init(void);
274
275
276
277
278
279
280
281
282#endif
283