~ubuntu-branches/ubuntu/karmic/linux-fsl-imx51/karmic

« back to all changes in this revision

Viewing changes to ubuntu/lirc/lirc_i2c/lirc_i2c.c

  • Committer: Bazaar Package Importer
  • Author(s): Andy Whitcroft, Andy Whitcroft, Upstream Kernel Changes, Ubuntu: 2.6.31-14.46, Ubuntu: 2.6.31-13.45, Ubuntu: 2.6.31-13.44
  • Date: 2009-10-13 15:59:33 UTC
  • Revision ID: james.westby@ubuntu.com-20091013155933-hxzquigs9nqajd9x
Tags: 2.6.31-105.14
[ Andy Whitcroft ]

* rebase to Ubuntu-2.6.31-14.46
* [Config] update configs since rebase to Ubuntu-2.6.31-14.46
* lirc update dropped module lirc_mceusb2

[ Upstream Kernel Changes ]

* mxc spi: fix spi driver for 2.6.31
  - LP: #427289, #446140

[ Ubuntu: 2.6.31-14.46 ]

* reinstate armel.mk with no flavours
  - LP: #449637
* [Upstream] elevator: fix fastfail checks to allow merge of readahead
  requests
  - LP: #444915
* [Upstream] block: silently error unsupported empty barriers too
  - LP: #420423
* SAUCE: AppArmor: Fix mediation of "deleted" paths
  - LP: #415632
* [Config] CONFIG_X86_MCE
  https://lists.ubuntu.com/archives/kernel-team/2009-October/007584.html
* Revert "appletalk: Fix skb leak when ipddp interface is not loaded,
  CVE-2009-2903" - Use patch from 2.6.31.4 which is slightly different.
