Commit 8eb5976a authored by Marcelo Schmitt's avatar Marcelo Schmitt Committed by Jonathan Cameron

iio: adc: ad7091r: Add chip_info callback to get conversion result channel

AD7091R-5 and AD7091R-2/-4/-8 have slightly different register field
layout and due to that require different masks for getting the index of
the channel associated with each read.
Add a callback function so the base driver can get correct channel ID
for each chip variant.
Signed-off-by: default avatarMarcelo Schmitt <marcelo.schmitt@analog.com>
Link: https://lore.kernel.org/r/1f7a40b4839b3a1c3f1a0654a1b329bea870feb6.1703013352.git.marcelo.schmitt1@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7e3ebda3
......@@ -16,10 +16,6 @@
#include "ad7091r-base.h"
/* AD7091R_REG_RESULT */
#define AD7091R_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
#define AD7091R_REG_RESULT_CONV_RESULT(x) ((x) & 0xfff)
const struct iio_event_spec ad7091r_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
......@@ -74,7 +70,7 @@ static int ad7091r_read_one(struct iio_dev *iio_dev,
if (ret)
return ret;
if (AD7091R_REG_RESULT_CH_ID(val) != channel)
if (st->chip_info->reg_result_chan_id(val) != channel)
return -EIO;
*read_val = AD7091R_REG_RESULT_CONV_RESULT(val);
......
......@@ -18,6 +18,11 @@
#define AD7091R_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
#define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
/* AD7091R_REG_RESULT */
#define AD7091R5_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
#define AD7091R8_REG_RESULT_CH_ID(x) (((x) >> 13) & 0x7)
#define AD7091R_REG_RESULT_CONV_RESULT(x) ((x) & 0xfff)
/* AD7091R_REG_CONF */
#define AD7091R_REG_CONF_INT_VREF BIT(0)
#define AD7091R_REG_CONF_ALERT_EN BIT(4)
......@@ -65,6 +70,7 @@ struct ad7091r_chip_info {
unsigned int num_channels;
const struct iio_chan_spec *channels;
unsigned int vref_mV;
unsigned int (*reg_result_chan_id)(unsigned int val);
int (*set_mode)(struct ad7091r_state *st, enum ad7091r_mode mode);
};
......
......@@ -54,11 +54,17 @@ static int ad7091r5_set_mode(struct ad7091r_state *st, enum ad7091r_mode mode)
return 0;
}
static unsigned int ad7091r5_reg_result_chan_id(unsigned int val)
{
return AD7091R5_REG_RESULT_CH_ID(val);
}
static const struct ad7091r_chip_info ad7091r5_chip_info_irq = {
.name = "ad7091r-5",
.channels = ad7091r5_channels_irq,
.num_channels = ARRAY_SIZE(ad7091r5_channels_irq),
.vref_mV = 2500,
.reg_result_chan_id = &ad7091r5_reg_result_chan_id,
.set_mode = &ad7091r5_set_mode,
};
......@@ -67,6 +73,7 @@ static const struct ad7091r_chip_info ad7091r5_chip_info_noirq = {
.channels = ad7091r5_channels_noirq,
.num_channels = ARRAY_SIZE(ad7091r5_channels_noirq),
.vref_mV = 2500,
.reg_result_chan_id = &ad7091r5_reg_result_chan_id,
.set_mode = &ad7091r5_set_mode,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment