blob: aa153a986ade3e7e264ab27815dd71db0538af18 [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);
Mark Weaver6c6c0b22005-11-13 16:07:52 -080034static int repeat_delay = 500;
35module_param(repeat_delay, int, 0644);
36static int repeat_period = 33;
37module_param(repeat_period, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Adrian Bunkc408a6f2006-12-28 12:47:47 -030039static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030040module_param(ir_rc5_remote_gap, int, 0644);
Adrian Bunkc408a6f2006-12-28 12:47:47 -030041static int ir_rc5_key_timeout = 200;
Hermann Pitton91607232006-12-07 21:45:28 -030042module_param(ir_rc5_key_timeout, int, 0644);
43
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030044#undef dprintk
45#define dprintk(arg...) do { \
46 if (ir_debug >= 1) \
47 printk(arg); \
48} while (0)
49
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020050#define DEVNAME "bttv-input"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/* ---------------------------------------------------------------------- */
53
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020054static void ir_handle_key(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Hermann Pitton91607232006-12-07 21:45:28 -030056 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 u32 gpio,data;
58
59 /* read gpio value */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020060 gpio = bttv_gpio_read(&btv->c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if (ir->polling) {
62 if (ir->last_gpio == gpio)
63 return;
64 ir->last_gpio = gpio;
65 }
66
67 /* extract data */
68 data = ir_extract_bits(gpio, ir->mask_keycode);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020069 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 gpio, data,
71 ir->polling ? "poll" : "irq",
72 (gpio & ir->mask_keydown) ? " down" : "",
73 (gpio & ir->mask_keyup) ? " up" : "");
74
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020075 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
76 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -030077 ir_input_keydown(ir->dev, &ir->ir, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 } else {
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030079 /* HACK: Probably, ir->mask_keydown is missing
80 for this board */
81 if (btv->c.type == BTTV_BOARD_WINFAST2000)
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -030082 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030083
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020084 ir_input_nokey(ir->dev,&ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030089static void ir_enltv_handle_key(struct bttv *btv)
90{
91 struct card_ir *ir = btv->remote;
92 u32 gpio, data, keyup;
93
94 /* read gpio value */
95 gpio = bttv_gpio_read(&btv->c);
96
97 /* extract data */
98 data = ir_extract_bits(gpio, ir->mask_keycode);
99
100 /* Check if it is keyup */
101 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
102
103 if ((ir->last_gpio & 0x7f) != data) {
104 dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
105 gpio, data,
106 (gpio & ir->mask_keyup) ? " up" : "up/down");
107
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300108 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300109 if (keyup)
110 ir_input_nokey(ir->dev, &ir->ir);
111 } else {
112 if ((ir->last_gpio & 1 << 31) == keyup)
113 return;
114
115 dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
116 gpio, data,
117 (gpio & ir->mask_keyup) ? " up" : "down");
118
119 if (keyup)
120 ir_input_nokey(ir->dev, &ir->ir);
121 else
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300122 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300123 }
124
125 ir->last_gpio = data | keyup;
126}
127
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200128void bttv_input_irq(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Hermann Pitton91607232006-12-07 21:45:28 -0300130 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 if (!ir->polling)
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200133 ir_handle_key(btv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200136static void bttv_input_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200138 struct bttv *btv = (struct bttv*)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300139 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300141 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
142 ir_enltv_handle_key(btv);
143 else
144 ir_handle_key(btv);
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300145 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800148/* ---------------------------------------------------------------*/
149
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200150static int bttv_rc5_irq(struct bttv *btv)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800151{
Hermann Pitton91607232006-12-07 21:45:28 -0300152 struct card_ir *ir = btv->remote;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800153 struct timeval tv;
154 u32 gpio;
155 u32 gap;
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300156 unsigned long current_jiffies;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800157
158 /* read gpio port */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200159 gpio = bttv_gpio_read(&btv->c);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800160
161 /* remote IRQ? */
162 if (!(gpio & 0x20))
163 return 0;
164
165 /* get time of bit */
166 current_jiffies = jiffies;
167 do_gettimeofday(&tv);
168
169 /* avoid overflow with gap >1s */
170 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
171 gap = 200000;
172 } else {
173 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
174 tv.tv_usec - ir->base_time.tv_usec;
175 }
176
177 /* active code => add bit */
178 if (ir->active) {
179 /* only if in the code (otherwise spurious IRQ or timer
180 late) */
181 if (ir->last_bit < 28) {
Hermann Pitton91607232006-12-07 21:45:28 -0300182 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
183 ir_rc5_remote_gap;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800184 ir->code |= 1 << ir->last_bit;
185 }
186 /* starting new code */
187 } else {
188 ir->active = 1;
189 ir->code = 0;
190 ir->base_time = tv;
191 ir->last_bit = 0;
192
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300193 mod_timer(&ir->timer_end,
194 current_jiffies + msecs_to_jiffies(30));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800195 }
196
197 /* toggle GPIO pin 4 to reset the irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200198 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
199 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800200 return 1;
201}
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/* ---------------------------------------------------------------------- */
204
Hermann Pitton91607232006-12-07 21:45:28 -0300205static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300206{
207 if (ir->polling) {
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300208 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
Mauro Carvalho Chehabfe06fe02007-07-17 16:36:20 -0300209 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300210 add_timer(&ir->timer);
211 } else if (ir->rc5_gpio) {
212 /* set timer_end for code completion */
213 init_timer(&ir->timer_end);
Hermann Pitton91607232006-12-07 21:45:28 -0300214 ir->timer_end.function = ir_rc5_timer_end;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300215 ir->timer_end.data = (unsigned long)ir;
216
217 init_timer(&ir->timer_keyup);
Hermann Pitton91607232006-12-07 21:45:28 -0300218 ir->timer_keyup.function = ir_rc5_timer_keyup;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300219 ir->timer_keyup.data = (unsigned long)ir;
Hermann Pitton91607232006-12-07 21:45:28 -0300220 ir->shift_by = 1;
221 ir->start = 3;
222 ir->addr = 0x0;
223 ir->rc5_key_timeout = ir_rc5_key_timeout;
224 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300225 }
226}
227
228static void bttv_ir_stop(struct bttv *btv)
229{
230 if (btv->remote->polling) {
231 del_timer_sync(&btv->remote->timer);
232 flush_scheduled_work();
233 }
234
235 if (btv->remote->rc5_gpio) {
236 u32 gpio;
237
238 del_timer_sync(&btv->remote->timer_end);
239 flush_scheduled_work();
240
241 gpio = bttv_gpio_read(&btv->c);
242 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
243 }
244}
245
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200246int bttv_input_init(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Hermann Pitton91607232006-12-07 21:45:28 -0300248 struct card_ir *ir;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300249 struct ir_scancode_table *ir_codes = NULL;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200250 struct input_dev *input_dev;
Mauro Carvalho Chehab971e8292009-12-14 13:53:37 -0300251 u64 ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300252 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200254 if (!btv->has_remote)
255 return -ENODEV;
256
257 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500258 input_dev = input_allocate_device();
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300259 if (!ir || !input_dev)
260 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /* detect & configure */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200263 switch (btv->c.type) {
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800264 case BTTV_BOARD_AVERMEDIA:
265 case BTTV_BOARD_AVPHONE98:
266 case BTTV_BOARD_AVERMEDIA98:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300267 ir_codes = &ir_codes_avermedia_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 ir->mask_keycode = 0xf88000;
269 ir->mask_keydown = 0x010000;
270 ir->polling = 50; // ms
271 break;
272
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800273 case BTTV_BOARD_AVDVBT_761:
274 case BTTV_BOARD_AVDVBT_771:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300275 ir_codes = &ir_codes_avermedia_dvbt_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 ir->mask_keycode = 0x0f00c0;
277 ir->mask_keydown = 0x000020;
278 ir->polling = 50; // ms
279 break;
280
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800281 case BTTV_BOARD_PXELVWPLTVPAK:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300282 ir_codes = &ir_codes_pixelview_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 ir->mask_keycode = 0x003e00;
284 ir->mask_keyup = 0x010000;
285 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800286 break;
Mauro Carvalho Chehabc6631552006-08-23 11:17:30 -0300287 case BTTV_BOARD_PV_M4900:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800288 case BTTV_BOARD_PV_BT878P_9B:
289 case BTTV_BOARD_PV_BT878P_PLUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300290 ir_codes = &ir_codes_pixelview_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 ir->mask_keycode = 0x001f00;
292 ir->mask_keyup = 0x008000;
293 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800294 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800296 case BTTV_BOARD_WINFAST2000:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300297 ir_codes = &ir_codes_winfast_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ir->mask_keycode = 0x1f8;
299 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800300 case BTTV_BOARD_MAGICTVIEW061:
301 case BTTV_BOARD_MAGICTVIEW063:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300302 ir_codes = &ir_codes_winfast_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 ir->mask_keycode = 0x0008e000;
304 ir->mask_keydown = 0x00200000;
305 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800306 case BTTV_BOARD_APAC_VIEWCOMP:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300307 ir_codes = &ir_codes_apac_viewcomp_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 ir->mask_keycode = 0x001f00;
309 ir->mask_keyup = 0x008000;
310 ir->polling = 50; // ms
311 break;
Mauro Carvalho Chehabed44f662009-08-22 14:43:50 -0300312 case BTTV_BOARD_ASKEY_CPH03X:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800313 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
BoyZonder4ab2b99b2006-02-27 00:08:15 -0300314 case BTTV_BOARD_CONTVFMI:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300315 ir_codes = &ir_codes_pixelview_table;
Ricardo Cerqueiracc9d8d42005-11-08 21:36:20 -0800316 ir->mask_keycode = 0x001F00;
317 ir->mask_keyup = 0x006000;
318 ir->polling = 50; // ms
319 break;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800320 case BTTV_BOARD_NEBULA_DIGITV:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300321 ir_codes = &ir_codes_nebula_table;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200322 btv->custom_irq = bttv_rc5_irq;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800323 ir->rc5_gpio = 1;
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800324 break;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200325 case BTTV_BOARD_MACHTV_MAGICTV:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300326 ir_codes = &ir_codes_apac_viewcomp_table;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200327 ir->mask_keycode = 0x001F00;
328 ir->mask_keyup = 0x004000;
329 ir->polling = 50; /* ms */
330 break;
Mauro Lacye80faad2008-04-22 14:45:58 -0300331 case BTTV_BOARD_KOZUMI_KTV_01C:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300332 ir_codes = &ir_codes_pctv_sedna_table;
Mauro Lacye80faad2008-04-22 14:45:58 -0300333 ir->mask_keycode = 0x001f00;
334 ir->mask_keyup = 0x006000;
335 ir->polling = 50; /* ms */
336 break;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300337 case BTTV_BOARD_ENLTV_FM_2:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300338 ir_codes = &ir_codes_encore_enltv2_table;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300339 ir->mask_keycode = 0x00fd00;
340 ir->mask_keyup = 0x000080;
341 ir->polling = 1; /* ms */
342 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
343 ir->mask_keycode);
344 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346 if (NULL == ir_codes) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300347 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
348 err = -ENODEV;
349 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800352 if (ir->rc5_gpio) {
353 u32 gpio;
Trent Piepho657de3c2006-06-20 00:30:57 -0300354 /* enable remote irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200355 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
356 gpio = bttv_gpio_read(&btv->c);
357 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
358 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800359 } else {
360 /* init hardware-specific stuff */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200361 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 /* init input device */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200365 ir->dev = input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200367 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
368 btv->c.type);
369 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
370 pci_name(btv->c.pci));
371
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300372 err = ir_input_init(input_dev, &ir->ir, ir_type);
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300373 if (err < 0)
374 goto err_out_free;
375
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500376 input_dev->name = ir->name;
377 input_dev->phys = ir->phys;
378 input_dev->id.bustype = BUS_PCI;
379 input_dev->id.version = 1;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200380 if (btv->c.pci->subsystem_vendor) {
381 input_dev->id.vendor = btv->c.pci->subsystem_vendor;
382 input_dev->id.product = btv->c.pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 } else {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200384 input_dev->id.vendor = btv->c.pci->vendor;
385 input_dev->id.product = btv->c.pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300387 input_dev->dev.parent = &btv->c.pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200389 btv->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300390 bttv_ir_start(btv, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* all done */
Mauro Carvalho Chehabe93854d2009-12-14 00:16:55 -0300393 err = ir_input_register(btv->remote->dev, ir_codes, NULL);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300394 if (err)
395 goto err_out_stop;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800396
397 /* the remote isn't as bouncy as a keyboard */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200398 ir->dev->rep[REP_DELAY] = repeat_delay;
399 ir->dev->rep[REP_PERIOD] = repeat_period;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300402
403 err_out_stop:
404 bttv_ir_stop(btv);
405 btv->remote = NULL;
406 err_out_free:
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300407 kfree(ir);
408 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200411void bttv_input_fini(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200413 if (btv->remote == NULL)
414 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300416 bttv_ir_stop(btv);
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -0300417 ir_input_unregister(btv->remote->dev);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200418 kfree(btv->remote);
419 btv->remote = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423/*
424 * Local variables:
425 * c-basic-offset: 8
426 * End:
427 */