blob: 8cfeb2bde90fa6c36d51b8a858fe0db60bce9c5b [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
Pedro0938e312007-10-17 17:58:40 -030047static int repeat_delay = 500;
48module_param(repeat_delay, int, 0644);
49MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
50static int repeat_period = 33;
51module_param(repeat_period, int, 0644);
Joe Perchesac9bb7f2007-11-20 09:00:35 -030052MODULE_PARM_DESC(repeat_period, "repeat period between "
Pedro0938e312007-10-17 17:58:40 -030053 "keypresses when key is down");
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define dprintk(fmt, arg...) if (ir_debug) \
56 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080057#define i2cdprintk(fmt, arg...) if (ir_debug) \
58 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Hermann Pitton91607232006-12-07 21:45:28 -030060/** rc5 functions */
61static int saa7134_rc5_irq(struct saa7134_dev *dev);
62
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080063/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65static int build_key(struct saa7134_dev *dev)
66{
Hermann Pitton91607232006-12-07 21:45:28 -030067 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 u32 gpio, data;
69
Pedro0938e312007-10-17 17:58:40 -030070 /* here comes the additional handshake steps for some cards */
71 switch (dev->board) {
72 case SAA7134_BOARD_GOTVIEW_7135:
73 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
74 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
75 break;
76 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /* rising SAA7134_GPIO_GPRESCAN reads the status */
78 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
79 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
80
81 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080082 if (ir->polling) {
83 if (ir->last_gpio == gpio)
84 return 0;
85 ir->last_gpio = gpio;
86 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080088 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
90 gpio, ir->mask_keycode, data);
91
Peter Missel0602fbb2006-01-09 18:21:23 -020092 if (ir->polling) {
93 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
94 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
95 ir_input_keydown(ir->dev, &ir->ir, data, data);
96 } else {
97 ir_input_nokey(ir->dev, &ir->ir);
98 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
Peter Missel0602fbb2006-01-09 18:21:23 -0200100 else { /* IRQ driven mode - handle key press and release in one go */
101 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
102 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
103 ir_input_keydown(ir->dev, &ir->ir, data, data);
104 ir_input_nokey(ir->dev, &ir->ir);
105 }
106 }
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return 0;
109}
110
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800111/* --------------------- Chip specific I2C key builders ----------------- */
112
113static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
114{
115 unsigned char b;
116
117 /* poll IR chip */
118 if (1 != i2c_master_recv(&ir->c,&b,1)) {
119 i2cdprintk("read error\n");
120 return -EIO;
121 }
122
123 /* no button press */
124 if (b==0)
125 return 0;
126
127 /* repeating */
128 if (b & 0x80)
129 return 1;
130
131 *ir_key = b;
132 *ir_raw = b;
133 return 1;
134}
135
Thomas Genty177aaaf2006-11-29 21:57:24 -0300136static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
137{
138 unsigned char buf[5], cod4, code3, code4;
139
140 /* poll IR chip */
141 if (5 != i2c_master_recv(&ir->c,buf,5))
142 return -EIO;
143
144 cod4 = buf[4];
145 code4 = (cod4 >> 2);
146 code3 = buf[3];
147 if (code3 == 0)
148 /* no key pressed */
149 return 0;
150
151 /* return key */
152 *ir_key = code4;
153 *ir_raw = code4;
154 return 1;
155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157void saa7134_input_irq(struct saa7134_dev *dev)
158{
Hermann Pitton91607232006-12-07 21:45:28 -0300159 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Hermann Pitton91607232006-12-07 21:45:28 -0300161 if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300163 } else if (ir->rc5_gpio) {
164 saa7134_rc5_irq(dev);
165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168static void saa7134_input_timer(unsigned long data)
169{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300170 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300171 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300174 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
Maxim Levitskyc4584732007-10-12 00:57:15 -0300177void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300178{
179 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300180 setup_timer(&ir->timer, saa7134_input_timer,
181 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300182 ir->timer.expires = jiffies + HZ;
183 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300184 } else if (ir->rc5_gpio) {
185 /* set timer_end for code completion */
186 init_timer(&ir->timer_end);
187 ir->timer_end.function = ir_rc5_timer_end;
188 ir->timer_end.data = (unsigned long)ir;
189 init_timer(&ir->timer_keyup);
190 ir->timer_keyup.function = ir_rc5_timer_keyup;
191 ir->timer_keyup.data = (unsigned long)ir;
192 ir->shift_by = 2;
193 ir->start = 0x2;
194 ir->addr = 0x17;
195 ir->rc5_key_timeout = ir_rc5_key_timeout;
196 ir->rc5_remote_gap = ir_rc5_remote_gap;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300197 }
198}
199
Maxim Levitskyc4584732007-10-12 00:57:15 -0300200void saa7134_ir_stop(struct saa7134_dev *dev)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300201{
202 if (dev->remote->polling)
203 del_timer_sync(&dev->remote->timer);
204}
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206int saa7134_input_init1(struct saa7134_dev *dev)
207{
Hermann Pitton91607232006-12-07 21:45:28 -0300208 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500209 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 IR_KEYTAB_TYPE *ir_codes = NULL;
211 u32 mask_keycode = 0;
212 u32 mask_keydown = 0;
213 u32 mask_keyup = 0;
214 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300215 int rc5_gpio = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 int ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300217 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800219 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return -ENODEV;
221 if (disable_ir)
222 return -ENODEV;
223
224 /* detect & configure */
225 switch (dev->board) {
226 case SAA7134_BOARD_FLYVIDEO2000:
227 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800228 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800229 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200230 ir_codes = ir_codes_flyvideo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 mask_keycode = 0xEC00000;
232 mask_keydown = 0x0040000;
233 break;
234 case SAA7134_BOARD_CINERGY400:
235 case SAA7134_BOARD_CINERGY600:
236 case SAA7134_BOARD_CINERGY600_MK3:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200237 ir_codes = ir_codes_cinergy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 mask_keycode = 0x00003f;
239 mask_keyup = 0x040000;
240 break;
241 case SAA7134_BOARD_ECS_TVP3XP:
242 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200243 ir_codes = ir_codes_eztv;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700244 mask_keycode = 0x00017c;
245 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700247 break;
248 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 case SAA7134_BOARD_AVACSSMARTTV:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200250 ir_codes = ir_codes_pixelview;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 mask_keycode = 0x00001F;
252 mask_keyup = 0x000020;
253 polling = 50; // ms
254 break;
255 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700256 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 case SAA7134_BOARD_AVERMEDIA_305:
258 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700259 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
260 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300261 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700262 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Albert Grahamd2761f22007-12-09 09:44:38 -0300263 case SAA7134_BOARD_AVERMEDIA_M102:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200264 ir_codes = ir_codes_avermedia;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 mask_keycode = 0x0007C8;
266 mask_keydown = 0x000010;
267 polling = 50; // ms
268 /* Set GPIO pin2 to high to enable the IR controller */
269 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
270 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
271 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300272 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300273 case SAA7134_BOARD_AVERMEDIA_A16AR:
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300274 ir_codes = ir_codes_avermedia;
275 mask_keycode = 0x02F200;
276 mask_keydown = 0x000400;
277 polling = 50; // ms
278 /* Without this we won't receive key up events */
279 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
280 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800281 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800282 case SAA7134_BOARD_KWORLD_TERMINATOR:
Nickolay V. Shmyrevb639f9d2006-01-23 09:44:10 -0200283 ir_codes = ir_codes_pixelview;
James R. Webbdc2286c2005-11-08 21:37:00 -0800284 mask_keycode = 0x00001f;
285 mask_keyup = 0x000060;
286 polling = 50; // ms
287 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700288 case SAA7134_BOARD_MANLI_MTV001:
289 case SAA7134_BOARD_MANLI_MTV002:
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800290 case SAA7134_BOARD_BEHOLD_409FM:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200291 ir_codes = ir_codes_manli;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700292 mask_keycode = 0x001f00;
293 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700294 polling = 50; // ms
295 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800296 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200297 ir_codes = ir_codes_pctv_sedna;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800298 mask_keycode = 0x001f00;
299 mask_keyup = 0x004000;
300 polling = 50; // ms
301 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800302 case SAA7134_BOARD_GOTVIEW_7135:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200303 ir_codes = ir_codes_gotview7135;
Pedro0938e312007-10-17 17:58:40 -0300304 mask_keycode = 0x0003CC;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800305 mask_keydown = 0x000010;
Pedro0938e312007-10-17 17:58:40 -0300306 polling = 5; /* ms */
307 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800308 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200310 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700311 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200312 ir_codes = ir_codes_videomate_tv_pvr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 mask_keycode = 0x00003F;
314 mask_keyup = 0x400000;
315 polling = 50; // ms
316 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300317 case SAA7134_BOARD_PROTEUS_2309:
318 ir_codes = ir_codes_proteus_2309;
319 mask_keycode = 0x00007F;
320 mask_keyup = 0x000080;
321 polling = 50; // ms
322 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800323 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
324 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Ricardo Cerqueira4c0f6312006-01-23 09:42:06 -0200325 ir_codes = ir_codes_videomate_tv_pvr;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800326 mask_keycode = 0x003F00;
327 mask_keyup = 0x040000;
328 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300329 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200330 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300331 case SAA7134_BOARD_FLYDVBTDUO:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200332 ir_codes = ir_codes_flydvb;
333 mask_keycode = 0x0001F00;
334 mask_keydown = 0x0040000;
335 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300336 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300337 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Hermann Pitton91607232006-12-07 21:45:28 -0300338 ir_codes = ir_codes_asus_pc39;
339 mask_keydown = 0x0040000;
340 rc5_gpio = 1;
341 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300342 case SAA7134_BOARD_ENCORE_ENLTV:
343 case SAA7134_BOARD_ENCORE_ENLTV_FM:
344 ir_codes = ir_codes_encore_enltv;
345 mask_keycode = 0x00007f;
346 mask_keyup = 0x040000;
347 polling = 50; // ms
348 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300349 case SAA7134_BOARD_10MOONSTVMASTER3:
350 ir_codes = ir_codes_encore_enltv;
351 mask_keycode = 0x5f80000;
352 mask_keyup = 0x8000000;
353 polling = 50; //ms
354 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356 if (NULL == ir_codes) {
357 printk("%s: Oops: IR config error [card=%d]\n",
358 dev->name, dev->board);
359 return -ENODEV;
360 }
361
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500362 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
363 input_dev = input_allocate_device();
364 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300365 err = -ENOMEM;
366 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500369 ir->dev = input_dev;
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* init hardware-specific stuff */
372 ir->mask_keycode = mask_keycode;
373 ir->mask_keydown = mask_keydown;
374 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800375 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300376 ir->rc5_gpio = rc5_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /* init input device */
379 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
380 saa7134_boards[dev->board].name);
381 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
382 pci_name(dev->pci));
383
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500384 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
385 input_dev->name = ir->name;
386 input_dev->phys = ir->phys;
387 input_dev->id.bustype = BUS_PCI;
388 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500390 input_dev->id.vendor = dev->pci->subsystem_vendor;
391 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500393 input_dev->id.vendor = dev->pci->vendor;
394 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300396 input_dev->dev.parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300399 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300401 err = input_register_device(ir->dev);
402 if (err)
403 goto err_out_stop;
404
Pedro0938e312007-10-17 17:58:40 -0300405 /* the remote isn't as bouncy as a keyboard */
406 ir->dev->rep[REP_DELAY] = repeat_delay;
407 ir->dev->rep[REP_PERIOD] = repeat_period;
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300410
411 err_out_stop:
412 saa7134_ir_stop(dev);
413 dev->remote = NULL;
414 err_out_free:
415 input_free_device(input_dev);
416 kfree(ir);
417 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
420void saa7134_input_fini(struct saa7134_dev *dev)
421{
422 if (NULL == dev->remote)
423 return;
424
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300425 saa7134_ir_stop(dev);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500426 input_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 kfree(dev->remote);
428 dev->remote = NULL;
429}
430
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800431void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
432{
433 if (disable_ir) {
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800434 dprintk("Found supported i2c remote, but IR has been disabled\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800435 ir->get_key=NULL;
436 return;
437 }
438
439 switch (dev->board) {
440 case SAA7134_BOARD_PINNACLE_PCTV_110i:
Hartmut Hackmanneb591af2006-10-12 19:46:16 -0300441 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800442 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
Sylvain Pascheb93eedb2006-03-25 23:14:42 -0300443 if (pinnacle_remote == 0) {
444 ir->get_key = get_key_pinnacle_color;
445 ir->ir_codes = ir_codes_pinnacle_color;
446 } else {
447 ir->get_key = get_key_pinnacle_grey;
448 ir->ir_codes = ir_codes_pinnacle_grey;
449 }
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800450 break;
451 case SAA7134_BOARD_UPMOST_PURPLE_TV:
452 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
453 ir->get_key = get_key_purpletv;
454 ir->ir_codes = ir_codes_purpletv;
455 break;
Thomas Genty177aaaf2006-11-29 21:57:24 -0300456 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
457 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
458 ir->get_key = get_key_hvr1110;
459 ir->ir_codes = ir_codes_hauppauge_new;
460 break;
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800461 default:
462 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
463 break;
464 }
465
466}
Hermann Pitton91607232006-12-07 21:45:28 -0300467
468static int saa7134_rc5_irq(struct saa7134_dev *dev)
469{
470 struct card_ir *ir = dev->remote;
471 struct timeval tv;
472 u32 gap;
473 unsigned long current_jiffies, timeout;
474
475 /* get time of bit */
476 current_jiffies = jiffies;
477 do_gettimeofday(&tv);
478
479 /* avoid overflow with gap >1s */
480 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
481 gap = 200000;
482 } else {
483 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
484 tv.tv_usec - ir->base_time.tv_usec;
485 }
486
487 /* active code => add bit */
488 if (ir->active) {
489 /* only if in the code (otherwise spurious IRQ or timer
490 late) */
491 if (ir->last_bit < 28) {
492 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
493 ir_rc5_remote_gap;
494 ir->code |= 1 << ir->last_bit;
495 }
496 /* starting new code */
497 } else {
498 ir->active = 1;
499 ir->code = 0;
500 ir->base_time = tv;
501 ir->last_bit = 0;
502
503 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
504 mod_timer(&ir->timer_end, timeout);
505 }
506
507 return 1;
508}
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510/* ----------------------------------------------------------------------
511 * Local variables:
512 * c-basic-offset: 8
513 * End:
514 */