2 * $Id: cx88-input.c,v 1.13 2005/06/13 16:07:46 nsh Exp $
4 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards.
7 * Copyright (c) 2003 Pavel Machek
8 * Copyright (c) 2004 Gerd Knorr
9 * Copyright (c) 2004 Chris Pascoe
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/input.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
33 #include <media/ir-common.h>
37 /* ---------------------------------------------------------------------- */
39 /* DigitalNow DNTV Live DVB-T Remote */
40 static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t
[IR_KEYTAB_SIZE
] = {
41 [ 0x00 ] = KEY_ESC
, // 'go up a level?'
42 [ 0x01 ] = KEY_KP1
, // '1'
43 [ 0x02 ] = KEY_KP2
, // '2'
44 [ 0x03 ] = KEY_KP3
, // '3'
45 [ 0x04 ] = KEY_KP4
, // '4'
46 [ 0x05 ] = KEY_KP5
, // '5'
47 [ 0x06 ] = KEY_KP6
, // '6'
48 [ 0x07 ] = KEY_KP7
, // '7'
49 [ 0x08 ] = KEY_KP8
, // '8'
50 [ 0x09 ] = KEY_KP9
, // '9'
51 [ 0x0a ] = KEY_KP0
, // '0'
52 [ 0x0b ] = KEY_TUNER
, // 'tv/fm'
53 [ 0x0c ] = KEY_SEARCH
, // 'scan'
54 [ 0x0d ] = KEY_STOP
, // 'stop'
55 [ 0x0e ] = KEY_PAUSE
, // 'pause'
56 [ 0x0f ] = KEY_LIST
, // 'source'
58 [ 0x10 ] = KEY_MUTE
, // 'mute'
59 [ 0x11 ] = KEY_REWIND
, // 'backward <<'
60 [ 0x12 ] = KEY_POWER
, // 'power'
61 [ 0x13 ] = KEY_S
, // 'snap'
62 [ 0x14 ] = KEY_AUDIO
, // 'stereo'
63 [ 0x15 ] = KEY_CLEAR
, // 'reset'
64 [ 0x16 ] = KEY_PLAY
, // 'play'
65 [ 0x17 ] = KEY_ENTER
, // 'enter'
66 [ 0x18 ] = KEY_ZOOM
, // 'full screen'
67 [ 0x19 ] = KEY_FASTFORWARD
, // 'forward >>'
68 [ 0x1a ] = KEY_CHANNELUP
, // 'channel +'
69 [ 0x1b ] = KEY_VOLUMEUP
, // 'volume +'
70 [ 0x1c ] = KEY_INFO
, // 'preview'
71 [ 0x1d ] = KEY_RECORD
, // 'record'
72 [ 0x1e ] = KEY_CHANNELDOWN
, // 'channel -'
73 [ 0x1f ] = KEY_VOLUMEDOWN
, // 'volume -'
76 /* ---------------------------------------------------------------------- */
78 /* IO-DATA BCTV7E Remote */
79 static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e
[IR_KEYTAB_SIZE
] = {
80 [ 0x40 ] = KEY_TV
, // TV
81 [ 0x20 ] = KEY_RADIO
, // FM
82 [ 0x60 ] = KEY_EPG
, // EPG
83 [ 0x00 ] = KEY_POWER
, // power
85 [ 0x50 ] = KEY_KP1
, // 1
86 [ 0x30 ] = KEY_KP2
, // 2
87 [ 0x70 ] = KEY_KP3
, // 3
88 [ 0x10 ] = KEY_L
, // Live
90 [ 0x48 ] = KEY_KP4
, // 4
91 [ 0x28 ] = KEY_KP5
, // 5
92 [ 0x68 ] = KEY_KP6
, // 6
93 [ 0x08 ] = KEY_T
, // Time Shift
95 [ 0x58 ] = KEY_KP7
, // 7
96 [ 0x38 ] = KEY_KP8
, // 8
97 [ 0x78 ] = KEY_KP9
, // 9
98 [ 0x18 ] = KEY_PLAYPAUSE
, // Play
100 [ 0x44 ] = KEY_KP0
, // 10
101 [ 0x24 ] = KEY_ENTER
, // 11
102 [ 0x64 ] = KEY_ESC
, // 12
103 [ 0x04 ] = KEY_M
, // Multi
105 [ 0x54 ] = KEY_VIDEO
, // VIDEO
106 [ 0x34 ] = KEY_CHANNELUP
, // channel +
107 [ 0x74 ] = KEY_VOLUMEUP
, // volume +
108 [ 0x14 ] = KEY_MUTE
, // Mute
110 [ 0x4c ] = KEY_S
, // SVIDEO
111 [ 0x2c ] = KEY_CHANNELDOWN
, // channel -
112 [ 0x6c ] = KEY_VOLUMEDOWN
, // volume -
113 [ 0x0c ] = KEY_ZOOM
, // Zoom
115 [ 0x5c ] = KEY_PAUSE
, // pause
116 [ 0x3c ] = KEY_C
, // || (red)
117 [ 0x7c ] = KEY_RECORD
, // recording
118 [ 0x1c ] = KEY_STOP
, // stop
120 [ 0x41 ] = KEY_REWIND
, // backward <<
121 [ 0x21 ] = KEY_PLAY
, // play
122 [ 0x61 ] = KEY_FASTFORWARD
, // forward >>
123 [ 0x01 ] = KEY_NEXT
, // skip >|
126 /* ---------------------------------------------------------------------- */
128 /* ADS Tech Instant TV DVB-T PCI Remote */
129 static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci
[IR_KEYTAB_SIZE
] = {
130 [ 0x5b ] = KEY_POWER
,
143 [ 0x5d ] = KEY_SEARCH
,
144 [ 0x17 ] = KEY_EPG
, // Guide
149 [ 0x1e ] = KEY_RIGHT
,
150 [ 0x0e ] = KEY_SELECT
, // Enter
153 [ 0x59 ] = KEY_PREVIOUS
,
155 [ 0x58 ] = KEY_REWIND
,
156 [ 0x50 ] = KEY_FORWARD
,
157 [ 0x44 ] = KEY_PLAYPAUSE
,
159 [ 0x1b ] = KEY_RECORD
,
160 [ 0x13 ] = KEY_TUNER
, // Live
163 [ 0x03 ] = KEY_PROG1
, // 1
164 [ 0x01 ] = KEY_PROG2
, // 2
165 [ 0x00 ] = KEY_PROG3
, // 3
167 [ 0x48 ] = KEY_AUX
, // Photo
168 [ 0x40 ] = KEY_VIDEO
,
169 [ 0x19 ] = KEY_AUDIO
, // Music
170 [ 0x0b ] = KEY_CHANNELUP
,
171 [ 0x08 ] = KEY_CHANNELDOWN
,
172 [ 0x15 ] = KEY_VOLUMEUP
,
173 [ 0x1c ] = KEY_VOLUMEDOWN
,
176 /* ---------------------------------------------------------------------- */
178 /* MSI TV@nywhere remote */
179 static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere
[IR_KEYTAB_SIZE
] = {
180 [ 0x00 ] = KEY_0
, /* '0' */
181 [ 0x01 ] = KEY_1
, /* '1' */
182 [ 0x02 ] = KEY_2
, /* '2' */
183 [ 0x03 ] = KEY_3
, /* '3' */
184 [ 0x04 ] = KEY_4
, /* '4' */
185 [ 0x05 ] = KEY_5
, /* '5' */
186 [ 0x06 ] = KEY_6
, /* '6' */
187 [ 0x07 ] = KEY_7
, /* '7' */
188 [ 0x08 ] = KEY_8
, /* '8' */
189 [ 0x09 ] = KEY_9
, /* '9' */
190 [ 0x0c ] = KEY_MUTE
, /* 'Mute' */
191 [ 0x0f ] = KEY_SCREEN
, /* 'Full Screen' */
192 [ 0x10 ] = KEY_F
, /* 'Funtion' */
193 [ 0x11 ] = KEY_T
, /* 'Time shift' */
194 [ 0x12 ] = KEY_POWER
, /* 'Power' */
195 [ 0x13 ] = KEY_MEDIA
, /* 'MTS' */
196 [ 0x14 ] = KEY_SLOW
, /* 'Slow' */
197 [ 0x16 ] = KEY_REWIND
, /* 'backward <<' */
198 [ 0x17 ] = KEY_ENTER
, /* 'Return' */
199 [ 0x18 ] = KEY_FASTFORWARD
, /* 'forward >>' */
200 [ 0x1a ] = KEY_CHANNELUP
, /* 'Channel+' */
201 [ 0x1b ] = KEY_VOLUMEUP
, /* 'Volume+' */
202 [ 0x1e ] = KEY_CHANNELDOWN
, /* 'Channel-' */
203 [ 0x1f ] = KEY_VOLUMEDOWN
, /* 'Volume-' */
206 /* ---------------------------------------------------------------------- */
209 struct cx88_core
*core
;
210 struct input_dev input
;
211 struct ir_input_state ir
;
215 /* sample from gpio pin 16 */
219 unsigned long release
;
221 /* poll external decoder */
223 struct work_struct work
;
224 struct timer_list timer
;
232 static int ir_debug
= 0;
233 module_param(ir_debug
, int, 0644); /* debug level [IR] */
234 MODULE_PARM_DESC(ir_debug
, "enable debug messages [IR]");
236 #define ir_dprintk(fmt, arg...) if (ir_debug) \
237 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name, ## arg)
239 /* ---------------------------------------------------------------------- */
241 static void cx88_ir_handle_key(struct cx88_IR
*ir
)
243 struct cx88_core
*core
= ir
->core
;
246 /* read gpio value */
247 gpio
= cx_read(ir
->gpio_addr
);
249 if (ir
->last_gpio
== gpio
)
251 ir
->last_gpio
= gpio
;
255 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
256 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
258 ir
->polling
? "poll" : "irq",
259 (gpio
& ir
->mask_keydown
) ? " down" : "",
260 (gpio
& ir
->mask_keyup
) ? " up" : "");
262 if (ir
->mask_keydown
) {
263 /* bit set on keydown */
264 if (gpio
& ir
->mask_keydown
) {
265 ir_input_keydown(&ir
->input
,&ir
->ir
,data
,data
);
267 ir_input_nokey(&ir
->input
,&ir
->ir
);
270 } else if (ir
->mask_keyup
) {
271 /* bit cleared on keydown */
272 if (0 == (gpio
& ir
->mask_keyup
)) {
273 ir_input_keydown(&ir
->input
,&ir
->ir
,data
,data
);
275 ir_input_nokey(&ir
->input
,&ir
->ir
);
279 /* can't distinguish keydown/up :-/ */
280 ir_input_keydown(&ir
->input
,&ir
->ir
,data
,data
);
281 ir_input_nokey(&ir
->input
,&ir
->ir
);
285 static void ir_timer(unsigned long data
)
287 struct cx88_IR
*ir
= (struct cx88_IR
*)data
;
289 schedule_work(&ir
->work
);
292 static void cx88_ir_work(void *data
)
294 struct cx88_IR
*ir
= data
;
295 unsigned long timeout
;
297 cx88_ir_handle_key(ir
);
298 timeout
= jiffies
+ (ir
->polling
* HZ
/ 1000);
299 mod_timer(&ir
->timer
, timeout
);
302 /* ---------------------------------------------------------------------- */
304 int cx88_ir_init(struct cx88_core
*core
, struct pci_dev
*pci
)
307 IR_KEYTAB_TYPE
*ir_codes
= NULL
;
308 int ir_type
= IR_TYPE_OTHER
;
310 ir
= kmalloc(sizeof(*ir
),GFP_KERNEL
);
313 memset(ir
,0,sizeof(*ir
));
315 /* detect & configure */
316 switch (core
->board
) {
317 case CX88_BOARD_DNTV_LIVE_DVB_T
:
318 case CX88_BOARD_KWORLD_DVB_T
:
319 ir_codes
= ir_codes_dntv_live_dvb_t
;
320 ir
->gpio_addr
= MO_GP1_IO
;
321 ir
->mask_keycode
= 0x1f;
322 ir
->mask_keyup
= 0x60;
323 ir
->polling
= 50; // ms
325 case CX88_BOARD_HAUPPAUGE
:
326 case CX88_BOARD_HAUPPAUGE_DVB_T1
:
327 ir_codes
= ir_codes_hauppauge_new
;
328 ir_type
= IR_TYPE_RC5
;
331 case CX88_BOARD_WINFAST2000XP_EXPERT
:
332 ir_codes
= ir_codes_winfast
;
333 ir
->gpio_addr
= MO_GP0_IO
;
334 ir
->mask_keycode
= 0x8f8;
335 ir
->mask_keyup
= 0x100;
336 ir
->polling
= 1; // ms
338 case CX88_BOARD_IODATA_GVBCTV7E
:
339 ir_codes
= ir_codes_iodata_bctv7e
;
340 ir
->gpio_addr
= MO_GP0_IO
;
341 ir
->mask_keycode
= 0xfd;
342 ir
->mask_keydown
= 0x02;
343 ir
->polling
= 5; // ms
345 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO
:
346 ir_codes
= ir_codes_pixelview
;
347 ir
->gpio_addr
= MO_GP1_IO
;
348 ir
->mask_keycode
= 0x1f;
349 ir
->mask_keyup
= 0x80;
350 ir
->polling
= 1; // ms
352 case CX88_BOARD_ADSTECH_DVB_T_PCI
:
353 ir_codes
= ir_codes_adstech_dvb_t_pci
;
354 ir
->gpio_addr
= MO_GP1_IO
;
355 ir
->mask_keycode
= 0xbf;
356 ir
->mask_keyup
= 0x40;
357 ir
->polling
= 50; // ms
359 case CX88_BOARD_MSI_TVANYWHERE_MASTER
:
360 ir_codes
= ir_codes_msi_tvanywhere
;
361 ir
->gpio_addr
= MO_GP1_IO
;
362 ir
->mask_keycode
= 0x1f;
363 ir
->mask_keyup
= 0x40;
368 if (NULL
== ir_codes
) {
373 /* init input device */
374 snprintf(ir
->name
, sizeof(ir
->name
), "cx88 IR (%s)",
375 cx88_boards
[core
->board
].name
);
376 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
379 ir_input_init(&ir
->input
, &ir
->ir
, ir_type
, ir_codes
);
380 ir
->input
.name
= ir
->name
;
381 ir
->input
.phys
= ir
->phys
;
382 ir
->input
.id
.bustype
= BUS_PCI
;
383 ir
->input
.id
.version
= 1;
384 if (pci
->subsystem_vendor
) {
385 ir
->input
.id
.vendor
= pci
->subsystem_vendor
;
386 ir
->input
.id
.product
= pci
->subsystem_device
;
388 ir
->input
.id
.vendor
= pci
->vendor
;
389 ir
->input
.id
.product
= pci
->device
;
392 /* record handles to ourself */
397 INIT_WORK(&ir
->work
, cx88_ir_work
, ir
);
398 init_timer(&ir
->timer
);
399 ir
->timer
.function
= ir_timer
;
400 ir
->timer
.data
= (unsigned long)ir
;
401 schedule_work(&ir
->work
);
404 core
->pci_irqmask
|= (1<<18); // IR_SMP_INT
405 cx_write(MO_DDS_IO
, 0xa80a80); // 4 kHz sample rate
406 cx_write(MO_DDSCFG_IO
, 0x5); // enable
410 input_register_device(&ir
->input
);
411 printk("%s: registered IR remote control\n", core
->name
);
416 int cx88_ir_fini(struct cx88_core
*core
)
418 struct cx88_IR
*ir
= core
->ir
;
420 /* skip detach on non attached boards */
425 del_timer(&ir
->timer
);
426 flush_scheduled_work();
429 input_unregister_device(&ir
->input
);
437 /* ---------------------------------------------------------------------- */
439 void cx88_ir_irq(struct cx88_core
*core
)
441 struct cx88_IR
*ir
= core
->ir
;
450 samples
= cx_read(MO_SAMPLE_IO
);
451 if (0 != samples
&& 0xffffffff != samples
) {
452 /* record sample data */
453 if (ir
->scount
< ARRAY_SIZE(ir
->samples
))
454 ir
->samples
[ir
->scount
++] = samples
;
458 /* nothing to sample */
459 if (ir
->ir
.keypressed
&& time_after(jiffies
,ir
->release
))
460 ir_input_nokey(&ir
->input
,&ir
->ir
);
464 /* have a complete sample */
465 if (ir
->scount
< ARRAY_SIZE(ir
->samples
))
466 ir
->samples
[ir
->scount
++] = samples
;
467 for (i
= 0; i
< ir
->scount
; i
++)
468 ir
->samples
[i
] = ~ir
->samples
[i
];
470 ir_dump_samples(ir
->samples
,ir
->scount
);
473 switch (core
->board
) {
474 case CX88_BOARD_HAUPPAUGE
:
475 case CX88_BOARD_HAUPPAUGE_DVB_T1
:
476 rc5
= ir_decode_biphase(ir
->samples
,ir
->scount
,5,7);
477 ir_dprintk("biphase decoded: %x\n",rc5
);
478 if ((rc5
& 0xfffff000) != 0x3000)
480 ir_input_keydown(&ir
->input
, &ir
->ir
, rc5
& 0x3f, rc5
);
481 ir
->release
= jiffies
+ msecs_to_jiffies(120);
489 /* ---------------------------------------------------------------------- */
491 MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
492 MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
493 MODULE_LICENSE("GPL");