diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-09-28 05:31:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-10-01 11:19:09 -0400 |
commit | 4f2c188597858aa215754be7279e91d778502d8e (patch) | |
tree | 452425db1521ed83a8fca3c9b614be6d1f8f4abb /drivers/iio/dac | |
parent | ca3bc8b62634215f899cefde52a31cc6600a686c (diff) |
iio:ad5380: 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>
Diffstat (limited to 'drivers/iio/dac')
-rw-r--r-- | drivers/iio/dac/ad5380.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c index 4c791e66e0d7..a59ff0e7b888 100644 --- a/drivers/iio/dac/ad5380.c +++ b/drivers/iio/dac/ad5380.c | |||
@@ -204,7 +204,6 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, | |||
204 | struct iio_chan_spec const *chan, int *val, int *val2, long info) | 204 | struct iio_chan_spec const *chan, int *val, int *val2, long info) |
205 | { | 205 | { |
206 | struct ad5380_state *st = iio_priv(indio_dev); | 206 | struct ad5380_state *st = iio_priv(indio_dev); |
207 | unsigned long scale_uv; | ||
208 | int ret; | 207 | int ret; |
209 | 208 | ||
210 | switch (info) { | 209 | switch (info) { |
@@ -225,10 +224,9 @@ static int ad5380_read_raw(struct iio_dev *indio_dev, | |||
225 | val -= (1 << chan->scan_type.realbits) / 2; | 224 | val -= (1 << chan->scan_type.realbits) / 2; |
226 | return IIO_VAL_INT; | 225 | return IIO_VAL_INT; |
227 | case IIO_CHAN_INFO_SCALE: | 226 | case IIO_CHAN_INFO_SCALE: |
228 | scale_uv = ((2 * st->vref) >> chan->scan_type.realbits) * 100; | 227 | *val = 2 * st->vref; |
229 | *val = scale_uv / 100000; | 228 | *val2 = chan->scan_type.realbits; |
230 | *val2 = (scale_uv % 100000) * 10; | 229 | return IIO_VAL_FRACTIONAL_LOG2; |
231 | return IIO_VAL_INT_PLUS_MICRO; | ||
232 | default: | 230 | default: |
233 | break; | 231 | break; |
234 | } | 232 | } |
@@ -271,72 +269,72 @@ static const struct ad5380_chip_info ad5380_chip_info_tbl[] = { | |||
271 | [ID_AD5380_3] = { | 269 | [ID_AD5380_3] = { |
272 | .channel_template = AD5380_CHANNEL(14), | 270 | .channel_template = AD5380_CHANNEL(14), |
273 | .num_channels = 40, | 271 | .num_channels = 40, |
274 | .int_vref = 1250000, | 272 | .int_vref = 1250, |
275 | }, | 273 | }, |
276 | [ID_AD5380_5] = { | 274 | [ID_AD5380_5] = { |
277 | .channel_template = AD5380_CHANNEL(14), | 275 | .channel_template = AD5380_CHANNEL(14), |
278 | .num_channels = 40, | 276 | .num_channels = 40, |
279 | .int_vref = 2500000, | 277 | .int_vref = 2500, |
280 | }, | 278 | }, |
281 | [ID_AD5381_3] = { | 279 | [ID_AD5381_3] = { |
282 | .channel_template = AD5380_CHANNEL(12), | 280 | .channel_template = AD5380_CHANNEL(12), |
283 | .num_channels = 16, | 281 | .num_channels = 16, |
284 | .int_vref = 1250000, | 282 | .int_vref = 1250, |
285 | }, | 283 | }, |
286 | [ID_AD5381_5] = { | 284 | [ID_AD5381_5] = { |
287 | .channel_template = AD5380_CHANNEL(12), | 285 | .channel_template = AD5380_CHANNEL(12), |
288 | .num_channels = 16, | 286 | .num_channels = 16, |
289 | .int_vref = 2500000, | 287 | .int_vref = 2500, |
290 | }, | 288 | }, |
291 | [ID_AD5382_3] = { | 289 | [ID_AD5382_3] = { |
292 | .channel_template = AD5380_CHANNEL(14), | 290 | .channel_template = AD5380_CHANNEL(14), |
293 | .num_channels = 32, | 291 | .num_channels = 32, |
294 | .int_vref = 1250000, | 292 | .int_vref = 1250, |
295 | }, | 293 | }, |
296 | [ID_AD5382_5] = { | 294 | [ID_AD5382_5] = { |
297 | .channel_template = AD5380_CHANNEL(14), | 295 | .channel_template = AD5380_CHANNEL(14), |
298 | .num_channels = 32, | 296 | .num_channels = 32, |
299 | .int_vref = 2500000, | 297 | .int_vref = 2500, |
300 | }, | 298 | }, |
301 | [ID_AD5383_3] = { | 299 | [ID_AD5383_3] = { |
302 | .channel_template = AD5380_CHANNEL(12), | 300 | .channel_template = AD5380_CHANNEL(12), |
303 | .num_channels = 32, | 301 | .num_channels = 32, |
304 | .int_vref = 1250000, | 302 | .int_vref = 1250, |
305 | }, | 303 | }, |
306 | [ID_AD5383_5] = { | 304 | [ID_AD5383_5] = { |
307 | .channel_template = AD5380_CHANNEL(12), | 305 | .channel_template = AD5380_CHANNEL(12), |
308 | .num_channels = 32, | 306 | .num_channels = 32, |
309 | .int_vref = 2500000, | 307 | .int_vref = 2500, |
310 | }, | 308 | }, |
311 | [ID_AD5390_3] = { | 309 | [ID_AD5390_3] = { |
312 | .channel_template = AD5380_CHANNEL(14), | 310 | .channel_template = AD5380_CHANNEL(14), |
313 | .num_channels = 16, | 311 | .num_channels = 16, |
314 | .int_vref = 1250000, | 312 | .int_vref = 1250, |
315 | }, | 313 | }, |
316 | [ID_AD5390_5] = { | 314 | [ID_AD5390_5] = { |
317 | .channel_template = AD5380_CHANNEL(14), | 315 | .channel_template = AD5380_CHANNEL(14), |
318 | .num_channels = 16, | 316 | .num_channels = 16, |
319 | .int_vref = 2500000, | 317 | .int_vref = 2500, |
320 | }, | 318 | }, |
321 | [ID_AD5391_3] = { | 319 | [ID_AD5391_3] = { |
322 | .channel_template = AD5380_CHANNEL(12), | 320 | .channel_template = AD5380_CHANNEL(12), |
323 | .num_channels = 16, | 321 | .num_channels = 16, |
324 | .int_vref = 1250000, | 322 | .int_vref = 1250, |
325 | }, | 323 | }, |
326 | [ID_AD5391_5] = { | 324 | [ID_AD5391_5] = { |
327 | .channel_template = AD5380_CHANNEL(12), | 325 | .channel_template = AD5380_CHANNEL(12), |
328 | .num_channels = 16, | 326 | .num_channels = 16, |
329 | .int_vref = 2500000, | 327 | .int_vref = 2500, |
330 | }, | 328 | }, |
331 | [ID_AD5392_3] = { | 329 | [ID_AD5392_3] = { |
332 | .channel_template = AD5380_CHANNEL(14), | 330 | .channel_template = AD5380_CHANNEL(14), |
333 | .num_channels = 8, | 331 | .num_channels = 8, |
334 | .int_vref = 1250000, | 332 | .int_vref = 1250, |
335 | }, | 333 | }, |
336 | [ID_AD5392_5] = { | 334 | [ID_AD5392_5] = { |
337 | .channel_template = AD5380_CHANNEL(14), | 335 | .channel_template = AD5380_CHANNEL(14), |
338 | .num_channels = 8, | 336 | .num_channels = 8, |
339 | .int_vref = 2500000, | 337 | .int_vref = 2500, |
340 | }, | 338 | }, |
341 | }; | 339 | }; |
342 | 340 | ||
@@ -395,7 +393,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, | |||
395 | return ret; | 393 | return ret; |
396 | } | 394 | } |
397 | 395 | ||
398 | if (st->chip_info->int_vref == 2500000) | 396 | if (st->chip_info->int_vref == 2500) |
399 | ctrl |= AD5380_CTRL_INT_VREF_2V5; | 397 | ctrl |= AD5380_CTRL_INT_VREF_2V5; |
400 | 398 | ||
401 | st->vref_reg = devm_regulator_get(dev, "vref"); | 399 | st->vref_reg = devm_regulator_get(dev, "vref"); |
@@ -411,7 +409,7 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, | |||
411 | if (ret < 0) | 409 | if (ret < 0) |
412 | goto error_disable_reg; | 410 | goto error_disable_reg; |
413 | 411 | ||
414 | st->vref = ret; | 412 | st->vref = ret / 1000; |
415 | } else { | 413 | } else { |
416 | st->vref = st->chip_info->int_vref; | 414 | st->vref = st->chip_info->int_vref; |
417 | ctrl |= AD5380_CTRL_INT_VREF_EN; | 415 | ctrl |= AD5380_CTRL_INT_VREF_EN; |