2019-11-15 06:57:20 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* AD7091R5 Analog to Digital converter driver
|
|
|
|
*
|
|
|
|
* Copyright 2014-2019 Analog Devices Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
|
|
|
|
#include "ad7091r-base.h"
|
|
|
|
|
|
|
|
static const struct iio_chan_spec ad7091r5_channels_irq[] = {
|
2023-12-19 13:26:01 -07:00
|
|
|
AD7091R_CHANNEL(0, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
|
|
|
|
AD7091R_CHANNEL(1, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
|
|
|
|
AD7091R_CHANNEL(2, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
|
|
|
|
AD7091R_CHANNEL(3, 12, ad7091r_events, ARRAY_SIZE(ad7091r_events)),
|
2019-11-15 06:57:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct iio_chan_spec ad7091r5_channels_noirq[] = {
|
|
|
|
AD7091R_CHANNEL(0, 12, NULL, 0),
|
|
|
|
AD7091R_CHANNEL(1, 12, NULL, 0),
|
|
|
|
AD7091R_CHANNEL(2, 12, NULL, 0),
|
|
|
|
AD7091R_CHANNEL(3, 12, NULL, 0),
|
|
|
|
};
|
|
|
|
|
2023-12-19 13:28:45 -07:00
|
|
|
static int ad7091r5_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
|
|
|
|
{
|
|
|
|
int ret, conf;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case AD7091R_MODE_SAMPLE:
|
|
|
|
conf = 0;
|
|
|
|
break;
|
|
|
|
case AD7091R_MODE_COMMAND:
|
|
|
|
conf = AD7091R_REG_CONF_CMD;
|
|
|
|
break;
|
|
|
|
case AD7091R_MODE_AUTOCYCLE:
|
|
|
|
conf = AD7091R_REG_CONF_AUTO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
|
|
|
|
AD7091R_REG_CONF_MODE_MASK, conf);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
st->mode = mode;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-19 13:29:30 -07:00
|
|
|
static unsigned int ad7091r5_reg_result_chan_id(unsigned int val)
|
|
|
|
{
|
|
|
|
return AD7091R5_REG_RESULT_CH_ID(val);
|
|
|
|
}
|
|
|
|
|
2019-11-15 06:57:20 -07:00
|
|
|
static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
|
2023-12-19 13:27:36 -07:00
|
|
|
.name = "ad7091r-5",
|
2019-11-15 06:57:20 -07:00
|
|
|
.channels = ad7091r5_channels_irq,
|
|
|
|
.num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
|
2019-11-15 06:57:21 -07:00
|
|
|
.vref_mV = 2500,
|
2023-12-19 13:29:30 -07:00
|
|
|
.reg_result_chan_id = &ad7091r5_reg_result_chan_id,
|
2023-12-19 13:28:45 -07:00
|
|
|
.set_mode = &ad7091r5_set_mode,
|
2019-11-15 06:57:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
|
2023-12-19 13:27:36 -07:00
|
|
|
.name = "ad7091r-5",
|
2019-11-15 06:57:20 -07:00
|
|
|
.channels = ad7091r5_channels_noirq,
|
|
|
|
.num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
|
2019-11-15 06:57:21 -07:00
|
|
|
.vref_mV = 2500,
|
2023-12-19 13:29:30 -07:00
|
|
|
.reg_result_chan_id = &ad7091r5_reg_result_chan_id,
|
2023-12-19 13:28:45 -07:00
|
|
|
.set_mode = &ad7091r5_set_mode,
|
2019-11-15 06:57:20 -07:00
|
|
|
};
|
|
|
|
|
2023-12-19 13:27:36 -07:00
|
|
|
static const struct regmap_config ad7091r_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
|
|
|
.writeable_reg = ad7091r_writeable_reg,
|
|
|
|
.volatile_reg = ad7091r_volatile_reg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ad7091r5_regmap_init(struct ad7091r_state *st,
|
|
|
|
const struct regmap_config *regmap_conf)
|
|
|
|
{
|
|
|
|
struct i2c_client *i2c = container_of(st->dev, struct i2c_client, dev);
|
|
|
|
|
|
|
|
st->map = devm_regmap_init_i2c(i2c, regmap_conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ad7091r_init_info ad7091r5_init_info = {
|
|
|
|
.info_irq = &ad7091r5_chip_info_irq,
|
|
|
|
.info_no_irq = &ad7091r5_chip_info_noirq,
|
|
|
|
.regmap_config = &ad7091r_regmap_config,
|
|
|
|
.init_adc_regmap = &ad7091r5_regmap_init
|
|
|
|
};
|
|
|
|
|
2022-11-18 15:36:33 -07:00
|
|
|
static int ad7091r5_i2c_probe(struct i2c_client *i2c)
|
2019-11-15 06:57:20 -07:00
|
|
|
{
|
2023-12-19 13:27:36 -07:00
|
|
|
const struct ad7091r_init_info *init_info;
|
2019-11-15 06:57:20 -07:00
|
|
|
|
2023-12-19 13:27:36 -07:00
|
|
|
init_info = i2c_get_match_data(i2c);
|
|
|
|
if (!init_info)
|
|
|
|
return -EINVAL;
|
2019-11-15 06:57:20 -07:00
|
|
|
|
2023-12-19 13:28:05 -07:00
|
|
|
return ad7091r_probe(&i2c->dev, init_info, i2c->irq);
|
2019-11-15 06:57:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id ad7091r5_dt_ids[] = {
|
2023-12-19 13:27:36 -07:00
|
|
|
{ .compatible = "adi,ad7091r5", .data = &ad7091r5_init_info },
|
2024-08-18 11:09:12 -07:00
|
|
|
{ }
|
2019-11-15 06:57:20 -07:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, ad7091r5_dt_ids);
|
|
|
|
|
|
|
|
static const struct i2c_device_id ad7091r5_i2c_ids[] = {
|
2024-08-18 11:09:12 -07:00
|
|
|
{ "ad7091r5", (kernel_ulong_t)&ad7091r5_init_info },
|
|
|
|
{ }
|
2019-11-15 06:57:20 -07:00
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, ad7091r5_i2c_ids);
|
|
|
|
|
|
|
|
static struct i2c_driver ad7091r5_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ad7091r5",
|
|
|
|
.of_match_table = ad7091r5_dt_ids,
|
|
|
|
},
|
2023-05-15 13:50:48 -07:00
|
|
|
.probe = ad7091r5_i2c_probe,
|
2019-11-15 06:57:20 -07:00
|
|
|
.id_table = ad7091r5_i2c_ids,
|
|
|
|
};
|
|
|
|
module_i2c_driver(ad7091r5_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Beniamin Bia <beniamin.bia@analog.com>");
|
|
|
|
MODULE_DESCRIPTION("Analog Devices AD7091R5 multi-channel ADC driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2022-01-30 13:56:47 -07:00
|
|
|
MODULE_IMPORT_NS(IIO_AD7091R);
|