* x86: fix csum_ipv6_magic asm memory clobber
* tty: Avoid dropping ldisc_mutex over hangup tty re-initialization
* x86: Don't leak 64-bit kernel register values to 32-bit processes
* tracing: correct module boundaries for ftrace_release
* ftrace: check for failure for all conversions
* futex: fix requeue_pi key imbalance
* futex: Move exit_pi_state() call to release_mm()
* futex: Nullify robust lists after cleanup
* futex: Fix locking imbalance
* NOHZ: update idle state also when NOHZ is inactive
* ima: ecryptfs fix imbalance message
* libata: fix incorrect link online check during probe
* sound: via82xx: move DXS volume controls to PCM interface
* ASoC: WM8350 capture PGA mutes are inverted
* KVM: Prevent overflow in KVM_GET_SUPPORTED_CPUID
* KVM: VMX: flush TLB with INVEPT on cpu migration
* KVM: fix LAPIC timer period overflow
* KVM: SVM: Fix tsc offset adjustment when running nested
* KVM: SVM: Handle tsc in svm_get_msr/svm_set_msr correctly
* net: Fix wrong sizeof
* mm: add_to_swap_cache() must not sleep
* sis5513: fix PIO setup for ATAPI devices
* PIT fixes to unbreak suspend/resume (bug #14222)
* IMA: open new file for read
* ACPI: Clarify resource conflict message
* ACPI: fix Compaq Evo N800c (Pentium 4m) boot hang regression
* net: restore tx timestamping for accelerated vlans
* net: unix: fix sending fds in multiple buffers
* tun: Return -EINVAL if neither IFF_TUN nor IFF_TAP is set.
* tcp: fix CONFIG_TCP_MD5SIG + CONFIG_PREEMPT timer BUG()
* net: Fix sock_wfree() race
* smsc95xx: fix transmission where ZLP is expected
* sky2: Set SKY2_HW_RAM_BUFFER in sky2_init
* appletalk: Fix skb leak when ipddp interface is not loaded
* ax25: Fix possible oops in ax25_make_new
* ax25: Fix SIOCAX25GETINFO ioctl
* sit: fix off-by-one in ipip6_tunnel_get_prl
* Linux 2.6.31.4
* drm/i915: Fix FDI M/N setting according with correct color depth
  - LP: #416792

[ Ubuntu: 2.6.31-13.45 ]

* [Config] Add sd_mod to scsi-modules udeb for powerpc
* SAUCE: Update to LIRC 0.8.6
  - LP: #432678
* [Config] CONFIG_X86_PAT=y
  https://lists.ubuntu.com/archives/kernel-team/2009-October/007477.html
  https://lists.ubuntu.com/archives/kernel-team/2009-October/007534.html
* [Config] Add armel arch to linux-libc-dev arches.
  - LP: #449637
* e1000e: swap max hw supported frame size between 82574 and 82583
* drm/i915: Initialize HDMI outputs as HDMI connectors, not DVI.
  - LP: #392017
* ALSA: hda - Add quirks for some HP laptops
  - LP: #449742
* ALSA: hda - Add support for HP dv6
  - LP: #449742

[ Ubuntu: 2.6.31-13.44 ]

* sgi-gru: Fix kernel stack buffer overrun, CVE-2009-2584
* appletalk: Fix skb leak when ipddp interface is not loaded,
  CVE-2009-2903
  Note - This patch causes an ABI change in the symbol aarp_send_ddp
  which I'm ignoring.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      $Id: lirc_i2c.c,v 1.70 2009/08/30 16:59:53 jarodwilson Exp $      */
 
2
 
1
3
/*
2
4
 * lirc_i2c.c
3
5
 *
42
44
 */
43
45
 
44
46
 
 
47
#ifdef HAVE_CONFIG_H
 
48
#include <config.h>
 
49
#endif
 
50
 
45
51
#include <linux/version.h>
46
52
#include <linux/module.h>
47
53
#include <linux/kmod.h>
55
61
#include <linux/i2c.h>
56
62
#include <linux/i2c-algo-bit.h>
57
63
 
 
64
#include "../kcompat.h"
58
65
#include "../lirc_dev/lirc_dev.h"
59
66
 
60
67
struct IR {
326
333
static int set_use_inc(void *data)
327
334
{
328
335
        struct IR *ir = data;
 
336
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
 
337
        int ret;
 
338
#endif
329
339
 
330
340
        dprintk("%s called\n", __func__);
331
341
 
 
342
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
 
343
        i2c_use_client(&ir->c);
 
344
#else
332
345
        /* lock bttv in memory while /dev/lirc is in use  */
333
 
        i2c_use_client(&ir->c);
 
346
        ret = i2c_use_client(&ir->c);
 
347
        if (ret != 0)
 
348
                return ret;
 
349
#endif
334
350
 
 
351
        MOD_INC_USE_COUNT;
335
352
        return 0;
336
353
}
337
354
 
342
359
        dprintk("%s called\n", __func__);
343
360
 
344
361
        i2c_release_client(&ir->c);
 
362
        MOD_DEC_USE_COUNT;
345
363
}
346
364
 
347
365
static struct lirc_driver lirc_template = {
352
370
        .owner          = THIS_MODULE,
353
371
};
354
372
 
 
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);
 
377
# else
355
378
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
 
379
#endif
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);
358
382
 
 
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 */
363
388
        { }
364
389
};
 
390
#endif
365
391
 
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,
 
396
#else
367
397
        .driver = {
368
398
                .owner  = THIS_MODULE,
369
399
                .name   = "i2c ir driver",
370
400
        },
 
401
#endif
 
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,
 
406
#else
371
407
        .probe          = ir_probe,
372
408
        .remove         = ir_remove,
373
409
        .id_table       = ir_receiver_id,
 
410
#endif
374
411
        .command        = ir_command,
375
412
};
376
413
 
 
414
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
415
static struct i2c_client client_template = {
 
416
        .name           = "unset",
 
417
        .driver         = &driver
 
418
};
 
419
#endif
 
420
 
 
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)
 
424
#else
377
425
static void pcf_probe(struct i2c_client *client, struct IR *ir)
378
426
{
379
427
        int ret1, ret2, ret3, ret4;
397
445
}
398
446
 
