blob: e8f60ab58db6f20481d8b74fc0b732182c1df8ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/interrupt.h>
25#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "bttv.h"
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020029#include "bttvp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Mark Weaver6c6c0b22005-11-13 16:07:52 -080031
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030032static int ir_debug;
33module_param(ir_debug, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Adrian Bunkc408a6f2006-12-28 12:47:47 -030035static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030036module_param(ir_rc5_remote_gap, int, 0644);
Hermann Pitton91607232006-12-07 21:45:28 -030037
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030038#undef dprintk
39#define dprintk(arg...) do { \
40 if (ir_debug >= 1) \
41 printk(arg); \
42} while (0)
43
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020044#define DEVNAME "bttv-input"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030046#define MODULE_NAME "bttv"
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* ---------------------------------------------------------------------- */
49
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020050static void ir_handle_key(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Hermann Pitton91607232006-12-07 21:45:28 -030052 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 u32 gpio,data;
54
55 /* read gpio value */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020056 gpio = bttv_gpio_read(&btv->c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (ir->polling) {
58 if (ir->last_gpio == gpio)
59 return;
60 ir->last_gpio = gpio;
61 }
62
63 /* extract data */
64 data = ir_extract_bits(gpio, ir->mask_keycode);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020065 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 gpio, data,
67 ir->polling ? "poll" : "irq",
68 (gpio & ir->mask_keydown) ? " down" : "",
69 (gpio & ir->mask_keyup) ? " up" : "");
70
David Härdeman62c65032010-10-29 16:08:07 -030071 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
72 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
73 ir_keydown_notimeout(ir->dev, data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 } else {
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030075 /* HACK: Probably, ir->mask_keydown is missing
76 for this board */
77 if (btv->c.type == BTTV_BOARD_WINFAST2000)
David Härdeman62c65032010-10-29 16:08:07 -030078 ir_keydown_notimeout(ir->dev, data, 0);
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030079
David Härdeman62c65032010-10-29 16:08:07 -030080 ir_keyup(ir->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82}
83
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030084static void ir_enltv_handle_key(struct bttv *btv)
85{
86 struct card_ir *ir = btv->remote;
87 u32 gpio, data, keyup;
88
89 /* read gpio value */
90 gpio = bttv_gpio_read(&btv->c);
91
92 /* extract data */
93 data = ir_extract_bits(gpio, ir->mask_keycode);
94
95 /* Check if it is keyup */
96 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
97
98 if ((ir->last_gpio & 0x7f) != data) {
99 dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
100 gpio, data,
101 (gpio & ir->mask_keyup) ? " up" : "up/down");
102
David Härdeman62c65032010-10-29 16:08:07 -0300103 ir_keydown_notimeout(ir->dev, data, 0);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300104 if (keyup)
David Härdeman62c65032010-10-29 16:08:07 -0300105 ir_keyup(ir->dev);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300106 } else {
107 if ((ir->last_gpio & 1 << 31) == keyup)
108 return;
109
110 dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
111 gpio, data,
112 (gpio & ir->mask_keyup) ? " up" : "down");
113
114 if (keyup)
David Härdeman62c65032010-10-29 16:08:07 -0300115 ir_keyup(ir->dev);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300116 else
David Härdeman62c65032010-10-29 16:08:07 -0300117 ir_keydown_notimeout(ir->dev, data, 0);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300118 }
119
120 ir->last_gpio = data | keyup;
121}
122
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200123void bttv_input_irq(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Hermann Pitton91607232006-12-07 21:45:28 -0300125 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 if (!ir->polling)
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200128 ir_handle_key(btv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200131static void bttv_input_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200133 struct bttv *btv = (struct bttv*)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300134 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300136 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
137 ir_enltv_handle_key(btv);
138 else
139 ir_handle_key(btv);
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300140 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -0300143/*
144 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
145 * on the rc-core way. As we need to be sure that both IRQ transitions are
146 * properly triggered, Better to touch it only with this hardware for
147 * testing.
148 */
149
150/* decode raw bit pattern to RC5 code */
151static u32 bttv_rc5_decode(unsigned int code)
152{
153 unsigned int org_code = code;
154 unsigned int pair;
155 unsigned int rc5 = 0;
156 int i;
157
158 for (i = 0; i < 14; ++i) {
159 pair = code & 0x3;
160 code >>= 2;
161
162 rc5 <<= 1;
163 switch (pair) {
164 case 0:
165 case 2:
166 break;
167 case 1:
168 rc5 |= 1;
169 break;
170 case 3:
171 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
172 org_code);
173 return 0;
174 }
175 }
176 dprintk(KERN_INFO DEVNAME ":"
177 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
178 "instr=%x\n", rc5, org_code, RC5_START(rc5),
179 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
180 return rc5;
181}
182
183void bttv_rc5_timer_end(unsigned long data)
184{
185 struct card_ir *ir = (struct card_ir *)data;
186 struct timeval tv;
187 unsigned long current_jiffies;
188 u32 gap;
189 u32 rc5 = 0;
190
191 /* get time */
192 current_jiffies = jiffies;
193 do_gettimeofday(&tv);
194
195 /* avoid overflow with gap >1s */
196 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
197 gap = 200000;
198 } else {
199 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
200 tv.tv_usec - ir->base_time.tv_usec;
201 }
202
203 /* signal we're ready to start a new code */
204 ir->active = 0;
205
206 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
207 if (gap < 28000) {
208 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
209 return;
210 }
211
212 if (ir->last_bit < 20) {
213 /* ignore spurious codes (caused by light/other remotes) */
214 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
215 } else {
216 ir->code = (ir->code << ir->shift_by) | 1;
217 rc5 = bttv_rc5_decode(ir->code);
218
219 /* two start bits? */
220 if (RC5_START(rc5) != ir->start) {
221 printk(KERN_INFO DEVNAME ":"
222 " rc5 start bits invalid: %u\n", RC5_START(rc5));
223
224 /* right address? */
225 } else if (RC5_ADDR(rc5) == ir->addr) {
226 u32 toggle = RC5_TOGGLE(rc5);
227 u32 instr = RC5_INSTR(rc5);
228
229 /* Good code */
230 ir_keydown(ir->dev, instr, toggle);
231 dprintk(KERN_INFO DEVNAME ":"
232 " instruction %x, toggle %x\n",
233 instr, toggle);
234 }
235 }
236}
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800237
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200238static int bttv_rc5_irq(struct bttv *btv)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800239{
Hermann Pitton91607232006-12-07 21:45:28 -0300240 struct card_ir *ir = btv->remote;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800241 struct timeval tv;
242 u32 gpio;
243 u32 gap;
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300244 unsigned long current_jiffies;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800245
246 /* read gpio port */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200247 gpio = bttv_gpio_read(&btv->c);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800248
249 /* remote IRQ? */
250 if (!(gpio & 0x20))
251 return 0;
252
253 /* get time of bit */
254 current_jiffies = jiffies;
255 do_gettimeofday(&tv);
256
257 /* avoid overflow with gap >1s */
258 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
259 gap = 200000;
260 } else {
261 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
262 tv.tv_usec - ir->base_time.tv_usec;
263 }
264
265 /* active code => add bit */
266 if (ir->active) {
267 /* only if in the code (otherwise spurious IRQ or timer
268 late) */
269 if (ir->last_bit < 28) {
Hermann Pitton91607232006-12-07 21:45:28 -0300270 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
271 ir_rc5_remote_gap;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800272 ir->code |= 1 << ir->last_bit;
273 }
274 /* starting new code */
275 } else {
276 ir->active = 1;
277 ir->code = 0;
278 ir->base_time = tv;
279 ir->last_bit = 0;
280
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300281 mod_timer(&ir->timer_end,
282 current_jiffies + msecs_to_jiffies(30));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800283 }
284
285 /* toggle GPIO pin 4 to reset the irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200286 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
287 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800288 return 1;
289}
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291/* ---------------------------------------------------------------------- */
292
Hermann Pitton91607232006-12-07 21:45:28 -0300293static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300294{
295 if (ir->polling) {
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300296 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
Mauro Carvalho Chehabfe06fe02007-07-17 16:36:20 -0300297 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300298 add_timer(&ir->timer);
299 } else if (ir->rc5_gpio) {
300 /* set timer_end for code completion */
301 init_timer(&ir->timer_end);
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -0300302 ir->timer_end.function = bttv_rc5_timer_end;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300303 ir->timer_end.data = (unsigned long)ir;
Hermann Pitton91607232006-12-07 21:45:28 -0300304 ir->shift_by = 1;
305 ir->start = 3;
306 ir->addr = 0x0;
Hermann Pitton91607232006-12-07 21:45:28 -0300307 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300308 }
309}
310
311static void bttv_ir_stop(struct bttv *btv)
312{
313 if (btv->remote->polling) {
314 del_timer_sync(&btv->remote->timer);
315 flush_scheduled_work();
316 }
317
318 if (btv->remote->rc5_gpio) {
319 u32 gpio;
320
321 del_timer_sync(&btv->remote->timer_end);
322 flush_scheduled_work();
323
324 gpio = bttv_gpio_read(&btv->c);
325 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
326 }
327}
328
Mauro Carvalho Chehabc0c46822010-09-22 23:24:04 -0300329/*
330 * Get_key functions used by I2C remotes
331 */
332
333static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
334{
335 unsigned char b;
336
337 /* poll IR chip */
338 if (1 != i2c_master_recv(ir->c, &b, 1)) {
339 dprintk(KERN_INFO DEVNAME ": read error\n");
340 return -EIO;
341 }
342
343 /* ignore 0xaa */
344 if (b==0xaa)
345 return 0;
346 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
347
348 *ir_key = b;
349 *ir_raw = b;
350 return 1;
351}
352
353/* Instantiate the I2C IR receiver device, if present */
354void __devinit init_bttv_i2c_ir(struct bttv *btv)
355{
356 const unsigned short addr_list[] = {
357 0x1a, 0x18, 0x64, 0x30, 0x71,
358 I2C_CLIENT_END
359 };
360 struct i2c_board_info info;
361
362 if (0 != btv->i2c_rc)
363 return;
364
365 memset(&info, 0, sizeof(struct i2c_board_info));
366 memset(&btv->init_data, 0, sizeof(btv->init_data));
367 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
368
369 switch (btv->c.type) {
370 case BTTV_BOARD_PV951:
371 btv->init_data.name = "PV951";
372 btv->init_data.get_key = get_key_pv951;
373 btv->init_data.ir_codes = RC_MAP_PV951;
Mauro Carvalho Chehabc0c46822010-09-22 23:24:04 -0300374 info.addr = 0x4b;
375 break;
376 default:
377 /*
378 * The external IR receiver is at i2c address 0x34 (0x35 for
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -0300379 * reads). Future Hauppauge cards will have an internal
380 * receiver at 0x30 (0x31 for reads). In theory, both can be
381 * fitted, and Hauppauge suggest an external overrides an
382 * internal.
Mauro Carvalho Chehabc0c46822010-09-22 23:24:04 -0300383 * That's why we probe 0x1a (~0x34) first. CB
384 */
385
386 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
387 return;
388 }
389
390 if (btv->init_data.name)
391 info.platform_data = &btv->init_data;
392 i2c_new_device(&btv->c.i2c_adap, &info);
393
394 return;
395}
396
397int __devexit fini_bttv_i2c(struct bttv *btv)
398{
399 if (0 != btv->i2c_rc)
400 return 0;
401
402 return i2c_del_adapter(&btv->c.i2c_adap);
403}
404
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200405int bttv_input_init(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Hermann Pitton91607232006-12-07 21:45:28 -0300407 struct card_ir *ir;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300408 char *ir_codes = NULL;
David Härdemand8b4b582010-10-29 16:08:23 -0300409 struct rc_dev *rc;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300410 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200412 if (!btv->has_remote)
413 return -ENODEV;
414
415 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
David Härdemand8b4b582010-10-29 16:08:23 -0300416 rc = rc_allocate_device();
417 if (!ir || !rc)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300418 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 /* detect & configure */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200421 switch (btv->c.type) {
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800422 case BTTV_BOARD_AVERMEDIA:
423 case BTTV_BOARD_AVPHONE98:
424 case BTTV_BOARD_AVERMEDIA98:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300425 ir_codes = RC_MAP_AVERMEDIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 ir->mask_keycode = 0xf88000;
427 ir->mask_keydown = 0x010000;
428 ir->polling = 50; // ms
429 break;
430
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800431 case BTTV_BOARD_AVDVBT_761:
432 case BTTV_BOARD_AVDVBT_771:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300433 ir_codes = RC_MAP_AVERMEDIA_DVBT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 ir->mask_keycode = 0x0f00c0;
435 ir->mask_keydown = 0x000020;
436 ir->polling = 50; // ms
437 break;
438
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800439 case BTTV_BOARD_PXELVWPLTVPAK:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300440 ir_codes = RC_MAP_PIXELVIEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 ir->mask_keycode = 0x003e00;
442 ir->mask_keyup = 0x010000;
443 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800444 break;
Mauro Carvalho Chehabc6631552006-08-23 11:17:30 -0300445 case BTTV_BOARD_PV_M4900:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800446 case BTTV_BOARD_PV_BT878P_9B:
447 case BTTV_BOARD_PV_BT878P_PLUS:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300448 ir_codes = RC_MAP_PIXELVIEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ir->mask_keycode = 0x001f00;
450 ir->mask_keyup = 0x008000;
451 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800452 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800454 case BTTV_BOARD_WINFAST2000:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300455 ir_codes = RC_MAP_WINFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 ir->mask_keycode = 0x1f8;
457 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800458 case BTTV_BOARD_MAGICTVIEW061:
459 case BTTV_BOARD_MAGICTVIEW063:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300460 ir_codes = RC_MAP_WINFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 ir->mask_keycode = 0x0008e000;
462 ir->mask_keydown = 0x00200000;
463 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800464 case BTTV_BOARD_APAC_VIEWCOMP:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300465 ir_codes = RC_MAP_APAC_VIEWCOMP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 ir->mask_keycode = 0x001f00;
467 ir->mask_keyup = 0x008000;
468 ir->polling = 50; // ms
469 break;
Mauro Carvalho Chehabed44f662009-08-22 14:43:50 -0300470 case BTTV_BOARD_ASKEY_CPH03X:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800471 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
BoyZonder4ab2b99b2006-02-27 00:08:15 -0300472 case BTTV_BOARD_CONTVFMI:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300473 ir_codes = RC_MAP_PIXELVIEW;
Ricardo Cerqueiracc9d8d42005-11-08 21:36:20 -0800474 ir->mask_keycode = 0x001F00;
475 ir->mask_keyup = 0x006000;
476 ir->polling = 50; // ms
477 break;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800478 case BTTV_BOARD_NEBULA_DIGITV:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300479 ir_codes = RC_MAP_NEBULA;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200480 btv->custom_irq = bttv_rc5_irq;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800481 ir->rc5_gpio = 1;
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800482 break;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200483 case BTTV_BOARD_MACHTV_MAGICTV:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300484 ir_codes = RC_MAP_APAC_VIEWCOMP;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200485 ir->mask_keycode = 0x001F00;
486 ir->mask_keyup = 0x004000;
487 ir->polling = 50; /* ms */
488 break;
Mauro Lacye80faad2008-04-22 14:45:58 -0300489 case BTTV_BOARD_KOZUMI_KTV_01C:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300490 ir_codes = RC_MAP_PCTV_SEDNA;
Mauro Lacye80faad2008-04-22 14:45:58 -0300491 ir->mask_keycode = 0x001f00;
492 ir->mask_keyup = 0x006000;
493 ir->polling = 50; /* ms */
494 break;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300495 case BTTV_BOARD_ENLTV_FM_2:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300496 ir_codes = RC_MAP_ENCORE_ENLTV2;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300497 ir->mask_keycode = 0x00fd00;
498 ir->mask_keyup = 0x000080;
499 ir->polling = 1; /* ms */
500 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
501 ir->mask_keycode);
502 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504 if (NULL == ir_codes) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300505 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
506 err = -ENODEV;
507 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800510 if (ir->rc5_gpio) {
511 u32 gpio;
Trent Piepho657de3c2006-06-20 00:30:57 -0300512 /* enable remote irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200513 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
514 gpio = bttv_gpio_read(&btv->c);
515 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
516 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800517 } else {
518 /* init hardware-specific stuff */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200519 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 /* init input device */
David Härdemand8b4b582010-10-29 16:08:23 -0300523 ir->dev = rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200525 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
526 btv->c.type);
527 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
528 pci_name(btv->c.pci));
529
David Härdemand8b4b582010-10-29 16:08:23 -0300530 rc->input_name = ir->name;
531 rc->input_phys = ir->phys;
532 rc->input_id.bustype = BUS_PCI;
533 rc->input_id.version = 1;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200534 if (btv->c.pci->subsystem_vendor) {
David Härdemand8b4b582010-10-29 16:08:23 -0300535 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
536 rc->input_id.product = btv->c.pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 } else {
David Härdemand8b4b582010-10-29 16:08:23 -0300538 rc->input_id.vendor = btv->c.pci->vendor;
539 rc->input_id.product = btv->c.pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
David Härdemand8b4b582010-10-29 16:08:23 -0300541 rc->dev.parent = &btv->c.pci->dev;
542 rc->map_name = ir_codes;
543 rc->driver_name = MODULE_NAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200545 btv->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300546 bttv_ir_start(btv, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* all done */
David Härdemand8b4b582010-10-29 16:08:23 -0300549 err = rc_register_device(rc);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300550 if (err)
551 goto err_out_stop;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300554
555 err_out_stop:
556 bttv_ir_stop(btv);
557 btv->remote = NULL;
558 err_out_free:
David Härdemand8b4b582010-10-29 16:08:23 -0300559 rc_free_device(rc);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300560 kfree(ir);
561 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200564void bttv_input_fini(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200566 if (btv->remote == NULL)
567 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300569 bttv_ir_stop(btv);
David Härdemand8b4b582010-10-29 16:08:23 -0300570 rc_unregister_device(btv->remote->dev);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200571 kfree(btv->remote);
572 btv->remote = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}