[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / media / video / saa7134 / saa7134-input.c
blobca50cf531f20948aed62c3524a53c6ca968997ac
1 /*
2 * $Id: saa7134-input.c,v 1.16 2004/12/10 12:33:39 kraxel Exp $
4 * handle saa7134 IR remotes via linux kernel input layer.
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.
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.
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
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/sched.h>
27 #include <linux/interrupt.h>
28 #include <linux/input.h>
30 #include "saa7134-reg.h"
31 #include "saa7134.h"
33 static unsigned int disable_ir = 0;
34 module_param(disable_ir, int, 0444);
35 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
37 static unsigned int ir_debug = 0;
38 module_param(ir_debug, int, 0644);
39 MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
41 #define dprintk(fmt, arg...) if (ir_debug) \
42 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
44 /* ---------------------------------------------------------------------- */
46 static IR_KEYTAB_TYPE flyvideo_codes[IR_KEYTAB_SIZE] = {
47 [ 15 ] = KEY_KP0,
48 [ 3 ] = KEY_KP1,
49 [ 4 ] = KEY_KP2,
50 [ 5 ] = KEY_KP3,
51 [ 7 ] = KEY_KP4,
52 [ 8 ] = KEY_KP5,
53 [ 9 ] = KEY_KP6,
54 [ 11 ] = KEY_KP7,
55 [ 12 ] = KEY_KP8,
56 [ 13 ] = KEY_KP9,
58 [ 14 ] = KEY_TUNER, // Air/Cable
59 [ 17 ] = KEY_VIDEO, // Video
60 [ 21 ] = KEY_AUDIO, // Audio
61 [ 0 ] = KEY_POWER, // Pover
62 [ 2 ] = KEY_ZOOM, // Fullscreen
63 [ 27 ] = KEY_MUTE, // Mute
64 [ 20 ] = KEY_VOLUMEUP,
65 [ 23 ] = KEY_VOLUMEDOWN,
66 [ 18 ] = KEY_CHANNELUP, // Channel +
67 [ 19 ] = KEY_CHANNELDOWN, // Channel -
68 [ 6 ] = KEY_AGAIN, // Recal
69 [ 16 ] = KEY_KPENTER, // Enter
71 #if 1 /* FIXME */
72 [ 26 ] = KEY_F22, // Stereo
73 [ 24 ] = KEY_EDIT, // AV Source
74 #endif
77 static IR_KEYTAB_TYPE cinergy_codes[IR_KEYTAB_SIZE] = {
78 [ 0 ] = KEY_KP0,
79 [ 1 ] = KEY_KP1,
80 [ 2 ] = KEY_KP2,
81 [ 3 ] = KEY_KP3,
82 [ 4 ] = KEY_KP4,
83 [ 5 ] = KEY_KP5,
84 [ 6 ] = KEY_KP6,
85 [ 7 ] = KEY_KP7,
86 [ 8 ] = KEY_KP8,
87 [ 9 ] = KEY_KP9,
89 [ 0x0a ] = KEY_POWER,
90 [ 0x0b ] = KEY_PROG1, // app
91 [ 0x0c ] = KEY_ZOOM, // zoom/fullscreen
92 [ 0x0d ] = KEY_CHANNELUP, // channel
93 [ 0x0e ] = KEY_CHANNELDOWN, // channel-
94 [ 0x0f ] = KEY_VOLUMEUP,
95 [ 0x10 ] = KEY_VOLUMEDOWN,
96 [ 0x11 ] = KEY_TUNER, // AV
97 [ 0x12 ] = KEY_NUMLOCK, // -/--
98 [ 0x13 ] = KEY_AUDIO, // audio
99 [ 0x14 ] = KEY_MUTE,
100 [ 0x15 ] = KEY_UP,
101 [ 0x16 ] = KEY_DOWN,
102 [ 0x17 ] = KEY_LEFT,
103 [ 0x18 ] = KEY_RIGHT,
104 [ 0x19 ] = BTN_LEFT,
105 [ 0x1a ] = BTN_RIGHT,
106 [ 0x1b ] = KEY_WWW, // text
107 [ 0x1c ] = KEY_REWIND,
108 [ 0x1d ] = KEY_FORWARD,
109 [ 0x1e ] = KEY_RECORD,
110 [ 0x1f ] = KEY_PLAY,
111 [ 0x20 ] = KEY_PREVIOUSSONG,
112 [ 0x21 ] = KEY_NEXTSONG,
113 [ 0x22 ] = KEY_PAUSE,
114 [ 0x23 ] = KEY_STOP,
117 /* Alfons Geser <a.geser@cox.net>
118 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
119 static IR_KEYTAB_TYPE eztv_codes[IR_KEYTAB_SIZE] = {
120 [ 18 ] = KEY_POWER,
121 [ 1 ] = KEY_TV, // DVR
122 [ 21 ] = KEY_DVD, // DVD
123 [ 23 ] = KEY_AUDIO, // music
124 // DVR mode / DVD mode / music mode
126 [ 27 ] = KEY_MUTE, // mute
127 [ 2 ] = KEY_LANGUAGE, // MTS/SAP / audio / autoseek
128 [ 30 ] = KEY_SUBTITLE, // closed captioning / subtitle / seek
129 [ 22 ] = KEY_ZOOM, // full screen
130 [ 28 ] = KEY_VIDEO, // video source / eject / delall
131 [ 29 ] = KEY_RESTART, // playback / angle / del
132 [ 47 ] = KEY_SEARCH, // scan / menu / playlist
133 [ 48 ] = KEY_CHANNEL, // CH surfing / bookmark / memo
135 [ 49 ] = KEY_HELP, // help
136 [ 50 ] = KEY_MODE, // num/memo
137 [ 51 ] = KEY_ESC, // cancel
139 [ 12 ] = KEY_UP, // up
140 [ 16 ] = KEY_DOWN, // down
141 [ 8 ] = KEY_LEFT, // left
142 [ 4 ] = KEY_RIGHT, // right
143 [ 3 ] = KEY_SELECT, // select
145 [ 31 ] = KEY_REWIND, // rewind
146 [ 32 ] = KEY_PLAYPAUSE, // play/pause
147 [ 41 ] = KEY_FORWARD, // forward
148 [ 20 ] = KEY_AGAIN, // repeat
149 [ 43 ] = KEY_RECORD, // recording
150 [ 44 ] = KEY_STOP, // stop
151 [ 45 ] = KEY_PLAY, // play
152 [ 46 ] = KEY_SHUFFLE, // snapshot / shuffle
154 [ 0 ] = KEY_KP0,
155 [ 5 ] = KEY_KP1,
156 [ 6 ] = KEY_KP2,
157 [ 7 ] = KEY_KP3,
158 [ 9 ] = KEY_KP4,
159 [ 10 ] = KEY_KP5,
160 [ 11 ] = KEY_KP6,
161 [ 13 ] = KEY_KP7,
162 [ 14 ] = KEY_KP8,
163 [ 15 ] = KEY_KP9,
165 [ 42 ] = KEY_VOLUMEUP,
166 [ 17 ] = KEY_VOLUMEDOWN,
167 [ 24 ] = KEY_CHANNELUP, // CH.tracking up
168 [ 25 ] = KEY_CHANNELDOWN, // CH.tracking down
170 [ 19 ] = KEY_KPENTER, // enter
171 [ 33 ] = KEY_KPDOT, // . (decimal dot)
174 static IR_KEYTAB_TYPE avacssmart_codes[IR_KEYTAB_SIZE] = {
175 [ 30 ] = KEY_POWER, // power
176 [ 28 ] = KEY_SEARCH, // scan
177 [ 7 ] = KEY_SELECT, // source
179 [ 22 ] = KEY_VOLUMEUP,
180 [ 20 ] = KEY_VOLUMEDOWN,
181 [ 31 ] = KEY_CHANNELUP,
182 [ 23 ] = KEY_CHANNELDOWN,
183 [ 24 ] = KEY_MUTE,
185 [ 2 ] = KEY_KP0,
186 [ 1 ] = KEY_KP1,
187 [ 11 ] = KEY_KP2,
188 [ 27 ] = KEY_KP3,
189 [ 5 ] = KEY_KP4,
190 [ 9 ] = KEY_KP5,
191 [ 21 ] = KEY_KP6,
192 [ 6 ] = KEY_KP7,
193 [ 10 ] = KEY_KP8,
194 [ 18 ] = KEY_KP9,
195 [ 16 ] = KEY_KPDOT,
197 [ 3 ] = KEY_TUNER, // tv/fm
198 [ 4 ] = KEY_REWIND, // fm tuning left or function left
199 [ 12 ] = KEY_FORWARD, // fm tuning right or function right
201 [ 0 ] = KEY_RECORD,
202 [ 8 ] = KEY_STOP,
203 [ 17 ] = KEY_PLAY,
205 [ 25 ] = KEY_ZOOM,
206 [ 14 ] = KEY_MENU, // function
207 [ 19 ] = KEY_AGAIN, // recall
208 [ 29 ] = KEY_RESTART, // reset
210 // FIXME
211 [ 13 ] = KEY_F21, // mts
212 [ 15 ] = KEY_F22, // min
213 [ 26 ] = KEY_F23, // freeze
216 /* Alex Hermann <gaaf@gmx.net> */
217 static IR_KEYTAB_TYPE md2819_codes[IR_KEYTAB_SIZE] = {
218 [ 40 ] = KEY_KP1,
219 [ 24 ] = KEY_KP2,
220 [ 56 ] = KEY_KP3,
221 [ 36 ] = KEY_KP4,
222 [ 20 ] = KEY_KP5,
223 [ 52 ] = KEY_KP6,
224 [ 44 ] = KEY_KP7,
225 [ 28 ] = KEY_KP8,
226 [ 60 ] = KEY_KP9,
227 [ 34 ] = KEY_KP0,
229 [ 32 ] = KEY_TV, // TV/FM
230 [ 16 ] = KEY_CD, // CD
231 [ 48 ] = KEY_TEXT, // TELETEXT
232 [ 0 ] = KEY_POWER, // POWER
234 [ 8 ] = KEY_VIDEO, // VIDEO
235 [ 4 ] = KEY_AUDIO, // AUDIO
236 [ 12 ] = KEY_ZOOM, // FULL SCREEN
238 [ 18 ] = KEY_SUBTITLE, // DISPLAY - ???
239 [ 50 ] = KEY_REWIND, // LOOP - ???
240 [ 2 ] = KEY_PRINT, // PREVIEW - ???
242 [ 42 ] = KEY_SEARCH, // AUTOSCAN
243 [ 26 ] = KEY_SLEEP, // FREEZE - ???
244 [ 58 ] = KEY_SHUFFLE, // SNAPSHOT - ???
245 [ 10 ] = KEY_MUTE, // MUTE
247 [ 38 ] = KEY_RECORD, // RECORD
248 [ 22 ] = KEY_PAUSE, // PAUSE
249 [ 54 ] = KEY_STOP, // STOP
250 [ 6 ] = KEY_PLAY, // PLAY
252 [ 46 ] = KEY_RED, // <RED>
253 [ 33 ] = KEY_GREEN, // <GREEN>
254 [ 14 ] = KEY_YELLOW, // <YELLOW>
255 [ 1 ] = KEY_BLUE, // <BLUE>
257 [ 30 ] = KEY_VOLUMEDOWN, // VOLUME-
258 [ 62 ] = KEY_VOLUMEUP, // VOLUME+
259 [ 17 ] = KEY_CHANNELDOWN, // CHANNEL/PAGE-
260 [ 49 ] = KEY_CHANNELUP // CHANNEL/PAGE+
263 static IR_KEYTAB_TYPE videomate_tv_pvr_codes[IR_KEYTAB_SIZE] = {
264 [ 20 ] = KEY_MUTE,
265 [ 36 ] = KEY_ZOOM,
267 [ 1 ] = KEY_DVD,
268 [ 35 ] = KEY_RADIO,
269 [ 0 ] = KEY_TV,
271 [ 10 ] = KEY_REWIND,
272 [ 8 ] = KEY_PLAYPAUSE,
273 [ 15 ] = KEY_FORWARD,
275 [ 2 ] = KEY_PREVIOUS,
276 [ 7 ] = KEY_STOP,
277 [ 6 ] = KEY_NEXT,
279 [ 12 ] = KEY_UP,
280 [ 14 ] = KEY_DOWN,
281 [ 11 ] = KEY_LEFT,
282 [ 13 ] = KEY_RIGHT,
283 [ 17 ] = KEY_OK,
285 [ 3 ] = KEY_MENU,
286 [ 9 ] = KEY_SETUP,
287 [ 5 ] = KEY_VIDEO,
288 [ 34 ] = KEY_CHANNEL,
290 [ 18 ] = KEY_VOLUMEUP,
291 [ 21 ] = KEY_VOLUMEDOWN,
292 [ 16 ] = KEY_CHANNELUP,
293 [ 19 ] = KEY_CHANNELDOWN,
295 [ 4 ] = KEY_RECORD,
297 [ 22 ] = KEY_KP1,
298 [ 23 ] = KEY_KP2,
299 [ 24 ] = KEY_KP3,
300 [ 25 ] = KEY_KP4,
301 [ 26 ] = KEY_KP5,
302 [ 27 ] = KEY_KP6,
303 [ 28 ] = KEY_KP7,
304 [ 29 ] = KEY_KP8,
305 [ 30 ] = KEY_KP9,
306 [ 31 ] = KEY_KP0,
308 [ 32 ] = KEY_LANGUAGE,
309 [ 33 ] = KEY_SLEEP,
311 /* ---------------------------------------------------------------------- */
313 static int build_key(struct saa7134_dev *dev)
315 struct saa7134_ir *ir = dev->remote;
316 u32 gpio, data;
318 /* rising SAA7134_GPIO_GPRESCAN reads the status */
319 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
320 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
322 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
323 if (ir->polling) {
324 if (ir->last_gpio == gpio)
325 return 0;
326 ir->last_gpio = gpio;
329 data = ir_extract_bits(gpio, ir->mask_keycode);
330 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
331 gpio, ir->mask_keycode, data);
333 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
334 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
335 ir_input_keydown(&ir->dev,&ir->ir,data,data);
336 } else {
337 ir_input_nokey(&ir->dev,&ir->ir);
339 return 0;
342 /* ---------------------------------------------------------------------- */
344 void saa7134_input_irq(struct saa7134_dev *dev)
346 struct saa7134_ir *ir = dev->remote;
348 if (!ir->polling)
349 build_key(dev);
352 static void saa7134_input_timer(unsigned long data)
354 struct saa7134_dev *dev = (struct saa7134_dev*)data;
355 struct saa7134_ir *ir = dev->remote;
356 unsigned long timeout;
358 build_key(dev);
359 timeout = jiffies + (ir->polling * HZ / 1000);
360 mod_timer(&ir->timer, timeout);
363 int saa7134_input_init1(struct saa7134_dev *dev)
365 struct saa7134_ir *ir;
366 IR_KEYTAB_TYPE *ir_codes = NULL;
367 u32 mask_keycode = 0;
368 u32 mask_keydown = 0;
369 u32 mask_keyup = 0;
370 int polling = 0;
371 int ir_type = IR_TYPE_OTHER;
373 if (!dev->has_remote)
374 return -ENODEV;
375 if (disable_ir)
376 return -ENODEV;
378 /* detect & configure */
379 switch (dev->board) {
380 case SAA7134_BOARD_FLYVIDEO2000:
381 case SAA7134_BOARD_FLYVIDEO3000:
382 case SAA7134_BOARD_FLYTVPLATINUM_FM:
383 ir_codes = flyvideo_codes;
384 mask_keycode = 0xEC00000;
385 mask_keydown = 0x0040000;
386 break;
387 case SAA7134_BOARD_CINERGY400:
388 case SAA7134_BOARD_CINERGY600:
389 case SAA7134_BOARD_CINERGY600_MK3:
390 ir_codes = cinergy_codes;
391 mask_keycode = 0x00003f;
392 mask_keyup = 0x040000;
393 break;
394 case SAA7134_BOARD_ECS_TVP3XP:
395 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
396 ir_codes = eztv_codes;
397 mask_keycode = 0x00017c;
398 mask_keyup = 0x000002;
399 polling = 50; // ms
400 break;
401 case SAA7134_BOARD_AVACSSMARTTV:
402 ir_codes = avacssmart_codes;
403 mask_keycode = 0x00001F;
404 mask_keyup = 0x000020;
405 polling = 50; // ms
406 break;
407 case SAA7134_BOARD_MD2819:
408 case SAA7134_BOARD_AVERMEDIA_305:
409 case SAA7134_BOARD_AVERMEDIA_307:
410 ir_codes = md2819_codes;
411 mask_keycode = 0x0007C8;
412 mask_keydown = 0x000010;
413 polling = 50; // ms
414 /* Set GPIO pin2 to high to enable the IR controller */
415 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
416 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
417 break;
418 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
419 ir_codes = videomate_tv_pvr_codes;
420 mask_keycode = 0x00003F;
421 mask_keyup = 0x400000;
422 polling = 50; // ms
423 break;
425 if (NULL == ir_codes) {
426 printk("%s: Oops: IR config error [card=%d]\n",
427 dev->name, dev->board);
428 return -ENODEV;
431 ir = kmalloc(sizeof(*ir),GFP_KERNEL);
432 if (NULL == ir)
433 return -ENOMEM;
434 memset(ir,0,sizeof(*ir));
436 /* init hardware-specific stuff */
437 ir->mask_keycode = mask_keycode;
438 ir->mask_keydown = mask_keydown;
439 ir->mask_keyup = mask_keyup;
440 ir->polling = polling;
442 /* init input device */
443 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
444 saa7134_boards[dev->board].name);
445 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
446 pci_name(dev->pci));
448 ir_input_init(&ir->dev, &ir->ir, ir_type, ir_codes);
449 ir->dev.name = ir->name;
450 ir->dev.phys = ir->phys;
451 ir->dev.id.bustype = BUS_PCI;
452 ir->dev.id.version = 1;
453 if (dev->pci->subsystem_vendor) {
454 ir->dev.id.vendor = dev->pci->subsystem_vendor;
455 ir->dev.id.product = dev->pci->subsystem_device;
456 } else {
457 ir->dev.id.vendor = dev->pci->vendor;
458 ir->dev.id.product = dev->pci->device;
461 /* all done */
462 dev->remote = ir;
463 if (ir->polling) {
464 init_timer(&ir->timer);
465 ir->timer.function = saa7134_input_timer;
466 ir->timer.data = (unsigned long)dev;
467 ir->timer.expires = jiffies + HZ;
468 add_timer(&ir->timer);
471 input_register_device(&dev->remote->dev);
472 printk("%s: registered input device for IR\n",dev->name);
473 return 0;
476 void saa7134_input_fini(struct saa7134_dev *dev)
478 if (NULL == dev->remote)
479 return;
481 input_unregister_device(&dev->remote->dev);
482 if (dev->remote->polling)
483 del_timer_sync(&dev->remote->timer);
484 kfree(dev->remote);
485 dev->remote = NULL;
488 /* ----------------------------------------------------------------------
489 * Local variables:
490 * c-basic-offset: 8
491 * End: