aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-09-28 05:31:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-10-01 11:19:12 -0400
commit488a21827a257b735571468632e9f677b13bdddd (patch)
tree2ddaf1b0bf51411bfb9fa37ed1bbc8160792c208
parentd88c89db9a7550c2ed6551f73b6702faee190434 (diff)
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>
-rw-r--r--drivers/iio/adc/ad7791.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
index c20203577d2d..c19f8fd1b4b7 100644
--- a/drivers/iio/adc/ad7791.c
+++ b/drivers/iio/adc/ad7791.c
@@ -202,7 +202,6 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
202{ 202{
203 struct ad7791_state *st = iio_priv(indio_dev); 203 struct ad7791_state *st = iio_priv(indio_dev);
204 bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR); 204 bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR);
205 unsigned long long scale_pv;
206 205
207 switch (info) { 206 switch (info) {
208 case IIO_CHAN_INFO_RAW: 207 case IIO_CHAN_INFO_RAW:
@@ -220,23 +219,26 @@ static int ad7791_read_raw(struct iio_dev *indio_dev,
220 case IIO_CHAN_INFO_SCALE: 219 case IIO_CHAN_INFO_SCALE:
221 /* The monitor channel uses an internal reference. */ 220 /* The monitor channel uses an internal reference. */
222 if (chan->address == AD7791_CH_AVDD_MONITOR) { 221 if (chan->address == AD7791_CH_AVDD_MONITOR) {
223 scale_pv = 5850000000000ULL; 222 /*
223 * The signal is attenuated by a factor of 5 and
224 * compared against a 1.17V internal reference.
225 */
226 *val = 1170 * 5;
224 } else { 227 } else {
225 int voltage_uv; 228 int voltage_uv;
226 229
227 voltage_uv = regulator_get_voltage(st->reg); 230 voltage_uv = regulator_get_voltage(st->reg);
228 if (voltage_uv < 0) 231 if (voltage_uv < 0)
229 return voltage_uv; 232 return voltage_uv;
230 scale_pv = (unsigned long long)voltage_uv * 1000000; 233
234 *val = voltage_uv / 1000;
231 } 235 }
232 if (unipolar) 236 if (unipolar)
233 scale_pv >>= chan->scan_type.realbits; 237 *val2 = chan->scan_type.realbits;
234 else 238 else
235 scale_pv >>= chan->scan_type.realbits - 1; 239 *val2 = chan->scan_type.realbits - 1;
236 *val2 = do_div(scale_pv, 1000000000);
237 *val = scale_pv;
238 240
239 return IIO_VAL_INT_PLUS_NANO; 241 return IIO_VAL_FRACTIONAL_LOG2;
240 } 242 }
241 243
242 return -EINVAL; 244 return -EINVAL;