blob: 411a8410620e616b2d978630dae80f7d00453d32 [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
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300105 ir_input_keydown(ir->dev, &ir->ir, data);
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300106 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)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300112 ir_input_keydown(ir->dev, &ir->ir, data);
Peter Missel0602fbb2006-01-09 18:21:23 -0200113 } 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)))) {
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -0300120 ir_input_keydown(ir->dev, &ir->ir, data);
Peter Missel0602fbb2006-01-09 18:21:23 -0200121 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
Lukas Karasd995a182009-11-24 12:06:52 -0300130static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
131{
132 int gpio;
133 int attempt = 0;
134 unsigned char b;
135
136 /* We need this to access GPI Used by the saa_readl macro. */
137 struct saa7134_dev *dev = ir->c->adapter->algo_data;
138
139 if (dev == NULL) {
140 dprintk("get_key_flydvb_trio: "
141 "gir->c->adapter->algo_data is NULL!\n");
142 return -EIO;
143 }
144
145 /* rising SAA7134_GPIGPRESCAN reads the status */
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 if (0x40000 & ~gpio)
152 return 0; /* No button press */
153
154 /* No button press - only before first key pressed */
155 if (b == 0xFF)
156 return 0;
157
158 /* poll IR chip */
159 /* weak up the IR chip */
160 b = 0;
161
162 while (1 != i2c_master_send(ir->c, &b, 1)) {
163 if ((attempt++) < 10) {
164 /*
165 * wait a bit for next attempt -
166 * I don't know how make it better
167 */
168 msleep(10);
169 continue;
170 }
171 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
172 "failed %dx\n", attempt);
173 return -EIO;
174 }
175 if (1 != i2c_master_recv(ir->c, &b, 1)) {
176 i2cdprintk("read error\n");
177 return -EIO;
178 }
179
180 *ir_key = b;
181 *ir_raw = b;
182 return 1;
183}
184
Brian Rogersba340b42008-10-13 08:37:06 -0300185static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
186 u32 *ir_raw)
187{
188 unsigned char b;
189 int gpio;
190
191 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
Jean Delvarec668f322009-05-13 16:48:50 -0300192 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Brian Rogersba340b42008-10-13 08:37:06 -0300193 if (dev == NULL) {
194 dprintk("get_key_msi_tvanywhere_plus: "
Jean Delvarec668f322009-05-13 16:48:50 -0300195 "gir->c->adapter->algo_data is NULL!\n");
Brian Rogersba340b42008-10-13 08:37:06 -0300196 return -EIO;
197 }
198
199 /* rising SAA7134_GPIO_GPRESCAN reads the status */
200
201 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
202 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
203
204 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
205
206 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
207 I2C receive if gpio&0x40 is not low. */
208
209 if (gpio & 0x40)
210 return 0; /* No button press */
211
212 /* GPIO says there is a button press. Get it. */
213
Jean Delvarec668f322009-05-13 16:48:50 -0300214 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Brian Rogersba340b42008-10-13 08:37:06 -0300215 i2cdprintk("read error\n");
216 return -EIO;
217 }
218
219 /* No button press */
220
221 if (b == 0xff)
222 return 0;
223
224 /* Button pressed */
225
226 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
227 *ir_key = b;
228 *ir_raw = b;
229 return 1;
230}
231
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800232static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
233{
234 unsigned char b;
235
236 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300237 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800238 i2cdprintk("read error\n");
239 return -EIO;
240 }
241
242 /* no button press */
243 if (b==0)
244 return 0;
245
246 /* repeating */
247 if (b & 0x80)
248 return 1;
249
250 *ir_key = b;
251 *ir_raw = b;
252 return 1;
253}
254
Thomas Genty177aaaf2006-11-29 21:57:24 -0300255static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
256{
257 unsigned char buf[5], cod4, code3, code4;
258
259 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300260 if (5 != i2c_master_recv(ir->c, buf, 5))
Thomas Genty177aaaf2006-11-29 21:57:24 -0300261 return -EIO;
262
263 cod4 = buf[4];
264 code4 = (cod4 >> 2);
265 code3 = buf[3];
266 if (code3 == 0)
267 /* no key pressed */
268 return 0;
269
270 /* return key */
271 *ir_key = code4;
272 *ir_raw = code4;
273 return 1;
274}
275
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300276
277static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
278{
279 unsigned char data[12];
280 u32 gpio;
281
Jean Delvarec668f322009-05-13 16:48:50 -0300282 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300283
284 /* rising SAA7134_GPIO_GPRESCAN reads the status */
285 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
286 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
287
288 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
289
Mauro Carvalho Chehab616f8872008-01-07 05:18:36 -0300290 if (0x400000 & ~gpio)
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300291 return 0; /* No button press */
292
Jean Delvarec668f322009-05-13 16:48:50 -0300293 ir->c->addr = 0x5a >> 1;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300294
Jean Delvarec668f322009-05-13 16:48:50 -0300295 if (12 != i2c_master_recv(ir->c, data, 12)) {
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300296 i2cdprintk("read error\n");
297 return -EIO;
298 }
299 /* IR of this card normally decode signals NEC-standard from
300 * - Sven IHOO MT 5.1R remote. xxyye718
301 * - Sven DVD HD-10xx remote. xxyyf708
302 * - BBK ...
303 * - mayby others
304 * So, skip not our, if disable full codes mode.
305 */
306 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
307 return 0;
308
Dmitri Belimov2d21ffe2009-09-07 20:36:05 -0300309 /* Wrong data decode fix */
310 if (data[9] != (unsigned char)(~data[8]))
311 return 0;
312
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300313 *ir_key = data[9];
314 *ir_raw = data[9];
315
316 return 1;
317}
318
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300319/* Common (grey or coloured) pinnacle PCTV remote handling
320 *
321 */
322static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
323 int parity_offset, int marker, int code_modulo)
324{
325 unsigned char b[4];
326 unsigned int start = 0,parity = 0,code = 0;
327
328 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300329 if (4 != i2c_master_recv(ir->c, b, 4)) {
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300330 i2cdprintk("read error\n");
331 return -EIO;
332 }
333
334 for (start = 0; start < ARRAY_SIZE(b); start++) {
335 if (b[start] == marker) {
336 code=b[(start+parity_offset + 1) % 4];
337 parity=b[(start+parity_offset) % 4];
338 }
339 }
340
341 /* Empty Request */
342 if (parity == 0)
343 return 0;
344
345 /* Repeating... */
346 if (ir->old == parity)
347 return 0;
348
349 ir->old = parity;
350
351 /* drop special codes when a key is held down a long time for the grey controller
352 In this case, the second bit of the code is asserted */
353 if (marker == 0xfe && (code & 0x40))
354 return 0;
355
356 code %= code_modulo;
357
358 *ir_raw = code;
359 *ir_key = code;
360
361 i2cdprintk("Pinnacle PCTV key %02x\n", code);
362
363 return 1;
364}
365
366/* The grey pinnacle PCTV remote
367 *
368 * There are one issue with this remote:
369 * - I2c packet does not change when the same key is pressed quickly. The workaround
370 * is to hold down each key for about half a second, so that another code is generated
371 * in the i2c packet, and the function can distinguish key presses.
372 *
373 * Sylvain Pasche <sylvain.pasche@gmail.com>
374 */
375static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
376{
377
378 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
379}
380
381
382/* The new pinnacle PCTV remote (with the colored buttons)
383 *
384 * Ricardo Cerqueira <v4l@cerqueira.org>
385 */
386static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
387{
388 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
389 *
390 * this is the only value that results in 42 unique
391 * codes < 128
392 */
393
394 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397void saa7134_input_irq(struct saa7134_dev *dev)
398{
Hermann Pitton91607232006-12-07 21:45:28 -0300399 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300401 if (ir->nec_gpio) {
402 saa7134_nec_irq(dev);
403 } else if (!ir->polling && !ir->rc5_gpio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 build_key(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300405 } else if (ir->rc5_gpio) {
406 saa7134_rc5_irq(dev);
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410static void saa7134_input_timer(unsigned long data)
411{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300412 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Hermann Pitton91607232006-12-07 21:45:28 -0300413 struct card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300416 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417}
418
Maxim Levitskyc4584732007-10-12 00:57:15 -0300419void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300420{
421 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300422 setup_timer(&ir->timer, saa7134_input_timer,
423 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300424 ir->timer.expires = jiffies + HZ;
425 add_timer(&ir->timer);
Hermann Pitton91607232006-12-07 21:45:28 -0300426 } else if (ir->rc5_gpio) {
427 /* set timer_end for code completion */
428 init_timer(&ir->timer_end);
429 ir->timer_end.function = ir_rc5_timer_end;
430 ir->timer_end.data = (unsigned long)ir;
431 init_timer(&ir->timer_keyup);
432 ir->timer_keyup.function = ir_rc5_timer_keyup;
433 ir->timer_keyup.data = (unsigned long)ir;
434 ir->shift_by = 2;
435 ir->start = 0x2;
436 ir->addr = 0x17;
437 ir->rc5_key_timeout = ir_rc5_key_timeout;
438 ir->rc5_remote_gap = ir_rc5_remote_gap;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300439 } else if (ir->nec_gpio) {
440 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
441 (unsigned long)dev);
442 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300443 }
444}
445
Maxim Levitskyc4584732007-10-12 00:57:15 -0300446void saa7134_ir_stop(struct saa7134_dev *dev)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300447{
448 if (dev->remote->polling)
449 del_timer_sync(&dev->remote->timer);
450}
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452int saa7134_input_init1(struct saa7134_dev *dev)
453{
Hermann Pitton91607232006-12-07 21:45:28 -0300454 struct card_ir *ir;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500455 struct input_dev *input_dev;
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300456 struct ir_scancode_table *ir_codes = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 u32 mask_keycode = 0;
458 u32 mask_keydown = 0;
459 u32 mask_keyup = 0;
460 int polling = 0;
Hermann Pitton91607232006-12-07 21:45:28 -0300461 int rc5_gpio = 0;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300462 int nec_gpio = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 int ir_type = IR_TYPE_OTHER;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300464 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800466 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return -ENODEV;
468 if (disable_ir)
469 return -ENODEV;
470
471 /* detect & configure */
472 switch (dev->board) {
473 case SAA7134_BOARD_FLYVIDEO2000:
474 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800475 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800476 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Eugene Yudin23389b82009-08-29 09:32:11 -0300477 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300478 ir_codes = &ir_codes_flyvideo_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 mask_keycode = 0xEC00000;
480 mask_keydown = 0x0040000;
481 break;
482 case SAA7134_BOARD_CINERGY400:
483 case SAA7134_BOARD_CINERGY600:
484 case SAA7134_BOARD_CINERGY600_MK3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300485 ir_codes = &ir_codes_cinergy_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 mask_keycode = 0x00003f;
487 mask_keyup = 0x040000;
488 break;
489 case SAA7134_BOARD_ECS_TVP3XP:
490 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300491 ir_codes = &ir_codes_eztv_table;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700492 mask_keycode = 0x00017c;
493 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700495 break;
496 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 case SAA7134_BOARD_AVACSSMARTTV:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300498 ir_codes = &ir_codes_pixelview_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 mask_keycode = 0x00001F;
500 mask_keyup = 0x000020;
501 polling = 50; // ms
502 break;
503 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700504 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 case SAA7134_BOARD_AVERMEDIA_305:
506 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700507 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
Vasiliy Temnikov5a5e1da2009-08-26 22:10:55 -0300508 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700509 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300510 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Andy Shevchenkodf0dbbe2009-04-08 14:01:19 -0300511 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700512 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Albert Grahamd2761f22007-12-09 09:44:38 -0300513 case SAA7134_BOARD_AVERMEDIA_M102:
Pham Thanh Nam6a2d8022008-12-30 23:26:09 -0300514 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300515 ir_codes = &ir_codes_avermedia_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 mask_keycode = 0x0007C8;
517 mask_keydown = 0x000010;
518 polling = 50; // ms
519 /* Set GPIO pin2 to high to enable the IR controller */
520 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
521 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
522 break;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300523 case SAA7134_BOARD_AVERMEDIA_M135A:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300524 ir_codes = &ir_codes_avermedia_m135a_table;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300525 mask_keydown = 0x0040000;
526 mask_keycode = 0x00013f;
527 nec_gpio = 1;
528 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300529 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300530 case SAA7134_BOARD_AVERMEDIA_A16AR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300531 ir_codes = &ir_codes_avermedia_table;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300532 mask_keycode = 0x02F200;
533 mask_keydown = 0x000400;
534 polling = 50; // ms
535 /* Without this we won't receive key up events */
536 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
537 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800538 break;
Tim Farrington6e501a32008-06-15 13:33:42 -0300539 case SAA7134_BOARD_AVERMEDIA_A16D:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300540 ir_codes = &ir_codes_avermedia_a16d_table;
Tim Farrington6e501a32008-06-15 13:33:42 -0300541 mask_keycode = 0x02F200;
542 mask_keydown = 0x000400;
543 polling = 50; /* ms */
544 /* Without this we won't receive key up events */
545 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
546 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
547 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800548 case SAA7134_BOARD_KWORLD_TERMINATOR:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300549 ir_codes = &ir_codes_pixelview_table;
James R. Webbdc2286c2005-11-08 21:37:00 -0800550 mask_keycode = 0x00001f;
551 mask_keyup = 0x000060;
552 polling = 50; // ms
553 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700554 case SAA7134_BOARD_MANLI_MTV001:
555 case SAA7134_BOARD_MANLI_MTV002:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300556 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300557 mask_keycode = 0x001f00;
558 mask_keyup = 0x004000;
559 polling = 50; /* ms */
560 break;
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800561 case SAA7134_BOARD_BEHOLD_409FM:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300562 case SAA7134_BOARD_BEHOLD_401:
563 case SAA7134_BOARD_BEHOLD_403:
564 case SAA7134_BOARD_BEHOLD_403FM:
565 case SAA7134_BOARD_BEHOLD_405:
566 case SAA7134_BOARD_BEHOLD_405FM:
567 case SAA7134_BOARD_BEHOLD_407:
568 case SAA7134_BOARD_BEHOLD_407FM:
569 case SAA7134_BOARD_BEHOLD_409:
570 case SAA7134_BOARD_BEHOLD_505FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300571 case SAA7134_BOARD_BEHOLD_505RDS:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300572 case SAA7134_BOARD_BEHOLD_507_9FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300573 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
574 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300575 ir_codes = &ir_codes_manli_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300576 mask_keycode = 0x003f00;
577 mask_keyup = 0x004000;
578 polling = 50; /* ms */
579 break;
580 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300581 ir_codes = &ir_codes_behold_columbus_table;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300582 mask_keycode = 0x003f00;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700583 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700584 polling = 50; // ms
585 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800586 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300587 ir_codes = &ir_codes_pctv_sedna_table;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800588 mask_keycode = 0x001f00;
589 mask_keyup = 0x004000;
590 polling = 50; // ms
591 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800592 case SAA7134_BOARD_GOTVIEW_7135:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300593 ir_codes = &ir_codes_gotview7135_table;
Pedro0938e312007-10-17 17:58:40 -0300594 mask_keycode = 0x0003CC;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800595 mask_keydown = 0x000010;
Pedro0938e312007-10-17 17:58:40 -0300596 polling = 5; /* ms */
597 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800598 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200600 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700601 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300602 ir_codes = &ir_codes_videomate_tv_pvr_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 mask_keycode = 0x00003F;
604 mask_keyup = 0x400000;
605 polling = 50; // ms
606 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300607 case SAA7134_BOARD_PROTEUS_2309:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300608 ir_codes = &ir_codes_proteus_2309_table;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300609 mask_keycode = 0x00007F;
610 mask_keyup = 0x000080;
611 polling = 50; // ms
612 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800613 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
614 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300615 ir_codes = &ir_codes_videomate_tv_pvr_table;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800616 mask_keycode = 0x003F00;
617 mask_keyup = 0x040000;
618 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300619 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200620 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300621 case SAA7134_BOARD_FLYDVBTDUO:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300622 ir_codes = &ir_codes_flydvb_table;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200623 mask_keycode = 0x0001F00;
624 mask_keydown = 0x0040000;
625 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300626 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300627 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Mauro Carvalho Chehabdfb4ba12009-08-20 10:13:40 -0300628 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300629 ir_codes = &ir_codes_asus_pc39_table;
Hermann Pitton91607232006-12-07 21:45:28 -0300630 mask_keydown = 0x0040000;
631 rc5_gpio = 1;
632 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300633 case SAA7134_BOARD_ENCORE_ENLTV:
634 case SAA7134_BOARD_ENCORE_ENLTV_FM:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300635 ir_codes = &ir_codes_encore_enltv_table;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300636 mask_keycode = 0x00007f;
637 mask_keyup = 0x040000;
638 polling = 50; // ms
639 break;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300640 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300641 ir_codes = &ir_codes_encore_enltv_fm53_table;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300642 mask_keydown = 0x0040000;
643 mask_keycode = 0x00007f;
644 nec_gpio = 1;
645 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300646 case SAA7134_BOARD_10MOONSTVMASTER3:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300647 ir_codes = &ir_codes_encore_enltv_table;
Tony Wan480f75a2007-05-11 11:33:50 -0300648 mask_keycode = 0x5f80000;
649 mask_keyup = 0x8000000;
650 polling = 50; //ms
651 break;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300652 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300653 ir_codes = &ir_codes_genius_tvgo_a11mce_table;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300654 mask_keycode = 0xff;
655 mask_keydown = 0xf00000;
656 polling = 50; /* ms */
657 break;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300658 case SAA7134_BOARD_REAL_ANGEL_220:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300659 ir_codes = &ir_codes_real_audio_220_32_keys_table;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300660 mask_keycode = 0x3f00;
661 mask_keyup = 0x4000;
662 polling = 50; /* ms */
663 break;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300664 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300665 ir_codes = &ir_codes_kworld_plus_tv_analog_table;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300666 mask_keycode = 0x7f;
667 polling = 40; /* ms */
668 break;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300669 case SAA7134_BOARD_VIDEOMATE_S350:
Mauro Carvalho Chehab715a2232009-08-29 14:15:55 -0300670 ir_codes = &ir_codes_videomate_s350_table;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300671 mask_keycode = 0x003f00;
672 mask_keydown = 0x040000;
673 break;
Michael Obst0700ade2009-10-31 14:05:42 -0300674 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
675 ir_codes = &ir_codes_winfast_table;
676 mask_keycode = 0x5f00;
677 mask_keyup = 0x020000;
Michael Krufky117e1342009-11-01 11:16:10 -0300678 polling = 50; /* ms */
Michael Obst0700ade2009-10-31 14:05:42 -0300679 break;
Lukas Karasd995a182009-11-24 12:06:52 -0300680 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682 if (NULL == ir_codes) {
683 printk("%s: Oops: IR config error [card=%d]\n",
684 dev->name, dev->board);
685 return -ENODEV;
686 }
687
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500688 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
689 input_dev = input_allocate_device();
690 if (!ir || !input_dev) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300691 err = -ENOMEM;
692 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500695 ir->dev = input_dev;
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* init hardware-specific stuff */
698 ir->mask_keycode = mask_keycode;
699 ir->mask_keydown = mask_keydown;
700 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800701 ir->polling = polling;
Hermann Pitton91607232006-12-07 21:45:28 -0300702 ir->rc5_gpio = rc5_gpio;
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300703 ir->nec_gpio = nec_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 /* init input device */
706 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
707 saa7134_boards[dev->board].name);
708 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
709 pci_name(dev->pci));
710
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300711 err = ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
712 if (err < 0)
713 goto err_out_free;
714
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500715 input_dev->name = ir->name;
716 input_dev->phys = ir->phys;
717 input_dev->id.bustype = BUS_PCI;
718 input_dev->id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (dev->pci->subsystem_vendor) {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500720 input_dev->id.vendor = dev->pci->subsystem_vendor;
721 input_dev->id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 } else {
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500723 input_dev->id.vendor = dev->pci->vendor;
724 input_dev->id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
Dmitry Torokhov2c8a3a32007-07-16 09:28:15 -0300726 input_dev->dev.parent = &dev->pci->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 dev->remote = ir;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300729 saa7134_ir_start(dev, ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300731 err = input_register_device(ir->dev);
732 if (err)
733 goto err_out_stop;
734
Pedro0938e312007-10-17 17:58:40 -0300735 /* the remote isn't as bouncy as a keyboard */
736 ir->dev->rep[REP_DELAY] = repeat_delay;
737 ir->dev->rep[REP_PERIOD] = repeat_period;
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300740
741 err_out_stop:
742 saa7134_ir_stop(dev);
743 dev->remote = NULL;
744 err_out_free:
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300745 ir_input_free(input_dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300746 input_free_device(input_dev);
747 kfree(ir);
748 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749}
750
751void saa7134_input_fini(struct saa7134_dev *dev)
752{
753 if (NULL == dev->remote)
754 return;
755
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300756 saa7134_ir_stop(dev);
Mauro Carvalho Chehab055cd552009-11-29 08:19:59 -0300757 ir_input_free(dev->remote->dev);
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500758 input_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 kfree(dev->remote);
760 dev->remote = NULL;
761}
762
Jean Delvarec668f322009-05-13 16:48:50 -0300763void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800764{
Jean Delvare43e16ea2009-10-02 05:47:08 -0300765 struct i2c_board_info info;
Jean Delvarec668f322009-05-13 16:48:50 -0300766
Jean Delvarec668f322009-05-13 16:48:50 -0300767 struct i2c_msg msg_msi = {
768 .addr = 0x50,
769 .flags = I2C_M_RD,
770 .len = 0,
771 .buf = NULL,
772 };
773
Jean Delvarec668f322009-05-13 16:48:50 -0300774 int rc;
775
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800776 if (disable_ir) {
Jean Delvarec668f322009-05-13 16:48:50 -0300777 dprintk("IR has been disabled, not probing for i2c remote\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800778 return;
779 }
780
Jean Delvare43e16ea2009-10-02 05:47:08 -0300781 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300782 memset(&dev->init_data, 0, sizeof(dev->init_data));
Jean Delvare43e16ea2009-10-02 05:47:08 -0300783 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300784
785 switch (dev->board) {
786 case SAA7134_BOARD_PINNACLE_PCTV_110i:
787 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300788 dev->init_data.name = "Pinnacle PCTV";
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300789 if (pinnacle_remote == 0) {
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300790 dev->init_data.get_key = get_key_pinnacle_color;
791 dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300792 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300793 } else {
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300794 dev->init_data.get_key = get_key_pinnacle_grey;
795 dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300796 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300797 }
798 break;
799 case SAA7134_BOARD_UPMOST_PURPLE_TV:
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300800 dev->init_data.name = "Purple TV";
801 dev->init_data.get_key = get_key_purpletv;
802 dev->init_data.ir_codes = &ir_codes_purpletv_table;
Jean Delvareaef02aa2009-10-02 08:47:22 -0300803 info.addr = 0x7a;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300804 break;
805 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300806 dev->init_data.name = "MSI TV@nywhere Plus";
807 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
808 dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300809 info.addr = 0x30;
Jean Delvareec218a42009-05-13 16:51:46 -0300810 /* MSI TV@nywhere Plus controller doesn't seem to
811 respond to probes unless we read something from
812 an existing device. Weird...
813 REVISIT: might no longer be needed */
814 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
815 dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
816 msg_msi.addr, dev->i2c_adap.name,
817 (1 == rc) ? "yes" : "no");
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300818 break;
819 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300820 dev->init_data.name = "HVR 1110";
821 dev->init_data.get_key = get_key_hvr1110;
822 dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
Jean Delvare30093e82009-10-02 09:48:04 -0300823 info.addr = 0x71;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300824 break;
825 case SAA7134_BOARD_BEHOLD_607FM_MK3:
826 case SAA7134_BOARD_BEHOLD_607FM_MK5:
827 case SAA7134_BOARD_BEHOLD_609FM_MK3:
828 case SAA7134_BOARD_BEHOLD_609FM_MK5:
829 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
830 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
831 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
832 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
833 case SAA7134_BOARD_BEHOLD_M6:
834 case SAA7134_BOARD_BEHOLD_M63:
835 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
836 case SAA7134_BOARD_BEHOLD_H6:
Dmitri Belimov2012c872009-08-26 01:01:12 -0300837 case SAA7134_BOARD_BEHOLD_X7:
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300838 dev->init_data.name = "BeholdTV";
839 dev->init_data.get_key = get_key_beholdm6xx;
840 dev->init_data.ir_codes = &ir_codes_behold_table;
Jean Delvare30093e82009-10-02 09:48:04 -0300841 info.addr = 0x2d;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300842 break;
Jean Delvared9a88e62009-05-13 16:52:44 -0300843 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
844 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
Jean Delvare43e16ea2009-10-02 05:47:08 -0300845 info.addr = 0x40;
Jean Delvared9a88e62009-05-13 16:52:44 -0300846 break;
Lukas Karasd995a182009-11-24 12:06:52 -0300847 case SAA7134_BOARD_FLYDVB_TRIO:
848 dev->init_data.name = "FlyDVB Trio";
849 dev->init_data.get_key = get_key_flydvb_trio;
850 dev->init_data.ir_codes = &ir_codes_flydvb_table;
851 info.addr = 0x0b;
852 break;
Jean Delvare30093e82009-10-02 09:48:04 -0300853 default:
854 dprintk("No I2C IR support for board %x\n", dev->board);
855 return;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300856 }
857
Mauro Carvalho Chehab7aedd5e2009-09-07 02:22:01 -0300858 if (dev->init_data.name)
Jean Delvare43e16ea2009-10-02 05:47:08 -0300859 info.platform_data = &dev->init_data;
Jean Delvare30093e82009-10-02 09:48:04 -0300860 i2c_new_device(&dev->i2c_adap, &info);
Jean Delvarec668f322009-05-13 16:48:50 -0300861}
862
Hermann Pitton91607232006-12-07 21:45:28 -0300863static int saa7134_rc5_irq(struct saa7134_dev *dev)
864{
865 struct card_ir *ir = dev->remote;
866 struct timeval tv;
867 u32 gap;
868 unsigned long current_jiffies, timeout;
869
870 /* get time of bit */
871 current_jiffies = jiffies;
872 do_gettimeofday(&tv);
873
874 /* avoid overflow with gap >1s */
875 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
876 gap = 200000;
877 } else {
878 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
879 tv.tv_usec - ir->base_time.tv_usec;
880 }
881
882 /* active code => add bit */
883 if (ir->active) {
884 /* only if in the code (otherwise spurious IRQ or timer
885 late) */
886 if (ir->last_bit < 28) {
887 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
888 ir_rc5_remote_gap;
889 ir->code |= 1 << ir->last_bit;
890 }
891 /* starting new code */
892 } else {
893 ir->active = 1;
894 ir->code = 0;
895 ir->base_time = tv;
896 ir->last_bit = 0;
897
898 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
899 mod_timer(&ir->timer_end, timeout);
900 }
901
902 return 1;
903}
904
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300905
906/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
907 The first pulse (start) has 9 + 4.5 ms
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 */
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -0300909
910static void saa7134_nec_timer(unsigned long data)
911{
912 struct saa7134_dev *dev = (struct saa7134_dev *) data;
913 struct card_ir *ir = dev->remote;
914
915 dprintk("Cancel key repeat\n");
916
917 ir_input_nokey(ir->dev, &ir->ir);
918}
919
920static void nec_task(unsigned long data)
921{
922 struct saa7134_dev *dev = (struct saa7134_dev *) data;
923 struct card_ir *ir;
924 struct timeval tv;
925 int count, pulse, oldpulse, gap;
926 u32 ircode = 0, not_code = 0;
927 int ngap = 0;
928
929 if (!data) {
930 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
931 /* GPIO will be kept disabled */
932 return;
933 }
934
935 ir = dev->remote;
936
937 /* rising SAA7134_GPIO_GPRESCAN reads the status */
938 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
939 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
940
941 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
942 pulse = oldpulse;
943
944 do_gettimeofday(&tv);
945 ir->base_time = tv;
946
947 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
948 Unfortunately, using IRQ to decode pulse didn't work, since it uses
949 a pulse train of 38KHz. This means one pulse on each 52 us
950 */
951 do {
952 /* Wait until the end of pulse/space or 5 ms */
953 for (count = 0; count < 500; count++) {
954 udelay(10);
955 /* rising SAA7134_GPIO_GPRESCAN reads the status */
956 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
957 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
958 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
959 & ir->mask_keydown;
960 if (pulse != oldpulse)
961 break;
962 }
963
964 do_gettimeofday(&tv);
965 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
966 tv.tv_usec - ir->base_time.tv_usec;
967
968 if (!pulse) {
969 /* Bit 0 has 560 us, while bit 1 has 1120 us.
970 Do something only if bit == 1
971 */
972 if (ngap && (gap > 560 + 280)) {
973 unsigned int shift = ngap - 1;
974
975 /* Address first, then command */
976 if (shift < 8) {
977 shift += 8;
978 ircode |= 1 << shift;
979 } else if (shift < 16) {
980 not_code |= 1 << shift;
981 } else if (shift < 24) {
982 shift -= 16;
983 ircode |= 1 << shift;
984 } else {
985 shift -= 24;
986 not_code |= 1 << shift;
987 }
988 }
989 ngap++;
990 }
991
992
993 ir->base_time = tv;
994
995 /* TIMEOUT - Long pulse */
996 if (gap >= 5000)
997 break;
998 oldpulse = pulse;
999 } while (ngap < 32);
1000
1001 if (ngap == 32) {
1002 /* FIXME: should check if not_code == ~ircode */
1003 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
1004
1005 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1006 ir->code, ircode, not_code);
1007
Mauro Carvalho Chehab8573b742009-11-27 22:40:22 -03001008 ir_input_keydown(ir->dev, &ir->ir, ir->code);
Mauro Carvalho Chehab622ecb32008-08-05 10:03:17 -03001009 } else
1010 dprintk("Repeat last key\n");
1011
1012 /* Keep repeating the last key */
1013 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
1014
1015 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
1016}
1017
1018static int saa7134_nec_irq(struct saa7134_dev *dev)
1019{
1020 struct card_ir *ir = dev->remote;
1021
1022 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
1023 tasklet_schedule(&ir->tlet);
1024
1025 return 1;
1026}