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 #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
16 .type = IIO_VOLTAGE, \
17 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
18 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
22 .num_event_specs = num_ev, \
23 .scan_type.storagebits = 16, \
24 .scan_type.realbits = bits, \
26 static const struct iio_chan_spec ad7091r5_channels_irq[] = {
27 AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
28 AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
29 AD7091R_CHANNEL(2, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
30 AD7091R_CHANNEL(3, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
33 static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
34 AD7091R_CHANNEL(0, 12, NULL, 0),
35 AD7091R_CHANNEL(1, 12, NULL, 0),
36 AD7091R_CHANNEL(2, 12, NULL, 0),
37 AD7091R_CHANNEL(3, 12, NULL, 0),
40 static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
41 .channels = ad7091r5_channels_irq,
42 .num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
46 static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
47 .channels = ad7091r5_channels_noirq,
48 .num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
52 static int ad7091r5_i2c_probe(struct i2c_client *i2c)
54 const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
55 const struct ad7091r_chip_info *chip_info;
56 struct regmap *map = devm_regmap_init_i2c(i2c, &ad7091r_regmap_config);
62 chip_info = &ad7091r5_chip_info_irq;
64 chip_info = &ad7091r5_chip_info_noirq;
66 return ad7091r_probe(&i2c->dev, id->name, chip_info, map, i2c->irq);
69 static const struct of_device_id ad7091r5_dt_ids[] = {
70 { .compatible = "adi,ad7091r5" },
73 MODULE_DEVICE_TABLE(of, ad7091r5_dt_ids);
75 static const struct i2c_device_id ad7091r5_i2c_ids[] = {
79 MODULE_DEVICE_TABLE(i2c, ad7091r5_i2c_ids);
81 static struct i2c_driver ad7091r5_driver = {
84 .of_match_table = ad7091r5_dt_ids,
86 .probe = ad7091r5_i2c_probe,
87 .id_table = ad7091r5_i2c_ids,
89 module_i2c_driver(ad7091r5_driver);
91 MODULE_AUTHOR("Beniamin Bia <beniamin.bia@analog.com>");
92 MODULE_DESCRIPTION("Analog Devices AD7091R5 multi-channel ADC driver");
93 MODULE_LICENSE("GPL v2");
94 MODULE_IMPORT_NS(IIO_AD7091R);