Blame view

include/media/rc-core.h 12.3 KB
8e8e69d67   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-only */
446e4a64d   Mauro Carvalho Chehab   V4L/DVB (13613): ...
2
3
4
  /*
   * Remote Controller core header
   *
37e59f876   Mauro Carvalho Chehab   [media, edac] Cha...
5
   * Copyright (C) 2009-2010 by Mauro Carvalho Chehab
446e4a64d   Mauro Carvalho Chehab   V4L/DVB (13613): ...
6
   */
ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
7
8
  #ifndef _RC_CORE
  #define _RC_CORE
446e4a64d   Mauro Carvalho Chehab   V4L/DVB (13613): ...
9

446e4a64d   Mauro Carvalho Chehab   V4L/DVB (13613): ...
10
  #include <linux/spinlock.h>
a6ddd4fec   Sean Young   media: lirc: remo...
11
  #include <linux/cdev.h>
a3572c34d   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
12
13
  #include <linux/kfifo.h>
  #include <linux/time.h>
9f1547829   Mauro Carvalho Chehab   V4L/DVB: saa7134:...
14
  #include <linux/timer.h>
02858eedc   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
15
  #include <media/rc-map.h>
446e4a64d   Mauro Carvalho Chehab   V4L/DVB (13613): ...
16

5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
17
  /**
f4ab70e3d   Mauro Carvalho Chehab   media: rc-core.h:...
18
   * enum rc_driver_type - type of the RC driver.
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
19
   *
f4ab70e3d   Mauro Carvalho Chehab   media: rc-core.h:...
20
   * @RC_DRIVER_SCANCODE:	 Driver or hardware generates a scancode.
d34aee101   Andi Shyti   [media] rc-core: ...
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   Mauro Carvalho Chehab   [media] doc-rst: ...
25
   */
626cf6979   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
26
  enum rc_driver_type {
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
27
28
  	RC_DRIVER_SCANCODE = 0,
  	RC_DRIVER_IR_RAW,
d34aee101   Andi Shyti   [media] rc-core: ...
29
  	RC_DRIVER_IR_RAW_TX,
626cf6979   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
30
  };
