1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _RC_CORE
17#define _RC_CORE
18
19#include <linux/spinlock.h>
20#include <linux/kfifo.h>
21#include <linux/time.h>
22#include <linux/timer.h>
23#include <media/rc-map.h>
24
25extern int rc_core_debug;
26#define IR_dprintk(level, fmt, ...) \
27do { \
28 if (rc_core_debug >= level) \
29 pr_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
30} while (0)
31
32enum rc_driver_type {
33 RC_DRIVER_SCANCODE = 0,
34 RC_DRIVER_IR_RAW,
35};
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88struct rc_dev {
89 struct device dev;
90 const char *input_name;
91 const char *input_phys;
92 struct input_id input_id;
93 char *driver_name;
94 const char *map_name;
95 struct rc_map rc_map;
96 struct mutex lock;
97 unsigned long devno;
98 struct ir_raw_event_ctrl *raw;
99 struct input_dev *input_dev;
100 enum rc_driver_type driver_type;
101 bool idle;
102 u64 allowed_protos;
103 u64 enabled_protocols;
104 u32 scanmask;
105 void *priv;
106 spinlock_t keylock;
107 bool keypressed;
108 unsigned long keyup_jiffies;
109 struct timer_list timer_keyup;
110 u32 last_keycode;
111 u32 last_scancode;
112 u8 last_toggle;
113 u32 timeout;
114 u32 min_timeout;
115 u32 max_timeout;
116 u32 rx_resolution;
117 u32 tx_resolution;
118 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
119 int (*open)(struct rc_dev *dev);
120 void (*close)(struct rc_dev *dev);
121 int (*s_tx_mask)(struct rc_dev *dev, u32 mask);
122 int (*s_tx_carrier)(struct rc_dev *dev, u32 carrier);
123 int (*s_tx_duty_cycle)(struct rc_dev *dev, u32 duty_cycle);
124 int (*s_rx_carrier_range)(struct rc_dev *dev, u32 min, u32 max);
125 int (*tx_ir)(struct rc_dev *dev, unsigned *txbuf, unsigned n);
126 void (*s_idle)(struct rc_dev *dev, bool enable);
127 int (*s_learning_mode)(struct rc_dev *dev, int enable);
128 int (*s_carrier_report) (struct rc_dev *dev, int enable);
129};
130
131#define to_rc_dev(d) container_of(d, struct rc_dev, dev)
132
133
134
135
136
137
138
139
140struct rc_dev *rc_allocate_device(void);
141void rc_free_device(struct rc_dev *dev);
142int rc_register_device(struct rc_dev *dev);
143void rc_unregister_device(struct rc_dev *dev);
144
145void rc_repeat(struct rc_dev *dev);
146void rc_keydown(struct rc_dev *dev, int scancode, u8 toggle);
147void rc_keydown_notimeout(struct rc_dev *dev, int scancode, u8 toggle);
148void rc_keyup(struct rc_dev *dev);
149u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode);
150
151
152
153
154
155
156
157enum raw_event_type {
158 IR_SPACE = (1 << 0),
159 IR_PULSE = (1 << 1),
160 IR_START_EVENT = (1 << 2),
161 IR_STOP_EVENT = (1 << 3),
162};
163
164struct ir_raw_event {
165 union {
166 u32 duration;
167
168 struct {
169 u32 carrier;
170 u8 duty_cycle;
171 };
172 };
173
174 unsigned pulse:1;
175 unsigned reset:1;
176 unsigned timeout:1;
177 unsigned carrier_report:1;
178};
179
180#define DEFINE_IR_RAW_EVENT(event) \
181 struct ir_raw_event event = { \
182 { .duration = 0 } , \
183 .pulse = 0, \
184 .reset = 0, \
185 .timeout = 0, \
186 .carrier_report = 0 }
187
188static inline void init_ir_raw_event(struct ir_raw_event *ev)
189{
190 memset(ev, 0, sizeof(*ev));
191}
192
193#define IR_MAX_DURATION 0xFFFFFFFF
194#define US_TO_NS(usec) ((usec) * 1000)
195#define MS_TO_US(msec) ((msec) * 1000)
196#define MS_TO_NS(msec) ((msec) * 1000 * 1000)
197
198void ir_raw_event_handle(struct rc_dev *dev);
199int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev);
200int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type);
201int ir_raw_event_store_with_filter(struct rc_dev *dev,
202 struct ir_raw_event *ev);
203void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
204
205static inline void ir_raw_event_reset(struct rc_dev *dev)
206{
207 DEFINE_IR_RAW_EVENT(ev);
208 ev.reset = true;
209
210 ir_raw_event_store(dev, &ev);
211 ir_raw_event_handle(dev);
212}
213
214
215static inline u32 ir_extract_bits(u32 data, u32 mask)
216{
217 u32 vbit = 1, value = 0;
218
219 do {
220 if (mask & 1) {
221 if (data & 1)
222 value |= vbit;
223 vbit <<= 1;
224 }
225 data >>= 1;
226 } while (mask >>= 1);
227
228 return value;
229}
230
231#endif
232