3 * handle saa7134 IR remotes via linux kernel input layer.
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.
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.
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
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>
29 #include "saa7134-reg.h"
32 static unsigned int disable_ir = 0;
33 module_param(disable_ir, int, 0444);
34 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
36 static unsigned int ir_debug = 0;
37 module_param(ir_debug, int, 0644);
38 MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
40 static int pinnacle_remote = 0;
41 module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
42 MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
44 #define dprintk(fmt, arg...) if (ir_debug) \
45 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
46 #define i2cdprintk(fmt, arg...) if (ir_debug) \
47 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
49 /* -------------------- GPIO generic keycode builder -------------------- */
51 static int build_key(struct saa7134_dev *dev)
53 struct saa7134_ir *ir = dev->remote;
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);
60 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
62 if (ir->last_gpio == gpio)
67 data = ir_extract_bits(gpio, ir->mask_keycode);
68 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
69 gpio, ir->mask_keycode, data);
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);
76 ir_input_nokey(ir->dev, &ir->ir);
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);
90 /* --------------------- Chip specific I2C key builders ----------------- */
92 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
97 if (1 != i2c_master_recv(&ir->c,&b,1)) {
98 i2cdprintk("read error\n");
102 /* no button press */
115 static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
117 unsigned char buf[5], cod4, code3, code4;
120 if (5 != i2c_master_recv(&ir->c,buf,5))
136 void saa7134_input_irq(struct saa7134_dev *dev)
138 struct saa7134_ir *ir = dev->remote;
144 static void saa7134_input_timer(unsigned long data)
146 struct saa7134_dev *dev = (struct saa7134_dev*)data;
147 struct saa7134_ir *ir = dev->remote;
148 unsigned long timeout;
151 timeout = jiffies + (ir->polling * HZ / 1000);
152 mod_timer(&ir->timer, timeout);
155 static void saa7134_ir_start(struct saa7134_dev *dev, struct saa7134_ir *ir)
158 init_timer(&ir->timer);
159 ir->timer.function = saa7134_input_timer;
160 ir->timer.data = (unsigned long)dev;
161 ir->timer.expires = jiffies + HZ;
162 add_timer(&ir->timer);
166 static void saa7134_ir_stop(struct saa7134_dev *dev)
168 if (dev->remote->polling)
169 del_timer_sync(&dev->remote->timer);
172 int saa7134_input_init1(struct saa7134_dev *dev)
174 struct saa7134_ir *ir;
175 struct input_dev *input_dev;
176 IR_KEYTAB_TYPE *ir_codes = NULL;
177 u32 mask_keycode = 0;
178 u32 mask_keydown = 0;
181 int ir_type = IR_TYPE_OTHER;
184 if (dev->has_remote != SAA7134_REMOTE_GPIO)
189 /* detect & configure */
190 switch (dev->board) {
191 case SAA7134_BOARD_FLYVIDEO2000:
192 case SAA7134_BOARD_FLYVIDEO3000:
193 case SAA7134_BOARD_FLYTVPLATINUM_FM:
194 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
195 ir_codes = ir_codes_flyvideo;
196 mask_keycode = 0xEC00000;
197 mask_keydown = 0x0040000;
199 case SAA7134_BOARD_CINERGY400:
200 case SAA7134_BOARD_CINERGY600:
201 case SAA7134_BOARD_CINERGY600_MK3:
202 ir_codes = ir_codes_cinergy;
203 mask_keycode = 0x00003f;
204 mask_keyup = 0x040000;
206 case SAA7134_BOARD_ECS_TVP3XP:
207 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
208 ir_codes = ir_codes_eztv;
209 mask_keycode = 0x00017c;
210 mask_keyup = 0x000002;
213 case SAA7134_BOARD_KWORLD_XPERT:
214 case SAA7134_BOARD_AVACSSMARTTV:
215 ir_codes = ir_codes_pixelview;
216 mask_keycode = 0x00001F;
217 mask_keyup = 0x000020;
220 case SAA7134_BOARD_MD2819:
221 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
222 case SAA7134_BOARD_AVERMEDIA_305:
223 case SAA7134_BOARD_AVERMEDIA_307:
224 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
225 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
226 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
227 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
228 ir_codes = ir_codes_avermedia;
229 mask_keycode = 0x0007C8;
230 mask_keydown = 0x000010;
232 /* Set GPIO pin2 to high to enable the IR controller */
233 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
234 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
236 case SAA7134_BOARD_AVERMEDIA_777:
237 case SAA7134_BOARD_AVERMEDIA_A16AR:
238 ir_codes = ir_codes_avermedia;
239 mask_keycode = 0x02F200;
240 mask_keydown = 0x000400;
242 /* Without this we won't receive key up events */
243 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
244 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
246 case SAA7134_BOARD_KWORLD_TERMINATOR:
247 ir_codes = ir_codes_pixelview;
248 mask_keycode = 0x00001f;
249 mask_keyup = 0x000060;
252 case SAA7134_BOARD_MANLI_MTV001:
253 case SAA7134_BOARD_MANLI_MTV002:
254 case SAA7134_BOARD_BEHOLD_409FM:
255 ir_codes = ir_codes_manli;
256 mask_keycode = 0x001f00;
257 mask_keyup = 0x004000;
260 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
261 ir_codes = ir_codes_pctv_sedna;
262 mask_keycode = 0x001f00;
263 mask_keyup = 0x004000;
266 case SAA7134_BOARD_GOTVIEW_7135:
267 ir_codes = ir_codes_gotview7135;
268 mask_keycode = 0x0003EC;
269 mask_keyup = 0x008000;
270 mask_keydown = 0x000010;
273 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
274 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
275 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
276 ir_codes = ir_codes_videomate_tv_pvr;
277 mask_keycode = 0x00003F;
278 mask_keyup = 0x400000;
281 case SAA7134_BOARD_PROTEUS_2309:
282 ir_codes = ir_codes_proteus_2309;
283 mask_keycode = 0x00007F;
284 mask_keyup = 0x000080;
287 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
288 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
289 ir_codes = ir_codes_videomate_tv_pvr;
290 mask_keycode = 0x003F00;
291 mask_keyup = 0x040000;
293 case SAA7134_BOARD_FLYDVBT_LR301:
294 case SAA7134_BOARD_FLYDVBTDUO:
295 ir_codes = ir_codes_flydvb;
296 mask_keycode = 0x0001F00;
297 mask_keydown = 0x0040000;
300 if (NULL == ir_codes) {
301 printk("%s: Oops: IR config error [card=%d]\n",
302 dev->name, dev->board);
306 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
307 input_dev = input_allocate_device();
308 if (!ir || !input_dev) {
315 /* init hardware-specific stuff */
316 ir->mask_keycode = mask_keycode;
317 ir->mask_keydown = mask_keydown;
318 ir->mask_keyup = mask_keyup;
319 ir->polling = polling;
321 /* init input device */
322 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
323 saa7134_boards[dev->board].name);
324 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
327 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
328 input_dev->name = ir->name;
329 input_dev->phys = ir->phys;
330 input_dev->id.bustype = BUS_PCI;
331 input_dev->id.version = 1;
332 if (dev->pci->subsystem_vendor) {
333 input_dev->id.vendor = dev->pci->subsystem_vendor;
334 input_dev->id.product = dev->pci->subsystem_device;
336 input_dev->id.vendor = dev->pci->vendor;
337 input_dev->id.product = dev->pci->device;
339 input_dev->cdev.dev = &dev->pci->dev;
342 saa7134_ir_start(dev, ir);
344 err = input_register_device(ir->dev);
351 saa7134_ir_stop(dev);
354 input_free_device(input_dev);
359 void saa7134_input_fini(struct saa7134_dev *dev)
361 if (NULL == dev->remote)
364 saa7134_ir_stop(dev);
365 input_unregister_device(dev->remote->dev);
370 void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
373 dprintk("Found supported i2c remote, but IR has been disabled\n");
378 switch (dev->board) {
379 case SAA7134_BOARD_PINNACLE_PCTV_110i:
380 case SAA7134_BOARD_PINNACLE_PCTV_310i:
381 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
382 if (pinnacle_remote == 0) {
383 ir->get_key = get_key_pinnacle_color;
384 ir->ir_codes = ir_codes_pinnacle_color;
386 ir->get_key = get_key_pinnacle_grey;
387 ir->ir_codes = ir_codes_pinnacle_grey;
390 case SAA7134_BOARD_UPMOST_PURPLE_TV:
391 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
392 ir->get_key = get_key_purpletv;
393 ir->ir_codes = ir_codes_purpletv;
395 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
396 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
397 ir->get_key = get_key_hvr1110;
398 ir->ir_codes = ir_codes_hauppauge_new;
401 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
406 /* ----------------------------------------------------------------------