Merge branch 'timer/cleanup' into late/mvebu2
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / media / pci / bt8xx / bttv-input.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 *
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
8af443e5
JP
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
1da177e4 23#include <linux/module.h>
1da177e4
LT
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/input.h>
5a0e3ad6 28#include <linux/slab.h>
1da177e4 29
1da177e4 30#include "bttv.h"
4abdfed5 31#include "bttvp.h"
1da177e4 32
6c6c0b2c 33
7d341a6a
MCC
34static int ir_debug;
35module_param(ir_debug, int, 0644);
1da177e4 36
c408a6f6 37static int ir_rc5_remote_gap = 885;
9160723e 38module_param(ir_rc5_remote_gap, int, 0644);
9160723e 39
7d341a6a 40#undef dprintk
8af443e5
JP
41#define dprintk(fmt, ...) \
42do { \
43 if (ir_debug >= 1) \
44 pr_info(fmt, ##__VA_ARGS__); \
7d341a6a
MCC
45} while (0)
46
4abdfed5 47#define DEVNAME "bttv-input"
1da177e4 48
727e625c
MCC
49#define MODULE_NAME "bttv"
50
1da177e4
LT
51/* ---------------------------------------------------------------------- */
52
4abdfed5 53static void ir_handle_key(struct bttv *btv)
1da177e4 54{
edb4c25c 55 struct bttv_ir *ir = btv->remote;
1da177e4
LT
56 u32 gpio,data;
57
58 /* read gpio value */
4abdfed5 59 gpio = bttv_gpio_read(&btv->c);
1da177e4
LT
60 if (ir->polling) {
61 if (ir->last_gpio == gpio)
62 return;
63 ir->last_gpio = gpio;
64 }
65
66 /* extract data */
67 data = ir_extract_bits(gpio, ir->mask_keycode);
8af443e5 68 dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
1da177e4
LT
69 gpio, data,
70 ir->polling ? "poll" : "irq",
71 (gpio & ir->mask_keydown) ? " down" : "",
72 (gpio & ir->mask_keyup) ? " up" : "");
73
62c65031
DH
74 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
75 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
ca86674b 76 rc_keydown_notimeout(ir->dev, data, 0);
1da177e4 77 } else {
b3d98135
MCC
78 /* HACK: Probably, ir->mask_keydown is missing
79 for this board */
80 if (btv->c.type == BTTV_BOARD_WINFAST2000)
ca86674b 81 rc_keydown_notimeout(ir->dev, data, 0);
b3d98135 82
ca86674b 83 rc_keyup(ir->dev);
1da177e4 84 }
1da177e4
LT
85}
86
7d341a6a
MCC
87static void ir_enltv_handle_key(struct bttv *btv)
88{
edb4c25c 89 struct bttv_ir *ir = btv->remote;
7d341a6a
MCC
90 u32 gpio, data, keyup;
91
92 /* read gpio value */
93 gpio = bttv_gpio_read(&btv->c);
94
95 /* extract data */
96 data = ir_extract_bits(gpio, ir->mask_keycode);
97
98 /* Check if it is keyup */
99 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
100
101 if ((ir->last_gpio & 0x7f) != data) {
8af443e5 102 dprintk("gpio=0x%x code=%d | %s\n",
7d341a6a
MCC
103 gpio, data,
104 (gpio & ir->mask_keyup) ? " up" : "up/down");
105
ca86674b 106 rc_keydown_notimeout(ir->dev, data, 0);
7d341a6a 107 if (keyup)
ca86674b 108 rc_keyup(ir->dev);
7d341a6a
MCC
109 } else {
110 if ((ir->last_gpio & 1 << 31) == keyup)
111 return;
112
8af443e5 113 dprintk("(cnt) gpio=0x%x code=%d | %s\n",
7d341a6a
MCC
114 gpio, data,
115 (gpio & ir->mask_keyup) ? " up" : "down");
116
117 if (keyup)
ca86674b 118 rc_keyup(ir->dev);
7d341a6a 119 else
ca86674b 120 rc_keydown_notimeout(ir->dev, data, 0);
7d341a6a
MCC
121 }
122
123 ir->last_gpio = data | keyup;
124}
125
b7c7a4be
MCC
126static int bttv_rc5_irq(struct bttv *btv);
127
4abdfed5 128void bttv_input_irq(struct bttv *btv)
1da177e4 129{
edb4c25c 130 struct bttv_ir *ir = btv->remote;
1da177e4 131
b7c7a4be
MCC
132 if (ir->rc5_gpio)
133 bttv_rc5_irq(btv);
134 else if (!ir->polling)
4abdfed5 135 ir_handle_key(btv);
1da177e4
LT
136}
137
4abdfed5 138static void bttv_input_timer(unsigned long data)
1da177e4 139{
4abdfed5 140 struct bttv *btv = (struct bttv*)data;
edb4c25c 141 struct bttv_ir *ir = btv->remote;
1da177e4 142
7d341a6a
MCC
143 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
144 ir_enltv_handle_key(btv);
145 else
146 ir_handle_key(btv);
c1904956 147 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
1da177e4
LT
148}
149
bce8d0fe
MCC
150/*
151 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
152 * on the rc-core way. As we need to be sure that both IRQ transitions are
153 * properly triggered, Better to touch it only with this hardware for
154 * testing.
155 */
156
a6e3b81f
MCC
157#define RC5_START(x) (((x) >> 12) & 3)
158#define RC5_TOGGLE(x) (((x) >> 11) & 1)
159#define RC5_ADDR(x) (((x) >> 6) & 31)
160#define RC5_INSTR(x) ((x) & 63)
161
bce8d0fe
MCC
162/* decode raw bit pattern to RC5 code */
163static u32 bttv_rc5_decode(unsigned int code)
164{
165 unsigned int org_code = code;
166 unsigned int pair;
167 unsigned int rc5 = 0;
168 int i;
169
170 for (i = 0; i < 14; ++i) {
171 pair = code & 0x3;
172 code >>= 2;
173
174 rc5 <<= 1;
175 switch (pair) {
176 case 0:
177 case 2:
178 break;
179 case 1:
180 rc5 |= 1;
181 break;
182 case 3:
8af443e5 183 dprintk("rc5_decode(%x) bad code\n",
bce8d0fe
MCC
184 org_code);
185 return 0;
186 }
187 }
8af443e5 188 dprintk("code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
bce8d0fe
MCC
189 "instr=%x\n", rc5, org_code, RC5_START(rc5),
190 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
191 return rc5;
192}
193
edb4c25c 194static void bttv_rc5_timer_end(unsigned long data)
bce8d0fe 195{
edb4c25c 196 struct bttv_ir *ir = (struct bttv_ir *)data;
bce8d0fe 197 struct timeval tv;
bce8d0fe
MCC
198 u32 gap;
199 u32 rc5 = 0;
200
201 /* get time */
bce8d0fe
MCC
202 do_gettimeofday(&tv);
203
204 /* avoid overflow with gap >1s */
205 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
206 gap = 200000;
207 } else {
208 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
209 tv.tv_usec - ir->base_time.tv_usec;
210 }
211
212 /* signal we're ready to start a new code */
edb4c25c 213 ir->active = false;
bce8d0fe
MCC
214
215 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
216 if (gap < 28000) {
8af443e5 217 dprintk("spurious timer_end\n");
bce8d0fe
MCC
218 return;
219 }
220
221 if (ir->last_bit < 20) {
222 /* ignore spurious codes (caused by light/other remotes) */
8af443e5 223 dprintk("short code: %x\n", ir->code);
bce8d0fe
MCC
224 } else {
225 ir->code = (ir->code << ir->shift_by) | 1;
226 rc5 = bttv_rc5_decode(ir->code);
227
228 /* two start bits? */
229 if (RC5_START(rc5) != ir->start) {
8af443e5 230 pr_info(DEVNAME ":"
bce8d0fe
MCC
231 " rc5 start bits invalid: %u\n", RC5_START(rc5));
232
233 /* right address? */
234 } else if (RC5_ADDR(rc5) == ir->addr) {
235 u32 toggle = RC5_TOGGLE(rc5);
236 u32 instr = RC5_INSTR(rc5);
237
238 /* Good code */
ca86674b 239 rc_keydown(ir->dev, instr, toggle);
8af443e5 240 dprintk("instruction %x, toggle %x\n",
bce8d0fe
MCC
241 instr, toggle);
242 }
243 }
244}
6c6c0b2c 245
4abdfed5 246static int bttv_rc5_irq(struct bttv *btv)
6c6c0b2c 247{
edb4c25c 248 struct bttv_ir *ir = btv->remote;
6c6c0b2c
MW
249 struct timeval tv;
250 u32 gpio;
251 u32 gap;
c1904956 252 unsigned long current_jiffies;
6c6c0b2c
MW
253
254 /* read gpio port */
4abdfed5 255 gpio = bttv_gpio_read(&btv->c);
6c6c0b2c 256
6c6c0b2c
MW
257 /* get time of bit */
258 current_jiffies = jiffies;
259 do_gettimeofday(&tv);
260
261 /* avoid overflow with gap >1s */
262 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
263 gap = 200000;
264 } else {
265 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
266 tv.tv_usec - ir->base_time.tv_usec;
267 }
268
8af443e5 269 dprintk("RC5 IRQ: gap %d us for %s\n",
b7c7a4be
MCC
270 gap, (gpio & 0x20) ? "mark" : "space");
271
272 /* remote IRQ? */
273 if (!(gpio & 0x20))
274 return 0;
275
6c6c0b2c
MW
276 /* active code => add bit */
277 if (ir->active) {
278 /* only if in the code (otherwise spurious IRQ or timer
279 late) */
280 if (ir->last_bit < 28) {
9160723e
HP
281 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
282 ir_rc5_remote_gap;
6c6c0b2c
MW
283 ir->code |= 1 << ir->last_bit;
284 }
285 /* starting new code */
286 } else {
edb4c25c 287 ir->active = true;
6c6c0b2c
MW
288 ir->code = 0;
289 ir->base_time = tv;
290 ir->last_bit = 0;
291
3938e0cf 292 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
6c6c0b2c
MW
293 }
294
295 /* toggle GPIO pin 4 to reset the irq */
4abdfed5
RC
296 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
297 bttv_gpio_write(&btv->c, gpio | (1 << 4));
6c6c0b2c
MW
298 return 1;
299}
300
1da177e4
LT
301/* ---------------------------------------------------------------------- */
302
edb4c25c 303static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
b07b4783
DT
304{
305 if (ir->polling) {
c1904956 306 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
fe06fe0a 307 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
b07b4783
DT
308 add_timer(&ir->timer);
309 } else if (ir->rc5_gpio) {
310 /* set timer_end for code completion */
3938e0cf 311 setup_timer(&ir->timer, bttv_rc5_timer_end, (unsigned long)ir);
9160723e
HP
312 ir->shift_by = 1;
313 ir->start = 3;
314 ir->addr = 0x0;
9160723e 315 ir->rc5_remote_gap = ir_rc5_remote_gap;
b07b4783
DT
316 }
317}
318
319static void bttv_ir_stop(struct bttv *btv)
320{
8c71778c 321 if (btv->remote->polling)
b07b4783 322 del_timer_sync(&btv->remote->timer);
b07b4783
DT
323
324 if (btv->remote->rc5_gpio) {
325 u32 gpio;
326
3938e0cf 327 del_timer_sync(&btv->remote->timer);
b07b4783
DT
328
329 gpio = bttv_gpio_read(&btv->c);
330 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
331 }
332}
333
c0c46826
MCC
334/*
335 * Get_key functions used by I2C remotes
336 */
337
338static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
339{
340 unsigned char b;
341
342 /* poll IR chip */
343 if (1 != i2c_master_recv(ir->c, &b, 1)) {
8af443e5 344 dprintk("read error\n");
c0c46826
MCC
345 return -EIO;
346 }
347
348 /* ignore 0xaa */
349 if (b==0xaa)
350 return 0;
8af443e5 351 dprintk("key %02x\n", b);
c0c46826 352
b2237454
MCC
353 /*
354 * NOTE:
355 * lirc_i2c maps the pv951 code as:
356 * addr = 0x61D6
357 * cmd = bit_reverse (b)
358 * So, it seems that this device uses NEC extended
359 * I decided to not fix the table, due to two reasons:
360 * 1) Without the actual device, this is only a guess;
361 * 2) As the addr is not reported via I2C, nor can be changed,
362 * the device is bound to the vendor-provided RC.
363 */
364
c0c46826
MCC
365 *ir_key = b;
366 *ir_raw = b;
367 return 1;
368}
369
370/* Instantiate the I2C IR receiver device, if present */
4c62e976 371void init_bttv_i2c_ir(struct bttv *btv)
c0c46826
MCC
372{
373 const unsigned short addr_list[] = {
374 0x1a, 0x18, 0x64, 0x30, 0x71,
375 I2C_CLIENT_END
376 };
377 struct i2c_board_info info;
378
379 if (0 != btv->i2c_rc)
380 return;
381
382 memset(&info, 0, sizeof(struct i2c_board_info));
383 memset(&btv->init_data, 0, sizeof(btv->init_data));
384 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
385
386 switch (btv->c.type) {
387 case BTTV_BOARD_PV951:
388 btv->init_data.name = "PV951";
389 btv->init_data.get_key = get_key_pv951;
390 btv->init_data.ir_codes = RC_MAP_PV951;
c0c46826
MCC
391 info.addr = 0x4b;
392 break;
393 default:
394 /*
395 * The external IR receiver is at i2c address 0x34 (0x35 for
bce8d0fe
MCC
396 * reads). Future Hauppauge cards will have an internal
397 * receiver at 0x30 (0x31 for reads). In theory, both can be
398 * fitted, and Hauppauge suggest an external overrides an
399 * internal.
c0c46826
MCC
400 * That's why we probe 0x1a (~0x34) first. CB
401 */
402
403 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
404 return;
405 }
406
407 if (btv->init_data.name)
408 info.platform_data = &btv->init_data;
409 i2c_new_device(&btv->c.i2c_adap, &info);
410
411 return;
412}
413
4c62e976 414int fini_bttv_i2c(struct bttv *btv)
c0c46826
MCC
415{
416 if (0 != btv->i2c_rc)
417 return 0;
418
419 return i2c_del_adapter(&btv->c.i2c_adap);
420}
421
4abdfed5 422int bttv_input_init(struct bttv *btv)
1da177e4 423{
edb4c25c 424 struct bttv_ir *ir;
02858eed 425 char *ir_codes = NULL;
d8b4b582 426 struct rc_dev *rc;
b07b4783 427 int err = -ENOMEM;
1da177e4 428
4abdfed5
RC
429 if (!btv->has_remote)
430 return -ENODEV;
431
432 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
d8b4b582
DH
433 rc = rc_allocate_device();
434 if (!ir || !rc)
b07b4783 435 goto err_out_free;
1da177e4
LT
436
437 /* detect & configure */
4abdfed5 438 switch (btv->c.type) {
5a25e84b
MCC
439 case BTTV_BOARD_AVERMEDIA:
440 case BTTV_BOARD_AVPHONE98:
441 case BTTV_BOARD_AVERMEDIA98:
02858eed 442 ir_codes = RC_MAP_AVERMEDIA;
1da177e4
LT
443 ir->mask_keycode = 0xf88000;
444 ir->mask_keydown = 0x010000;
445 ir->polling = 50; // ms
446 break;
447
5a25e84b
MCC
448 case BTTV_BOARD_AVDVBT_761:
449 case BTTV_BOARD_AVDVBT_771:
02858eed 450 ir_codes = RC_MAP_AVERMEDIA_DVBT;
1da177e4
LT
451 ir->mask_keycode = 0x0f00c0;
452 ir->mask_keydown = 0x000020;
453 ir->polling = 50; // ms
454 break;
455
5a25e84b 456 case BTTV_BOARD_PXELVWPLTVPAK:
02858eed 457 ir_codes = RC_MAP_PIXELVIEW;
1da177e4
LT
458 ir->mask_keycode = 0x003e00;
459 ir->mask_keyup = 0x010000;
460 ir->polling = 50; // ms
4ac97914 461 break;
c663155c 462 case BTTV_BOARD_PV_M4900:
5a25e84b
MCC
463 case BTTV_BOARD_PV_BT878P_9B:
464 case BTTV_BOARD_PV_BT878P_PLUS:
02858eed 465 ir_codes = RC_MAP_PIXELVIEW;
1da177e4
LT
466 ir->mask_keycode = 0x001f00;
467 ir->mask_keyup = 0x008000;
468 ir->polling = 50; // ms
4ac97914 469 break;
1da177e4 470
5a25e84b 471 case BTTV_BOARD_WINFAST2000:
02858eed 472 ir_codes = RC_MAP_WINFAST;
1da177e4
LT
473 ir->mask_keycode = 0x1f8;
474 break;
5a25e84b
MCC
475 case BTTV_BOARD_MAGICTVIEW061:
476 case BTTV_BOARD_MAGICTVIEW063:
02858eed 477 ir_codes = RC_MAP_WINFAST;
1da177e4
LT
478 ir->mask_keycode = 0x0008e000;
479 ir->mask_keydown = 0x00200000;
480 break;
5a25e84b 481 case BTTV_BOARD_APAC_VIEWCOMP:
02858eed 482 ir_codes = RC_MAP_APAC_VIEWCOMP;
1da177e4
LT
483 ir->mask_keycode = 0x001f00;
484 ir->mask_keyup = 0x008000;
485 ir->polling = 50; // ms
486 break;
ed44f66e 487 case BTTV_BOARD_ASKEY_CPH03X:
5a25e84b 488 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
4ab2b99b 489 case BTTV_BOARD_CONTVFMI:
02858eed 490 ir_codes = RC_MAP_PIXELVIEW;
cc9d8d49
RC
491 ir->mask_keycode = 0x001F00;
492 ir->mask_keyup = 0x006000;
493 ir->polling = 50; // ms
494 break;
6c6c0b2c 495 case BTTV_BOARD_NEBULA_DIGITV:
02858eed 496 ir_codes = RC_MAP_NEBULA;
b7c7a4be 497 ir->rc5_gpio = true;
674434c6 498 break;
2d05ae6b 499 case BTTV_BOARD_MACHTV_MAGICTV:
02858eed 500 ir_codes = RC_MAP_APAC_VIEWCOMP;
2d05ae6b
JC
501 ir->mask_keycode = 0x001F00;
502 ir->mask_keyup = 0x004000;
503 ir->polling = 50; /* ms */
504 break;
e80faad3 505 case BTTV_BOARD_KOZUMI_KTV_01C:
02858eed 506 ir_codes = RC_MAP_PCTV_SEDNA;
e80faad3
ML
507 ir->mask_keycode = 0x001f00;
508 ir->mask_keyup = 0x006000;
509 ir->polling = 50; /* ms */
510 break;
7d341a6a 511 case BTTV_BOARD_ENLTV_FM_2:
02858eed 512 ir_codes = RC_MAP_ENCORE_ENLTV2;
7d341a6a
MCC
513 ir->mask_keycode = 0x00fd00;
514 ir->mask_keyup = 0x000080;
515 ir->polling = 1; /* ms */
516 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
517 ir->mask_keycode);
518 break;
1da177e4
LT
519 }
520 if (NULL == ir_codes) {
8af443e5 521 dprintk("Ooops: IR config error [card=%d]\n", btv->c.type);
b07b4783
DT
522 err = -ENODEV;
523 goto err_out_free;
1da177e4
LT
524 }
525
6c6c0b2c
MW
526 if (ir->rc5_gpio) {
527 u32 gpio;
657de3cd 528 /* enable remote irq */
4abdfed5
RC
529 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
530 gpio = bttv_gpio_read(&btv->c);
531 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
532 bttv_gpio_write(&btv->c, gpio | (1 << 4));
6c6c0b2c
MW
533 } else {
534 /* init hardware-specific stuff */
4abdfed5 535 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
6c6c0b2c 536 }
1da177e4
LT
537
538 /* init input device */
d8b4b582 539 ir->dev = rc;
4abdfed5 540
1da177e4 541 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
4abdfed5 542 btv->c.type);
1da177e4 543 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
4abdfed5 544 pci_name(btv->c.pci));
1da177e4 545
d8b4b582
DH
546 rc->input_name = ir->name;
547 rc->input_phys = ir->phys;
548 rc->input_id.bustype = BUS_PCI;
549 rc->input_id.version = 1;
4abdfed5 550 if (btv->c.pci->subsystem_vendor) {
d8b4b582
DH
551 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
552 rc->input_id.product = btv->c.pci->subsystem_device;
1da177e4 553 } else {
d8b4b582
DH
554 rc->input_id.vendor = btv->c.pci->vendor;
555 rc->input_id.product = btv->c.pci->device;
1da177e4 556 }
d8b4b582
DH
557 rc->dev.parent = &btv->c.pci->dev;
558 rc->map_name = ir_codes;
559 rc->driver_name = MODULE_NAME;
1da177e4 560
4abdfed5 561 btv->remote = ir;
b07b4783 562 bttv_ir_start(btv, ir);
1da177e4
LT
563
564 /* all done */
d8b4b582 565 err = rc_register_device(rc);
b07b4783
DT
566 if (err)
567 goto err_out_stop;
6c6c0b2c 568
1da177e4 569 return 0;
b07b4783
DT
570
571 err_out_stop:
572 bttv_ir_stop(btv);
573 btv->remote = NULL;
574 err_out_free:
d8b4b582 575 rc_free_device(rc);
b07b4783
DT
576 kfree(ir);
577 return err;
1da177e4
LT
578}
579
4abdfed5 580void bttv_input_fini(struct bttv *btv)
1da177e4 581{
4abdfed5
RC
582 if (btv->remote == NULL)
583 return;
1da177e4 584
b07b4783 585 bttv_ir_stop(btv);
d8b4b582 586 rc_unregister_device(btv->remote->dev);
4abdfed5
RC
587 kfree(btv->remote);
588 btv->remote = NULL;
1da177e4 589}