399
447
static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
448
#endif
400
449
{
401
450
        struct IR *ir;
 
451
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
452
        int err, retval;
 
453
 
 
454
        client_template.adapter = adap;
 
455
        client_template.addr = addr;
 
456
#else
402
457
        struct i2c_adapter *adap = client->adapter;
403
458
        unsigned short addr = client->addr;
404
459
        int retval;
 
460
#endif
405
461
 
406
 
        ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
 
462
        ir = kmalloc(sizeof(struct IR), GFP_KERNEL);
407
463
        if (!ir)
408
464
                return -ENOMEM;
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));
 
468
 
 
469
        ir->c.adapter = adap;
 
470
        ir->c.addr    = addr;
 
471
        i2c_set_clientdata(&ir->c, ir);
 
472
#else
410
473
        memcpy(&ir->c, client, sizeof(struct i2c_client));
411
474
 
412
475
        i2c_set_clientdata(client, ir);
 
476
#endif
413
477
        ir->l.data    = 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;
417
482
 
418
483
        switch (addr) {
427
492
                ir->l.add_to_buf = add_to_buf_pv951;
428
493
                break;
429
494
        case 0x71:
430
 
                if (adap->id == I2C_HW_B_BT848 ||
431
 
                    adap->id == I2C_HW_B_CX2341X) {
 
495
#ifdef I2C_HW_B_CX2341X
 
496
                if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848) ||
 
497
                    adap->id == (I2C_ALGO_BIT | I2C_HW_B_CX2341X)) {
 
498
#else
 
499
                if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) {
 
500
#endif
432
501
                        /*
433
502
                         * The PVR150 IR receiver uses the same protocol as
434
503
                         * other Hauppauge cards, but the data flow is
447
516
                break;
448
517
        case 0x18:
449
518
        case 0x1a:
450
 
                if (adap->id == I2C_HW_B_BT848 ||
451
 
                    adap->id == I2C_HW_B_CX2341X) {
 
519
#ifdef I2C_HW_B_CX2341X
 
520
                if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848) ||
 
521
                    adap->id == (I2C_ALGO_BIT | I2C_HW_B_CX2341X)) {
 
522
#else
 
523
                if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) {
 
524
#endif
452
525
                        strlcpy(ir->c.name, "Hauppauge IR", I2C_NAME_SIZE);
453
526
                        ir->l.code_length = 13;
454
527
                        ir->l.add_to_buf = add_to_buf_haup;
465
538
                break;
466
539
        case 0x21:
467
540
        case 0x23:
 
541
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
542
                ir->bits = flags & 0xff;
 
543
                ir->flag = (flags >> 8) & 0xff;
 
544
#else
468
545
                pcf_probe(client, ir);
 
546
#endif
469
547
                strlcpy(ir->c.name, "TV-Box IR", I2C_NAME_SIZE);
470
548
                ir->l.code_length = 8;
471
549
                ir->l.add_to_buf = add_to_buf_pcf8574;
479
557
        printk(KERN_INFO "lirc_i2c: chip 0x%x found @ 0x%02x (%s)\n",
480
558
               adap->id, addr, ir->c.name);
481
559
 
 
560
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
561
        /* register device */
 
562
        err = i2c_attach_client(&ir->c);
 
563
        if (err) {
 
564
                kfree(ir);
 
565
                return err;
 
566
        }
 
567
#endif
 
568
 
482
569
        retval = lirc_register_driver(&ir->l);
483
570
 
484
571
        if (retval < 0) {
485
572
                printk(KERN_ERR "lirc_i2c: failed to register driver!\n");
 
573
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
574
                i2c_detach_client(&ir->c);
 
575
#endif
486
576
                kfree(ir);
487
577
                return retval;
488
578
        }
498
588
 
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);
 
593
#endif
501
594
 
502
595
        /* free memory */
503
596
        kfree(ir);
504
597
        return 0;
505
598
}
506
599
 
 
600
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
 
601
static int ir_probe(struct i2c_adapter *adap)
 
