1 // SPDX-License-Identifier: GPL-2.0
3 * AD7091R5 Analog to Digital converter driver
5 * Copyright 2014-2019 Analog Devices Inc.
9 #include <linux/iio/iio.h>
10 #include <linux/module.h>
11 #include <linux/regmap.h>
13 #include "ad7091r-base.h"
15 static const struct iio_event_spec ad7091r5_events
[] = {
17 .type
= IIO_EV_TYPE_THRESH
,
18 .dir
= IIO_EV_DIR_RISING
,
19 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
20 BIT(IIO_EV_INFO_ENABLE
),
23 .type
= IIO_EV_TYPE_THRESH
,
24 .dir
= IIO_EV_DIR_FALLING
,
25 .mask_separate
= BIT(IIO_EV_INFO_VALUE
) |
26 BIT(IIO_EV_INFO_ENABLE
),
29 .type
= IIO_EV_TYPE_THRESH
,
30 .dir
= IIO_EV_DIR_EITHER
,
31 .mask_separate
= BIT(IIO_EV_INFO_HYSTERESIS
),
35 #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
36 .type = IIO_VOLTAGE, \
37 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
38 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
42 .num_event_specs = num_ev, \
43 .scan_type.storagebits = 16, \
44 .scan_type.realbits = bits, \
46 static const struct iio_chan_spec ad7091r5_channels_irq
[] = {
47 AD7091R_CHANNEL(0, 12, ad7091r5_events
, ARRAY_SIZE(ad7091r5_events
)),
48 AD7091R_CHANNEL(1, 12, ad7091r5_events
, ARRAY_SIZE(ad7091r5_events
)),
49 AD7091R_CHANNEL(2, 12, ad7091r5_events
, ARRAY_SIZE(ad7091r5_events
)),
50 AD7091R_CHANNEL(3, 12, ad7091r5_events
, ARRAY_SIZE(ad7091r5_events
)),
53 static const struct iio_chan_spec ad7091r5_channels_noirq
[] = {
54 AD7091R_CHANNEL(0, 12, NULL
, 0),
55 AD7091R_CHANNEL(1, 12, NULL
, 0),
56 AD7091R_CHANNEL(2, 12, NULL
, 0),
57 AD7091R_CHANNEL(3, 12, NULL
, 0),
60 static const struct ad7091r_chip_info ad7091r5_chip_info_irq
= {
61 .channels
= ad7091r5_channels_irq
,
62 .num_channels
= ARRAY_SIZE(ad7091r5_channels_irq
),
66 static const struct ad7091r_chip_info ad7091r5_chip_info_noirq
= {
67 .channels
= ad7091r5_channels_noirq
,
68 .num_channels
= ARRAY_SIZE(ad7091r5_channels_noirq
),
72 static int ad7091r5_i2c_probe(struct i2c_client
*i2c
,
73 const struct i2c_device_id
*id
)
75 const struct ad7091r_chip_info
*chip_info
;
76 struct regmap
*map
= devm_regmap_init_i2c(i2c
, &ad7091r_regmap_config
);
82 chip_info
= &ad7091r5_chip_info_irq
;
84 chip_info
= &ad7091r5_chip_info_noirq
;
86 return ad7091r_probe(&i2c
->dev
, id
->name
, chip_info
, map
, i2c
->irq
);
89 static const struct of_device_id ad7091r5_dt_ids
[] = {
90 { .compatible
= "adi,ad7091r5" },
93 MODULE_DEVICE_TABLE(of
, ad7091r5_dt_ids
);
95 static const struct i2c_device_id ad7091r5_i2c_ids
[] = {
99 MODULE_DEVICE_TABLE(i2c
, ad7091r5_i2c_ids
);
101 static struct i2c_driver ad7091r5_driver
= {
104 .of_match_table
= ad7091r5_dt_ids
,
106 .probe
= ad7091r5_i2c_probe
,
107 .id_table
= ad7091r5_i2c_ids
,
109 module_i2c_driver(ad7091r5_driver
);
111 MODULE_AUTHOR("Beniamin Bia <beniamin.bia@analog.com>");
112 MODULE_DESCRIPTION("Analog Devices AD7091R5 multi-channel ADC driver");
113 MODULE_LICENSE("GPL v2");