blob: 86aff371a287882d3d999fd1799b37ee16b31a03 [file] [log] [blame]
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -08001/*
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -08002 handle em28xx IR remotes via linux kernel input layer.
3
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com>
Mauro Carvalho Chehab2e7c6dc2006-04-03 07:53:40 -03006 Mauro Carvalho Chehab <mchehab@infradead.org>
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -08007 Sascha Sommer <saschasommer@freenet.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080022 */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/sched.h>
29#include <linux/interrupt.h>
30#include <linux/input.h>
31#include <linux/usb.h>
32
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080033#include "em28xx.h"
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080034
35static unsigned int disable_ir = 0;
36module_param(disable_ir, int, 0444);
37MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
38
39static unsigned int ir_debug = 0;
40module_param(ir_debug, int, 0644);
41MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
42
43#define dprintk(fmt, arg...) if (ir_debug) \
44 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
45
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080046/* ----------------------------------------------------------------------- */
47
Markus Rechbergere43f14a2005-11-08 21:37:35 -080048static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
49{
50 unsigned char b;
51
52 /* poll IR chip */
53 if (1 != i2c_master_recv(&ir->c,&b,1)) {
54 dprintk("read error\n");
55 return -EIO;
56 }
57
58 /* it seems that 0xFE indicates that a button is still hold
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080059 down, while 0xff indicates that no button is hold
60 down. 0xfe sequences are sometimes interrupted by 0xFF */
Markus Rechbergere43f14a2005-11-08 21:37:35 -080061
62 dprintk("key %02x\n", b);
63
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080064 if (b == 0xff)
Markus Rechbergere43f14a2005-11-08 21:37:35 -080065 return 0;
66
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080067 if (b == 0xfe)
Markus Rechbergere43f14a2005-11-08 21:37:35 -080068 /* keep old data */
69 return 1;
70
71 *ir_key = b;
72 *ir_raw = b;
73 return 1;
74}
75
76
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080077static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
78{
79 unsigned char buf[2];
80 unsigned char code;
81
82 /* poll IR chip */
83 if (2 != i2c_master_recv(&ir->c,buf,2))
84 return -EIO;
85
86 /* Does eliminate repeated parity code */
87 if (buf[1]==0xff)
88 return 0;
89
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080090 ir->old=buf[1];
91
92 /* Rearranges bits to the right order */
93 code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
94 ((buf[0]&0x02)<<3) | /* 0001 0000 */
95 ((buf[0]&0x04)<<1) | /* 0000 1000 */
96 ((buf[0]&0x08)>>1) | /* 0000 0100 */
97 ((buf[0]&0x10)>>3) | /* 0000 0010 */
98 ((buf[0]&0x20)>>5); /* 0000 0001 */
99
100 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
101
102 /* return key */
103 *ir_key = code;
104 *ir_raw = code;
105 return 1;
106}
107
Markus Rechberger366cc642006-01-15 21:04:27 -0200108static int get_key_pinnacle_usb(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
109{
110 unsigned char buf[3];
111
112 /* poll IR chip */
113
114 if (3 != i2c_master_recv(&ir->c,buf,3)) {
115 dprintk("read error\n");
116 return -EIO;
117 }
118
119 dprintk("key %02x\n", buf[2]&0x3f);
120 if (buf[0]!=0x00){
121 return 0;
122 }
123
124 *ir_key = buf[2]&0x3f;
125 *ir_raw = buf[2]&0x3f;
126
127 return 1;
128}
129
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800130/* ----------------------------------------------------------------------- */
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -0800131void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir)
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800132{
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800133 if (disable_ir) {
134 ir->get_key=NULL;
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800135 return ;
Ricardo Cerqueiraac9cd972005-11-08 21:37:56 -0800136 }
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800137
138 /* detect & configure */
139 switch (dev->model) {
140 case (EM2800_BOARD_UNKNOWN):
141 break;
142 case (EM2820_BOARD_UNKNOWN):
143 break;
Sascha Sommer16f2e622005-11-08 21:37:37 -0800144 case (EM2800_BOARD_TERRATEC_CINERGY_200):
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800145 case (EM2820_BOARD_TERRATEC_CINERGY_250):
Markus Rechbergere43f14a2005-11-08 21:37:35 -0800146 ir->ir_codes = ir_codes_em_terratec;
147 ir->get_key = get_key_terratec;
Mauro Carvalho Chehab3acf2802005-11-08 21:38:27 -0800148 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)");
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800149 break;
150 case (EM2820_BOARD_PINNACLE_USB_2):
Markus Rechberger366cc642006-01-15 21:04:27 -0200151 ir->ir_codes = ir_codes_em_pinnacle_usb;
152 ir->get_key = get_key_pinnacle_usb;
153 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)");
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800154 break;
155 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
156 ir->ir_codes = ir_codes_hauppauge_new;
157 ir->get_key = get_key_em_haup;
Markus Rechbergere43f14a2005-11-08 21:37:35 -0800158 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800159 break;
160 case (EM2820_BOARD_MSI_VOX_USB_2):
161 break;
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800162 case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
163 break;
164 case (EM2800_BOARD_KWORLD_USB2800):
165 break;
166 }
167}
168
169/* ----------------------------------------------------------------------
170 * Local variables:
171 * c-basic-offset: 8
172 * End:
173 */