cx88-input.c 14.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*
 *
 * Device driver for GPIO attached remote control interfaces
 * on Conexant 2388x based TV/DVB cards.
 *
 * Copyright (c) 2003 Pavel Machek
 * Copyright (c) 2004 Gerd Knorr
8
 * Copyright (c) 2004, 2005 Chris Pascoe
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <linux/init.h>
26
#include <linux/hrtimer.h>
L
Linus Torvalds 已提交
27 28
#include <linux/input.h>
#include <linux/pci.h>
29
#include <linux/slab.h>
L
Linus Torvalds 已提交
30 31 32
#include <linux/module.h>

#include "cx88.h"
33
#include <media/ir-common.h>
L
Linus Torvalds 已提交
34 35 36 37

/* ---------------------------------------------------------------------- */

struct cx88_IR {
M
Mauro Carvalho Chehab 已提交
38
	struct cx88_core *core;
39
	struct input_dev *input;
M
Mauro Carvalho Chehab 已提交
40 41 42
	struct ir_input_state ir;
	char name[32];
	char phys[32];
L
Linus Torvalds 已提交
43 44

	/* sample from gpio pin 16 */
45
	u32 sampling;
M
Mauro Carvalho Chehab 已提交
46 47 48
	u32 samples[16];
	int scount;
	unsigned long release;
L
Linus Torvalds 已提交
49 50

	/* poll external decoder */
M
Mauro Carvalho Chehab 已提交
51
	int polling;
52
	struct hrtimer timer;
M
Mauro Carvalho Chehab 已提交
53 54 55 56 57
	u32 gpio_addr;
	u32 last_gpio;
	u32 mask_keycode;
	u32 mask_keydown;
	u32 mask_keyup;
L
Linus Torvalds 已提交
58 59
};

60
static int ir_debug;
M
Mauro Carvalho Chehab 已提交
61
module_param(ir_debug, int, 0644);	/* debug level [IR] */
L
Linus Torvalds 已提交
62 63 64
MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");

#define ir_dprintk(fmt, arg...)	if (ir_debug) \
65
	printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg)
L
Linus Torvalds 已提交
66 67 68 69 70 71

/* ---------------------------------------------------------------------- */

static void cx88_ir_handle_key(struct cx88_IR *ir)
{
	struct cx88_core *core = ir->core;
72
	u32 gpio, data, auxgpio;
L
Linus Torvalds 已提交
73 74 75

	/* read gpio value */
	gpio = cx_read(ir->gpio_addr);
76
	switch (core->boardnr) {
77
	case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
78 79 80 81 82 83 84 85 86 87 88 89 90 91
		/* This board apparently uses a combination of 2 GPIO
		   to represent the keys. Additionally, the second GPIO
		   can be used for parity.

		   Example:

		   for key "5"
			gpio = 0x758, auxgpio = 0xe5 or 0xf5
		   for key "Power"
			gpio = 0x758, auxgpio = 0xed or 0xfd
		 */

		auxgpio = cx_read(MO_GP1_IO);
		/* Take out the parity part */
92
		gpio=(gpio & 0x7fd) + (auxgpio & 0xef);
93 94
		break;
	case CX88_BOARD_WINFAST_DTV1000:
95
	case CX88_BOARD_WINFAST_DTV1800H:
96
	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
97 98
		gpio = (gpio & 0x6ff) | ((cx_read(MO_GP1_IO) << 8) & 0x900);
		auxgpio = gpio;
99 100
		break;
	default:
101
		auxgpio = gpio;
102
	}
L
Linus Torvalds 已提交
103
	if (ir->polling) {
104
		if (ir->last_gpio == auxgpio)
L
Linus Torvalds 已提交
105
			return;
106
		ir->last_gpio = auxgpio;
L
Linus Torvalds 已提交
107 108 109 110 111
	}

	/* extract data */
	data = ir_extract_bits(gpio, ir->mask_keycode);
	ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
M
Mauro Carvalho Chehab 已提交
112 113 114 115
		   gpio, data,
		   ir->polling ? "poll" : "irq",
		   (gpio & ir->mask_keydown) ? " down" : "",
		   (gpio & ir->mask_keyup) ? " up" : "");
L
Linus Torvalds 已提交
116

117
	if (ir->core->boardnr == CX88_BOARD_NORWOOD_MICRO) {
118 119 120 121
		u32 gpio_key = cx_read(MO_GP0_IO);

		data = (data << 4) | ((gpio_key & 0xf0) >> 4);

122
		ir_input_keydown(ir->input, &ir->ir, data);
123 124 125
		ir_input_nokey(ir->input, &ir->ir);

	} else if (ir->mask_keydown) {
L
Linus Torvalds 已提交
126 127
		/* bit set on keydown */
		if (gpio & ir->mask_keydown) {
128
			ir_input_keydown(ir->input, &ir->ir, data);
L
Linus Torvalds 已提交
129
		} else {
130
			ir_input_nokey(ir->input, &ir->ir);
L
Linus Torvalds 已提交
131 132 133 134 135
		}

	} else if (ir->mask_keyup) {
		/* bit cleared on keydown */
		if (0 == (gpio & ir->mask_keyup)) {
136
			ir_input_keydown(ir->input, &ir->ir, data);
L
Linus Torvalds 已提交
137
		} else {
138
			ir_input_nokey(ir->input, &ir->ir);
L
Linus Torvalds 已提交
139 140 141 142
		}

	} else {
		/* can't distinguish keydown/up :-/ */
143
		ir_input_keydown(ir->input, &ir->ir, data);
144
		ir_input_nokey(ir->input, &ir->ir);
L
Linus Torvalds 已提交
145 146 147
	}
}

148
static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
L
Linus Torvalds 已提交
149
{
150 151
	unsigned long missed;
	struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);
L
Linus Torvalds 已提交
152 153

	cx88_ir_handle_key(ir);
154 155 156 157 158 159
	missed = hrtimer_forward_now(&ir->timer,
				     ktime_set(0, ir->polling * 1000000));
	if (missed > 1)
		ir_dprintk("Missed ticks %ld\n", missed - 1);

	return HRTIMER_RESTART;
L
Linus Torvalds 已提交
160 161
}

162
void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
163 164
{
	if (ir->polling) {
165 166 167 168 169
		hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
		ir->timer.function = cx88_ir_work;
		hrtimer_start(&ir->timer,
			      ktime_set(0, ir->polling * 1000000),
			      HRTIMER_MODE_REL);
170 171
	}
	if (ir->sampling) {
172
		core->pci_irqmask |= PCI_INT_IR_SMPINT;
173 174 175 176 177
		cx_write(MO_DDS_IO, 0xa80a80);	/* 4 kHz sample rate */
		cx_write(MO_DDSCFG_IO, 0x5);	/* enable */
	}
}

178
void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
179 180 181
{
	if (ir->sampling) {
		cx_write(MO_DDSCFG_IO, 0x0);
182
		core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
183 184
	}

185
	if (ir->polling)
186
		hrtimer_cancel(&ir->timer);
187 188
}

L
Linus Torvalds 已提交
189 190 191 192 193
/* ---------------------------------------------------------------------- */

