Skip to content

Commit 4a702eb

Browse files
maximlevitskyMauro Carvalho Chehab
authored andcommitted
V4L/DVB: IR: add helper function for hardware with small o/b buffer
Some ir input devices have small buffer, and interrupt the host each time it is full (or half full) Add a helper that automaticly handles timeouts, and also automaticly merges samples of same time (space-space) Such samples might be placed by hardware because size of sample in the buffer is small (a byte for example). Also remove constness from ir_dev_props, because it now contains timeout settings that driver might want to change Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Acked-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent b378f43 commit 4a702eb

4 files changed

Lines changed: 106 additions & 4 deletions

File tree

‎drivers/media/IR/ir-core-priv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct ir_raw_event_ctrl {
4141

4242
/* raw decoder state follows */
4343
struct ir_raw_event prev_ev;
44+
struct ir_raw_event this_ev;
4445
struct nec_dec {
4546
int state;
4647
unsigned count;

‎drivers/media/IR/ir-keytable.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static void ir_close(struct input_dev *input_dev)
428428
*/
429429
int __ir_input_register(struct input_dev *input_dev,
430430
const struct ir_scancode_table *rc_tab,
431-
const struct ir_dev_props *props,
431+
struct ir_dev_props *props,
432432
const char *driver_name)
433433
{
434434
struct ir_input_dev *ir_dev;

‎drivers/media/IR/ir-raw-event.c‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,90 @@ int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type typ
139139
}
140140
EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
141141

142+
/**
143+
* ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing
144+
* @input_dev: the struct input_dev device descriptor
145+
* @type: the type of the event that has occurred
146+
*
147+
* This routine (which may be called from an interrupt context) works
148+
* in similiar manner to ir_raw_event_store_edge.
149+
* This routine is intended for devices with limited internal buffer
150+
* It automerges samples of same type, and handles timeouts
151+
*/
152+
int ir_raw_event_store_with_filter(struct input_dev *input_dev,
153+
struct ir_raw_event *ev)
154+
{
155+
struct ir_input_dev *ir = input_get_drvdata(input_dev);
156+
struct ir_raw_event_ctrl *raw = ir->raw;
157+
158+
if (!raw || !ir->props)
159+
return -EINVAL;
160+
161+
/* Ignore spaces in idle mode */
162+
if (ir->idle && !ev->pulse)
163+
return 0;
164+
else if (ir->idle)
165+
ir_raw_event_set_idle(input_dev, 0);
166+
167+
if (!raw->this_ev.duration) {
168+
raw->this_ev = *ev;
169+
} else if (ev->pulse == raw->this_ev.pulse) {
170+
raw->this_ev.duration += ev->duration;
171+
} else {
172+
ir_raw_event_store(input_dev, &raw->this_ev);
173+
raw->this_ev = *ev;
174+
}
175+
176+
/* Enter idle mode if nessesary */
177+
if (!ev->pulse && ir->props->timeout &&
178+
raw->this_ev.duration >= ir->props->timeout)
179+
ir_raw_event_set_idle(input_dev, 1);
180+
return 0;
181+
}
182+
EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
183+
184+
void ir_raw_event_set_idle(struct input_dev *input_dev, int idle)
185+
{
186+
struct ir_input_dev *ir = input_get_drvdata(input_dev);
187+
struct ir_raw_event_ctrl *raw = ir->raw;
188+
ktime_t now;
189+
u64 delta;
190+
191+
if (!ir->props)
192+
return;
193+
194+
if (!ir->raw)
195+
goto out;
196+
197+
if (idle) {
198+
IR_dprintk(2, "enter idle mode\n");
199+
raw->last_event = ktime_get();
200+
} else {
201+
IR_dprintk(2, "exit idle mode\n");
202+
203+
now = ktime_get();
204+
delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event));
205+
206+
WARN_ON(raw->this_ev.pulse);
207+
208+
raw->this_ev.duration =
209+
min(raw->this_ev.duration + delta,
210+
(u64)IR_MAX_DURATION);
211+
212+
ir_raw_event_store(input_dev, &raw->this_ev);
213+
214+
if (raw->this_ev.duration == IR_MAX_DURATION)
215+
ir_raw_event_reset(input_dev);
216+
217+
raw->this_ev.duration = 0;
218+
}
219+
out:
220+
if (ir->props->s_idle)
221+
ir->props->s_idle(ir->props->priv, idle);
222+
ir->idle = idle;
223+
}
224+
EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
225+
142226
/**
143227
* ir_raw_event_handle() - schedules the decoding of stored ir data
144228
* @input_dev: the struct input_dev device descriptor

‎include/media/ir-core.h‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ enum rc_driver_type {
4141
* anything with it. Yet, as the same keycode table can be used with other
4242
* devices, a mask is provided to allow its usage. Drivers should generally
4343
* leave this field in blank
44+
* @timeout: optional time after which device stops sending data
45+
* @min_timeout: minimum timeout supported by device
46+
* @max_timeout: maximum timeout supported by device
4447
* @priv: driver-specific data, to be used on the callbacks
4548
* @change_protocol: allow changing the protocol used on hardware decoders
4649
* @open: callback to allow drivers to enable polling/irq when IR input device
@@ -50,28 +53,38 @@ enum rc_driver_type {
5053
* @s_tx_mask: set transmitter mask (for devices with multiple tx outputs)
5154
* @s_tx_carrier: set transmit carrier frequency
5255
* @tx_ir: transmit IR
56+
* @s_idle: optional: enable/disable hardware idle mode, upon which,
57+
* device doesn't interrupt host untill it sees IR data
5358
*/
5459
struct ir_dev_props {
5560
enum rc_driver_type driver_type;
5661
unsigned long allowed_protos;
5762
u32 scanmask;
63+
64+
u32 timeout;
65+
u32 min_timeout;
66+
u32 max_timeout;
67+
68+
5869
void *priv;
5970
int (*change_protocol)(void *priv, u64 ir_type);
6071
int (*open)(void *priv);
6172
void (*close)(void *priv);
6273
int (*s_tx_mask)(void *priv, u32 mask);
6374
int (*s_tx_carrier)(void *priv, u32 carrier);
6475
int (*tx_ir)(void *priv, int *txbuf, u32 n);
76+
void (*s_idle)(void *priv, int enable);
6577
};
6678

