diff options
author | Oliver Endriss <o.endriss@gmx.de> | 2005-09-09 16:03:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-09 16:57:46 -0400 |
commit | 03388ae30260475650bab24223151397afb72ec9 (patch) | |
tree | f393f529f904cc1d53c87221ef3ec383b5e5f2bc | |
parent | 9a7b102e7f5ccb2826a81315abc89f95adaf4421 (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>
-rw-r--r-- | drivers/media/dvb/ttpci/av7110.c | 70 | ||||
-rw-r--r-- | drivers/media/dvb/ttpci/av7110.h | 11 | ||||
-rw-r--r-- | drivers/media/dvb/ttpci/av7110_ir.c | 140 |
3 files changed, 110 insertions, 111 deletions
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c index 48e8097d8430..b5d40d424365 100644 --- a/drivers/media/dvb/ttpci/av7110.c +++ b/drivers/media/dvb/ttpci/av7110.c | |||
@@ -177,9 +177,6 @@ static void init_av7110_av(struct av7110 *av7110) | |||
177 | ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right); | 177 | ret = av7110_set_volume(av7110, av7110->mixer.volume_left, av7110->mixer.volume_right); |
178 | if (ret < 0) | 178 | if (ret < 0) |
179 | printk("dvb-ttpci:cannot set volume :%d\n",ret); | 179 | printk("dvb-ttpci:cannot set volume :%d\n",ret); |
180 | ret = av7110_setup_irc_config(av7110, 0); | ||
181 | if (ret < 0) | ||
182 | printk("dvb-ttpci:cannot setup irc config :%d\n",ret); | ||
183 | } | 180 | } |
184 | 181 | ||
185 | static void recover_arm(struct av7110 *av7110) | 182 | static void recover_arm(struct av7110 *av7110) |
@@ -265,60 +262,6 @@ static int arm_thread(void *data) | |||
265 | } | 262 | } |
266 | 263 | ||
267 | 264 | ||
268 | /** | ||
269 | * Hack! we save the last av7110 ptr. This should be ok, since | ||
270 | * you rarely will use more then one IR control. | ||
271 | * | ||
272 | * If we want to support multiple controls we would have to do much more... | ||
273 | */ | ||
274 | int av7110_setup_irc_config(struct av7110 *av7110, u32 ir_config) | ||
275 | { | ||
276 | int ret = 0; | ||
277 | static struct av7110 *last; | ||
278 | |||
279 | dprintk(4, "%p\n", av7110); | ||
280 | |||
281 | if (!av7110) | ||
282 | av7110 = last; | ||
283 | else | ||
284 | last = av7110; | ||
285 | |||
286 | if (av7110) { | ||
287 | ret = av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetIR, 1, ir_config); | ||
288 | av7110->ir_config = ir_config; | ||
289 | } | ||
290 | return ret; | ||
291 | } | ||
292 | |||
293 | static void (*irc_handler)(u32); | ||
294 | |||
295 | void av7110_register_irc_handler(void (*func)(u32)) | ||
296 | { | ||
297 | dprintk(4, "registering %p\n", func); | ||
298 | irc_handler = func; | ||
299 | } | ||
300 | |||
301 | void av7110_unregister_irc_handler(void (*func)(u32)) | ||
302 | { | ||
303 | dprintk(4, "unregistering %p\n", func); | ||
304 | irc_handler = NULL; | ||
305 | } | ||
306 | |||
307 | static void run_handlers(unsigned long ircom) | ||
308 | { | ||
309 | if (irc_handler != NULL) | ||
310 | (*irc_handler)((u32) ircom); | ||
311 | } | ||
312 | |||
313 | static DECLARE_TASKLET(irtask, run_handlers, 0); | ||
314 | |||
315 | static void IR_handle(struct av7110 *av7110, u32 ircom) | ||
316 | { | ||
317 | dprintk(4, "ircommand = %08x\n", ircom); | ||
318 | irtask.data = (unsigned long) ircom; | ||
319 | tasklet_schedule(&irtask); | ||
320 | } | ||
321 | |||
322 | /**************************************************************************** | 265 | /**************************************************************************** |
323 | * IRQ handling | 266 | * IRQ handling |
324 | ****************************************************************************/ | 267 | ****************************************************************************/ |
@@ -711,8 +654,9 @@ static void gpioirq(unsigned long data) | |||
711 | return; | 654 | return; |
712 | 655 | ||
713 | case DATA_IRCOMMAND: | 656 | case DATA_IRCOMMAND: |
714 | IR_handle(av7110, | 657 | if (av7110->ir_handler) |
715 | swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4))); | 658 | av7110->ir_handler(av7110, |
659 | swahw32(irdebi(av7110, DEBINOSWAP, Reserved, 0, 4))); | ||
716 | iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2); | 660 | iwdebi(av7110, DEBINOSWAP, RX_BUFF, 0, 2); |
717 | break; | 661 | break; |
718 | 662 | ||
@@ -2783,7 +2727,7 @@ static int av7110_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_d | |||
2783 | goto err_av7110_exit_v4l_12; | 2727 | goto err_av7110_exit_v4l_12; |
2784 | 2728 | ||
2785 | #if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) | 2729 | #if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) |
2786 | av7110_ir_init(); | 2730 | av7110_ir_init(av7110); |
2787 | #endif | 2731 | #endif |
2788 | printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num); | 2732 | printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num); |
2789 | av7110_num++; | 2733 | av7110_num++; |
@@ -2825,6 +2769,9 @@ static int av7110_detach(struct saa7146_dev* saa) | |||
2825 | struct av7110 *av7110 = saa->ext_priv; | 2769 | struct av7110 *av7110 = saa->ext_priv; |
2826 | dprintk(4, "%p\n", av7110); | 2770 | dprintk(4, "%p\n", av7110); |
2827 | 2771 | ||
2772 | #if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) | ||
2773 | av7110_ir_exit(av7110); | ||
2774 | #endif | ||
2828 | if (budgetpatch) { | 2775 | if (budgetpatch) { |
2829 | /* Disable RPS1 */ | 2776 | /* Disable RPS1 */ |
2830 | saa7146_write(saa, MC1, MASK_29); | 2777 | saa7146_write(saa, MC1, MASK_29); |
@@ -2980,9 +2927,6 @@ static int __init av7110_init(void) | |||
2980 | 2927 | ||
2981 | static void __exit av7110_exit(void) | 2928 | static void __exit av7110_exit(void) |
2982 | { | 2929 | { |
2983 | #if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) | ||
2984 | av7110_ir_exit(); | ||
2985 | #endif | ||
2986 | saa7146_unregister_extension(&av7110_extension); | 2930 | saa7146_unregister_extension(&av7110_extension); |
2987 | } | 2931 | } |
2988 | 2932 | ||
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h index 508b7739c609..cce00ef293e9 100644 --- a/drivers/media/dvb/ttpci/av7110.h +++ b/drivers/media/dvb/ttpci/av7110.h | |||
@@ -228,7 +228,10 @@ struct av7110 { | |||
228 | struct dvb_video_events video_events; | 228 | struct dvb_video_events video_events; |
229 | video_size_t video_size; | 229 | video_size_t video_size; |
230 | 230 | ||
231 | u32 ir_config; | 231 | u32 ir_config; |
232 | u32 ir_command; | ||
233 | void (*ir_handler)(struct av7110 *av7110, u32 ircom); | ||
234 | struct tasklet_struct ir_tasklet; | ||
232 | 235 | ||
233 | /* firmware stuff */ | 236 | /* firmware stuff */ |
234 | unsigned char *bin_fw; | 237 | unsigned char *bin_fw; |
@@ -257,12 +260,10 @@ struct av7110 { | |||
257 | extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, | 260 | extern int ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid, |
258 | u16 subpid, u16 pcrpid); | 261 | u16 subpid, u16 pcrpid); |
259 | 262 | ||
260 | extern void av7110_register_irc_handler(void (*func)(u32)); | ||
261 | extern void av7110_unregister_irc_handler(void (*func)(u32)); | ||
262 | extern int av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config); | 263 | extern int av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config); |
263 | 264 | ||
264 | extern int av7110_ir_init (void); | 265 | extern int av7110_ir_init(struct av7110 *av7110); |
265 | extern void av7110_ir_exit (void); | 266 | extern void av7110_ir_exit(struct av7110 *av7110); |
266 | 267 | ||
267 | /* msp3400 i2c subaddresses */ | 268 | /* msp3400 i2c subaddresses */ |
268 | #define MSP_WR_DEM 0x10 | 269 | #define MSP_WR_DEM 0x10 |
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 | ||
15 | static int ir_initialized; | 16 | static int av_cnt; |
17 | static struct av7110 *av_list[4]; | ||
16 | static struct input_dev input_dev; | 18 | static struct input_dev input_dev; |
17 | 19 | ||
18 | static u32 ir_config; | ||
19 | |||
20 | static u16 key_map [256] = { | 20 | static 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) | |||
53 | static struct timer_list keyup_timer = { .function = av7110_emit_keyup }; | 53 | static struct timer_list keyup_timer = { .function = av7110_emit_keyup }; |
54 | 54 | ||
55 | 55 | ||
56 | static void av7110_emit_key(u32 ircom) | 56 | static 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 | ||
162 | int __init av7110_ir_init(void) | 184 | int 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"; | 197 | static 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(); | 205 | int __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 | ||
199 | void __exit av7110_ir_exit(void) | 240 | void __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 | |||