blob: 10da2fd8d9875072fe3476ed683266c450c4f08d [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>
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080025#include <linux/init.h>
26#include <linux/delay.h>
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080027#include <linux/interrupt.h>
28#include <linux/input.h>
29#include <linux/usb.h>
30
Mauro Carvalho Chehabf7abcd32005-11-08 21:38:25 -080031#include "em28xx.h"
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080032
Mauro Carvalho Chehabc8793b02008-01-13 15:42:17 -030033static unsigned int ir_debug;
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080034module_param(ir_debug, int, 0644);
35MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
36
37#define dprintk(fmt, arg...) if (ir_debug) \
38 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
39
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080040/* ----------------------------------------------------------------------- */
41
Mauro Carvalho Chehabc8793b02008-01-13 15:42:17 -030042int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
Markus Rechbergere43f14a2005-11-08 21:37:35 -080043{
44 unsigned char b;
45
46 /* poll IR chip */
47 if (1 != i2c_master_recv(&ir->c,&b,1)) {
48 dprintk("read error\n");
49 return -EIO;
50 }
51
52 /* it seems that 0xFE indicates that a button is still hold
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080053 down, while 0xff indicates that no button is hold
54 down. 0xfe sequences are sometimes interrupted by 0xFF */
Markus Rechbergere43f14a2005-11-08 21:37:35 -080055
56 dprintk("key %02x\n", b);
57
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080058 if (b == 0xff)
Markus Rechbergere43f14a2005-11-08 21:37:35 -080059 return 0;
60
Mauro Carvalho Chehab4f9c05a2005-11-08 21:37:36 -080061 if (b == 0xfe)
Markus Rechbergere43f14a2005-11-08 21:37:35 -080062 /* keep old data */
63 return 1;
64
65 *ir_key = b;
66 *ir_raw = b;
67 return 1;
68}
69
70
Mauro Carvalho Chehabc8793b02008-01-13 15:42:17 -030071int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080072{
73 unsigned char buf[2];
74 unsigned char code;
75
76 /* poll IR chip */
77 if (2 != i2c_master_recv(&ir->c,buf,2))
78 return -EIO;
79
80 /* Does eliminate repeated parity code */
81 if (buf[1]==0xff)
82 return 0;
83
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -080084 ir->old=buf[1];
85
86 /* Rearranges bits to the right order */
87 code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
88 ((buf[0]&0x02)<<3) | /* 0001 0000 */
89 ((buf[0]&0x04)<<1) | /* 0000 1000 */
90 ((buf[0]&0x08)>>1) | /* 0000 0100 */
91 ((buf[0]&0x10)>>3) | /* 0000 0010 */
92 ((buf[0]&0x20)>>5); /* 0000 0001 */
93
94 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
95
96 /* return key */
97 *ir_key = code;
98 *ir_raw = code;
99 return 1;
100}
101
Mauro Carvalho Chehabc8793b02008-01-13 15:42:17 -0300102int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
103 u32 *ir_raw)
Markus Rechberger366cc642006-01-15 21:04:27 -0200104{
105 unsigned char buf[3];
106
107 /* poll IR chip */
108
109 if (3 != i2c_master_recv(&ir->c,buf,3)) {
110 dprintk("read error\n");
111 return -EIO;
112 }
113
114 dprintk("key %02x\n", buf[2]&0x3f);
115 if (buf[0]!=0x00){
116 return 0;
117 }
118
119 *ir_key = buf[2]&0x3f;
120 *ir_raw = buf[2]&0x3f;
121
122 return 1;
123}
124
Mauro Carvalho Chehabd5e52652005-11-08 21:37:32 -0800125/* ----------------------------------------------------------------------
126 * Local variables:
127 * c-basic-offset: 8
128 * End:
129 */