V4L/DVB (4896): Dvb-usb: fix vendor ID ordering
[deliverable/linux.git] / drivers / media / video / saa7134 / saa7134-input.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 *
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>
22#include <linux/moduleparam.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/sched.h>
26#include <linux/interrupt.h>
27#include <linux/input.h>
28
29#include "saa7134-reg.h"
30#include "saa7134.h"
31
32static unsigned int disable_ir = 0;
33module_param(disable_ir, int, 0444);
34MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
35
36static unsigned int ir_debug = 0;
37module_param(ir_debug, int, 0644);
38MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
39
b93eedb6
SP
40static int pinnacle_remote = 0;
41module_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
1da177e4
LT
44#define dprintk(fmt, arg...) if (ir_debug) \
45 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
ac9cd976
RC
46#define i2cdprintk(fmt, arg...) if (ir_debug) \
47 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
1da177e4 48
ac9cd976 49/* -------------------- GPIO generic keycode builder -------------------- */
1da177e4
LT
50
51static int build_key(struct saa7134_dev *dev)
52{
53 struct saa7134_ir *ir = dev->remote;
54 u32 gpio, data;
55
56 /* rising SAA7134_GPIO_GPRESCAN reads the status */
57 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
58 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
59
60 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
4ac97914
MCC
61 if (ir->polling) {
62 if (ir->last_gpio == gpio)
63 return 0;
64 ir->last_gpio = gpio;
65 }
1da177e4 66
4ac97914 67 data = ir_extract_bits(gpio, ir->mask_keycode);
1da177e4
LT
68 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
69 gpio, ir->mask_keycode, data);
70
0602fbb2
PM
71 if (ir->polling) {
72 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
73 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
74 ir_input_keydown(ir->dev, &ir->ir, data, data);
75 } else {
76 ir_input_nokey(ir->dev, &ir->ir);
77 }
1da177e4 78 }
0602fbb2
PM
79 else { /* IRQ driven mode - handle key press and release in one go */
80 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
81 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
82 ir_input_keydown(ir->dev, &ir->ir, data, data);
83 ir_input_nokey(ir->dev, &ir->ir);
84 }
85 }
86
1da177e4
LT
87 return 0;
88}
89
ac9cd976
RC
90/* --------------------- Chip specific I2C key builders ----------------- */
91
92static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
93{
94 unsigned char b;
95
96 /* poll IR chip */
97 if (1 != i2c_master_recv(&ir->c,&b,1)) {
98 i2cdprintk("read error\n");
99 return -EIO;
100 }
101
102 /* no button press */
103 if (b==0)
104 return 0;
105
106 /* repeating */
107 if (b & 0x80)
108 return 1;
109
110 *ir_key = b;
111 *ir_raw = b;
112 return 1;
113}
114
1da177e4
LT
115void saa7134_input_irq(struct saa7134_dev *dev)
116{
4ac97914 117 struct saa7134_ir *ir = dev->remote;
1da177e4 118
4ac97914 119 if (!ir->polling)
1da177e4
LT
120 build_key(dev);
121}
122
123static void saa7134_input_timer(unsigned long data)
124{
125 struct saa7134_dev *dev = (struct saa7134_dev*)data;
126 struct saa7134_ir *ir = dev->remote;
127 unsigned long timeout;
128
129 build_key(dev);
130 timeout = jiffies + (ir->polling * HZ / 1000);
131 mod_timer(&ir->timer, timeout);
132}
133
b07b4783
DT
134static void saa7134_ir_start(struct saa7134_dev *dev, struct saa7134_ir *ir)
135{
136 if (ir->polling) {
137 init_timer(&ir->timer);
138 ir->timer.function = saa7134_input_timer;
139 ir->timer.data = (unsigned long)dev;
140 ir->timer.expires = jiffies + HZ;
141 add_timer(&ir->timer);
142 }
143}
144
145static void saa7134_ir_stop(struct saa7134_dev *dev)
146{
147 if (dev->remote->polling)
148 del_timer_sync(&dev->remote->timer);
149}
150
1da177e4
LT
151int saa7134_input_init1(struct saa7134_dev *dev)
152{
153 struct saa7134_ir *ir;
b7df3910 154 struct input_dev *input_dev;
1da177e4
LT
155 IR_KEYTAB_TYPE *ir_codes = NULL;
156 u32 mask_keycode = 0;
157 u32 mask_keydown = 0;
158 u32 mask_keyup = 0;
159 int polling = 0;
160 int ir_type = IR_TYPE_OTHER;
b07b4783 161 int err;
1da177e4 162
cb2444df 163 if (dev->has_remote != SAA7134_REMOTE_GPIO)
1da177e4
LT
164 return -ENODEV;
165 if (disable_ir)
166 return -ENODEV;
167
168 /* detect & configure */
169 switch (dev->board) {
170 case SAA7134_BOARD_FLYVIDEO2000:
171 case SAA7134_BOARD_FLYVIDEO3000:
4ac97914 172 case SAA7134_BOARD_FLYTVPLATINUM_FM:
6af90ab5 173 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
4c0f631e 174 ir_codes = ir_codes_flyvideo;
1da177e4
LT
175 mask_keycode = 0xEC00000;
176 mask_keydown = 0x0040000;
177 break;
178 case SAA7134_BOARD_CINERGY400:
179 case SAA7134_BOARD_CINERGY600:
180 case SAA7134_BOARD_CINERGY600_MK3:
4c0f631e 181 ir_codes = ir_codes_cinergy;
1da177e4
LT
182 mask_keycode = 0x00003f;
183 mask_keyup = 0x040000;
184 break;
185 case SAA7134_BOARD_ECS_TVP3XP:
186 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
4c0f631e 187 ir_codes = ir_codes_eztv;
330a115a
MCC
188 mask_keycode = 0x00017c;
189 mask_keyup = 0x000002;
1da177e4 190 polling = 50; // ms
330a115a
MCC
191 break;
192 case SAA7134_BOARD_KWORLD_XPERT:
1da177e4 193 case SAA7134_BOARD_AVACSSMARTTV:
b639f9d2 194 ir_codes = ir_codes_pixelview;
1da177e4
LT
195 mask_keycode = 0x00001F;
196 mask_keyup = 0x000020;
197 polling = 50; // ms
198 break;
199 case SAA7134_BOARD_MD2819:
ac19ecc6 200 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
1da177e4
LT
201 case SAA7134_BOARD_AVERMEDIA_305:
202 case SAA7134_BOARD_AVERMEDIA_307:
ac19ecc6
MCC
203 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
204 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
3ac706d2 205 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
ac19ecc6 206 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
b639f9d2 207 ir_codes = ir_codes_avermedia;
1da177e4
LT
208 mask_keycode = 0x0007C8;
209 mask_keydown = 0x000010;
210 polling = 50; // ms
211 /* Set GPIO pin2 to high to enable the IR controller */
212 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
213 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
214 break;
450efcfd 215 case SAA7134_BOARD_AVERMEDIA_777:
29e0f1a1 216 case SAA7134_BOARD_AVERMEDIA_A16AR:
450efcfd 217 ir_codes = ir_codes_avermedia;
218 mask_keycode = 0x02F200;
219 mask_keydown = 0x000400;
220 polling = 50; // ms
221 /* Without this we won't receive key up events */
222 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
223 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
4dd7406e 224 break;
4ac97914 225 case SAA7134_BOARD_KWORLD_TERMINATOR:
b639f9d2 226 ir_codes = ir_codes_pixelview;
dc2286cf
JW
227 mask_keycode = 0x00001f;
228 mask_keyup = 0x000060;
229 polling = 50; // ms
230 break;
ac19ecc6
MCC
231 case SAA7134_BOARD_MANLI_MTV001:
232 case SAA7134_BOARD_MANLI_MTV002:
a8ff417e 233 case SAA7134_BOARD_BEHOLD_409FM:
4c0f631e 234 ir_codes = ir_codes_manli;
ac19ecc6
MCC
235 mask_keycode = 0x001f00;
236 mask_keyup = 0x004000;
ac19ecc6
MCC
237 polling = 50; // ms
238 break;
17ce1ff9 239 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
4c0f631e 240 ir_codes = ir_codes_pctv_sedna;
c3d93192
PM
241 mask_keycode = 0x001f00;
242 mask_keyup = 0x004000;
243 polling = 50; // ms
244 break;
4ac97914 245 case SAA7134_BOARD_GOTVIEW_7135:
4c0f631e 246 ir_codes = ir_codes_gotview7135;
6b961440
NS
247 mask_keycode = 0x0003EC;
248 mask_keyup = 0x008000;
249 mask_keydown = 0x000010;
250 polling = 50; // ms
251 break;
1da177e4 252 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
2a9a9a84 253 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
330a115a 254 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
4c0f631e 255 ir_codes = ir_codes_videomate_tv_pvr;
1da177e4
LT
256 mask_keycode = 0x00003F;
257 mask_keyup = 0x400000;
258 polling = 50; // ms
259 break;
b04c1baf
MM
260 case SAA7134_BOARD_PROTEUS_2309:
261 ir_codes = ir_codes_proteus_2309;
262 mask_keycode = 0x00007F;
263 mask_keyup = 0x000080;
264 polling = 50; // ms
265 break;
4ac97914
MCC
266 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
267 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
4c0f631e 268 ir_codes = ir_codes_videomate_tv_pvr;
fea095fe
NS
269 mask_keycode = 0x003F00;
270 mask_keyup = 0x040000;
271 break;
3d8466ec 272 case SAA7134_BOARD_FLYDVBT_LR301:
a8029170 273 case SAA7134_BOARD_FLYDVBTDUO:
3d8466ec
GG
274 ir_codes = ir_codes_flydvb;
275 mask_keycode = 0x0001F00;
276 mask_keydown = 0x0040000;
277 break;
1da177e4
LT
278 }
279 if (NULL == ir_codes) {
280 printk("%s: Oops: IR config error [card=%d]\n",
281 dev->name, dev->board);
282 return -ENODEV;
283 }
284
b7df3910
DT
285 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
286 input_dev = input_allocate_device();
287 if (!ir || !input_dev) {
b07b4783
DT
288 err = -ENOMEM;
289 goto err_out_free;
b7df3910 290 }
1da177e4 291
d271d1c2
DT
292 ir->dev = input_dev;
293
1da177e4
LT
294 /* init hardware-specific stuff */
295 ir->mask_keycode = mask_keycode;
296 ir->mask_keydown = mask_keydown;
297 ir->mask_keyup = mask_keyup;
4ac97914 298 ir->polling = polling;
1da177e4
LT
299
300 /* init input device */
301 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
302 saa7134_boards[dev->board].name);
303 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
304 pci_name(dev->pci));
305
b7df3910
DT
306 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
307 input_dev->name = ir->name;
308 input_dev->phys = ir->phys;
309 input_dev->id.bustype = BUS_PCI;
310 input_dev->id.version = 1;
1da177e4 311 if (dev->pci->subsystem_vendor) {
b7df3910
DT
312 input_dev->id.vendor = dev->pci->subsystem_vendor;
313 input_dev->id.product = dev->pci->subsystem_device;
1da177e4 314 } else {
b7df3910
DT
315 input_dev->id.vendor = dev->pci->vendor;
316 input_dev->id.product = dev->pci->device;
1da177e4 317 }
b7df3910 318 input_dev->cdev.dev = &dev->pci->dev;
1da177e4 319
1da177e4 320 dev->remote = ir;
b07b4783
DT
321 saa7134_ir_start(dev, ir);
322
323 err = input_register_device(ir->dev);
324 if (err)
325 goto err_out_stop;
1da177e4 326
1da177e4 327 return 0;
b07b4783
DT
328
329 err_out_stop:
330 saa7134_ir_stop(dev);
331 dev->remote = NULL;
332 err_out_free:
333 input_free_device(input_dev);
334 kfree(ir);
335 return err;
1da177e4
LT
336}
337
338void saa7134_input_fini(struct saa7134_dev *dev)
339{
340 if (NULL == dev->remote)
341 return;
342
b07b4783 343 saa7134_ir_stop(dev);
b7df3910 344 input_unregister_device(dev->remote->dev);
1da177e4
LT
345 kfree(dev->remote);
346 dev->remote = NULL;
347}
348
ac9cd976
RC
349void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
350{
351 if (disable_ir) {
cb2444df 352 dprintk("Found supported i2c remote, but IR has been disabled\n");
ac9cd976
RC
353 ir->get_key=NULL;
354 return;
355 }
356
357 switch (dev->board) {
358 case SAA7134_BOARD_PINNACLE_PCTV_110i:
eb591af3 359 case SAA7134_BOARD_PINNACLE_PCTV_310i:
ac9cd976 360 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
b93eedb6
SP
361 if (pinnacle_remote == 0) {
362 ir->get_key = get_key_pinnacle_color;
363 ir->ir_codes = ir_codes_pinnacle_color;
364 } else {
365 ir->get_key = get_key_pinnacle_grey;
366 ir->ir_codes = ir_codes_pinnacle_grey;
367 }
ac9cd976
RC
368 break;
369 case SAA7134_BOARD_UPMOST_PURPLE_TV:
370 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
371 ir->get_key = get_key_purpletv;
372 ir->ir_codes = ir_codes_purpletv;
373 break;
374 default:
375 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
376 break;
377 }
378
379}
1da177e4
LT
380/* ----------------------------------------------------------------------
381 * Local variables:
382 * c-basic-offset: 8
383 * End:
384 */
This page took 0.254777 seconds and 5 git commands to generate.