int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
{
	struct cx88_IR *ir;
194
	struct input_dev *input_dev;
195
	struct ir_scancode_table *ir_codes = NULL;
196
	u64 ir_type = IR_TYPE_OTHER;
197
	int err = -ENOMEM;
L
Linus Torvalds 已提交
198

199 200
	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
201 202
	if (!ir || !input_dev)
		goto err_out_free;
203 204

	ir->input = input_dev;
L
Linus Torvalds 已提交
205 206

	/* detect & configure */
207
	switch (core->boardnr) {
L
Linus Torvalds 已提交
208
	case CX88_BOARD_DNTV_LIVE_DVB_T:
209
	case CX88_BOARD_KWORLD_DVB_T:
210
	case CX88_BOARD_KWORLD_DVB_T_CX22702:
211
		ir_codes = &ir_codes_dntv_live_dvb_t_table;
M
Mauro Carvalho Chehab 已提交
212
		ir->gpio_addr = MO_GP1_IO;
L
Linus Torvalds 已提交
213
		ir->mask_keycode = 0x1f;
M
Mauro Carvalho Chehab 已提交
214 215
		ir->mask_keyup = 0x60;
		ir->polling = 50; /* ms */
L
Linus Torvalds 已提交
216
		break;
217
	case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
218
		ir_codes = &ir_codes_cinergy_1400_table;
219
		ir_type = IR_TYPE_PD;
220
		ir->sampling = 0xeb04; /* address */
221
		break;
L
Linus Torvalds 已提交
222 223
	case CX88_BOARD_HAUPPAUGE:
	case CX88_BOARD_HAUPPAUGE_DVB_T1:
224 225
	case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
	case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
226
	case CX88_BOARD_HAUPPAUGE_HVR1100:
227
	case CX88_BOARD_HAUPPAUGE_HVR3000:
228 229
	case CX88_BOARD_HAUPPAUGE_HVR4000:
	case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
230 231
	case CX88_BOARD_PCHDTV_HD3000:
	case CX88_BOARD_PCHDTV_HD5500:
232
	case CX88_BOARD_HAUPPAUGE_IRONLY:
233
		ir_codes = &ir_codes_hauppauge_new_table;
M
Mauro Carvalho Chehab 已提交
234 235
		ir_type = IR_TYPE_RC5;
		ir->sampling = 1;
L
Linus Torvalds 已提交
236
		break;
237
	case CX88_BOARD_WINFAST_DTV2000H:
238
	case CX88_BOARD_WINFAST_DTV2000H_J:
239
	case CX88_BOARD_WINFAST_DTV1800H:
240
		ir_codes = &ir_codes_winfast_table;
M
Mauro Carvalho Chehab 已提交
241
		ir->gpio_addr = MO_GP0_IO;
L
Linus Torvalds 已提交
242
		ir->mask_keycode = 0x8f8;
M
Mauro Carvalho Chehab 已提交
243
		ir->mask_keyup = 0x100;
244
		ir->polling = 50; /* ms */
L
Linus Torvalds 已提交
245
		break;
246
	case CX88_BOARD_WINFAST2000XP_EXPERT:
247
	case CX88_BOARD_WINFAST_DTV1000:
248
	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
249
		ir_codes = &ir_codes_winfast_table;
250 251 252 253 254
		ir->gpio_addr = MO_GP0_IO;
		ir->mask_keycode = 0x8f8;
		ir->mask_keyup = 0x100;
		ir->polling = 1; /* ms */
		break;
L
Linus Torvalds 已提交
255
	case CX88_BOARD_IODATA_GVBCTV7E:
256
		ir_codes = &ir_codes_iodata_bctv7e_table;
M
Mauro Carvalho Chehab 已提交
257
		ir->gpio_addr = MO_GP0_IO;
L
Linus Torvalds 已提交
258 259
		ir->mask_keycode = 0xfd;
		ir->mask_keydown = 0x02;
M
Mauro Carvalho Chehab 已提交
260
		ir->polling = 5; /* ms */
L
Linus Torvalds 已提交
261
		break;
262
	case CX88_BOARD_PROLINK_PLAYTVPVR:
263
	case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
264
		ir_codes = &ir_codes_pixelview_table;
M
Mauro Carvalho Chehab 已提交
265
		ir->gpio_addr = MO_GP1_IO;
266
		ir->mask_keycode = 0x1f;
M
Mauro Carvalho Chehab 已提交
267 268
		ir->mask_keyup = 0x80;
		ir->polling = 1; /* ms */
269
		break;
270
	case CX88_BOARD_PROLINK_PV_8000GT:
271
	case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
272
		ir_codes = &ir_codes_pixelview_new_table;
273 274 275 276 277
		ir->gpio_addr = MO_GP1_IO;
		ir->mask_keycode = 0x3f;
		ir->mask_keyup = 0x80;
		ir->polling = 1; /* ms */
		break;
278
	case CX88_BOARD_KWORLD_LTV883:
279
		ir_codes = &ir_codes_pixelview_table;
280 281 282 283 284
		ir->gpio_addr = MO_GP1_IO;
		ir->mask_keycode = 0x1f;
		ir->mask_keyup = 0x60;
		ir->polling = 1; /* ms */
		break;
M
Mauro Carvalho Chehab 已提交
285
	case CX88_BOARD_ADSTECH_DVB_T_PCI:
286
		ir_codes = &ir_codes_adstech_dvb_t_pci_table;
M
Mauro Carvalho Chehab 已提交
287
		ir->gpio_addr = MO_GP1_IO;
M
Mauro Carvalho Chehab 已提交
288
		ir->mask_keycode = 0xbf;
M
Mauro Carvalho Chehab 已提交
289 290 291 292
		ir->mask_keyup = 0x40;
		ir->polling = 50; /* ms */
		break;
	case CX88_BOARD_MSI_TVANYWHERE_MASTER:
293
		ir_codes = &ir_codes_msi_tvanywhere_table;
M
Mauro Carvalho Chehab 已提交
294 295 296 297
		ir->gpio_addr = MO_GP1_IO;
		ir->mask_keycode = 0x1f;
		ir->mask_keyup = 0x40;
		ir->polling = 1; /* ms */
M
Mauro Carvalho Chehab 已提交
298
		break;
299
	case CX88_BOARD_AVERTV_303:
300
	case CX88_BOARD_AVERTV_STUDIO_303:
301
		ir_codes         = &ir_codes_avertv_303_table;
302 303 304 305 306
		ir->gpio_addr    = MO_GP2_IO;
		ir->mask_keycode = 0xfb;
		ir->mask_keydown = 0x02;
		ir->polling      = 50; /* ms */
		break;
307 308 309 310 311
	case CX88_BOARD_OMICOM_SS4_PCI:
	case CX88_BOARD_SATTRADE_ST4200:
	case CX88_BOARD_TBS_8920:
	case CX88_BOARD_TBS_8910:
	case CX88_BOARD_PROF_7300:
312
	case CX88_BOARD_PROF_7301:
313 314 315 316 317 318 319
	case CX88_BOARD_PROF_6200:
		ir_codes = &ir_codes_tbs_nec_table;
		ir_type = IR_TYPE_PD;
		ir->sampling = 0xff00; /* address */
		break;
	case CX88_BOARD_TEVII_S460:
	case CX88_BOARD_TEVII_S420:
320
		ir_codes = &ir_codes_tevii_nec_table;
321 322 323
		ir_type = IR_TYPE_PD;
		ir->sampling = 0xff00; /* address */
		break;
324
	case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
325 326 327
		ir_codes         = &ir_codes_dntv_live_dvbt_pro_table;
		ir_type          = IR_TYPE_PD;
		ir->sampling     = 0xff00; /* address */
328
		break;
329
	case CX88_BOARD_NORWOOD_MICRO:
330
		ir_codes         = &ir_codes_norwood_table;
331 332 333 334 335
		ir->gpio_addr    = MO_GP1_IO;
		ir->mask_keycode = 0x0e;
		ir->mask_keyup   = 0x80;
		ir->polling      = 50; /* ms */
		break;
336
	case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
337 338
		ir_codes         = &ir_codes_npgtech_table;
		ir->gpio_addr    = MO_GP0_IO;
339
		ir->mask_keycode = 0xfa;
340
		ir->polling      = 50; /* ms */
341
		break;
342
	case CX88_BOARD_PINNACLE_PCTV_HD_800i:
343 344 345
		ir_codes         = &ir_codes_pinnacle_pctv_hd_table;
		ir_type          = IR_TYPE_RC5;
		ir->sampling     = 1;
346
		break;
347
	case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
348 349
		ir_codes         = &ir_codes_powercolor_real_angel_table;
		ir->gpio_addr    = MO_GP2_IO;
350
		ir->mask_keycode = 0x7e;
351
		ir->polling      = 100; /* ms */
352
		break;
L
Linus Torvalds 已提交
353
	}
354

L
Linus Torvalds 已提交
355
	if (NULL == ir_codes) {
356 357
		err = -ENODEV;
		goto err_out_free;
L
Linus Torvalds 已提交
358 359 360
	}

	/* init input device */
361
	snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
M
Mauro Carvalho Chehab 已提交
362
	snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
L
Linus Torvalds 已提交
363

364
	err = ir_input_init(input_dev, &ir->ir, ir_type);
365 366 367
	if (err < 0)
		goto err_out_free;

368 369 370 371
	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_PCI;
	input_dev->id.version = 1;
L
Linus Torvalds 已提交
372
	if (pci->subsystem_vendor) {
373 374
		input_dev->id.vendor = pci->subsystem_vendor;
		input_dev->id.product = pci->subsystem_device;
L
Linus Torvalds 已提交
375
	} else {
376 377
		input_dev->id.vendor = pci->vendor;
		input_dev->id.product = pci->device;
L
Linus Torvalds 已提交
378
	}
379
	input_dev->dev.parent = &pci->dev;
L
Linus Torvalds 已提交
380 381 382 383
	/* record handles to ourself */
	ir->core = core;
	core->ir = ir;

384
	cx88_ir_start(core, ir);
L
Linus Torvalds 已提交
385 386

	/* all done */
387
	err = ir_input_register(ir->input, ir_codes, NULL);
388 389
	if (err)
		goto err_out_stop;
L
Linus Torvalds 已提交
390 391

	return 0;
392 393 394 395 396 397 398

 err_out_stop:
	cx88_ir_stop(core, ir);
	core->ir = NULL;
 err_out_free:
	kfree(ir);
	return err;
L
Linus Torvalds 已提交
399 400 401 402 403 404 405 406 407 408
}

int cx88_ir_fini(struct cx88_core *core)
{
	struct cx88_IR *ir = core->ir;

	/* skip detach on non attached boards */
	if (NULL == ir)
		return 0;

409
	cx88_ir_stop(core, ir);
410
	ir_input_unregister(ir->input);
L
Linus Torvalds 已提交
411 412 413 414 415 416 417 418 419 420 421 422
	kfree(ir);

	/* done */
	core->ir = NULL;
	return 0;
}

/* ---------------------------------------------------------------------- */

void cx88_ir_irq(struct cx88_core *core)
{
	struct cx88_IR *ir = core->ir;
423
	u32 samples, ircode;
424
	int i, start, range, toggle, dev, code;
L
Linus Torvalds 已提交
425 426 427 428 429 430 431

	if (NULL == ir)
		return;
	if (!ir->sampling)
		return;

	samples = cx_read(MO_SAMPLE_IO);
M
Mauro Carvalho Chehab 已提交
432
	if (0 != samples && 0xffffffff != samples) {
L
Linus Torvalds 已提交
433 434 435 436 437 438 439
		/* record sample data */
		if (ir->scount < ARRAY_SIZE(ir->samples))
			ir->samples[ir->scount++] = samples;
		return;
	}
	if (!ir->scount) {
		/* nothing to sample */
M
Mauro Carvalho Chehab 已提交
440
		if (ir->ir.keypressed && time_after(jiffies, ir->release))
441
			ir_input_nokey(ir->input, &ir->ir);
L
Linus Torvalds 已提交
442 443 444 445 446 447 448 449 450
		return;
	}

	/* have a complete sample */
	if (ir->scount < ARRAY_SIZE(ir->samples))
		ir->samples[ir->scount++] = samples;
	for (i = 0; i < ir->scount; i++)
		ir->samples[i] = ~ir->samples[i];
	if (ir_debug)
M
Mauro Carvalho Chehab 已提交
451
		ir_dump_samples(ir->samples, ir->scount);
L
Linus Torvalds 已提交
452 453

	/* decode it */
454
	switch (core->boardnr) {
455 456
	case CX88_BOARD_TEVII_S460:
	case CX88_BOARD_TEVII_S420:
457
	case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
458
	case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
459 460 461 462 463
	case CX88_BOARD_OMICOM_SS4_PCI:
	case CX88_BOARD_SATTRADE_ST4200:
	case CX88_BOARD_TBS_8920:
	case CX88_BOARD_TBS_8910:
	case CX88_BOARD_PROF_7300:
464
	case CX88_BOARD_PROF_7301:
465
	case CX88_BOARD_PROF_6200:
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
		ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);

		if (ircode == 0xffffffff) { /* decoding error */
			ir_dprintk("pulse distance decoding error\n");
			break;
		}

		ir_dprintk("pulse distance decoded: %x\n", ircode);

		if (ircode == 0) { /* key still pressed */
			ir_dprintk("pulse distance decoded repeat code\n");
			ir->release = jiffies + msecs_to_jiffies(120);
			break;
		}

481
		if ((ircode & 0xffff) != (ir->sampling & 0xffff)) { /* wrong address */
482
			ir_dprintk("pulse distance decoded wrong address\n");
483
			break;
484 485 486 487 488 489 490 491 492
		}

		if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */
			ir_dprintk("pulse distance decoded wrong check sum\n");
			break;
		}

		ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f);

