mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-13 00:29:50 +00:00
iio:ad7791: Report scale as fractional value
Move the complexity of calculating the fixed point scale to the core. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
d88c89db9a
commit
488a21827a
@ -202,7 +202,6 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
|
|||||||
{
|
{
|
||||||
struct ad7791_state *st = iio_priv(indio_dev);
|
struct ad7791_state *st = iio_priv(indio_dev);
|
||||||
bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR);
|
bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR);
|
||||||
unsigned long long scale_pv;
|
|
||||||
|
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
@ -220,23 +219,26 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
|
|||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
/* The monitor channel uses an internal reference. */
|
/* The monitor channel uses an internal reference. */
|
||||||
if (chan->address == AD7791_CH_AVDD_MONITOR) {
|
if (chan->address == AD7791_CH_AVDD_MONITOR) {
|
||||||
scale_pv = 5850000000000ULL;
|
/*
|
||||||
|
* The signal is attenuated by a factor of 5 and
|
||||||
|
* compared against a 1.17V internal reference.
|
||||||
|
*/
|
||||||
|
*val = 1170 * 5;
|
||||||
} else {
|
} else {
|
||||||
int voltage_uv;
|
int voltage_uv;
|
||||||
|
|
||||||
voltage_uv = regulator_get_voltage(st->reg);
|
voltage_uv = regulator_get_voltage(st->reg);
|
||||||
if (voltage_uv < 0)
|
if (voltage_uv < 0)
|
||||||
return voltage_uv;
|
return voltage_uv;
|
||||||
scale_pv = (unsigned long long)voltage_uv * 1000000;
|
|
||||||
|
*val = voltage_uv / 1000;
|
||||||
}
|
}
|
||||||
if (unipolar)
|
if (unipolar)
|
||||||
scale_pv >>= chan->scan_type.realbits;
|
*val2 = chan->scan_type.realbits;
|
||||||
else
|
else
|
||||||
scale_pv >>= chan->scan_type.realbits - 1;
|
*val2 = chan->scan_type.realbits - 1;
|
||||||
*val2 = do_div(scale_pv, 1000000000);
|
|
||||||
*val = scale_pv;
|
|
||||||
|
|
||||||
return IIO_VAL_INT_PLUS_NANO;
|
return IIO_VAL_FRACTIONAL_LOG2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user