aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-08-10 12:36:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-08-16 15:24:34 -0400
commit2a9e0662f6779d2074ecaa80ea5753d5f0cf1b93 (patch)
tree616e32f056310a660430609eab899a95cbeacb6a /drivers
parent680f8ea0e85c5c3a7283be99435d6461e8725348 (diff)
staging:iio:ad7793: Fix temperature scale and offset
The temperature channel uses the internal 1.17V reference with 0.81 mv/C. The reported temperature is in Kevlin, so we need to add the Kelvin to Celcius offset when reporting the offset for the temperature channel. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/iio/adc/ad7793.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index 56014a8b687..3c8d1d4c619 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -617,30 +617,37 @@ static int ad7793_read_raw(struct iio_dev *indio_dev,
617 return IIO_VAL_INT_PLUS_NANO; 617 return IIO_VAL_INT_PLUS_NANO;
618 } else { 618 } else {
619 /* 1170mV / 2^23 * 6 */ 619 /* 1170mV / 2^23 * 6 */
620 scale_uv = (1170ULL * 100000000ULL * 6ULL) 620 scale_uv = (1170ULL * 100000000ULL * 6ULL);
621 >> (chan->scan_type.realbits -
622 (unipolar ? 0 : 1));
623 } 621 }
624 break; 622 break;
625 case IIO_TEMP: 623 case IIO_TEMP:
626 /* Always uses unity gain and internal ref */ 624 /* 1170mV / 0.81 mV/C / 2^23 */
627 scale_uv = (2500ULL * 100000000ULL) 625 scale_uv = 1444444444444ULL;
628 >> (chan->scan_type.realbits -
629 (unipolar ? 0 : 1));
630 break; 626 break;
631 default: 627 default:
632 return -EINVAL; 628 return -EINVAL;
633 } 629 }
634 630
635 *val2 = do_div(scale_uv, 100000000) * 10; 631 scale_uv >>= (chan->scan_type.realbits - (unipolar ? 0 : 1));
636 *val = scale_uv; 632 *val = 0;
637 633 *val2 = scale_uv;
638 return IIO_VAL_INT_PLUS_NANO; 634 return IIO_VAL_INT_PLUS_NANO;
639 case IIO_CHAN_INFO_OFFSET: 635 case IIO_CHAN_INFO_OFFSET:
640 if (!unipolar) 636 if (!unipolar)
641 *val -= (1 << (chan->scan_type.realbits - 1)); 637 *val = -(1 << (chan->scan_type.realbits - 1));
642 else 638 else
643 *val = 0; 639 *val = 0;
640
641 /* Kelvin to Celsius */
642 if (chan->type == IIO_TEMP) {
643 unsigned long long offset;
644 unsigned int shift;
645
646 shift = chan->scan_type.realbits - (unipolar ? 0 : 1);
647 offset = 273ULL << shift;
648 do_div(offset, 1444);
649 *val -= offset;
650 }
644 return IIO_VAL_INT; 651 return IIO_VAL_INT;
645 } 652 }
646 return -EINVAL; 653 return -EINVAL;