aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/ttpci/av7110_ir.c
diff options
context:
space:
mode:
authorOliver Endriss <o.endriss@gmx.de>2005-09-09 16:03:12 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-09 16:57:46 -0400
commit03388ae30260475650bab24223151397afb72ec9 (patch)
treef393f529f904cc1d53c87221ef3ec383b5e5f2bc /drivers/media/dvb/ttpci/av7110_ir.c
parent9a7b102e7f5ccb2826a81315abc89f95adaf4421 (diff)
[PATCH] dvb: ttpci: av7110: RC5+ remote control support
Improved remote control support for av7110-based cards: o extended rc5 protocol, firmware >= 0x2620 required o key-up timer slightly adjusted o completely moved remote control code to av7110_ir.c o support for multiple ir receivers o for now, all av7110 cards share the same ir configuration and event device Signed-off-by: Oliver Endriss <o.endriss@gmx.de> Signed-off-by: Johannes Stezenbach <js@linuxtv.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/media/dvb/ttpci/av7110_ir.c')
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c140
1 files changed, 97 insertions, 43 deletions
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 665cdb8a3f71..357a3728ec68 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -7,16 +7,16 @@
7#include <asm/bitops.h> 7#include <asm/bitops.h>
8 8
9#include "av7110.h" 9#include "av7110.h"
10#include "av7110_hw.h"
10 11
11#define UP_TIMEOUT (HZ/4) 12#define UP_TIMEOUT (HZ*7/25)
12 13
13/* enable ir debugging by or'ing debug with 16 */ 14/* enable ir debugging by or'ing debug with 16 */
14 15
15static int ir_initialized; 16static int av_cnt;
17static struct av7110 *av_list[4];
16static struct input_dev input_dev; 18static struct input_dev input_dev;
17 19
18static u32 ir_config;
19
20static u16 key_map [256] = { 20static u16 key_map [256] = {
21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, 21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
22 KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO, 22 KEY_8, KEY_9, KEY_BACK, 0, KEY_POWER, KEY_MUTE, 0, KEY_INFO,
@@ -53,8 +53,11 @@ static void av7110_emit_keyup(unsigned long data)
53static struct timer_list keyup_timer = { .function = av7110_emit_keyup }; 53static struct timer_list keyup_timer = { .function = av7110_emit_keyup };
54 54
55 55
56static void av7110_emit_key(u32 ircom) 56static void av7110_emit_key(unsigned long parm)
57{ 57{
58 struct av7110 *av7110 = (struct av7110 *) parm;
59 u32 ir_config = av7110->ir_config;
60 u32 ircom = av7110->ir_command;
58 u8 data; 61 u8 data;
59 u8 addr; 62 u8 addr;
60 static u16 old_toggle = 0; 63 static u16 old_toggle = 0;
@@ -62,19 +65,33 @@ static void av7110_emit_key(u32 ircom)
62 u16 keycode; 65 u16 keycode;
63 66
64 /* extract device address and data */ 67 /* extract device address and data */
65 if (ir_config & 0x0001) { 68 switch (ir_config & 0x0003) {
66 /* TODO RCMM: ? bits device address, 8 bits data */ 69 case 0: /* RC5: 5 bits device address, 6 bits data */
70 data = ircom & 0x3f;
71 addr = (ircom >> 6) & 0x1f;
72 break;
73
74 case 1: /* RCMM: 8(?) bits device address, 8(?) bits data */
67 data = ircom & 0xff; 75 data = ircom & 0xff;
68 addr = (ircom >> 8) & 0xff; 76 addr = (ircom >> 8) & 0xff;
69 } else { 77 break;
70 /* RC5: 5 bits device address, 6 bits data */ 78
79 case 2: /* extended RC5: 5 bits device address, 7 bits data */
71 data = ircom & 0x3f; 80 data = ircom & 0x3f;
72 addr = (ircom >> 6) & 0x1f; 81 addr = (ircom >> 6) & 0x1f;
82 /* invert 7th data bit for backward compatibility with RC5 keymaps */
83 if (!(ircom & 0x1000))
84 data |= 0x40;
85 break;
86
87 default:
88 printk("invalid ir_config %x\n", ir_config);
89 return;
73 } 90 }
74 91
75 keycode = key_map[data]; 92 keycode = key_map[data];
76 93
77 dprintk(16, "#########%08x######### addr %i data 0x%02x (keycode %i)\n", 94 dprintk(16, "code %08x -> addr %i data 0x%02x -> keycode %i\n",
78 ircom, addr, data, keycode); 95 ircom, addr, data, keycode);
79 96
80 /* check device address (if selected) */ 97 /* check device address (if selected) */
@@ -87,10 +104,10 @@ static void av7110_emit_key(u32 ircom)
87 return; 104 return;
88 } 105 }
89 106
90 if (ir_config & 0x0001) 107 if ((ir_config & 0x0003) == 1)
91 new_toggle = 0; /* RCMM */ 108 new_toggle = 0; /* RCMM */
92 else 109 else
93 new_toggle = (ircom & 0x800); /* RC5 */ 110 new_toggle = (ircom & 0x800); /* RC5, extended RC5 */
94 111
95 if (timer_pending(&keyup_timer)) { 112 if (timer_pending(&keyup_timer)) {
96 del_timer(&keyup_timer); 113 del_timer(&keyup_timer);
@@ -137,6 +154,8 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
137{ 154{
138 char *page; 155 char *page;
139 int size = 4 + 256 * sizeof(u16); 156 int size = 4 + 256 * sizeof(u16);
157 u32 ir_config;
158 int i;
140 159
141 if (count < size) 160 if (count < size)
142 return -EINVAL; 161 return -EINVAL;
@@ -153,60 +172,95 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
153 memcpy(&ir_config, page, 4); 172 memcpy(&ir_config, page, 4);
154 memcpy(&key_map, page + 4, 256 * sizeof(u16)); 173 memcpy(&key_map, page + 4, 256 * sizeof(u16));
155 vfree(page); 174 vfree(page);
156 av7110_setup_irc_config(NULL, ir_config); 175 if (FW_VERSION(av_list[0]->arm_app) >= 0x2620 && !(ir_config & 0x0001))
176 ir_config |= 0x0002; /* enable extended RC5 */
177 for (i = 0; i < av_cnt; i++)
178 av7110_setup_irc_config(av_list[i], ir_config);
157 input_register_keys(); 179 input_register_keys();
158 return count; 180 return count;
159} 181}
160 182
161 183
162int __init av7110_ir_init(void) 184int av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config)
163{ 185{
164 static struct proc_dir_entry *e; 186 int ret = 0;
165 187
166 if (ir_initialized) 188 dprintk(4, "%p\n", av7110);
167 return 0; 189 if (av7110) {
190 ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config);
191 av7110->ir_config = ir_config;
192 }
193 return ret;
194}
168 195
169 init_timer(&keyup_timer);
170 keyup_timer.data = 0;
171 196
172 input_dev.name = "DVB on-card IR receiver"; 197static void ir_handler(struct av7110 *av7110, u32 ircom)
198{
199 dprintk(4, "ircommand = %08x\n", ircom);
200 av7110->ir_command = ircom;
201 tasklet_schedule(&av7110->ir_tasklet);
202}
173 203
174 /**
175 * enable keys
176 */
177 set_bit(EV_KEY, input_dev.evbit);
178 set_bit(EV_REP, input_dev.evbit);
179 204
180 input_register_keys(); 205int __init av7110_ir_init(struct av7110 *av7110)
206{
207 static struct proc_dir_entry *e;
181 208
182 input_register_device(&input_dev); 209 if (av_cnt >= sizeof av_list/sizeof av_list[0])
183 input_dev.timer.function = input_repeat_key; 210 return -ENOSPC;
184 211
185 av7110_setup_irc_config(NULL, 0x0001); 212 av7110_setup_irc_config(av7110, 0x0001);
186 av7110_register_irc_handler(av7110_emit_key); 213 av_list[av_cnt++] = av7110;
187 214
188 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); 215 if (av_cnt == 1) {
189 if (e) { 216 init_timer(&keyup_timer);
190 e->write_proc = av7110_ir_write_proc; 217 keyup_timer.data = 0;
191 e->size = 4 + 256 * sizeof(u16); 218
219 input_dev.name = "DVB on-card IR receiver";
220 set_bit(EV_KEY, input_dev.evbit);
221 set_bit(EV_REP, input_dev.evbit);
222 input_register_keys();
223 input_register_device(&input_dev);
224 input_dev.timer.function = input_repeat_key;
225
226 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL);
227 if (e) {
228 e->write_proc = av7110_ir_write_proc;
229 e->size = 4 + 256 * sizeof(u16);
230 }
192 } 231 }
193 232
194 ir_initialized = 1; 233 tasklet_init(&av7110->ir_tasklet, av7110_emit_key, (unsigned long) av7110);
234 av7110->ir_handler = ir_handler;
235
195 return 0; 236 return 0;
196} 237}
197 238
198 239
199void __exit av7110_ir_exit(void) 240void __exit av7110_ir_exit(struct av7110 *av7110)
200{ 241{
201 if (ir_initialized == 0) 242 int i;
243
244 if (av_cnt == 0)
202 return; 245 return;
203 del_timer_sync(&keyup_timer); 246
204 remove_proc_entry("av7110_ir", NULL); 247 av7110->ir_handler = NULL;
205 av7110_unregister_irc_handler(av7110_emit_key); 248 tasklet_kill(&av7110->ir_tasklet);
206 input_unregister_device(&input_dev); 249 for (i = 0; i < av_cnt; i++)
207 ir_initialized = 0; 250 if (av_list[i] == av7110) {
251 av_list[i] = av_list[av_cnt-1];
252 av_list[av_cnt-1] = NULL;
253 break;
254 }
255
256 if (av_cnt == 1) {
257 del_timer_sync(&keyup_timer);
258 remove_proc_entry("av7110_ir", NULL);
259 input_unregister_device(&input_dev);
260 }
261
262 av_cnt--;
208} 263}
209 264
210//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>"); 265//MODULE_AUTHOR("Holger Waechtler <holger@convergence.de>");
211//MODULE_LICENSE("GPL"); 266//MODULE_LICENSE("GPL");
212