Commit 4f2c1885 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

iio:ad5380: Report scale as fractional value

Move the complexity of calculating the fixed point scale to the core.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent ca3bc8b6
...@@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, ...@@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val, int *val2, long info) struct iio_chan_spec const *chan, int *val, int *val2, long info)
{ {
struct ad5380_state *st = iio_priv(indio_dev); struct ad5380_state *st = iio_priv(indio_dev);
unsigned long scale_uv;
int ret; int ret;
switch (info) { switch (info) {
...@@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, ...@@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev,
val -= (1 << chan->scan_type.realbits) / 2; val -= (1 << chan->scan_type.realbits) / 2;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
scale_uv = ((2 * st->vref) >> chan->scan_type.realbits) * 100; *val = 2 * st->vref;
*val = scale_uv / 100000; *val2 = chan->scan_type.realbits;
*val2 = (scale_uv % 100000) * 10; return IIO_VAL_FRACTIONAL_LOG2;
return IIO_VAL_INT_PLUS_MICRO;
default: default:
break; break;
} }
...@@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { ...@@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = {
[ID_AD5380_3] = { [ID_AD5380_3] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 40, .num_channels = 40,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5380_5] = { [ID_AD5380_5] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 40, .num_channels = 40,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5381_3] = { [ID_AD5381_3] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 16, .num_channels = 16,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5381_5] = { [ID_AD5381_5] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 16, .num_channels = 16,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5382_3] = { [ID_AD5382_3] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 32, .num_channels = 32,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5382_5] = { [ID_AD5382_5] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 32, .num_channels = 32,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5383_3] = { [ID_AD5383_3] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 32, .num_channels = 32,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5383_5] = { [ID_AD5383_5] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 32, .num_channels = 32,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5390_3] = { [ID_AD5390_3] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 16, .num_channels = 16,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5390_5] = { [ID_AD5390_5] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 16, .num_channels = 16,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5391_3] = { [ID_AD5391_3] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 16, .num_channels = 16,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5391_5] = { [ID_AD5391_5] = {
.channel_template = AD5380_CHANNEL(12), .channel_template = AD5380_CHANNEL(12),
.num_channels = 16, .num_channels = 16,
.int_vref = 2500000, .int_vref = 2500,
}, },
[ID_AD5392_3] = { [ID_AD5392_3] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 8, .num_channels = 8,
.int_vref = 1250000, .int_vref = 1250,
}, },
[ID_AD5392_5] = { [ID_AD5392_5] = {
.channel_template = AD5380_CHANNEL(14), .channel_template = AD5380_CHANNEL(14),
.num_channels = 8, .num_channels = 8,
.int_vref = 2500000, .int_vref = 2500,
}, },
}; };
...@@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, ...@@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
return ret; return ret;
} }
if (st->chip_info->int_vref == 2500000) if (st->chip_info->int_vref == 2500)
ctrl |= AD5380_CTRL_INT_VREF_2V5; ctrl |= AD5380_CTRL_INT_VREF_2V5;
st->vref_reg = devm_regulator_get(dev, "vref"); st->vref_reg = devm_regulator_get(dev, "vref");
...@@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, ...@@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap,
if (ret < 0) if (ret < 0)
goto error_disable_reg; goto error_disable_reg;
st->vref = ret; st->vref = ret / 1000;
} else { } else {
st->vref = st->chip_info->int_vref; st->vref = st->chip_info->int_vref;
ctrl |= AD5380_CTRL_INT_VREF_EN; ctrl |= AD5380_CTRL_INT_VREF_EN;
......
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