1 /*
2  *
3  * Device driver for GPIO attached remote control interfaces
4  * on Conexant 2388x based TV/DVB cards.
5  *
6  * Copyright (c) 2003 Pavel Machek
7  * Copyright (c) 2004 Gerd Knorr
8  * Copyright (c) 2004, 2005 Chris Pascoe
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 #include "cx88.h"
22 
23 #include <linux/init.h>
24 #include <linux/hrtimer.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
28 
29 #include <media/rc-core.h>
30 
31 #define MODULE_NAME "cx88xx"
32 
33 /* ---------------------------------------------------------------------- */
34 
35 struct cx88_IR {
36 	struct cx88_core *core;
37 	struct rc_dev *dev;
38 
39 	int users;
40 
41 	char name[32];
42 	char phys[32];
43 
44 	/* sample from gpio pin 16 */
45 	u32 sampling;
46 
47 	/* poll external decoder */
48 	int polling;
49 	struct hrtimer timer;
50 	u32 gpio_addr;
51 	u32 last_gpio;
52 	u32 mask_keycode;
53 	u32 mask_keydown;
54 	u32 mask_keyup;
55 };
56 
57 static unsigned int ir_samplerate = 4;
58 module_param(ir_samplerate, uint, 0444);
59 MODULE_PARM_DESC(ir_samplerate, "IR samplerate in kHz, 1 - 20, default 4");
60 
61 static int ir_debug;
62 module_param(ir_debug, int, 0644);	/* debug level [IR] */
63 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
64 
65 #define ir_dprintk(fmt, arg...)	do {					\
66 	if (ir_debug)							\
67 		printk(KERN_DEBUG "%s IR: " fmt, ir->core->name, ##arg);\
68 } while (0)
69 
70 #define dprintk(fmt, arg...) do {					\
71 	if (ir_debug)							\
72 		printk(KERN_DEBUG "cx88 IR: " fmt, ##arg);		\
73 } while (0)
74 
75 /* ---------------------------------------------------------------------- */
76 
77 static void cx88_ir_handle_key(struct cx88_IR *ir)
78 {
79 	struct cx88_core *core = ir->core;
80 	u32 gpio, data, auxgpio;
81 
82 	/* read gpio value */
83 	gpio = cx_read(ir->gpio_addr);
84 	switch (core->boardnr) {
85 	case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
86 		/*
87 		 * This board apparently uses a combination of 2 GPIO
88 		 * to represent the keys. Additionally, the second GPIO
89 		 * can be used for parity.
90 		 *
91 		 * Example:
92 		 *
93 		 * for key "5"
94 		 *	gpio = 0x758, auxgpio = 0xe5 or 0xf5
95 		 * for key "Power"
96 		 *	gpio = 0x758, auxgpio = 0xed or 0xfd
97 		 */
98 
99 		auxgpio = cx_read(MO_GP1_IO);
100 		/* Take out the parity part */
101 		gpio = (gpio & 0x7fd) + (auxgpio & 0xef);
102 		break;
103 	case CX88_BOARD_WINFAST_DTV1000:
104 	case CX88_BOARD_WINFAST_DTV1800H:
105 	case CX88_BOARD_WINFAST_DTV1800H_XC4000:
106 	case CX88_BOARD_WINFAST_DTV2000H_PLUS:
107 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
108 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36:
109 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43:
110 		gpio = (gpio & 0x6ff) | ((cx_read(MO_GP1_IO) << 8) & 0x900);
111 		auxgpio = gpio;
112 		break;
113 	default:
114 		auxgpio = gpio;
115 	}
116 	if (ir->polling) {
117 		if (ir->last_gpio == auxgpio)
118 			return;
119 		ir->last_gpio = auxgpio;
120 	}
121 
122 	/* extract data */
123 	data = ir_extract_bits(gpio, ir->mask_keycode);
124 	ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
125 		   gpio, data,
126 		   ir->polling ? "poll" : "irq",
127 		   (gpio & ir->mask_keydown) ? " down" : "",
128 		   (gpio & ir->mask_keyup) ? " up" : "");
129 
130 	if (ir->core->boardnr == CX88_BOARD_NORWOOD_MICRO) {
131 		u32 gpio_key = cx_read(MO_GP0_IO);
132 
133 		data = (data << 4) | ((gpio_key & 0xf0) >> 4);
134 
135 		rc_keydown(ir->dev, RC_PROTO_UNKNOWN, data, 0);
136 
137 	} else if (ir->core->boardnr == CX88_BOARD_PROLINK_PLAYTVPVR ||
138 		   ir->core->boardnr == CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO) {
139 		/* bit cleared on keydown, NEC scancode, 0xAAAACC, A = 0x866b */
140 		u16 addr;
141 		u8 cmd;
142 		u32 scancode;
143 
144 		addr = (data >> 8) & 0xffff;
145 		cmd  = (data >> 0) & 0x00ff;
146 		scancode = RC_SCANCODE_NECX(addr, cmd);
147 
148 		if (0 == (gpio & ir->mask_keyup))
149 			rc_keydown_notimeout(ir->dev, RC_PROTO_NECX, scancode,
150 					     0);
151 		else
152 			rc_keyup(ir->dev);
153 
154 	} else if (ir->mask_keydown) {
155 		/* bit set on keydown */
156 		if (gpio & ir->mask_keydown)
157 			rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
158 					     0);
159 		else
160 			rc_keyup(ir->dev);
161 
162 	} else if (ir->mask_keyup) {
163 		/* bit cleared on keydown */
164 		if (0 == (gpio & ir->mask_keyup))
165 			rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
166 					     0);
167 		else
168 			rc_keyup(ir->dev);
169 
170 	} else {
171 		/* can't distinguish keydown/up :-/ */
172 		rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0);
173 		rc_keyup(ir->dev);
174 	}
175 }
176 
177 static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
178 {
179 	unsigned long missed;
180 	struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);
181 
182 	cx88_ir_handle_key(ir);
183 	missed = hrtimer_forward_now(&ir->timer, ir->polling * 1000000);
184 	if (missed > 1)
185 		ir_dprintk("Missed ticks %ld\n", missed - 1);
186 
187 	return HRTIMER_RESTART;
188 }
189 
190 static int __cx88_ir_start(void *priv)
191 {
192 	struct cx88_core *core = priv;
193 	struct cx88_IR *ir;
194 
195 	if (!core || !core->ir)
196 		return -EINVAL;
197 
198 	ir = core->ir;
199 
200 	if (ir->polling) {
201 		hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
202 		ir->timer.function = cx88_ir_work;
203 		hrtimer_start(&ir->timer, ir->polling * 1000000,
204 			      HRTIMER_MODE_REL);
205 	}
206 	if (ir->sampling) {
207 		core->pci_irqmask |= PCI_INT_IR_SMPINT;
208 		cx_write(MO_DDS_IO, 0x33F286 * ir_samplerate); /* samplerate */
209 		cx_write(MO_DDSCFG_IO, 0x5); /* enable */
210 	}
211 	return 0;
212 }
213 
214 static void __cx88_ir_stop(void *priv)
215 {
216 	struct cx88_core *core = priv;
217 	struct cx88_IR *ir;
218 
219 	if (!core || !core->ir)
220 		return;
221 
222 	ir = core->ir;
223 	if (ir->sampling) {
224 		cx_write(MO_DDSCFG_IO, 0x0);
225 		core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
226 	}
227 
228 	if (ir->polling)
229 		hrtimer_cancel(&ir->timer);
230 }
231 
232 int cx88_ir_start(struct cx88_core *core)
233 {
234 	if (core->ir->users)
235 		return __cx88_ir_start(core);
236 
237 	return 0;
238 }
239 EXPORT_SYMBOL(cx88_ir_start);
240 
241 void cx88_ir_stop(struct cx88_core *core)
242 {
243 	if (core->ir->users)
244 		__cx88_ir_stop(core);
245 }
246 EXPORT_SYMBOL(cx88_ir_stop);
247 
248 static int cx88_ir_open(struct rc_dev *rc)
249 {
250 	struct cx88_core *core = rc->priv;
251 
252 	core->ir->users++;
253 	return __cx88_ir_start(core);
254 }
255 
256 static void cx88_ir_close(struct rc_dev *rc)
257 {
258 	struct cx88_core *core = rc->priv;
259 
260 	core->ir->users--;
261 	if (!core->ir->users)
262 		__cx88_ir_stop(core);
263 }
264 
265 /* ---------------------------------------------------------------------- */
266 
267 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
268 {
269 	struct cx88_IR *ir;
270 	struct rc_dev *dev;
271 	char *ir_codes = NULL;
272 	u64 rc_proto = RC_PROTO_BIT_OTHER;
273 	int err = -ENOMEM;
274 	u32 hardware_mask = 0;	/* For devices with a hardware mask, when
275 				 * used with a full-code IR table
276 				 */
277 
278 	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
279 	dev = rc_allocate_device(RC_DRIVER_IR_RAW);
280 	if (!ir || !dev)
281 		goto err_out_free;
282 
283 	ir->dev = dev;
284 
285 	/* detect & configure */
286 	switch (core->boardnr) {
287 	case CX88_BOARD_DNTV_LIVE_DVB_T:
288 	case CX88_BOARD_KWORLD_DVB_T:
289 	case CX88_BOARD_KWORLD_DVB_T_CX22702:
290 		ir_codes = RC_MAP_DNTV_LIVE_DVB_T;
291 		ir->gpio_addr = MO_GP1_IO;
292 		ir->mask_keycode = 0x1f;
293 		ir->mask_keyup = 0x60;
294 		ir->polling = 50; /* ms */
295 		break;
296 	case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
297 		ir_codes = RC_MAP_CINERGY_1400;
298 		ir->sampling = 0xeb04; /* address */
299 		break;
300 	case CX88_BOARD_HAUPPAUGE:
301 	case CX88_BOARD_HAUPPAUGE_DVB_T1:
302 	case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
303 	case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
304 	case CX88_BOARD_HAUPPAUGE_HVR1100:
305 	case CX88_BOARD_HAUPPAUGE_HVR3000:
306 	case CX88_BOARD_HAUPPAUGE_HVR4000:
307 	case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
308 	case CX88_BOARD_PCHDTV_HD3000:
309 	case CX88_BOARD_PCHDTV_HD5500:
310 	case CX88_BOARD_HAUPPAUGE_IRONLY:
311 		ir_codes = RC_MAP_HAUPPAUGE;
312 		ir->sampling = 1;
313 		break;
314 	case CX88_BOARD_WINFAST_DTV2000H:
315 	case CX88_BOARD_WINFAST_DTV2000H_J:
316 	case CX88_BOARD_WINFAST_DTV1800H:
317 	case CX88_BOARD_WINFAST_DTV1800H_XC4000:
318 	case CX88_BOARD_WINFAST_DTV2000H_PLUS:
319 		ir_codes = RC_MAP_WINFAST;
320 		ir->gpio_addr = MO_GP0_IO;
321 		ir->mask_keycode = 0x8f8;
322 		ir->mask_keyup = 0x100;
323 		ir->polling = 50; /* ms */
324 		break;
325 	case CX88_BOARD_WINFAST2000XP_EXPERT:
326 	case CX88_BOARD_WINFAST_DTV1000:
327 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
328 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36:
329 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43:
330 		ir_codes = RC_MAP_WINFAST;
331 		ir->gpio_addr = MO_GP0_IO;
332 		ir->mask_keycode = 0x8f8;
333 		ir->mask_keyup = 0x100;
334 		ir->polling = 1; /* ms */
335 		break;
336 	case CX88_BOARD_IODATA_GVBCTV7E:
337 		ir_codes = RC_MAP_IODATA_BCTV7E;
338 		ir->gpio_addr = MO_GP0_IO;
339 		ir->mask_keycode = 0xfd;
340 		ir->mask_keydown = 0x02;
341 		ir->polling = 5; /* ms */
342 		break;
343 	case CX88_BOARD_PROLINK_PLAYTVPVR:
344 	case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
345 		/*
346 		 * It seems that this hardware is paired with NEC extended
347 		 * address 0x866b. So, unfortunately, its usage with other
348 		 * IR's with different address won't work. Still, there are
349 		 * other IR's from the same manufacturer that works, like the
350 		 * 002-T mini RC, provided with newer PV hardware
351 		 */
352 		ir_codes = RC_MAP_PIXELVIEW_MK12;
353 		rc_proto = RC_PROTO_BIT_NECX;
354 		ir->gpio_addr = MO_GP1_IO;
355 		ir->mask_keyup = 0x80;
356 		ir->polling = 10; /* ms */
357 		hardware_mask = 0x3f;	/* Hardware returns only 6 bits from command part */
358 		break;
359 	case CX88_BOARD_PROLINK_PV_8000GT:
360 	case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
361 		ir_codes = RC_MAP_PIXELVIEW_NEW;
362 		ir->gpio_addr = MO_GP1_IO;
363 		ir->mask_keycode = 0x3f;
364 		ir->mask_keyup = 0x80;
365 		ir->polling = 1; /* ms */
366 		break;
367 	case CX88_BOARD_KWORLD_LTV883:
368 		ir_codes = RC_MAP_PIXELVIEW;
369 		ir->gpio_addr = MO_GP1_IO;
370 		ir->mask_keycode = 0x1f;
371 		ir->mask_keyup = 0x60;
372 		ir->polling = 1; /* ms */
373 		break;
374 	case CX88_BOARD_ADSTECH_DVB_T_PCI:
375 		ir_codes = RC_MAP_ADSTECH_DVB_T_PCI;
376 		ir->gpio_addr = MO_GP1_IO;
377 		ir->mask_keycode = 0xbf;
378 		ir->mask_keyup = 0x40;
379 		ir->polling = 50; /* ms */
380 		break;
381 	case CX88_BOARD_MSI_TVANYWHERE_MASTER:
382 		ir_codes = RC_MAP_MSI_TVANYWHERE;
383 		ir->gpio_addr = MO_GP1_IO;
384 		ir->mask_keycode = 0x1f;
385 		ir->mask_keyup = 0x40;
386 		ir->polling = 1; /* ms */
387 		break;
388 	case CX88_BOARD_AVERTV_303:
389 	case CX88_BOARD_AVERTV_STUDIO_303:
390 		ir_codes         = RC_MAP_AVERTV_303;
391 		ir->gpio_addr    = MO_GP2_IO;
392 		ir->mask_keycode = 0xfb;
393 		ir->mask_keydown = 0x02;
394 		ir->polling      = 50; /* ms */
395 		break;
396 	case CX88_BOARD_OMICOM_SS4_PCI:
397 	case CX88_BOARD_SATTRADE_ST4200:
398 	case CX88_BOARD_TBS_8920:
399 	case CX88_BOARD_TBS_8910:
400 	case CX88_BOARD_PROF_7300:
401 	case CX88_BOARD_PROF_7301:
402 	case CX88_BOARD_PROF_6200:
403 		ir_codes = RC_MAP_TBS_NEC;
404 		ir->sampling = 0xff00; /* address */
405 		break;
406 	case CX88_BOARD_TEVII_S464:
407 	case CX88_BOARD_TEVII_S460:
408 	case CX88_BOARD_TEVII_S420:
409 		ir_codes = RC_MAP_TEVII_NEC;
410 		ir->sampling = 0xff00; /* address */
411 		break;
412 	case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
413 		ir_codes         = RC_MAP_DNTV_LIVE_DVBT_PRO;
414 		ir->sampling     = 0xff00; /* address */
415 		break;
416 	case CX88_BOARD_NORWOOD_MICRO:
417 		ir_codes         = RC_MAP_NORWOOD;
418 		ir->gpio_addr    = MO_GP1_IO;
419 		ir->mask_keycode = 0x0e;
420 		ir->mask_keyup   = 0x80;
421 		ir->polling      = 50; /* ms */
422 		break;
423 	case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
424 		ir_codes         = RC_MAP_NPGTECH;
425 		ir->gpio_addr    = MO_GP0_IO;
426 		ir->mask_keycode = 0xfa;
427 		ir->polling      = 50; /* ms */
428 		break;
429 	case CX88_BOARD_PINNACLE_PCTV_HD_800i:
430 		ir_codes         = RC_MAP_PINNACLE_PCTV_HD;
431 		ir->sampling     = 1;
432 		break;
433 	case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
434 		ir_codes         = RC_MAP_POWERCOLOR_REAL_ANGEL;
435 		ir->gpio_addr    = MO_GP2_IO;
436 		ir->mask_keycode = 0x7e;
437 		ir->polling      = 100; /* ms */
438 		break;
439 	case CX88_BOARD_TWINHAN_VP1027_DVBS:
440 		ir_codes         = RC_MAP_TWINHAN_VP1027_DVBS;
441 		ir->sampling     = 0xff00; /* address */
442 		break;
443 	}
444 
445 	if (!ir_codes) {
446 		err = -ENODEV;
447 		goto err_out_free;
448 	}
449 
450 	/*
451 	 * The usage of mask_keycode were very convenient, due to several
452 	 * reasons. Among others, the scancode tables were using the scancode
453 	 * as the index elements. So, the less bits it was used, the smaller
454 	 * the table were stored. After the input changes, the better is to use
455 	 * the full scancodes, since it allows replacing the IR remote by
456 	 * another one. Unfortunately, there are still some hardware, like
457 	 * Pixelview Ultra Pro, where only part of the scancode is sent via
458 	 * GPIO. So, there's no way to get the full scancode. Due to that,
459 	 * hardware_mask were introduced here: it represents those hardware
460 	 * that has such limits.
461 	 */
462 	if (hardware_mask && !ir->mask_keycode)
463 		ir->mask_keycode = hardware_mask;
464 
465 	/* init input device */
466 	snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
467 	snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
468 
469 	dev->device_name = ir->name;
470 	dev->input_phys = ir->phys;
471 	dev->input_id.bustype = BUS_PCI;
472 	dev->input_id.version = 1;
473 	if (pci->subsystem_vendor) {
474 		dev->input_id.vendor = pci->subsystem_vendor;
475 		dev->input_id.product = pci->subsystem_device;
476 	} else {
477 		dev->input_id.vendor = pci->vendor;
478 		dev->input_id.product = pci->device;
479 	}
480 	dev->dev.parent = &pci->dev;
481 	dev->map_name = ir_codes;
482 	dev->driver_name = MODULE_NAME;
483 	dev->priv = core;
484 	dev->open = cx88_ir_open;
485 	dev->close = cx88_ir_close;
486 	dev->scancode_mask = hardware_mask;
487 
488 	if (ir->sampling) {
489 		dev->timeout = 10 * 1000 * 1000; /* 10 ms */
490 	} else {
491 		dev->driver_type = RC_DRIVER_SCANCODE;
492 		dev->allowed_protocols = rc_proto;
493 	}
494 
495 	ir->core = core;
496 	core->ir = ir;
497 
498 	/* all done */
499 	err = rc_register_device(dev);
500 	if (err)
501 		goto err_out_free;
502 
503 	return 0;
504 
505 err_out_free:
506 	rc_free_device(dev);
507 	core->ir = NULL;
508 	kfree(ir);
509 	return err;
510 }
511 
512 int cx88_ir_fini(struct cx88_core *core)
513 {
514 	struct cx88_IR *ir = core->ir;
515 
516 	/* skip detach on non attached boards */
517 	if (!ir)
518 		return 0;
519 
520 	cx88_ir_stop(core);
521 	rc_unregister_device(ir->dev);
522 	kfree(ir);
523 
524 	/* done */
525 	core->ir = NULL;
526 	return 0;
527 }
528 
529 /* ---------------------------------------------------------------------- */
530 
531 void cx88_ir_irq(struct cx88_core *core)
532 {
533 	struct cx88_IR *ir = core->ir;
534 	u32 samples;
535 	unsigned int todo, bits;
536 	struct ir_raw_event ev;
537 
538 	if (!ir || !ir->sampling)
539 		return;
540 
541 	/*
542 	 * Samples are stored in a 32 bit register, oldest sample in
543 	 * the msb. A set bit represents space and an unset bit
544 	 * represents a pulse.
545 	 */
546 	samples = cx_read(MO_SAMPLE_IO);
547 
548 	if (samples == 0xff && ir->dev->idle)
549 		return;
550 
551 	init_ir_raw_event(&ev);
552 	for (todo = 32; todo > 0; todo -= bits) {
553 		ev.pulse = samples & 0x80000000 ? false : true;
554 		bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
555 		ev.duration = (bits * (NSEC_PER_SEC / 1000)) / ir_samplerate;
556 		ir_raw_event_store_with_filter(ir->dev, &ev);
557 		samples <<= bits;
558 	}
559 	ir_raw_event_handle(ir->dev);
560 }
561 
562 static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol,
563 			   u32 *scancode, u8 *toggle)
564 {
565 	int flags, code;
566 
567 	/* poll IR chip */
568 	flags = i2c_smbus_read_byte_data(ir->c, 0x10);
569 	if (flags < 0) {
570 		dprintk("read error\n");
571 		return 0;
572 	}
573 	/* key pressed ? */
574 	if (0 == (flags & 0x80))
575 		return 0;
576 
577 	/* read actual key code */
578 	code = i2c_smbus_read_byte_data(ir->c, 0x00);
579 	if (code < 0) {
580 		dprintk("read error\n");
581 		return 0;
582 	}
583 
584 	dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
585 		code & 0xff, flags & 0xff);
586 
587 	*protocol = RC_PROTO_UNKNOWN;
588 	*scancode = code & 0xff;
589 	*toggle = 0;
590 	return 1;
591 }
592 
593 void cx88_i2c_init_ir(struct cx88_core *core)
594 {
595 	struct i2c_board_info info;
596 	const unsigned short default_addr_list[] = {
597 		0x18, 0x6b, 0x71,
598 		I2C_CLIENT_END
599 	};
600 	const unsigned short pvr2000_addr_list[] = {
601 		0x18, 0x1a,
602 		I2C_CLIENT_END
603 	};
604 	const unsigned short *addr_list = default_addr_list;
605 	const unsigned short *addrp;
606 	/* Instantiate the IR receiver device, if present */
607 	if (core->i2c_rc != 0)
608 		return;
609 
610 	memset(&info, 0, sizeof(struct i2c_board_info));
611 	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
612 
613 	switch (core->boardnr) {
614 	case CX88_BOARD_LEADTEK_PVR2000:
615 		addr_list = pvr2000_addr_list;
616 		core->init_data.name = "cx88 Leadtek PVR 2000 remote";
617 		core->init_data.type = RC_PROTO_BIT_UNKNOWN;
618 		core->init_data.get_key = get_key_pvr2000;
619 		core->init_data.ir_codes = RC_MAP_EMPTY;
620 		break;
621 	}
622 
623 	/*
624 	 * We can't call i2c_new_probed_device() because it uses
625 	 * quick writes for probing and at least some RC receiver
626 	 * devices only reply to reads.
627 	 * Also, Hauppauge XVR needs to be specified, as address 0x71
628 	 * conflicts with another remote type used with saa7134
629 	 */
630 	for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
631 		info.platform_data = NULL;
632 		memset(&core->init_data, 0, sizeof(core->init_data));
633 
634 		if (*addrp == 0x71) {
635 			/* Hauppauge XVR */
636 			core->init_data.name = "cx88 Hauppauge XVR remote";
637 			core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
638 			core->init_data.type = RC_PROTO_BIT_RC5 |
639 				RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32;
640 			core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
641 
642 			info.platform_data = &core->init_data;
643 		}
644 		if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
645 				   I2C_SMBUS_READ, 0,
646 				   I2C_SMBUS_QUICK, NULL) >= 0) {
647 			info.addr = *addrp;
648 			i2c_new_device(&core->i2c_adap, &info);
649 			break;
650 		}
651 	}
652 }
653 
654 /* ---------------------------------------------------------------------- */
655 
656 MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
657 MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
658 MODULE_LICENSE("GPL");
659