V4L/DVB (6715): ivtv: Remove unnecessary register update
[linux-2.6/verdex.git] / drivers / media / video / em28xx / em28xx-input.c
blobe3894b68c4ee26b778aebe3945c9f3489e20c609
1 /*
2 handle em28xx IR remotes via linux kernel input layer.
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com>
6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Sascha Sommer <saschasommer@freenet.de>
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.
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.
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
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/input.h>
29 #include <linux/usb.h>
31 #include "em28xx.h"
33 static unsigned int disable_ir = 0;
34 module_param(disable_ir, int, 0444);
35 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
37 static unsigned int ir_debug = 0;
38 module_param(ir_debug, int, 0644);
39 MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
41 #define dprintk(fmt, arg...) if (ir_debug) \
42 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
44 /* ----------------------------------------------------------------------- */
46 static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
48 unsigned char b;
50 /* poll IR chip */
51 if (1 != i2c_master_recv(&ir->c,&b,1)) {
52 dprintk("read error\n");
53 return -EIO;
56 /* it seems that 0xFE indicates that a button is still hold
57 down, while 0xff indicates that no button is hold
58 down. 0xfe sequences are sometimes interrupted by 0xFF */
60 dprintk("key %02x\n", b);
62 if (b == 0xff)
63 return 0;
65 if (b == 0xfe)
66 /* keep old data */
67 return 1;
69 *ir_key = b;
70 *ir_raw = b;
71 return 1;
75 static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
77 unsigned char buf[2];
78 unsigned char code;
80 /* poll IR chip */
81 if (2 != i2c_master_recv(&ir->c,buf,2))
82 return -EIO;
84 /* Does eliminate repeated parity code */
85 if (buf[1]==0xff)
86 return 0;
88 ir->old=buf[1];
90 /* Rearranges bits to the right order */
91 code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
92 ((buf[0]&0x02)<<3) | /* 0001 0000 */
93 ((buf[0]&0x04)<<1) | /* 0000 1000 */
94 ((buf[0]&0x08)>>1) | /* 0000 0100 */
95 ((buf[0]&0x10)>>3) | /* 0000 0010 */
96 ((buf[0]&0x20)>>5); /* 0000 0001 */
98 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
100 /* return key */
101 *ir_key = code;
102 *ir_raw = code;
103 return 1;
106 static int get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
108 unsigned char buf[3];
110 /* poll IR chip */
112 if (3 != i2c_master_recv(&ir->c,buf,3)) {
113 dprintk("read error\n");
114 return -EIO;
117 dprintk("key %02x\n", buf[2]&0x3f);
118 if (buf[0]!=0x00){
119 return 0;
122 *ir_key = buf[2]&0x3f;
123 *ir_raw = buf[2]&0x3f;
125 return 1;
128 /* ----------------------------------------------------------------------- */
129 void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir)
131 if (disable_ir) {
132 ir->get_key=NULL;
133 return ;
136 /* detect & configure */
137 switch (dev->model) {
138 case (EM2800_BOARD_UNKNOWN):
139 break;
140 case (EM2820_BOARD_UNKNOWN):
141 break;
142 case (EM2800_BOARD_TERRATEC_CINERGY_200):
143 case (EM2820_BOARD_TERRATEC_CINERGY_250):
144 ir->ir_codes = ir_codes_em_terratec;
145 ir->get_key = get_key_terratec;
146 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)");
147 break;
148 case (EM2820_BOARD_PINNACLE_USB_2):
149 ir->ir_codes = ir_codes_pinnacle_grey;
150 ir->get_key = get_key_pinnacle_usb_grey;
151 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)");
152 break;
153 case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
154 ir->ir_codes = ir_codes_hauppauge_new;
155 ir->get_key = get_key_em_haup;
156 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
157 break;
158 case (EM2820_BOARD_MSI_VOX_USB_2):
159 break;
160 case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
161 break;
162 case (EM2800_BOARD_KWORLD_USB2800):
163 break;
167 /* ----------------------------------------------------------------------
168 * Local variables:
169 * c-basic-offset: 8
170 * End: