blob: 21488779819211555eb47b19bbec397ff662fca5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07002 * $Id: cx88-input.c,v 1.15 2005/07/07 13:58:38 mchehab Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Device driver for GPIO attached remote control interfaces
5 * on Conexant 2388x based TV/DVB cards.
6 *
7 * Copyright (c) 2003 Pavel Machek
8 * Copyright (c) 2004 Gerd Knorr
9 * Copyright (c) 2004 Chris Pascoe
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/input.h>
29#include <linux/pci.h>
30#include <linux/module.h>
31#include <linux/moduleparam.h>
32
33#include <media/ir-common.h>
34
35#include "cx88.h"
36
37/* ---------------------------------------------------------------------- */
38
39/* DigitalNow DNTV Live DVB-T Remote */
40static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070041 [0x00] = KEY_ESC, /* 'go up a level?' */
42 /* Keys 0 to 9 */
43 [0x0a] = KEY_KP0,
44 [0x01] = KEY_KP1,
45 [0x02] = KEY_KP2,
46 [0x03] = KEY_KP3,
47 [0x04] = KEY_KP4,
48 [0x05] = KEY_KP5,
49 [0x06] = KEY_KP6,
50 [0x07] = KEY_KP7,
51 [0x08] = KEY_KP8,
52 [0x09] = KEY_KP9,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070054 [0x0b] = KEY_TUNER, /* tv/fm */
55 [0x0c] = KEY_SEARCH, /* scan */
56 [0x0d] = KEY_STOP,
57 [0x0e] = KEY_PAUSE,
58 [0x0f] = KEY_LIST, /* source */
59
60 [0x10] = KEY_MUTE,
61 [0x11] = KEY_REWIND, /* backward << */
62 [0x12] = KEY_POWER,
63 [0x13] = KEY_S, /* snap */
64 [0x14] = KEY_AUDIO, /* stereo */
65 [0x15] = KEY_CLEAR, /* reset */
66 [0x16] = KEY_PLAY,
67 [0x17] = KEY_ENTER,
68 [0x18] = KEY_ZOOM, /* full screen */
69 [0x19] = KEY_FASTFORWARD, /* forward >> */
70 [0x1a] = KEY_CHANNELUP,
71 [0x1b] = KEY_VOLUMEUP,
72 [0x1c] = KEY_INFO, /* preview */
73 [0x1d] = KEY_RECORD, /* record */
74 [0x1e] = KEY_CHANNELDOWN,
75 [0x1f] = KEY_VOLUMEDOWN,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
78/* ---------------------------------------------------------------------- */
79
80/* IO-DATA BCTV7E Remote */
81static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070082 [0x40] = KEY_TV,
83 [0x20] = KEY_RADIO, /* FM */
84 [0x60] = KEY_EPG,
85 [0x00] = KEY_POWER,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070087 /* Keys 0 to 9 */
88 [0x44] = KEY_KP0, /* 10 */
89 [0x50] = KEY_KP1,
90 [0x30] = KEY_KP2,
91 [0x70] = KEY_KP3,
92 [0x48] = KEY_KP4,
93 [0x28] = KEY_KP5,
94 [0x68] = KEY_KP6,
95 [0x58] = KEY_KP7,
96 [0x38] = KEY_KP8,
97 [0x78] = KEY_KP9,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -070099 [0x10] = KEY_L, /* Live */
100 [0x08] = KEY_T, /* Time Shift */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700102 [0x18] = KEY_PLAYPAUSE, /* Play */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700104 [0x24] = KEY_ENTER, /* 11 */
105 [0x64] = KEY_ESC, /* 12 */
106 [0x04] = KEY_M, /* Multi */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700108 [0x54] = KEY_VIDEO,
109 [0x34] = KEY_CHANNELUP,
110 [0x74] = KEY_VOLUMEUP,
111 [0x14] = KEY_MUTE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700113 [0x4c] = KEY_S, /* SVIDEO */
114 [0x2c] = KEY_CHANNELDOWN,
115 [0x6c] = KEY_VOLUMEDOWN,
116 [0x0c] = KEY_ZOOM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700118 [0x5c] = KEY_PAUSE,
119 [0x3c] = KEY_C, /* || (red) */
120 [0x7c] = KEY_RECORD, /* recording */
121 [0x1c] = KEY_STOP,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700123 [0x41] = KEY_REWIND, /* backward << */
124 [0x21] = KEY_PLAY,
125 [0x61] = KEY_FASTFORWARD, /* forward >> */
126 [0x01] = KEY_NEXT, /* skip >| */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129/* ---------------------------------------------------------------------- */
130
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700131/* ADS Tech Instant TV DVB-T PCI Remote */
132static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700133 /* Keys 0 to 9 */
134 [0x4d] = KEY_0,
135 [0x57] = KEY_1,
136 [0x4f] = KEY_2,
137 [0x53] = KEY_3,
138 [0x56] = KEY_4,
139 [0x4e] = KEY_5,
140 [0x5e] = KEY_6,
141 [0x54] = KEY_7,
142 [0x4c] = KEY_8,
143 [0x5c] = KEY_9,
144
145 [0x5b] = KEY_POWER,
146 [0x5f] = KEY_MUTE,
147 [0x55] = KEY_GOTO,
148 [0x5d] = KEY_SEARCH,
149 [0x17] = KEY_EPG, /* Guide */
150 [0x1f] = KEY_MENU,
151 [0x0f] = KEY_UP,
152 [0x46] = KEY_DOWN,
153 [0x16] = KEY_LEFT,
154 [0x1e] = KEY_RIGHT,
155 [0x0e] = KEY_SELECT, /* Enter */
156 [0x5a] = KEY_INFO,
157 [0x52] = KEY_EXIT,
158 [0x59] = KEY_PREVIOUS,
159 [0x51] = KEY_NEXT,
160 [0x58] = KEY_REWIND,
161 [0x50] = KEY_FORWARD,
162 [0x44] = KEY_PLAYPAUSE,
163 [0x07] = KEY_STOP,
164 [0x1b] = KEY_RECORD,
165 [0x13] = KEY_TUNER, /* Live */
166 [0x0a] = KEY_A,
167 [0x12] = KEY_B,
168 [0x03] = KEY_PROG1, /* 1 */
169 [0x01] = KEY_PROG2, /* 2 */
170 [0x00] = KEY_PROG3, /* 3 */
171 [0x06] = KEY_DVD,
172 [0x48] = KEY_AUX, /* Photo */
173 [0x40] = KEY_VIDEO,
174 [0x19] = KEY_AUDIO, /* Music */
175 [0x0b] = KEY_CHANNELUP,
176 [0x08] = KEY_CHANNELDOWN,
177 [0x15] = KEY_VOLUMEUP,
178 [0x1c] = KEY_VOLUMEDOWN,
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700179};
180
181/* ---------------------------------------------------------------------- */
182
183/* MSI TV@nywhere remote */
184static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700185 /* Keys 0 to 9 */
186 [0x00] = KEY_0,
187 [0x01] = KEY_1,
188 [0x02] = KEY_2,
189 [0x03] = KEY_3,
190 [0x04] = KEY_4,
191 [0x05] = KEY_5,
192 [0x06] = KEY_6,
193 [0x07] = KEY_7,
194 [0x08] = KEY_8,
195 [0x09] = KEY_9,
196
197 [0x0c] = KEY_MUTE,
198 [0x0f] = KEY_SCREEN, /* Full Screen */
199 [0x10] = KEY_F, /* Funtion */
200 [0x11] = KEY_T, /* Time shift */
201 [0x12] = KEY_POWER,
202 [0x13] = KEY_MEDIA, /* MTS */
203 [0x14] = KEY_SLOW,
204 [0x16] = KEY_REWIND, /* backward << */
205 [0x17] = KEY_ENTER, /* Return */
206 [0x18] = KEY_FASTFORWARD, /* forward >> */
207 [0x1a] = KEY_CHANNELUP,
208 [0x1b] = KEY_VOLUMEUP,
209 [0x1e] = KEY_CHANNELDOWN,
210 [0x1f] = KEY_VOLUMEDOWN,
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700211};
212
213/* ---------------------------------------------------------------------- */
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215struct cx88_IR {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700216 struct cx88_core *core;
217 struct input_dev input;
218 struct ir_input_state ir;
219 char name[32];
220 char phys[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* sample from gpio pin 16 */
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700223 int sampling;
224 u32 samples[16];
225 int scount;
226 unsigned long release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* poll external decoder */
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700229 int polling;
230 struct work_struct work;
231 struct timer_list timer;
232 u32 gpio_addr;
233 u32 last_gpio;
234 u32 mask_keycode;
235 u32 mask_keydown;
236 u32 mask_keyup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
239static int ir_debug = 0;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700240module_param(ir_debug, int, 0644); /* debug level [IR] */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
242
243#define ir_dprintk(fmt, arg...) if (ir_debug) \
244 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name, ## arg)
245
246/* ---------------------------------------------------------------------- */
247
248static void cx88_ir_handle_key(struct cx88_IR *ir)
249{
250 struct cx88_core *core = ir->core;
251 u32 gpio, data;
252
253 /* read gpio value */
254 gpio = cx_read(ir->gpio_addr);
255 if (ir->polling) {
256 if (ir->last_gpio == gpio)
257 return;
258 ir->last_gpio = gpio;
259 }
260
261 /* extract data */
262 data = ir_extract_bits(gpio, ir->mask_keycode);
263 ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700264 gpio, data,
265 ir->polling ? "poll" : "irq",
266 (gpio & ir->mask_keydown) ? " down" : "",
267 (gpio & ir->mask_keyup) ? " up" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 if (ir->mask_keydown) {
270 /* bit set on keydown */
271 if (gpio & ir->mask_keydown) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700272 ir_input_keydown(&ir->input, &ir->ir, data, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 } else {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700274 ir_input_nokey(&ir->input, &ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 } else if (ir->mask_keyup) {
278 /* bit cleared on keydown */
279 if (0 == (gpio & ir->mask_keyup)) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700280 ir_input_keydown(&ir->input, &ir->ir, data, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 } else {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700282 ir_input_nokey(&ir->input, &ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 } else {
286 /* can't distinguish keydown/up :-/ */
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700287 ir_input_keydown(&ir->input, &ir->ir, data, data);
288 ir_input_nokey(&ir->input, &ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290}
291
292static void ir_timer(unsigned long data)
293{
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700294 struct cx88_IR *ir = (struct cx88_IR *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 schedule_work(&ir->work);
297}
298
299static void cx88_ir_work(void *data)
300{
301 struct cx88_IR *ir = data;
302 unsigned long timeout;
303
304 cx88_ir_handle_key(ir);
305 timeout = jiffies + (ir->polling * HZ / 1000);
306 mod_timer(&ir->timer, timeout);
307}
308
309/* ---------------------------------------------------------------------- */
310
311int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
312{
313 struct cx88_IR *ir;
314 IR_KEYTAB_TYPE *ir_codes = NULL;
315 int ir_type = IR_TYPE_OTHER;
316
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700317 ir = kmalloc(sizeof(*ir), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (NULL == ir)
319 return -ENOMEM;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700320 memset(ir, 0, sizeof(*ir));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* detect & configure */
323 switch (core->board) {
324 case CX88_BOARD_DNTV_LIVE_DVB_T:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700325 case CX88_BOARD_KWORLD_DVB_T:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700326 ir_codes = ir_codes_dntv_live_dvb_t;
327 ir->gpio_addr = MO_GP1_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 ir->mask_keycode = 0x1f;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700329 ir->mask_keyup = 0x60;
330 ir->polling = 50; /* ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 break;
332 case CX88_BOARD_HAUPPAUGE:
333 case CX88_BOARD_HAUPPAUGE_DVB_T1:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700334 ir_codes = ir_codes_hauppauge_new;
335 ir_type = IR_TYPE_RC5;
336 ir->sampling = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 break;
338 case CX88_BOARD_WINFAST2000XP_EXPERT:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700339 ir_codes = ir_codes_winfast;
340 ir->gpio_addr = MO_GP0_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 ir->mask_keycode = 0x8f8;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700342 ir->mask_keyup = 0x100;
343 ir->polling = 1; /* ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
345 case CX88_BOARD_IODATA_GVBCTV7E:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700346 ir_codes = ir_codes_iodata_bctv7e;
347 ir->gpio_addr = MO_GP0_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 ir->mask_keycode = 0xfd;
349 ir->mask_keydown = 0x02;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700350 ir->polling = 5; /* ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
Manuel Capinha239df2e2005-06-23 22:04:53 -0700352 case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700353 ir_codes = ir_codes_pixelview;
354 ir->gpio_addr = MO_GP1_IO;
Manuel Capinha239df2e2005-06-23 22:04:53 -0700355 ir->mask_keycode = 0x1f;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700356 ir->mask_keyup = 0x80;
357 ir->polling = 1; /* ms */
Manuel Capinha239df2e2005-06-23 22:04:53 -0700358 break;
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700359 case CX88_BOARD_ADSTECH_DVB_T_PCI:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700360 ir_codes = ir_codes_adstech_dvb_t_pci;
361 ir->gpio_addr = MO_GP1_IO;
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700362 ir->mask_keycode = 0xbf;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700363 ir->mask_keyup = 0x40;
364 ir->polling = 50; /* ms */
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -0700365 break;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700366 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
367 ir_codes = ir_codes_msi_tvanywhere;
368 ir->gpio_addr = MO_GP1_IO;
369 ir->mask_keycode = 0x1f;
370 ir->mask_keyup = 0x40;
371 ir->polling = 1; /* ms */
372 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -0700374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (NULL == ir_codes) {
376 kfree(ir);
377 return -ENODEV;
378 }
379
380 /* init input device */
381 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
382 cx88_boards[core->board].name);
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700383 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes);
386 ir->input.name = ir->name;
387 ir->input.phys = ir->phys;
388 ir->input.id.bustype = BUS_PCI;
389 ir->input.id.version = 1;
390 if (pci->subsystem_vendor) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700391 ir->input.id.vendor = pci->subsystem_vendor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 ir->input.id.product = pci->subsystem_device;
393 } else {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700394 ir->input.id.vendor = pci->vendor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 ir->input.id.product = pci->device;
396 }
397
398 /* record handles to ourself */
399 ir->core = core;
400 core->ir = ir;
401
402 if (ir->polling) {
403 INIT_WORK(&ir->work, cx88_ir_work, ir);
404 init_timer(&ir->timer);
405 ir->timer.function = ir_timer;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700406 ir->timer.data = (unsigned long)ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 schedule_work(&ir->work);
408 }
409 if (ir->sampling) {
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700410 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
411 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
412 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414
415 /* all done */
416 input_register_device(&ir->input);
417 printk("%s: registered IR remote control\n", core->name);
418
419 return 0;
420}
421
422int cx88_ir_fini(struct cx88_core *core)
423{
424 struct cx88_IR *ir = core->ir;
425
426 /* skip detach on non attached boards */
427 if (NULL == ir)
428 return 0;
429
430 if (ir->polling) {
431 del_timer(&ir->timer);
432 flush_scheduled_work();
433 }
434
435 input_unregister_device(&ir->input);
436 kfree(ir);
437
438 /* done */
439 core->ir = NULL;
440 return 0;
441}
442
443/* ---------------------------------------------------------------------- */
444
445void cx88_ir_irq(struct cx88_core *core)
446{
447 struct cx88_IR *ir = core->ir;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700448 u32 samples, rc5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 int i;
450
451 if (NULL == ir)
452 return;
453 if (!ir->sampling)
454 return;
455
456 samples = cx_read(MO_SAMPLE_IO);
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700457 if (0 != samples && 0xffffffff != samples) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* record sample data */
459 if (ir->scount < ARRAY_SIZE(ir->samples))
460 ir->samples[ir->scount++] = samples;
461 return;
462 }
463 if (!ir->scount) {
464 /* nothing to sample */
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700465 if (ir->ir.keypressed && time_after(jiffies, ir->release))
466 ir_input_nokey(&ir->input, &ir->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return;
468 }
469
470 /* have a complete sample */
471 if (ir->scount < ARRAY_SIZE(ir->samples))
472 ir->samples[ir->scount++] = samples;
473 for (i = 0; i < ir->scount; i++)
474 ir->samples[i] = ~ir->samples[i];
475 if (ir_debug)
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700476 ir_dump_samples(ir->samples, ir->scount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 /* decode it */
479 switch (core->board) {
480 case CX88_BOARD_HAUPPAUGE:
481 case CX88_BOARD_HAUPPAUGE_DVB_T1:
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700482 rc5 = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
483 ir_dprintk("biphase decoded: %x\n", rc5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if ((rc5 & 0xfffff000) != 0x3000)
485 break;
486 ir_input_keydown(&ir->input, &ir->ir, rc5 & 0x3f, rc5);
487 ir->release = jiffies + msecs_to_jiffies(120);
488 break;
489 }
490
491 ir->scount = 0;
492 return;
493}
494
495/* ---------------------------------------------------------------------- */
496
497MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
498MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
499MODULE_LICENSE("GPL");
500
501/*
502 * Local variables:
503 * c-basic-offset: 8
504 * End:
505 */