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
,
149 return i2c_smbus_write_byte_data(st
->client
, AD7998_CONF_REG
,
152 /* Will be written when doing a conversion */
158 static int ad799x_read_config(struct ad799x_state
*st
)
163 return i2c_smbus_read_word_swapped(st
->client
, AD7998_CONF_REG
);
167 return i2c_smbus_read_byte_data(st
->client
, AD7998_CONF_REG
);
169 /* No readback support */
175 * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
177 * Currently there is no option in this driver to disable the saving of
178 * timestamps within the ring.
180 static irqreturn_t
ad799x_trigger_handler(int irq
, void *p
)
182 struct iio_poll_func
*pf
= p
;
183 struct iio_dev
*indio_dev
= pf
->indio_dev
;
184 struct ad799x_state
*st
= iio_priv(indio_dev
);
193 (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
);
198 cmd
= (*indio_dev
->active_scan_mask
<< AD799X_CHANNEL_SHIFT
) |
203 cmd
= AD7997_8_READ_SEQUENCE
| AD7998_CONV_RES_REG
;
209 b_sent
= i2c_smbus_read_i2c_block_data(st
->client
,
210 cmd
, st
->transfer_size
, st
->rx_buf
);
214 iio_push_to_buffers_with_timestamp(indio_dev
, st
->rx_buf
,
217 iio_trigger_notify_done(indio_dev
->trig
);
222 static int ad799x_update_scan_mode(struct iio_dev
*indio_dev
,
223 const unsigned long *scan_mask
)
225 struct ad799x_state
*st
= iio_priv(indio_dev
);
228 st
->rx_buf
= kmalloc(indio_dev
->scan_bytes
, GFP_KERNEL
);
232 st
->transfer_size
= bitmap_weight(scan_mask
, indio_dev
->masklength
) * 2;
240 st
->config
&= ~(GENMASK(7, 0) << AD799X_CHANNEL_SHIFT
);
241 st
->config
|= (*scan_mask
<< AD799X_CHANNEL_SHIFT
);
242 return ad799x_write_config(st
, st
->config
);
248 static int ad799x_scan_direct(struct ad799x_state
*st
, unsigned ch
)
256 cmd
= st
->config
| (BIT(ch
) << AD799X_CHANNEL_SHIFT
);
261 cmd
= BIT(ch
) << AD799X_CHANNEL_SHIFT
;
265 cmd
= (ch
<< AD799X_CHANNEL_SHIFT
) | AD7997_8_READ_SINGLE
;
271 return i2c_smbus_read_word_swapped(st
->client
, cmd
);
274 static int ad799x_read_raw(struct iio_dev
*indio_dev
,
275 struct iio_chan_spec
const *chan
,
281 struct ad799x_state
*st
= iio_priv(indio_dev
);
284 case IIO_CHAN_INFO_RAW
:
285 mutex_lock(&indio_dev
->mlock
);
286 if (iio_buffer_enabled(indio_dev
))
289 ret
= ad799x_scan_direct(st
, chan
->scan_index
);
290 mutex_unlock(&indio_dev
->mlock
);
294 *val
= (ret
>> chan
->scan_type
.shift
) &
295 GENMASK(chan
->scan_type
.realbits
- 1, 0);
297 case IIO_CHAN_INFO_SCALE
:
298 ret
= regulator_get_voltage(st
->vref
);
302 *val2
= chan
->scan_type
.realbits
;
303 return IIO_VAL_FRACTIONAL_LOG2
;
307 static const unsigned int ad7998_frequencies
[] = {
308 [AD7998_CYC_DIS
] = 0,
309 [AD7998_CYC_TCONF_32
] = 15625,
310 [AD7998_CYC_TCONF_64
] = 7812,
311 [AD7998_CYC_TCONF_128
] = 3906,
312 [AD7998_CYC_TCONF_512
] = 976,
313 [AD7998_CYC_TCONF_1024
] = 488,
314 [AD7998_CYC_TCONF_2048
] = 244,
317 static ssize_t
ad799x_read_frequency(struct device
*dev
,
318 struct device_attribute
*attr
,
321 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
322 struct ad799x_state
*st
= iio_priv(indio_dev
);
324 int ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
328 return sprintf(buf
, "%u\n", ad7998_frequencies
[ret
& AD7998_CYC_MASK
]);
331 static ssize_t
ad799x_write_frequency(struct device
*dev
,
332 struct device_attribute
*attr
,
336 struct iio_dev
*indio_dev
= dev_to_iio_dev(dev
);
337 struct ad799x_state
*st
= iio_priv(indio_dev
);
342 ret
= kstrtol(buf
, 10, &val
);
346 mutex_lock(&indio_dev
->mlock
);
347 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
);
349 goto error_ret_mutex
;
350 /* Wipe the bits clean */
351 ret
&= ~AD7998_CYC_MASK
;
353 for (i
= 0; i
< ARRAY_SIZE(ad7998_frequencies
); i
++)
354 if (val
== ad7998_frequencies
[i
])
356 if (i
== ARRAY_SIZE(ad7998_frequencies
)) {
358 goto error_ret_mutex
;
361 ret
= i2c_smbus_write_byte_data(st
->client
, AD7998_CYCLE_TMR_REG
,
364 goto error_ret_mutex
;
368 mutex_unlock(&indio_dev
->mlock
);
373 static int ad799x_read_event_config(struct iio_dev
*indio_dev
,
374 const struct iio_chan_spec
*chan
,
375 enum iio_event_type type
,
376 enum iio_event_direction dir
)
378 struct ad799x_state
*st
= iio_priv(indio_dev
);
380 if (!(st
->config
& AD7998_ALERT_EN
))
383 if ((st
->config
>> AD799X_CHANNEL_SHIFT
) & BIT(chan
->scan_index
))
389 static int ad799x_write_event_config(struct iio_dev
*indio_dev
,
390 const struct iio_chan_spec
*chan
,
391 enum iio_event_type type
,
392 enum iio_event_direction dir
,
395 struct ad799x_state
*st
= iio_priv(indio_dev
);
398 mutex_lock(&indio_dev
->mlock
);
399 if (iio_buffer_enabled(indio_dev
)) {
405 st
->config
|= BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
;
407 st
->config
&= ~(BIT(chan
->scan_index
) << AD799X_CHANNEL_SHIFT
);
409 if (st
->config
>> AD799X_CHANNEL_SHIFT
)
410 st
->config
|= AD7998_ALERT_EN
;
412 st
->config
&= ~AD7998_ALERT_EN
;
414 ret
= ad799x_write_config(st
, st
->config
);
417 mutex_unlock(&indio_dev
->mlock
);
422 static unsigned int ad799x_threshold_reg(const struct iio_chan_spec
*chan
,
423 enum iio_event_direction dir
,
424 enum iio_event_info info
)
427 case IIO_EV_INFO_VALUE
:
428 if (dir
== IIO_EV_DIR_FALLING
)
429 return AD7998_DATALOW_REG(chan
->channel
);
431 return AD7998_DATAHIGH_REG(chan
->channel
);
432 case IIO_EV_INFO_HYSTERESIS
:
433 return AD7998_HYST_REG(chan
->channel
);
441 static int ad799x_write_event_value(struct iio_dev
*indio_dev
,
442 const struct iio_chan_spec
*chan
,
443 enum iio_event_type type
,
444 enum iio_event_direction dir
,
445 enum iio_event_info info
,
449 struct ad799x_state
*st
= iio_priv(indio_dev
);
451 if (val
< 0 || val
> GENMASK(chan
->scan_type
.realbits
- 1, 0))
454 mutex_lock(&indio_dev
->mlock
);
455 ret
= i2c_smbus_write_word_swapped(st
->client
,
456 ad799x_threshold_reg(chan
, dir
, info
),
457 val
<< chan
->scan_type
.shift
);
458 mutex_unlock(&indio_dev
->mlock
);
463 static int ad799x_read_event_value(struct iio_dev
*indio_dev
,
464 const struct iio_chan_spec
*chan
,
465 enum iio_event_type type
,
466 enum iio_event_direction dir
,
467 enum iio_event_info info
,
471 struct ad799x_state
*st
= iio_priv(indio_dev
);
473 mutex_lock(&indio_dev
->mlock
);
474 ret
= i2c_smbus_read_word_swapped(st
->client
,
475 ad799x_threshold_reg(chan
, dir
, info
));
476 mutex_unlock(&indio_dev
->mlock
);
479 *val
= (ret
>> chan
->scan_type
.shift
) &
480 GENMASK(chan
->scan_type
.realbits
- 1, 0);
485 static irqreturn_t
ad799x_event_handler(int irq
, void *private)
487 struct iio_dev
*indio_dev
= private;
488 struct ad799x_state
*st
= iio_priv(private);
491 ret
= i2c_smbus_read_byte_data(st
->client
, AD7998_ALERT_STAT_REG
);
495 if (i2c_smbus_write_byte_data(st
->client
, AD7998_ALERT_STAT_REG
,
496 AD7998_ALERT_STAT_CLEAR
) < 0)
499 for (i
= 0; i
< 8; i
++) {
501 iio_push_event(indio_dev
,
503 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
507 IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE
,
518 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR
| S_IRUGO
,
519 ad799x_read_frequency
,
520 ad799x_write_frequency
);
521 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
523 static struct attribute
*ad799x_event_attributes
[] = {
524 &iio_dev_attr_sampling_frequency
.dev_attr
.attr
,
525 &iio_const_attr_sampling_frequency_available
.dev_attr
.attr
,
529 static struct attribute_group ad799x_event_attrs_group
= {
530 .attrs
= ad799x_event_attributes
,
533 static const struct iio_info ad7991_info
= {
534 .read_raw
= &ad799x_read_raw
,
535 .driver_module
= THIS_MODULE
,
538 static const struct iio_info ad7993_4_7_8_noirq_info
= {
539 .read_raw
= &ad799x_read_raw
,
540 .driver_module
= THIS_MODULE
,
541 .update_scan_mode
= ad799x_update_scan_mode
,
544 static const struct iio_info ad7993_4_7_8_irq_info
= {
545 .read_raw
= &ad799x_read_raw
,
546 .event_attrs
= &ad799x_event_attrs_group
,
547 .read_event_config
= &ad799x_read_event_config
,
548 .write_event_config
= &ad799x_write_event_config
,
549 .read_event_value
= &ad799x_read_event_value
,
550 .write_event_value
= &ad799x_write_event_value
,
551 .driver_module
= THIS_MODULE
,
552 .update_scan_mode
= ad799x_update_scan_mode
,
555 static const struct iio_event_spec ad799x_events
[] = {
557 .type
= IIO_EV_TYPE_THRESH
,
558 .dir
= IIO_EV_DIR_RISING
,
559 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
560 BIT(IIO_EV_INFO_ENABLE
),
562 .type
= IIO_EV_TYPE_THRESH
,
563 .dir
= IIO_EV_DIR_FALLING
,
564 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
565 BIT(IIO_EV_INFO_ENABLE
),
567 .type
= IIO_EV_TYPE_THRESH
,
568 .dir
= IIO_EV_DIR_EITHER
,
569 .mask_separate
= BIT(IIO_EV_INFO_HYSTERESIS
),
573 #define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
574 .type = IIO_VOLTAGE, \
576 .channel = (_index), \
577 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
578 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
579 .scan_index = (_index), \
582 .realbits = (_realbits), \
584 .shift = 12 - (_realbits), \
585 .endianness = IIO_BE, \
587 .event_spec = _ev_spec, \
588 .num_event_specs = _num_ev_spec, \
591 #define AD799X_CHANNEL(_index, _realbits) \
592 _AD799X_CHANNEL(_index, _realbits, NULL, 0)
594 #define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
595 _AD799X_CHANNEL(_index, _realbits, ad799x_events, \
596 ARRAY_SIZE(ad799x_events))
598 static const struct ad799x_chip_info ad799x_chip_info_tbl
[] = {
603 AD799X_CHANNEL(0, 12),
604 AD799X_CHANNEL(1, 12),
605 AD799X_CHANNEL(2, 12),
606 AD799X_CHANNEL(3, 12),
607 IIO_CHAN_SOFT_TIMESTAMP(4),
609 .info
= &ad7991_info
,
616 AD799X_CHANNEL(0, 10),
617 AD799X_CHANNEL(1, 10),
618 AD799X_CHANNEL(2, 10),
619 AD799X_CHANNEL(3, 10),
620 IIO_CHAN_SOFT_TIMESTAMP(4),
622 .info
= &ad7991_info
,
629 AD799X_CHANNEL(0, 8),
630 AD799X_CHANNEL(1, 8),
631 AD799X_CHANNEL(2, 8),
632 AD799X_CHANNEL(3, 8),
633 IIO_CHAN_SOFT_TIMESTAMP(4),
635 .info
= &ad7991_info
,
642 AD799X_CHANNEL(0, 12),
643 AD799X_CHANNEL(1, 12),
644 IIO_CHAN_SOFT_TIMESTAMP(3),
646 .info
= &ad7993_4_7_8_noirq_info
,
650 AD799X_CHANNEL_WITH_EVENTS(0, 12),
651 AD799X_CHANNEL_WITH_EVENTS(1, 12),
652 IIO_CHAN_SOFT_TIMESTAMP(3),
654 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
655 .info
= &ad7993_4_7_8_irq_info
,
662 AD799X_CHANNEL(0, 10),
663 AD799X_CHANNEL(1, 10),
664 AD799X_CHANNEL(2, 10),
665 AD799X_CHANNEL(3, 10),
666 IIO_CHAN_SOFT_TIMESTAMP(4),
668 .info
= &ad7993_4_7_8_noirq_info
,
672 AD799X_CHANNEL_WITH_EVENTS(0, 10),
673 AD799X_CHANNEL_WITH_EVENTS(1, 10),
674 AD799X_CHANNEL_WITH_EVENTS(2, 10),
675 AD799X_CHANNEL_WITH_EVENTS(3, 10),
676 IIO_CHAN_SOFT_TIMESTAMP(4),
678 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
679 .info
= &ad7993_4_7_8_irq_info
,
686 AD799X_CHANNEL(0, 12),
687 AD799X_CHANNEL(1, 12),
688 AD799X_CHANNEL(2, 12),
689 AD799X_CHANNEL(3, 12),
690 IIO_CHAN_SOFT_TIMESTAMP(4),
692 .info
= &ad7993_4_7_8_noirq_info
,
696 AD799X_CHANNEL_WITH_EVENTS(0, 12),
697 AD799X_CHANNEL_WITH_EVENTS(1, 12),
698 AD799X_CHANNEL_WITH_EVENTS(2, 12),
699 AD799X_CHANNEL_WITH_EVENTS(3, 12),
700 IIO_CHAN_SOFT_TIMESTAMP(4),
702 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
703 .info
= &ad7993_4_7_8_irq_info
,
710 AD799X_CHANNEL(0, 10),
711 AD799X_CHANNEL(1, 10),
712 AD799X_CHANNEL(2, 10),
713 AD799X_CHANNEL(3, 10),
714 AD799X_CHANNEL(4, 10),
715 AD799X_CHANNEL(5, 10),
716 AD799X_CHANNEL(6, 10),
717 AD799X_CHANNEL(7, 10),
718 IIO_CHAN_SOFT_TIMESTAMP(8),
720 .info
= &ad7993_4_7_8_noirq_info
,
724 AD799X_CHANNEL_WITH_EVENTS(0, 10),
725 AD799X_CHANNEL_WITH_EVENTS(1, 10),
726 AD799X_CHANNEL_WITH_EVENTS(2, 10),
727 AD799X_CHANNEL_WITH_EVENTS(3, 10),
728 AD799X_CHANNEL(4, 10),
729 AD799X_CHANNEL(5, 10),
730 AD799X_CHANNEL(6, 10),
731 AD799X_CHANNEL(7, 10),
732 IIO_CHAN_SOFT_TIMESTAMP(8),
734 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
735 .info
= &ad7993_4_7_8_irq_info
,
742 AD799X_CHANNEL(0, 12),
743 AD799X_CHANNEL(1, 12),
744 AD799X_CHANNEL(2, 12),
745 AD799X_CHANNEL(3, 12),
746 AD799X_CHANNEL(4, 12),
747 AD799X_CHANNEL(5, 12),
748 AD799X_CHANNEL(6, 12),
749 AD799X_CHANNEL(7, 12),
750 IIO_CHAN_SOFT_TIMESTAMP(8),
752 .info
= &ad7993_4_7_8_noirq_info
,
756 AD799X_CHANNEL_WITH_EVENTS(0, 12),
757 AD799X_CHANNEL_WITH_EVENTS(1, 12),
758 AD799X_CHANNEL_WITH_EVENTS(2, 12),
759 AD799X_CHANNEL_WITH_EVENTS(3, 12),
760 AD799X_CHANNEL(4, 12),
761 AD799X_CHANNEL(5, 12),
762 AD799X_CHANNEL(6, 12),
763 AD799X_CHANNEL(7, 12),
764 IIO_CHAN_SOFT_TIMESTAMP(8),
766 .default_config
= AD7998_ALERT_EN
| AD7998_BUSY_ALERT
,
767 .info
= &ad7993_4_7_8_irq_info
,
772 static int ad799x_probe(struct i2c_client
*client
,
773 const struct i2c_device_id
*id
)
776 struct ad799x_state
*st
;
777 struct iio_dev
*indio_dev
;
778 const struct ad799x_chip_info
*chip_info
=
779 &ad799x_chip_info_tbl
[id
->driver_data
];
781 indio_dev
= devm_iio_device_alloc(&client
->dev
, sizeof(*st
));
782 if (indio_dev
== NULL
)
785 st
= iio_priv(indio_dev
);
786 /* this is only used for device removal purposes */
787 i2c_set_clientdata(client
, indio_dev
);
789 st
->id
= id
->driver_data
;
790 if (client
->irq
> 0 && chip_info
->irq_config
.info
)
791 st
->chip_config
= &chip_info
->irq_config
;
793 st
->chip_config
= &chip_info
->noirq_config
;
795 /* TODO: Add pdata options for filtering and bit delay */
797 st
->reg
= devm_regulator_get(&client
->dev
, "vcc");
799 return PTR_ERR(st
->reg
);
800 ret
= regulator_enable(st
->reg
);
803 st
->vref
= devm_regulator_get(&client
->dev
, "vref");
804 if (IS_ERR(st
->vref
)) {
805 ret
= PTR_ERR(st
->vref
);
806 goto error_disable_reg
;
808 ret
= regulator_enable(st
->vref
);
810 goto error_disable_reg
;
814 indio_dev
->dev
.parent
= &client
->dev
;
815 indio_dev
->name
= id
->name
;
816 indio_dev
->info
= st
->chip_config
->info
;
818 indio_dev
->modes
= INDIO_DIRECT_MODE
;
819 indio_dev
->channels
= st
->chip_config
->channel
;
820 indio_dev
->num_channels
= chip_info
->num_channels
;
822 ret
= ad799x_write_config(st
, st
->chip_config
->default_config
);
824 goto error_disable_reg
;
825 ret
= ad799x_read_config(st
);
827 goto error_disable_reg
;
830 ret
= iio_triggered_buffer_setup(indio_dev
, NULL
,
831 &ad799x_trigger_handler
, NULL
);
833 goto error_disable_vref
;
835 if (client
->irq
> 0) {
836 ret
= devm_request_threaded_irq(&client
->dev
,
839 ad799x_event_handler
,
840 IRQF_TRIGGER_FALLING
|
845 goto error_cleanup_ring
;
847 ret
= iio_device_register(indio_dev
);
849 goto error_cleanup_ring
;
854 iio_triggered_buffer_cleanup(indio_dev
);
856 regulator_disable(st
->vref
);
858 regulator_disable(st
->reg
);
863 static int ad799x_remove(struct i2c_client
*client
)
865 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
866 struct ad799x_state
*st
= iio_priv(indio_dev
);
868 iio_device_unregister(indio_dev
);
870 iio_triggered_buffer_cleanup(indio_dev
);
871 regulator_disable(st
->vref
);
872 regulator_disable(st
->reg
);
878 static const struct i2c_device_id ad799x_id
[] = {
879 { "ad7991", ad7991
},
880 { "ad7995", ad7995
},
881 { "ad7999", ad7999
},
882 { "ad7992", ad7992
},
883 { "ad7993", ad7993
},
884 { "ad7994", ad7994
},
885 { "ad7997", ad7997
},
886 { "ad7998", ad7998
},
890 MODULE_DEVICE_TABLE(i2c
, ad799x_id
);
892 static struct i2c_driver ad799x_driver
= {
896 .probe
= ad799x_probe
,
897 .remove
= ad799x_remove
,
898 .id_table
= ad799x_id
,
900 module_i2c_driver(ad799x_driver
);
902 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
903 MODULE_DESCRIPTION("Analog Devices AD799x ADC");
904 MODULE_LICENSE("GPL v2");