602
{
 
603
        /*
 
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
 
608
         * internal.
 
609
         *
 
610
         * That's why we probe 0x1a (~0x34) first. CB
 
611
         *
 
612
         * The i2c address for the Hauppauge PVR-150 card is 0xe2,
 
613
         * so we need to probe 0x71 as well.
 
614
         */
 
615
 
 
616
        static const int probe[] = {
 
617
                0x1a, /* Hauppauge IR external */
 
618
                0x18, /* Hauppauge IR internal */
 
619
                0x71, /* Hauppauge IR (PVR150) */
 
620
                0x4b, /* PV951 IR */
 
621
                0x64, /* Pixelview IR */
 
622
                0x30, /* KNC ONE IR */
 
623
                0x6b, /* Adaptec IR */
 
624
                -1};
 
625
 
 
626
#ifdef I2C_HW_B_CX2388x
 
627
        static const int probe_cx88[] = {
 
628
                0x18, /* Leadtek Winfast PVR2000 */
 
629
                0x71, /* Hauppauge HVR-IR */
 
630
                -1};
 
631
#endif
 
632
 
 
633
        struct i2c_client c;
 
634
        char buf;
 
635
        int i, rc;
 
636
 
 
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)) {
 
641
#else
 
642
        if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) {
 
643
#endif
 
644
                c.adapter = adap;
 
645
                for (i = 0; -1 != probe[i]; i++) {
 
646
                        c.addr = probe[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");
 
651
                        if (1 == rc) {
 
652
                                rc = ir_attach(adap, probe[i], 0, 0);
 
653
                                if (rc < 0)
 
654
                                        goto attach_fail;
 
655
                        }
 
656
                }
 
657
        }
 
658
 
 
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)) {
 
662
                c.adapter = adap;
 
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",
 
667
                                c.addr, adap->name,
 
668
                                (1 == rc) ? "yes" : "no");
 
669
                        if (1 == rc) {
 
670
                                rc = ir_attach(adap, c.addr, 0, 0);
 
671
                                if (rc < 0)
 
672
                                        goto attach_fail;
 
673
                        }
 
674
                }
 
675
        }
 
676
#endif
 
677
 
 
678
        /* Asus TV-Box and Creative/VisionTek BreakOut-Box (PCF8574) */
 
679
        else if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_RIVA)) {
 
680
                /*
 
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)
 
687
                 */
 
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;
 
692
 
 
693
                c.adapter = adap;
 
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);
 
700
 
 
701
                        /* ensure that the writable bitmask works correctly */
 
702
                        rc = 0;
 
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;
 
709
                                        flag = 0x04;
 
710
                                        rc = 1;
 
711
                                }
 
712
                        /* in the Creative/VisionTek BreakOut-Box: bit 7-6 */
 
713
                                if (((ret2 & 0xc0) == 0xc0) &&
 
714
                                    ((ret4 & 0xc0) == 0x00)) {
 
715
                                        bits = (unsigned char) ~0xe0;
 
716
                                        flag = 0x20;
 
717
                                        rc = 1;
 
718
                                }
 
719
                        }
 
720
                        dprintk("probe 0x%02x @ %s: %s\n",
 
721
                                c.addr, adap->name, rc ? "yes" : "no");
 
722
                        if (rc) {
 
723
                                rc = ir_attach(adap, pcf_probe[i],
 
724
                                               bits | (flag << 8), 0);
 
725
                                if (rc < 0)
 
726
                                        goto attach_fail;
 
727
                        }
 
728
                }
 
729
        }
 
730
 
 
731
        return 0;
 
732
 
 
733
attach_fail:
 
734
        printk(KERN_ERR "lirc_i2c: %s: ir_attach failed!\n", __func__);
 
735
        return rc;
 
736
 
 
737
}
 
738
#endif
 
739
 
507
740
static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg)
508
741
{
509
742
        /* nothing */
510
743
        return 0;
511
744
}
512
745
 
 
746
#ifdef MODULE
 
747
 
513
748
static int __init lirc_i2c_init(void)
514
749
{
 
750
        request_module("bttv");
 
751
        request_module("rivatv");
 
752
        request_module("ivtv");
 
753
        request_module("cx8800");
515
754
        i2c_add_driver(&driver);
516
755
        return 0;
517
756
}
535
774
 
536
775
module_init(lirc_i2c_init);
537
776
module_exit(lirc_i2c_exit);
 
777
EXPORT_NO_SYMBOLS;
 
778
 
 
779
#endif /* MODULE */