502
498
ad774x_show_cap_gain,
503
499
ad774x_store_cap_gain);
505
static ssize_t ad774x_show_name(struct device *dev,
506
struct device_attribute *attr,
509
struct iio_dev *dev_info = dev_get_drvdata(dev);
510
struct ad774x_chip_info *chip = dev_info->dev_data;
511
return sprintf(buf, "%s\n", chip->name);
514
static IIO_DEVICE_ATTR(name, S_IRUGO, ad774x_show_name, NULL, 0);
516
501
static struct attribute *ad774x_attributes[] = {
517
502
&iio_dev_attr_available_conversion_modes.dev_attr.attr,
518
503
&iio_dev_attr_conversion_mode.dev_attr.attr,
538
522
* data ready events
541
#define IIO_EVENT_CODE_CAP_RDY IIO_BUFFER_EVENT_CODE(0)
542
#define IIO_EVENT_CODE_VT_RDY IIO_BUFFER_EVENT_CODE(1)
525
#define IIO_EVENT_CODE_CAP_RDY 0
526
#define IIO_EVENT_CODE_VT_RDY 1
544
528
#define IIO_EVENT_ATTR_CAP_RDY_SH(_evlist, _show, _store, _mask) \
545
529
IIO_EVENT_ATTR_SH(cap_rdy, _evlist, _show, _store, _mask)
547
531
#define IIO_EVENT_ATTR_VT_RDY_SH(_evlist, _show, _store, _mask) \
548
532
IIO_EVENT_ATTR_SH(vt_rdy, _evlist, _show, _store, _mask)
550
static void ad774x_interrupt_handler_bh(struct work_struct *work_s)
534
static irqreturn_t ad774x_event_handler(int irq, void *private)
552
struct ad774x_chip_info *chip =
553
container_of(work_s, struct ad774x_chip_info, thresh_work);
536
struct iio_dev *indio_dev = private;
537
struct ad774x_chip_info *chip = iio_dev_get_devdata(indio_dev);
556
enable_irq(chip->client->irq);
558
540
ad774x_i2c_read(chip, AD774X_STATUS, &int_status, 1);
560
542
if (int_status & AD774X_STATUS_RDYCAP)
561
iio_push_event(chip->indio_dev, 0,
562
IIO_EVENT_CODE_CAP_RDY,
563
chip->last_timestamp);
543
iio_push_event(indio_dev, 0,
544
IIO_EVENT_CODE_CAP_RDY,
565
547
if (int_status & AD774X_STATUS_RDYVT)
566
iio_push_event(chip->indio_dev, 0,
567
IIO_EVENT_CODE_VT_RDY,
568
chip->last_timestamp);
571
static int ad774x_interrupt_handler_th(struct iio_dev *dev_info,
576
struct ad774x_chip_info *chip = dev_info->dev_data;
578
chip->last_timestamp = timestamp;
579
schedule_work(&chip->thresh_work);
584
IIO_EVENT_SH(data_rdy, &ad774x_interrupt_handler_th);
586
static ssize_t ad774x_query_out_mode(struct device *dev,
587
struct device_attribute *attr,
591
* AD774X provides one /RDY pin, which can be used as interrupt
592
* but the pin is not configurable
594
return sprintf(buf, "1\n");
597
static ssize_t ad774x_set_out_mode(struct device *dev,
598
struct device_attribute *attr,
605
IIO_EVENT_ATTR_CAP_RDY_SH(iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode, 0);
606
IIO_EVENT_ATTR_VT_RDY_SH(iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode, 0);
548
iio_push_event(indio_dev, 0,
549
IIO_EVENT_CODE_VT_RDY,
555
static IIO_CONST_ATTR(cap_rdy_en, "1");
556
static IIO_CONST_ATTR(vt_rdy_en, "1");
608
558
static struct attribute *ad774x_event_attributes[] = {
609
&iio_event_attr_cap_rdy.dev_attr.attr,
610
&iio_event_attr_vt_rdy.dev_attr.attr,
559
&iio_const_attr_cap_rdy_en.dev_attr.attr,
560
&iio_const_attr_vt_rdy_en.dev_attr.attr,
615
565
.attrs = ad774x_event_attributes,
568
static const struct iio_info ad774x_info = {
569
.attrs = &ad774x_event_attribute_group,
570
.event_attrs = &ad774x_event_attribute_group,
571
.num_interrupt_lines = 1,
572
.driver_module = THIS_MODULE,
619
575
* device probe and remove
633
589
i2c_set_clientdata(client, chip);
635
591
chip->client = client;
636
chip->name = id->name;
638
chip->indio_dev = iio_allocate_device();
593
chip->indio_dev = iio_allocate_device(0);
639
594
if (chip->indio_dev == NULL) {
641
596
goto error_free_chip;
644
599
/* Establish that the iio_dev is a child of the i2c device */
600
chip->indio_dev->name = id->name;
645
601
chip->indio_dev->dev.parent = &client->dev;
646
chip->indio_dev->attrs = &ad774x_attribute_group;
647
chip->indio_dev->event_attrs = &ad774x_event_attribute_group;
602
chip->indio_dev->info = &ad774x_info;
648
603
chip->indio_dev->dev_data = (void *)(chip);
649
chip->indio_dev->driver_module = THIS_MODULE;
650
chip->indio_dev->num_interrupt_lines = 1;
651
604
chip->indio_dev->modes = INDIO_DIRECT_MODE;
653
606
ret = iio_device_register(chip->indio_dev);
658
611
if (client->irq) {
659
ret = iio_register_interrupt_line(client->irq,
662
IRQF_TRIGGER_FALLING,
612
ret = request_threaded_irq(client->irq,
614
&ad774x_event_handler,
615
IRQF_TRIGGER_FALLING,
665
619
goto error_free_dev;
667
iio_add_event_to_list(iio_event_attr_cap_rdy.listel,
668
&chip->indio_dev->interrupts[0]->ev_list);
670
INIT_WORK(&chip->thresh_work, ad774x_interrupt_handler_bh);
673
622
dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);