9dfe4e833   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
31
  /**
00942d1a1   James Hogan   [media] media: rc...
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   Sean Young   media: lirc: allo...
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   David Härdeman   [media] ir-core: ...
82
83
   * struct rc_dev - represents a remote control device
   * @dev: driver model's view of this device
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
84
   * @managed_alloc: devm_rc_allocate_device was used to create rc_dev
99b0f3c96   David Härdeman   [media] rc-core: ...
85
   * @sysfs_groups: sysfs attribute groups
518f4b26b   Sean Young   media: rc-core: r...
86
   * @device_name: name of the rc child device
d8b4b5822   David Härdeman   [media] ir-core: ...
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   Mauro Carvalho Chehab   [media] rc: Prope...
91
   * @rc_map: current scan/key table
08aeb7c9a   Jarod Wilson   [media] rc: add l...
92
93
   * @lock: used to ensure we've filled in all protocol details before
   *	anyone can call show_protocols or store_protocols
fcb130978   David Härdeman   [media] rc-core: ...
94
   * @minor: unique minor remote control device number
d8b4b5822   David Härdeman   [media] ir-core: ...
95
96
   * @raw: additional data for raw pulse/space devices
   * @input_dev: the input child device used to communicate events to userspace
08aeb7c9a   Jarod Wilson   [media] rc: add l...
97
   * @driver_type: specifies if protocol decoding is done in hardware or software
d8b4b5822   David Härdeman   [media] ir-core: ...
98
   * @idle: used to keep track of RX state
f423ccc1a   James Hogan   [media] rc: rc-co...
99
100
   * @encode_wakeup: wakeup filtering uses IR encode API, therefore the allowed
   *	wakeup protocols is the set of all raw encoders
6d741bfed   Sean Young   media: rc: rename...
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   David Härdeman   [media] rc-core: ...
107
108
   * @scancode_filter: scancode filter
   * @scancode_wakeup_filter: scancode wakeup filters
9d2f1d3cd   David Härdeman   [media] rc-core: ...
109
   * @scancode_mask: some hardware decoders are not capable of providing the full
9dfe4e833   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
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   David Härdeman   [media] rc-core: ...
114
   * @users: number of current users of the device
d8b4b5822   David Härdeman   [media] ir-core: ...
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   Sean Young   media: cec: move ...
120
121
   * @timer_repeat: timer for autorepeat events. This is needed for CEC, which
   *	has non-standard repeats.
d8b4b5822   David Härdeman   [media] ir-core: ...
122
   * @last_keycode: keycode of last keypress
120703f9e   David Härdeman   [media] rc-core: ...
123
   * @last_protocol: protocol of last keypress
d8b4b5822   David Härdeman   [media] ir-core: ...
124
125
   * @last_scancode: scancode of last keypress
   * @last_toggle: toggle value of last command
4a702ebf6   Maxim Levitsky   V4L/DVB: IR: add ...
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   Maxim Levitsky   V4L/DVB: IR: exte...
129
130
   * @rx_resolution : resolution (in ns) of input sampler
   * @tx_resolution: resolution (in ns) of output sampler
a6ddd4fec   Sean Young   media: lirc: remo...
131
132
   * @lirc_dev: lirc device
   * @lirc_cdev: lirc char cdev
a60d64b15   Sean Young   media: lirc: lirc...
133
134
135
   * @gap_start: time when gap starts
   * @gap_duration: duration of initial gap
   * @gap: true if we're in a gap
7e45d660e   Sean Young   media: lirc: allo...
136
137
   * @lirc_fh_lock: protects lirc_fh list
   * @lirc_fh: list of open files
7790e81f7   Sean Young   media: lirc: move...
138
139
   * @registered: set to true by rc_register_device(), false by
   *	rc_unregister_device
9dfe4e833   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
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   Jarod Wilson   V4L/DVB: IR: add ...
145
146
   * @s_tx_mask: set transmitter mask (for devices with multiple tx outputs)
   * @s_tx_carrier: set transmit carrier frequency
e589333f3   Maxim Levitsky   V4L/DVB: IR: exte...
147
   * @s_tx_duty_cycle: set transmit duty cycle (0% - 100%)
fa810845e   Mauro Carvalho Chehab   [media] Docbook: ...
148
   * @s_rx_carrier_range: inform driver about carrier it is expected to handle
9b7c54d92   Jarod Wilson   V4L/DVB: IR: add ...
149
   * @tx_ir: transmit IR
d8b4b5822   David Härdeman   [media] ir-core: ...
150
151
   * @s_idle: enable/disable hardware idle mode, upon which,
   *	device doesn't interrupt host until it sees IR pulses
e589333f3   Maxim Levitsky   V4L/DVB: IR: exte...
152
   * @s_learning_mode: enable wide band receiver used for learning
4651918a4   Maxim Levitsky   [media] IR: exten...
153
   * @s_carrier_report: enable carrier reports
120703f9e   David Härdeman   [media] rc-core: ...
154
   * @s_filter: set the scancode filter
0751d33c2   Sean Young   [media] rc: chang...
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   Sean Young   [media] redrat3: ...
158
   * @s_timeout: set hardware timeout in ns
9dfe4e833   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
159
   */
