blob: c1fe7c9369b2881ac52f922a89c88d8c143b93a1 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "saa7134-reg.h"
29#include "saa7134.h"
30
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030031#define MODULE_NAME "saa7134"
32
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030033static unsigned int disable_ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034module_param(disable_ir, int, 0444);
35MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
36
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030037static unsigned int ir_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038module_param(ir_debug, int, 0644);
39MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
40
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030041static int pinnacle_remote;
Sylvain Pascheb93eedb2006-03-25 23:14:42 -030042module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
43MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
44
Adrian Bunkc408a6f2006-12-28 12:47:47 -030045static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030046module_param(ir_rc5_remote_gap, int, 0644);
Adrian Bunkc408a6f2006-12-28 12:47:47 -030047static int ir_rc5_key_timeout = 115;
Hermann Pitton91607232006-12-07 21:45:28 -030048module_param(ir_rc5_key_timeout, int, 0644);
49
Pedro0938e312007-10-17 17:58:40 -030050static int repeat_delay = 500;
51module_param(repeat_delay, int, 0644);
52MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
53static int repeat_period = 33;
54module_param(repeat_period, int, 0644);
Joe Perchesac9bb7f2007-11-20 09:00:35 -030055MODULE_PARM_DESC(repeat_period, "repeat period between "
Pedro0938e312007-10-17 17:58:40 -030056 "keypresses when key is down");
57
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -030058static unsigned int disable_other_ir;
59module_param(disable_other_ir, int, 0644);
60MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
61 "alternative remotes from other manufacturers");
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define dprintk(fmt, arg...) if (ir_debug) \
64 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080065#define i2cdprintk(fmt, arg...) if (ir_debug) \
Jean Delvare1df8e982009-05-13 16:48:07 -030066 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -030068/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
Hermann Pitton91607232006-12-07 21:45:28 -030069static int saa7134_rc5_irq(struct saa7134_dev *dev);
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -030070static int saa7134_nec_irq(struct saa7134_dev *dev);
71static void nec_task(unsigned long data);
72static void saa7134_nec_timer(unsigned long data);
Hermann Pitton91607232006-12-07 21:45:28 -030073
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080074/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76static int build_key(struct saa7134_dev *dev)
77{
Hermann Pitton91607232006-12-07 21:45:28 -030078 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 u32 gpio, data;
80
Pedro0938e312007-10-17 17:58:40 -030081 /* here comes the additional handshake steps for some cards */
82 switch (dev->board) {
83 case SAA7134_BOARD_GOTVIEW_7135:
84 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
85 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
86 break;
87 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* rising SAA7134_GPIO_GPRESCAN reads the status */
89 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
90 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
91
92 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080093 if (ir->polling) {
94 if (ir->last_gpio == gpio)
95 return 0;
96 ir->last_gpio = gpio;
97 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080099 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
101 gpio, ir->mask_keycode, data);
102
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300103 switch (dev->board) {
104 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
105 if (data == ir->mask_keycode)
106 ir_input_nokey(ir->dev, &ir->ir);
107 else
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300108 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300109 return 0;
110 }
111
Peter Missel0602fbb2006-01-09 18:21:23 -0200112 if (ir->polling) {
113 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
114 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300115 ir_input_keydown(ir->dev, &ir->ir, data);
Peter Missel0602fbb2006-01-09 18:21:23 -0200116 } else {
117 ir_input_nokey(ir->dev, &ir->ir);
118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
Peter Missel0602fbb2006-01-09 18:21:23 -0200120 else { /* IRQ driven mode - handle key press and release in one go */
121 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
122 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300123 ir_input_keydown(ir->dev, &ir->ir, data);
Peter Missel0602fbb2006-01-09 18:21:23 -0200124 ir_input_nokey(ir->dev, &ir->ir);
125 }
126 }
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return 0;
129}
130
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800131/* --------------------- Chip specific I2C key builders ----------------- */
132
Lukas Karasd995a182009-11-24 12:06:52 -0300133static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
134{
135 int gpio;
136 int attempt = 0;
137 unsigned char b;
138
139 /* We need this to access GPI Used by the saa_readl macro. */
140 struct saa7134_dev *dev = ir->c->adapter->algo_data;
141
142 if (dev == NULL) {
143 dprintk("get_key_flydvb_trio: "
144 "gir->c->adapter->algo_data is NULL!\n");
145 return -EIO;
146 }
147
148 /* rising SAA7134_GPIGPRESCAN reads the status */
149 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
150 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
151
152 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
153
154 if (0x40000 & ~gpio)
155 return 0; /* No button press */
156
157 /* No button press - only before first key pressed */
158 if (b == 0xFF)
159 return 0;
160
161 /* poll IR chip */
162 /* weak up the IR chip */
163 b = 0;
164
165 while (1 != i2c_master_send(ir->c, &b, 1)) {
166 if ((attempt++) < 10) {
167 /*
168 * wait a bit for next attempt -
169 * I don't know how make it better
170 */
171 msleep(10);
172 continue;
173 }
174 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
175 "failed %dx\n", attempt);
176 return -EIO;
177 }
178 if (1 != i2c_master_recv(ir->c, &b, 1)) {
179 i2cdprintk("read error\n");
180 return -EIO;
181 }
182
183 *ir_key = b;
184 *ir_raw = b;
185 return 1;
186}
187
Brian Rogersba340b42008-10-13 08:37:06 -0300188static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
189 u32 *ir_raw)
190{
191 unsigned char b;
192 int gpio;
193
194 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
Jean Delvarec668f322009-05-13 16:48:50 -0300195 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Brian Rogersba340b42008-10-13 08:37:06 -0300196 if (dev == NULL) {
197 dprintk("get_key_msi_tvanywhere_plus: "
Jean Delvarec668f322009-05-13 16:48:50 -0300198 "gir->c->adapter->algo_data is NULL!\n");
Brian Rogersba340b42008-10-13 08:37:06 -0300199 return -EIO;
200 }
201
202 /* rising SAA7134_GPIO_GPRESCAN reads the status */
203
204 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
205 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
206
207 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
208
209 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
210 I2C receive if gpio&0x40 is not low. */
211
212 if (gpio & 0x40)
213 return 0; /* No button press */
214
215 /* GPIO says there is a button press. Get it. */
216
Jean Delvarec668f322009-05-13 16:48:50 -0300217 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Brian Rogersba340b42008-10-13 08:37:06 -0300218 i2cdprintk("read error\n");
219 return -EIO;
220 }
221
222 /* No button press */
223
224 if (b == 0xff)
225 return 0;
226
227 /* Button pressed */
228
229 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
230 *ir_key = b;
231 *ir_raw = b;
232 return 1;
233}
234
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800235static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
236{
237 unsigned char b;
238
239 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300240 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800241 i2cdprintk("read error\n");
242 return -EIO;
243 }
244
245 /* no button press */
246 if (b==0)
247 return 0;
248
249 /* repeating */
250 if (b & 0x80)
251 return 1;
252
253 *ir_key = b;
254 *ir_raw = b;
255 return 1;
256}
257
Thomas Genty177aaaf2006-11-29 21:57:24 -0300258static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
259{
260 unsigned char buf[5], cod4, code3, code4;
261
262 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300263 if (5 != i2c_master_recv(ir->c, buf, 5))
Thomas Genty177aaaf2006-11-29 21:57:24 -0300264 return -EIO;
265
266 cod4 = buf[4];
267 code4 = (cod4 >> 2);
268 code3 = buf[3];
269 if (code3 == 0)
270 /* no key pressed */
271 return 0;
272
273 /* return key */
274 *ir_key = code4;
275 *ir_raw = code4;
276 return 1;
277}
278
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300279
280static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
281{
282 unsigned char data[12];
283 u32 gpio;
284
Jean Delvarec668f322009-05-13 16:48:50 -0300285 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300286
287 /* rising SAA7134_GPIO_GPRESCAN reads the status */
288 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
289 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
290
291 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
292
Mauro Carvalho Chehab616f8872008-01-07 05:18:36 -0300293 if (0x400000 & ~gpio)
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300294 return 0; /* No button press */
295
Jean Delvarec668f322009-05-13 16:48:50 -0300296 ir->c->addr = 0x5a >> 1;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300297
Jean Delvarec668f322009-05-13 16:48:50 -0300298 if (12 != i2c_master_recv(ir->c, data, 12)) {
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300299 i2cdprintk("read error\n");
300 return -EIO;
301 }
302 /* IR of this card normally decode signals NEC-standard from
303 * - Sven IHOO MT 5.1R remote. xxyye718
304 * - Sven DVD HD-10xx remote. xxyyf708
305 * - BBK ...
306 * - mayby others
307 * So, skip not our, if disable full codes mode.
308 */
309 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
310 return 0;
311
Dmitri Belimov2d21ffe2009-09-07 20:36:05 -0300312 /* Wrong data decode fix */
313 if (data[9] != (unsigned char)(~data[8]))
314 return 0;
315
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300316 *ir_key = data[9];
317 *ir_raw = data[9];
318
319 return 1;
320}
321
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300322/* Common (grey or coloured) pinnacle PCTV remote handling
323 *
324 */
325static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
326 int parity_offset, int marker, int code_modulo)
327{
328 unsigned char b[4];
329 unsigned int start = 0,parity = 0,code = 0;
330
331 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300332 if (4 != i2c_master_recv(ir->c, b, 4)) {
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300333 i2cdprintk("read error\n");
334 return -EIO;
335 }
336
337 for (start = 0; start < ARRAY_SIZE(b); start++) {
338 if (b[start] == marker) {
339 code=b[(start+parity_offset + 1) % 4];
340 parity=b[(start+parity_offset) % 4];
341 }
342 }
343
344 /* Empty Request */
345 if (parity == 0)
346 return 0;
347
348 /* Repeating... */
349 if (ir->old == parity)
350 return 0;
351
352 ir->old = parity;
353
354 /* drop special codes when a key is held down a long time for the grey controller
355 In this case, the second bit of the code is asserted */
356 if (marker == 0xfe && (code & 0x40))
357 return 0;
358
359 code %= code_modulo;
360
361 *ir_raw = code;
362 *ir_key = code;
363
364 i2cdprintk("Pinnacle PCTV key %02x\n", code);
365
366 return 1;
367}
368
369/* The grey pinnacle PCTV remote
370 *
371 * There are one issue with this remote:
372 * - I2c packet does not change when the same key is pressed quickly. The workaround
373 * is to hold down each key for about half a second, so that another code is generated
374 * in the i2c packet, and the function can distinguish key presses.
375 *
376 * Sylvain Pasche <sylvain.pasche@gmail.com>
377 */
378static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
379{
380
381 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
382}
383
384
385/* The new pinnacle PCTV remote (with the colored buttons)
386 *
387 * Ricardo Cerqueira <v4l@cerqueira.org>
388 */
389static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
390{
391 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
392 *
393 * this is the only value that results in 42 unique
394 * codes < 128
395 */
396
397 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
398}
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400void saa7134_input_irq(struct saa7134_dev *dev)
401{
Hermann Pitton91607232006-12-07 21:45:28 -0300402 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300404 if (ir->nec_gpio) {
405 saa7134_nec_irq(dev);
406 } else if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300408 } else if (ir->rc5_gpio) {
409 saa7134_rc5_irq(dev);
410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413static void saa7134_input_timer(unsigned long data)
414{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300415 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300416 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300419 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Maxim Levitskyc4584732007-10-12 00:57:15 -0300422void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300423{
424 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300425 setup_timer(&ir->timer, saa7134_input_timer,
426 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300427 ir->timer.expires = jiffies + HZ;
428 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300429 } else if (ir->rc5_gpio) {
430 /* set timer_end for code completion */
431 init_timer(&ir->timer_end);
432 ir->timer_end.function = ir_rc5_timer_end;
433 ir->timer_end.data = (unsigned long)ir;
434 init_timer(&ir->timer_keyup);
435 ir->timer_keyup.function = ir_rc5_timer_keyup;
436 ir->timer_keyup.data = (unsigned long)ir;
437 ir->shift_by = 2;
438 ir->start = 0x2;
439 ir->addr = 0x17;
440 ir->rc5_key_timeout = ir_rc5_key_timeout;
441 ir->rc5_remote_gap = ir_rc5_remote_gap;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300442 } else if (ir->nec_gpio) {
443 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
444 (unsigned long)dev);
445 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300446 }
447}
448
Maxim Levitskyc4584732007-10-12 00:57:15 -0300449void saa7134_ir_stop(struct saa7134_dev *dev)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300450{
451 if (dev->remote->polling)
452 del_timer_sync(&dev->remote->timer);
453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455int saa7134_input_init1(struct saa7134_dev *dev)
456{
Hermann Pitton91607232006-12-07 21:45:28 -0300457 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500458 struct input_dev *input_dev;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300459 struct ir_scancode_table *ir_codes = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 u32 mask_keycode = 0;
461 u32 mask_keydown = 0;
462 u32 mask_keyup = 0;
463 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300464 int rc5_gpio = 0;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300465 int nec_gpio = 0;
Mauro Carvalho Chehab971e8292009-12-14 13:53:37 -0300466 u64 ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300467 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800469 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return -ENODEV;
471 if (disable_ir)
472 return -ENODEV;
473
474 /* detect & configure */
475 switch (dev->board) {
476 case SAA7134_BOARD_FLYVIDEO2000:
477 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800478 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800479 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Eugene Yudin23389b82009-08-29 09:32:11 -0300480 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300481 ir_codes = &ir_codes_flyvideo_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 mask_keycode = 0xEC00000;
483 mask_keydown = 0x0040000;
484 break;
485 case SAA7134_BOARD_CINERGY400:
486 case SAA7134_BOARD_CINERGY600:
487 case SAA7134_BOARD_CINERGY600_MK3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300488 ir_codes = &ir_codes_cinergy_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 mask_keycode = 0x00003f;
490 mask_keyup = 0x040000;
491 break;
492 case SAA7134_BOARD_ECS_TVP3XP:
493 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300494 ir_codes = &ir_codes_eztv_table;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700495 mask_keycode = 0x00017c;
496 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700498 break;
499 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 case SAA7134_BOARD_AVACSSMARTTV:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300501 ir_codes = &ir_codes_pixelview_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 mask_keycode = 0x00001F;
503 mask_keyup = 0x000020;
504 polling = 50; // ms
505 break;
506 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700507 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 case SAA7134_BOARD_AVERMEDIA_305:
509 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700510 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
Vasiliy Temnikov5a5e1da2009-08-26 22:10:55 -0300511 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700512 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300513 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Andy Shevchenkodf0dbbe2009-04-08 14:01:19 -0300514 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700515 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Albert Grahamd2761f22007-12-09 09:44:38 -0300516 case SAA7134_BOARD_AVERMEDIA_M102:
Pham Thanh Nam6a2d8022008-12-30 23:26:09 -0300517 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300518 ir_codes = &ir_codes_avermedia_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 mask_keycode = 0x0007C8;
520 mask_keydown = 0x000010;
521 polling = 50; // ms
522 /* Set GPIO pin2 to high to enable the IR controller */
523 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
524 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
525 break;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300526 case SAA7134_BOARD_AVERMEDIA_M135A:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300527 ir_codes = &ir_codes_avermedia_m135a_table;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300528 mask_keydown = 0x0040000;
529 mask_keycode = 0x00013f;
530 nec_gpio = 1;
531 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300532 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300533 case SAA7134_BOARD_AVERMEDIA_A16AR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300534 ir_codes = &ir_codes_avermedia_table;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300535 mask_keycode = 0x02F200;
536 mask_keydown = 0x000400;
537 polling = 50; // ms
538 /* Without this we won't receive key up events */
539 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
540 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800541 break;
Tim Farrington6e501a32008-06-15 13:33:42 -0300542 case SAA7134_BOARD_AVERMEDIA_A16D:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300543 ir_codes = &ir_codes_avermedia_a16d_table;
Tim Farrington6e501a32008-06-15 13:33:42 -0300544 mask_keycode = 0x02F200;
545 mask_keydown = 0x000400;
546 polling = 50; /* ms */
547 /* Without this we won't receive key up events */
548 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
549 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
550 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800551 case SAA7134_BOARD_KWORLD_TERMINATOR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300552 ir_codes = &ir_codes_pixelview_table;
James R. Webbdc2286c2005-11-08 21:37:00 -0800553 mask_keycode = 0x00001f;
554 mask_keyup = 0x000060;
555 polling = 50; // ms
556 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700557 case SAA7134_BOARD_MANLI_MTV001:
558 case SAA7134_BOARD_MANLI_MTV002:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300559 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300560 mask_keycode = 0x001f00;
561 mask_keyup = 0x004000;
562 polling = 50; /* ms */
563 break;
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800564 case SAA7134_BOARD_BEHOLD_409FM:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300565 case SAA7134_BOARD_BEHOLD_401:
566 case SAA7134_BOARD_BEHOLD_403:
567 case SAA7134_BOARD_BEHOLD_403FM:
568 case SAA7134_BOARD_BEHOLD_405:
569 case SAA7134_BOARD_BEHOLD_405FM:
570 case SAA7134_BOARD_BEHOLD_407:
571 case SAA7134_BOARD_BEHOLD_407FM:
572 case SAA7134_BOARD_BEHOLD_409:
573 case SAA7134_BOARD_BEHOLD_505FM:
Dmitri Belimov9c6f97a2009-12-21 02:00:38 -0300574 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
575 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300576 case SAA7134_BOARD_BEHOLD_507_9FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300577 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
578 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300579 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300580 mask_keycode = 0x003f00;
581 mask_keyup = 0x004000;
582 polling = 50; /* ms */
583 break;
584 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300585 ir_codes = &ir_codes_behold_columbus_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300586 mask_keycode = 0x003f00;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700587 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700588 polling = 50; // ms
589 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800590 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300591 ir_codes = &ir_codes_pctv_sedna_table;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800592 mask_keycode = 0x001f00;
593 mask_keyup = 0x004000;
594 polling = 50; // ms
595 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800596 case SAA7134_BOARD_GOTVIEW_7135:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300597 ir_codes = &ir_codes_gotview7135_table;
Pedro0938e312007-10-17 17:58:40 -0300598 mask_keycode = 0x0003CC;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800599 mask_keydown = 0x000010;
Pedro0938e312007-10-17 17:58:40 -0300600 polling = 5; /* ms */
601 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800602 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200604 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700605 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300606 ir_codes = &ir_codes_videomate_tv_pvr_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 mask_keycode = 0x00003F;
608 mask_keyup = 0x400000;
609 polling = 50; // ms
610 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300611 case SAA7134_BOARD_PROTEUS_2309:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300612 ir_codes = &ir_codes_proteus_2309_table;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300613 mask_keycode = 0x00007F;
614 mask_keyup = 0x000080;
615 polling = 50; // ms
616 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800617 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
618 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300619 ir_codes = &ir_codes_videomate_tv_pvr_table;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800620 mask_keycode = 0x003F00;
621 mask_keyup = 0x040000;
622 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300623 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200624 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300625 case SAA7134_BOARD_FLYDVBTDUO:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300626 ir_codes = &ir_codes_flydvb_table;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200627 mask_keycode = 0x0001F00;
628 mask_keydown = 0x0040000;
629 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300630 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300631 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Mauro Carvalho Chehabdfb4ba12009-08-20 10:13:40 -0300632 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300633 ir_codes = &ir_codes_asus_pc39_table;
Hermann Pitton91607232006-12-07 21:45:28 -0300634 mask_keydown = 0x0040000;
635 rc5_gpio = 1;
636 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300637 case SAA7134_BOARD_ENCORE_ENLTV:
638 case SAA7134_BOARD_ENCORE_ENLTV_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300639 ir_codes = &ir_codes_encore_enltv_table;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300640 mask_keycode = 0x00007f;
641 mask_keyup = 0x040000;
642 polling = 50; // ms
643 break;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300644 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300645 ir_codes = &ir_codes_encore_enltv_fm53_table;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300646 mask_keydown = 0x0040000;
647 mask_keycode = 0x00007f;
648 nec_gpio = 1;
649 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300650 case SAA7134_BOARD_10MOONSTVMASTER3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300651 ir_codes = &ir_codes_encore_enltv_table;
Tony Wan480f75a2007-05-11 11:33:50 -0300652 mask_keycode = 0x5f80000;
653 mask_keyup = 0x8000000;
654 polling = 50; //ms
655 break;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300656 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300657 ir_codes = &ir_codes_genius_tvgo_a11mce_table;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300658 mask_keycode = 0xff;
659 mask_keydown = 0xf00000;
660 polling = 50; /* ms */
661 break;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300662 case SAA7134_BOARD_REAL_ANGEL_220:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300663 ir_codes = &ir_codes_real_audio_220_32_keys_table;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300664 mask_keycode = 0x3f00;
665 mask_keyup = 0x4000;
666 polling = 50; /* ms */
667 break;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300668 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300669 ir_codes = &ir_codes_kworld_plus_tv_analog_table;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300670 mask_keycode = 0x7f;
671 polling = 40; /* ms */
672 break;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300673 case SAA7134_BOARD_VIDEOMATE_S350:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300674 ir_codes = &ir_codes_videomate_s350_table;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300675 mask_keycode = 0x003f00;
676 mask_keydown = 0x040000;
677 break;
Michael Obst0700ade2009-10-31 14:05:42 -0300678 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
679 ir_codes = &ir_codes_winfast_table;
680 mask_keycode = 0x5f00;
681 mask_keyup = 0x020000;
Michael Krufky117e1342009-11-01 11:16:10 -0300682 polling = 50; /* ms */
Michael Obst0700ade2009-10-31 14:05:42 -0300683 break;
Lukas Karasd995a182009-11-24 12:06:52 -0300684 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686 if (NULL == ir_codes) {
687 printk("%s: Oops: IR config error [card=%d]\n",
688 dev->name, dev->board);
689 return -ENODEV;
690 }
691
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500692 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
693 input_dev = input_allocate_device();
694 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300695 err = -ENOMEM;
696 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500699 ir->dev = input_dev;
700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /* init hardware-specific stuff */
702 ir->mask_keycode = mask_keycode;
703 ir->mask_keydown = mask_keydown;
704 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800705 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300706 ir->rc5_gpio = rc5_gpio;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300707 ir->nec_gpio = nec_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 /* init input device */
710 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
711 saa7134_boards[dev->board].name);
712 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
713 pci_name(dev->pci));
714
Mauro Carvalho Chehab579e7d62009-12-11 11:20:59 -0300715 err = ir_input_init(input_dev, &ir->ir, ir_type);
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300716 if (err < 0)
717 goto err_out_free;
718
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500719 input_dev->name = ir->name;
720 input_dev->phys = ir->phys;
721 input_dev->id.bustype = BUS_PCI;
722 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500724 input_dev->id.vendor = dev->pci->subsystem_vendor;
725 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500727 input_dev->id.vendor = dev->pci->vendor;
728 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300730 input_dev->dev.parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300733 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -0300735 err = ir_input_register(ir->dev, ir_codes, NULL, MODULE_NAME);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300736 if (err)
737 goto err_out_stop;
738
Pedro0938e312007-10-17 17:58:40 -0300739 /* the remote isn't as bouncy as a keyboard */
740 ir->dev->rep[REP_DELAY] = repeat_delay;
741 ir->dev->rep[REP_PERIOD] = repeat_period;
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300744
745 err_out_stop:
746 saa7134_ir_stop(dev);
747 dev->remote = NULL;
748 err_out_free:
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300749 kfree(ir);
750 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}
752
753void saa7134_input_fini(struct saa7134_dev *dev)
754{
755 if (NULL == dev->remote)
756 return;
757
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300758 saa7134_ir_stop(dev);
Mauro Carvalho Chehab38ef6aa2009-12-11 09:47:42 -0300759 ir_input_unregister(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 kfree(dev->remote);
761 dev->remote = NULL;
762}
763
Jean Delvarec668f322009-05-13 16:48:50 -0300764void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800765{
Jean Delvare43e16ea2009-10-02 05:47:08 -0300766 struct i2c_board_info info;
Jean Delvarec668f322009-05-13 16:48:50 -0300767
Jean Delvarec668f322009-05-13 16:48:50 -0300768 struct i2c_msg msg_msi = {
769 .addr = 0x50,
770 .flags = I2C_M_RD,
771 .len = 0,
772 .buf = NULL,
773 };
774
Jean Delvarec668f322009-05-13 16:48:50 -0300775 int rc;
776
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800777 if (disable_ir) {
Jean Delvarec668f322009-05-13 16:48:50 -0300778 dprintk("IR has been disabled, not probing for i2c remote\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800779 return;
780 }
781
Jean Delvare43e16ea2009-10-02 05:47:08 -0300782 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300783 memset(&dev->init_data, 0, sizeof(dev->init_data));
Jean Delvare43e16ea2009-10-02 05:47:08 -0300784 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300785
786 switch (dev->board) {
787 case SAA7134_BOARD_PINNACLE_PCTV_110i:
788 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300789 dev->init_data.name = "Pinnacle PCTV";
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300790 if (pinnacle_remote == 0) {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300791 dev->init_data.get_key = get_key_pinnacle_color;
792 dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300793 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300794 } else {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300795 dev->init_data.get_key = get_key_pinnacle_grey;
796 dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300797 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300798 }
799 break;
800 case SAA7134_BOARD_UPMOST_PURPLE_TV:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300801 dev->init_data.name = "Purple TV";
802 dev->init_data.get_key = get_key_purpletv;
803 dev->init_data.ir_codes = &ir_codes_purpletv_table;
Jean Delvareaef02aa2009-10-02 08:47:22 -0300804 info.addr = 0x7a;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300805 break;
806 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300807 dev->init_data.name = "MSI TV@nywhere Plus";
808 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
809 dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300810 info.addr = 0x30;
Jean Delvareec218a42009-05-13 16:51:46 -0300811 /* MSI TV@nywhere Plus controller doesn't seem to
812 respond to probes unless we read something from
813 an existing device. Weird...
814 REVISIT: might no longer be needed */
815 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
816 dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
817 msg_msi.addr, dev->i2c_adap.name,
818 (1 == rc) ? "yes" : "no");
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300819 break;
820 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300821 dev->init_data.name = "HVR 1110";
822 dev->init_data.get_key = get_key_hvr1110;
823 dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
Jean Delvare30093e82009-10-02 09:48:04 -0300824 info.addr = 0x71;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300825 break;
826 case SAA7134_BOARD_BEHOLD_607FM_MK3:
827 case SAA7134_BOARD_BEHOLD_607FM_MK5:
828 case SAA7134_BOARD_BEHOLD_609FM_MK3:
829 case SAA7134_BOARD_BEHOLD_609FM_MK5:
830 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
831 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
832 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
833 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
834 case SAA7134_BOARD_BEHOLD_M6:
835 case SAA7134_BOARD_BEHOLD_M63:
836 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
837 case SAA7134_BOARD_BEHOLD_H6:
Dmitri Belimov2012c872009-08-26 01:01:12 -0300838 case SAA7134_BOARD_BEHOLD_X7:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300839 dev->init_data.name = "BeholdTV";
840 dev->init_data.get_key = get_key_beholdm6xx;
841 dev->init_data.ir_codes = &ir_codes_behold_table;
Dmitri Belimov2ffbb642010-03-04 02:40:37 -0300842 dev->init_data.type = IR_TYPE_NEC;
Jean Delvare30093e82009-10-02 09:48:04 -0300843 info.addr = 0x2d;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300844 break;
Jean Delvared9a88e62009-05-13 16:52:44 -0300845 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
846 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
Jean Delvare43e16ea2009-10-02 05:47:08 -0300847 info.addr = 0x40;
Jean Delvared9a88e62009-05-13 16:52:44 -0300848 break;
Lukas Karasd995a182009-11-24 12:06:52 -0300849 case SAA7134_BOARD_FLYDVB_TRIO:
850 dev->init_data.name = "FlyDVB Trio";
851 dev->init_data.get_key = get_key_flydvb_trio;
852 dev->init_data.ir_codes = &ir_codes_flydvb_table;
853 info.addr = 0x0b;
854 break;
Jean Delvare30093e82009-10-02 09:48:04 -0300855 default:
856 dprintk("No I2C IR support for board %x\n", dev->board);
857 return;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300858 }
859
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300860 if (dev->init_data.name)
Jean Delvare43e16ea2009-10-02 05:47:08 -0300861 info.platform_data = &dev->init_data;
Jean Delvare30093e82009-10-02 09:48:04 -0300862 i2c_new_device(&dev->i2c_adap, &info);
Jean Delvarec668f322009-05-13 16:48:50 -0300863}
864
Hermann Pitton91607232006-12-07 21:45:28 -0300865static int saa7134_rc5_irq(struct saa7134_dev *dev)
866{
867 struct card_ir *ir = dev->remote;
868 struct timeval tv;
869 u32 gap;
870 unsigned long current_jiffies, timeout;
871
872 /* get time of bit */
873 current_jiffies = jiffies;
874 do_gettimeofday(&tv);
875
876 /* avoid overflow with gap >1s */
877 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
878 gap = 200000;
879 } else {
880 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
881 tv.tv_usec - ir->base_time.tv_usec;
882 }
883
884 /* active code => add bit */
885 if (ir->active) {
886 /* only if in the code (otherwise spurious IRQ or timer
887 late) */
888 if (ir->last_bit < 28) {
889 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
890 ir_rc5_remote_gap;
891 ir->code |= 1 << ir->last_bit;
892 }
893 /* starting new code */
894 } else {
895 ir->active = 1;
896 ir->code = 0;
897 ir->base_time = tv;
898 ir->last_bit = 0;
899
900 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
901 mod_timer(&ir->timer_end, timeout);
902 }
903
904 return 1;
905}
906
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300907
908/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
909 The first pulse (start) has 9 + 4.5 ms
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 */
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300911
912static void saa7134_nec_timer(unsigned long data)
913{
914 struct saa7134_dev *dev = (struct saa7134_dev *) data;
915 struct card_ir *ir = dev->remote;
916
917 dprintk("Cancel key repeat\n");
918
919 ir_input_nokey(ir->dev, &ir->ir);
920}
921
922static void nec_task(unsigned long data)
923{
924 struct saa7134_dev *dev = (struct saa7134_dev *) data;
925 struct card_ir *ir;
926 struct timeval tv;
927 int count, pulse, oldpulse, gap;
928 u32 ircode = 0, not_code = 0;
929 int ngap = 0;
930
931 if (!data) {
932 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
933 /* GPIO will be kept disabled */
934 return;
935 }
936
937 ir = dev->remote;
938
939 /* rising SAA7134_GPIO_GPRESCAN reads the status */
940 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
941 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
942
943 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
944 pulse = oldpulse;
945
946 do_gettimeofday(&tv);
947 ir->base_time = tv;
948
949 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
950 Unfortunately, using IRQ to decode pulse didn't work, since it uses
951 a pulse train of 38KHz. This means one pulse on each 52 us
952 */
953 do {
954 /* Wait until the end of pulse/space or 5 ms */
955 for (count = 0; count < 500; count++) {
956 udelay(10);
957 /* rising SAA7134_GPIO_GPRESCAN reads the status */
958 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
959 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
960 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
961 & ir->mask_keydown;
962 if (pulse != oldpulse)
963 break;
964 }
965
966 do_gettimeofday(&tv);
967 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
968 tv.tv_usec - ir->base_time.tv_usec;
969
970 if (!pulse) {
971 /* Bit 0 has 560 us, while bit 1 has 1120 us.
972 Do something only if bit == 1
973 */
974 if (ngap && (gap > 560 + 280)) {
975 unsigned int shift = ngap - 1;
976
977 /* Address first, then command */
978 if (shift < 8) {
979 shift += 8;
980 ircode |= 1 << shift;
981 } else if (shift < 16) {
982 not_code |= 1 << shift;
983 } else if (shift < 24) {
984 shift -= 16;
985 ircode |= 1 << shift;
986 } else {
987 shift -= 24;
988 not_code |= 1 << shift;
989 }
990 }
991 ngap++;
992 }
993
994
995 ir->base_time = tv;
996
997 /* TIMEOUT - Long pulse */
998 if (gap >= 5000)
999 break;
1000 oldpulse = pulse;
1001 } while (ngap < 32);
1002
1003 if (ngap == 32) {
1004 /* FIXME: should check if not_code == ~ircode */
1005 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
1006
1007 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1008 ir->code, ircode, not_code);
1009
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -03001010 ir_input_keydown(ir->dev, &ir->ir, ir->code);
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -03001011 } else
1012 dprintk("Repeat last key\n");
1013
1014 /* Keep repeating the last key */
1015 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
1016
1017 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
1018}
1019
1020static int saa7134_nec_irq(struct saa7134_dev *dev)
1021{
1022 struct card_ir *ir = dev->remote;
1023
1024 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
1025 tasklet_schedule(&ir->tlet);
1026
1027 return 1;
1028}