blob: 83206cfb7b8cedab05e3d633f9c0e55f87f40221 [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
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030030static unsigned int disable_ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031module_param(disable_ir, int, 0444);
32MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
33
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030034static unsigned int ir_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035module_param(ir_debug, int, 0644);
36MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
37
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030038static int pinnacle_remote;
Sylvain Pascheb93eedb2006-03-25 23:14:42 -030039module_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
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -030055static unsigned int disable_other_ir;
56module_param(disable_other_ir, int, 0644);
57MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
58 "alternative remotes from other manufacturers");
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define dprintk(fmt, arg...) if (ir_debug) \
61 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080062#define i2cdprintk(fmt, arg...) if (ir_debug) \
Jean Delvare1df8e982009-05-13 16:48:07 -030063 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -030065/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
Hermann Pitton91607232006-12-07 21:45:28 -030066static int saa7134_rc5_irq(struct saa7134_dev *dev);
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -030067static int saa7134_nec_irq(struct saa7134_dev *dev);
68static void nec_task(unsigned long data);
69static void saa7134_nec_timer(unsigned long data);
Hermann Pitton91607232006-12-07 21:45:28 -030070
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080071/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73static int build_key(struct saa7134_dev *dev)
74{
Hermann Pitton91607232006-12-07 21:45:28 -030075 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 u32 gpio, data;
77
Pedro0938e312007-10-17 17:58:40 -030078 /* here comes the additional handshake steps for some cards */
79 switch (dev->board) {
80 case SAA7134_BOARD_GOTVIEW_7135:
81 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
82 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
83 break;
84 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /* rising SAA7134_GPIO_GPRESCAN reads the status */
86 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
87 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
88
89 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080090 if (ir->polling) {
91 if (ir->last_gpio == gpio)
92 return 0;
93 ir->last_gpio = gpio;
94 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080096 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
98 gpio, ir->mask_keycode, data);
99
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300100 switch (dev->board) {
101 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
102 if (data == ir->mask_keycode)
103 ir_input_nokey(ir->dev, &ir->ir);
104 else
105 ir_input_keydown(ir->dev, &ir->ir, data, data);
106 return 0;
107 }
108
Peter Missel0602fbb2006-01-09 18:21:23 -0200109 if (ir->polling) {
110 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
111 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
112 ir_input_keydown(ir->dev, &ir->ir, data, data);
113 } else {
114 ir_input_nokey(ir->dev, &ir->ir);
115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
Peter Missel0602fbb2006-01-09 18:21:23 -0200117 else { /* IRQ driven mode - handle key press and release in one go */
118 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
119 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
120 ir_input_keydown(ir->dev, &ir->ir, data, data);
121 ir_input_nokey(ir->dev, &ir->ir);
122 }
123 }
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 return 0;
126}
127
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800128/* --------------------- Chip specific I2C key builders ----------------- */
129
Brian Rogersba340b42008-10-13 08:37:06 -0300130static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
131 u32 *ir_raw)
132{
133 unsigned char b;
134 int gpio;
135
136 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
Jean Delvarec668f322009-05-13 16:48:50 -0300137 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Brian Rogersba340b42008-10-13 08:37:06 -0300138 if (dev == NULL) {
139 dprintk("get_key_msi_tvanywhere_plus: "
Jean Delvarec668f322009-05-13 16:48:50 -0300140 "gir->c->adapter->algo_data is NULL!\n");
Brian Rogersba340b42008-10-13 08:37:06 -0300141 return -EIO;
142 }
143
144 /* rising SAA7134_GPIO_GPRESCAN reads the status */
145
146 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
147 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
148
149 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
150
151 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
152 I2C receive if gpio&0x40 is not low. */
153
154 if (gpio & 0x40)
155 return 0; /* No button press */
156
157 /* GPIO says there is a button press. Get it. */
158
Jean Delvarec668f322009-05-13 16:48:50 -0300159 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Brian Rogersba340b42008-10-13 08:37:06 -0300160 i2cdprintk("read error\n");
161 return -EIO;
162 }
163
164 /* No button press */
165
166 if (b == 0xff)
167 return 0;
168
169 /* Button pressed */
170
171 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
172 *ir_key = b;
173 *ir_raw = b;
174 return 1;
175}
176
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800177static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
178{
179 unsigned char b;
180
181 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300182 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800183 i2cdprintk("read error\n");
184 return -EIO;
185 }
186
187 /* no button press */
188 if (b==0)
189 return 0;
190
191 /* repeating */
192 if (b & 0x80)
193 return 1;
194
195 *ir_key = b;
196 *ir_raw = b;
197 return 1;
198}
199
Thomas Genty177aaaf2006-11-29 21:57:24 -0300200static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
201{
202 unsigned char buf[5], cod4, code3, code4;
203
204 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300205 if (5 != i2c_master_recv(ir->c, buf, 5))
Thomas Genty177aaaf2006-11-29 21:57:24 -0300206 return -EIO;
207
208 cod4 = buf[4];
209 code4 = (cod4 >> 2);
210 code3 = buf[3];
211 if (code3 == 0)
212 /* no key pressed */
213 return 0;
214
215 /* return key */
216 *ir_key = code4;
217 *ir_raw = code4;
218 return 1;
219}
220
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300221
222static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
223{
224 unsigned char data[12];
225 u32 gpio;
226
Jean Delvarec668f322009-05-13 16:48:50 -0300227 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300228
229 /* rising SAA7134_GPIO_GPRESCAN reads the status */
230 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
231 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
232
233 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
234
Mauro Carvalho Chehab616f8872008-01-07 05:18:36 -0300235 if (0x400000 & ~gpio)
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300236 return 0; /* No button press */
237
Jean Delvarec668f322009-05-13 16:48:50 -0300238 ir->c->addr = 0x5a >> 1;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300239
Jean Delvarec668f322009-05-13 16:48:50 -0300240 if (12 != i2c_master_recv(ir->c, data, 12)) {
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300241 i2cdprintk("read error\n");
242 return -EIO;
243 }
244 /* IR of this card normally decode signals NEC-standard from
245 * - Sven IHOO MT 5.1R remote. xxyye718
246 * - Sven DVD HD-10xx remote. xxyyf708
247 * - BBK ...
248 * - mayby others
249 * So, skip not our, if disable full codes mode.
250 */
251 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
252 return 0;
253
Dmitri Belimov2d21ffe2009-09-07 20:36:05 -0300254 /* Wrong data decode fix */
255 if (data[9] != (unsigned char)(~data[8]))
256 return 0;
257
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300258 *ir_key = data[9];
259 *ir_raw = data[9];
260
261 return 1;
262}
263
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300264/* Common (grey or coloured) pinnacle PCTV remote handling
265 *
266 */
267static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
268 int parity_offset, int marker, int code_modulo)
269{
270 unsigned char b[4];
271 unsigned int start = 0,parity = 0,code = 0;
272
273 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300274 if (4 != i2c_master_recv(ir->c, b, 4)) {
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300275 i2cdprintk("read error\n");
276 return -EIO;
277 }
278
279 for (start = 0; start < ARRAY_SIZE(b); start++) {
280 if (b[start] == marker) {
281 code=b[(start+parity_offset + 1) % 4];
282 parity=b[(start+parity_offset) % 4];
283 }
284 }
285
286 /* Empty Request */
287 if (parity == 0)
288 return 0;
289
290 /* Repeating... */
291 if (ir->old == parity)
292 return 0;
293
294 ir->old = parity;
295
296 /* drop special codes when a key is held down a long time for the grey controller
297 In this case, the second bit of the code is asserted */
298 if (marker == 0xfe && (code & 0x40))
299 return 0;
300
301 code %= code_modulo;
302
303 *ir_raw = code;
304 *ir_key = code;
305
306 i2cdprintk("Pinnacle PCTV key %02x\n", code);
307
308 return 1;
309}
310
311/* The grey pinnacle PCTV remote
312 *
313 * There are one issue with this remote:
314 * - I2c packet does not change when the same key is pressed quickly. The workaround
315 * is to hold down each key for about half a second, so that another code is generated
316 * in the i2c packet, and the function can distinguish key presses.
317 *
318 * Sylvain Pasche <sylvain.pasche@gmail.com>
319 */
320static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
321{
322
323 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
324}
325
326
327/* The new pinnacle PCTV remote (with the colored buttons)
328 *
329 * Ricardo Cerqueira <v4l@cerqueira.org>
330 */
331static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
332{
333 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
334 *
335 * this is the only value that results in 42 unique
336 * codes < 128
337 */
338
339 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342void saa7134_input_irq(struct saa7134_dev *dev)
343{
Hermann Pitton91607232006-12-07 21:45:28 -0300344 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300346 if (ir->nec_gpio) {
347 saa7134_nec_irq(dev);
348 } else if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300350 } else if (ir->rc5_gpio) {
351 saa7134_rc5_irq(dev);
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355static void saa7134_input_timer(unsigned long data)
356{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300357 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300358 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300361 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Maxim Levitskyc4584732007-10-12 00:57:15 -0300364void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300365{
366 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300367 setup_timer(&ir->timer, saa7134_input_timer,
368 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300369 ir->timer.expires = jiffies + HZ;
370 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300371 } else if (ir->rc5_gpio) {
372 /* set timer_end for code completion */
373 init_timer(&ir->timer_end);
374 ir->timer_end.function = ir_rc5_timer_end;
375 ir->timer_end.data = (unsigned long)ir;
376 init_timer(&ir->timer_keyup);
377 ir->timer_keyup.function = ir_rc5_timer_keyup;
378 ir->timer_keyup.data = (unsigned long)ir;
379 ir->shift_by = 2;
380 ir->start = 0x2;
381 ir->addr = 0x17;
382 ir->rc5_key_timeout = ir_rc5_key_timeout;
383 ir->rc5_remote_gap = ir_rc5_remote_gap;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300384 } else if (ir->nec_gpio) {
385 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
386 (unsigned long)dev);
387 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300388 }
389}
390
Maxim Levitskyc4584732007-10-12 00:57:15 -0300391void saa7134_ir_stop(struct saa7134_dev *dev)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300392{
393 if (dev->remote->polling)
394 del_timer_sync(&dev->remote->timer);
395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397int saa7134_input_init1(struct saa7134_dev *dev)
398{
Hermann Pitton91607232006-12-07 21:45:28 -0300399 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500400 struct input_dev *input_dev;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300401 struct ir_scancode_table *ir_codes = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 u32 mask_keycode = 0;
403 u32 mask_keydown = 0;
404 u32 mask_keyup = 0;
405 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300406 int rc5_gpio = 0;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300407 int nec_gpio = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 int ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300409 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800411 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return -ENODEV;
413 if (disable_ir)
414 return -ENODEV;
415
416 /* detect & configure */
417 switch (dev->board) {
418 case SAA7134_BOARD_FLYVIDEO2000:
419 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800420 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800421 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Eugene Yudin23389b82009-08-29 09:32:11 -0300422 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300423 ir_codes = &ir_codes_flyvideo_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 mask_keycode = 0xEC00000;
425 mask_keydown = 0x0040000;
426 break;
427 case SAA7134_BOARD_CINERGY400:
428 case SAA7134_BOARD_CINERGY600:
429 case SAA7134_BOARD_CINERGY600_MK3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300430 ir_codes = &ir_codes_cinergy_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 mask_keycode = 0x00003f;
432 mask_keyup = 0x040000;
433 break;
434 case SAA7134_BOARD_ECS_TVP3XP:
435 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300436 ir_codes = &ir_codes_eztv_table;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700437 mask_keycode = 0x00017c;
438 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700440 break;
441 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 case SAA7134_BOARD_AVACSSMARTTV:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300443 ir_codes = &ir_codes_pixelview_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 mask_keycode = 0x00001F;
445 mask_keyup = 0x000020;
446 polling = 50; // ms
447 break;
448 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700449 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 case SAA7134_BOARD_AVERMEDIA_305:
451 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700452 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
Vasiliy Temnikov5a5e1da2009-08-26 22:10:55 -0300453 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700454 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300455 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Andy Shevchenkodf0dbbe2009-04-08 14:01:19 -0300456 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700457 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Albert Grahamd2761f22007-12-09 09:44:38 -0300458 case SAA7134_BOARD_AVERMEDIA_M102:
Pham Thanh Nam6a2d8022008-12-30 23:26:09 -0300459 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300460 ir_codes = &ir_codes_avermedia_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 mask_keycode = 0x0007C8;
462 mask_keydown = 0x000010;
463 polling = 50; // ms
464 /* Set GPIO pin2 to high to enable the IR controller */
465 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
466 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
467 break;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300468 case SAA7134_BOARD_AVERMEDIA_M135A:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300469 ir_codes = &ir_codes_avermedia_m135a_table;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300470 mask_keydown = 0x0040000;
471 mask_keycode = 0x00013f;
472 nec_gpio = 1;
473 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300474 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300475 case SAA7134_BOARD_AVERMEDIA_A16AR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300476 ir_codes = &ir_codes_avermedia_table;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300477 mask_keycode = 0x02F200;
478 mask_keydown = 0x000400;
479 polling = 50; // ms
480 /* Without this we won't receive key up events */
481 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
482 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800483 break;
Tim Farrington6e501a32008-06-15 13:33:42 -0300484 case SAA7134_BOARD_AVERMEDIA_A16D:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300485 ir_codes = &ir_codes_avermedia_a16d_table;
Tim Farrington6e501a32008-06-15 13:33:42 -0300486 mask_keycode = 0x02F200;
487 mask_keydown = 0x000400;
488 polling = 50; /* ms */
489 /* Without this we won't receive key up events */
490 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
491 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
492 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800493 case SAA7134_BOARD_KWORLD_TERMINATOR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300494 ir_codes = &ir_codes_pixelview_table;
James R. Webbdc2286c2005-11-08 21:37:00 -0800495 mask_keycode = 0x00001f;
496 mask_keyup = 0x000060;
497 polling = 50; // ms
498 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700499 case SAA7134_BOARD_MANLI_MTV001:
500 case SAA7134_BOARD_MANLI_MTV002:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300501 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300502 mask_keycode = 0x001f00;
503 mask_keyup = 0x004000;
504 polling = 50; /* ms */
505 break;
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800506 case SAA7134_BOARD_BEHOLD_409FM:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300507 case SAA7134_BOARD_BEHOLD_401:
508 case SAA7134_BOARD_BEHOLD_403:
509 case SAA7134_BOARD_BEHOLD_403FM:
510 case SAA7134_BOARD_BEHOLD_405:
511 case SAA7134_BOARD_BEHOLD_405FM:
512 case SAA7134_BOARD_BEHOLD_407:
513 case SAA7134_BOARD_BEHOLD_407FM:
514 case SAA7134_BOARD_BEHOLD_409:
515 case SAA7134_BOARD_BEHOLD_505FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300516 case SAA7134_BOARD_BEHOLD_505RDS:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300517 case SAA7134_BOARD_BEHOLD_507_9FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300518 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
519 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300520 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300521 mask_keycode = 0x003f00;
522 mask_keyup = 0x004000;
523 polling = 50; /* ms */
524 break;
525 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300526 ir_codes = &ir_codes_behold_columbus_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300527 mask_keycode = 0x003f00;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700528 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700529 polling = 50; // ms
530 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800531 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300532 ir_codes = &ir_codes_pctv_sedna_table;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800533 mask_keycode = 0x001f00;
534 mask_keyup = 0x004000;
535 polling = 50; // ms
536 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800537 case SAA7134_BOARD_GOTVIEW_7135:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300538 ir_codes = &ir_codes_gotview7135_table;
Pedro0938e312007-10-17 17:58:40 -0300539 mask_keycode = 0x0003CC;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800540 mask_keydown = 0x000010;
Pedro0938e312007-10-17 17:58:40 -0300541 polling = 5; /* ms */
542 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200545 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700546 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300547 ir_codes = &ir_codes_videomate_tv_pvr_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 mask_keycode = 0x00003F;
549 mask_keyup = 0x400000;
550 polling = 50; // ms
551 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300552 case SAA7134_BOARD_PROTEUS_2309:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300553 ir_codes = &ir_codes_proteus_2309_table;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300554 mask_keycode = 0x00007F;
555 mask_keyup = 0x000080;
556 polling = 50; // ms
557 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800558 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
559 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300560 ir_codes = &ir_codes_videomate_tv_pvr_table;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800561 mask_keycode = 0x003F00;
562 mask_keyup = 0x040000;
563 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300564 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200565 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300566 case SAA7134_BOARD_FLYDVBTDUO:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300567 ir_codes = &ir_codes_flydvb_table;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200568 mask_keycode = 0x0001F00;
569 mask_keydown = 0x0040000;
570 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300571 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300572 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Mauro Carvalho Chehabdfb4ba12009-08-20 10:13:40 -0300573 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300574 ir_codes = &ir_codes_asus_pc39_table;
Hermann Pitton91607232006-12-07 21:45:28 -0300575 mask_keydown = 0x0040000;
576 rc5_gpio = 1;
577 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300578 case SAA7134_BOARD_ENCORE_ENLTV:
579 case SAA7134_BOARD_ENCORE_ENLTV_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300580 ir_codes = &ir_codes_encore_enltv_table;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300581 mask_keycode = 0x00007f;
582 mask_keyup = 0x040000;
583 polling = 50; // ms
584 break;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300585 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300586 ir_codes = &ir_codes_encore_enltv_fm53_table;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300587 mask_keydown = 0x0040000;
588 mask_keycode = 0x00007f;
589 nec_gpio = 1;
590 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300591 case SAA7134_BOARD_10MOONSTVMASTER3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300592 ir_codes = &ir_codes_encore_enltv_table;
Tony Wan480f75a2007-05-11 11:33:50 -0300593 mask_keycode = 0x5f80000;
594 mask_keyup = 0x8000000;
595 polling = 50; //ms
596 break;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300597 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300598 ir_codes = &ir_codes_genius_tvgo_a11mce_table;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300599 mask_keycode = 0xff;
600 mask_keydown = 0xf00000;
601 polling = 50; /* ms */
602 break;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300603 case SAA7134_BOARD_REAL_ANGEL_220:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300604 ir_codes = &ir_codes_real_audio_220_32_keys_table;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300605 mask_keycode = 0x3f00;
606 mask_keyup = 0x4000;
607 polling = 50; /* ms */
608 break;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300609 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300610 ir_codes = &ir_codes_kworld_plus_tv_analog_table;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300611 mask_keycode = 0x7f;
612 polling = 40; /* ms */
613 break;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300614 case SAA7134_BOARD_VIDEOMATE_S350:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300615 ir_codes = &ir_codes_videomate_s350_table;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300616 mask_keycode = 0x003f00;
617 mask_keydown = 0x040000;
618 break;
Michael Obst0700ade2009-10-31 14:05:42 -0300619 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
620 ir_codes = &ir_codes_winfast_table;
621 mask_keycode = 0x5f00;
622 mask_keyup = 0x020000;
623 polling = 50; // ms
624 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626 if (NULL == ir_codes) {
627 printk("%s: Oops: IR config error [card=%d]\n",
628 dev->name, dev->board);
629 return -ENODEV;
630 }
631
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500632 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
633 input_dev = input_allocate_device();
634 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300635 err = -ENOMEM;
636 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500639 ir->dev = input_dev;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* init hardware-specific stuff */
642 ir->mask_keycode = mask_keycode;
643 ir->mask_keydown = mask_keydown;
644 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800645 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300646 ir->rc5_gpio = rc5_gpio;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300647 ir->nec_gpio = nec_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 /* init input device */
650 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
651 saa7134_boards[dev->board].name);
652 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
653 pci_name(dev->pci));
654
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500655 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
656 input_dev->name = ir->name;
657 input_dev->phys = ir->phys;
658 input_dev->id.bustype = BUS_PCI;
659 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500661 input_dev->id.vendor = dev->pci->subsystem_vendor;
662 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500664 input_dev->id.vendor = dev->pci->vendor;
665 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300667 input_dev->dev.parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300670 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300672 err = input_register_device(ir->dev);
673 if (err)
674 goto err_out_stop;
675
Pedro0938e312007-10-17 17:58:40 -0300676 /* the remote isn't as bouncy as a keyboard */
677 ir->dev->rep[REP_DELAY] = repeat_delay;
678 ir->dev->rep[REP_PERIOD] = repeat_period;
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300681
682 err_out_stop:
683 saa7134_ir_stop(dev);
684 dev->remote = NULL;
685 err_out_free:
686 input_free_device(input_dev);
687 kfree(ir);
688 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691void saa7134_input_fini(struct saa7134_dev *dev)
692{
693 if (NULL == dev->remote)
694 return;
695
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300696 saa7134_ir_stop(dev);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500697 input_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 kfree(dev->remote);
699 dev->remote = NULL;
700}
701
Jean Delvarec668f322009-05-13 16:48:50 -0300702void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800703{
Jean Delvare43e16ea2009-10-02 05:47:08 -0300704 struct i2c_board_info info;
Jean Delvarec668f322009-05-13 16:48:50 -0300705
Jean Delvarec668f322009-05-13 16:48:50 -0300706 struct i2c_msg msg_msi = {
707 .addr = 0x50,
708 .flags = I2C_M_RD,
709 .len = 0,
710 .buf = NULL,
711 };
712
Jean Delvarec668f322009-05-13 16:48:50 -0300713 int rc;
714
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800715 if (disable_ir) {
Jean Delvarec668f322009-05-13 16:48:50 -0300716 dprintk("IR has been disabled, not probing for i2c remote\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800717 return;
718 }
719
Jean Delvare43e16ea2009-10-02 05:47:08 -0300720 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300721 memset(&dev->init_data, 0, sizeof(dev->init_data));
Jean Delvare43e16ea2009-10-02 05:47:08 -0300722 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300723
724 switch (dev->board) {
725 case SAA7134_BOARD_PINNACLE_PCTV_110i:
726 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300727 dev->init_data.name = "Pinnacle PCTV";
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300728 if (pinnacle_remote == 0) {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300729 dev->init_data.get_key = get_key_pinnacle_color;
730 dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300731 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300732 } else {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300733 dev->init_data.get_key = get_key_pinnacle_grey;
734 dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300735 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300736 }
737 break;
738 case SAA7134_BOARD_UPMOST_PURPLE_TV:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300739 dev->init_data.name = "Purple TV";
740 dev->init_data.get_key = get_key_purpletv;
741 dev->init_data.ir_codes = &ir_codes_purpletv_table;
Jean Delvareaef02aa2009-10-02 08:47:22 -0300742 info.addr = 0x7a;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300743 break;
744 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300745 dev->init_data.name = "MSI TV@nywhere Plus";
746 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
747 dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300748 info.addr = 0x30;
Jean Delvareec218a42009-05-13 16:51:46 -0300749 /* MSI TV@nywhere Plus controller doesn't seem to
750 respond to probes unless we read something from
751 an existing device. Weird...
752 REVISIT: might no longer be needed */
753 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
754 dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
755 msg_msi.addr, dev->i2c_adap.name,
756 (1 == rc) ? "yes" : "no");
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300757 break;
758 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300759 dev->init_data.name = "HVR 1110";
760 dev->init_data.get_key = get_key_hvr1110;
761 dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
Jean Delvare30093e82009-10-02 09:48:04 -0300762 info.addr = 0x71;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300763 break;
764 case SAA7134_BOARD_BEHOLD_607FM_MK3:
765 case SAA7134_BOARD_BEHOLD_607FM_MK5:
766 case SAA7134_BOARD_BEHOLD_609FM_MK3:
767 case SAA7134_BOARD_BEHOLD_609FM_MK5:
768 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
769 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
770 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
771 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
772 case SAA7134_BOARD_BEHOLD_M6:
773 case SAA7134_BOARD_BEHOLD_M63:
774 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
775 case SAA7134_BOARD_BEHOLD_H6:
Dmitri Belimov2012c87f2009-08-26 01:01:12 -0300776 case SAA7134_BOARD_BEHOLD_X7:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300777 dev->init_data.name = "BeholdTV";
778 dev->init_data.get_key = get_key_beholdm6xx;
779 dev->init_data.ir_codes = &ir_codes_behold_table;
Jean Delvare30093e82009-10-02 09:48:04 -0300780 info.addr = 0x2d;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300781 break;
Jean Delvared9a88e62009-05-13 16:52:44 -0300782 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
783 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
Jean Delvare43e16ea2009-10-02 05:47:08 -0300784 info.addr = 0x40;
Jean Delvared9a88e62009-05-13 16:52:44 -0300785 break;
Jean Delvare30093e82009-10-02 09:48:04 -0300786 default:
787 dprintk("No I2C IR support for board %x\n", dev->board);
788 return;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300789 }
790
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300791 if (dev->init_data.name)
Jean Delvare43e16ea2009-10-02 05:47:08 -0300792 info.platform_data = &dev->init_data;
Jean Delvare30093e82009-10-02 09:48:04 -0300793 i2c_new_device(&dev->i2c_adap, &info);
Jean Delvarec668f322009-05-13 16:48:50 -0300794}
795
Hermann Pitton91607232006-12-07 21:45:28 -0300796static int saa7134_rc5_irq(struct saa7134_dev *dev)
797{
798 struct card_ir *ir = dev->remote;
799 struct timeval tv;
800 u32 gap;
801 unsigned long current_jiffies, timeout;
802
803 /* get time of bit */
804 current_jiffies = jiffies;
805 do_gettimeofday(&tv);
806
807 /* avoid overflow with gap >1s */
808 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
809 gap = 200000;
810 } else {
811 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
812 tv.tv_usec - ir->base_time.tv_usec;
813 }
814
815 /* active code => add bit */
816 if (ir->active) {
817 /* only if in the code (otherwise spurious IRQ or timer
818 late) */
819 if (ir->last_bit < 28) {
820 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
821 ir_rc5_remote_gap;
822 ir->code |= 1 << ir->last_bit;
823 }
824 /* starting new code */
825 } else {
826 ir->active = 1;
827 ir->code = 0;
828 ir->base_time = tv;
829 ir->last_bit = 0;
830
831 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
832 mod_timer(&ir->timer_end, timeout);
833 }
834
835 return 1;
836}
837
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300838
839/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
840 The first pulse (start) has 9 + 4.5 ms
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 */
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300842
843static void saa7134_nec_timer(unsigned long data)
844{
845 struct saa7134_dev *dev = (struct saa7134_dev *) data;
846 struct card_ir *ir = dev->remote;
847
848 dprintk("Cancel key repeat\n");
849
850 ir_input_nokey(ir->dev, &ir->ir);
851}
852
853static void nec_task(unsigned long data)
854{
855 struct saa7134_dev *dev = (struct saa7134_dev *) data;
856 struct card_ir *ir;
857 struct timeval tv;
858 int count, pulse, oldpulse, gap;
859 u32 ircode = 0, not_code = 0;
860 int ngap = 0;
861
862 if (!data) {
863 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
864 /* GPIO will be kept disabled */
865 return;
866 }
867
868 ir = dev->remote;
869
870 /* rising SAA7134_GPIO_GPRESCAN reads the status */
871 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
872 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
873
874 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
875 pulse = oldpulse;
876
877 do_gettimeofday(&tv);
878 ir->base_time = tv;
879
880 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
881 Unfortunately, using IRQ to decode pulse didn't work, since it uses
882 a pulse train of 38KHz. This means one pulse on each 52 us
883 */
884 do {
885 /* Wait until the end of pulse/space or 5 ms */
886 for (count = 0; count < 500; count++) {
887 udelay(10);
888 /* rising SAA7134_GPIO_GPRESCAN reads the status */
889 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
890 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
891 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
892 & ir->mask_keydown;
893 if (pulse != oldpulse)
894 break;
895 }
896
897 do_gettimeofday(&tv);
898 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
899 tv.tv_usec - ir->base_time.tv_usec;
900
901 if (!pulse) {
902 /* Bit 0 has 560 us, while bit 1 has 1120 us.
903 Do something only if bit == 1
904 */
905 if (ngap && (gap > 560 + 280)) {
906 unsigned int shift = ngap - 1;
907
908 /* Address first, then command */
909 if (shift < 8) {
910 shift += 8;
911 ircode |= 1 << shift;
912 } else if (shift < 16) {
913 not_code |= 1 << shift;
914 } else if (shift < 24) {
915 shift -= 16;
916 ircode |= 1 << shift;
917 } else {
918 shift -= 24;
919 not_code |= 1 << shift;
920 }
921 }
922 ngap++;
923 }
924
925
926 ir->base_time = tv;
927
928 /* TIMEOUT - Long pulse */
929 if (gap >= 5000)
930 break;
931 oldpulse = pulse;
932 } while (ngap < 32);
933
934 if (ngap == 32) {
935 /* FIXME: should check if not_code == ~ircode */
936 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
937
938 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
939 ir->code, ircode, not_code);
940
941 ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code);
942 } else
943 dprintk("Repeat last key\n");
944
945 /* Keep repeating the last key */
946 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
947
948 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
949}
950
951static int saa7134_nec_irq(struct saa7134_dev *dev)
952{
953 struct card_ir *ir = dev->remote;
954
955 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
956 tasklet_schedule(&ir->tlet);
957
958 return 1;
959}