aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-rc5-sz-decoder.c
diff options
context:
space:
mode:
authorJarod Wilson <jarod@redhat.com>2010-08-07 12:31:40 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-20 23:04:47 -0400
commit7a569f524dd36806b995c844f29e28ff40c444b2 (patch)
treef771e5bd298089fe007a74d654c756fda4c39f3e /drivers/media/IR/ir-rc5-sz-decoder.c
parent516c714c6c823e412dc485ca9c5307348cddd097 (diff)
V4L/DVB: IR/streamzap: functional in-kernel decoding
This patch makes in-kernel decoding with the stock Streamzap PC Remote work out of the box. There are quite a few things going on in this patch, all related to getting this working: 1) I had to enable reporting of a long space at the end of each signal, or I had weird buffering and keybounce issues. 2) The keymap has been reworked slightly to match actual decoded values, the first edition was missing the pre-data bits present in the lirc config file for this remote. 3) There's a whole new decoder included, specifically for the not-quite-RC5 15-bit protocol variant used by the Streamzap PC Remote. The decoder, while usable with other recievers (tested with an mceusb receiver), will only be loaded by the streamzap driver, as its likely not of use in almost all other situations. This can be revisited if/when all keytable loading (and disabling of unneeded protocol decoder engines) is moved to userspace, but for now, I think this makes the most sense. Note that I did try to enable handling the streamzap RC5-ish protocol in the current RC5 decoder, but there's no particularly easy way to tell if its 14-bit RC5 or 15-bit Streamzap until we see bit 14, and even then, in testing an attempted decoder merge, only 2/3 of the keys were properly recognized as being the 15-bit variant and decoded correctly, the rest were close enough to compliant with 14-bit that they were decoded as such (but they have overlap with one another, and thus we can't just shrug and use the 14-bit decoded values). Also of note in this patch is the removal of the streamzap driver's internal delay buffer. Per discussion w/Christoph, it shouldn't be needed by lirc any longer anyway, and it doesn't seem to make any difference to the in-kernel decoder engine. That being the case, I'm yanking it all out, as it greatly simplifies the driver code. Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-rc5-sz-decoder.c')
-rw-r--r--drivers/media/IR/ir-rc5-sz-decoder.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/drivers/media/IR/ir-rc5-sz-decoder.c b/drivers/media/IR/ir-rc5-sz-decoder.c
new file mode 100644
index 000000000000..68f11d6acd5b
--- /dev/null
+++ b/drivers/media/IR/ir-rc5-sz-decoder.c
@@ -0,0 +1,153 @@
1/* ir-rc5-sz-decoder.c - handle RC5 Streamzap IR Pulse/Space protocol
2 *
3 * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 * Copyright (C) 2010 by Jarod Wilson <jarod@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16/*
17 * This code handles the 15 bit RC5-ish protocol used by the Streamzap
18 * PC Remote.
19 * It considers a carrier of 36 kHz, with a total of 15 bits, where
20 * the first two bits are start bits, and a third one is a filing bit
21 */
22
23#include "ir-core-priv.h"
24
25#define RC5_SZ_NBITS 15
26#define RC5_UNIT 888888 /* ns */
27#define RC5_BIT_START (1 * RC5_UNIT)
28#define RC5_BIT_END (1 * RC5_UNIT)
29
30enum rc5_sz_state {
31 STATE_INACTIVE,
32 STATE_BIT_START,
33 STATE_BIT_END,
34 STATE_FINISHED,
35};
36
37/**
38 * ir_rc5_sz_decode() - Decode one RC-5 Streamzap pulse or space
39 * @input_dev: the struct input_dev descriptor of the device
40 * @ev: the struct ir_raw_event descriptor of the pulse/space
41 *
42 * This function returns -EINVAL if the pulse violates the state machine
43 */
44static int ir_rc5_sz_decode(struct input_dev *input_dev, struct ir_raw_event ev)
45{
46 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
47 struct rc5_sz_dec *data = &ir_dev->raw->rc5_sz;
48 u8 toggle, command, system;
49 u32 scancode;
50
51 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5_SZ))
52 return 0;
53
54 if (IS_RESET(ev)) {
55 data->state = STATE_INACTIVE;
56 return 0;
57 }
58
59 if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2))
60 goto out;
61
62again:
63 IR_dprintk(2, "RC5-sz decode started at state %i (%uus %s)\n",
64 data->state, TO_US(ev.duration), TO_STR(ev.pulse));
65
66 if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2))
67 return 0;
68
69 switch (data->state) {
70
71 case STATE_INACTIVE:
72 if (!ev.pulse)
73 break;
74
75 data->state = STATE_BIT_START;
76 data->count = 1;
77 data->wanted_bits = RC5_SZ_NBITS;
78 decrease_duration(&ev, RC5_BIT_START);
79 goto again;
80
81 case STATE_BIT_START:
82 if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2))
83 break;
84
85 data->bits <<= 1;
86 if (!ev.pulse)
87 data->bits |= 1;
88 data->count++;
89 data->state = STATE_BIT_END;
90 return 0;
91
92 case STATE_BIT_END:
93 if (!is_transition(&ev, &ir_dev->raw->prev_ev))
94 break;
95
96 if (data->count == data->wanted_bits)
97 data->state = STATE_FINISHED;
98 else
99 data->state = STATE_BIT_START;
100
101 decrease_duration(&ev, RC5_BIT_END);
102 goto again;
103
104 case STATE_FINISHED:
105 if (ev.pulse)
106 break;
107
108 /* RC5-sz */
109 command = (data->bits & 0x0003F) >> 0;
110 system = (data->bits & 0x02FC0) >> 6;
111 toggle = (data->bits & 0x01000) ? 1 : 0;
112 scancode = system << 6 | command;
113
114 IR_dprintk(1, "RC5-sz scancode 0x%04x (toggle: %u)\n",
115 scancode, toggle);
116
117 ir_keydown(input_dev, scancode, toggle);
118 data->state = STATE_INACTIVE;
119 return 0;
120 }
121
122out:
123 IR_dprintk(1, "RC5-sz decode failed at state %i (%uus %s)\n",
124 data->state, TO_US(ev.duration), TO_STR(ev.pulse));
125 data->state = STATE_INACTIVE;
126 return -EINVAL;
127}
128
129static struct ir_raw_handler rc5_sz_handler = {
130 .protocols = IR_TYPE_RC5_SZ,
131 .decode = ir_rc5_sz_decode,
132};
133
134static int __init ir_rc5_sz_decode_init(void)
135{
136 ir_raw_handler_register(&rc5_sz_handler);
137
138 printk(KERN_INFO "IR RC5 (streamzap) protocol handler initialized\n");
139 return 0;
140}
141
142static void __exit ir_rc5_sz_decode_exit(void)
143{
144 ir_raw_handler_unregister(&rc5_sz_handler);
145}
146
147module_init(ir_rc5_sz_decode_init);
148module_exit(ir_rc5_sz_decode_exit);
149
150MODULE_LICENSE("GPL");
151MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
152MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
153MODULE_DESCRIPTION("RC5 (streamzap) IR protocol decoder");