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