352
370
.owner = THIS_MODULE,
373
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
374
static int ir_attach(struct i2c_adapter *adap, int addr,
375
unsigned short flags, int kind);
376
static int ir_probe(struct i2c_adapter *adap);
355
378
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
356
380
static int ir_remove(struct i2c_client *client);
357
381
static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg);
383
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30)
359
384
static const struct i2c_device_id ir_receiver_id[] = {
360
385
/* Generic entry for any IR receiver */
361
386
{ "ir_video", 0 },
362
387
/* IR device specific entries could be added here */
366
392
static struct i2c_driver driver = {
393
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
394
.name = "i2c ir driver",
395
.flags = I2C_DF_NOTIFY,
368
398
.owner = THIS_MODULE,
369
399
.name = "i2c ir driver",
402
.id = I2C_DRIVERID_EXP3, /* FIXME */
403
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
404
.attach_adapter = ir_probe,
405
.detach_client = ir_remove,
371
407
.probe = ir_probe,
372
408
.remove = ir_remove,
373
409
.id_table = ir_receiver_id,
374
411
.command = ir_command,
414
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
415
static struct i2c_client client_template = {
421
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
422
static int ir_attach(struct i2c_adapter *adap, int addr,
423
unsigned short flags, int kind)
377
425
static void pcf_probe(struct i2c_client *client, struct IR *ir)
379
427
int ret1, ret2, ret3, ret4;
399
447
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
451
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
454
client_template.adapter = adap;
455
client_template.addr = addr;
402
457
struct i2c_adapter *adap = client->adapter;
403
458
unsigned short addr = client->addr;
406
ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
462
ir = kmalloc(sizeof(struct IR), GFP_KERNEL);
409
465
memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
466
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
467
memcpy(&ir->c, &client_template, sizeof(struct i2c_client));
469
ir->c.adapter = adap;
471
i2c_set_clientdata(&ir->c, ir);
410
473
memcpy(&ir->c, client, sizeof(struct i2c_client));
412
475
i2c_set_clientdata(client, ir);
414
478
ir->l.minor = minor;
415
479
ir->l.sample_rate = 10;
480
ir->l.dev = &ir->c.dev;
416
481
ir->nextkey = -1;
499
589
/* unregister device */
500
590
lirc_unregister_driver(ir->l.minor);
591
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
592
i2c_detach_client(&ir->c);
502
595
/* free memory */
600
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
601
static int ir_probe(struct i2c_adapter *adap)
604
* The external IR receiver is at i2c address 0x34 (0x35 for
605
* reads). Future Hauppauge cards will have an internal
606
* receiver at 0x30 (0x31 for reads). In theory, both can be
607
* fitted, and Hauppauge suggest an external overrides an
610
* That's why we probe 0x1a (~0x34) first. CB
612
* The i2c address for the Hauppauge PVR-150 card is 0xe2,
613
* so we need to probe 0x71 as well.
616
static const int probe[] = {
617
0x1a, /* Hauppauge IR external */
618
0x18, /* Hauppauge IR internal */
619
0x71, /* Hauppauge IR (PVR150) */
621
0x64, /* Pixelview IR */
622
0x30, /* KNC ONE IR */
623
0x6b, /* Adaptec IR */
626
#ifdef I2C_HW_B_CX2388x
627
static const int probe_cx88[] = {
628
0x18, /* Leadtek Winfast PVR2000 */
629
0x71, /* Hauppauge HVR-IR */
637
memset(&c, 0, sizeof(c));
638
#ifdef I2C_HW_B_CX2341X
639
if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848) ||
640
adap->id == (I2C_ALGO_BIT | I2C_HW_B_CX2341X)) {
642
if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) {
645
for (i = 0; -1 != probe[i]; i++) {
647
rc = i2c_master_recv(&c, &buf, 1);
648
dprintk("probe 0x%02x @ %s: %s\n",
649
probe[i], adap->name,
650
(1 == rc) ? "yes" : "no");
652
rc = ir_attach(adap, probe[i], 0, 0);
659
#ifdef I2C_HW_B_CX2388x
660
/* Leadtek Winfast PVR2000 or Hauppauge HVR-1300 */
661
else if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_CX2388x)) {
663
for (i = 0; -1 != probe_cx88[i]; i++) {
664
c.addr = probe_cx88[i];
665
rc = i2c_master_recv(&c, &buf, 1);
666
dprintk("probe 0x%02x @ %s: %s\n",
668
(1 == rc) ? "yes" : "no");
670
rc = ir_attach(adap, c.addr, 0, 0);
678
/* Asus TV-Box and Creative/VisionTek BreakOut-Box (PCF8574) */
679
else if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_RIVA)) {
681
* addresses to probe;
682
* leave 0x24 and 0x25 because SAA7113H possibly uses it
683
* 0x21 and 0x22 possibly used by SAA7108E
684
* Asus: 0x21 is a correct address (channel 1 of PCF8574)
685
* Creative: 0x23 is a correct address (channel 3 of PCF8574)
686
* VisionTek: 0x23 is a correct address (channel 3 of PCF8574)
688
static const int pcf_probe[] = { 0x20, 0x21, 0x22, 0x23,
689
0x24, 0x25, 0x26, 0x27, -1 };
690
int ret1, ret2, ret3, ret4;
691
unsigned char bits = 0, flag = 0;
694
for (i = 0; -1 != pcf_probe[i]; i++) {
695
c.addr = pcf_probe[i];
696
ret1 = i2c_smbus_write_byte(&c, 0xff);
697
ret2 = i2c_smbus_read_byte(&c);
698
ret3 = i2c_smbus_write_byte(&c, 0x00);
699
ret4 = i2c_smbus_read_byte(&c);
701
/* ensure that the writable bitmask works correctly */
703
if (ret1 != -1 && ret2 != -1 &&
704
ret3 != -1 && ret4 != -1) {
705
/* in the Asus TV-Box: bit 1-0 */
706
if (((ret2 & 0x03) == 0x03) &&
707
((ret4 & 0x03) == 0x00)) {
708
bits = (unsigned char) ~0x07;
712
/* in the Creative/VisionTek BreakOut-Box: bit 7-6 */
713
if (((ret2 & 0xc0) == 0xc0) &&
714
((ret4 & 0xc0) == 0x00)) {
715
bits = (unsigned char) ~0xe0;
720
dprintk("probe 0x%02x @ %s: %s\n",
721
c.addr, adap->name, rc ? "yes" : "no");
723
rc = ir_attach(adap, pcf_probe[i],
724
bits | (flag << 8), 0);
734
printk(KERN_ERR "lirc_i2c: %s: ir_attach failed!\n", __func__);
507
740
static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg)
513
748
static int __init lirc_i2c_init(void)
750
request_module("bttv");
751
request_module("rivatv");
752
request_module("ivtv");
753
request_module("cx8800");
515
754
i2c_add_driver(&driver);