[PATCH] v4l: CX88 cards update
[deliverable/linux.git] / drivers / media / video / ir-kbd-gpio.c
1 /*
2 * $Id: ir-kbd-gpio.c,v 1.13 2005/05/15 19:01:26 mchehab Exp $
3 *
4 * Copyright (c) 2003 Gerd Knorr
5 * Copyright (c) 2003 Pavel Machek
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/input.h>
28 #include <linux/pci.h>
29
30 #include <media/ir-common.h>
31
32 #include "bttv.h"
33
34 /* ---------------------------------------------------------------------- */
35
36 static IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = {
37 [ 34 ] = KEY_KP0,
38 [ 40 ] = KEY_KP1,
39 [ 24 ] = KEY_KP2,
40 [ 56 ] = KEY_KP3,
41 [ 36 ] = KEY_KP4,
42 [ 20 ] = KEY_KP5,
43 [ 52 ] = KEY_KP6,
44 [ 44 ] = KEY_KP7,
45 [ 28 ] = KEY_KP8,
46 [ 60 ] = KEY_KP9,
47
48 [ 48 ] = KEY_EJECTCD, // Unmarked on my controller
49 [ 0 ] = KEY_POWER,
50 [ 18 ] = BTN_LEFT, // DISPLAY/L
51 [ 50 ] = BTN_RIGHT, // LOOP/R
52 [ 10 ] = KEY_MUTE,
53 [ 38 ] = KEY_RECORD,
54 [ 22 ] = KEY_PAUSE,
55 [ 54 ] = KEY_STOP,
56 [ 30 ] = KEY_VOLUMEDOWN,
57 [ 62 ] = KEY_VOLUMEUP,
58
59 [ 32 ] = KEY_TUNER, // TV/FM
60 [ 16 ] = KEY_CD,
61 [ 8 ] = KEY_VIDEO,
62 [ 4 ] = KEY_AUDIO,
63 [ 12 ] = KEY_ZOOM, // full screen
64 [ 2 ] = KEY_INFO, // preview
65 [ 42 ] = KEY_SEARCH, // autoscan
66 [ 26 ] = KEY_STOP, // freeze
67 [ 58 ] = KEY_RECORD, // capture
68 [ 6 ] = KEY_PLAY, // unmarked
69 [ 46 ] = KEY_RED, // unmarked
70 [ 14 ] = KEY_GREEN, // unmarked
71
72 [ 33 ] = KEY_YELLOW, // unmarked
73 [ 17 ] = KEY_CHANNELDOWN,
74 [ 49 ] = KEY_CHANNELUP,
75 [ 1 ] = KEY_BLUE, // unmarked
76 };
77
78 /* Matt Jesson <dvb@jesson.eclipse.co.uk */
79 static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
80 [ 0x28 ] = KEY_KP0, //'0' / 'enter'
81 [ 0x22 ] = KEY_KP1, //'1'
82 [ 0x12 ] = KEY_KP2, //'2' / 'up arrow'
83 [ 0x32 ] = KEY_KP3, //'3'
84 [ 0x24 ] = KEY_KP4, //'4' / 'left arrow'
85 [ 0x14 ] = KEY_KP5, //'5'
86 [ 0x34 ] = KEY_KP6, //'6' / 'right arrow'
87 [ 0x26 ] = KEY_KP7, //'7'
88 [ 0x16 ] = KEY_KP8, //'8' / 'down arrow'
89 [ 0x36 ] = KEY_KP9, //'9'
90
91 [ 0x20 ] = KEY_LIST, // 'source'
92 [ 0x10 ] = KEY_TEXT, // 'teletext'
93 [ 0x00 ] = KEY_POWER, // 'power'
94 [ 0x04 ] = KEY_AUDIO, // 'audio'
95 [ 0x06 ] = KEY_ZOOM, // 'full screen'
96 [ 0x18 ] = KEY_VIDEO, // 'display'
97 [ 0x38 ] = KEY_SEARCH, // 'loop'
98 [ 0x08 ] = KEY_INFO, // 'preview'
99 [ 0x2a ] = KEY_REWIND, // 'backward <<'
100 [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>'
101 [ 0x3a ] = KEY_RECORD, // 'capture'
102 [ 0x0a ] = KEY_MUTE, // 'mute'
103 [ 0x2c ] = KEY_RECORD, // 'record'
104 [ 0x1c ] = KEY_PAUSE, // 'pause'
105 [ 0x3c ] = KEY_STOP, // 'stop'
106 [ 0x0c ] = KEY_PLAY, // 'play'
107 [ 0x2e ] = KEY_RED, // 'red'
108 [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel'
109 [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok'
110 [ 0x21 ] = KEY_GREEN, // 'green'
111 [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -'
112 [ 0x31 ] = KEY_CHANNELUP, // 'channel +'
113 [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -'
114 [ 0x3e ] = KEY_VOLUMEUP, // 'volume +'
115 };
116
117 /* Attila Kondoros <attila.kondoros@chello.hu> */
118 static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
119
120 [ 1 ] = KEY_KP1,
121 [ 2 ] = KEY_KP2,
122 [ 3 ] = KEY_KP3,
123 [ 4 ] = KEY_KP4,
124 [ 5 ] = KEY_KP5,
125 [ 6 ] = KEY_KP6,
126 [ 7 ] = KEY_KP7,
127 [ 8 ] = KEY_KP8,
128 [ 9 ] = KEY_KP9,
129 [ 0 ] = KEY_KP0,
130 [ 23 ] = KEY_LAST, // +100
131 [ 10 ] = KEY_LIST, // recall
132
133
134 [ 28 ] = KEY_TUNER, // TV/FM
135 [ 21 ] = KEY_SEARCH, // scan
136 [ 18 ] = KEY_POWER, // power
137 [ 31 ] = KEY_VOLUMEDOWN, // vol up
138 [ 27 ] = KEY_VOLUMEUP, // vol down
139 [ 30 ] = KEY_CHANNELDOWN, // chn up
140 [ 26 ] = KEY_CHANNELUP, // chn down
141
142 [ 17 ] = KEY_VIDEO, // video
143 [ 15 ] = KEY_ZOOM, // full screen
144 [ 19 ] = KEY_MUTE, // mute/unmute
145 [ 16 ] = KEY_TEXT, // min
146
147 [ 13 ] = KEY_STOP, // freeze
148 [ 14 ] = KEY_RECORD, // record
149 [ 29 ] = KEY_PLAYPAUSE, // stop
150 [ 25 ] = KEY_PLAY, // play
151
152 [ 22 ] = KEY_GOTO, // osd
153 [ 20 ] = KEY_REFRESH, // default
154 [ 12 ] = KEY_KPPLUS, // fine tune >>>>
155 [ 24 ] = KEY_KPMINUS // fine tune <<<<
156 };
157
158 /* ---------------------------------------------------------------------- */
159
160 struct IR {
161 struct bttv_sub_device *sub;
162 struct input_dev input;
163 struct ir_input_state ir;
164 char name[32];
165 char phys[32];
166 u32 mask_keycode;
167 u32 mask_keydown;
168 u32 mask_keyup;
169
170 int polling;
171 u32 last_gpio;
172 struct work_struct work;
173 struct timer_list timer;
174 };
175
176 static int debug;
177 module_param(debug, int, 0644); /* debug level (0,1,2) */
178
179 #define DEVNAME "ir-kbd-gpio"
180 #define dprintk(fmt, arg...) if (debug) \
181 printk(KERN_DEBUG DEVNAME ": " fmt , ## arg)
182
183 static void ir_irq(struct bttv_sub_device *sub);
184 static int ir_probe(struct device *dev);
185 static int ir_remove(struct device *dev);
186
187 static struct bttv_sub_driver driver = {
188 .drv = {
189 .name = DEVNAME,
190 .probe = ir_probe,
191 .remove = ir_remove,
192 },
193 .gpio_irq = ir_irq,
194 };
195
196 /* ---------------------------------------------------------------------- */
197
198 static void ir_handle_key(struct IR *ir)
199 {
200 u32 gpio,data;
201
202 /* read gpio value */
203 gpio = bttv_gpio_read(ir->sub->core);
204 if (ir->polling) {
205 if (ir->last_gpio == gpio)
206 return;
207 ir->last_gpio = gpio;
208 }
209
210 /* extract data */
211 data = ir_extract_bits(gpio, ir->mask_keycode);
212 dprintk(DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
213 gpio, data,
214 ir->polling ? "poll" : "irq",
215 (gpio & ir->mask_keydown) ? " down" : "",
216 (gpio & ir->mask_keyup) ? " up" : "");
217
218 if (ir->mask_keydown) {
219 /* bit set on keydown */
220 if (gpio & ir->mask_keydown) {
221 ir_input_keydown(&ir->input,&ir->ir,data,data);
222 } else {
223 ir_input_nokey(&ir->input,&ir->ir);
224 }
225
226 } else if (ir->mask_keyup) {
227 /* bit cleared on keydown */
228 if (0 == (gpio & ir->mask_keyup)) {
229 ir_input_keydown(&ir->input,&ir->ir,data,data);
230 } else {
231 ir_input_nokey(&ir->input,&ir->ir);
232 }
233
234 } else {
235 /* can't disturgissh keydown/up :-/ */
236 ir_input_keydown(&ir->input,&ir->ir,data,data);
237 ir_input_nokey(&ir->input,&ir->ir);
238 }
239 }
240
241 static void ir_irq(struct bttv_sub_device *sub)
242 {
243 struct IR *ir = dev_get_drvdata(&sub->dev);
244
245 if (!ir->polling)
246 ir_handle_key(ir);
247 }
248
249 static void ir_timer(unsigned long data)
250 {
251 struct IR *ir = (struct IR*)data;
252
253 schedule_work(&ir->work);
254 }
255
256 static void ir_work(void *data)
257 {
258 struct IR *ir = data;
259 unsigned long timeout;
260
261 ir_handle_key(ir);
262 timeout = jiffies + (ir->polling * HZ / 1000);
263 mod_timer(&ir->timer, timeout);
264 }
265
266 /* ---------------------------------------------------------------------- */
267
268 static int ir_probe(struct device *dev)
269 {
270 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
271 struct IR *ir;
272 IR_KEYTAB_TYPE *ir_codes = NULL;
273 int ir_type = IR_TYPE_OTHER;
274
275 ir = kmalloc(sizeof(*ir),GFP_KERNEL);
276 if (NULL == ir)
277 return -ENOMEM;
278 memset(ir,0,sizeof(*ir));
279
280 /* detect & configure */
281 switch (sub->core->type) {
282 case BTTV_AVERMEDIA:
283 case BTTV_AVPHONE98:
284 case BTTV_AVERMEDIA98:
285 ir_codes = ir_codes_avermedia;
286 ir->mask_keycode = 0xf88000;
287 ir->mask_keydown = 0x010000;
288 ir->polling = 50; // ms
289 break;
290
291 case BTTV_AVDVBT_761:
292 case BTTV_AVDVBT_771:
293 ir_codes = ir_codes_avermedia_dvbt;
294 ir->mask_keycode = 0x0f00c0;
295 ir->mask_keydown = 0x000020;
296 ir->polling = 50; // ms
297 break;
298
299 case BTTV_PXELVWPLTVPAK:
300 ir_codes = ir_codes_pixelview;
301 ir->mask_keycode = 0x003e00;
302 ir->mask_keyup = 0x010000;
303 ir->polling = 50; // ms
304 break;
305 case BTTV_PV_BT878P_9B:
306 case BTTV_PV_BT878P_PLUS:
307 ir_codes = ir_codes_pixelview;
308 ir->mask_keycode = 0x001f00;
309 ir->mask_keyup = 0x008000;
310 ir->polling = 50; // ms
311 break;
312
313 case BTTV_WINFAST2000:
314 ir_codes = ir_codes_winfast;
315 ir->mask_keycode = 0x1f8;
316 break;
317 case BTTV_MAGICTVIEW061:
318 case BTTV_MAGICTVIEW063:
319 ir_codes = ir_codes_winfast;
320 ir->mask_keycode = 0x0008e000;
321 ir->mask_keydown = 0x00200000;
322 break;
323 case BTTV_APAC_VIEWCOMP:
324 ir_codes = ir_codes_apac_viewcomp;
325 ir->mask_keycode = 0x001f00;
326 ir->mask_keyup = 0x008000;
327 ir->polling = 50; // ms
328 break;
329 }
330 if (NULL == ir_codes) {
331 kfree(ir);
332 return -ENODEV;
333 }
334
335 /* init hardware-specific stuff */
336 bttv_gpio_inout(sub->core, ir->mask_keycode | ir->mask_keydown, 0);
337 ir->sub = sub;
338
339 /* init input device */
340 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
341 sub->core->type);
342 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
343 pci_name(sub->core->pci));
344
345 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes);
346 ir->input.name = ir->name;
347 ir->input.phys = ir->phys;
348 ir->input.id.bustype = BUS_PCI;
349 ir->input.id.version = 1;
350 if (sub->core->pci->subsystem_vendor) {
351 ir->input.id.vendor = sub->core->pci->subsystem_vendor;
352 ir->input.id.product = sub->core->pci->subsystem_device;
353 } else {
354 ir->input.id.vendor = sub->core->pci->vendor;
355 ir->input.id.product = sub->core->pci->device;
356 }
357
358 if (ir->polling) {
359 INIT_WORK(&ir->work, ir_work, ir);
360 init_timer(&ir->timer);
361 ir->timer.function = ir_timer;
362 ir->timer.data = (unsigned long)ir;
363 schedule_work(&ir->work);
364 }
365
366 /* all done */
367 dev_set_drvdata(dev,ir);
368 input_register_device(&ir->input);
369 printk(DEVNAME ": %s detected at %s\n",ir->input.name,ir->input.phys);
370
371 return 0;
372 }
373
374 static int ir_remove(struct device *dev)
375 {
376 struct IR *ir = dev_get_drvdata(dev);
377
378 if (ir->polling) {
379 del_timer(&ir->timer);
380 flush_scheduled_work();
381 }
382
383 input_unregister_device(&ir->input);
384 kfree(ir);
385 return 0;
386 }
387
388 /* ---------------------------------------------------------------------- */
389
390 MODULE_AUTHOR("Gerd Knorr, Pavel Machek");
391 MODULE_DESCRIPTION("input driver for bt8x8 gpio IR remote controls");
392 MODULE_LICENSE("GPL");
393
394 static int ir_init(void)
395 {
396 return bttv_sub_register(&driver, "remote");
397 }
398
399 static void ir_fini(void)
400 {
401 bttv_sub_unregister(&driver);
402 }
403
404 module_init(ir_init);
405 module_exit(ir_fini);
406
407
408 /*
409 * Local variables:
410 * c-basic-offset: 8
411 * End:
412 */
This page took 0.04012 seconds and 5 git commands to generate.