Blame view
include/media/rc-core.h
12.3 KB
8e8e69d67
|
1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
446e4a64d
|
2 3 4 |
/* * Remote Controller core header * |
37e59f876
|
5 |
* Copyright (C) 2009-2010 by Mauro Carvalho Chehab |
446e4a64d
|
6 |
*/ |
ca86674b8
|
7 8 |
#ifndef _RC_CORE #define _RC_CORE |
446e4a64d
|
9 |
|
446e4a64d
|
10 |
#include <linux/spinlock.h> |
a6ddd4fec
|
11 |
#include <linux/cdev.h> |
a3572c34d
|
12 13 |
#include <linux/kfifo.h> #include <linux/time.h> |
9f1547829
|
14 |
#include <linux/timer.h> |
02858eedc
|
15 |
#include <media/rc-map.h> |
446e4a64d
|
16 |
|
5b6137dc8
|
17 |
/** |
f4ab70e3d
|
18 |
* enum rc_driver_type - type of the RC driver. |
5b6137dc8
|
19 |
* |
f4ab70e3d
|
20 |
* @RC_DRIVER_SCANCODE: Driver or hardware generates a scancode. |
d34aee101
|
21 22 23 24 |
* @RC_DRIVER_IR_RAW: Driver or hardware generates pulse/space sequences. * It needs a Infra-Red pulse/space decoder * @RC_DRIVER_IR_RAW_TX: Device transmitter only, * driver requires pulse/space data sequence. |
5b6137dc8
|
25 |
*/ |
626cf6979
|
26 |
enum rc_driver_type { |
5b6137dc8
|
27 28 |
RC_DRIVER_SCANCODE = 0, RC_DRIVER_IR_RAW, |
d34aee101
|
29 |
RC_DRIVER_IR_RAW_TX, |
626cf6979
|
30 |
}; |
9dfe4e833
|
31 |
/** |
00942d1a1
|
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
* struct rc_scancode_filter - Filter scan codes. * @data: Scancode data to match. * @mask: Mask of bits of scancode to compare. */ struct rc_scancode_filter { u32 data; u32 mask; }; /** * enum rc_filter_type - Filter type constants. * @RC_FILTER_NORMAL: Filter for normal operation. * @RC_FILTER_WAKEUP: Filter for waking from suspend. * @RC_FILTER_MAX: Number of filter types. */ enum rc_filter_type { RC_FILTER_NORMAL = 0, RC_FILTER_WAKEUP, RC_FILTER_MAX }; /** |
7e45d660e
|
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 |
* struct lirc_fh - represents an open lirc file * @list: list of open file handles * @rc: rcdev for this lirc chardev * @carrier_low: when setting the carrier range, first the low end must be * set with an ioctl and then the high end with another ioctl * @send_timeout_reports: report timeouts in lirc raw IR. * @rawir: queue for incoming raw IR * @scancodes: queue for incoming decoded scancodes * @wait_poll: poll struct for lirc device * @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or * LIRC_MODE_PULSE * @rec_mode: lirc mode for receiving, either LIRC_MODE_SCANCODE or * LIRC_MODE_MODE2 */ struct lirc_fh { struct list_head list; struct rc_dev *rc; int carrier_low; bool send_timeout_reports; DECLARE_KFIFO_PTR(rawir, unsigned int); DECLARE_KFIFO_PTR(scancodes, struct lirc_scancode); wait_queue_head_t wait_poll; u8 send_mode; u8 rec_mode; }; /** |
d8b4b5822
|
82 83 |
* struct rc_dev - represents a remote control device * @dev: driver model's view of this device |
ddbf7d5a6
|
84 |
* @managed_alloc: devm_rc_allocate_device was used to create rc_dev |
99b0f3c96
|
85 |
* @sysfs_groups: sysfs attribute groups |
518f4b26b
|
86 |
* @device_name: name of the rc child device |
d8b4b5822
|
87 88 89 90 |
* @input_phys: physical path to the input child device * @input_id: id of the input child device (struct input_id) * @driver_name: name of the hardware driver which registered this device * @map_name: name of the default keymap |
b088ba658
|
91 |
* @rc_map: current scan/key table |
08aeb7c9a
|
92 93 |
* @lock: used to ensure we've filled in all protocol details before * anyone can call show_protocols or store_protocols |
fcb130978
|
94 |
* @minor: unique minor remote control device number |
d8b4b5822
|
95 96 |
* @raw: additional data for raw pulse/space devices * @input_dev: the input child device used to communicate events to userspace |
08aeb7c9a
|
97 |
* @driver_type: specifies if protocol decoding is done in hardware or software |
d8b4b5822
|
98 |
* @idle: used to keep track of RX state |
f423ccc1a
|
99 100 |
* @encode_wakeup: wakeup filtering uses IR encode API, therefore the allowed * wakeup protocols is the set of all raw encoders |
6d741bfed
|
101 102 103 104 105 106 |
* @allowed_protocols: bitmask with the supported RC_PROTO_BIT_* protocols * @enabled_protocols: bitmask with the enabled RC_PROTO_BIT_* protocols * @allowed_wakeup_protocols: bitmask with the supported RC_PROTO_BIT_* wakeup * protocols * @wakeup_protocol: the enabled RC_PROTO_* wakeup protocol or * RC_PROTO_UNKNOWN if disabled. |
c5540fbb9
|
107 108 |
* @scancode_filter: scancode filter * @scancode_wakeup_filter: scancode wakeup filters |
9d2f1d3cd
|
109 |
* @scancode_mask: some hardware decoders are not capable of providing the full |
9dfe4e833
|
110 111 112 113 |
* scancode to the application. As this is a hardware limit, we can't do * anything with it. Yet, as the same keycode table can be used with other * devices, a mask is provided to allow its usage. Drivers should generally * leave this field in blank |
9d2f1d3cd
|
114 |
* @users: number of current users of the device |
d8b4b5822
|
115 116 117 118 119 |
* @priv: driver-specific data * @keylock: protects the remaining members of the struct * @keypressed: whether a key is currently pressed * @keyup_jiffies: time (in jiffies) when the current keypress should be released * @timer_keyup: timer for releasing a keypress |
57c642cb4
|
120 121 |
* @timer_repeat: timer for autorepeat events. This is needed for CEC, which * has non-standard repeats. |
d8b4b5822
|
122 |
* @last_keycode: keycode of last keypress |
120703f9e
|
123 |
* @last_protocol: protocol of last keypress |
d8b4b5822
|
124 125 |
* @last_scancode: scancode of last keypress * @last_toggle: toggle value of last command |
4a702ebf6
|
126 127 128 |
* @timeout: optional time after which device stops sending data * @min_timeout: minimum timeout supported by device * @max_timeout: maximum timeout supported by device |
e589333f3
|
129 130 |
* @rx_resolution : resolution (in ns) of input sampler * @tx_resolution: resolution (in ns) of output sampler |
a6ddd4fec
|
131 132 |
* @lirc_dev: lirc device * @lirc_cdev: lirc char cdev |
a60d64b15
|
133 134 135 |
* @gap_start: time when gap starts * @gap_duration: duration of initial gap * @gap: true if we're in a gap |
7e45d660e
|
136 137 |
* @lirc_fh_lock: protects lirc_fh list * @lirc_fh: list of open files |
7790e81f7
|
138 139 |
* @registered: set to true by rc_register_device(), false by * rc_unregister_device |
9dfe4e833
|
140 141 142 143 144 |
* @change_protocol: allow changing the protocol used on hardware decoders * @open: callback to allow drivers to enable polling/irq when IR input device * is opened. * @close: callback to allow drivers to disable polling/irq when IR input device * is opened. |
9b7c54d92
|
145 146 |
* @s_tx_mask: set transmitter mask (for devices with multiple tx outputs) * @s_tx_carrier: set transmit carrier frequency |
e589333f3
|
147 |
* @s_tx_duty_cycle: set transmit duty cycle (0% - 100%) |
fa810845e
|
148 |
* @s_rx_carrier_range: inform driver about carrier it is expected to handle |
9b7c54d92
|
149 |
* @tx_ir: transmit IR |
d8b4b5822
|
150 151 |
* @s_idle: enable/disable hardware idle mode, upon which, * device doesn't interrupt host until it sees IR pulses |
e589333f3
|
152 |
* @s_learning_mode: enable wide band receiver used for learning |
4651918a4
|
153 |
* @s_carrier_report: enable carrier reports |
120703f9e
|
154 |
* @s_filter: set the scancode filter |
0751d33c2
|
155 156 157 |
* @s_wakeup_filter: set the wakeup scancode filter. If the mask is zero * then wakeup should be disabled. wakeup_protocol will be set to * a valid protocol if mask is nonzero. |
4f253cecf
|
158 |
* @s_timeout: set hardware timeout in ns |
9dfe4e833
|
159 |
*/ |
d8b4b5822
|
160 161 |
struct rc_dev { struct device dev; |
ddbf7d5a6
|
162 |
bool managed_alloc; |
99b0f3c96
|
163 |
const struct attribute_group *sysfs_groups[5]; |
518f4b26b
|
164 |
const char *device_name; |
d8b4b5822
|
165 166 |
const char *input_phys; struct input_id input_id; |
518f4b26b
|
167 |
const char *driver_name; |
d8b4b5822
|
168 |
const char *map_name; |
08aeb7c9a
|
169 170 |
struct rc_map rc_map; struct mutex lock; |
fcb130978
|
171 |
unsigned int minor; |
d8b4b5822
|
172 173 174 |
struct ir_raw_event_ctrl *raw; struct input_dev *input_dev; enum rc_driver_type driver_type; |
4a702ebf6
|
175 |
bool idle; |
f423ccc1a
|
176 |
bool encode_wakeup; |
c5540fbb9
|
177 178 179 |
u64 allowed_protocols; u64 enabled_protocols; u64 allowed_wakeup_protocols; |
6d741bfed
|
180 |
enum rc_proto wakeup_protocol; |
c5540fbb9
|
181 182 |
struct rc_scancode_filter scancode_filter; struct rc_scancode_filter scancode_wakeup_filter; |
9d2f1d3cd
|
183 |
u32 scancode_mask; |
8b2ff3204
|
184 |
u32 users; |
d8b4b5822
|
185 186 187 188 189 |
void *priv; spinlock_t keylock; bool keypressed; unsigned long keyup_jiffies; struct timer_list timer_keyup; |
57c642cb4
|
190 |
struct timer_list timer_repeat; |
d8b4b5822
|
191 |
u32 last_keycode; |
6d741bfed
|
192 |
enum rc_proto last_protocol; |
d8b4b5822
|
193 194 195 196 197 198 199 |
u32 last_scancode; u8 last_toggle; u32 timeout; u32 min_timeout; u32 max_timeout; u32 rx_resolution; u32 tx_resolution; |
a60d64b15
|
200 |
#ifdef CONFIG_LIRC |
a6ddd4fec
|
201 202 |
struct device lirc_dev; struct cdev lirc_cdev; |
a60d64b15
|
203 204 205 |
ktime_t gap_start; u64 gap_duration; bool gap; |
7e45d660e
|
206 207 |
spinlock_t lirc_fh_lock; struct list_head lirc_fh; |
a60d64b15
|
208 |
#endif |
7790e81f7
|
209 |
bool registered; |
6d741bfed
|
210 |
int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto); |
d8b4b5822
|
211 212 213 214 215 216 |
int (*open)(struct rc_dev *dev); void (*close)(struct rc_dev *dev); int (*s_tx_mask)(struct rc_dev *dev, u32 mask); int (*s_tx_carrier)(struct rc_dev *dev, u32 carrier); int (*s_tx_duty_cycle)(struct rc_dev *dev, u32 duty_cycle); int (*s_rx_carrier_range)(struct rc_dev *dev, u32 min, u32 max); |
5588dc2b0
|
217 |
int (*tx_ir)(struct rc_dev *dev, unsigned *txbuf, unsigned n); |
d8b4b5822
|
218 219 220 |
void (*s_idle)(struct rc_dev *dev, bool enable); int (*s_learning_mode)(struct rc_dev *dev, int enable); int (*s_carrier_report) (struct rc_dev *dev, int enable); |
00942d1a1
|
221 |
int (*s_filter)(struct rc_dev *dev, |
00942d1a1
|
222 |
struct rc_scancode_filter *filter); |
23c843b5e
|
223 224 |
int (*s_wakeup_filter)(struct rc_dev *dev, struct rc_scancode_filter *filter); |
4f253cecf
|
225 226 |
int (*s_timeout)(struct rc_dev *dev, unsigned int timeout); |
75543cce0
|
227 |
}; |
a3572c34d
|
228 |
|
ca86674b8
|
229 230 231 232 233 234 235 236 |
#define to_rc_dev(d) container_of(d, struct rc_dev, dev) /* * From rc-main.c * Those functions can be used on any type of Remote Controller. They * basically creates an input_dev and properly reports the device as a * Remote Controller, at sys/class/rc. */ |
5b6137dc8
|
237 238 239 |
/** * rc_allocate_device - Allocates a RC device * |
0f7499fdd
|
240 |
* @rc_driver_type: specifies the type of the RC output to be allocated |
5b6137dc8
|
241 242 |
* returns a pointer to struct rc_dev. */ |
0f7499fdd
|
243 |
struct rc_dev *rc_allocate_device(enum rc_driver_type); |
5b6137dc8
|
244 245 |
/** |
ddbf7d5a6
|
246 247 248 |
* devm_rc_allocate_device - Managed RC device allocation * * @dev: pointer to struct device |
0f7499fdd
|
249 |
* @rc_driver_type: specifies the type of the RC output to be allocated |
ddbf7d5a6
|
250 251 |
* returns a pointer to struct rc_dev. */ |
0f7499fdd
|
252 |
struct rc_dev *devm_rc_allocate_device(struct device *dev, enum rc_driver_type); |
ddbf7d5a6
|
253 254 |
/** |
5b6137dc8
|
255 256 257 258 |
* rc_free_device - Frees a RC device * * @dev: pointer to struct rc_dev. */ |
ca86674b8
|
259 |
void rc_free_device(struct rc_dev *dev); |
5b6137dc8
|
260 261 262 263 264 265 |
/** * rc_register_device - Registers a RC device * * @dev: pointer to struct rc_dev. */ |
ca86674b8
|
266 |
int rc_register_device(struct rc_dev *dev); |
5b6137dc8
|
267 268 |
/** |
ddbf7d5a6
|
269 270 271 272 273 274 275 276 |
* devm_rc_register_device - Manageded registering of a RC device * * @parent: pointer to struct device. * @dev: pointer to struct rc_dev. */ int devm_rc_register_device(struct device *parent, struct rc_dev *dev); /** |
5b6137dc8
|
277 278 279 280 |
* rc_unregister_device - Unregisters a RC device * * @dev: pointer to struct rc_dev. */ |
ca86674b8
|
281 282 283 |
void rc_unregister_device(struct rc_dev *dev); void rc_repeat(struct rc_dev *dev); |
6d741bfed
|
284 285 286 287 |
void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u32 scancode, u8 toggle); void rc_keydown_notimeout(struct rc_dev *dev, enum rc_proto protocol, u32 scancode, u8 toggle); |
ca86674b8
|
288 289 290 291 292 293 294 295 |
void rc_keyup(struct rc_dev *dev); u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode); /* * From rc-raw.c * The Raw interface is specific to InfraRed. It may be a good idea to * split it later into a separate header. */ |
e40b1127f
|
296 |
struct ir_raw_event { |
4651918a4
|
297 298 |
union { u32 duration; |
5f61ff861
|
299 |
u32 carrier; |
4651918a4
|
300 |
}; |
5f61ff861
|
301 |
u8 duty_cycle; |
4651918a4
|
302 303 304 305 306 |
unsigned pulse:1; unsigned reset:1; unsigned timeout:1; unsigned carrier_report:1; |
e40b1127f
|
307 |
}; |
c8e1bbc52
|
308 |
#define IR_DEFAULT_TIMEOUT MS_TO_NS(125) |
6b20cf3c0
|
309 |
#define IR_MAX_DURATION 500000000 /* 500 ms */ |
5aad72428
|
310 311 312 |
#define US_TO_NS(usec) ((usec) * 1000) #define MS_TO_US(msec) ((msec) * 1000) #define MS_TO_NS(msec) ((msec) * 1000 * 1000) |
e40b1127f
|
313 |
|
d8b4b5822
|
314 315 |
void ir_raw_event_handle(struct rc_dev *dev); int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev); |
86fe1ac0d
|
316 |
int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse); |
d8b4b5822
|
317 |
int ir_raw_event_store_with_filter(struct rc_dev *dev, |
8d7a77ce5
|
318 319 320 |
struct ir_raw_event *ev); int ir_raw_event_store_with_timeout(struct rc_dev *dev, struct ir_raw_event *ev); |
d8b4b5822
|
321 |
void ir_raw_event_set_idle(struct rc_dev *dev, bool idle); |
6d741bfed
|
322 |
int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode, |
3875233d0
|
323 |
struct ir_raw_event *events, unsigned int max); |
cdfaa01c1
|
324 |
int ir_raw_encode_carrier(enum rc_proto protocol); |
4a702ebf6
|
325 |
|
d8b4b5822
|
326 |
static inline void ir_raw_event_reset(struct rc_dev *dev) |
e40b1127f
|
327 |
{ |
183e19f5b
|
328 |
ir_raw_event_store(dev, &((struct ir_raw_event) { .reset = true })); |
e0d51e6ce
|
329 |
dev->idle = true; |
d8b4b5822
|
330 |
ir_raw_event_handle(dev); |
e40b1127f
|
331 |
} |
724e24955
|
332 |
|
3ffea4988
|
333 334 335 336 337 338 |
/* extract mask bits out of data and pack them into the result */ static inline u32 ir_extract_bits(u32 data, u32 mask) { u32 vbit = 1, value = 0; do { |
829ba9fe3
|
339 340 341 342 343 344 |
if (mask & 1) { if (data & 1) value |= vbit; vbit <<= 1; } data >>= 1; |
3ffea4988
|
345 346 347 348 |
} while (mask >>= 1); return value; } |
e8ffda786
|
349 350 351 |
/* Get NEC scancode and protocol type from address and command bytes */ static inline u32 ir_nec_bytes_to_scancode(u8 address, u8 not_address, u8 command, u8 not_command, |
6d741bfed
|
352 |
enum rc_proto *protocol) |
e8ffda786
|
353 354 355 356 357 358 359 360 361 362 363 |
{ u32 scancode; if ((command ^ not_command) != 0xff) { /* NEC transport, but modified protocol, used by at * least Apple and TiVo remotes */ scancode = not_address << 24 | address << 16 | not_command << 8 | command; |
6d741bfed
|
364 |
*protocol = RC_PROTO_NEC32; |
e8ffda786
|
365 366 367 368 369 |
} else if ((address ^ not_address) != 0xff) { /* Extended NEC */ scancode = address << 16 | not_address << 8 | command; |
6d741bfed
|
370 |
*protocol = RC_PROTO_NECX; |
e8ffda786
|
371 372 373 |
} else { /* Normal NEC */ scancode = address << 8 | command; |
6d741bfed
|
374 |
*protocol = RC_PROTO_NEC; |
e8ffda786
|
375 376 377 378 |
} return scancode; } |
ca86674b8
|
379 |
#endif /* _RC_CORE */ |