blob: 6bf05a7dc5f9f36c348e851104450e4d2a739368 [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
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030052#define MODULE_NAME "bttv"
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/* ---------------------------------------------------------------------- */
55
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020056static void ir_handle_key(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Hermann Pitton91607232006-12-07 21:45:28 -030058 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 u32 gpio,data;
60
61 /* read gpio value */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020062 gpio = bttv_gpio_read(&btv->c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 if (ir->polling) {
64 if (ir->last_gpio == gpio)
65 return;
66 ir->last_gpio = gpio;
67 }
68
69 /* extract data */
70 data = ir_extract_bits(gpio, ir->mask_keycode);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020071 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 gpio, data,
73 ir->polling ? "poll" : "irq",
74 (gpio & ir->mask_keydown) ? " down" : "",
75 (gpio & ir->mask_keyup) ? " up" : "");
76
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020077 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
78 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -030079 ir_input_keydown(ir->dev, &ir->ir, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 } else {
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030081 /* HACK: Probably, ir->mask_keydown is missing
82 for this board */
83 if (btv->c.type == BTTV_BOARD_WINFAST2000)
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -030084 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehabb3d98132008-01-07 09:30:31 -030085
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020086 ir_input_nokey(ir->dev,&ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -030091static void ir_enltv_handle_key(struct bttv *btv)
92{
93 struct card_ir *ir = btv->remote;
94 u32 gpio, data, keyup;
95
96 /* read gpio value */
97 gpio = bttv_gpio_read(&btv->c);
98
99 /* extract data */
100 data = ir_extract_bits(gpio, ir->mask_keycode);
101
102 /* Check if it is keyup */
103 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
104
105 if ((ir->last_gpio & 0x7f) != data) {
106 dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
107 gpio, data,
108 (gpio & ir->mask_keyup) ? " up" : "up/down");
109
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300110 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300111 if (keyup)
112 ir_input_nokey(ir->dev, &ir->ir);
113 } else {
114 if ((ir->last_gpio & 1 << 31) == keyup)
115 return;
116
117 dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
118 gpio, data,
119 (gpio & ir->mask_keyup) ? " up" : "down");
120
121 if (keyup)
122 ir_input_nokey(ir->dev, &ir->ir);
123 else
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300124 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300125 }
126
127 ir->last_gpio = data | keyup;
128}
129
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200130void bttv_input_irq(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Hermann Pitton91607232006-12-07 21:45:28 -0300132 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 if (!ir->polling)
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200135 ir_handle_key(btv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200138static void bttv_input_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200140 struct bttv *btv = (struct bttv*)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300141 struct card_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300143 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
144 ir_enltv_handle_key(btv);
145 else
146 ir_handle_key(btv);
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300147 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800150/* ---------------------------------------------------------------*/
151
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200152static int bttv_rc5_irq(struct bttv *btv)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800153{
Hermann Pitton91607232006-12-07 21:45:28 -0300154 struct card_ir *ir = btv->remote;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800155 struct timeval tv;
156 u32 gpio;
157 u32 gap;
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300158 unsigned long current_jiffies;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800159
160 /* read gpio port */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200161 gpio = bttv_gpio_read(&btv->c);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800162
163 /* remote IRQ? */
164 if (!(gpio & 0x20))
165 return 0;
166
167 /* get time of bit */
168 current_jiffies = jiffies;
169 do_gettimeofday(&tv);
170
171 /* avoid overflow with gap >1s */
172 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
173 gap = 200000;
174 } else {
175 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
176 tv.tv_usec - ir->base_time.tv_usec;
177 }
178
179 /* active code => add bit */
180 if (ir->active) {
181 /* only if in the code (otherwise spurious IRQ or timer
182 late) */
183 if (ir->last_bit < 28) {
Hermann Pitton91607232006-12-07 21:45:28 -0300184 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
185 ir_rc5_remote_gap;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800186 ir->code |= 1 << ir->last_bit;
187 }
188 /* starting new code */
189 } else {
190 ir->active = 1;
191 ir->code = 0;
192 ir->base_time = tv;
193 ir->last_bit = 0;
194
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300195 mod_timer(&ir->timer_end,
196 current_jiffies + msecs_to_jiffies(30));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800197 }
198
199 /* toggle GPIO pin 4 to reset the irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200200 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
201 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800202 return 1;
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/* ---------------------------------------------------------------------- */
206
Hermann Pitton91607232006-12-07 21:45:28 -0300207static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300208{
209 if (ir->polling) {
Dmitry Torokhovc1904952007-01-02 03:29:48 -0300210 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
Mauro Carvalho Chehabfe06fe02007-07-17 16:36:20 -0300211 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300212 add_timer(&ir->timer);
213 } else if (ir->rc5_gpio) {
214 /* set timer_end for code completion */
215 init_timer(&ir->timer_end);
Hermann Pitton91607232006-12-07 21:45:28 -0300216 ir->timer_end.function = ir_rc5_timer_end;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300217 ir->timer_end.data = (unsigned long)ir;
218
219 init_timer(&ir->timer_keyup);
Hermann Pitton91607232006-12-07 21:45:28 -0300220 ir->timer_keyup.function = ir_rc5_timer_keyup;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300221 ir->timer_keyup.data = (unsigned long)ir;
Hermann Pitton91607232006-12-07 21:45:28 -0300222 ir->shift_by = 1;
223 ir->start = 3;
224 ir->addr = 0x0;
225 ir->rc5_key_timeout = ir_rc5_key_timeout;
226 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300227 }
228}
229
230static void bttv_ir_stop(struct bttv *btv)
231{
232 if (btv->remote->polling) {
233 del_timer_sync(&btv->remote->timer);
234 flush_scheduled_work();
235 }
236
237 if (btv->remote->rc5_gpio) {
238 u32 gpio;
239
240 del_timer_sync(&btv->remote->timer_end);
241 flush_scheduled_work();
242
243 gpio = bttv_gpio_read(&btv->c);
244 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
245 }
246}
247
Mauro Carvalho Chehabc0c46822010-09-22 23:24:04 -0300248/*
249 * Get_key functions used by I2C remotes
250 */
251
252static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
253{
254 unsigned char b;
255
256 /* poll IR chip */
257 if (1 != i2c_master_recv(ir->c, &b, 1)) {
258 dprintk(KERN_INFO DEVNAME ": read error\n");
259 return -EIO;
260 }
261
262 /* ignore 0xaa */
263 if (b==0xaa)
264 return 0;
265 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
266
267 *ir_key = b;
268 *ir_raw = b;
269 return 1;
270}
271
272/* Instantiate the I2C IR receiver device, if present */
273void __devinit init_bttv_i2c_ir(struct bttv *btv)
274{
275 const unsigned short addr_list[] = {
276 0x1a, 0x18, 0x64, 0x30, 0x71,
277 I2C_CLIENT_END
278 };
279 struct i2c_board_info info;
280
281 if (0 != btv->i2c_rc)
282 return;
283
284 memset(&info, 0, sizeof(struct i2c_board_info));
285 memset(&btv->init_data, 0, sizeof(btv->init_data));
286 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
287
288 switch (btv->c.type) {
289 case BTTV_BOARD_PV951:
290 btv->init_data.name = "PV951";
291 btv->init_data.get_key = get_key_pv951;
292 btv->init_data.ir_codes = RC_MAP_PV951;
293 btv->init_data.type = IR_TYPE_OTHER;
294 info.addr = 0x4b;
295 break;
296 default:
297 /*
298 * The external IR receiver is at i2c address 0x34 (0x35 for
299 * reads). Future Hauppauge cards will have an internal
300 * receiver at 0x30 (0x31 for reads). In theory, both can be
301 * fitted, and Hauppauge suggest an external overrides an
302 * internal.
303 * That's why we probe 0x1a (~0x34) first. CB
304 */
305
306 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
307 return;
308 }
309
310 if (btv->init_data.name)
311 info.platform_data = &btv->init_data;
312 i2c_new_device(&btv->c.i2c_adap, &info);
313
314 return;
315}
316
317int __devexit fini_bttv_i2c(struct bttv *btv)
318{
319 if (0 != btv->i2c_rc)
320 return 0;
321
322 return i2c_del_adapter(&btv->c.i2c_adap);
323}
324
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200325int bttv_input_init(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Hermann Pitton91607232006-12-07 21:45:28 -0300327 struct card_ir *ir;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300328 char *ir_codes = NULL;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200329 struct input_dev *input_dev;
Mauro Carvalho Chehab971e8292009-12-14 13:53:37 -0300330 u64 ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300331 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200333 if (!btv->has_remote)
334 return -ENODEV;
335
336 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500337 input_dev = input_allocate_device();
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300338 if (!ir || !input_dev)
339 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* detect & configure */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200342 switch (btv->c.type) {
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800343 case BTTV_BOARD_AVERMEDIA:
344 case BTTV_BOARD_AVPHONE98:
345 case BTTV_BOARD_AVERMEDIA98:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300346 ir_codes = RC_MAP_AVERMEDIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 ir->mask_keycode = 0xf88000;
348 ir->mask_keydown = 0x010000;
349 ir->polling = 50; // ms
350 break;
351
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800352 case BTTV_BOARD_AVDVBT_761:
353 case BTTV_BOARD_AVDVBT_771:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300354 ir_codes = RC_MAP_AVERMEDIA_DVBT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 ir->mask_keycode = 0x0f00c0;
356 ir->mask_keydown = 0x000020;
357 ir->polling = 50; // ms
358 break;
359
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800360 case BTTV_BOARD_PXELVWPLTVPAK:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300361 ir_codes = RC_MAP_PIXELVIEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 ir->mask_keycode = 0x003e00;
363 ir->mask_keyup = 0x010000;
364 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800365 break;
Mauro Carvalho Chehabc6631552006-08-23 11:17:30 -0300366 case BTTV_BOARD_PV_M4900:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800367 case BTTV_BOARD_PV_BT878P_9B:
368 case BTTV_BOARD_PV_BT878P_PLUS:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300369 ir_codes = RC_MAP_PIXELVIEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 ir->mask_keycode = 0x001f00;
371 ir->mask_keyup = 0x008000;
372 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800375 case BTTV_BOARD_WINFAST2000:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300376 ir_codes = RC_MAP_WINFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 ir->mask_keycode = 0x1f8;
378 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800379 case BTTV_BOARD_MAGICTVIEW061:
380 case BTTV_BOARD_MAGICTVIEW063:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300381 ir_codes = RC_MAP_WINFAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 ir->mask_keycode = 0x0008e000;
383 ir->mask_keydown = 0x00200000;
384 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800385 case BTTV_BOARD_APAC_VIEWCOMP:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300386 ir_codes = RC_MAP_APAC_VIEWCOMP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 ir->mask_keycode = 0x001f00;
388 ir->mask_keyup = 0x008000;
389 ir->polling = 50; // ms
390 break;
Mauro Carvalho Chehabed44f662009-08-22 14:43:50 -0300391 case BTTV_BOARD_ASKEY_CPH03X:
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800392 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
BoyZonder4ab2b99b2006-02-27 00:08:15 -0300393 case BTTV_BOARD_CONTVFMI:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300394 ir_codes = RC_MAP_PIXELVIEW;
Ricardo Cerqueiracc9d8d42005-11-08 21:36:20 -0800395 ir->mask_keycode = 0x001F00;
396 ir->mask_keyup = 0x006000;
397 ir->polling = 50; // ms
398 break;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800399 case BTTV_BOARD_NEBULA_DIGITV:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300400 ir_codes = RC_MAP_NEBULA;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200401 btv->custom_irq = bttv_rc5_irq;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800402 ir->rc5_gpio = 1;
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800403 break;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200404 case BTTV_BOARD_MACHTV_MAGICTV:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300405 ir_codes = RC_MAP_APAC_VIEWCOMP;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200406 ir->mask_keycode = 0x001F00;
407 ir->mask_keyup = 0x004000;
408 ir->polling = 50; /* ms */
409 break;
Mauro Lacye80faad2008-04-22 14:45:58 -0300410 case BTTV_BOARD_KOZUMI_KTV_01C:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300411 ir_codes = RC_MAP_PCTV_SEDNA;
Mauro Lacye80faad2008-04-22 14:45:58 -0300412 ir->mask_keycode = 0x001f00;
413 ir->mask_keyup = 0x006000;
414 ir->polling = 50; /* ms */
415 break;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300416 case BTTV_BOARD_ENLTV_FM_2:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300417 ir_codes = RC_MAP_ENCORE_ENLTV2;
Mauro Carvalho Chehab7d341a62008-08-05 10:14:13 -0300418 ir->mask_keycode = 0x00fd00;
419 ir->mask_keyup = 0x000080;
420 ir->polling = 1; /* ms */
421 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
422 ir->mask_keycode);
423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425 if (NULL == ir_codes) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300426 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
427 err = -ENODEV;
428 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800431 if (ir->rc5_gpio) {
432 u32 gpio;
Trent Piepho657de3c2006-06-20 00:30:57 -0300433 /* enable remote irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200434 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
435 gpio = bttv_gpio_read(&btv->c);
436 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
437 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800438 } else {
439 /* init hardware-specific stuff */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200440 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 /* init input device */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200444 ir->dev = input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200446 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
447 btv->c.type);
448 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
449 pci_name(btv->c.pci));
450
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300451 err = ir_input_init(input_dev, &ir->ir, ir_type);
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300452 if (err < 0)
453 goto err_out_free;
454
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500455 input_dev->name = ir->name;
456 input_dev->phys = ir->phys;
457 input_dev->id.bustype = BUS_PCI;
458 input_dev->id.version = 1;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200459 if (btv->c.pci->subsystem_vendor) {
460 input_dev->id.vendor = btv->c.pci->subsystem_vendor;
461 input_dev->id.product = btv->c.pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 } else {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200463 input_dev->id.vendor = btv->c.pci->vendor;
464 input_dev->id.product = btv->c.pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300466 input_dev->dev.parent = &btv->c.pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200468 btv->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300469 bttv_ir_start(btv, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 /* all done */
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300472 err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300473 if (err)
474 goto err_out_stop;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800475
476 /* the remote isn't as bouncy as a keyboard */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200477 ir->dev->rep[REP_DELAY] = repeat_delay;
478 ir->dev->rep[REP_PERIOD] = repeat_period;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300481
482 err_out_stop:
483 bttv_ir_stop(btv);
484 btv->remote = NULL;
485 err_out_free:
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300486 kfree(ir);
487 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200490void bttv_input_fini(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200492 if (btv->remote == NULL)
493 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300495 bttv_ir_stop(btv);
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -0300496 ir_input_unregister(btv->remote->dev);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200497 kfree(btv->remote);
498 btv->remote = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}