blob: 69efa0e5174d58ffb113d97479f8b82180490b65 [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>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/interrupt.h>
26#include <linux/input.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
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int debug;
33module_param(debug, int, 0644); /* debug level (0,1,2) */
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
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020039#define DEVNAME "bttv-input"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* ---------------------------------------------------------------------- */
42
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020043static void ir_handle_key(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020045 struct bttv_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 u32 gpio,data;
47
48 /* read gpio value */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020049 gpio = bttv_gpio_read(&btv->c);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 if (ir->polling) {
51 if (ir->last_gpio == gpio)
52 return;
53 ir->last_gpio = gpio;
54 }
55
56 /* extract data */
57 data = ir_extract_bits(gpio, ir->mask_keycode);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020058 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 gpio, data,
60 ir->polling ? "poll" : "irq",
61 (gpio & ir->mask_keydown) ? " down" : "",
62 (gpio & ir->mask_keyup) ? " up" : "");
63
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020064 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
65 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
66 ir_input_keydown(ir->dev,&ir->ir,data,data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 } else {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020068 ir_input_nokey(ir->dev,&ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020073void bttv_input_irq(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020075 struct bttv_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 if (!ir->polling)
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020078 ir_handle_key(btv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020081static void bttv_input_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020083 struct bttv *btv = (struct bttv*)data;
84 struct bttv_ir *ir = btv->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned long timeout;
86
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -020087 ir_handle_key(btv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 timeout = jiffies + (ir->polling * HZ / 1000);
89 mod_timer(&ir->timer, timeout);
90}
91
Mark Weaver6c6c0b22005-11-13 16:07:52 -080092/* ---------------------------------------------------------------*/
93
94static int rc5_remote_gap = 885;
95module_param(rc5_remote_gap, int, 0644);
96static int rc5_key_timeout = 200;
97module_param(rc5_key_timeout, int, 0644);
98
99#define RC5_START(x) (((x)>>12)&3)
100#define RC5_TOGGLE(x) (((x)>>11)&1)
101#define RC5_ADDR(x) (((x)>>6)&31)
102#define RC5_INSTR(x) ((x)&63)
103
104/* decode raw bit pattern to RC5 code */
105static u32 rc5_decode(unsigned int code)
106{
107 unsigned int org_code = code;
108 unsigned int pair;
109 unsigned int rc5 = 0;
110 int i;
111
112 code = (code << 1) | 1;
113 for (i = 0; i < 14; ++i) {
114 pair = code & 0x3;
115 code >>= 2;
116
117 rc5 <<= 1;
118 switch (pair) {
119 case 0:
120 case 2:
121 break;
122 case 1:
123 rc5 |= 1;
124 break;
125 case 3:
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200126 dprintk(KERN_WARNING "bad code: %x\n", org_code);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800127 return 0;
128 }
129 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200130 dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800131 "instr=%x\n", rc5, org_code, RC5_START(rc5),
132 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
133 return rc5;
134}
135
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200136static int bttv_rc5_irq(struct bttv *btv)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800137{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200138 struct bttv_ir *ir = btv->remote;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800139 struct timeval tv;
140 u32 gpio;
141 u32 gap;
142 unsigned long current_jiffies, timeout;
143
144 /* read gpio port */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200145 gpio = bttv_gpio_read(&btv->c);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800146
147 /* remote IRQ? */
148 if (!(gpio & 0x20))
149 return 0;
150
151 /* get time of bit */
152 current_jiffies = jiffies;
153 do_gettimeofday(&tv);
154
155 /* avoid overflow with gap >1s */
156 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
157 gap = 200000;
158 } else {
159 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
160 tv.tv_usec - ir->base_time.tv_usec;
161 }
162
163 /* active code => add bit */
164 if (ir->active) {
165 /* only if in the code (otherwise spurious IRQ or timer
166 late) */
167 if (ir->last_bit < 28) {
168 ir->last_bit = (gap - rc5_remote_gap / 2) /
169 rc5_remote_gap;
170 ir->code |= 1 << ir->last_bit;
171 }
172 /* starting new code */
173 } else {
174 ir->active = 1;
175 ir->code = 0;
176 ir->base_time = tv;
177 ir->last_bit = 0;
178
179 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
180 mod_timer(&ir->timer_end, timeout);
181 }
182
183 /* toggle GPIO pin 4 to reset the irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200184 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
185 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800186 return 1;
187}
188
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200189
190static void bttv_rc5_timer_end(unsigned long data)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800191{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200192 struct bttv_ir *ir = (struct bttv_ir *)data;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800193 struct timeval tv;
194 unsigned long current_jiffies, timeout;
195 u32 gap;
196
197 /* get time */
198 current_jiffies = jiffies;
199 do_gettimeofday(&tv);
200
201 /* avoid overflow with gap >1s */
202 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
203 gap = 200000;
204 } else {
205 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
206 tv.tv_usec - ir->base_time.tv_usec;
207 }
208
209 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
210 if (gap < 28000) {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200211 dprintk(KERN_WARNING "spurious timer_end\n");
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800212 return;
213 }
214
215 ir->active = 0;
216 if (ir->last_bit < 20) {
217 /* ignore spurious codes (caused by light/other remotes) */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200218 dprintk(KERN_WARNING "short code: %x\n", ir->code);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800219 } else {
220 u32 rc5 = rc5_decode(ir->code);
221
222 /* two start bits? */
223 if (RC5_START(rc5) != 3) {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200224 dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800225
226 /* right address? */
227 } else if (RC5_ADDR(rc5) == 0x0) {
228 u32 toggle = RC5_TOGGLE(rc5);
229 u32 instr = RC5_INSTR(rc5);
230
231 /* Good code, decide if repeat/repress */
232 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
233 instr != RC5_INSTR(ir->last_rc5)) {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200234 dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr,
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800235 toggle);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200236 ir_input_nokey(ir->dev, &ir->ir);
237 ir_input_keydown(ir->dev, &ir->ir, instr,
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800238 instr);
239 }
240
241 /* Set/reset key-up timer */
242 timeout = current_jiffies + (500 + rc5_key_timeout
243 * HZ) / 1000;
244 mod_timer(&ir->timer_keyup, timeout);
245
246 /* Save code for repeat test */
247 ir->last_rc5 = rc5;
248 }
249 }
250}
251
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200252static void bttv_rc5_timer_keyup(unsigned long data)
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800253{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200254 struct bttv_ir *ir = (struct bttv_ir *)data;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800255
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200256 dprintk(KERN_DEBUG "key released\n");
257 ir_input_nokey(ir->dev, &ir->ir);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800258}
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/* ---------------------------------------------------------------------- */
261
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200262int bttv_input_init(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200264 struct bttv_ir *ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 IR_KEYTAB_TYPE *ir_codes = NULL;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200266 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 int ir_type = IR_TYPE_OTHER;
268
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200269 if (!btv->has_remote)
270 return -ENODEV;
271
272 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500273 input_dev = input_allocate_device();
274 if (!ir || !input_dev) {
275 kfree(ir);
276 input_free_device(input_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 return -ENOMEM;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500278 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200279 memset(ir,0,sizeof(*ir));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 /* detect & configure */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200282 switch (btv->c.type) {
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800283 case BTTV_BOARD_AVERMEDIA:
284 case BTTV_BOARD_AVPHONE98:
285 case BTTV_BOARD_AVERMEDIA98:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 ir_codes = ir_codes_avermedia;
287 ir->mask_keycode = 0xf88000;
288 ir->mask_keydown = 0x010000;
289 ir->polling = 50; // ms
290 break;
291
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800292 case BTTV_BOARD_AVDVBT_761:
293 case BTTV_BOARD_AVDVBT_771:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 ir_codes = ir_codes_avermedia_dvbt;
295 ir->mask_keycode = 0x0f00c0;
296 ir->mask_keydown = 0x000020;
297 ir->polling = 50; // ms
298 break;
299
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800300 case BTTV_BOARD_PXELVWPLTVPAK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 ir_codes = ir_codes_pixelview;
302 ir->mask_keycode = 0x003e00;
303 ir->mask_keyup = 0x010000;
304 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800305 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800306 case BTTV_BOARD_PV_BT878P_9B:
307 case BTTV_BOARD_PV_BT878P_PLUS:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 ir_codes = ir_codes_pixelview;
309 ir->mask_keycode = 0x001f00;
310 ir->mask_keyup = 0x008000;
311 ir->polling = 50; // ms
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800312 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800314 case BTTV_BOARD_WINFAST2000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 ir_codes = ir_codes_winfast;
316 ir->mask_keycode = 0x1f8;
317 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800318 case BTTV_BOARD_MAGICTVIEW061:
319 case BTTV_BOARD_MAGICTVIEW063:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 ir_codes = ir_codes_winfast;
321 ir->mask_keycode = 0x0008e000;
322 ir->mask_keydown = 0x00200000;
323 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800324 case BTTV_BOARD_APAC_VIEWCOMP:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 ir_codes = ir_codes_apac_viewcomp;
326 ir->mask_keycode = 0x001f00;
327 ir->mask_keyup = 0x008000;
328 ir->polling = 50; // ms
329 break;
Mauro Carvalho Chehab5a25e842005-11-08 21:36:52 -0800330 case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
BoyZonder4ab2b992006-02-27 00:08:15 -0300331 case BTTV_BOARD_CONTVFMI:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200332 ir_codes = ir_codes_pixelview;
Ricardo Cerqueiracc9d8d42005-11-08 21:36:20 -0800333 ir->mask_keycode = 0x001F00;
334 ir->mask_keyup = 0x006000;
335 ir->polling = 50; // ms
336 break;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800337 case BTTV_BOARD_NEBULA_DIGITV:
338 ir_codes = ir_codes_nebula;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200339 btv->custom_irq = bttv_rc5_irq;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800340 ir->rc5_gpio = 1;
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800341 break;
Julian Calaby2d05ae62006-01-11 19:40:09 -0200342 case BTTV_BOARD_MACHTV_MAGICTV:
343 ir_codes = ir_codes_apac_viewcomp;
344 ir->mask_keycode = 0x001F00;
345 ir->mask_keyup = 0x004000;
346 ir->polling = 50; /* ms */
347 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349 if (NULL == ir_codes) {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200350 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 kfree(ir);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500352 input_free_device(input_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return -ENODEV;
354 }
355
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800356 if (ir->rc5_gpio) {
357 u32 gpio;
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800358 /* enable remote irq */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200359 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
360 gpio = bttv_gpio_read(&btv->c);
361 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
362 bttv_gpio_write(&btv->c, gpio | (1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800363 } else {
364 /* init hardware-specific stuff */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200365 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 /* init input device */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200369 ir->dev = input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200371 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
372 btv->c.type);
373 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
374 pci_name(btv->c.pci));
375
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500376 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
377 input_dev->name = ir->name;
378 input_dev->phys = ir->phys;
379 input_dev->id.bustype = BUS_PCI;
380 input_dev->id.version = 1;
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200381 if (btv->c.pci->subsystem_vendor) {
382 input_dev->id.vendor = btv->c.pci->subsystem_vendor;
383 input_dev->id.product = btv->c.pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 } else {
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200385 input_dev->id.vendor = btv->c.pci->vendor;
386 input_dev->id.product = btv->c.pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200388 input_dev->cdev.dev = &btv->c.pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200390 btv->remote = ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (ir->polling) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 init_timer(&ir->timer);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200393 ir->timer.function = bttv_input_timer;
394 ir->timer.data = (unsigned long)btv;
395 ir->timer.expires = jiffies + HZ;
396 add_timer(&ir->timer);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800397 } else if (ir->rc5_gpio) {
398 /* set timer_end for code completion */
399 init_timer(&ir->timer_end);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200400 ir->timer_end.function = bttv_rc5_timer_end;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800401 ir->timer_end.data = (unsigned long)ir;
402
403 init_timer(&ir->timer_keyup);
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200404 ir->timer_keyup.function = bttv_rc5_timer_keyup;
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800405 ir->timer_keyup.data = (unsigned long)ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
408 /* all done */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200409 input_register_device(btv->remote->dev);
Mauro Carvalho Chehab7e578192006-01-09 15:25:27 -0200410 printk(DEVNAME ": %s detected at %s\n",ir->name,ir->phys);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800411
412 /* the remote isn't as bouncy as a keyboard */
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200413 ir->dev->rep[REP_DELAY] = repeat_delay;
414 ir->dev->rep[REP_PERIOD] = repeat_period;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
416 return 0;
417}
418
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200419void bttv_input_fini(struct bttv *btv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200421 if (btv->remote == NULL)
422 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200424 if (btv->remote->polling) {
425 del_timer_sync(&btv->remote->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 flush_scheduled_work();
427 }
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -0800428
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200429
430 if (btv->remote->rc5_gpio) {
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800431 u32 gpio;
432
Andrew Mortonbc61b012006-01-09 15:25:28 -0200433 del_timer_sync(&btv->remote->timer_end);
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800434 flush_scheduled_work();
435
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200436 gpio = bttv_gpio_read(&btv->c);
437 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
Mark Weaver6c6c0b22005-11-13 16:07:52 -0800438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Ricardo Cerqueira4abdfed2006-01-09 15:25:25 -0200440 input_unregister_device(btv->remote->dev);
441 kfree(btv->remote);
442 btv->remote = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446/*
447 * Local variables:
448 * c-basic-offset: 8
449 * End:
450 */