3 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
5 * based on iio/adc/max1363
6 * Copyright (C) 2008-2010 Jonathan Cameron
8 * based on linux/drivers/i2c/chips/max123x
9 * Copyright (C) 2002-2004 Stefan Eletzhofer
11 * based on linux/drivers/acron/char/pcf8583.c
12 * Copyright (C) 2000 Russell King
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
20 * Support for ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997,
21 * ad7998 and similar chips.
25 #include <linux/interrupt.h>
26 #include <linux/device.h>
27 #include <linux/kernel.h>
28 #include <linux/sysfs.h>
29 #include <linux/i2c.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/err.h>
34 #include <linux/module.h>
35 #include <linux/bitops.h>
37 #include <linux/iio/iio.h>
38 #include <linux/iio/sysfs.h>
39 #include <linux/iio/events.h>
40 #include <linux/iio/buffer.h>
41 #include <linux/iio/trigger_consumer.h>
42 #include <linux/iio/triggered_buffer.h>
44 #define AD799X_CHANNEL_SHIFT 4
47 * AD7991, AD7995 and AD7999 defines
50 #define AD7991_REF_SEL 0x08
51 #define AD7991_FLTR 0x04
52 #define AD7991_BIT_TRIAL_DELAY 0x02
53 #define AD7991_SAMPLE_DELAY 0x01
56 * AD7992, AD7993, AD7994, AD7997 and AD7998 defines
59 #define AD7998_FLTR BIT(3)
60 #define AD7998_ALERT_EN BIT(2)
61 #define AD7998_BUSY_ALERT BIT(1)
62 #define AD7998_BUSY_ALERT_POL BIT(0)
64 #define AD7998_CONV_RES_REG 0x0
65 #define AD7998_ALERT_STAT_REG 0x1
66 #define AD7998_CONF_REG 0x2
67 #define AD7998_CYCLE_TMR_REG 0x3
69 #define AD7998_DATALOW_REG(x) ((x) * 3 + 0x4)
70 #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5)
71 #define AD7998_HYST_REG(x) ((x) * 3 + 0x6)
73 #define AD7998_CYC_MASK GENMASK(2, 0)
74 #define AD7998_CYC_DIS 0x0
75 #define AD7998_CYC_TCONF_32 0x1
76 #define AD7998_CYC_TCONF_64 0x2
77 #define AD7998_CYC_TCONF_128 0x3
78 #define AD7998_CYC_TCONF_256 0x4
79 #define AD7998_CYC_TCONF_512 0x5
80 #define AD7998_CYC_TCONF_1024 0x6
81 #define AD7998_CYC_TCONF_2048 0x7
83 #define AD7998_ALERT_STAT_CLEAR 0xFF
86 * AD7997 and AD7997 defines
89 #define AD7997_8_READ_SINGLE BIT(7)
90 #define AD7997_8_READ_SEQUENCE (BIT(6) | BIT(5) | BIT(4))
104 * struct ad799x_chip_config - chip specific information
105 * @channel: channel specification
106 * @default_config: device default configuration
107 * @info: pointer to iio_info struct
109 struct ad799x_chip_config
{
110 const struct iio_chan_spec channel
[9];
112 const struct iio_info
*info
;
116 * struct ad799x_chip_info - chip specific information
117 * @num_channels: number of channels
118 * @noirq_config: device configuration w/o IRQ
119 * @irq_config: device configuration w/IRQ
121 struct ad799x_chip_info
{
123 const struct ad799x_chip_config noirq_config
;
124 const struct ad799x_chip_config irq_config
;
127 struct ad799x_state
{
128 struct i2c_client
*client
;
129 const struct ad799x_chip_config
*chip_config
;
130 struct regulator
*reg
;
131 struct regulator
*vref
;
136 unsigned int transfer_size
;
139 static int ad799x_write_config(struct ad799x_state
*st
, u16 val
)
144 return i2c_smbus_write_word_swapped(st
->client
, AD7998_CONF_REG
,
147 return i2c_smbus_write_byte_data(st
->client
, AD7998_CONF_REG
,
152 static int ad799x_read_config(struct ad799x_state
*st
)
157 return i2c_smbus_read_word_swapped(st
->client
, AD7998_CONF_REG
);
159 return i2c_smbus_read_byte_data(st
->client
, AD7998_CONF_REG
);
164 * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
166 * Currently there is no option in this driver to disable the saving of
167 * timestamps within the ring.
169 static irqreturn_t
ad799x_trigger_handler(int irq
, void *p
)
171 struct iio_poll_func
*pf
= p
;
172 struct iio_dev
*indio_dev
= pf
->indio_dev
;
173 struct ad799x_state
*st
= iio_priv(indio_dev
);
182 (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
);
187 cmd
= (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
) |
192 cmd
= AD7997_8_READ_SEQUENCE
| AD7998_CONV_RES_REG
;
198 b_sent
= i2c_smbus_read_i2c_block_data(st
->client
,
199 cmd
, st
->transfer_size
, st
->rx_buf
);
203 iio_push_to_buffers_with_timestamp(indio_dev
, st
->rx_buf
,
206 iio_trigger_notify_done(indio_dev
->trig
);
211 static int ad799x_update_scan_mode(struct iio_dev
*indio_dev
,
212 const unsigned long *scan_mask
)
214 struct ad799x_state
*st
= iio_priv(indio_dev
);
217 st
->rx_buf
= kmalloc(indio_dev
->scan_bytes
, GFP_KERNEL
);
221 st
->transfer_size
= bitmap_weight(scan_mask
, indio_dev
->masklength
) * 2;
229 st
->config
&= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT
);
230 st
->config
|= (*scan_mask
<< AD799X_CHANNEL_SHIFT
);
231 return ad799x_write_config(st
, st
->config
);
237 static int ad799x_scan_direct(struct ad799x_state
*st
, unsigned ch
)
245 cmd
= st
->config
| (BIT(ch
) << AD799X_CHANNEL_SHIFT
);
250 cmd
= BIT(ch
) << AD799X_CHANNEL_SHIFT
;
254 cmd
= (ch
<< AD799X_CHANNEL_SHIFT
) | AD7997_8_READ_SINGLE
;
260 return i2c_smbus_read_word_swapped(st
->client
, cmd
);
263 static int ad799x_read_raw(struct iio_dev
*indio_dev
,
264 struct iio_chan_spec
const *chan
,
270 struct ad799x_state
*st
= iio_priv(indio_dev
);
273 case IIO_CHAN_INFO_RAW
:
274 mutex_lock(&indio_dev
->mlock
);
275 if (iio_buffer_enabled(indio_dev
))
278 ret
= ad799x_scan_direct(st
, chan
->scan_index
);
279 mutex_unlock(&indio_dev
->mlock
);
283 *val
= (ret
>> chan
->scan_type
.shift
) &
284 GENMASK(chan
->scan_type
.realbits
- 1, 0);
286 case IIO_CHAN_INFO_SCALE
:
287 ret
= regulator_get_voltage(st
->vref
);
291 *val2
= chan
->scan_type
.realbits
;
292 return IIO_VAL_FRACTIONAL_LOG2
;
296 static const unsigned int ad7998_frequencies
[] = {
297 [AD7998_CYC_DIS
] = 0,
298 [AD7998_CYC_TCONF_32
] = 15625,
299 [AD7998_CYC_TCONF_64
] = 7812,
300 [AD7998_CYC_TCONF_128
] = 3906,
301 [AD7998_CYC_TCONF_512
] = 976,
302 [AD7998_CYC_TCONF_1024
] = 488,
303 [AD7998_CYC_TCONF_2048
] = 244,
306 static ssize_t
ad799x_read_frequency(struct device
*dev
,
307 struct device_attribute
*attr
,
310 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
311 struct ad799x_state
*st
= iio_priv(indio_dev
);
313 int ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
317 return sprintf(buf
, "%u\n", ad7998_frequencies
[ret
& AD7998_CYC_MASK
]);
320 static ssize_t
ad799x_write_frequency(struct device
*dev
,
321 struct device_attribute
*attr
,
325 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
326 struct ad799x_state
*st
= iio_priv(indio_dev
);
331 ret
= kstrtol(buf
, 10, &val
);
335 mutex_lock(&indio_dev
->mlock
);
336 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
338 goto error_ret_mutex
;
339 /* Wipe the bits clean */
340 ret
&= ~AD7998_CYC_MASK
;
342 for (i
= 0; i
< ARRAY_SIZE(ad7998_frequencies
); i
++)
343 if (val
== ad7998_frequencies
[i
])
345 if (i
== ARRAY_SIZE(ad7998_frequencies
)) {
347 goto error_ret_mutex
;
350 ret
= i2c_smbus_write_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
,
353 goto error_ret_mutex
;
357 mutex_unlock(&indio_dev
->mlock
);
362 static int ad799x_read_event_config(struct iio_dev
*indio_dev
,
363 const struct iio_chan_spec
*chan
,
364 enum iio_event_type type
,
365 enum iio_event_direction dir
)
367 struct ad799x_state
*st
= iio_priv(indio_dev
);
369 if (!(st
->config
& AD7998_ALERT_EN
))
372 if ((st
->config
>> AD799X_CHANNEL_SHIFT
) & BIT(chan
->scan_index
))
378 static int ad799x_write_event_config(struct iio_dev
*indio_dev
,
379 const struct iio_chan_spec
*chan
,
380 enum iio_event_type type
,
381 enum iio_event_direction dir
,
384 struct ad799x_state
*st
= iio_priv(indio_dev
);
387 mutex_lock(&indio_dev
->mlock
);
388 if (iio_buffer_enabled(indio_dev
)) {
394 st
->config
|= BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
;
396 st
->config
&= ~(BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
);
398 if (st
->config
>> AD799X_CHANNEL_SHIFT
)
399 st
->config
|= AD7998_ALERT_EN
;
401 st
->config
&= ~AD7998_ALERT_EN
;
403 ret
= ad799x_write_config(st
, st
->config
);
406 mutex_unlock(&indio_dev
->mlock
);
411 static unsigned int ad799x_threshold_reg(const struct iio_chan_spec
*chan
,
412 enum iio_event_direction dir
,
413 enum iio_event_info info
)
416 case IIO_EV_INFO_VALUE
:
417 if (dir
== IIO_EV_DIR_FALLING
)
418 return AD7998_DATALOW_REG(chan
->channel
);
420 return AD7998_DATAHIGH_REG(chan
->channel
);
421 case IIO_EV_INFO_HYSTERESIS
:
422 return AD7998_HYST_REG(chan
->channel
);
430 static int ad799x_write_event_value(struct iio_dev
*indio_dev
,
431 const struct iio_chan_spec
*chan
,
432 enum iio_event_type type
,
433 enum iio_event_direction dir
,
434 enum iio_event_info info
,
438 struct ad799x_state
*st
= iio_priv(indio_dev
);
440 if (val
< 0 || val
> GENMASK(chan
->scan_type
.realbits
- 1, 0))
443 mutex_lock(&indio_dev
->mlock
);
444 ret
= i2c_smbus_write_word_swapped(st
->client
,
445 ad799x_threshold_reg(chan
, dir
, info
),
446 val
<< chan
->scan_type
.shift
);
447 mutex_unlock(&indio_dev
->mlock
);
452 static int ad799x_read_event_value(struct iio_dev
*indio_dev
,
453 const struct iio_chan_spec
*chan
,
454 enum iio_event_type type
,
455 enum iio_event_direction dir
,
456 enum iio_event_info info
,
460 struct ad799x_state
*st
= iio_priv(indio_dev
);
462 mutex_lock(&indio_dev
->mlock
);
463 ret
= i2c_smbus_read_word_swapped(st
->client
,
464 ad799x_threshold_reg(chan
, dir
, info
));
465 mutex_unlock(&indio_dev
->mlock
);
468 *val
= (ret
>> chan
->scan_type
.shift
) &
469 GENMASK(chan
->scan_type
.realbits
- 1 , 0);
474 static irqreturn_t
ad799x_event_handler(int irq
, void *private)
476 struct iio_dev
*indio_dev
= private;
477 struct ad799x_state
*st
= iio_priv(private);
480 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_ALERT_STAT_REG
);
484 if (i2c_smbus_write_byte_data(st
->client
, AD7998_ALERT_STAT_REG
,
485 AD7998_ALERT_STAT_CLEAR
) < 0)
488 for (i
= 0; i
< 8; i
++) {
490 iio_push_event(indio_dev
,
492 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
496 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
507 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR
| S_IRUGO
,
508 ad799x_read_frequency
,
509 ad799x_write_frequency
);
510 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
512 static struct attribute
*ad799x_event_attributes
[] = {
513 &iio_dev_attr_sampling_frequency
.dev_attr
.attr
,
514 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
518 static struct attribute_group ad799x_event_attrs_group
= {
519 .attrs
= ad799x_event_attributes
,
523 static const struct iio_info ad7991_info
= {
524 .read_raw
= &ad799x_read_raw
,
525 .driver_module
= THIS_MODULE
,
528 static const struct iio_info ad7993_4_7_8_noirq_info
= {
529 .read_raw
= &ad799x_read_raw
,
530 .driver_module
= THIS_MODULE
,
531 .update_scan_mode
= ad799x_update_scan_mode
,
534 static const struct iio_info ad7993_4_7_8_irq_info
= {
535 .read_raw
= &ad799x_read_raw
,
536 .event_attrs
= &ad799x_event_attrs_group
,
537 .read_event_config
= &ad799x_read_event_config
,
538 .write_event_config
= &ad799x_write_event_config
,
539 .read_event_value
= &ad799x_read_event_value
,
540 .write_event_value
= &ad799x_write_event_value
,
541 .driver_module
= THIS_MODULE
,
542 .update_scan_mode
= ad799x_update_scan_mode
,
545 static const struct iio_event_spec ad799x_events
[] = {
547 .type
= IIO_EV_TYPE_THRESH
,
548 .dir
= IIO_EV_DIR_RISING
,
549 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
550 BIT(IIO_EV_INFO_ENABLE
),
552 .type
= IIO_EV_TYPE_THRESH
,
553 .dir
= IIO_EV_DIR_FALLING
,
554 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
555 BIT(IIO_EV_INFO_ENABLE
),
557 .type
= IIO_EV_TYPE_THRESH
,
558 .dir
= IIO_EV_DIR_EITHER
,
559 .mask_separate
= BIT(IIO_EV_INFO_HYSTERESIS
),
563 #define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
564 .type = IIO_VOLTAGE, \
566 .channel = (_index), \
567 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
568 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
569 .scan_index = (_index), \
572 .realbits = (_realbits), \
574 .shift = 12 - (_realbits), \
575 .endianness = IIO_BE, \
577 .event_spec = _ev_spec, \
578 .num_event_specs = _num_ev_spec, \
581 #define AD799X_CHANNEL(_index, _realbits) \
582 _AD799X_CHANNEL(_index, _realbits, NULL, 0)
584 #define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
585 _AD799X_CHANNEL(_index, _realbits, ad799x_events, \
586 ARRAY_SIZE(ad799x_events))
588 static const struct ad799x_chip_info ad799x_chip_info_tbl
[] = {
593 AD799X_CHANNEL(0, 12),
594 AD799X_CHANNEL(1, 12),
595 AD799X_CHANNEL(2, 12),
596 AD799X_CHANNEL(3, 12),
597 IIO_CHAN_SOFT_TIMESTAMP(4),
599 .info
= &ad7991_info
,
606 AD799X_CHANNEL(0, 10),
607 AD799X_CHANNEL(1, 10),
608 AD799X_CHANNEL(2, 10),
609 AD799X_CHANNEL(3, 10),
610 IIO_CHAN_SOFT_TIMESTAMP(4),
612 .info
= &ad7991_info
,
619 AD799X_CHANNEL(0, 8),
620 AD799X_CHANNEL(1, 8),
621 AD799X_CHANNEL(2, 8),
622 AD799X_CHANNEL(3, 8),
623 IIO_CHAN_SOFT_TIMESTAMP(4),
625 .info
= &ad7991_info
,
632 AD799X_CHANNEL(0, 12),
633 AD799X_CHANNEL(1, 12),
634 IIO_CHAN_SOFT_TIMESTAMP(3),
636 .info
= &ad7993_4_7_8_noirq_info
,
640 AD799X_CHANNEL_WITH_EVENTS(0, 12),
641 AD799X_CHANNEL_WITH_EVENTS(1, 12),
642 IIO_CHAN_SOFT_TIMESTAMP(3),
644 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
645 .info
= &ad7993_4_7_8_irq_info
,
652 AD799X_CHANNEL(0, 10),
653 AD799X_CHANNEL(1, 10),
654 AD799X_CHANNEL(2, 10),
655 AD799X_CHANNEL(3, 10),
656 IIO_CHAN_SOFT_TIMESTAMP(4),
658 .info
= &ad7993_4_7_8_noirq_info
,
662 AD799X_CHANNEL_WITH_EVENTS(0, 10),
663 AD799X_CHANNEL_WITH_EVENTS(1, 10),
664 AD799X_CHANNEL_WITH_EVENTS(2, 10),
665 AD799X_CHANNEL_WITH_EVENTS(3, 10),
666 IIO_CHAN_SOFT_TIMESTAMP(4),
668 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
669 .info
= &ad7993_4_7_8_irq_info
,
676 AD799X_CHANNEL(0, 12),
677 AD799X_CHANNEL(1, 12),
678 AD799X_CHANNEL(2, 12),
679 AD799X_CHANNEL(3, 12),
680 IIO_CHAN_SOFT_TIMESTAMP(4),
682 .info
= &ad7993_4_7_8_noirq_info
,
686 AD799X_CHANNEL_WITH_EVENTS(0, 12),
687 AD799X_CHANNEL_WITH_EVENTS(1, 12),
688 AD799X_CHANNEL_WITH_EVENTS(2, 12),
689 AD799X_CHANNEL_WITH_EVENTS(3, 12),
690 IIO_CHAN_SOFT_TIMESTAMP(4),
692 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
693 .info
= &ad7993_4_7_8_irq_info
,
700 AD799X_CHANNEL(0, 10),
701 AD799X_CHANNEL(1, 10),
702 AD799X_CHANNEL(2, 10),
703 AD799X_CHANNEL(3, 10),
704 AD799X_CHANNEL(4, 10),
705 AD799X_CHANNEL(5, 10),
706 AD799X_CHANNEL(6, 10),
707 AD799X_CHANNEL(7, 10),
708 IIO_CHAN_SOFT_TIMESTAMP(8),
710 .info
= &ad7993_4_7_8_noirq_info
,
714 AD799X_CHANNEL_WITH_EVENTS(0, 10),
715 AD799X_CHANNEL_WITH_EVENTS(1, 10),
716 AD799X_CHANNEL_WITH_EVENTS(2, 10),
717 AD799X_CHANNEL_WITH_EVENTS(3, 10),
718 AD799X_CHANNEL(4, 10),
719 AD799X_CHANNEL(5, 10),
720 AD799X_CHANNEL(6, 10),
721 AD799X_CHANNEL(7, 10),
722 IIO_CHAN_SOFT_TIMESTAMP(8),
724 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
725 .info
= &ad7993_4_7_8_irq_info
,
732 AD799X_CHANNEL(0, 12),
733 AD799X_CHANNEL(1, 12),
734 AD799X_CHANNEL(2, 12),
735 AD799X_CHANNEL(3, 12),
736 AD799X_CHANNEL(4, 12),
737 AD799X_CHANNEL(5, 12),
738 AD799X_CHANNEL(6, 12),
739 AD799X_CHANNEL(7, 12),
740 IIO_CHAN_SOFT_TIMESTAMP(8),
742 .info
= &ad7993_4_7_8_noirq_info
,
746 AD799X_CHANNEL_WITH_EVENTS(0, 12),
747 AD799X_CHANNEL_WITH_EVENTS(1, 12),
748 AD799X_CHANNEL_WITH_EVENTS(2, 12),
749 AD799X_CHANNEL_WITH_EVENTS(3, 12),
750 AD799X_CHANNEL(4, 12),
751 AD799X_CHANNEL(5, 12),
752 AD799X_CHANNEL(6, 12),
753 AD799X_CHANNEL(7, 12),
754 IIO_CHAN_SOFT_TIMESTAMP(8),
756 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
757 .info
= &ad7993_4_7_8_irq_info
,
762 static int ad799x_probe(struct i2c_client
*client
,
763 const struct i2c_device_id
*id
)
766 struct ad799x_state
*st
;
767 struct iio_dev
*indio_dev
;
768 const struct ad799x_chip_info
*chip_info
=
769 &ad799x_chip_info_tbl
[id
->driver_data
];
771 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*st
));
772 if (indio_dev
== NULL
)
775 st
= iio_priv(indio_dev
);
776 /* this is only used for device removal purposes */
777 i2c_set_clientdata(client
, indio_dev
);
779 st
->id
= id
->driver_data
;
780 if (client
->irq
> 0 && chip_info
->irq_config
.info
)
781 st
->chip_config
= &chip_info
->irq_config
;
783 st
->chip_config
= &chip_info
->noirq_config
;
785 /* TODO: Add pdata options for filtering and bit delay */
787 st
->reg
= devm_regulator_get(&client
->dev
, "vcc");
789 return PTR_ERR(st
->reg
);
790 ret
= regulator_enable(st
->reg
);
793 st
->vref
= devm_regulator_get(&client
->dev
, "vref");
794 if (IS_ERR(st
->vref
)) {
795 ret
= PTR_ERR(st
->vref
);
796 goto error_disable_reg
;
798 ret
= regulator_enable(st
->vref
);
800 goto error_disable_reg
;
804 indio_dev
->dev
.parent
= &client
->dev
;
805 indio_dev
->name
= id
->name
;
806 indio_dev
->info
= st
->chip_config
->info
;
808 indio_dev
->modes
= INDIO_DIRECT_MODE
;
809 indio_dev
->channels
= st
->chip_config
->channel
;
810 indio_dev
->num_channels
= chip_info
->num_channels
;
812 ret
= ad799x_write_config(st
, st
->chip_config
->default_config
);
814 goto error_disable_reg
;
815 ret
= ad799x_read_config(st
);
817 goto error_disable_reg
;
820 ret
= iio_triggered_buffer_setup(indio_dev
, NULL
,
821 &ad799x_trigger_handler
, NULL
);
823 goto error_disable_vref
;
825 if (client
->irq
> 0) {
826 ret
= devm_request_threaded_irq(&client
->dev
,
829 ad799x_event_handler
,
830 IRQF_TRIGGER_FALLING
|
835 goto error_cleanup_ring
;
837 ret
= iio_device_register(indio_dev
);
839 goto error_cleanup_ring
;
844 iio_triggered_buffer_cleanup(indio_dev
);
846 regulator_disable(st
->vref
);
848 regulator_disable(st
->reg
);
853 static int ad799x_remove(struct i2c_client
*client
)
855 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
856 struct ad799x_state
*st
= iio_priv(indio_dev
);
858 iio_device_unregister(indio_dev
);
860 iio_triggered_buffer_cleanup(indio_dev
);
861 regulator_disable(st
->vref
);
862 regulator_disable(st
->reg
);
868 static const struct i2c_device_id ad799x_id
[] = {
869 { "ad7991", ad7991
},
870 { "ad7995", ad7995
},
871 { "ad7999", ad7999
},
872 { "ad7992", ad7992
},
873 { "ad7993", ad7993
},
874 { "ad7994", ad7994
},
875 { "ad7997", ad7997
},
876 { "ad7998", ad7998
},
880 MODULE_DEVICE_TABLE(i2c
, ad799x_id
);
882 static struct i2c_driver ad799x_driver
= {
886 .probe
= ad799x_probe
,
887 .remove
= ad799x_remove
,
888 .id_table
= ad799x_id
,
890 module_i2c_driver(ad799x_driver
);
892 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
893 MODULE_DESCRIPTION("Analog Devices AD799x ADC");
894 MODULE_LICENSE("GPL v2");