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