3 * Copyright (c) 2003 Gerd Knorr
4 * Copyright (c) 2003 Pavel Machek
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
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>
29 #include <media/ir-common.h>
33 /* ---------------------------------------------------------------------- */
35 static IR_KEYTAB_TYPE ir_codes_avermedia
[IR_KEYTAB_SIZE
] = {
47 [ 48 ] = KEY_EJECTCD
, // Unmarked on my controller
49 [ 18 ] = BTN_LEFT
, // DISPLAY/L
50 [ 50 ] = BTN_RIGHT
, // LOOP/R
55 [ 30 ] = KEY_VOLUMEDOWN
,
56 [ 62 ] = KEY_VOLUMEUP
,
58 [ 32 ] = KEY_TUNER
, // TV/FM
62 [ 12 ] = KEY_ZOOM
, // full screen
63 [ 2 ] = KEY_INFO
, // preview
64 [ 42 ] = KEY_SEARCH
, // autoscan
65 [ 26 ] = KEY_STOP
, // freeze
66 [ 58 ] = KEY_RECORD
, // capture
67 [ 6 ] = KEY_PLAY
, // unmarked
68 [ 46 ] = KEY_RED
, // unmarked
69 [ 14 ] = KEY_GREEN
, // unmarked
71 [ 33 ] = KEY_YELLOW
, // unmarked
72 [ 17 ] = KEY_CHANNELDOWN
,
73 [ 49 ] = KEY_CHANNELUP
,
74 [ 1 ] = KEY_BLUE
, // unmarked
77 /* Matt Jesson <dvb@jesson.eclipse.co.uk */
78 static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt
[IR_KEYTAB_SIZE
] = {
79 [ 0x28 ] = KEY_KP0
, //'0' / 'enter'
80 [ 0x22 ] = KEY_KP1
, //'1'
81 [ 0x12 ] = KEY_KP2
, //'2' / 'up arrow'
82 [ 0x32 ] = KEY_KP3
, //'3'
83 [ 0x24 ] = KEY_KP4
, //'4' / 'left arrow'
84 [ 0x14 ] = KEY_KP5
, //'5'
85 [ 0x34 ] = KEY_KP6
, //'6' / 'right arrow'
86 [ 0x26 ] = KEY_KP7
, //'7'
87 [ 0x16 ] = KEY_KP8
, //'8' / 'down arrow'
88 [ 0x36 ] = KEY_KP9
, //'9'
90 [ 0x20 ] = KEY_LIST
, // 'source'
91 [ 0x10 ] = KEY_TEXT
, // 'teletext'
92 [ 0x00 ] = KEY_POWER
, // 'power'
93 [ 0x04 ] = KEY_AUDIO
, // 'audio'
94 [ 0x06 ] = KEY_ZOOM
, // 'full screen'
95 [ 0x18 ] = KEY_VIDEO
, // 'display'
96 [ 0x38 ] = KEY_SEARCH
, // 'loop'
97 [ 0x08 ] = KEY_INFO
, // 'preview'
98 [ 0x2a ] = KEY_REWIND
, // 'backward <<'
99 [ 0x1a ] = KEY_FASTFORWARD
, // 'forward >>'
100 [ 0x3a ] = KEY_RECORD
, // 'capture'
101 [ 0x0a ] = KEY_MUTE
, // 'mute'
102 [ 0x2c ] = KEY_RECORD
, // 'record'
103 [ 0x1c ] = KEY_PAUSE
, // 'pause'
104 [ 0x3c ] = KEY_STOP
, // 'stop'
105 [ 0x0c ] = KEY_PLAY
, // 'play'
106 [ 0x2e ] = KEY_RED
, // 'red'
107 [ 0x01 ] = KEY_BLUE
, // 'blue' / 'cancel'
108 [ 0x0e ] = KEY_YELLOW
, // 'yellow' / 'ok'
109 [ 0x21 ] = KEY_GREEN
, // 'green'
110 [ 0x11 ] = KEY_CHANNELDOWN
, // 'channel -'
111 [ 0x31 ] = KEY_CHANNELUP
, // 'channel +'
112 [ 0x1e ] = KEY_VOLUMEDOWN
, // 'volume -'
113 [ 0x3e ] = KEY_VOLUMEUP
, // 'volume +'
116 /* Attila Kondoros <attila.kondoros@chello.hu> */
117 static IR_KEYTAB_TYPE ir_codes_apac_viewcomp
[IR_KEYTAB_SIZE
] = {
129 [ 23 ] = KEY_LAST
, // +100
130 [ 10 ] = KEY_LIST
, // recall
133 [ 28 ] = KEY_TUNER
, // TV/FM
134 [ 21 ] = KEY_SEARCH
, // scan
135 [ 18 ] = KEY_POWER
, // power
136 [ 31 ] = KEY_VOLUMEDOWN
, // vol up
137 [ 27 ] = KEY_VOLUMEUP
, // vol down
138 [ 30 ] = KEY_CHANNELDOWN
, // chn up
139 [ 26 ] = KEY_CHANNELUP
, // chn down
141 [ 17 ] = KEY_VIDEO
, // video
142 [ 15 ] = KEY_ZOOM
, // full screen
143 [ 19 ] = KEY_MUTE
, // mute/unmute
144 [ 16 ] = KEY_TEXT
, // min
146 [ 13 ] = KEY_STOP
, // freeze
147 [ 14 ] = KEY_RECORD
, // record
148 [ 29 ] = KEY_PLAYPAUSE
, // stop
149 [ 25 ] = KEY_PLAY
, // play
151 [ 22 ] = KEY_GOTO
, // osd
152 [ 20 ] = KEY_REFRESH
, // default
153 [ 12 ] = KEY_KPPLUS
, // fine tune >>>>
154 [ 24 ] = KEY_KPMINUS
// fine tune <<<<
157 /* ---------------------------------------------------------------------- */
160 struct bttv_sub_device
*sub
;
161 struct input_dev
*input
;
162 struct ir_input_state ir
;
171 struct work_struct work
;
172 struct timer_list timer
;
176 module_param(debug
, int, 0644); /* debug level (0,1,2) */
178 #define DEVNAME "ir-kbd-gpio"
179 #define dprintk(fmt, arg...) if (debug) \
180 printk(KERN_DEBUG DEVNAME ": " fmt , ## arg)
182 static void ir_irq(struct bttv_sub_device
*sub
);
183 static int ir_probe(struct device
*dev
);
184 static int ir_remove(struct device
*dev
);
186 static struct bttv_sub_driver driver
= {
195 /* ---------------------------------------------------------------------- */
197 static void ir_handle_key(struct IR
*ir
)
201 /* read gpio value */
202 gpio
= bttv_gpio_read(ir
->sub
->core
);
204 if (ir
->last_gpio
== gpio
)
206 ir
->last_gpio
= gpio
;
210 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
211 dprintk(DEVNAME
": irq gpio=0x%x code=%d | %s%s%s\n",
213 ir
->polling
? "poll" : "irq",
214 (gpio
& ir
->mask_keydown
) ? " down" : "",
215 (gpio
& ir
->mask_keyup
) ? " up" : "");
217 if (ir
->mask_keydown
) {
218 /* bit set on keydown */
219 if (gpio
& ir
->mask_keydown
) {
220 ir_input_keydown(ir
->input
, &ir
->ir
, data
, data
);
222 ir_input_nokey(ir
->input
, &ir
->ir
);
225 } else if (ir
->mask_keyup
) {
226 /* bit cleared on keydown */
227 if (0 == (gpio
& ir
->mask_keyup
)) {
228 ir_input_keydown(ir
->input
, &ir
->ir
, data
, data
);
230 ir_input_nokey(ir
->input
, &ir
->ir
);
234 /* can't disturgissh keydown/up :-/ */
235 ir_input_keydown(ir
->input
, &ir
->ir
, data
, data
);
236 ir_input_nokey(ir
->input
, &ir
->ir
);
240 static void ir_irq(struct bttv_sub_device
*sub
)
242 struct IR
*ir
= dev_get_drvdata(&sub
->dev
);
248 static void ir_timer(unsigned long data
)
250 struct IR
*ir
= (struct IR
*)data
;
252 schedule_work(&ir
->work
);
255 static void ir_work(void *data
)
257 struct IR
*ir
= data
;
258 unsigned long timeout
;
261 timeout
= jiffies
+ (ir
->polling
* HZ
/ 1000);
262 mod_timer(&ir
->timer
, timeout
);
265 /* ---------------------------------------------------------------------- */
267 static int ir_probe(struct device
*dev
)
269 struct bttv_sub_device
*sub
= to_bttv_sub_dev(dev
);
271 struct input_dev
*input_dev
;
272 IR_KEYTAB_TYPE
*ir_codes
= NULL
;
273 int ir_type
= IR_TYPE_OTHER
;
275 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
276 input_dev
= input_allocate_device();
277 if (!ir
|| !input_dev
) {
279 input_free_device(input_dev
);
283 /* detect & configure */
284 switch (sub
->core
->type
) {
287 case BTTV_AVERMEDIA98
:
288 ir_codes
= ir_codes_avermedia
;
289 ir
->mask_keycode
= 0xf88000;
290 ir
->mask_keydown
= 0x010000;
291 ir
->polling
= 50; // ms
294 case BTTV_AVDVBT_761
:
295 case BTTV_AVDVBT_771
:
296 ir_codes
= ir_codes_avermedia_dvbt
;
297 ir
->mask_keycode
= 0x0f00c0;
298 ir
->mask_keydown
= 0x000020;
299 ir
->polling
= 50; // ms
302 case BTTV_PXELVWPLTVPAK
:
303 ir_codes
= ir_codes_pixelview
;
304 ir
->mask_keycode
= 0x003e00;
305 ir
->mask_keyup
= 0x010000;
306 ir
->polling
= 50; // ms
308 case BTTV_PV_BT878P_9B
:
309 case BTTV_PV_BT878P_PLUS
:
310 ir_codes
= ir_codes_pixelview
;
311 ir
->mask_keycode
= 0x001f00;
312 ir
->mask_keyup
= 0x008000;
313 ir
->polling
= 50; // ms
316 case BTTV_WINFAST2000
:
317 ir_codes
= ir_codes_winfast
;
318 ir
->mask_keycode
= 0x1f8;
320 case BTTV_MAGICTVIEW061
:
321 case BTTV_MAGICTVIEW063
:
322 ir_codes
= ir_codes_winfast
;
323 ir
->mask_keycode
= 0x0008e000;
324 ir
->mask_keydown
= 0x00200000;
326 case BTTV_APAC_VIEWCOMP
:
327 ir_codes
= ir_codes_apac_viewcomp
;
328 ir
->mask_keycode
= 0x001f00;
329 ir
->mask_keyup
= 0x008000;
330 ir
->polling
= 50; // ms
333 if (NULL
== ir_codes
) {
335 input_free_device(input_dev
);
339 /* init hardware-specific stuff */
340 bttv_gpio_inout(sub
->core
, ir
->mask_keycode
| ir
->mask_keydown
, 0);
343 /* init input device */
344 snprintf(ir
->name
, sizeof(ir
->name
), "bttv IR (card=%d)",
346 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
347 pci_name(sub
->core
->pci
));
349 ir_input_init(input_dev
, &ir
->ir
, ir_type
, ir_codes
);
350 input_dev
->name
= ir
->name
;
351 input_dev
->phys
= ir
->phys
;
352 input_dev
->id
.bustype
= BUS_PCI
;
353 input_dev
->id
.version
= 1;
354 if (sub
->core
->pci
->subsystem_vendor
) {
355 input_dev
->id
.vendor
= sub
->core
->pci
->subsystem_vendor
;
356 input_dev
->id
.product
= sub
->core
->pci
->subsystem_device
;
358 input_dev
->id
.vendor
= sub
->core
->pci
->vendor
;
359 input_dev
->id
.product
= sub
->core
->pci
->device
;
361 input_dev
->cdev
.dev
= &sub
->core
->pci
->dev
;
364 INIT_WORK(&ir
->work
, ir_work
, ir
);
365 init_timer(&ir
->timer
);
366 ir
->timer
.function
= ir_timer
;
367 ir
->timer
.data
= (unsigned long)ir
;
368 schedule_work(&ir
->work
);
372 dev_set_drvdata(dev
, ir
);
373 input_register_device(ir
->input
);
378 static int ir_remove(struct device
*dev
)
380 struct IR
*ir
= dev_get_drvdata(dev
);
383 del_timer(&ir
->timer
);
384 flush_scheduled_work();
387 input_unregister_device(ir
->input
);
392 /* ---------------------------------------------------------------------- */
394 MODULE_AUTHOR("Gerd Knorr, Pavel Machek");
395 MODULE_DESCRIPTION("input driver for bt8x8 gpio IR remote controls");
396 MODULE_LICENSE("GPL");
398 static int ir_init(void)
400 return bttv_sub_register(&driver
, "remote");
403 static void ir_fini(void)
405 bttv_sub_unregister(&driver
);
408 module_init(ir_init
);
409 module_exit(ir_fini
);