blob: d4907ce4e51f444f4ffd3af03a488935aea81024 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/interrupt.h>
25#include <linux/input.h>
26
27#include "saa7134-reg.h"
28#include "saa7134.h"
29
30static unsigned int disable_ir = 0;
31module_param(disable_ir, int, 0444);
32MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
33
34static unsigned int ir_debug = 0;
35module_param(ir_debug, int, 0644);
36MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
37
Sylvain Pascheb93eedb2006-03-25 23:14:42 -030038static int pinnacle_remote = 0;
39module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
40MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
41
Adrian Bunkc408a6f2006-12-28 12:47:47 -030042static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030043module_param(ir_rc5_remote_gap, int, 0644);
Adrian Bunkc408a6f2006-12-28 12:47:47 -030044static int ir_rc5_key_timeout = 115;
Hermann Pitton91607232006-12-07 21:45:28 -030045module_param(ir_rc5_key_timeout, int, 0644);
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define dprintk(fmt, arg...) if (ir_debug) \
48 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080049#define i2cdprintk(fmt, arg...) if (ir_debug) \
50 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Hermann Pitton91607232006-12-07 21:45:28 -030052/** rc5 functions */
53static int saa7134_rc5_irq(struct saa7134_dev *dev);
54
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080055/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57static int build_key(struct saa7134_dev *dev)
58{
Hermann Pitton91607232006-12-07 21:45:28 -030059 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 u32 gpio, data;
61
62 /* rising SAA7134_GPIO_GPRESCAN reads the status */
63 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
64 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
65
66 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080067 if (ir->polling) {
68 if (ir->last_gpio == gpio)
69 return 0;
70 ir->last_gpio = gpio;
71 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080073 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
75 gpio, ir->mask_keycode, data);
76
Peter Missel0602fbb2006-01-09 18:21:23 -020077 if (ir->polling) {
78 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
79 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
80 ir_input_keydown(ir->dev, &ir->ir, data, data);
81 } else {
82 ir_input_nokey(ir->dev, &ir->ir);
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
Peter Missel0602fbb2006-01-09 18:21:23 -020085 else { /* IRQ driven mode - handle key press and release in one go */
86 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
87 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
88 ir_input_keydown(ir->dev, &ir->ir, data, data);
89 ir_input_nokey(ir->dev, &ir->ir);
90 }
91 }
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return 0;
94}
95
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080096/* --------------------- Chip specific I2C key builders ----------------- */
97
98static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
99{
100 unsigned char b;
101
102 /* poll IR chip */
103 if (1 != i2c_master_recv(&ir->c,&b,1)) {
104 i2cdprintk("read error\n");
105 return -EIO;
106 }
107
108 /* no button press */
109 if (b==0)
110 return 0;
111
112 /* repeating */
113 if (b & 0x80)
114 return 1;
115
116 *ir_key = b;
117 *ir_raw = b;
118 return 1;
119}
120
Thomas Genty177aaaf2006-11-29 21:57:24 -0300121static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
122{
123 unsigned char buf[5], cod4, code3, code4;
124
125 /* poll IR chip */
126 if (5 != i2c_master_recv(&ir->c,buf,5))
127 return -EIO;
128
129 cod4 = buf[4];
130 code4 = (cod4 >> 2);
131 code3 = buf[3];
132 if (code3 == 0)
133 /* no key pressed */
134 return 0;
135
136 /* return key */
137 *ir_key = code4;
138 *ir_raw = code4;
139 return 1;
140}
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142void saa7134_input_irq(struct saa7134_dev *dev)
143{
Hermann Pitton91607232006-12-07 21:45:28 -0300144 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Hermann Pitton91607232006-12-07 21:45:28 -0300146 if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300148 } else if (ir->rc5_gpio) {
149 saa7134_rc5_irq(dev);
150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static void saa7134_input_timer(unsigned long data)
154{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300155 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300156 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300159 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Maxim Levitskyc4584732007-10-12 00:57:15 -0300162void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300163{
164 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300165 setup_timer(&ir->timer, saa7134_input_timer,
166 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300167 ir->timer.expires = jiffies + HZ;
168 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300169 } else if (ir->rc5_gpio) {
170 /* set timer_end for code completion */
171 init_timer(&ir->timer_end);
172 ir->timer_end.function = ir_rc5_timer_end;
173 ir->timer_end.data = (unsigned long)ir;
174 init_timer(&ir->timer_keyup);
175 ir->timer_keyup.function = ir_rc5_timer_keyup;
176 ir->timer_keyup.data = (unsigned long)ir;
177 ir->shift_by = 2;
178 ir->start = 0x2;
179 ir->addr = 0x17;
180 ir->rc5_key_timeout = ir_rc5_key_timeout;
181 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300182 }
183}
184
Maxim Levitskyc4584732007-10-12 00:57:15 -0300185void saa7134_ir_stop(struct saa7134_dev *dev)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300186{
187 if (dev->remote->polling)
188 del_timer_sync(&dev->remote->timer);
189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191int saa7134_input_init1(struct saa7134_dev *dev)
192{
Hermann Pitton91607232006-12-07 21:45:28 -0300193 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500194 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 IR_KEYTAB_TYPE *ir_codes = NULL;
196 u32 mask_keycode = 0;
197 u32 mask_keydown = 0;
198 u32 mask_keyup = 0;
199 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300200 int rc5_gpio = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 int ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300202 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800204 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return -ENODEV;
206 if (disable_ir)
207 return -ENODEV;
208
209 /* detect & configure */
210 switch (dev->board) {
211 case SAA7134_BOARD_FLYVIDEO2000:
212 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800213 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800214 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200215 ir_codes = ir_codes_flyvideo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 mask_keycode = 0xEC00000;
217 mask_keydown = 0x0040000;
218 break;
219 case SAA7134_BOARD_CINERGY400:
220 case SAA7134_BOARD_CINERGY600:
221 case SAA7134_BOARD_CINERGY600_MK3:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200222 ir_codes = ir_codes_cinergy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 mask_keycode = 0x00003f;
224 mask_keyup = 0x040000;
225 break;
226 case SAA7134_BOARD_ECS_TVP3XP:
227 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200228 ir_codes = ir_codes_eztv;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700229 mask_keycode = 0x00017c;
230 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700232 break;
233 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 case SAA7134_BOARD_AVACSSMARTTV:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200235 ir_codes = ir_codes_pixelview;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 mask_keycode = 0x00001F;
237 mask_keyup = 0x000020;
238 polling = 50; // ms
239 break;
240 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700241 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 case SAA7134_BOARD_AVERMEDIA_305:
243 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700244 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
245 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300246 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700247 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200248 ir_codes = ir_codes_avermedia;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 mask_keycode = 0x0007C8;
250 mask_keydown = 0x000010;
251 polling = 50; // ms
252 /* Set GPIO pin2 to high to enable the IR controller */
253 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
254 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
255 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300256 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300257 case SAA7134_BOARD_AVERMEDIA_A16AR:
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300258 ir_codes = ir_codes_avermedia;
259 mask_keycode = 0x02F200;
260 mask_keydown = 0x000400;
261 polling = 50; // ms
262 /* Without this we won't receive key up events */
263 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
264 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800265 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800266 case SAA7134_BOARD_KWORLD_TERMINATOR:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200267 ir_codes = ir_codes_pixelview;
James R. Webbdc2286c2005-11-08 21:37:00 -0800268 mask_keycode = 0x00001f;
269 mask_keyup = 0x000060;
270 polling = 50; // ms
271 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700272 case SAA7134_BOARD_MANLI_MTV001:
273 case SAA7134_BOARD_MANLI_MTV002:
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800274 case SAA7134_BOARD_BEHOLD_409FM:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200275 ir_codes = ir_codes_manli;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700276 mask_keycode = 0x001f00;
277 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700278 polling = 50; // ms
279 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800280 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200281 ir_codes = ir_codes_pctv_sedna;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800282 mask_keycode = 0x001f00;
283 mask_keyup = 0x004000;
284 polling = 50; // ms
285 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800286 case SAA7134_BOARD_GOTVIEW_7135:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200287 ir_codes = ir_codes_gotview7135;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800288 mask_keycode = 0x0003EC;
289 mask_keyup = 0x008000;
290 mask_keydown = 0x000010;
291 polling = 50; // ms
292 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200294 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700295 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200296 ir_codes = ir_codes_videomate_tv_pvr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 mask_keycode = 0x00003F;
298 mask_keyup = 0x400000;
299 polling = 50; // ms
300 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300301 case SAA7134_BOARD_PROTEUS_2309:
302 ir_codes = ir_codes_proteus_2309;
303 mask_keycode = 0x00007F;
304 mask_keyup = 0x000080;
305 polling = 50; // ms
306 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800307 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
308 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200309 ir_codes = ir_codes_videomate_tv_pvr;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800310 mask_keycode = 0x003F00;
311 mask_keyup = 0x040000;
312 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300313 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200314 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300315 case SAA7134_BOARD_FLYDVBTDUO:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200316 ir_codes = ir_codes_flydvb;
317 mask_keycode = 0x0001F00;
318 mask_keydown = 0x0040000;
319 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300320 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300321 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Hermann Pitton91607232006-12-07 21:45:28 -0300322 ir_codes = ir_codes_asus_pc39;
323 mask_keydown = 0x0040000;
324 rc5_gpio = 1;
325 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300326 case SAA7134_BOARD_ENCORE_ENLTV:
327 case SAA7134_BOARD_ENCORE_ENLTV_FM:
328 ir_codes = ir_codes_encore_enltv;
329 mask_keycode = 0x00007f;
330 mask_keyup = 0x040000;
331 polling = 50; // ms
332 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300333 case SAA7134_BOARD_10MOONSTVMASTER3:
334 ir_codes = ir_codes_encore_enltv;
335 mask_keycode = 0x5f80000;
336 mask_keyup = 0x8000000;
337 polling = 50; //ms
338 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340 if (NULL == ir_codes) {
341 printk("%s: Oops: IR config error [card=%d]\n",
342 dev->name, dev->board);
343 return -ENODEV;
344 }
345
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500346 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
347 input_dev = input_allocate_device();
348 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300349 err = -ENOMEM;
350 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500353 ir->dev = input_dev;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /* init hardware-specific stuff */
356 ir->mask_keycode = mask_keycode;
357 ir->mask_keydown = mask_keydown;
358 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800359 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300360 ir->rc5_gpio = rc5_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* init input device */
363 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
364 saa7134_boards[dev->board].name);
365 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
366 pci_name(dev->pci));
367
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500368 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
369 input_dev->name = ir->name;
370 input_dev->phys = ir->phys;
371 input_dev->id.bustype = BUS_PCI;
372 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500374 input_dev->id.vendor = dev->pci->subsystem_vendor;
375 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500377 input_dev->id.vendor = dev->pci->vendor;
378 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300380 input_dev->dev.parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300383 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300385 err = input_register_device(ir->dev);
386 if (err)
387 goto err_out_stop;
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300390
391 err_out_stop:
392 saa7134_ir_stop(dev);
393 dev->remote = NULL;
394 err_out_free:
395 input_free_device(input_dev);
396 kfree(ir);
397 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400void saa7134_input_fini(struct saa7134_dev *dev)
401{
402 if (NULL == dev->remote)
403 return;
404
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300405 saa7134_ir_stop(dev);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500406 input_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 kfree(dev->remote);
408 dev->remote = NULL;
409}
410
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800411void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
412{
413 if (disable_ir) {
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800414 dprintk("Found supported i2c remote, but IR has been disabled\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800415 ir->get_key=NULL;
416 return;
417 }
418
419 switch (dev->board) {
420 case SAA7134_BOARD_PINNACLE_PCTV_110i:
Hartmut Hackmanneb591af2006-10-12 19:46:16 -0300421 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800422 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
Sylvain Pascheb93eedb2006-03-25 23:14:42 -0300423 if (pinnacle_remote == 0) {
424 ir->get_key = get_key_pinnacle_color;
425 ir->ir_codes = ir_codes_pinnacle_color;
426 } else {
427 ir->get_key = get_key_pinnacle_grey;
428 ir->ir_codes = ir_codes_pinnacle_grey;
429 }
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800430 break;
431 case SAA7134_BOARD_UPMOST_PURPLE_TV:
432 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
433 ir->get_key = get_key_purpletv;
434 ir->ir_codes = ir_codes_purpletv;
435 break;
Thomas Genty177aaaf2006-11-29 21:57:24 -0300436 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
437 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
438 ir->get_key = get_key_hvr1110;
439 ir->ir_codes = ir_codes_hauppauge_new;
440 break;
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800441 default:
442 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
443 break;
444 }
445
446}
Hermann Pitton91607232006-12-07 21:45:28 -0300447
448static int saa7134_rc5_irq(struct saa7134_dev *dev)
449{
450 struct card_ir *ir = dev->remote;
451 struct timeval tv;
452 u32 gap;
453 unsigned long current_jiffies, timeout;
454
455 /* get time of bit */
456 current_jiffies = jiffies;
457 do_gettimeofday(&tv);
458
459 /* avoid overflow with gap >1s */
460 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
461 gap = 200000;
462 } else {
463 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
464 tv.tv_usec - ir->base_time.tv_usec;
465 }
466
467 /* active code => add bit */
468 if (ir->active) {
469 /* only if in the code (otherwise spurious IRQ or timer
470 late) */
471 if (ir->last_bit < 28) {
472 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
473 ir_rc5_remote_gap;
474 ir->code |= 1 << ir->last_bit;
475 }
476 /* starting new code */
477 } else {
478 ir->active = 1;
479 ir->code = 0;
480 ir->base_time = tv;
481 ir->last_bit = 0;
482
483 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
484 mod_timer(&ir->timer_end, timeout);
485 }
486
487 return 1;
488}
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490/* ----------------------------------------------------------------------
491 * Local variables:
492 * c-basic-offset: 8
493 * End:
494 */