493
		ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f);
494 495
		ir->release = jiffies + msecs_to_jiffies(120);
		break;
L
Linus Torvalds 已提交
496 497
	case CX88_BOARD_HAUPPAUGE:
	case CX88_BOARD_HAUPPAUGE_DVB_T1:
498 499
	case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
	case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
C
 
Chris Pascoe 已提交
500
	case CX88_BOARD_HAUPPAUGE_HVR1100:
501
	case CX88_BOARD_HAUPPAUGE_HVR3000:
502 503
	case CX88_BOARD_HAUPPAUGE_HVR4000:
	case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
504 505
	case CX88_BOARD_PCHDTV_HD3000:
	case CX88_BOARD_PCHDTV_HD5500:
506
	case CX88_BOARD_HAUPPAUGE_IRONLY:
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
		ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
		ir_dprintk("biphase decoded: %x\n", ircode);
		/*
		 * RC5 has an extension bit which adds a new range
		 * of available codes, this is detected here. Also
		 * hauppauge remotes (black/silver) always use
		 * specific device ids. If we do not filter the
		 * device ids then messages destined for devices
		 * such as TVs (id=0) will get through to the
		 * device causing mis-fired events.
		 */
		/* split rc5 data block ... */
		start = (ircode & 0x2000) >> 13;
		range = (ircode & 0x1000) >> 12;
		toggle= (ircode & 0x0800) >> 11;
		dev   = (ircode & 0x07c0) >> 6;
		code  = (ircode & 0x003f) | ((range << 6) ^ 0x0040);
		if( start != 1)
			/* no key pressed */
			break;
		if ( dev != 0x1e && dev != 0x1f )
			/* not a hauppauge remote */
			break;
530
		ir_input_keydown(ir->input, &ir->ir, code);
531 532 533
		ir->release = jiffies + msecs_to_jiffies(120);
		break;
	case CX88_BOARD_PINNACLE_PCTV_HD_800i:
534 535 536
		ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
		ir_dprintk("biphase decoded: %x\n", ircode);
		if ((ircode & 0xfffff000) != 0x3000)
L
Linus Torvalds 已提交
537
			break;
538
		ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f);
L
Linus Torvalds 已提交
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
		ir->release = jiffies + msecs_to_jiffies(120);
		break;
	}

	ir->scount = 0;
	return;
}

/* ---------------------------------------------------------------------- */

MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
MODULE_LICENSE("GPL");
/*
 * Local variables:
 * c-basic-offset: 8
 * End:
 */