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