This source file includes following definitions.
- geq_margin
- eq_margin
- is_transition
- decrease_duration
- is_timing_event
- init_ir_raw_event_duration
- ir_raw_gen_pulse_space
- lirc_dev_init
- lirc_dev_exit
- ir_lirc_raw_event
- ir_lirc_scancode_event
- ir_lirc_register
- ir_lirc_unregister
- lirc_bpf_free
- lirc_bpf_run
1
2
3
4
5
6
7
8 #ifndef _RC_CORE_PRIV
9 #define _RC_CORE_PRIV
10
11 #define RC_DEV_MAX 256
12
13 #define MAX_IR_EVENT_SIZE 512
14
15 #include <linux/slab.h>
16 #include <uapi/linux/bpf.h>
17 #include <media/rc-core.h>
18
19
20
21
22
23
24 int rc_open(struct rc_dev *rdev);
25
26
27
28
29
30
31 void rc_close(struct rc_dev *rdev);
32
33 struct ir_raw_handler {
34 struct list_head list;
35
36 u64 protocols;
37 int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
38 int (*encode)(enum rc_proto protocol, u32 scancode,
39 struct ir_raw_event *events, unsigned int max);
40 u32 carrier;
41 u32 min_timeout;
42
43
44 int (*raw_register)(struct rc_dev *dev);
45 int (*raw_unregister)(struct rc_dev *dev);
46 };
47
48 struct ir_raw_event_ctrl {
49 struct list_head list;
50 struct task_struct *thread;
51
52 DECLARE_KFIFO(kfifo, struct ir_raw_event, MAX_IR_EVENT_SIZE);
53 ktime_t last_event;
54 struct rc_dev *dev;
55
56 spinlock_t edge_spinlock;
57 struct timer_list edge_handle;
58
59
60 struct ir_raw_event prev_ev;
61 struct ir_raw_event this_ev;
62
63 #ifdef CONFIG_BPF_LIRC_MODE2
64 u32 bpf_sample;
65 struct bpf_prog_array __rcu *progs;
66 #endif
67 struct nec_dec {
68 int state;
69 unsigned count;
70 u32 bits;
71 bool is_nec_x;
72 bool necx_repeat;
73 } nec;
74 struct rc5_dec {
75 int state;
76 u32 bits;
77 unsigned count;
78 bool is_rc5x;
79 } rc5;
80 struct rc6_dec {
81 int state;
82 u8 header;
83 u32 body;
84 bool toggle;
85 unsigned count;
86 unsigned wanted_bits;
87 } rc6;
88 struct sony_dec {
89 int state;
90 u32 bits;
91 unsigned count;
92 } sony;
93 struct jvc_dec {
94 int state;
95 u16 bits;
96 u16 old_bits;
97 unsigned count;
98 bool first;
99 bool toggle;
100 } jvc;
101 struct sanyo_dec {
102 int state;
103 unsigned count;
104 u64 bits;
105 } sanyo;
106 struct sharp_dec {
107 int state;
108 unsigned count;
109 u32 bits;
110 unsigned int pulse_len;
111 } sharp;
112 struct mce_kbd_dec {
113
114 spinlock_t keylock;
115 struct timer_list rx_timeout;
116 int state;
117 u8 header;
118 u32 body;
119 unsigned count;
120 unsigned wanted_bits;
121 } mce_kbd;
122 struct xmp_dec {
123 int state;
124 unsigned count;
125 u32 durations[16];
126 } xmp;
127 struct imon_dec {
128 int state;
129 int count;
130 int last_chk;
131 unsigned int bits;
132 bool stick_keyboard;
133 } imon;
134 struct rcmm_dec {
135 int state;
136 unsigned int count;
137 u32 bits;
138 } rcmm;
139 };
140
141
142 extern struct mutex ir_raw_handler_lock;
143
144
145 static inline bool geq_margin(unsigned d1, unsigned d2, unsigned margin)
146 {
147 return d1 > (d2 - margin);
148 }
149
150 static inline bool eq_margin(unsigned d1, unsigned d2, unsigned margin)
151 {
152 return ((d1 > (d2 - margin)) && (d1 < (d2 + margin)));
153 }
154
155 static inline bool is_transition(struct ir_raw_event *x, struct ir_raw_event *y)
156 {
157 return x->pulse != y->pulse;
158 }
159
160 static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration)
161 {
162 if (duration > ev->duration)
163 ev->duration = 0;
164 else
165 ev->duration -= duration;
166 }
167
168
169 static inline bool is_timing_event(struct ir_raw_event ev)
170 {
171 return !ev.carrier_report && !ev.reset;
172 }
173
174 #define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
175 #define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
176
177
178 bool rc_validate_scancode(enum rc_proto proto, u32 scancode);
179
180 static inline void init_ir_raw_event_duration(struct ir_raw_event *ev,
181 unsigned int pulse,
182 u32 duration)
183 {
184 *ev = (struct ir_raw_event) {
185 .duration = duration,
186 .pulse = pulse
187 };
188 }
189
190
191
192
193
194
195
196
197
198
199
200 struct ir_raw_timings_manchester {
201 unsigned int leader_pulse;
202 unsigned int leader_space;
203 unsigned int clock;
204 unsigned int invert:1;
205 unsigned int trailer_space;
206 };
207
208 int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
209 const struct ir_raw_timings_manchester *timings,
210 unsigned int n, u64 data);
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 static inline int ir_raw_gen_pulse_space(struct ir_raw_event **ev,
226 unsigned int *max,
227 unsigned int pulse_width,
228 unsigned int space_width)
229 {
230 if (!*max)
231 return -ENOBUFS;
232 init_ir_raw_event_duration((*ev)++, 1, pulse_width);
233 if (!--*max)
234 return -ENOBUFS;
235 init_ir_raw_event_duration((*ev)++, 0, space_width);
236 --*max;
237 return 0;
238 }
239
240
241
242
243
244
245
246
247
248
249
250 struct ir_raw_timings_pd {
251 unsigned int header_pulse;
252 unsigned int header_space;
253 unsigned int bit_pulse;
254 unsigned int bit_space[2];
255 unsigned int trailer_pulse;
256 unsigned int trailer_space;
257 unsigned int msb_first:1;
258 };
259
260 int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int max,
261 const struct ir_raw_timings_pd *timings,
262 unsigned int n, u64 data);
263
264
265
266
267
268
269
270
271
272 struct ir_raw_timings_pl {
273 unsigned int header_pulse;
274 unsigned int bit_space;
275 unsigned int bit_pulse[2];
276 unsigned int trailer_space;
277 unsigned int msb_first:1;
278 };
279
280 int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max,
281 const struct ir_raw_timings_pl *timings,
282 unsigned int n, u64 data);
283
284
285
286
287 u64 ir_raw_get_allowed_protocols(void);
288 int ir_raw_event_prepare(struct rc_dev *dev);
289 int ir_raw_event_register(struct rc_dev *dev);
290 void ir_raw_event_free(struct rc_dev *dev);
291 void ir_raw_event_unregister(struct rc_dev *dev);
292 int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
293 void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
294 void ir_raw_load_modules(u64 *protocols);
295 void ir_raw_init(void);
296
297
298
299
300 #ifdef CONFIG_LIRC
301 int lirc_dev_init(void);
302 void lirc_dev_exit(void);
303 void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev);
304 void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc);
305 int ir_lirc_register(struct rc_dev *dev);
306 void ir_lirc_unregister(struct rc_dev *dev);
307 struct rc_dev *rc_dev_get_from_fd(int fd);
308 #else
309 static inline int lirc_dev_init(void) { return 0; }
310 static inline void lirc_dev_exit(void) {}
311 static inline void ir_lirc_raw_event(struct rc_dev *dev,
312 struct ir_raw_event ev) { }
313 static inline void ir_lirc_scancode_event(struct rc_dev *dev,
314 struct lirc_scancode *lsc) { }
315 static inline int ir_lirc_register(struct rc_dev *dev) { return 0; }
316 static inline void ir_lirc_unregister(struct rc_dev *dev) { }
317 #endif
318
319
320
321
322 #ifdef CONFIG_BPF_LIRC_MODE2
323 void lirc_bpf_free(struct rc_dev *dev);
324 void lirc_bpf_run(struct rc_dev *dev, u32 sample);
325 #else
326 static inline void lirc_bpf_free(struct rc_dev *dev) { }
327 static inline void lirc_bpf_run(struct rc_dev *dev, u32 sample) { }
328 #endif
329
330 #endif