~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/iio/light/tsl2563.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
        u16 max;
93
93
};
94
94
 
95
 
static struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = {
 
95
static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = {
96
96
        {
97
97
                .gaintime       = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN16,
98
98
                .min            = 0,
115
115
struct tsl2563_chip {
116
116
        struct mutex            lock;
117
117
        struct i2c_client       *client;
118
 
        struct iio_dev          *indio_dev;
119
118
        struct delayed_work     poweroff_work;
120
119
 
121
 
        struct work_struct      work_thresh;
122
 
        s64                     event_timestamp;
123
120
        /* Remember state for suspend and resume functions */
124
121
        pm_message_t            state;
125
122
 
126
 
        struct tsl2563_gainlevel_coeff *gainlevel;
 
123
        struct tsl2563_gainlevel_coeff const *gainlevel;
127
124
 
128
125
        u16                     low_thres;
129
126
        u16                     high_thres;
467
464
/*                      Sysfs interface                         */
468
465
/*--------------------------------------------------------------*/
469
466
 
470
 
static ssize_t tsl2563_adc_show(struct device *dev,
471
 
                                struct device_attribute *attr, char *buf)
472
 
{
473
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
474
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
475
 
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
476
 
        int ret;
477
 
 
478
 
        mutex_lock(&chip->lock);
479
 
 
480
 
        ret = tsl2563_get_adc(chip);
481
 
        if (ret)
482
 
                goto out;
483
 
 
484
 
        switch (this_attr->address) {
485
 
        case 0:
486
 
                ret = snprintf(buf, PAGE_SIZE, "%d\n", chip->data0);
487
 
                break;
488
 
        case 1:
489
 
                ret = snprintf(buf, PAGE_SIZE, "%d\n", chip->data1);
490
 
                break;
491
 
        }
492
 
out:
493
 
        mutex_unlock(&chip->lock);
494
 
        return ret;
495
 
}
496
467
 
497
468
/* Apply calibration coefficient to ADC count. */
498
469
static u32 calib_adc(u32 adc, u32 calib)
505
476
        return (u32) scaled;
506
477
}
507
478
 
508
 
static ssize_t tsl2563_lux_show(struct device *dev,
509
 
                                struct device_attribute *attr, char *buf)
510
 
{
511
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
512
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
 
479
static int tsl2563_write_raw(struct iio_dev *indio_dev,
 
480
                               struct iio_chan_spec const *chan,
 
481
                               int val,
 
482
                               int val2,
 
483
                               long mask)
 
484
{
 
485
        struct tsl2563_chip *chip = iio_priv(indio_dev);
 
486
 
 
487
        if (chan->channel == 0)
 
488
                chip->calib0 = calib_from_sysfs(val);
 
489
        else
 
490
                chip->calib1 = calib_from_sysfs(val);
 
491
 
 
492
        return 0;
 
493
}
 
494
 
 
495
static int tsl2563_read_raw(struct iio_dev *indio_dev,
 
496
                            struct iio_chan_spec const *chan,
 
497
                            int *val,
 
498
                            int *val2,
 
499
                            long m)
 
500
{
 
501
        int ret = -EINVAL;
513
502
        u32 calib0, calib1;
514
 
        int ret;
515
 
 
516
 
        mutex_lock(&chip->lock);
517
 
 
518
 
        ret = tsl2563_get_adc(chip);
519
 
        if (ret)
520
 
                goto out;
521
 
 
522
 
        calib0 = calib_adc(chip->data0, chip->calib0) * chip->cover_comp_gain;
523
 
        calib1 = calib_adc(chip->data1, chip->calib1) * chip->cover_comp_gain;
524
 
 
525
 
        ret = snprintf(buf, PAGE_SIZE, "%d\n", adc_to_lux(calib0, calib1));
526
 
 
527
 
out:
528
 
        mutex_unlock(&chip->lock);
529
 
        return ret;
530
 
}
531
 
 
532
 
static ssize_t format_calib(char *buf, int len, u32 calib)
533
 
{
534
 
        return snprintf(buf, PAGE_SIZE, "%d\n", calib_to_sysfs(calib));
535
 
}
536
 
 
537
 
static ssize_t tsl2563_calib_show(struct device *dev,
538
 
                                struct device_attribute *attr, char *buf)
539
 
{
540
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
541
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
542
 
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
543
 
        int ret;
544
 
 
545
 
        mutex_lock(&chip->lock);
546
 
        switch (this_attr->address) {
547
 
        case 0:
548
 
                ret = format_calib(buf, PAGE_SIZE, chip->calib0);
549
 
                break;
550
 
        case 1:
551
 
                ret = format_calib(buf, PAGE_SIZE, chip->calib1);
552
 
                break;
553
 
        default:
554
 
                ret = -ENODEV;
555
 
        }
556
 
        mutex_unlock(&chip->lock);
557
 
        return ret;
558
 
}
559
 
 
560
 
static ssize_t tsl2563_calib_store(struct device *dev,
561
 
                                struct device_attribute *attr,
562
 
                                const char *buf, size_t len)
563
 
{
564
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
565
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
566
 
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
567
 
        int value;
568
 
        u32 calib;
569
 
 
570
 
        if (1 != sscanf(buf, "%d", &value))
571
 
                return -EINVAL;
572
 
 
573
 
        calib = calib_from_sysfs(value);
574
 
 
575
 
        switch (this_attr->address) {
576
 
        case 0:
577
 
                chip->calib0 = calib;
578
 
                break;
579
 
        case 1:
580
 
                chip->calib1 = calib;
581
 
                break;
582
 
        }
583
 
 
584
 
        return len;
585
 
}
586
 
 
587
 
static IIO_DEVICE_ATTR(intensity0_both_raw, S_IRUGO,
588
 
                tsl2563_adc_show, NULL, 0);
589
 
static IIO_DEVICE_ATTR(intensity1_ir_raw, S_IRUGO,
590
 
                tsl2563_adc_show, NULL, 1);
591
 
static DEVICE_ATTR(illuminance0_input, S_IRUGO, tsl2563_lux_show, NULL);
592
 
static IIO_DEVICE_ATTR(intensity0_both_calibgain, S_IRUGO | S_IWUSR,
593
 
                tsl2563_calib_show, tsl2563_calib_store, 0);
594
 
static IIO_DEVICE_ATTR(intensity1_ir_calibgain, S_IRUGO | S_IWUSR,
595
 
                tsl2563_calib_show, tsl2563_calib_store, 1);
596
 
 
597
 
static ssize_t tsl2563_show_name(struct device *dev,
598
 
                                struct device_attribute *attr,
599
 
                                char *buf)
600
 
{
601
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
602
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
603
 
        return sprintf(buf, "%s\n", chip->client->name);
604
 
}
605
 
 
606
 
static DEVICE_ATTR(name, S_IRUGO, tsl2563_show_name, NULL);
607
 
 
608
 
static struct attribute *tsl2563_attributes[] = {
609
 
        &iio_dev_attr_intensity0_both_raw.dev_attr.attr,
610
 
        &iio_dev_attr_intensity1_ir_raw.dev_attr.attr,
611
 
        &dev_attr_illuminance0_input.attr,
612
 
        &iio_dev_attr_intensity0_both_calibgain.dev_attr.attr,
613
 
        &iio_dev_attr_intensity1_ir_calibgain.dev_attr.attr,
614
 
        &dev_attr_name.attr,
615
 
        NULL
616
 
};
617
 
 
618
 
static const struct attribute_group tsl2563_group = {
619
 
        .attrs = tsl2563_attributes,
620
 
};
621
 
 
622
 
static ssize_t tsl2563_read_thresh(struct device *dev,
623
 
                        struct device_attribute *attr,
624
 
                        char *buf)
625
 
{
626
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
627
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
628
 
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
629
 
        u16 val = 0;
630
 
        switch (this_attr->address) {
631
 
        case TSL2563_REG_HIGHLOW:
632
 
                val = chip->high_thres;
633
 
                break;
634
 
        case TSL2563_REG_LOWLOW:
635
 
                val = chip->low_thres;
636
 
                break;
637
 
        }
638
 
        return snprintf(buf, PAGE_SIZE, "%d\n", val);
639
 
}
640
 
 
641
 
static ssize_t tsl2563_write_thresh(struct device *dev,
642
 
                                struct device_attribute *attr,
643
 
                                const char *buf,
644
 
                                size_t len)
645
 
{
646
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
647
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
648
 
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
649
 
        unsigned long val;
650
 
        int ret;
651
 
 
652
 
        ret = strict_strtoul(buf, 10, &val);
653
 
        if (ret)
654
 
                return ret;
655
 
        mutex_lock(&chip->lock);
656
 
        ret = tsl2563_write(chip->client, this_attr->address, val & 0xFF);
 
503
        struct tsl2563_chip *chip = iio_priv(indio_dev);
 
504
 
 
505
        mutex_lock(&chip->lock);
 
506
        switch (m) {
 
507
        case 0:
 
508
                switch (chan->type) {
 
509
                case IIO_LIGHT:
 
510
                        ret = tsl2563_get_adc(chip);
 
511
                        if (ret)
 
512
                                goto error_ret;
 
513
                        calib0 = calib_adc(chip->data0, chip->calib0) *
 
514
                                chip->cover_comp_gain;
 
515
                        calib1 = calib_adc(chip->data1, chip->calib1) *
 
516
                                chip->cover_comp_gain;
 
517
                        *val = adc_to_lux(calib0, calib1);
 
518
                        ret = IIO_VAL_INT;
 
519
                        break;
 
520
                case IIO_INTENSITY:
 
521
                        ret = tsl2563_get_adc(chip);
 
522
                        if (ret)
 
523
                                goto error_ret;
 
524
                        if (chan->channel == 0)
 
525
                                *val = chip->data0;
 
526
                        else
 
527
                                *val = chip->data1;
 
528
                        ret = IIO_VAL_INT;
 
529
                        break;
 
530
                default:
 
531
                        break;
 
532
                }
 
533
                break;
 
534
 
 
535
        case (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE):
 
536
                if (chan->channel == 0)
 
537
                        *val = calib_to_sysfs(chip->calib0);
 
538
                else
 
539
                        *val = calib_to_sysfs(chip->calib1);
 
540
                ret = IIO_VAL_INT;
 
541
                break;
 
542
        default:
 
543
                return -EINVAL;
 
544
        }
 
545
 
 
546
error_ret:
 
547
        mutex_unlock(&chip->lock);
 
548
        return ret;
 
549
}
 
550
 
 
551
static const struct iio_chan_spec tsl2563_channels[] = {
 
552
        IIO_CHAN(IIO_LIGHT, 0, 1, 1, NULL, 0, 0, 0, 0, 0, {}, 0),
 
553
        IIO_CHAN(IIO_INTENSITY, 1, 1, 0, "both", 0,
 
554
                 (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE), 0, 0, 0, {},
 
555
                 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
 
556
                 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)),
 
557
        IIO_CHAN(IIO_INTENSITY, 1, 1, 0, "ir", 1,
 
558
                 (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE), 0, 0, 0, {},
 
559
                 0)
 
560
};
 
561
 
 
562
static int tsl2563_read_thresh(struct iio_dev *indio_dev,
 
563
                                int event_code,
 
564
                                int *val)
 
565
{
 
566
        struct tsl2563_chip *chip = iio_priv(indio_dev);
 
567
 
 
568
        switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
 
569
        case IIO_EV_DIR_RISING:
 
570
                *val = chip->high_thres;
 
571
                break;
 
572
        case IIO_EV_DIR_FALLING:
 
573
                *val = chip->low_thres;
 
574
                break;
 
575
        default:
 
576
                return -EINVAL;
 
577
        }
 
578
 
 
579
        return 0;
 
580
}
 
581
 
 
582
static ssize_t tsl2563_write_thresh(struct iio_dev *indio_dev,
 
583
                                  int event_code,
 
584
                                  int val)
 
585
{
 
586
        struct tsl2563_chip *chip = iio_priv(indio_dev);
 
587
        int ret;
 
588
        u8 address;
 
589
 
 
590
        if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
 
591
                address = TSL2563_REG_HIGHLOW;
 
592
        else
 
593
                address = TSL2563_REG_LOWLOW;
 
594
        mutex_lock(&chip->lock);
 
595
        ret = tsl2563_write(chip->client, address, val & 0xFF);
657
596
        if (ret)
658
597
                goto error_ret;
659
 
        ret = tsl2563_write(chip->client, this_attr->address + 1,
 
598
        ret = tsl2563_write(chip->client, address + 1,
660
599
                        (val >> 8) & 0xFF);
661
 
        switch (this_attr->address) {
662
 
        case TSL2563_REG_HIGHLOW:
 
600
        if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
663
601
                chip->high_thres = val;
664
 
                break;
665
 
        case TSL2563_REG_LOWLOW:
 
602
        else
666
603
                chip->low_thres = val;
667
 
                break;
668
 
        }
669
604
 
670
605
error_ret:
671
606
        mutex_unlock(&chip->lock);
672
607
 
673
 
        return ret < 0 ? ret : len;
674
 
}
675
 
 
676
 
static IIO_DEVICE_ATTR(intensity0_both_raw_thresh_rising_value,
677
 
                S_IRUGO | S_IWUSR,
678
 
                tsl2563_read_thresh,
679
 
                tsl2563_write_thresh,
680
 
                TSL2563_REG_HIGHLOW);
681
 
 
682
 
static IIO_DEVICE_ATTR(intensity0_both_raw_thresh_falling_value,
683
 
                S_IRUGO | S_IWUSR,
684
 
                tsl2563_read_thresh,
685
 
                tsl2563_write_thresh,
686
 
                TSL2563_REG_LOWLOW);
687
 
 
688
 
static int tsl2563_int_th(struct iio_dev *dev_info,
689
 
                        int index,
690
 
                        s64 timestamp,
691
 
                        int not_test)
692
 
{
693
 
        struct tsl2563_chip *chip = dev_info->dev_data;
694
 
 
695
 
        chip->event_timestamp = timestamp;
696
 
        schedule_work(&chip->work_thresh);
697
 
 
698
 
        return 0;
699
 
}
700
 
 
701
 
static void tsl2563_int_bh(struct work_struct *work_s)
702
 
{
703
 
        struct tsl2563_chip *chip
704
 
                = container_of(work_s,
705
 
                        struct tsl2563_chip, work_thresh);
 
608
        return ret;
 
609
}
 
610
 
 
611
static irqreturn_t tsl2563_event_handler(int irq, void *private)
 
612
{
 
613
        struct iio_dev *dev_info = private;
 
614
        struct tsl2563_chip *chip = iio_priv(dev_info);
706
615
        u8 cmd = TSL2563_CMD | TSL2563_CLEARINT;
707
616
 
708
 
        iio_push_event(chip->indio_dev, 0,
 
617
        iio_push_event(dev_info, 0,
709
618
                       IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_LIGHT,
710
619
                                            0,
711
620
                                            IIO_EV_TYPE_THRESH,
712
621
                                            IIO_EV_DIR_EITHER),
713
 
                       chip->event_timestamp);
 
622
                       iio_get_time_ns());
714
623
 
715
 
        /* reenable_irq */
716
 
        enable_irq(chip->client->irq);
717
624
        /* clear the interrupt and push the event */
718
625
        i2c_master_send(chip->client, &cmd, sizeof(cmd));
719
 
 
 
626
        return IRQ_HANDLED;
720
627
}
721
628
 
722
 
static ssize_t tsl2563_write_interrupt_config(struct device *dev,
723
 
                                        struct device_attribute *attr,
724
 
                                        const char *buf,
725
 
                                        size_t len)
 
629
static int tsl2563_write_interrupt_config(struct iio_dev *indio_dev,
 
630
                                        int event_code,
 
631
                                        int state)
726
632
{
727
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
728
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
729
 
        struct iio_event_attr *this_attr = to_iio_event_attr(attr);
730
 
        int input, ret = 0;
 
633
        struct tsl2563_chip *chip = iio_priv(indio_dev);
 
634
        int ret = 0;
731
635
 
732
 
        ret = sscanf(buf, "%d", &input);
733
 
        if (ret != 1)
734
 
                return -EINVAL;
735
636
        mutex_lock(&chip->lock);
736
 
        if (input && !(chip->intr & 0x30)) {
737
 
                iio_add_event_to_list(this_attr->listel,
738
 
                                &indio_dev->interrupts[0]->ev_list);
 
637
        if (state && !(chip->intr & 0x30)) {
739
638
                chip->intr &= ~0x30;
740
639
                chip->intr |= 0x10;
741
640
                /* ensure the chip is actually on */
752
651
                chip->int_enabled = true;
753
652
        }
754
653
 
755
 
        if (!input && (chip->intr & 0x30)) {
 
654
        if (!state && (chip->intr & 0x30)) {
756
655
                chip->intr |= ~0x30;
757
656
                ret = tsl2563_write(chip->client, TSL2563_REG_INT, chip->intr);
758
 
                iio_remove_event_from_list(this_attr->listel,
759
 
                                        &indio_dev->interrupts[0]->ev_list);
760
657
                chip->int_enabled = false;
761
658
                /* now the interrupt is not enabled, we can go to sleep */
762
659
                schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
764
661
out:
765
662
        mutex_unlock(&chip->lock);
766
663
 
767
 
        return (ret < 0) ? ret : len;
 
664
        return ret;
768
665
}
769
666
 
770
 
static ssize_t tsl2563_read_interrupt_config(struct device *dev,
771
 
                                        struct device_attribute *attr,
772
 
                                        char *buf)
 
667
static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev,
 
668
                                           int event_code)
773
669
{
774
 
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
775
 
        struct tsl2563_chip *chip = indio_dev->dev_data;
776
 
        int ret;
 
670
        struct tsl2563_chip *chip = iio_priv(indio_dev);
777
671
        u8 rxbuf;
778
 
        ssize_t len;
 
672
        int ret;
779
673
 
780
674
        mutex_lock(&chip->lock);
781
 
        ret = tsl2563_read(chip->client,
782
 
                        TSL2563_REG_INT,
783
 
                        &rxbuf,
784
 
                        sizeof(rxbuf));
 
675
        ret = tsl2563_read(chip->client, TSL2563_REG_INT,
 
676
                           &rxbuf, sizeof(rxbuf));
785
677
        mutex_unlock(&chip->lock);
786
678
        if (ret < 0)
787
679
                goto error_ret;
788
 
        len = snprintf(buf, PAGE_SIZE, "%d\n", !!(rxbuf & 0x30));
 
680
        ret = !!(rxbuf & 0x30);
789
681
error_ret:
790
682
 
791
 
        return (ret < 0) ? ret : len;
 
683
        return ret;
792
684
}
793
685
 
794
 
IIO_EVENT_ATTR(intensity0_both_thresh_en,
795
 
        tsl2563_read_interrupt_config,
796
 
        tsl2563_write_interrupt_config,
797
 
        0,
798
 
        tsl2563_int_th);
799
 
 
800
 
static struct attribute *tsl2563_event_attributes[] = {
801
 
        &iio_event_attr_intensity0_both_thresh_en.dev_attr.attr,
802
 
        &iio_dev_attr_intensity0_both_raw_thresh_rising_value.dev_attr.attr,
803
 
        &iio_dev_attr_intensity0_both_raw_thresh_falling_value.dev_attr.attr,
804
 
        NULL,
805
 
};
806
 
 
807
 
static struct attribute_group tsl2563_event_attribute_group = {
808
 
        .attrs = tsl2563_event_attributes,
809
 
};
810
 
 
811
686
/*--------------------------------------------------------------*/
812
687
/*                      Probe, Attach, Remove                   */
813
688
/*--------------------------------------------------------------*/
814
689
static struct i2c_driver tsl2563_i2c_driver;
815
690
 
 
691
static const struct iio_info tsl2563_info_no_irq = {
 
692
        .driver_module = THIS_MODULE,
 
693
};
 
694
 
 
695
static const struct iio_info tsl2563_info = {
 
696
        .driver_module = THIS_MODULE,
 
697
        .num_interrupt_lines = 1,
 
698
        .read_raw = &tsl2563_read_raw,
 
699
        .write_raw = &tsl2563_write_raw,
 
700
        .read_event_value = &tsl2563_read_thresh,
 
701
        .write_event_value = &tsl2563_write_thresh,
 
702
        .read_event_config = &tsl2563_read_interrupt_config,
 
703
        .write_event_config = &tsl2563_write_interrupt_config,
 
704
};
 
705
 
816
706
static int __devinit tsl2563_probe(struct i2c_client *client,
817
707
                                const struct i2c_device_id *device_id)
818
708
{
 
709
        struct iio_dev *indio_dev;
819
710
        struct tsl2563_chip *chip;
820
711
        struct tsl2563_platform_data *pdata = client->dev.platform_data;
821
712
        int err = 0;
822
713
        int ret;
823
714
        u8 id;
824
715
 
825
 
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
826
 
        if (!chip)
 
716
        indio_dev = iio_allocate_device(sizeof(*chip));
 
717
        if (!indio_dev)
827
718
                return -ENOMEM;
828
719
 
829
 
        INIT_WORK(&chip->work_thresh, tsl2563_int_bh);
 
720
        chip = iio_priv(indio_dev);
 
721
 
830
722
        i2c_set_clientdata(client, chip);
831
723
        chip->client = client;
832
724
 
856
748
                chip->cover_comp_gain = 1;
857
749
 
858
750
        dev_info(&client->dev, "model %d, rev. %d\n", id >> 4, id & 0x0f);
859
 
 
860
 
        chip->indio_dev = iio_allocate_device();
861
 
        if (!chip->indio_dev)
862
 
                goto fail1;
863
 
        chip->indio_dev->attrs = &tsl2563_group;
864
 
        chip->indio_dev->dev.parent = &client->dev;
865
 
        chip->indio_dev->dev_data = (void *)(chip);
866
 
        chip->indio_dev->driver_module = THIS_MODULE;
867
 
        chip->indio_dev->modes = INDIO_DIRECT_MODE;
868
 
        if (client->irq) {
869
 
                chip->indio_dev->num_interrupt_lines = 1;
870
 
                chip->indio_dev->event_attrs
871
 
                        = &tsl2563_event_attribute_group;
872
 
        }
873
 
        ret = iio_device_register(chip->indio_dev);
 
751
        indio_dev->name = client->name;
 
752
        indio_dev->channels = tsl2563_channels;
 
753
        indio_dev->num_channels = ARRAY_SIZE(tsl2563_channels);
 
754
        indio_dev->dev.parent = &client->dev;
 
755
        indio_dev->modes = INDIO_DIRECT_MODE;
 
756
        if (client->irq)
 
757
                indio_dev->info = &tsl2563_info;
 
758
        else
 
759
                indio_dev->info = &tsl2563_info_no_irq;
 
760
        ret = iio_device_register(indio_dev);
874
761
        if (ret)
875
762
                goto fail1;
876
 
 
877
763
        if (client->irq) {
878
 
                ret = iio_register_interrupt_line(client->irq,
879
 
                                                chip->indio_dev,
880
 
                                                0,
881
 
                                                IRQF_TRIGGER_RISING,
882
 
                                                client->name);
 
764
                ret = request_threaded_irq(client->irq,
 
765
                                           NULL,
 
766
                                           &tsl2563_event_handler,
 
767
                                           IRQF_TRIGGER_RISING | IRQF_ONESHOT,
 
768
                                           "tsl2563_event",
 
769
                                           indio_dev);
883
770
                if (ret)
884
771
                        goto fail2;
885
772
        }
894
781
        return 0;
895
782
fail3:
896
783
        if (client->irq)
897
 
                iio_unregister_interrupt_line(chip->indio_dev, 0);
 
784
                free_irq(client->irq, indio_dev);
898
785
fail2:
899
 
        iio_device_unregister(chip->indio_dev);
 
786
        iio_device_unregister(indio_dev);
900
787
fail1:
901
788
        kfree(chip);
902
789
        return err;
905
792
static int tsl2563_remove(struct i2c_client *client)
906
793
{
907
794
        struct tsl2563_chip *chip = i2c_get_clientdata(client);
 
795
        struct iio_dev *indio_dev = iio_priv_to_dev(chip);
908
796
        if (!chip->int_enabled)
909
797
                cancel_delayed_work(&chip->poweroff_work);
910
798
        /* Ensure that interrupts are disabled - then flush any bottom halves */
913
801
        flush_scheduled_work();
914
802
        tsl2563_set_power(chip, 0);
915
803
        if (client->irq)
916
 
                iio_unregister_interrupt_line(chip->indio_dev, 0);
917
 
        iio_device_unregister(chip->indio_dev);
 
804
                free_irq(client->irq, indio_dev);
 
805
        iio_device_unregister(indio_dev);
918
806
 
919
 
        kfree(chip);
920
807
        return 0;
921
808
}
922
809