blob: cd39aea30389e016684c6b0c7506bf8d86fcb0a1 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include "saa7134-reg.h"
28#include "saa7134.h"
29
Mauro Carvalho Chehabd3025482010-10-06 22:02:58 -030030#define MODULE_NAME "saa7134"
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030031
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030032static unsigned int disable_ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033module_param(disable_ir, int, 0444);
34MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
35
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030036static unsigned int ir_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037module_param(ir_debug, int, 0644);
38MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
39
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030040static int pinnacle_remote;
Sylvain Pascheb93eedb2006-03-25 23:14:42 -030041module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
42MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
43
Adrian Bunkc408a6f2006-12-28 12:47:47 -030044static int ir_rc5_remote_gap = 885;
Hermann Pitton91607232006-12-07 21:45:28 -030045module_param(ir_rc5_remote_gap, int, 0644);
Hermann Pitton91607232006-12-07 21:45:28 -030046
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -030047static unsigned int disable_other_ir;
48module_param(disable_other_ir, int, 0644);
49MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
50 "alternative remotes from other manufacturers");
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define dprintk(fmt, arg...) if (ir_debug) \
53 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080054#define i2cdprintk(fmt, arg...) if (ir_debug) \
Jean Delvare1df8e982009-05-13 16:48:07 -030055 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -030057/* Helper function for raw decoding at GPIO16 or GPIO18 */
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -030058static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
Hermann Pitton91607232006-12-07 21:45:28 -030059
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -080060/* -------------------- GPIO generic keycode builder -------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62static int build_key(struct saa7134_dev *dev)
63{
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -030064 struct saa7134_card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 u32 gpio, data;
66
Pedro0938e312007-10-17 17:58:40 -030067 /* here comes the additional handshake steps for some cards */
68 switch (dev->board) {
69 case SAA7134_BOARD_GOTVIEW_7135:
70 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
71 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
72 break;
73 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 /* rising SAA7134_GPIO_GPRESCAN reads the status */
75 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
76 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
77
78 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080079 if (ir->polling) {
80 if (ir->last_gpio == gpio)
81 return 0;
82 ir->last_gpio = gpio;
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -080085 data = ir_extract_bits(gpio, ir->mask_keycode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
87 gpio, ir->mask_keycode, data);
88
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -030089 switch (dev->board) {
90 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
91 if (data == ir->mask_keycode)
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -030092 rc_keyup(ir->dev);
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -030093 else
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -030094 rc_keydown_notimeout(ir->dev, data, 0);
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -030095 return 0;
96 }
97
Peter Missel0602fbb2006-01-09 18:21:23 -020098 if (ir->polling) {
99 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
100 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -0300101 rc_keydown_notimeout(ir->dev, data, 0);
Peter Missel0602fbb2006-01-09 18:21:23 -0200102 } else {
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -0300103 rc_keyup(ir->dev);
Peter Missel0602fbb2006-01-09 18:21:23 -0200104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
Peter Missel0602fbb2006-01-09 18:21:23 -0200106 else { /* IRQ driven mode - handle key press and release in one go */
107 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
108 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -0300109 rc_keydown_notimeout(ir->dev, data, 0);
110 rc_keyup(ir->dev);
Peter Missel0602fbb2006-01-09 18:21:23 -0200111 }
112 }
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return 0;
115}
116
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800117/* --------------------- Chip specific I2C key builders ----------------- */
118
Lukas Karasd995a182009-11-24 12:06:52 -0300119static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
120{
121 int gpio;
122 int attempt = 0;
123 unsigned char b;
124
125 /* We need this to access GPI Used by the saa_readl macro. */
126 struct saa7134_dev *dev = ir->c->adapter->algo_data;
127
128 if (dev == NULL) {
Dan Carpenter129c34d2010-05-26 11:58:10 -0300129 i2cdprintk("get_key_flydvb_trio: "
130 "ir->c->adapter->algo_data is NULL!\n");
Lukas Karasd995a182009-11-24 12:06:52 -0300131 return -EIO;
132 }
133
134 /* rising SAA7134_GPIGPRESCAN reads the status */
135 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
136 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
137
138 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
139
140 if (0x40000 & ~gpio)
141 return 0; /* No button press */
142
143 /* No button press - only before first key pressed */
144 if (b == 0xFF)
145 return 0;
146
147 /* poll IR chip */
148 /* weak up the IR chip */
149 b = 0;
150
151 while (1 != i2c_master_send(ir->c, &b, 1)) {
152 if ((attempt++) < 10) {
153 /*
154 * wait a bit for next attempt -
155 * I don't know how make it better
156 */
157 msleep(10);
158 continue;
159 }
160 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
161 "failed %dx\n", attempt);
162 return -EIO;
163 }
164 if (1 != i2c_master_recv(ir->c, &b, 1)) {
165 i2cdprintk("read error\n");
166 return -EIO;
167 }
168
169 *ir_key = b;
170 *ir_raw = b;
171 return 1;
172}
173
Brian Rogersba340b42008-10-13 08:37:06 -0300174static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
175 u32 *ir_raw)
176{
177 unsigned char b;
178 int gpio;
179
180 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
Jean Delvarec668f322009-05-13 16:48:50 -0300181 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Brian Rogersba340b42008-10-13 08:37:06 -0300182 if (dev == NULL) {
Dan Carpenter129c34d2010-05-26 11:58:10 -0300183 i2cdprintk("get_key_msi_tvanywhere_plus: "
184 "ir->c->adapter->algo_data is NULL!\n");
Brian Rogersba340b42008-10-13 08:37:06 -0300185 return -EIO;
186 }
187
188 /* rising SAA7134_GPIO_GPRESCAN reads the status */
189
190 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
191 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
192
193 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
194
195 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
196 I2C receive if gpio&0x40 is not low. */
197
198 if (gpio & 0x40)
199 return 0; /* No button press */
200
201 /* GPIO says there is a button press. Get it. */
202
Jean Delvarec668f322009-05-13 16:48:50 -0300203 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Brian Rogersba340b42008-10-13 08:37:06 -0300204 i2cdprintk("read error\n");
205 return -EIO;
206 }
207
208 /* No button press */
209
210 if (b == 0xff)
211 return 0;
212
213 /* Button pressed */
214
215 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
216 *ir_key = b;
217 *ir_raw = b;
218 return 1;
219}
220
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800221static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
222{
223 unsigned char b;
224
225 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300226 if (1 != i2c_master_recv(ir->c, &b, 1)) {
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800227 i2cdprintk("read error\n");
228 return -EIO;
229 }
230
231 /* no button press */
232 if (b==0)
233 return 0;
234
235 /* repeating */
236 if (b & 0x80)
237 return 1;
238
239 *ir_key = b;
240 *ir_raw = b;
241 return 1;
242}
243
Thomas Genty177aaaf2006-11-29 21:57:24 -0300244static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
245{
246 unsigned char buf[5], cod4, code3, code4;
247
248 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300249 if (5 != i2c_master_recv(ir->c, buf, 5))
Thomas Genty177aaaf2006-11-29 21:57:24 -0300250 return -EIO;
251
252 cod4 = buf[4];
253 code4 = (cod4 >> 2);
254 code3 = buf[3];
255 if (code3 == 0)
256 /* no key pressed */
257 return 0;
258
259 /* return key */
260 *ir_key = code4;
261 *ir_raw = code4;
262 return 1;
263}
264
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300265
266static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
267{
268 unsigned char data[12];
269 u32 gpio;
270
Jean Delvarec668f322009-05-13 16:48:50 -0300271 struct saa7134_dev *dev = ir->c->adapter->algo_data;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300272
273 /* rising SAA7134_GPIO_GPRESCAN reads the status */
274 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
275 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
276
277 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
278
Mauro Carvalho Chehab616f8872008-01-07 05:18:36 -0300279 if (0x400000 & ~gpio)
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300280 return 0; /* No button press */
281
Jean Delvarec668f322009-05-13 16:48:50 -0300282 ir->c->addr = 0x5a >> 1;
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300283
Jean Delvarec668f322009-05-13 16:48:50 -0300284 if (12 != i2c_master_recv(ir->c, data, 12)) {
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300285 i2cdprintk("read error\n");
286 return -EIO;
287 }
288 /* IR of this card normally decode signals NEC-standard from
289 * - Sven IHOO MT 5.1R remote. xxyye718
290 * - Sven DVD HD-10xx remote. xxyyf708
291 * - BBK ...
292 * - mayby others
293 * So, skip not our, if disable full codes mode.
294 */
295 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
296 return 0;
297
Dmitri Belimov2d21ffe2009-09-07 20:36:05 -0300298 /* Wrong data decode fix */
299 if (data[9] != (unsigned char)(~data[8]))
300 return 0;
301
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300302 *ir_key = data[9];
303 *ir_raw = data[9];
304
305 return 1;
306}
307
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300308/* Common (grey or coloured) pinnacle PCTV remote handling
309 *
310 */
311static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
312 int parity_offset, int marker, int code_modulo)
313{
314 unsigned char b[4];
315 unsigned int start = 0,parity = 0,code = 0;
316
317 /* poll IR chip */
Jean Delvarec668f322009-05-13 16:48:50 -0300318 if (4 != i2c_master_recv(ir->c, b, 4)) {
Mauro Carvalho Chehab1c22dad2008-07-17 22:31:29 -0300319 i2cdprintk("read error\n");
320 return -EIO;
321 }
322
323 for (start = 0; start < ARRAY_SIZE(b); start++) {
324 if (b[start] == marker) {
325 code=b[(start+parity_offset + 1) % 4];
326 parity=b[(start+parity_offset) % 4];
327 }
328 }
329
330 /* Empty Request */
331 if (parity == 0)
332 return 0;
333
334 /* Repeating... */
335 if (ir->old == parity)
336 return 0;
337
338 ir->old = parity;
339
340 /* drop special codes when a key is held down a long time for the grey controller
341 In this case, the second bit of the code is asserted */
342 if (marker == 0xfe && (code & 0x40))
343 return 0;
344
345 code %= code_modulo;
346
347 *ir_raw = code;
348 *ir_key = code;
349
350 i2cdprintk("Pinnacle PCTV key %02x\n", code);
351
352 return 1;
353}
354
355/* The grey pinnacle PCTV remote
356 *
357 * There are one issue with this remote:
358 * - I2c packet does not change when the same key is pressed quickly. The workaround
359 * is to hold down each key for about half a second, so that another code is generated
360 * in the i2c packet, and the function can distinguish key presses.
361 *
362 * Sylvain Pasche <sylvain.pasche@gmail.com>
363 */
364static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
365{
366
367 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
368}
369
370
371/* The new pinnacle PCTV remote (with the colored buttons)
372 *
373 * Ricardo Cerqueira <v4l@cerqueira.org>
374 */
375static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
376{
377 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
378 *
379 * this is the only value that results in 42 unique
380 * codes < 128
381 */
382
383 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386void saa7134_input_irq(struct saa7134_dev *dev)
387{
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300388 struct saa7134_card_ir *ir;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300389
390 if (!dev || !dev->remote)
391 return;
392
393 ir = dev->remote;
394 if (!ir->running)
395 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -0300397 if (!ir->polling && !ir->raw_decode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 build_key(dev);
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300399 } else if (ir->raw_decode) {
400 saa7134_raw_decode_irq(dev);
Hermann Pitton91607232006-12-07 21:45:28 -0300401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
404static void saa7134_input_timer(unsigned long data)
405{
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300406 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300407 struct saa7134_card_ir *ir = dev->remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 build_key(dev);
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300410 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
Mauro Carvalho Chehabe051f692010-09-29 13:46:23 -0300413static void ir_raw_decode_timer_end(unsigned long data)
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300414{
415 struct saa7134_dev *dev = (struct saa7134_dev *)data;
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300416 struct saa7134_card_ir *ir = dev->remote;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300417
Mauro Carvalho Chehabada39632010-03-21 12:24:24 -0300418 ir_raw_event_handle(dev->remote->dev);
Mauro Carvalho Chehab9f154782010-03-21 13:00:55 -0300419
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300420 ir->active = false;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300421}
422
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300423static int __saa7134_ir_start(void *priv)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300424{
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300425 struct saa7134_dev *dev = priv;
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300426 struct saa7134_card_ir *ir;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300427
428 if (!dev)
429 return -EINVAL;
430
431 ir = dev->remote;
432 if (!ir)
433 return -EINVAL;
434
Mauro Carvalho Chehab02108942010-03-20 00:25:37 -0300435 if (ir->running)
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300436 return 0;
Mauro Carvalho Chehab02108942010-03-20 00:25:37 -0300437
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300438 ir->running = true;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300439 if (ir->polling) {
Dmitry Torokhovb4ba7882007-05-21 11:41:02 -0300440 setup_timer(&ir->timer, saa7134_input_timer,
441 (unsigned long)dev);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300442 ir->timer.expires = jiffies + HZ;
443 add_timer(&ir->timer);
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300444 } else if (ir->raw_decode) {
445 /* set timer_end for code completion */
446 init_timer(&ir->timer_end);
447 ir->timer_end.function = ir_raw_decode_timer_end;
448 ir->timer_end.data = (unsigned long)dev;
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300449 ir->active = false;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300450 }
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300451
452 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300453}
454
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300455static void __saa7134_ir_stop(void *priv)
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300456{
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300457 struct saa7134_dev *dev = priv;
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300458 struct saa7134_card_ir *ir;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300459
460 if (!dev)
461 return;
462
463 ir = dev->remote;
464 if (!ir)
465 return;
Mauro Carvalho Chehab02108942010-03-20 00:25:37 -0300466
467 if (!ir->running)
468 return;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300469 if (dev->remote->polling)
470 del_timer_sync(&dev->remote->timer);
Mauro Carvalho Chehab9f154782010-03-21 13:00:55 -0300471 else if (ir->raw_decode) {
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300472 del_timer_sync(&ir->timer_end);
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300473 ir->active = false;
Mauro Carvalho Chehab9f154782010-03-21 13:00:55 -0300474 }
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300475
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300476 ir->running = false;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300477
478 return;
Mauro Carvalho Chehab02108942010-03-20 00:25:37 -0300479}
480
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300481int saa7134_ir_start(struct saa7134_dev *dev)
482{
483 if (dev->remote->users)
484 return __saa7134_ir_start(dev);
485
486 return 0;
487}
488
489void saa7134_ir_stop(struct saa7134_dev *dev)
490{
491 if (dev->remote->users)
492 __saa7134_ir_stop(dev);
493}
494
David Härdemand8b4b582010-10-29 16:08:23 -0300495static int saa7134_ir_open(struct rc_dev *rc)
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300496{
David Härdemand8b4b582010-10-29 16:08:23 -0300497 struct saa7134_dev *dev = rc->priv;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300498
499 dev->remote->users++;
500 return __saa7134_ir_start(dev);
501}
502
David Härdemand8b4b582010-10-29 16:08:23 -0300503static void saa7134_ir_close(struct rc_dev *rc)
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300504{
David Härdemand8b4b582010-10-29 16:08:23 -0300505 struct saa7134_dev *dev = rc->priv;
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300506
507 dev->remote->users--;
508 if (!dev->remote->users)
509 __saa7134_ir_stop(dev);
510}
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512int saa7134_input_init1(struct saa7134_dev *dev)
513{
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300514 struct saa7134_card_ir *ir;
David Härdemand8b4b582010-10-29 16:08:23 -0300515 struct rc_dev *rc;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300516 char *ir_codes = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 u32 mask_keycode = 0;
518 u32 mask_keydown = 0;
519 u32 mask_keyup = 0;
520 int polling = 0;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300521 int raw_decode = 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300522 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Ricardo Cerqueiracb2444d2005-11-08 21:38:47 -0800524 if (dev->has_remote != SAA7134_REMOTE_GPIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 return -ENODEV;
526 if (disable_ir)
527 return -ENODEV;
528
529 /* detect & configure */
530 switch (dev->board) {
531 case SAA7134_BOARD_FLYVIDEO2000:
532 case SAA7134_BOARD_FLYVIDEO3000:
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800533 case SAA7134_BOARD_FLYTVPLATINUM_FM:
Arnaud Patard6af90ab2005-11-08 21:36:55 -0800534 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
Eugene Yudin23389b82009-08-29 09:32:11 -0300535 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300536 ir_codes = RC_MAP_FLYVIDEO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 mask_keycode = 0xEC00000;
538 mask_keydown = 0x0040000;
539 break;
540 case SAA7134_BOARD_CINERGY400:
541 case SAA7134_BOARD_CINERGY600:
542 case SAA7134_BOARD_CINERGY600_MK3:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300543 ir_codes = RC_MAP_CINERGY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 mask_keycode = 0x00003f;
545 mask_keyup = 0x040000;
546 break;
547 case SAA7134_BOARD_ECS_TVP3XP:
548 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300549 ir_codes = RC_MAP_EZTV;
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700550 mask_keycode = 0x00017c;
551 mask_keyup = 0x000002;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 polling = 50; // ms
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700553 break;
554 case SAA7134_BOARD_KWORLD_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 case SAA7134_BOARD_AVACSSMARTTV:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300556 ir_codes = RC_MAP_PIXELVIEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 mask_keycode = 0x00001F;
558 mask_keyup = 0x000020;
559 polling = 50; // ms
560 break;
561 case SAA7134_BOARD_MD2819:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700562 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 case SAA7134_BOARD_AVERMEDIA_305:
564 case SAA7134_BOARD_AVERMEDIA_307:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700565 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
Vasiliy Temnikov5a5e1da2009-08-26 22:10:55 -0300566 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700567 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
Mikhail Fedotov3ac706d2006-10-06 20:23:47 -0300568 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
Andy Shevchenkodf0dbbe2009-04-08 14:01:19 -0300569 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700570 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
Albert Grahamd2761f22007-12-09 09:44:38 -0300571 case SAA7134_BOARD_AVERMEDIA_M102:
Pham Thanh Nam6a2d8022008-12-30 23:26:09 -0300572 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300573 ir_codes = RC_MAP_AVERMEDIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 mask_keycode = 0x0007C8;
575 mask_keydown = 0x000010;
576 polling = 50; // ms
577 /* Set GPIO pin2 to high to enable the IR controller */
578 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
579 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
580 break;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300581 case SAA7134_BOARD_AVERMEDIA_M135A:
Herton Ronaldo Krzesinski63fc31e2010-05-10 15:43:31 -0300582 ir_codes = RC_MAP_AVERMEDIA_M135A;
Mauro Carvalho Chehab2f16f632010-04-03 18:51:50 -0300583 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
584 mask_keyup = 0x0040000;
Mauro Carvalho Chehabd152b8b2010-03-20 00:23:30 -0300585 mask_keycode = 0xffff;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300586 raw_decode = 1;
Mauro Carvalho Chehab36f6bb92008-06-26 17:03:00 -0300587 break;
Herton Ronaldo Krzesinski9e1d9e72010-05-08 02:23:37 -0300588 case SAA7134_BOARD_AVERMEDIA_M733A:
589 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
590 mask_keydown = 0x0040000;
591 mask_keyup = 0x0040000;
592 mask_keycode = 0xffff;
593 raw_decode = 1;
594 break;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300595 case SAA7134_BOARD_AVERMEDIA_777:
pasky@ucw.cz29e0f1a2006-11-12 14:23:32 -0300596 case SAA7134_BOARD_AVERMEDIA_A16AR:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300597 ir_codes = RC_MAP_AVERMEDIA;
pasky@ucw.cz450efcf2006-11-12 14:22:32 -0300598 mask_keycode = 0x02F200;
599 mask_keydown = 0x000400;
600 polling = 50; // ms
601 /* Without this we won't receive key up events */
602 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
603 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
Linus Torvalds4dd74062006-11-13 09:50:11 -0800604 break;
Tim Farrington6e501a32008-06-15 13:33:42 -0300605 case SAA7134_BOARD_AVERMEDIA_A16D:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300606 ir_codes = RC_MAP_AVERMEDIA_A16D;
Tim Farrington6e501a32008-06-15 13:33:42 -0300607 mask_keycode = 0x02F200;
608 mask_keydown = 0x000400;
609 polling = 50; /* ms */
610 /* Without this we won't receive key up events */
611 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
612 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
613 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800614 case SAA7134_BOARD_KWORLD_TERMINATOR:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300615 ir_codes = RC_MAP_PIXELVIEW;
James R. Webbdc2286c2005-11-08 21:37:00 -0800616 mask_keycode = 0x00001f;
617 mask_keyup = 0x000060;
618 polling = 50; // ms
619 break;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700620 case SAA7134_BOARD_MANLI_MTV001:
621 case SAA7134_BOARD_MANLI_MTV002:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300622 ir_codes = RC_MAP_MANLI;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300623 mask_keycode = 0x001f00;
624 mask_keyup = 0x004000;
625 polling = 50; /* ms */
626 break;
Nickolay V. Shmyreva8ff4172005-11-08 21:36:16 -0800627 case SAA7134_BOARD_BEHOLD_409FM:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300628 case SAA7134_BOARD_BEHOLD_401:
629 case SAA7134_BOARD_BEHOLD_403:
630 case SAA7134_BOARD_BEHOLD_403FM:
631 case SAA7134_BOARD_BEHOLD_405:
632 case SAA7134_BOARD_BEHOLD_405FM:
633 case SAA7134_BOARD_BEHOLD_407:
634 case SAA7134_BOARD_BEHOLD_407FM:
635 case SAA7134_BOARD_BEHOLD_409:
636 case SAA7134_BOARD_BEHOLD_505FM:
Dmitri Belimov9c6f97a2009-12-21 02:00:38 -0300637 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
638 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
Andrey J. Melnikoff (TEMHOTA)e8018c92008-01-07 05:17:39 -0300639 case SAA7134_BOARD_BEHOLD_507_9FM:
Dmitri Belimov84d728c2009-04-23 02:32:49 -0300640 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
641 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300642 ir_codes = RC_MAP_MANLI;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300643 mask_keycode = 0x003f00;
644 mask_keyup = 0x004000;
645 polling = 50; /* ms */
646 break;
647 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300648 ir_codes = RC_MAP_BEHOLD_COLUMBUS;
Dmitry Belimovb34dddb2008-04-23 14:09:08 -0300649 mask_keycode = 0x003f00;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700650 mask_keyup = 0x004000;
Mauro Carvalho Chehabac19ecc2005-06-23 22:05:09 -0700651 polling = 50; // ms
652 break;
Ricardo Cerqueira17ce1ff2005-11-08 21:38:47 -0800653 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300654 ir_codes = RC_MAP_PCTV_SEDNA;
Pavel Mihaylovc3d93192005-11-08 21:38:43 -0800655 mask_keycode = 0x001f00;
656 mask_keyup = 0x004000;
657 polling = 50; // ms
658 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800659 case SAA7134_BOARD_GOTVIEW_7135:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300660 ir_codes = RC_MAP_GOTVIEW7135;
Pedro0938e312007-10-17 17:58:40 -0300661 mask_keycode = 0x0003CC;
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800662 mask_keydown = 0x000010;
Pedro0938e312007-10-17 17:58:40 -0300663 polling = 5; /* ms */
664 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
Nickolay V. Shmyrev6b961442005-11-08 21:36:22 -0800665 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
Nickolay V. Shmyrev2a9a9a82006-01-09 15:25:33 -0200667 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
Mauro Carvalho Chehab330a1152005-07-12 13:59:01 -0700668 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300669 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 mask_keycode = 0x00003F;
671 mask_keyup = 0x400000;
672 polling = 50; // ms
673 break;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300674 case SAA7134_BOARD_PROTEUS_2309:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300675 ir_codes = RC_MAP_PROTEUS_2309;
Michal Majchrowiczb04c1ba2006-09-13 16:42:42 -0300676 mask_keycode = 0x00007F;
677 mask_keyup = 0x000080;
678 polling = 50; // ms
679 break;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800680 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
681 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300682 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
Nickolay V. Shmyrevfea095f2005-11-08 21:36:47 -0800683 mask_keycode = 0x003F00;
684 mask_keyup = 0x040000;
685 break;
James Le Cuirotf5c965a2007-07-02 12:53:25 -0300686 case SAA7134_BOARD_FLYDVBS_LR300:
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200687 case SAA7134_BOARD_FLYDVBT_LR301:
Rudo Thomasa8029172006-02-27 00:08:46 -0300688 case SAA7134_BOARD_FLYDVBTDUO:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300689 ir_codes = RC_MAP_FLYDVB;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200690 mask_keycode = 0x0001F00;
691 mask_keydown = 0x0040000;
692 break;
Hermann Pitton91607232006-12-07 21:45:28 -0300693 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Ed Vipas904ab882007-03-29 18:32:49 -0300694 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Mauro Carvalho Chehabdfb4ba12009-08-20 10:13:40 -0300695 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300696 ir_codes = RC_MAP_ASUS_PC39;
Mauro Carvalho Chehabfe8b67132010-09-30 14:46:47 -0300697 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
698 mask_keyup = 0x0040000;
699 mask_keycode = 0xffff;
700 raw_decode = 1;
Hermann Pitton91607232006-12-07 21:45:28 -0300701 break;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300702 case SAA7134_BOARD_ENCORE_ENLTV:
703 case SAA7134_BOARD_ENCORE_ENLTV_FM:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300704 ir_codes = RC_MAP_ENCORE_ENLTV;
Juan Pablo Sormanic36c4592006-12-27 12:46:36 -0300705 mask_keycode = 0x00007f;
706 mask_keyup = 0x040000;
707 polling = 50; // ms
708 break;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300709 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300710 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
Mauro Carvalho Chehabbce8d0f2010-11-17 09:58:09 -0300711 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
712 mask_keyup = 0x0040000;
713 mask_keycode = 0xffff;
714 raw_decode = 1;
Mauro Carvalho Chehabbf1ece62008-06-26 17:03:00 -0300715 break;
Tony Wan480f75a2007-05-11 11:33:50 -0300716 case SAA7134_BOARD_10MOONSTVMASTER3:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300717 ir_codes = RC_MAP_ENCORE_ENLTV;
Tony Wan480f75a2007-05-11 11:33:50 -0300718 mask_keycode = 0x5f80000;
719 mask_keyup = 0x8000000;
720 polling = 50; //ms
721 break;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300722 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300723 ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
Adrian Pardinif0ba3562008-02-11 12:40:53 -0300724 mask_keycode = 0xff;
725 mask_keydown = 0xf00000;
726 polling = 50; /* ms */
727 break;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300728 case SAA7134_BOARD_REAL_ANGEL_220:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300729 ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
Mauro Carvalho Chehab9b000192008-06-26 17:03:00 -0300730 mask_keycode = 0x3f00;
731 mask_keyup = 0x4000;
732 polling = 50; /* ms */
733 break;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300734 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300735 ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
Mauro Carvalho Chehab26d5f3a2008-12-07 13:19:29 -0300736 mask_keycode = 0x7f;
737 polling = 40; /* ms */
738 break;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300739 case SAA7134_BOARD_VIDEOMATE_S350:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300740 ir_codes = RC_MAP_VIDEOMATE_S350;
Igor M. Liplianinecfcfec2009-08-13 21:42:21 -0300741 mask_keycode = 0x003f00;
742 mask_keydown = 0x040000;
743 break;
Michael Obst0700ade2009-10-31 14:05:42 -0300744 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300745 ir_codes = RC_MAP_WINFAST;
Michael Obst0700ade2009-10-31 14:05:42 -0300746 mask_keycode = 0x5f00;
747 mask_keyup = 0x020000;
Michael Krufky117e1342009-11-01 11:16:10 -0300748 polling = 50; /* ms */
Michael Obst0700ade2009-10-31 14:05:42 -0300749 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751 if (NULL == ir_codes) {
752 printk("%s: Oops: IR config error [card=%d]\n",
753 dev->name, dev->board);
754 return -ENODEV;
755 }
756
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500757 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
David Härdemand8b4b582010-10-29 16:08:23 -0300758 rc = rc_allocate_device();
759 if (!ir || !rc) {
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300760 err = -ENOMEM;
761 goto err_out_free;
Dmitry Torokhovb7df3912005-09-15 02:01:53 -0500762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
David Härdemand8b4b582010-10-29 16:08:23 -0300764 ir->dev = rc;
Mauro Carvalho Chehab02108942010-03-20 00:25:37 -0300765 dev->remote = ir;
766
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300767 ir->running = false;
Dmitry Torokhovd271d1c2005-11-20 00:56:54 -0500768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 /* init hardware-specific stuff */
770 ir->mask_keycode = mask_keycode;
771 ir->mask_keydown = mask_keydown;
772 ir->mask_keyup = mask_keyup;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800773 ir->polling = polling;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300774 ir->raw_decode = raw_decode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 /* init input device */
777 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
778 saa7134_boards[dev->board].name);
779 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
780 pci_name(dev->pci));
781
David Härdemand8b4b582010-10-29 16:08:23 -0300782 rc->priv = dev;
783 rc->open = saa7134_ir_open;
784 rc->close = saa7134_ir_close;
Mauro Carvalho Chehab626cf692010-04-06 23:21:46 -0300785 if (raw_decode)
David Härdemand8b4b582010-10-29 16:08:23 -0300786 rc->driver_type = RC_DRIVER_IR_RAW;
Mauro Carvalho Chehab626cf692010-04-06 23:21:46 -0300787
David Härdemand8b4b582010-10-29 16:08:23 -0300788 rc->input_name = ir->name;
789 rc->input_phys = ir->phys;
790 rc->input_id.bustype = BUS_PCI;
791 rc->input_id.version = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 if (dev->pci->subsystem_vendor) {
David Härdemand8b4b582010-10-29 16:08:23 -0300793 rc->input_id.vendor = dev->pci->subsystem_vendor;
794 rc->input_id.product = dev->pci->subsystem_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 } else {
David Härdemand8b4b582010-10-29 16:08:23 -0300796 rc->input_id.vendor = dev->pci->vendor;
797 rc->input_id.product = dev->pci->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
David Härdemand8b4b582010-10-29 16:08:23 -0300799 rc->dev.parent = &dev->pci->dev;
800 rc->map_name = ir_codes;
801 rc->driver_name = MODULE_NAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
David Härdemand8b4b582010-10-29 16:08:23 -0300803 err = rc_register_device(rc);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300804 if (err)
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300805 goto err_out_free;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 return 0;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300808
Mauro Carvalho Chehab716aab42010-03-31 14:40:35 -0300809err_out_free:
David Härdemand8b4b582010-10-29 16:08:23 -0300810 rc_free_device(rc);
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300811 dev->remote = NULL;
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300812 kfree(ir);
813 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
816void saa7134_input_fini(struct saa7134_dev *dev)
817{
818 if (NULL == dev->remote)
819 return;
820
Dmitry Torokhovb07b4782006-11-20 10:23:04 -0300821 saa7134_ir_stop(dev);
David Härdemand8b4b582010-10-29 16:08:23 -0300822 rc_unregister_device(dev->remote->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 kfree(dev->remote);
824 dev->remote = NULL;
825}
826
Jean Delvarec668f322009-05-13 16:48:50 -0300827void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800828{
Jean Delvare43e16ea2009-10-02 05:47:08 -0300829 struct i2c_board_info info;
Jean Delvarec668f322009-05-13 16:48:50 -0300830
Jean Delvarec668f322009-05-13 16:48:50 -0300831 struct i2c_msg msg_msi = {
832 .addr = 0x50,
833 .flags = I2C_M_RD,
834 .len = 0,
835 .buf = NULL,
836 };
837
Jean Delvarec668f322009-05-13 16:48:50 -0300838 int rc;
839
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800840 if (disable_ir) {
Jean Delvarec668f322009-05-13 16:48:50 -0300841 dprintk("IR has been disabled, not probing for i2c remote\n");
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800842 return;
843 }
844
Jean Delvare43e16ea2009-10-02 05:47:08 -0300845 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300846 memset(&dev->init_data, 0, sizeof(dev->init_data));
Jean Delvare43e16ea2009-10-02 05:47:08 -0300847 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300848
849 switch (dev->board) {
850 case SAA7134_BOARD_PINNACLE_PCTV_110i:
851 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300852 dev->init_data.name = "Pinnacle PCTV";
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300853 if (pinnacle_remote == 0) {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300854 dev->init_data.get_key = get_key_pinnacle_color;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300855 dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300856 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300857 } else {
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300858 dev->init_data.get_key = get_key_pinnacle_grey;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300859 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300860 info.addr = 0x47;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300861 }
862 break;
863 case SAA7134_BOARD_UPMOST_PURPLE_TV:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300864 dev->init_data.name = "Purple TV";
865 dev->init_data.get_key = get_key_purpletv;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300866 dev->init_data.ir_codes = RC_MAP_PURPLETV;
Jean Delvareaef02aa2009-10-02 08:47:22 -0300867 info.addr = 0x7a;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300868 break;
869 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300870 dev->init_data.name = "MSI TV@nywhere Plus";
871 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300872 dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
Mauro Carvalho Chehabc72ba8e2010-09-23 01:23:10 -0300873 /*
874 * MSI TV@nyware Plus requires more frequent polling
875 * otherwise it will miss some keypresses
876 */
877 dev->init_data.polling_interval = 50;
Jean Delvare43e16ea2009-10-02 05:47:08 -0300878 info.addr = 0x30;
Jean Delvareec218a42009-05-13 16:51:46 -0300879 /* MSI TV@nywhere Plus controller doesn't seem to
880 respond to probes unless we read something from
881 an existing device. Weird...
882 REVISIT: might no longer be needed */
883 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
Joe Perchesc429e7b2010-10-25 23:44:25 -0300884 dprintk("probe 0x%02x @ %s: %s\n",
Jean Delvareec218a42009-05-13 16:51:46 -0300885 msg_msi.addr, dev->i2c_adap.name,
886 (1 == rc) ? "yes" : "no");
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300887 break;
888 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300889 dev->init_data.name = "HVR 1110";
890 dev->init_data.get_key = get_key_hvr1110;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300891 dev->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW;
Jean Delvare30093e82009-10-02 09:48:04 -0300892 info.addr = 0x71;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300893 break;
894 case SAA7134_BOARD_BEHOLD_607FM_MK3:
895 case SAA7134_BOARD_BEHOLD_607FM_MK5:
896 case SAA7134_BOARD_BEHOLD_609FM_MK3:
897 case SAA7134_BOARD_BEHOLD_609FM_MK5:
898 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
899 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
900 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
901 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
902 case SAA7134_BOARD_BEHOLD_M6:
903 case SAA7134_BOARD_BEHOLD_M63:
904 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
905 case SAA7134_BOARD_BEHOLD_H6:
Dmitri Belimov2012c872009-08-26 01:01:12 -0300906 case SAA7134_BOARD_BEHOLD_X7:
Dmitri Belimov0faa2ed2010-04-06 01:00:05 -0300907 case SAA7134_BOARD_BEHOLD_H7:
908 case SAA7134_BOARD_BEHOLD_A7:
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300909 dev->init_data.name = "BeholdTV";
910 dev->init_data.get_key = get_key_beholdm6xx;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300911 dev->init_data.ir_codes = RC_MAP_BEHOLD;
Dmitri Belimov2ffbb642010-03-04 02:40:37 -0300912 dev->init_data.type = IR_TYPE_NEC;
Jean Delvare30093e82009-10-02 09:48:04 -0300913 info.addr = 0x2d;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300914 break;
Jean Delvared9a88e62009-05-13 16:52:44 -0300915 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
916 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
Jean Delvare43e16ea2009-10-02 05:47:08 -0300917 info.addr = 0x40;
Jean Delvared9a88e62009-05-13 16:52:44 -0300918 break;
Lukas Karasd995a182009-11-24 12:06:52 -0300919 case SAA7134_BOARD_FLYDVB_TRIO:
920 dev->init_data.name = "FlyDVB Trio";
921 dev->init_data.get_key = get_key_flydvb_trio;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -0300922 dev->init_data.ir_codes = RC_MAP_FLYDVB;
Lukas Karasd995a182009-11-24 12:06:52 -0300923 info.addr = 0x0b;
924 break;
Jean Delvare30093e82009-10-02 09:48:04 -0300925 default:
926 dprintk("No I2C IR support for board %x\n", dev->board);
927 return;
Jean Delvare4d7a2d62009-05-13 16:49:32 -0300928 }
929
Mauro Carvalho Chehab7aedd5ec2009-09-07 02:22:01 -0300930 if (dev->init_data.name)
Jean Delvare43e16ea2009-10-02 05:47:08 -0300931 info.platform_data = &dev->init_data;
Jean Delvare30093e82009-10-02 09:48:04 -0300932 i2c_new_device(&dev->i2c_adap, &info);
Jean Delvarec668f322009-05-13 16:48:50 -0300933}
934
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300935static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
936{
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300937 struct saa7134_card_ir *ir = dev->remote;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300938 unsigned long timeout;
Mauro Carvalho Chehab2f16f632010-04-03 18:51:50 -0300939 int space;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300940
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300941 /* Generate initial event */
942 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
943 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
Mauro Carvalho Chehab2f16f632010-04-03 18:51:50 -0300944 space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
David Härdeman724e2492010-04-08 13:10:00 -0300945 ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300946
Mauro Carvalho Chehab9f154782010-03-21 13:00:55 -0300947
948 /*
949 * Wait 15 ms from the start of the first IR event before processing
950 * the event. This time is enough for NEC protocol. May need adjustments
951 * to work with other protocols.
952 */
953 if (!ir->active) {
954 timeout = jiffies + jiffies_to_msecs(15);
955 mod_timer(&ir->timer_end, timeout);
Mauro Carvalho Chehaba6e3b812010-11-17 10:05:29 -0300956 ir->active = true;
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300957 }
958
Mauro Carvalho Chehaba3572c32010-03-20 20:59:44 -0300959 return 1;
960}