0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/i2c.h>
0009 #include <linux/iio/iio.h>
0010 #include <linux/module.h>
0011 #include <linux/regmap.h>
0012
0013 #include "ad7091r-base.h"
0014
0015 static const struct iio_event_spec ad7091r5_events[] = {
0016 {
0017 .type = IIO_EV_TYPE_THRESH,
0018 .dir = IIO_EV_DIR_RISING,
0019 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
0020 BIT(IIO_EV_INFO_ENABLE),
0021 },
0022 {
0023 .type = IIO_EV_TYPE_THRESH,
0024 .dir = IIO_EV_DIR_FALLING,
0025 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
0026 BIT(IIO_EV_INFO_ENABLE),
0027 },
0028 {
0029 .type = IIO_EV_TYPE_THRESH,
0030 .dir = IIO_EV_DIR_EITHER,
0031 .mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
0032 },
0033 };
0034
0035 #define AD7091R_CHANNEL(idx, bits, ev, num_ev) { \
0036 .type = IIO_VOLTAGE, \
0037 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
0038 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
0039 .indexed = 1, \
0040 .channel = idx, \
0041 .event_spec = ev, \
0042 .num_event_specs = num_ev, \
0043 .scan_type.storagebits = 16, \
0044 .scan_type.realbits = bits, \
0045 }
0046 static const struct iio_chan_spec ad7091r5_channels_irq[] = {
0047 AD7091R_CHANNEL(0, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
0048 AD7091R_CHANNEL(1, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
0049 AD7091R_CHANNEL(2, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
0050 AD7091R_CHANNEL(3, 12, ad7091r5_events, ARRAY_SIZE(ad7091r5_events)),
0051 };
0052
0053 static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
0054 AD7091R_CHANNEL(0, 12, NULL, 0),
0055 AD7091R_CHANNEL(1, 12, NULL, 0),
0056 AD7091R_CHANNEL(2, 12, NULL, 0),
0057 AD7091R_CHANNEL(3, 12, NULL, 0),
0058 };
0059
0060 static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
0061 .channels = ad7091r5_channels_irq,
0062 .num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
0063 .vref_mV = 2500,
0064 };
0065
0066 static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
0067 .channels = ad7091r5_channels_noirq,
0068 .num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
0069 .vref_mV = 2500,
0070 };
0071
0072 static int ad7091r5_i2c_probe(struct i2c_client *i2c,
0073 const struct i2c_device_id *id)
0074 {
0075 const struct ad7091r_chip_info *chip_info;
0076 struct regmap *map = devm_regmap_init_i2c(i2c, &ad7091r_regmap_config);
0077
0078 if (IS_ERR(map))
0079 return PTR_ERR(map);
0080
0081 if (i2c->irq)
0082 chip_info = &ad7091r5_chip_info_irq;
0083 else
0084 chip_info = &ad7091r5_chip_info_noirq;
0085
0086 return ad7091r_probe(&i2c->dev, id->name, chip_info, map, i2c->irq);
0087 }
0088
0089 static const struct of_device_id ad7091r5_dt_ids[] = {
0090 { .compatible = "adi,ad7091r5" },
0091 {},
0092 };
0093 MODULE_DEVICE_TABLE(of, ad7091r5_dt_ids);
0094
0095 static const struct i2c_device_id ad7091r5_i2c_ids[] = {
0096 {"ad7091r5", 0},
0097 {}
0098 };
0099 MODULE_DEVICE_TABLE(i2c, ad7091r5_i2c_ids);
0100
0101 static struct i2c_driver ad7091r5_driver = {
0102 .driver = {
0103 .name = "ad7091r5",
0104 .of_match_table = ad7091r5_dt_ids,
0105 },
0106 .probe = ad7091r5_i2c_probe,
0107 .id_table = ad7091r5_i2c_ids,
0108 };
0109 module_i2c_driver(ad7091r5_driver);
0110
0111 MODULE_AUTHOR("Beniamin Bia <beniamin.bia@analog.com>");
0112 MODULE_DESCRIPTION("Analog Devices AD7091R5 multi-channel ADC driver");
0113 MODULE_LICENSE("GPL v2");
0114 MODULE_IMPORT_NS(IIO_AD7091R);