d8b4b5822   David Härdeman   [media] ir-core: ...
160
161
  struct rc_dev {
  	struct device			dev;
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
162
  	bool				managed_alloc;
99b0f3c96   David Härdeman   [media] rc-core: ...
163
  	const struct attribute_group	*sysfs_groups[5];
518f4b26b   Sean Young   media: rc-core: r...
164
  	const char			*device_name;
d8b4b5822   David Härdeman   [media] ir-core: ...
165
166
  	const char			*input_phys;
  	struct input_id			input_id;
518f4b26b   Sean Young   media: rc-core: r...
167
  	const char			*driver_name;
d8b4b5822   David Härdeman   [media] ir-core: ...
168
  	const char			*map_name;
08aeb7c9a   Jarod Wilson   [media] rc: add l...
169
170
  	struct rc_map			rc_map;
  	struct mutex			lock;
fcb130978   David Härdeman   [media] rc-core: ...
171
  	unsigned int			minor;
d8b4b5822   David Härdeman   [media] ir-core: ...
172
173
174
  	struct ir_raw_event_ctrl	*raw;
  	struct input_dev		*input_dev;
  	enum rc_driver_type		driver_type;
4a702ebf6   Maxim Levitsky   V4L/DVB: IR: add ...
175
  	bool				idle;
f423ccc1a   James Hogan   [media] rc: rc-co...
176
  	bool				encode_wakeup;
c5540fbb9   David Härdeman   [media] rc-core: ...
177
178
179
  	u64				allowed_protocols;
  	u64				enabled_protocols;
  	u64				allowed_wakeup_protocols;
6d741bfed   Sean Young   media: rc: rename...
180
  	enum rc_proto			wakeup_protocol;
c5540fbb9   David Härdeman   [media] rc-core: ...
181
182
  	struct rc_scancode_filter	scancode_filter;
  	struct rc_scancode_filter	scancode_wakeup_filter;
9d2f1d3cd   David Härdeman   [media] rc-core: ...
183
  	u32				scancode_mask;
8b2ff3204   Srinivas Kandagatla   [media] media: rc...
184
  	u32				users;
d8b4b5822   David Härdeman   [media] ir-core: ...
185
186
187
188
189
  	void				*priv;
  	spinlock_t			keylock;
  	bool				keypressed;
  	unsigned long			keyup_jiffies;
  	struct timer_list		timer_keyup;
57c642cb4   Sean Young   media: cec: move ...
190
  	struct timer_list		timer_repeat;
d8b4b5822   David Härdeman   [media] ir-core: ...
191
  	u32				last_keycode;
6d741bfed   Sean Young   media: rc: rename...
192
  	enum rc_proto			last_protocol;
d8b4b5822   David Härdeman   [media] ir-core: ...
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   Sean Young   media: lirc: lirc...
200
  #ifdef CONFIG_LIRC
a6ddd4fec   Sean Young   media: lirc: remo...
201
202
  	struct device			lirc_dev;
  	struct cdev			lirc_cdev;
a60d64b15   Sean Young   media: lirc: lirc...
203
204
205
  	ktime_t				gap_start;
  	u64				gap_duration;
  	bool				gap;
7e45d660e   Sean Young   media: lirc: allo...
206
207
  	spinlock_t			lirc_fh_lock;
  	struct list_head		lirc_fh;
a60d64b15   Sean Young   media: lirc: lirc...
208
  #endif
7790e81f7   Sean Young   media: lirc: move...
209
  	bool				registered;
6d741bfed   Sean Young   media: rc: rename...
210
  	int				(*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
d8b4b5822   David Härdeman   [media] ir-core: ...
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   David Härdeman   [media] rc-core: ...
217
  	int				(*tx_ir)(struct rc_dev *dev, unsigned *txbuf, unsigned n);
d8b4b5822   David Härdeman   [media] ir-core: ...
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   James Hogan   [media] media: rc...
221
  	int				(*s_filter)(struct rc_dev *dev,
00942d1a1   James Hogan   [media] media: rc...
222
  						    struct rc_scancode_filter *filter);
23c843b5e   David Härdeman   [media] rc-core: ...
223
224
  	int				(*s_wakeup_filter)(struct rc_dev *dev,
  							   struct rc_scancode_filter *filter);
4f253cecf   Sean Young   [media] redrat3: ...
225
226
  	int				(*s_timeout)(struct rc_dev *dev,
  						     unsigned int timeout);
75543cce0   Mauro Carvalho Chehab   V4L/DVB (13615): ...
227
  };
a3572c34d   Mauro Carvalho Chehab   V4L/DVB: ir-core:...
228

ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
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   Mauro Carvalho Chehab   [media] doc-rst: ...
237
238
239
  /**
   * rc_allocate_device - Allocates a RC device
   *
0f7499fdd   Andi Shyti   [media] rc-main: ...
240
   * @rc_driver_type: specifies the type of the RC output to be allocated
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
241
242
   * returns a pointer to struct rc_dev.
   */
0f7499fdd   Andi Shyti   [media] rc-main: ...
243
  struct rc_dev *rc_allocate_device(enum rc_driver_type);
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
244
245
  
  /**
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
246
247
248
   * devm_rc_allocate_device - Managed RC device allocation
   *
   * @dev: pointer to struct device
0f7499fdd   Andi Shyti   [media] rc-main: ...
249
   * @rc_driver_type: specifies the type of the RC output to be allocated
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
250
251
   * returns a pointer to struct rc_dev.
   */
0f7499fdd   Andi Shyti   [media] rc-main: ...
252
  struct rc_dev *devm_rc_allocate_device(struct device *dev, enum rc_driver_type);
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
253
254
  
  /**
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
255
256
257
258
   * rc_free_device - Frees a RC device
   *
   * @dev: pointer to struct rc_dev.
   */
ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
259
  void rc_free_device(struct rc_dev *dev);
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
260
261
262
263
264
265
  
  /**
   * rc_register_device - Registers a RC device
   *
   * @dev: pointer to struct rc_dev.
   */
ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
266
  int rc_register_device(struct rc_dev *dev);
5b6137dc8   Mauro Carvalho Chehab   [media] doc-rst: ...
267
268
  
  /**
ddbf7d5a6   Heiner Kallweit   [media] rc: core:...
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   Mauro Carvalho Chehab   [media] doc-rst: ...
277
278
279
280
   * rc_unregister_device - Unregisters a RC device
   *
   * @dev: pointer to struct rc_dev.
   */
ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
281
282
283
  void rc_unregister_device(struct rc_dev *dev);
  
  void rc_repeat(struct rc_dev *dev);
6d741bfed   Sean Young   media: rc: rename...
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   Mauro Carvalho Chehab   [media] Rename al...
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   David Härdeman   V4L/DVB: ir-core:...
296
  struct ir_raw_event {
4651918a4   Maxim Levitsky   [media] IR: exten...
297
298
  	union {
  		u32             duration;
5f61ff861   Heiner Kallweit   [media] media: rc...
299
  		u32             carrier;
4651918a4   Maxim Levitsky   [media] IR: exten...
300
  	};
5f61ff861   Heiner Kallweit   [media] media: rc...
301
  	u8                      duty_cycle;
4651918a4   Maxim Levitsky   [media] IR: exten...
302
303
304
305
306
  
  	unsigned                pulse:1;
  	unsigned                reset:1;
  	unsigned                timeout:1;
  	unsigned                carrier_report:1;
e40b1127f   David Härdeman   V4L/DVB: ir-core:...
307
  };
c8e1bbc52   Eric Nelson   [media] rc-core: ...
308
  #define IR_DEFAULT_TIMEOUT	MS_TO_NS(125)
6b20cf3c0   Mauro Carvalho Chehab   [media] rc: set I...
309
  #define IR_MAX_DURATION         500000000	/* 500 ms */
5aad72428   Jarod Wilson   [media] rc: fix u...
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   David Härdeman   V4L/DVB: ir-core:...
313

d8b4b5822   David Härdeman   [media] ir-core: ...
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   Sean Young   media: rc: simpli...
316
  int ir_raw_event_store_edge(struct rc_dev *dev, bool pulse);
d8b4b5822   David Härdeman   [media] ir-core: ...
317
  int ir_raw_event_store_with_filter(struct rc_dev *dev,
8d7a77ce5   Sean Young   media: rc: meson-...
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   David Härdeman   [media] ir-core: ...
321
  void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
6d741bfed   Sean Young   media: rc: rename...
322
  int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode,
3875233d0   James Hogan   [media] rc: rc-ir...
323
  			   struct ir_raw_event *events, unsigned int max);
cdfaa01c1   Sean Young   media: lirc: use ...
324
  int ir_raw_encode_carrier(enum rc_proto protocol);
4a702ebf6   Maxim Levitsky   V4L/DVB: IR: add ...
325

d8b4b5822   David Härdeman   [media] ir-core: ...
326
  static inline void ir_raw_event_reset(struct rc_dev *dev)
e40b1127f   David Härdeman   V4L/DVB: ir-core:...
327
  {
183e19f5b   Sean Young   media: rc: Remove...
328
  	ir_raw_event_store(dev, &((struct ir_raw_event) { .reset = true }));
e0d51e6ce   Sean Young   media: rc: defaul...
329
  	dev->idle = true;
d8b4b5822   David Härdeman   [media] ir-core: ...
330
  	ir_raw_event_handle(dev);
e40b1127f   David Härdeman   V4L/DVB: ir-core:...
331
  }
724e24955   David Härdeman   V4L/DVB: Teach dr...
332

3ffea4988   David Härdeman   [media] ir-core: ...
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   David Härdeman   [media] rc-core: ...
339
340
341
342
343
344
  		if (mask & 1) {
  			if (data & 1)
  				value |= vbit;
  			vbit <<= 1;
  		}
  		data >>= 1;
3ffea4988   David Härdeman   [media] ir-core: ...
345
346
347
348
  	} while (mask >>= 1);
  
  	return value;
  }
e8ffda786   Shawn Guo   media: rc: ir-nec...
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   Sean Young   media: rc: rename...
352
  					   enum rc_proto *protocol)
e8ffda786   Shawn Guo   media: rc: ir-nec...
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   Sean Young   media: rc: rename...
364
  		*protocol = RC_PROTO_NEC32;
e8ffda786   Shawn Guo   media: rc: ir-nec...
365
366
367
368
369
  	} else if ((address ^ not_address) != 0xff) {
  		/* Extended NEC */
  		scancode = address     << 16 |
  			   not_address <<  8 |
  			   command;
6d741bfed   Sean Young   media: rc: rename...
370
  		*protocol = RC_PROTO_NECX;
e8ffda786   Shawn Guo   media: rc: ir-nec...
371
372
373
  	} else {
  		/* Normal NEC */
  		scancode = address << 8 | command;
6d741bfed   Sean Young   media: rc: rename...
374
  		*protocol = RC_PROTO_NEC;
e8ffda786   Shawn Guo   media: rc: ir-nec...
375
376
377
378
  	}
  
  	return scancode;
  }
ca86674b8   Mauro Carvalho Chehab   [media] Rename al...
379
  #endif /* _RC_CORE */