1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
6 * based on iio/adc/max1363
7 * Copyright (C) 2008-2010 Jonathan Cameron
9 * based on linux/drivers/i2c/chips/max123x
10 * Copyright (C) 2002-2004 Stefan Eletzhofer
12 * based on linux/drivers/acron/char/pcf8583.c
13 * Copyright (C) 2000 Russell King
17 * Support for ad7991, ad7995, ad7999, ad7992, ad7993, ad7994, ad7997,
18 * ad7998 and similar chips.
21 #include <linux/interrupt.h>
22 #include <linux/device.h>
23 #include <linux/kernel.h>
24 #include <linux/sysfs.h>
25 #include <linux/i2c.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/err.h>
30 #include <linux/module.h>
31 #include <linux/bitops.h>
33 #include <linux/iio/iio.h>
34 #include <linux/iio/sysfs.h>
35 #include <linux/iio/events.h>
36 #include <linux/iio/buffer.h>
37 #include <linux/iio/trigger_consumer.h>
38 #include <linux/iio/triggered_buffer.h>
40 #define AD799X_CHANNEL_SHIFT 4
43 * AD7991, AD7995 and AD7999 defines
46 #define AD7991_REF_SEL 0x08
47 #define AD7991_FLTR 0x04
48 #define AD7991_BIT_TRIAL_DELAY 0x02
49 #define AD7991_SAMPLE_DELAY 0x01
52 * AD7992, AD7993, AD7994, AD7997 and AD7998 defines
55 #define AD7998_FLTR BIT(3)
56 #define AD7998_ALERT_EN BIT(2)
57 #define AD7998_BUSY_ALERT BIT(1)
58 #define AD7998_BUSY_ALERT_POL BIT(0)
60 #define AD7998_CONV_RES_REG 0x0
61 #define AD7998_ALERT_STAT_REG 0x1
62 #define AD7998_CONF_REG 0x2
63 #define AD7998_CYCLE_TMR_REG 0x3
65 #define AD7998_DATALOW_REG(x) ((x) * 3 + 0x4)
66 #define AD7998_DATAHIGH_REG(x) ((x) * 3 + 0x5)
67 #define AD7998_HYST_REG(x) ((x) * 3 + 0x6)
69 #define AD7998_CYC_MASK GENMASK(2, 0)
70 #define AD7998_CYC_DIS 0x0
71 #define AD7998_CYC_TCONF_32 0x1
72 #define AD7998_CYC_TCONF_64 0x2
73 #define AD7998_CYC_TCONF_128 0x3
74 #define AD7998_CYC_TCONF_256 0x4
75 #define AD7998_CYC_TCONF_512 0x5
76 #define AD7998_CYC_TCONF_1024 0x6
77 #define AD7998_CYC_TCONF_2048 0x7
79 #define AD7998_ALERT_STAT_CLEAR 0xFF
82 * AD7997 and AD7997 defines
85 #define AD7997_8_READ_SINGLE BIT(7)
86 #define AD7997_8_READ_SEQUENCE (BIT(6) | BIT(5) | BIT(4))
100 * struct ad799x_chip_config - chip specific information
101 * @channel: channel specification
102 * @default_config: device default configuration
103 * @info: pointer to iio_info struct
105 struct ad799x_chip_config
{
106 const struct iio_chan_spec channel
[9];
108 const struct iio_info
*info
;
112 * struct ad799x_chip_info - chip specific information
113 * @num_channels: number of channels
114 * @noirq_config: device configuration w/o IRQ
115 * @irq_config: device configuration w/IRQ
117 struct ad799x_chip_info
{
119 const struct ad799x_chip_config noirq_config
;
120 const struct ad799x_chip_config irq_config
;
123 struct ad799x_state
{
124 struct i2c_client
*client
;
125 const struct ad799x_chip_config
*chip_config
;
126 struct regulator
*reg
;
127 struct regulator
*vref
;
132 unsigned int transfer_size
;
135 static int ad799x_write_config(struct ad799x_state
*st
, u16 val
)
140 return i2c_smbus_write_word_swapped(st
->client
, AD7998_CONF_REG
,
145 return i2c_smbus_write_byte_data(st
->client
, AD7998_CONF_REG
,
148 /* Will be written when doing a conversion */
154 static int ad799x_read_config(struct ad799x_state
*st
)
159 return i2c_smbus_read_word_swapped(st
->client
, AD7998_CONF_REG
);
163 return i2c_smbus_read_byte_data(st
->client
, AD7998_CONF_REG
);
165 /* No readback support */
171 * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
173 * Currently there is no option in this driver to disable the saving of
174 * timestamps within the ring.
176 static irqreturn_t
ad799x_trigger_handler(int irq
, void *p
)
178 struct iio_poll_func
*pf
= p
;
179 struct iio_dev
*indio_dev
= pf
->indio_dev
;
180 struct ad799x_state
*st
= iio_priv(indio_dev
);
189 (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
);
194 cmd
= (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
) |
199 cmd
= AD7997_8_READ_SEQUENCE
| AD7998_CONV_RES_REG
;
205 b_sent
= i2c_smbus_read_i2c_block_data(st
->client
,
206 cmd
, st
->transfer_size
, st
->rx_buf
);
210 iio_push_to_buffers_with_timestamp(indio_dev
, st
->rx_buf
,
211 iio_get_time_ns(indio_dev
));
213 iio_trigger_notify_done(indio_dev
->trig
);
218 static int ad799x_update_scan_mode(struct iio_dev
*indio_dev
,
219 const unsigned long *scan_mask
)
221 struct ad799x_state
*st
= iio_priv(indio_dev
);
224 st
->rx_buf
= kmalloc(indio_dev
->scan_bytes
, GFP_KERNEL
);
228 st
->transfer_size
= bitmap_weight(scan_mask
, indio_dev
->masklength
) * 2;
236 st
->config
&= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT
);
237 st
->config
|= (*scan_mask
<< AD799X_CHANNEL_SHIFT
);
238 return ad799x_write_config(st
, st
->config
);
244 static int ad799x_scan_direct(struct ad799x_state
*st
, unsigned ch
)
252 cmd
= st
->config
| (BIT(ch
) << AD799X_CHANNEL_SHIFT
);
257 cmd
= BIT(ch
) << AD799X_CHANNEL_SHIFT
;
261 cmd
= (ch
<< AD799X_CHANNEL_SHIFT
) | AD7997_8_READ_SINGLE
;
267 return i2c_smbus_read_word_swapped(st
->client
, cmd
);
270 static int ad799x_read_raw(struct iio_dev
*indio_dev
,
271 struct iio_chan_spec
const *chan
,
277 struct ad799x_state
*st
= iio_priv(indio_dev
);
280 case IIO_CHAN_INFO_RAW
:
281 ret
= iio_device_claim_direct_mode(indio_dev
);
284 ret
= ad799x_scan_direct(st
, chan
->scan_index
);
285 iio_device_release_direct_mode(indio_dev
);
289 *val
= (ret
>> chan
->scan_type
.shift
) &
290 GENMASK(chan
->scan_type
.realbits
- 1, 0);
292 case IIO_CHAN_INFO_SCALE
:
293 ret
= regulator_get_voltage(st
->vref
);
297 *val2
= chan
->scan_type
.realbits
;
298 return IIO_VAL_FRACTIONAL_LOG2
;
302 static const unsigned int ad7998_frequencies
[] = {
303 [AD7998_CYC_DIS
] = 0,
304 [AD7998_CYC_TCONF_32
] = 15625,
305 [AD7998_CYC_TCONF_64
] = 7812,
306 [AD7998_CYC_TCONF_128
] = 3906,
307 [AD7998_CYC_TCONF_512
] = 976,
308 [AD7998_CYC_TCONF_1024
] = 488,
309 [AD7998_CYC_TCONF_2048
] = 244,
312 static ssize_t
ad799x_read_frequency(struct device
*dev
,
313 struct device_attribute
*attr
,
316 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
317 struct ad799x_state
*st
= iio_priv(indio_dev
);
319 int ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
323 return sprintf(buf
, "%u\n", ad7998_frequencies
[ret
& AD7998_CYC_MASK
]);
326 static ssize_t
ad799x_write_frequency(struct device
*dev
,
327 struct device_attribute
*attr
,
331 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
332 struct ad799x_state
*st
= iio_priv(indio_dev
);
337 ret
= kstrtol(buf
, 10, &val
);
341 mutex_lock(&indio_dev
->mlock
);
342 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
344 goto error_ret_mutex
;
345 /* Wipe the bits clean */
346 ret
&= ~AD7998_CYC_MASK
;
348 for (i
= 0; i
< ARRAY_SIZE(ad7998_frequencies
); i
++)
349 if (val
== ad7998_frequencies
[i
])
351 if (i
== ARRAY_SIZE(ad7998_frequencies
)) {
353 goto error_ret_mutex
;
356 ret
= i2c_smbus_write_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
,
359 goto error_ret_mutex
;
363 mutex_unlock(&indio_dev
->mlock
);
368 static int ad799x_read_event_config(struct iio_dev
*indio_dev
,
369 const struct iio_chan_spec
*chan
,
370 enum iio_event_type type
,
371 enum iio_event_direction dir
)
373 struct ad799x_state
*st
= iio_priv(indio_dev
);
375 if (!(st
->config
& AD7998_ALERT_EN
))
378 if ((st
->config
>> AD799X_CHANNEL_SHIFT
) & BIT(chan
->scan_index
))
384 static int ad799x_write_event_config(struct iio_dev
*indio_dev
,
385 const struct iio_chan_spec
*chan
,
386 enum iio_event_type type
,
387 enum iio_event_direction dir
,
390 struct ad799x_state
*st
= iio_priv(indio_dev
);
393 ret
= iio_device_claim_direct_mode(indio_dev
);
398 st
->config
|= BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
;
400 st
->config
&= ~(BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
);
402 if (st
->config
>> AD799X_CHANNEL_SHIFT
)
403 st
->config
|= AD7998_ALERT_EN
;
405 st
->config
&= ~AD7998_ALERT_EN
;
407 ret
= ad799x_write_config(st
, st
->config
);
408 iio_device_release_direct_mode(indio_dev
);
412 static unsigned int ad799x_threshold_reg(const struct iio_chan_spec
*chan
,
413 enum iio_event_direction dir
,
414 enum iio_event_info info
)
417 case IIO_EV_INFO_VALUE
:
418 if (dir
== IIO_EV_DIR_FALLING
)
419 return AD7998_DATALOW_REG(chan
->channel
);
421 return AD7998_DATAHIGH_REG(chan
->channel
);
422 case IIO_EV_INFO_HYSTERESIS
:
423 return AD7998_HYST_REG(chan
->channel
);
431 static int ad799x_write_event_value(struct iio_dev
*indio_dev
,
432 const struct iio_chan_spec
*chan
,
433 enum iio_event_type type
,
434 enum iio_event_direction dir
,
435 enum iio_event_info info
,
439 struct ad799x_state
*st
= iio_priv(indio_dev
);
441 if (val
< 0 || val
> GENMASK(chan
->scan_type
.realbits
- 1, 0))
444 mutex_lock(&indio_dev
->mlock
);
445 ret
= i2c_smbus_write_word_swapped(st
->client
,
446 ad799x_threshold_reg(chan
, dir
, info
),
447 val
<< chan
->scan_type
.shift
);
448 mutex_unlock(&indio_dev
->mlock
);
453 static int ad799x_read_event_value(struct iio_dev
*indio_dev
,
454 const struct iio_chan_spec
*chan
,
455 enum iio_event_type type
,
456 enum iio_event_direction dir
,
457 enum iio_event_info info
,
461 struct ad799x_state
*st
= iio_priv(indio_dev
);
463 mutex_lock(&indio_dev
->mlock
);
464 ret
= i2c_smbus_read_word_swapped(st
->client
,
465 ad799x_threshold_reg(chan
, dir
, info
));
466 mutex_unlock(&indio_dev
->mlock
);
469 *val
= (ret
>> chan
->scan_type
.shift
) &
470 GENMASK(chan
->scan_type
.realbits
- 1, 0);
475 static irqreturn_t
ad799x_event_handler(int irq
, void *private)
477 struct iio_dev
*indio_dev
= private;
478 struct ad799x_state
*st
= iio_priv(private);
481 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_ALERT_STAT_REG
);
485 if (i2c_smbus_write_byte_data(st
->client
, AD7998_ALERT_STAT_REG
,
486 AD7998_ALERT_STAT_CLEAR
) < 0)
489 for (i
= 0; i
< 8; i
++) {
491 iio_push_event(indio_dev
,
493 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
497 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
501 iio_get_time_ns(indio_dev
));
508 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR
| S_IRUGO
,
509 ad799x_read_frequency
,
510 ad799x_write_frequency
);
511 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
513 static struct attribute
*ad799x_event_attributes
[] = {
514 &iio_dev_attr_sampling_frequency
.dev_attr
.attr
,
515 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
519 static const struct attribute_group ad799x_event_attrs_group
= {
520 .attrs
= ad799x_event_attributes
,
523 static const struct iio_info ad7991_info
= {
524 .read_raw
= &ad799x_read_raw
,
525 .update_scan_mode
= ad799x_update_scan_mode
,
528 static const struct iio_info ad7993_4_7_8_noirq_info
= {
529 .read_raw
= &ad799x_read_raw
,
530 .update_scan_mode
= ad799x_update_scan_mode
,
533 static const struct iio_info ad7993_4_7_8_irq_info
= {
534 .read_raw
= &ad799x_read_raw
,
535 .event_attrs
= &ad799x_event_attrs_group
,
536 .read_event_config
= &ad799x_read_event_config
,
537 .write_event_config
= &ad799x_write_event_config
,
538 .read_event_value
= &ad799x_read_event_value
,
539 .write_event_value
= &ad799x_write_event_value
,
540 .update_scan_mode
= ad799x_update_scan_mode
,
543 static const struct iio_event_spec ad799x_events
[] = {
545 .type
= IIO_EV_TYPE_THRESH
,
546 .dir
= IIO_EV_DIR_RISING
,
547 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
548 BIT(IIO_EV_INFO_ENABLE
),
550 .type
= IIO_EV_TYPE_THRESH
,
551 .dir
= IIO_EV_DIR_FALLING
,
552 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
553 BIT(IIO_EV_INFO_ENABLE
),
555 .type
= IIO_EV_TYPE_THRESH
,
556 .dir
= IIO_EV_DIR_EITHER
,
557 .mask_separate
= BIT(IIO_EV_INFO_HYSTERESIS
),
561 #define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
562 .type = IIO_VOLTAGE, \
564 .channel = (_index), \
565 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
566 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
567 .scan_index = (_index), \
570 .realbits = (_realbits), \
572 .shift = 12 - (_realbits), \
573 .endianness = IIO_BE, \
575 .event_spec = _ev_spec, \
576 .num_event_specs = _num_ev_spec, \
579 #define AD799X_CHANNEL(_index, _realbits) \
580 _AD799X_CHANNEL(_index, _realbits, NULL, 0)
582 #define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
583 _AD799X_CHANNEL(_index, _realbits, ad799x_events, \
584 ARRAY_SIZE(ad799x_events))
586 static const struct ad799x_chip_info ad799x_chip_info_tbl
[] = {
591 AD799X_CHANNEL(0, 12),
592 AD799X_CHANNEL(1, 12),
593 AD799X_CHANNEL(2, 12),
594 AD799X_CHANNEL(3, 12),
595 IIO_CHAN_SOFT_TIMESTAMP(4),
597 .info
= &ad7991_info
,
604 AD799X_CHANNEL(0, 10),
605 AD799X_CHANNEL(1, 10),
606 AD799X_CHANNEL(2, 10),
607 AD799X_CHANNEL(3, 10),
608 IIO_CHAN_SOFT_TIMESTAMP(4),
610 .info
= &ad7991_info
,
617 AD799X_CHANNEL(0, 8),
618 AD799X_CHANNEL(1, 8),
619 AD799X_CHANNEL(2, 8),
620 AD799X_CHANNEL(3, 8),
621 IIO_CHAN_SOFT_TIMESTAMP(4),
623 .info
= &ad7991_info
,
630 AD799X_CHANNEL(0, 12),
631 AD799X_CHANNEL(1, 12),
632 IIO_CHAN_SOFT_TIMESTAMP(3),
634 .info
= &ad7993_4_7_8_noirq_info
,
638 AD799X_CHANNEL_WITH_EVENTS(0, 12),
639 AD799X_CHANNEL_WITH_EVENTS(1, 12),
640 IIO_CHAN_SOFT_TIMESTAMP(3),
642 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
643 .info
= &ad7993_4_7_8_irq_info
,
650 AD799X_CHANNEL(0, 10),
651 AD799X_CHANNEL(1, 10),
652 AD799X_CHANNEL(2, 10),
653 AD799X_CHANNEL(3, 10),
654 IIO_CHAN_SOFT_TIMESTAMP(4),
656 .info
= &ad7993_4_7_8_noirq_info
,
660 AD799X_CHANNEL_WITH_EVENTS(0, 10),
661 AD799X_CHANNEL_WITH_EVENTS(1, 10),
662 AD799X_CHANNEL_WITH_EVENTS(2, 10),
663 AD799X_CHANNEL_WITH_EVENTS(3, 10),
664 IIO_CHAN_SOFT_TIMESTAMP(4),
666 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
667 .info
= &ad7993_4_7_8_irq_info
,
674 AD799X_CHANNEL(0, 12),
675 AD799X_CHANNEL(1, 12),
676 AD799X_CHANNEL(2, 12),
677 AD799X_CHANNEL(3, 12),
678 IIO_CHAN_SOFT_TIMESTAMP(4),
680 .info
= &ad7993_4_7_8_noirq_info
,
684 AD799X_CHANNEL_WITH_EVENTS(0, 12),
685 AD799X_CHANNEL_WITH_EVENTS(1, 12),
686 AD799X_CHANNEL_WITH_EVENTS(2, 12),
687 AD799X_CHANNEL_WITH_EVENTS(3, 12),
688 IIO_CHAN_SOFT_TIMESTAMP(4),
690 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
691 .info
= &ad7993_4_7_8_irq_info
,
698 AD799X_CHANNEL(0, 10),
699 AD799X_CHANNEL(1, 10),
700 AD799X_CHANNEL(2, 10),
701 AD799X_CHANNEL(3, 10),
702 AD799X_CHANNEL(4, 10),
703 AD799X_CHANNEL(5, 10),
704 AD799X_CHANNEL(6, 10),
705 AD799X_CHANNEL(7, 10),
706 IIO_CHAN_SOFT_TIMESTAMP(8),
708 .info
= &ad7993_4_7_8_noirq_info
,
712 AD799X_CHANNEL_WITH_EVENTS(0, 10),
713 AD799X_CHANNEL_WITH_EVENTS(1, 10),
714 AD799X_CHANNEL_WITH_EVENTS(2, 10),
715 AD799X_CHANNEL_WITH_EVENTS(3, 10),
716 AD799X_CHANNEL(4, 10),
717 AD799X_CHANNEL(5, 10),
718 AD799X_CHANNEL(6, 10),
719 AD799X_CHANNEL(7, 10),
720 IIO_CHAN_SOFT_TIMESTAMP(8),
722 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
723 .info
= &ad7993_4_7_8_irq_info
,
730 AD799X_CHANNEL(0, 12),
731 AD799X_CHANNEL(1, 12),
732 AD799X_CHANNEL(2, 12),
733 AD799X_CHANNEL(3, 12),
734 AD799X_CHANNEL(4, 12),
735 AD799X_CHANNEL(5, 12),
736 AD799X_CHANNEL(6, 12),
737 AD799X_CHANNEL(7, 12),
738 IIO_CHAN_SOFT_TIMESTAMP(8),
740 .info
= &ad7993_4_7_8_noirq_info
,
744 AD799X_CHANNEL_WITH_EVENTS(0, 12),
745 AD799X_CHANNEL_WITH_EVENTS(1, 12),
746 AD799X_CHANNEL_WITH_EVENTS(2, 12),
747 AD799X_CHANNEL_WITH_EVENTS(3, 12),
748 AD799X_CHANNEL(4, 12),
749 AD799X_CHANNEL(5, 12),
750 AD799X_CHANNEL(6, 12),
751 AD799X_CHANNEL(7, 12),
752 IIO_CHAN_SOFT_TIMESTAMP(8),
754 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
755 .info
= &ad7993_4_7_8_irq_info
,
760 static int ad799x_probe(struct i2c_client
*client
,
761 const struct i2c_device_id
*id
)
764 struct ad799x_state
*st
;
765 struct iio_dev
*indio_dev
;
766 const struct ad799x_chip_info
*chip_info
=
767 &ad799x_chip_info_tbl
[id
->driver_data
];
769 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*st
));
770 if (indio_dev
== NULL
)
773 st
= iio_priv(indio_dev
);
774 /* this is only used for device removal purposes */
775 i2c_set_clientdata(client
, indio_dev
);
777 st
->id
= id
->driver_data
;
778 if (client
->irq
> 0 && chip_info
->irq_config
.info
)
779 st
->chip_config
= &chip_info
->irq_config
;
781 st
->chip_config
= &chip_info
->noirq_config
;
783 /* TODO: Add pdata options for filtering and bit delay */
785 st
->reg
= devm_regulator_get(&client
->dev
, "vcc");
787 return PTR_ERR(st
->reg
);
788 ret
= regulator_enable(st
->reg
);
791 st
->vref
= devm_regulator_get(&client
->dev
, "vref");
792 if (IS_ERR(st
->vref
)) {
793 ret
= PTR_ERR(st
->vref
);
794 goto error_disable_reg
;
796 ret
= regulator_enable(st
->vref
);
798 goto error_disable_reg
;
802 indio_dev
->dev
.parent
= &client
->dev
;
803 indio_dev
->dev
.of_node
= client
->dev
.of_node
;
804 indio_dev
->name
= id
->name
;
805 indio_dev
->info
= st
->chip_config
->info
;
807 indio_dev
->modes
= INDIO_DIRECT_MODE
;
808 indio_dev
->channels
= st
->chip_config
->channel
;
809 indio_dev
->num_channels
= chip_info
->num_channels
;
811 ret
= ad799x_write_config(st
, st
->chip_config
->default_config
);
813 goto error_disable_reg
;
814 ret
= ad799x_read_config(st
);
816 goto error_disable_reg
;
819 ret
= iio_triggered_buffer_setup(indio_dev
, NULL
,
820 &ad799x_trigger_handler
, NULL
);
822 goto error_disable_vref
;
824 if (client
->irq
> 0) {
825 ret
= devm_request_threaded_irq(&client
->dev
,
828 ad799x_event_handler
,
829 IRQF_TRIGGER_FALLING
|
834 goto error_cleanup_ring
;
836 ret
= iio_device_register(indio_dev
);
838 goto error_cleanup_ring
;
843 iio_triggered_buffer_cleanup(indio_dev
);
845 regulator_disable(st
->vref
);
847 regulator_disable(st
->reg
);
852 static int ad799x_remove(struct i2c_client
*client
)
854 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
855 struct ad799x_state
*st
= iio_priv(indio_dev
);
857 iio_device_unregister(indio_dev
);
859 iio_triggered_buffer_cleanup(indio_dev
);
860 regulator_disable(st
->vref
);
861 regulator_disable(st
->reg
);
867 static const struct i2c_device_id ad799x_id
[] = {
868 { "ad7991", ad7991
},
869 { "ad7995", ad7995
},
870 { "ad7999", ad7999
},
871 { "ad7992", ad7992
},
872 { "ad7993", ad7993
},
873 { "ad7994", ad7994
},
874 { "ad7997", ad7997
},
875 { "ad7998", ad7998
},
879 MODULE_DEVICE_TABLE(i2c
, ad799x_id
);
881 static struct i2c_driver ad799x_driver
= {
885 .probe
= ad799x_probe
,
886 .remove
= ad799x_remove
,
887 .id_table
= ad799x_id
,
889 module_i2c_driver(ad799x_driver
);
891 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
892 MODULE_DESCRIPTION("Analog Devices AD799x ADC");
893 MODULE_LICENSE("GPL v2");