blob: 46c583f1e78813da272216a3ceeffd41892d9c7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * handle saa7134 IR remotes via linux kernel input layer.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/interrupt.h>
26#include <linux/input.h>
27
28#include "saa7134-reg.h"
29#include "saa7134.h"
30
31static unsigned int disable_ir = 0;
32module_param(disable_ir, int, 0444);
33MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
34
35static unsigned int ir_debug = 0;
36module_param(ir_debug, int, 0644);
37MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
38
Sylvain Pascheb93eedb2006-03-25 23:14:42 -030039static int pinnacle_remote = 0;
40module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
41MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
42
Adrian Bunkc408a6f2006-12-28 12:47:47 -030043static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030044module_param(ir_rc5_remote_gap, int, 0644);
Adrian Bunkc408a6f2006-12-28 12:47:47 -030045static int ir_rc5_key_timeout = 115;
Hermann Pitton91607232006-12-07 21:45:28 -030046module_param(ir_rc5_key_timeout, int, 0644);
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define dprintk(fmt, arg...) if (ir_debug) \
49 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080050#define i2cdprintk(fmt, arg...) if (ir_debug) \
51 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Hermann Pitton91607232006-12-07 21:45:28 -030053/** rc5 functions */
54static int saa7134_rc5_irq(struct saa7134_dev *dev);
55
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080056/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static int build_key(struct saa7134_dev *dev)
59{
Hermann Pitton91607232006-12-07 21:45:28 -030060 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 u32 gpio, data;
62
63 /* rising SAA7134_GPIO_GPRESCAN reads the status */
64 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
65 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
66
67 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080068 if (ir->polling) {
69 if (ir->last_gpio == gpio)
70 return 0;
71 ir->last_gpio = gpio;
72 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080074 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
76 gpio, ir->mask_keycode, data);
77
Peter Missel0602fbb2006-01-09 18:21:23 -020078 if (ir->polling) {
79 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
80 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
81 ir_input_keydown(ir->dev, &ir->ir, data, data);
82 } else {
83 ir_input_nokey(ir->dev, &ir->ir);
84 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
Peter Missel0602fbb2006-01-09 18:21:23 -020086 else { /* IRQ driven mode - handle key press and release in one go */
87 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
88 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
89 ir_input_keydown(ir->dev, &ir->ir, data, data);
90 ir_input_nokey(ir->dev, &ir->ir);
91 }
92 }
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return 0;
95}
96
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080097/* --------------------- Chip specific I2C key builders ----------------- */
98
99static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
100{
101 unsigned char b;
102
103 /* poll IR chip */
104 if (1 != i2c_master_recv(&ir->c,&b,1)) {
105 i2cdprintk("read error\n");
106 return -EIO;
107 }
108
109 /* no button press */
110 if (b==0)
111 return 0;
112
113 /* repeating */
114 if (b & 0x80)
115 return 1;
116
117 *ir_key = b;
118 *ir_raw = b;
119 return 1;
120}
121
Thomas Genty177aaaf2006-11-29 21:57:24 -0300122static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
123{
124 unsigned char buf[5], cod4, code3, code4;
125
126 /* poll IR chip */
127 if (5 != i2c_master_recv(&ir->c,buf,5))
128 return -EIO;
129
130 cod4 = buf[4];
131 code4 = (cod4 >> 2);
132 code3 = buf[3];
133 if (code3 == 0)
134 /* no key pressed */
135 return 0;
136
137 /* return key */
138 *ir_key = code4;
139 *ir_raw = code4;
140 return 1;
141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143void saa7134_input_irq(struct saa7134_dev *dev)
144{
Hermann Pitton91607232006-12-07 21:45:28 -0300145 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Hermann Pitton91607232006-12-07 21:45:28 -0300147 if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300149 } else if (ir->rc5_gpio) {
150 saa7134_rc5_irq(dev);
151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static void saa7134_input_timer(unsigned long data)
155{
156 struct saa7134_dev *dev = (struct saa7134_dev*)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300157 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned long timeout;
159
160 build_key(dev);
161 timeout = jiffies + (ir->polling * HZ / 1000);
162 mod_timer(&ir->timer, timeout);
163}
164
Hermann Pitton91607232006-12-07 21:45:28 -0300165static void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300166{
167 if (ir->polling) {
168 init_timer(&ir->timer);
169 ir->timer.function = saa7134_input_timer;
170 ir->timer.data = (unsigned long)dev;
171 ir->timer.expires = jiffies + HZ;
172 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300173 } else if (ir->rc5_gpio) {
174 /* set timer_end for code completion */
175 init_timer(&ir->timer_end);
176 ir->timer_end.function = ir_rc5_timer_end;
177 ir->timer_end.data = (unsigned long)ir;
178 init_timer(&ir->timer_keyup);
179 ir->timer_keyup.function = ir_rc5_timer_keyup;
180 ir->timer_keyup.data = (unsigned long)ir;
181 ir->shift_by = 2;
182 ir->start = 0x2;
183 ir->addr = 0x17;
184 ir->rc5_key_timeout = ir_rc5_key_timeout;
185 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300186 }
187}
188
189static void saa7134_ir_stop(struct saa7134_dev *dev)
190{
191 if (dev->remote->polling)
192 del_timer_sync(&dev->remote->timer);
193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195int saa7134_input_init1(struct saa7134_dev *dev)
196{
Hermann Pitton91607232006-12-07 21:45:28 -0300197 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500198 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 IR_KEYTAB_TYPE *ir_codes = NULL;
200 u32 mask_keycode = 0;
201 u32 mask_keydown = 0;
202 u32 mask_keyup = 0;
203 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300204 int rc5_gpio = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 int ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300206 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800208 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return -ENODEV;
210 if (disable_ir)
211 return -ENODEV;
212
213 /* detect & configure */
214 switch (dev->board) {
215 case SAA7134_BOARD_FLYVIDEO2000:
216 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800217 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800218 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200219 ir_codes = ir_codes_flyvideo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 mask_keycode = 0xEC00000;
221 mask_keydown = 0x0040000;
222 break;
223 case SAA7134_BOARD_CINERGY400:
224 case SAA7134_BOARD_CINERGY600:
225 case SAA7134_BOARD_CINERGY600_MK3:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200226 ir_codes = ir_codes_cinergy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 mask_keycode = 0x00003f;
228 mask_keyup = 0x040000;
229 break;
230 case SAA7134_BOARD_ECS_TVP3XP:
231 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200232 ir_codes = ir_codes_eztv;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700233 mask_keycode = 0x00017c;
234 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700236 break;
237 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 case SAA7134_BOARD_AVACSSMARTTV:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200239 ir_codes = ir_codes_pixelview;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 mask_keycode = 0x00001F;
241 mask_keyup = 0x000020;
242 polling = 50; // ms
243 break;
244 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700245 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 case SAA7134_BOARD_AVERMEDIA_305:
247 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700248 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
249 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300250 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700251 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200252 ir_codes = ir_codes_avermedia;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 mask_keycode = 0x0007C8;
254 mask_keydown = 0x000010;
255 polling = 50; // ms
256 /* Set GPIO pin2 to high to enable the IR controller */
257 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
258 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
259 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300260 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300261 case SAA7134_BOARD_AVERMEDIA_A16AR:
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300262 ir_codes = ir_codes_avermedia;
263 mask_keycode = 0x02F200;
264 mask_keydown = 0x000400;
265 polling = 50; // ms
266 /* Without this we won't receive key up events */
267 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
268 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800269 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800270 case SAA7134_BOARD_KWORLD_TERMINATOR:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200271 ir_codes = ir_codes_pixelview;
James R. Webbdc2286c2005-11-08 21:37:00 -0800272 mask_keycode = 0x00001f;
273 mask_keyup = 0x000060;
274 polling = 50; // ms
275 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700276 case SAA7134_BOARD_MANLI_MTV001:
277 case SAA7134_BOARD_MANLI_MTV002:
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800278 case SAA7134_BOARD_BEHOLD_409FM:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200279 ir_codes = ir_codes_manli;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700280 mask_keycode = 0x001f00;
281 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700282 polling = 50; // ms
283 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800284 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200285 ir_codes = ir_codes_pctv_sedna;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800286 mask_keycode = 0x001f00;
287 mask_keyup = 0x004000;
288 polling = 50; // ms
289 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800290 case SAA7134_BOARD_GOTVIEW_7135:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200291 ir_codes = ir_codes_gotview7135;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800292 mask_keycode = 0x0003EC;
293 mask_keyup = 0x008000;
294 mask_keydown = 0x000010;
295 polling = 50; // ms
296 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200298 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700299 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200300 ir_codes = ir_codes_videomate_tv_pvr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 mask_keycode = 0x00003F;
302 mask_keyup = 0x400000;
303 polling = 50; // ms
304 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300305 case SAA7134_BOARD_PROTEUS_2309:
306 ir_codes = ir_codes_proteus_2309;
307 mask_keycode = 0x00007F;
308 mask_keyup = 0x000080;
309 polling = 50; // ms
310 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800311 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
312 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200313 ir_codes = ir_codes_videomate_tv_pvr;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800314 mask_keycode = 0x003F00;
315 mask_keyup = 0x040000;
316 break;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200317 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300318 case SAA7134_BOARD_FLYDVBTDUO:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200319 ir_codes = ir_codes_flydvb;
320 mask_keycode = 0x0001F00;
321 mask_keydown = 0x0040000;
322 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300323 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
324 ir_codes = ir_codes_asus_pc39;
325 mask_keydown = 0x0040000;
326 rc5_gpio = 1;
327 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300328 case SAA7134_BOARD_ENCORE_ENLTV:
329 case SAA7134_BOARD_ENCORE_ENLTV_FM:
330 ir_codes = ir_codes_encore_enltv;
331 mask_keycode = 0x00007f;
332 mask_keyup = 0x040000;
333 polling = 50; // ms
334 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336 if (NULL == ir_codes) {
337 printk("%s: Oops: IR config error [card=%d]\n",
338 dev->name, dev->board);
339 return -ENODEV;
340 }
341
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500342 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
343 input_dev = input_allocate_device();
344 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300345 err = -ENOMEM;
346 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500349 ir->dev = input_dev;
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /* init hardware-specific stuff */
352 ir->mask_keycode = mask_keycode;
353 ir->mask_keydown = mask_keydown;
354 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800355 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300356 ir->rc5_gpio = rc5_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* init input device */
359 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
360 saa7134_boards[dev->board].name);
361 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
362 pci_name(dev->pci));
363
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500364 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
365 input_dev->name = ir->name;
366 input_dev->phys = ir->phys;
367 input_dev->id.bustype = BUS_PCI;
368 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500370 input_dev->id.vendor = dev->pci->subsystem_vendor;
371 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500373 input_dev->id.vendor = dev->pci->vendor;
374 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500376 input_dev->cdev.dev = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300379 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300381 err = input_register_device(ir->dev);
382 if (err)
383 goto err_out_stop;
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300386
387 err_out_stop:
388 saa7134_ir_stop(dev);
389 dev->remote = NULL;
390 err_out_free:
391 input_free_device(input_dev);
392 kfree(ir);
393 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
396void saa7134_input_fini(struct saa7134_dev *dev)
397{
398 if (NULL == dev->remote)
399 return;
400
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300401 saa7134_ir_stop(dev);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500402 input_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 kfree(dev->remote);
404 dev->remote = NULL;
405}
406
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800407void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
408{
409 if (disable_ir) {
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800410 dprintk("Found supported i2c remote, but IR has been disabled\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800411 ir->get_key=NULL;
412 return;
413 }
414
415 switch (dev->board) {
416 case SAA7134_BOARD_PINNACLE_PCTV_110i:
Hartmut Hackmanneb591af2006-10-12 19:46:16 -0300417 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800418 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
Sylvain Pascheb93eedb2006-03-25 23:14:42 -0300419 if (pinnacle_remote == 0) {
420 ir->get_key = get_key_pinnacle_color;
421 ir->ir_codes = ir_codes_pinnacle_color;
422 } else {
423 ir->get_key = get_key_pinnacle_grey;
424 ir->ir_codes = ir_codes_pinnacle_grey;
425 }
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800426 break;
427 case SAA7134_BOARD_UPMOST_PURPLE_TV:
428 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
429 ir->get_key = get_key_purpletv;
430 ir->ir_codes = ir_codes_purpletv;
431 break;
Thomas Genty177aaaf2006-11-29 21:57:24 -0300432 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
433 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
434 ir->get_key = get_key_hvr1110;
435 ir->ir_codes = ir_codes_hauppauge_new;
436 break;
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800437 default:
438 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
439 break;
440 }
441
442}
Hermann Pitton91607232006-12-07 21:45:28 -0300443
444static int saa7134_rc5_irq(struct saa7134_dev *dev)
445{
446 struct card_ir *ir = dev->remote;
447 struct timeval tv;
448 u32 gap;
449 unsigned long current_jiffies, timeout;
450
451 /* get time of bit */
452 current_jiffies = jiffies;
453 do_gettimeofday(&tv);
454
455 /* avoid overflow with gap >1s */
456 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
457 gap = 200000;
458 } else {
459 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
460 tv.tv_usec - ir->base_time.tv_usec;
461 }
462
463 /* active code => add bit */
464 if (ir->active) {
465 /* only if in the code (otherwise spurious IRQ or timer
466 late) */
467 if (ir->last_bit < 28) {
468 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
469 ir_rc5_remote_gap;
470 ir->code |= 1 << ir->last_bit;
471 }
472 /* starting new code */
473 } else {
474 ir->active = 1;
475 ir->code = 0;
476 ir->base_time = tv;
477 ir->last_bit = 0;
478
479 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
480 mod_timer(&ir->timer_end, timeout);
481 }
482
483 return 1;
484}
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486/* ----------------------------------------------------------------------
487 * Local variables:
488 * c-basic-offset: 8
489 * End:
490 */