diff options
author | Ricardo Cerqueira <v4l@cerqueira.org> | 2006-01-09 12:25:25 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@brturbo.com.br> | 2006-01-09 12:25:25 -0500 |
commit | 4abdfed5676e5ef7f2461bb76f5929068a9cc9cf (patch) | |
tree | ff4e3e80f57f788a9cf450966f137c44b58ff1b2 /drivers/media/video/ir-kbd-gpio.c | |
parent | e0b2d7a89bb250fb0c9068c4481c9fd26c3fb227 (diff) |
V4L/DVB (3161): ir-kbd-gpio is now part of bttv
- Merged ir-kbd-gpio into bttv as bttv-input, for consistency with other
input modules
Signed-off-by: Ricardo Cerqueira <v4l@cerqueira.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
Diffstat (limited to 'drivers/media/video/ir-kbd-gpio.c')
-rw-r--r-- | drivers/media/video/ir-kbd-gpio.c | 766 |
1 files changed, 0 insertions, 766 deletions
diff --git a/drivers/media/video/ir-kbd-gpio.c b/drivers/media/video/ir-kbd-gpio.c deleted file mode 100644 index 556da9ff128f..000000000000 --- a/drivers/media/video/ir-kbd-gpio.c +++ /dev/null | |||
@@ -1,766 +0,0 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Copyright (c) 2003 Gerd Knorr | ||
4 | * Copyright (c) 2003 Pavel Machek | ||
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; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/moduleparam.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/input.h> | ||
27 | #include <linux/pci.h> | ||
28 | |||
29 | #include "bttv.h" | ||
30 | #include <media/ir-common.h> | ||
31 | |||
32 | /* ---------------------------------------------------------------------- */ | ||
33 | |||
34 | static IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = { | ||
35 | [ 34 ] = KEY_KP0, | ||
36 | [ 40 ] = KEY_KP1, | ||
37 | [ 24 ] = KEY_KP2, | ||
38 | [ 56 ] = KEY_KP3, | ||
39 | [ 36 ] = KEY_KP4, | ||
40 | [ 20 ] = KEY_KP5, | ||
41 | [ 52 ] = KEY_KP6, | ||
42 | [ 44 ] = KEY_KP7, | ||
43 | [ 28 ] = KEY_KP8, | ||
44 | [ 60 ] = KEY_KP9, | ||
45 | |||
46 | [ 48 ] = KEY_EJECTCD, // Unmarked on my controller | ||
47 | [ 0 ] = KEY_POWER, | ||
48 | [ 18 ] = BTN_LEFT, // DISPLAY/L | ||
49 | [ 50 ] = BTN_RIGHT, // LOOP/R | ||
50 | [ 10 ] = KEY_MUTE, | ||
51 | [ 38 ] = KEY_RECORD, | ||
52 | [ 22 ] = KEY_PAUSE, | ||
53 | [ 54 ] = KEY_STOP, | ||
54 | [ 30 ] = KEY_VOLUMEDOWN, | ||
55 | [ 62 ] = KEY_VOLUMEUP, | ||
56 | |||
57 | [ 32 ] = KEY_TUNER, // TV/FM | ||
58 | [ 16 ] = KEY_CD, | ||
59 | [ 8 ] = KEY_VIDEO, | ||
60 | [ 4 ] = KEY_AUDIO, | ||
61 | [ 12 ] = KEY_ZOOM, // full screen | ||
62 | [ 2 ] = KEY_INFO, // preview | ||
63 | [ 42 ] = KEY_SEARCH, // autoscan | ||
64 | [ 26 ] = KEY_STOP, // freeze | ||
65 | [ 58 ] = KEY_RECORD, // capture | ||
66 | [ 6 ] = KEY_PLAY, // unmarked | ||
67 | [ 46 ] = KEY_RED, // unmarked | ||
68 | [ 14 ] = KEY_GREEN, // unmarked | ||
69 | |||
70 | [ 33 ] = KEY_YELLOW, // unmarked | ||
71 | [ 17 ] = KEY_CHANNELDOWN, | ||
72 | [ 49 ] = KEY_CHANNELUP, | ||
73 | [ 1 ] = KEY_BLUE, // unmarked | ||
74 | }; | ||
75 | |||
76 | /* Matt Jesson <dvb@jesson.eclipse.co.uk */ | ||
77 | static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = { | ||
78 | [ 0x28 ] = KEY_KP0, //'0' / 'enter' | ||
79 | [ 0x22 ] = KEY_KP1, //'1' | ||
80 | [ 0x12 ] = KEY_KP2, //'2' / 'up arrow' | ||
81 | [ 0x32 ] = KEY_KP3, //'3' | ||
82 | [ 0x24 ] = KEY_KP4, //'4' / 'left arrow' | ||
83 | [ 0x14 ] = KEY_KP5, //'5' | ||
84 | [ 0x34 ] = KEY_KP6, //'6' / 'right arrow' | ||
85 | [ 0x26 ] = KEY_KP7, //'7' | ||
86 | [ 0x16 ] = KEY_KP8, //'8' / 'down arrow' | ||
87 | [ 0x36 ] = KEY_KP9, //'9' | ||
88 | |||
89 | [ 0x20 ] = KEY_LIST, // 'source' | ||
90 | [ 0x10 ] = KEY_TEXT, // 'teletext' | ||
91 | [ 0x00 ] = KEY_POWER, // 'power' | ||
92 | [ 0x04 ] = KEY_AUDIO, // 'audio' | ||
93 | [ 0x06 ] = KEY_ZOOM, // 'full screen' | ||
94 | [ 0x18 ] = KEY_VIDEO, // 'display' | ||
95 | [ 0x38 ] = KEY_SEARCH, // 'loop' | ||
96 | [ 0x08 ] = KEY_INFO, // 'preview' | ||
97 | [ 0x2a ] = KEY_REWIND, // 'backward <<' | ||
98 | [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>' | ||
99 | [ 0x3a ] = KEY_RECORD, // 'capture' | ||
100 | [ 0x0a ] = KEY_MUTE, // 'mute' | ||
101 | [ 0x2c ] = KEY_RECORD, // 'record' | ||
102 | [ 0x1c ] = KEY_PAUSE, // 'pause' | ||
103 | [ 0x3c ] = KEY_STOP, // 'stop' | ||
104 | [ 0x0c ] = KEY_PLAY, // 'play' | ||
105 | [ 0x2e ] = KEY_RED, // 'red' | ||
106 | [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel' | ||
107 | [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok' | ||
108 | [ 0x21 ] = KEY_GREEN, // 'green' | ||
109 | [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -' | ||
110 | [ 0x31 ] = KEY_CHANNELUP, // 'channel +' | ||
111 | [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -' | ||
112 | [ 0x3e ] = KEY_VOLUMEUP, // 'volume +' | ||
113 | }; | ||
114 | |||
115 | /* Attila Kondoros <attila.kondoros@chello.hu> */ | ||
116 | static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = { | ||
117 | |||
118 | [ 1 ] = KEY_KP1, | ||
119 | [ 2 ] = KEY_KP2, | ||
120 | [ 3 ] = KEY_KP3, | ||
121 | [ 4 ] = KEY_KP4, | ||
122 | [ 5 ] = KEY_KP5, | ||
123 | [ 6 ] = KEY_KP6, | ||
124 | [ 7 ] = KEY_KP7, | ||
125 | [ 8 ] = KEY_KP8, | ||
126 | [ 9 ] = KEY_KP9, | ||
127 | [ 0 ] = KEY_KP0, | ||
128 | [ 23 ] = KEY_LAST, // +100 | ||
129 | [ 10 ] = KEY_LIST, // recall | ||
130 | |||
131 | |||
132 | [ 28 ] = KEY_TUNER, // TV/FM | ||
133 | [ 21 ] = KEY_SEARCH, // scan | ||
134 | [ 18 ] = KEY_POWER, // power | ||
135 | [ 31 ] = KEY_VOLUMEDOWN, // vol up | ||
136 | [ 27 ] = KEY_VOLUMEUP, // vol down | ||
137 | [ 30 ] = KEY_CHANNELDOWN, // chn up | ||
138 | [ 26 ] = KEY_CHANNELUP, // chn down | ||
139 | |||
140 | [ 17 ] = KEY_VIDEO, // video | ||
141 | [ 15 ] = KEY_ZOOM, // full screen | ||
142 | [ 19 ] = KEY_MUTE, // mute/unmute | ||
143 | [ 16 ] = KEY_TEXT, // min | ||
144 | |||
145 | [ 13 ] = KEY_STOP, // freeze | ||
146 | [ 14 ] = KEY_RECORD, // record | ||
147 | [ 29 ] = KEY_PLAYPAUSE, // stop | ||
148 | [ 25 ] = KEY_PLAY, // play | ||
149 | |||
150 | [ 22 ] = KEY_GOTO, // osd | ||
151 | [ 20 ] = KEY_REFRESH, // default | ||
152 | [ 12 ] = KEY_KPPLUS, // fine tune >>>> | ||
153 | [ 24 ] = KEY_KPMINUS // fine tune <<<< | ||
154 | }; | ||
155 | |||
156 | /* ---------------------------------------------------------------------- */ | ||
157 | |||
158 | /* Ricardo Cerqueira <v4l@cerqueira.org> */ | ||
159 | /* Weird matching, since the remote has "uncommon" keys */ | ||
160 | |||
161 | static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = { | ||
162 | |||
163 | [ 30 ] = KEY_POWER, // power | ||
164 | [ 7 ] = KEY_MEDIA, // source | ||
165 | [ 28 ] = KEY_SEARCH, // scan | ||
166 | |||
167 | /* FIXME: duplicate keycodes? | ||
168 | * | ||
169 | * These four keys seem to share the same GPIO as CH+, CH-, <<< and >>> | ||
170 | * The GPIO values are | ||
171 | * 6397fb for both "Scan <" and "CH -", | ||
172 | * 639ffb for "Scan >" and "CH+", | ||
173 | * 6384fb for "Tune <" and "<<<", | ||
174 | * 638cfb for "Tune >" and ">>>", regardless of the mask. | ||
175 | * | ||
176 | * [ 23 ] = KEY_BACK, // fm scan << | ||
177 | * [ 31 ] = KEY_FORWARD, // fm scan >> | ||
178 | * | ||
179 | * [ 4 ] = KEY_LEFT, // fm tuning < | ||
180 | * [ 12 ] = KEY_RIGHT, // fm tuning > | ||
181 | * | ||
182 | * For now, these four keys are disabled. Pressing them will generate | ||
183 | * the CH+/CH-/<<</>>> events | ||
184 | */ | ||
185 | |||
186 | [ 3 ] = KEY_TUNER, // TV/FM | ||
187 | |||
188 | [ 0 ] = KEY_RECORD, | ||
189 | [ 8 ] = KEY_STOP, | ||
190 | [ 17 ] = KEY_PLAY, | ||
191 | |||
192 | [ 26 ] = KEY_PLAYPAUSE, // freeze | ||
193 | [ 25 ] = KEY_ZOOM, // zoom | ||
194 | [ 15 ] = KEY_TEXT, // min | ||
195 | |||
196 | [ 1 ] = KEY_KP1, | ||
197 | [ 11 ] = KEY_KP2, | ||
198 | [ 27 ] = KEY_KP3, | ||
199 | [ 5 ] = KEY_KP4, | ||
200 | [ 9 ] = KEY_KP5, | ||
201 | [ 21 ] = KEY_KP6, | ||
202 | [ 6 ] = KEY_KP7, | ||
203 | [ 10 ] = KEY_KP8, | ||
204 | [ 18 ] = KEY_KP9, | ||
205 | [ 2 ] = KEY_KP0, | ||
206 | [ 16 ] = KEY_LAST, // +100 | ||
207 | [ 19 ] = KEY_LIST, // recall | ||
208 | |||
209 | [ 31 ] = KEY_CHANNELUP, // chn down | ||
210 | [ 23 ] = KEY_CHANNELDOWN, // chn up | ||
211 | [ 22 ] = KEY_VOLUMEUP, // vol down | ||
212 | [ 20 ] = KEY_VOLUMEDOWN, // vol up | ||
213 | |||
214 | [ 4 ] = KEY_KPMINUS, // <<< | ||
215 | [ 14 ] = KEY_SETUP, // function | ||
216 | [ 12 ] = KEY_KPPLUS, // >>> | ||
217 | |||
218 | [ 13 ] = KEY_GOTO, // mts | ||
219 | [ 29 ] = KEY_REFRESH, // reset | ||
220 | [ 24 ] = KEY_MUTE // mute/unmute | ||
221 | }; | ||
222 | |||
223 | static IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = { | ||
224 | [0x00] = KEY_KP0, | ||
225 | [0x01] = KEY_KP1, | ||
226 | [0x02] = KEY_KP2, | ||
227 | [0x03] = KEY_KP3, | ||
228 | [0x04] = KEY_KP4, | ||
229 | [0x05] = KEY_KP5, | ||
230 | [0x06] = KEY_KP6, | ||
231 | [0x07] = KEY_KP7, | ||
232 | [0x08] = KEY_KP8, | ||
233 | [0x09] = KEY_KP9, | ||
234 | [0x0a] = KEY_TV, | ||
235 | [0x0b] = KEY_AUX, | ||
236 | [0x0c] = KEY_DVD, | ||
237 | [0x0d] = KEY_POWER, | ||
238 | [0x0e] = KEY_MHP, /* labelled 'Picture' */ | ||
239 | [0x0f] = KEY_AUDIO, | ||
240 | [0x10] = KEY_INFO, | ||
241 | [0x11] = KEY_F13, /* 16:9 */ | ||
242 | [0x12] = KEY_F14, /* 14:9 */ | ||
243 | [0x13] = KEY_EPG, | ||
244 | [0x14] = KEY_EXIT, | ||
245 | [0x15] = KEY_MENU, | ||
246 | [0x16] = KEY_UP, | ||
247 | [0x17] = KEY_DOWN, | ||
248 | [0x18] = KEY_LEFT, | ||
249 | [0x19] = KEY_RIGHT, | ||
250 | [0x1a] = KEY_ENTER, | ||
251 | [0x1b] = KEY_CHANNELUP, | ||
252 | [0x1c] = KEY_CHANNELDOWN, | ||
253 | [0x1d] = KEY_VOLUMEUP, | ||
254 | [0x1e] = KEY_VOLUMEDOWN, | ||
255 | [0x1f] = KEY_RED, | ||
256 | [0x20] = KEY_GREEN, | ||
257 | [0x21] = KEY_YELLOW, | ||
258 | [0x22] = KEY_BLUE, | ||
259 | [0x23] = KEY_SUBTITLE, | ||
260 | [0x24] = KEY_F15, /* AD */ | ||
261 | [0x25] = KEY_TEXT, | ||
262 | [0x26] = KEY_MUTE, | ||
263 | [0x27] = KEY_REWIND, | ||
264 | [0x28] = KEY_STOP, | ||
265 | [0x29] = KEY_PLAY, | ||
266 | [0x2a] = KEY_FASTFORWARD, | ||
267 | [0x2b] = KEY_F16, /* chapter */ | ||
268 | [0x2c] = KEY_PAUSE, | ||
269 | [0x2d] = KEY_PLAY, | ||
270 | [0x2e] = KEY_RECORD, | ||
271 | [0x2f] = KEY_F17, /* picture in picture */ | ||
272 | [0x30] = KEY_KPPLUS, /* zoom in */ | ||
273 | [0x31] = KEY_KPMINUS, /* zoom out */ | ||
274 | [0x32] = KEY_F18, /* capture */ | ||
275 | [0x33] = KEY_F19, /* web */ | ||
276 | [0x34] = KEY_EMAIL, | ||
277 | [0x35] = KEY_PHONE, | ||
278 | [0x36] = KEY_PC | ||
279 | }; | ||
280 | |||
281 | struct IR { | ||
282 | struct bttv_sub_device *sub; | ||
283 | struct input_dev *input; | ||
284 | struct ir_input_state ir; | ||
285 | char name[32]; | ||
286 | char phys[32]; | ||
287 | |||
288 | /* Usual gpio signalling */ | ||
289 | |||
290 | u32 mask_keycode; | ||
291 | u32 mask_keydown; | ||
292 | u32 mask_keyup; | ||
293 | u32 polling; | ||
294 | u32 last_gpio; | ||
295 | struct work_struct work; | ||
296 | struct timer_list timer; | ||
297 | |||
298 | /* RC5 gpio */ | ||
299 | u32 rc5_gpio; | ||
300 | struct timer_list timer_end; /* timer_end for code completion */ | ||
301 | struct timer_list timer_keyup; /* timer_end for key release */ | ||
302 | u32 last_rc5; /* last good rc5 code */ | ||
303 | u32 last_bit; /* last raw bit seen */ | ||
304 | u32 code; /* raw code under construction */ | ||
305 | struct timeval base_time; /* time of last seen code */ | ||
306 | int active; /* building raw code */ | ||
307 | }; | ||
308 | |||
309 | static int debug; | ||
310 | module_param(debug, int, 0644); /* debug level (0,1,2) */ | ||
311 | static int repeat_delay = 500; | ||
312 | module_param(repeat_delay, int, 0644); | ||
313 | static int repeat_period = 33; | ||
314 | module_param(repeat_period, int, 0644); | ||
315 | |||
316 | #define DEVNAME "ir-kbd-gpio" | ||
317 | #define dprintk(fmt, arg...) if (debug) \ | ||
318 | printk(KERN_DEBUG DEVNAME ": " fmt , ## arg) | ||
319 | |||
320 | static void ir_irq(struct bttv_sub_device *sub); | ||
321 | static int ir_probe(struct device *dev); | ||
322 | static int ir_remove(struct device *dev); | ||
323 | |||
324 | static struct bttv_sub_driver driver = { | ||
325 | .drv = { | ||
326 | .name = DEVNAME, | ||
327 | .probe = ir_probe, | ||
328 | .remove = ir_remove, | ||
329 | }, | ||
330 | .gpio_irq = ir_irq, | ||
331 | }; | ||
332 | |||
333 | /* ---------------------------------------------------------------------- */ | ||
334 | |||
335 | static void ir_handle_key(struct IR *ir) | ||
336 | { | ||
337 | u32 gpio,data; | ||
338 | |||
339 | /* read gpio value */ | ||
340 | gpio = bttv_gpio_read(ir->sub->core); | ||
341 | if (ir->polling) { | ||
342 | if (ir->last_gpio == gpio) | ||
343 | return; | ||
344 | ir->last_gpio = gpio; | ||
345 | } | ||
346 | |||
347 | /* extract data */ | ||
348 | data = ir_extract_bits(gpio, ir->mask_keycode); | ||
349 | dprintk(DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n", | ||
350 | gpio, data, | ||
351 | ir->polling ? "poll" : "irq", | ||
352 | (gpio & ir->mask_keydown) ? " down" : "", | ||
353 | (gpio & ir->mask_keyup) ? " up" : ""); | ||
354 | |||
355 | if (ir->mask_keydown) { | ||
356 | /* bit set on keydown */ | ||
357 | if (gpio & ir->mask_keydown) { | ||
358 | ir_input_keydown(ir->input, &ir->ir, data, data); | ||
359 | } else { | ||
360 | ir_input_nokey(ir->input, &ir->ir); | ||
361 | } | ||
362 | |||
363 | } else if (ir->mask_keyup) { | ||
364 | /* bit cleared on keydown */ | ||
365 | if (0 == (gpio & ir->mask_keyup)) { | ||
366 | ir_input_keydown(ir->input, &ir->ir, data, data); | ||
367 | } else { | ||
368 | ir_input_nokey(ir->input, &ir->ir); | ||
369 | } | ||
370 | |||
371 | } else { | ||
372 | /* can't disturgissh keydown/up :-/ */ | ||
373 | ir_input_keydown(ir->input, &ir->ir, data, data); | ||
374 | ir_input_nokey(ir->input, &ir->ir); | ||
375 | } | ||
376 | } | ||
377 | |||
378 | static void ir_irq(struct bttv_sub_device *sub) | ||
379 | { | ||
380 | struct IR *ir = dev_get_drvdata(&sub->dev); | ||
381 | |||
382 | if (!ir->polling) | ||
383 | ir_handle_key(ir); | ||
384 | } | ||
385 | |||
386 | static void ir_timer(unsigned long data) | ||
387 | { | ||
388 | struct IR *ir = (struct IR*)data; | ||
389 | |||
390 | schedule_work(&ir->work); | ||
391 | } | ||
392 | |||
393 | static void ir_work(void *data) | ||
394 | { | ||
395 | struct IR *ir = data; | ||
396 | unsigned long timeout; | ||
397 | |||
398 | ir_handle_key(ir); | ||
399 | timeout = jiffies + (ir->polling * HZ / 1000); | ||
400 | mod_timer(&ir->timer, timeout); | ||
401 | } | ||
402 | |||
403 | /* ---------------------------------------------------------------*/ | ||
404 | |||
405 | static int rc5_remote_gap = 885; | ||
406 | module_param(rc5_remote_gap, int, 0644); | ||
407 | static int rc5_key_timeout = 200; | ||
408 | module_param(rc5_key_timeout, int, 0644); | ||
409 | |||
410 | #define RC5_START(x) (((x)>>12)&3) | ||
411 | #define RC5_TOGGLE(x) (((x)>>11)&1) | ||
412 | #define RC5_ADDR(x) (((x)>>6)&31) | ||
413 | #define RC5_INSTR(x) ((x)&63) | ||
414 | |||
415 | /* decode raw bit pattern to RC5 code */ | ||
416 | static u32 rc5_decode(unsigned int code) | ||
417 | { | ||
418 | unsigned int org_code = code; | ||
419 | unsigned int pair; | ||
420 | unsigned int rc5 = 0; | ||
421 | int i; | ||
422 | |||
423 | code = (code << 1) | 1; | ||
424 | for (i = 0; i < 14; ++i) { | ||
425 | pair = code & 0x3; | ||
426 | code >>= 2; | ||
427 | |||
428 | rc5 <<= 1; | ||
429 | switch (pair) { | ||
430 | case 0: | ||
431 | case 2: | ||
432 | break; | ||
433 | case 1: | ||
434 | rc5 |= 1; | ||
435 | break; | ||
436 | case 3: | ||
437 | dprintk("bad code: %x\n", org_code); | ||
438 | return 0; | ||
439 | } | ||
440 | } | ||
441 | dprintk("code=%x, rc5=%x, start=%x, toggle=%x, address=%x, " | ||
442 | "instr=%x\n", rc5, org_code, RC5_START(rc5), | ||
443 | RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5)); | ||
444 | return rc5; | ||
445 | } | ||
446 | |||
447 | static int ir_rc5_irq(struct bttv_sub_device *sub) | ||
448 | { | ||
449 | struct IR *ir = dev_get_drvdata(&sub->dev); | ||
450 | struct timeval tv; | ||
451 | u32 gpio; | ||
452 | u32 gap; | ||
453 | unsigned long current_jiffies, timeout; | ||
454 | |||
455 | /* read gpio port */ | ||
456 | gpio = bttv_gpio_read(ir->sub->core); | ||
457 | |||
458 | /* remote IRQ? */ | ||
459 | if (!(gpio & 0x20)) | ||
460 | return 0; | ||
461 | |||
462 | /* get time of bit */ | ||
463 | current_jiffies = jiffies; | ||
464 | do_gettimeofday(&tv); | ||
465 | |||
466 | /* avoid overflow with gap >1s */ | ||
467 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { | ||
468 | gap = 200000; | ||
469 | } else { | ||
470 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + | ||
471 | tv.tv_usec - ir->base_time.tv_usec; | ||
472 | } | ||
473 | |||
474 | /* active code => add bit */ | ||
475 | if (ir->active) { | ||
476 | /* only if in the code (otherwise spurious IRQ or timer | ||
477 | late) */ | ||
478 | if (ir->last_bit < 28) { | ||
479 | ir->last_bit = (gap - rc5_remote_gap / 2) / | ||
480 | rc5_remote_gap; | ||
481 | ir->code |= 1 << ir->last_bit; | ||
482 | } | ||
483 | /* starting new code */ | ||
484 | } else { | ||
485 | ir->active = 1; | ||
486 | ir->code = 0; | ||
487 | ir->base_time = tv; | ||
488 | ir->last_bit = 0; | ||
489 | |||
490 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; | ||
491 | mod_timer(&ir->timer_end, timeout); | ||
492 | } | ||
493 | |||
494 | /* toggle GPIO pin 4 to reset the irq */ | ||
495 | bttv_gpio_write(ir->sub->core, gpio & ~(1 << 4)); | ||
496 | bttv_gpio_write(ir->sub->core, gpio | (1 << 4)); | ||
497 | return 1; | ||
498 | } | ||
499 | |||
500 | static void ir_rc5_timer_end(unsigned long data) | ||
501 | { | ||
502 | struct IR *ir = (struct IR *)data; | ||
503 | struct timeval tv; | ||
504 | unsigned long current_jiffies, timeout; | ||
505 | u32 gap; | ||
506 | |||
507 | /* get time */ | ||
508 | current_jiffies = jiffies; | ||
509 | do_gettimeofday(&tv); | ||
510 | |||
511 | /* avoid overflow with gap >1s */ | ||
512 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { | ||
513 | gap = 200000; | ||
514 | } else { | ||
515 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + | ||
516 | tv.tv_usec - ir->base_time.tv_usec; | ||
517 | } | ||
518 | |||
519 | /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */ | ||
520 | if (gap < 28000) { | ||
521 | dprintk("spurious timer_end\n"); | ||
522 | return; | ||
523 | } | ||
524 | |||
525 | ir->active = 0; | ||
526 | if (ir->last_bit < 20) { | ||
527 | /* ignore spurious codes (caused by light/other remotes) */ | ||
528 | dprintk("short code: %x\n", ir->code); | ||
529 | } else { | ||
530 | u32 rc5 = rc5_decode(ir->code); | ||
531 | |||
532 | /* two start bits? */ | ||
533 | if (RC5_START(rc5) != 3) { | ||
534 | dprintk("rc5 start bits invalid: %u\n", RC5_START(rc5)); | ||
535 | |||
536 | /* right address? */ | ||
537 | } else if (RC5_ADDR(rc5) == 0x0) { | ||
538 | u32 toggle = RC5_TOGGLE(rc5); | ||
539 | u32 instr = RC5_INSTR(rc5); | ||
540 | |||
541 | /* Good code, decide if repeat/repress */ | ||
542 | if (toggle != RC5_TOGGLE(ir->last_rc5) || | ||
543 | instr != RC5_INSTR(ir->last_rc5)) { | ||
544 | dprintk("instruction %x, toggle %x\n", instr, | ||
545 | toggle); | ||
546 | ir_input_nokey(ir->input, &ir->ir); | ||
547 | ir_input_keydown(ir->input, &ir->ir, instr, | ||
548 | instr); | ||
549 | } | ||
550 | |||
551 | /* Set/reset key-up timer */ | ||
552 | timeout = current_jiffies + (500 + rc5_key_timeout | ||
553 | * HZ) / 1000; | ||
554 | mod_timer(&ir->timer_keyup, timeout); | ||
555 | |||
556 | /* Save code for repeat test */ | ||
557 | ir->last_rc5 = rc5; | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | |||
562 | static void ir_rc5_timer_keyup(unsigned long data) | ||
563 | { | ||
564 | struct IR *ir = (struct IR *)data; | ||
565 | |||
566 | dprintk("key released\n"); | ||
567 | ir_input_nokey(ir->input, &ir->ir); | ||
568 | } | ||
569 | |||
570 | /* ---------------------------------------------------------------------- */ | ||
571 | |||
572 | static int ir_probe(struct device *dev) | ||
573 | { | ||
574 | struct bttv_sub_device *sub = to_bttv_sub_dev(dev); | ||
575 | struct IR *ir; | ||
576 | struct input_dev *input_dev; | ||
577 | IR_KEYTAB_TYPE *ir_codes = NULL; | ||
578 | int ir_type = IR_TYPE_OTHER; | ||
579 | |||
580 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); | ||
581 | input_dev = input_allocate_device(); | ||
582 | if (!ir || !input_dev) { | ||
583 | kfree(ir); | ||
584 | input_free_device(input_dev); | ||
585 | return -ENOMEM; | ||
586 | } | ||
587 | |||
588 | /* detect & configure */ | ||
589 | switch (sub->core->type) { | ||
590 | case BTTV_BOARD_AVERMEDIA: | ||
591 | case BTTV_BOARD_AVPHONE98: | ||
592 | case BTTV_BOARD_AVERMEDIA98: | ||
593 | ir_codes = ir_codes_avermedia; | ||
594 | ir->mask_keycode = 0xf88000; | ||
595 | ir->mask_keydown = 0x010000; | ||
596 | ir->polling = 50; // ms | ||
597 | break; | ||
598 | |||
599 | case BTTV_BOARD_AVDVBT_761: | ||
600 | case BTTV_BOARD_AVDVBT_771: | ||
601 | ir_codes = ir_codes_avermedia_dvbt; | ||
602 | ir->mask_keycode = 0x0f00c0; | ||
603 | ir->mask_keydown = 0x000020; | ||
604 | ir->polling = 50; // ms | ||
605 | break; | ||
606 | |||
607 | case BTTV_BOARD_PXELVWPLTVPAK: | ||
608 | ir_codes = ir_codes_pixelview; | ||
609 | ir->mask_keycode = 0x003e00; | ||
610 | ir->mask_keyup = 0x010000; | ||
611 | ir->polling = 50; // ms | ||
612 | break; | ||
613 | case BTTV_BOARD_PV_BT878P_9B: | ||
614 | case BTTV_BOARD_PV_BT878P_PLUS: | ||
615 | ir_codes = ir_codes_pixelview; | ||
616 | ir->mask_keycode = 0x001f00; | ||
617 | ir->mask_keyup = 0x008000; | ||
618 | ir->polling = 50; // ms | ||
619 | break; | ||
620 | |||
621 | case BTTV_BOARD_WINFAST2000: | ||
622 | ir_codes = ir_codes_winfast; | ||
623 | ir->mask_keycode = 0x1f8; | ||
624 | break; | ||
625 | case BTTV_BOARD_MAGICTVIEW061: | ||
626 | case BTTV_BOARD_MAGICTVIEW063: | ||
627 | ir_codes = ir_codes_winfast; | ||
628 | ir->mask_keycode = 0x0008e000; | ||
629 | ir->mask_keydown = 0x00200000; | ||
630 | break; | ||
631 | case BTTV_BOARD_APAC_VIEWCOMP: | ||
632 | ir_codes = ir_codes_apac_viewcomp; | ||
633 | ir->mask_keycode = 0x001f00; | ||
634 | ir->mask_keyup = 0x008000; | ||
635 | ir->polling = 50; // ms | ||
636 | break; | ||
637 | case BTTV_BOARD_CONCEPTRONIC_CTVFMI2: | ||
638 | ir_codes = ir_codes_conceptronic; | ||
639 | ir->mask_keycode = 0x001F00; | ||
640 | ir->mask_keyup = 0x006000; | ||
641 | ir->polling = 50; // ms | ||
642 | break; | ||
643 | case BTTV_BOARD_NEBULA_DIGITV: | ||
644 | ir_codes = ir_codes_nebula; | ||
645 | driver.any_irq = ir_rc5_irq; | ||
646 | driver.gpio_irq = NULL; | ||
647 | ir->rc5_gpio = 1; | ||
648 | break; | ||
649 | } | ||
650 | if (NULL == ir_codes) { | ||
651 | kfree(ir); | ||
652 | input_free_device(input_dev); | ||
653 | return -ENODEV; | ||
654 | } | ||
655 | |||
656 | if (ir->rc5_gpio) { | ||
657 | u32 gpio; | ||
658 | /* enable remote irq */ | ||
659 | bttv_gpio_inout(sub->core, (1 << 4), 1 << 4); | ||
660 | gpio = bttv_gpio_read(sub->core); | ||
661 | bttv_gpio_write(sub->core, gpio & ~(1 << 4)); | ||
662 | bttv_gpio_write(sub->core, gpio | (1 << 4)); | ||
663 | } else { | ||
664 | /* init hardware-specific stuff */ | ||
665 | bttv_gpio_inout(sub->core, ir->mask_keycode | ir->mask_keydown, 0); | ||
666 | } | ||
667 | |||
668 | /* init input device */ | ||
669 | snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", | ||
670 | sub->core->type); | ||
671 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", | ||
672 | pci_name(sub->core->pci)); | ||
673 | |||
674 | ir->input = input_dev; | ||
675 | ir->sub = sub; | ||
676 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); | ||
677 | input_dev->name = ir->name; | ||
678 | input_dev->phys = ir->phys; | ||
679 | input_dev->id.bustype = BUS_PCI; | ||
680 | input_dev->id.version = 1; | ||
681 | if (sub->core->pci->subsystem_vendor) { | ||
682 | input_dev->id.vendor = sub->core->pci->subsystem_vendor; | ||
683 | input_dev->id.product = sub->core->pci->subsystem_device; | ||
684 | } else { | ||
685 | input_dev->id.vendor = sub->core->pci->vendor; | ||
686 | input_dev->id.product = sub->core->pci->device; | ||
687 | } | ||
688 | input_dev->cdev.dev = &sub->core->pci->dev; | ||
689 | |||
690 | if (ir->polling) { | ||
691 | INIT_WORK(&ir->work, ir_work, ir); | ||
692 | init_timer(&ir->timer); | ||
693 | ir->timer.function = ir_timer; | ||
694 | ir->timer.data = (unsigned long)ir; | ||
695 | schedule_work(&ir->work); | ||
696 | } else if (ir->rc5_gpio) { | ||
697 | /* set timer_end for code completion */ | ||
698 | init_timer(&ir->timer_end); | ||
699 | ir->timer_end.function = ir_rc5_timer_end; | ||
700 | ir->timer_end.data = (unsigned long)ir; | ||
701 | |||
702 | init_timer(&ir->timer_keyup); | ||
703 | ir->timer_keyup.function = ir_rc5_timer_keyup; | ||
704 | ir->timer_keyup.data = (unsigned long)ir; | ||
705 | } | ||
706 | |||
707 | /* all done */ | ||
708 | dev_set_drvdata(dev, ir); | ||
709 | input_register_device(ir->input); | ||
710 | |||
711 | /* the remote isn't as bouncy as a keyboard */ | ||
712 | ir->input->rep[REP_DELAY] = repeat_delay; | ||
713 | ir->input->rep[REP_PERIOD] = repeat_period; | ||
714 | |||
715 | return 0; | ||
716 | } | ||
717 | |||
718 | static int ir_remove(struct device *dev) | ||
719 | { | ||
720 | struct IR *ir = dev_get_drvdata(dev); | ||
721 | |||
722 | if (ir->polling) { | ||
723 | del_timer(&ir->timer); | ||
724 | flush_scheduled_work(); | ||
725 | } | ||
726 | |||
727 | if (ir->rc5_gpio) { | ||
728 | u32 gpio; | ||
729 | |||
730 | del_timer(&ir->timer_end); | ||
731 | flush_scheduled_work(); | ||
732 | |||
733 | gpio = bttv_gpio_read(ir->sub->core); | ||
734 | bttv_gpio_write(ir->sub->core, gpio & ~(1 << 4)); | ||
735 | } | ||
736 | |||
737 | input_unregister_device(ir->input); | ||
738 | kfree(ir); | ||
739 | return 0; | ||
740 | } | ||
741 | |||
742 | /* ---------------------------------------------------------------------- */ | ||
743 | |||
744 | MODULE_AUTHOR("Gerd Knorr, Pavel Machek"); | ||
745 | MODULE_DESCRIPTION("input driver for bt8x8 gpio IR remote controls"); | ||
746 | MODULE_LICENSE("GPL"); | ||
747 | |||
748 | static int ir_init(void) | ||
749 | { | ||
750 | return bttv_sub_register(&driver, "remote"); | ||
751 | } | ||
752 | |||
753 | static void ir_fini(void) | ||
754 | { | ||
755 | bttv_sub_unregister(&driver); | ||
756 | } | ||
757 | |||
758 | module_init(ir_init); | ||
759 | module_exit(ir_fini); | ||
760 | |||
761 | |||
762 | /* | ||
763 | * Local variables: | ||
764 | * c-basic-offset: 8 | ||
765 | * End: | ||
766 | */ | ||