6779
struct ir_input_dev {
6880
struct device dev; /* device */
6981
char *driver_name; /* Name of the driver module */
7082
struct ir_scancode_table rc_tab; /* scan/key table */
7183
unsigned long devno; /* device number */
72-
const struct ir_dev_props *props; /* Device properties */
84+
struct ir_dev_props *props; /* Device properties */
7385
struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
7486
struct input_dev *input_dev; /* the input device associated with this device */
87+
bool idle;
7588

7689
/* key info - needed by IR keycode handlers */
7790
spinlock_t keylock; /* protects the below members */
@@ -95,12 +108,12 @@ enum raw_event_type {
95108
/* From ir-keytable.c */
96109
int __ir_input_register(struct input_dev *dev,
97110
const struct ir_scancode_table *ir_codes,
98-
const struct ir_dev_props *props,
111+
struct ir_dev_props *props,
99112
const char *driver_name);
100113

101114
static inline int ir_input_register(struct input_dev *dev,
102115
const char *map_name,
103-
const struct ir_dev_props *props,
116+
struct ir_dev_props *props,
104117
const char *driver_name) {
105118
struct ir_scancode_table *ir_codes;
106119
struct ir_input_dev *ir_dev;
@@ -148,6 +161,10 @@ struct ir_raw_event {
148161
void ir_raw_event_handle(struct input_dev *input_dev);
149162
int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev);
150163
int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type);
164+
int ir_raw_event_store_with_filter(struct input_dev *input_dev,
165+
struct ir_raw_event *ev);
166+
void ir_raw_event_set_idle(struct input_dev *input_dev, int idle);
167+
151168
static inline void ir_raw_event_reset(struct input_dev *input_dev)
152169
{
153170
struct ir_raw_event ev = { .pulse = false, .duration = 0 };

0 commit comments

Comments
 (0)