xref: /openbmc/linux/drivers/media/pci/cx88/cx88-input.c (revision 4ed91d48259d9ddd378424d008f2e6559f7e78f8)
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_TYPE_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_TYPE_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_TYPE_UNKNOWN, data, 0);
158 		else
159 			rc_keyup(ir->dev);
160 
161 	} else if (ir->mask_keyup) {
162 		/* bit cleared on keydown */
163 		if (0 == (gpio & ir->mask_keyup))
164 			rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
165 		else
166 			rc_keyup(ir->dev);
167 
168 	} else {
169 		/* can't distinguish keydown/up :-/ */
170 		rc_keydown_notimeout(ir->dev, RC_TYPE_UNKNOWN, data, 0);
171 		rc_keyup(ir->dev);
172 	}
173 }
174 
175 static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
176 {
177 	unsigned long missed;
178 	struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);
179 
180 	cx88_ir_handle_key(ir);
181 	missed = hrtimer_forward_now(&ir->timer, ir->polling * 1000000);
182 	if (missed > 1)
183 		ir_dprintk("Missed ticks %ld\n", missed - 1);
184 
185 	return HRTIMER_RESTART;
186 }
187 
188 static int __cx88_ir_start(void *priv)
189 {
190 	struct cx88_core *core = priv;
191 	struct cx88_IR *ir;
192 
193 	if (!core || !core->ir)
194 		return -EINVAL;
195 
196 	ir = core->ir;
197 
198 	if (ir->polling) {
199 		hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
200 		ir->timer.function = cx88_ir_work;
201 		hrtimer_start(&ir->timer, ir->polling * 1000000,
202 			      HRTIMER_MODE_REL);
203 	}
204 	if (ir->sampling) {
205 		core->pci_irqmask |= PCI_INT_IR_SMPINT;
206 		cx_write(MO_DDS_IO, 0x33F286 * ir_samplerate); /* samplerate */
207 		cx_write(MO_DDSCFG_IO, 0x5); /* enable */
208 	}
209 	return 0;
210 }
211 
212 static void __cx88_ir_stop(void *priv)
213 {
214 	struct cx88_core *core = priv;
215 	struct cx88_IR *ir;
216 
217 	if (!core || !core->ir)
218 		return;
219 
220 	ir = core->ir;
221 	if (ir->sampling) {
222 		cx_write(MO_DDSCFG_IO, 0x0);
223 		core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
224 	}
225 
226 	if (ir->polling)
227 		hrtimer_cancel(&ir->timer);
228 }
229 
230 int cx88_ir_start(struct cx88_core *core)
231 {
232 	if (core->ir->users)
233 		return __cx88_ir_start(core);
234 
235 	return 0;
236 }
237 EXPORT_SYMBOL(cx88_ir_start);
238 
239 void cx88_ir_stop(struct cx88_core *core)
240 {
241 	if (core->ir->users)
242 		__cx88_ir_stop(core);
243 }
244 EXPORT_SYMBOL(cx88_ir_stop);
245 
246 static int cx88_ir_open(struct rc_dev *rc)
247 {
248 	struct cx88_core *core = rc->priv;
249 
250 	core->ir->users++;
251 	return __cx88_ir_start(core);
252 }
253 
254 static void cx88_ir_close(struct rc_dev *rc)
255 {
256 	struct cx88_core *core = rc->priv;
257 
258 	core->ir->users--;
259 	if (!core->ir->users)
260 		__cx88_ir_stop(core);
261 }
262 
263 /* ---------------------------------------------------------------------- */
264 
265 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
266 {
267 	struct cx88_IR *ir;
268 	struct rc_dev *dev;
269 	char *ir_codes = NULL;
270 	u64 rc_type = RC_BIT_OTHER;
271 	int err = -ENOMEM;
272 	u32 hardware_mask = 0;	/* For devices with a hardware mask, when
273 				 * used with a full-code IR table
274 				 */
275 
276 	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
277 	dev = rc_allocate_device(RC_DRIVER_IR_RAW);
278 	if (!ir || !dev)
279 		goto err_out_free;
280 
281 	ir->dev = dev;
282 
283 	/* detect & configure */
284 	switch (core->boardnr) {
285 	case CX88_BOARD_DNTV_LIVE_DVB_T:
286 	case CX88_BOARD_KWORLD_DVB_T:
287 	case CX88_BOARD_KWORLD_DVB_T_CX22702:
288 		ir_codes = RC_MAP_DNTV_LIVE_DVB_T;
289 		ir->gpio_addr = MO_GP1_IO;
290 		ir->mask_keycode = 0x1f;
291 		ir->mask_keyup = 0x60;
292 		ir->polling = 50; /* ms */
293 		break;
294 	case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
295 		ir_codes = RC_MAP_CINERGY_1400;
296 		ir->sampling = 0xeb04; /* address */
297 		break;
298 	case CX88_BOARD_HAUPPAUGE:
299 	case CX88_BOARD_HAUPPAUGE_DVB_T1:
300 	case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
301 	case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
302 	case CX88_BOARD_HAUPPAUGE_HVR1100:
303 	case CX88_BOARD_HAUPPAUGE_HVR3000:
304 	case CX88_BOARD_HAUPPAUGE_HVR4000:
305 	case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
306 	case CX88_BOARD_PCHDTV_HD3000:
307 	case CX88_BOARD_PCHDTV_HD5500:
308 	case CX88_BOARD_HAUPPAUGE_IRONLY:
309 		ir_codes = RC_MAP_HAUPPAUGE;
310 		ir->sampling = 1;
311 		break;
312 	case CX88_BOARD_WINFAST_DTV2000H:
313 	case CX88_BOARD_WINFAST_DTV2000H_J:
314 	case CX88_BOARD_WINFAST_DTV1800H:
315 	case CX88_BOARD_WINFAST_DTV1800H_XC4000:
316 	case CX88_BOARD_WINFAST_DTV2000H_PLUS:
317 		ir_codes = RC_MAP_WINFAST;
318 		ir->gpio_addr = MO_GP0_IO;
319 		ir->mask_keycode = 0x8f8;
320 		ir->mask_keyup = 0x100;
321 		ir->polling = 50; /* ms */
322 		break;
323 	case CX88_BOARD_WINFAST2000XP_EXPERT:
324 	case CX88_BOARD_WINFAST_DTV1000:
325 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
326 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36:
327 	case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43:
328 		ir_codes = RC_MAP_WINFAST;
329 		ir->gpio_addr = MO_GP0_IO;
330 		ir->mask_keycode = 0x8f8;
331 		ir->mask_keyup = 0x100;
332 		ir->polling = 1; /* ms */
333 		break;
334 	case CX88_BOARD_IODATA_GVBCTV7E:
335 		ir_codes = RC_MAP_IODATA_BCTV7E;
336 		ir->gpio_addr = MO_GP0_IO;
337 		ir->mask_keycode = 0xfd;
338 		ir->mask_keydown = 0x02;
339 		ir->polling = 5; /* ms */
340 		break;
341 	case CX88_BOARD_PROLINK_PLAYTVPVR:
342 	case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
343 		/*
344 		 * It seems that this hardware is paired with NEC extended
345 		 * address 0x866b. So, unfortunately, its usage with other
346 		 * IR's with different address won't work. Still, there are
347 		 * other IR's from the same manufacturer that works, like the
348 		 * 002-T mini RC, provided with newer PV hardware
349 		 */
350 		ir_codes = RC_MAP_PIXELVIEW_MK12;
351 		rc_type = RC_BIT_NECX;
352 		ir->gpio_addr = MO_GP1_IO;
353 		ir->mask_keyup = 0x80;
354 		ir->polling = 10; /* ms */
355 		hardware_mask = 0x3f;	/* Hardware returns only 6 bits from command part */
356 		break;
357 	case CX88_BOARD_PROLINK_PV_8000GT:
358 	case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
359 		ir_codes = RC_MAP_PIXELVIEW_NEW;
360 		ir->gpio_addr = MO_GP1_IO;
361 		ir->mask_keycode = 0x3f;
362 		ir->mask_keyup = 0x80;
363 		ir->polling = 1; /* ms */
364 		break;
365 	case CX88_BOARD_KWORLD_LTV883:
366 		ir_codes = RC_MAP_PIXELVIEW;
367 		ir->gpio_addr = MO_GP1_IO;
368 		ir->mask_keycode = 0x1f;
369 		ir->mask_keyup = 0x60;
370 		ir->polling = 1; /* ms */
371 		break;
372 	case CX88_BOARD_ADSTECH_DVB_T_PCI:
373 		ir_codes = RC_MAP_ADSTECH_DVB_T_PCI;
374 		ir->gpio_addr = MO_GP1_IO;
375 		ir->mask_keycode = 0xbf;
376 		ir->mask_keyup = 0x40;
377 		ir->polling = 50; /* ms */
378 		break;
379 	case CX88_BOARD_MSI_TVANYWHERE_MASTER:
380 		ir_codes = RC_MAP_MSI_TVANYWHERE;
381 		ir->gpio_addr = MO_GP1_IO;
382 		ir->mask_keycode = 0x1f;
383 		ir->mask_keyup = 0x40;
384 		ir->polling = 1; /* ms */
385 		break;
386 	case CX88_BOARD_AVERTV_303:
387 	case CX88_BOARD_AVERTV_STUDIO_303:
388 		ir_codes         = RC_MAP_AVERTV_303;
389 		ir->gpio_addr    = MO_GP2_IO;
390 		ir->mask_keycode = 0xfb;
391 		ir->mask_keydown = 0x02;
392 		ir->polling      = 50; /* ms */
393 		break;
394 	case CX88_BOARD_OMICOM_SS4_PCI:
395 	case CX88_BOARD_SATTRADE_ST4200:
396 	case CX88_BOARD_TBS_8920:
397 	case CX88_BOARD_TBS_8910:
398 	case CX88_BOARD_PROF_7300:
399 	case CX88_BOARD_PROF_7301:
400 	case CX88_BOARD_PROF_6200:
401 		ir_codes = RC_MAP_TBS_NEC;
402 		ir->sampling = 0xff00; /* address */
403 		break;
404 	case CX88_BOARD_TEVII_S464:
405 	case CX88_BOARD_TEVII_S460:
406 	case CX88_BOARD_TEVII_S420:
407 		ir_codes = RC_MAP_TEVII_NEC;
408 		ir->sampling = 0xff00; /* address */
409 		break;
410 	case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
411 		ir_codes         = RC_MAP_DNTV_LIVE_DVBT_PRO;
412 		ir->sampling     = 0xff00; /* address */
413 		break;
414 	case CX88_BOARD_NORWOOD_MICRO:
415 		ir_codes         = RC_MAP_NORWOOD;
416 		ir->gpio_addr    = MO_GP1_IO;
417 		ir->mask_keycode = 0x0e;
418 		ir->mask_keyup   = 0x80;
419 		ir->polling      = 50; /* ms */
420 		break;
421 	case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
422 		ir_codes         = RC_MAP_NPGTECH;
423 		ir->gpio_addr    = MO_GP0_IO;
424 		ir->mask_keycode = 0xfa;
425 		ir->polling      = 50; /* ms */
426 		break;
427 	case CX88_BOARD_PINNACLE_PCTV_HD_800i:
428 		ir_codes         = RC_MAP_PINNACLE_PCTV_HD;
429 		ir->sampling     = 1;
430 		break;
431 	case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
432 		ir_codes         = RC_MAP_POWERCOLOR_REAL_ANGEL;
433 		ir->gpio_addr    = MO_GP2_IO;
434 		ir->mask_keycode = 0x7e;
435 		ir->polling      = 100; /* ms */
436 		break;
437 	case CX88_BOARD_TWINHAN_VP1027_DVBS:
438 		ir_codes         = RC_MAP_TWINHAN_VP1027_DVBS;
439 		ir->sampling     = 0xff00; /* address */
440 		break;
441 	}
442 
443 	if (!ir_codes) {
444 		err = -ENODEV;
445 		goto err_out_free;
446 	}
447 
448 	/*
449 	 * The usage of mask_keycode were very convenient, due to several
450 	 * reasons. Among others, the scancode tables were using the scancode
451 	 * as the index elements. So, the less bits it was used, the smaller
452 	 * the table were stored. After the input changes, the better is to use
453 	 * the full scancodes, since it allows replacing the IR remote by
454 	 * another one. Unfortunately, there are still some hardware, like
455 	 * Pixelview Ultra Pro, where only part of the scancode is sent via
456 	 * GPIO. So, there's no way to get the full scancode. Due to that,
457 	 * hardware_mask were introduced here: it represents those hardware
458 	 * that has such limits.
459 	 */
460 	if (hardware_mask && !ir->mask_keycode)
461 		ir->mask_keycode = hardware_mask;
462 
463 	/* init input device */
464 	snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
465 	snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
466 
467 	dev->input_name = ir->name;
468 	dev->input_phys = ir->phys;
469 	dev->input_id.bustype = BUS_PCI;
470 	dev->input_id.version = 1;
471 	if (pci->subsystem_vendor) {
472 		dev->input_id.vendor = pci->subsystem_vendor;
473 		dev->input_id.product = pci->subsystem_device;
474 	} else {
475 		dev->input_id.vendor = pci->vendor;
476 		dev->input_id.product = pci->device;
477 	}
478 	dev->dev.parent = &pci->dev;
479 	dev->map_name = ir_codes;
480 	dev->driver_name = MODULE_NAME;
481 	dev->priv = core;
482 	dev->open = cx88_ir_open;
483 	dev->close = cx88_ir_close;
484 	dev->scancode_mask = hardware_mask;
485 
486 	if (ir->sampling) {
487 		dev->timeout = 10 * 1000 * 1000; /* 10 ms */
488 	} else {
489 		dev->driver_type = RC_DRIVER_SCANCODE;
490 		dev->allowed_protocols = rc_type;
491 	}
492 
493 	ir->core = core;
494 	core->ir = ir;
495 
496 	/* all done */
497 	err = rc_register_device(dev);
498 	if (err)
499 		goto err_out_free;
500 
501 	return 0;
502 
503 err_out_free:
504 	rc_free_device(dev);
505 	core->ir = NULL;
506 	kfree(ir);
507 	return err;
508 }
509 
510 int cx88_ir_fini(struct cx88_core *core)
511 {
512 	struct cx88_IR *ir = core->ir;
513 
514 	/* skip detach on non attached boards */
515 	if (!ir)
516 		return 0;
517 
518 	cx88_ir_stop(core);
519 	rc_unregister_device(ir->dev);
520 	kfree(ir);
521 
522 	/* done */
523 	core->ir = NULL;
524 	return 0;
525 }
526 
527 /* ---------------------------------------------------------------------- */
528 
529 void cx88_ir_irq(struct cx88_core *core)
530 {
531 	struct cx88_IR *ir = core->ir;
532 	u32 samples;
533 	unsigned int todo, bits;
534 	struct ir_raw_event ev;
535 
536 	if (!ir || !ir->sampling)
537 		return;
538 
539 	/*
540 	 * Samples are stored in a 32 bit register, oldest sample in
541 	 * the msb. A set bit represents space and an unset bit
542 	 * represents a pulse.
543 	 */
544 	samples = cx_read(MO_SAMPLE_IO);
545 
546 	if (samples == 0xff && ir->dev->idle)
547 		return;
548 
549 	init_ir_raw_event(&ev);
550 	for (todo = 32; todo > 0; todo -= bits) {
551 		ev.pulse = samples & 0x80000000 ? false : true;
552 		bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
553 		ev.duration = (bits * (NSEC_PER_SEC / 1000)) / ir_samplerate;
554 		ir_raw_event_store_with_filter(ir->dev, &ev);
555 		samples <<= bits;
556 	}
557 	ir_raw_event_handle(ir->dev);
558 }
559 
560 static int get_key_pvr2000(struct IR_i2c *ir, enum rc_type *protocol,
561 			   u32 *scancode, u8 *toggle)
562 {
563 	int flags, code;
564 
565 	/* poll IR chip */
566 	flags = i2c_smbus_read_byte_data(ir->c, 0x10);
567 	if (flags < 0) {
568 		dprintk("read error\n");
569 		return 0;
570 	}
571 	/* key pressed ? */
572 	if (0 == (flags & 0x80))
573 		return 0;
574 
575 	/* read actual key code */
576 	code = i2c_smbus_read_byte_data(ir->c, 0x00);
577 	if (code < 0) {
578 		dprintk("read error\n");
579 		return 0;
580 	}
581 
582 	dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
583 		code & 0xff, flags & 0xff);
584 
585 	*protocol = RC_TYPE_UNKNOWN;
586 	*scancode = code & 0xff;
587 	*toggle = 0;
588 	return 1;
589 }
590 
591 void cx88_i2c_init_ir(struct cx88_core *core)
592 {
593 	struct i2c_board_info info;
594 	const unsigned short default_addr_list[] = {
595 		0x18, 0x6b, 0x71,
596 		I2C_CLIENT_END
597 	};
598 	const unsigned short pvr2000_addr_list[] = {
599 		0x18, 0x1a,
600 		I2C_CLIENT_END
601 	};
602 	const unsigned short *addr_list = default_addr_list;
603 	const unsigned short *addrp;
604 	/* Instantiate the IR receiver device, if present */
605 	if (core->i2c_rc != 0)
606 		return;
607 
608 	memset(&info, 0, sizeof(struct i2c_board_info));
609 	strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
610 
611 	switch (core->boardnr) {
612 	case CX88_BOARD_LEADTEK_PVR2000:
613 		addr_list = pvr2000_addr_list;
614 		core->init_data.name = "cx88 Leadtek PVR 2000 remote";
615 		core->init_data.type = RC_BIT_UNKNOWN;
616 		core->init_data.get_key = get_key_pvr2000;
617 		core->init_data.ir_codes = RC_MAP_EMPTY;
618 		break;
619 	}
620 
621 	/*
622 	 * We can't call i2c_new_probed_device() because it uses
623 	 * quick writes for probing and at least some RC receiver
624 	 * devices only reply to reads.
625 	 * Also, Hauppauge XVR needs to be specified, as address 0x71
626 	 * conflicts with another remote type used with saa7134
627 	 */
628 	for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
629 		info.platform_data = NULL;
630 		memset(&core->init_data, 0, sizeof(core->init_data));
631 
632 		if (*addrp == 0x71) {
633 			/* Hauppauge XVR */
634 			core->init_data.name = "cx88 Hauppauge XVR remote";
635 			core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
636 			core->init_data.type = RC_BIT_RC5 | RC_BIT_RC6_MCE |
637 							RC_BIT_RC6_6A_32;
638 			core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
639 
640 			info.platform_data = &core->init_data;
641 		}
642 		if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
643 				   I2C_SMBUS_READ, 0,
644 				   I2C_SMBUS_QUICK, NULL) >= 0) {
645 			info.addr = *addrp;
646 			i2c_new_device(&core->i2c_adap, &info);
647 			break;
648 		}
649 	}
650 }
651 
652 /* ---------------------------------------------------------------------- */
653 
654 MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
655 MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
656 MODULE_LICENSE("GPL");
657