aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/ir-functions.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-21 14:10:30 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-21 14:10:30 -0500
commite695e10bc996d6f83df7d85f1011c8d00573f68b (patch)
tree3d0ba107ea8fe7d0090e3cfd5e36cdb4abcaab99 /drivers/media/common/ir-functions.c
parent3a5f10e3708e00c406f154bae412652ec3eb2b48 (diff)
parentf6982d59480953a8f5a84c237a9dabff39f788ce (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb
* 'master' of master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb: (196 commits) V4L/DVB (5253): Qt1010: whitespace / 80 column cleanups V4L/DVB (5252): Qt1010: use ARRAY_SIZE macro when appropriate V4L/DVB (5251): Qt1010: fix compiler warning V4L/DVB (5249): Fix compiler warning in vivi.c V4L/DVB (5247): Stv0297: Enable BER/UNC counting V4L/DVB (5246): Budget-ci: IR handling fixups V4L/DVB (5245): Dvb-ttpci: use i2c gate ctrl from stv0297 frontend driver V4L/DVB (5244): Dvbdev: fix illegal re-usage of fileoperations struct V4L/DVB (5178): Avoid race when deregistering the IR control for dvb-usb V4L/DVB (5240): Qt1010: use i2c_gate_ctrl where appropriate V4L/DVB (5239): Whitespace / 80-column cleanups V4L/DVB (5238): Kconfig: qt1010 should be selected by gl861 and au6610 V4L/DVB (5237): Dvb: add new qt1010 tuner module V4L/DVB (5236): Initial support for Sigmatek DVB-110 DVB-T V4L/DVB (5235): Gl861: use parallel_ts V4L/DVB (5234): Gl861: remove unneeded declaration V4L/DVB (5233): Gl861: correct address of the bulk endpoint V4L/DVB (5232): Gl861: correct oops when loading module V4L/DVB (5231): Gl861: whitespace cleanups V4L/DVB (5230): Gl861: remove NULL entry from gl861_properties ...
Diffstat (limited to 'drivers/media/common/ir-functions.c')
-rw-r--r--drivers/media/common/ir-functions.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index 9a8dd8764c99..cbf7c0564889 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -256,6 +256,112 @@ int ir_decode_biphase(u32 *samples, int count, int low, int high)
256 return value; 256 return value;
257} 257}
258 258
259/* RC5 decoding stuff, moved from bttv-input.c to share it with
260 * saa7134 */
261
262/* decode raw bit pattern to RC5 code */
263u32 ir_rc5_decode(unsigned int code)
264{
265 unsigned int org_code = code;
266 unsigned int pair;
267 unsigned int rc5 = 0;
268 int i;
269
270 for (i = 0; i < 14; ++i) {
271 pair = code & 0x3;
272 code >>= 2;
273
274 rc5 <<= 1;
275 switch (pair) {
276 case 0:
277 case 2:
278 break;
279 case 1:
280 rc5 |= 1;
281 break;
282 case 3:
283 dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
284 return 0;
285 }
286 }
287 dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
288 "instr=%x\n", rc5, org_code, RC5_START(rc5),
289 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
290 return rc5;
291}
292
293void ir_rc5_timer_end(unsigned long data)
294{
295 struct card_ir *ir = (struct card_ir *)data;
296 struct timeval tv;
297 unsigned long current_jiffies, timeout;
298 u32 gap;
299 u32 rc5 = 0;
300
301 /* get time */
302 current_jiffies = jiffies;
303 do_gettimeofday(&tv);
304
305 /* avoid overflow with gap >1s */
306 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
307 gap = 200000;
308 } else {
309 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
310 tv.tv_usec - ir->base_time.tv_usec;
311 }
312
313 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
314 if (gap < 28000) {
315 dprintk(1, "ir-common: spurious timer_end\n");
316 return;
317 }
318
319 ir->active = 0;
320 if (ir->last_bit < 20) {
321 /* ignore spurious codes (caused by light/other remotes) */
322 dprintk(1, "ir-common: short code: %x\n", ir->code);
323 } else {
324 ir->code = (ir->code << ir->shift_by) | 1;
325 rc5 = ir_rc5_decode(ir->code);
326
327 /* two start bits? */
328 if (RC5_START(rc5) != ir->start) {
329 dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));
330
331 /* right address? */
332 } else if (RC5_ADDR(rc5) == ir->addr) {
333 u32 toggle = RC5_TOGGLE(rc5);
334 u32 instr = RC5_INSTR(rc5);
335
336 /* Good code, decide if repeat/repress */
337 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
338 instr != RC5_INSTR(ir->last_rc5)) {
339 dprintk(1, "ir-common: instruction %x, toggle %x\n", instr,
340 toggle);
341 ir_input_nokey(ir->dev, &ir->ir);
342 ir_input_keydown(ir->dev, &ir->ir, instr,
343 instr);
344 }
345
346 /* Set/reset key-up timer */
347 timeout = current_jiffies + (500 + ir->rc5_key_timeout
348 * HZ) / 1000;
349 mod_timer(&ir->timer_keyup, timeout);
350
351 /* Save code for repeat test */
352 ir->last_rc5 = rc5;
353 }
354 }
355}
356
357void ir_rc5_timer_keyup(unsigned long data)
358{
359 struct card_ir *ir = (struct card_ir *)data;
360
361 dprintk(1, "ir-common: key released\n");
362 ir_input_nokey(ir->dev, &ir->ir);
363}
364
259EXPORT_SYMBOL_GPL(ir_input_init); 365EXPORT_SYMBOL_GPL(ir_input_init);
260EXPORT_SYMBOL_GPL(ir_input_nokey); 366EXPORT_SYMBOL_GPL(ir_input_nokey);
261EXPORT_SYMBOL_GPL(ir_input_keydown); 367EXPORT_SYMBOL_GPL(ir_input_keydown);
@@ -265,6 +371,10 @@ EXPORT_SYMBOL_GPL(ir_dump_samples);
265EXPORT_SYMBOL_GPL(ir_decode_biphase); 371EXPORT_SYMBOL_GPL(ir_decode_biphase);
266EXPORT_SYMBOL_GPL(ir_decode_pulsedistance); 372EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
267 373
374EXPORT_SYMBOL_GPL(ir_rc5_decode);
375EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
376EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);
377
268/* 378/*
269 * Local variables: 379 * Local variables:
270 * c-basic-offset: 8 380 * c-basic-offset: 8