aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
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:37 -0400
commit4fcbcf95b775acc430742a09fb3334dce08b6c10 (patch)
tree4bf7af6363578ea6bd1e94bf8615d4f422a7f836 /drivers/staging
parent58cdff6ee71b4ea00a6b822a52ebf9ceb0b6a7d5 (diff)
staging:iio:ad7192: Report offset and scale for temperature channel
The temperature channel reports values in degree Kelvin with sensitivity of 5630 codes per degree. If the chip is configured in bipolar mode there is an additional binary offset of 0x800000 and the sensitivity is divided by two. Currently the driver does the mapping from the raw value to degree Celsius when doing a manual conversion. This has several disadvantages, the major one being that it does not work for buffered mode, also by doing the division by the sensitivity in the driver the precession of the reported value is needlessly reduced. Furthermore the current calculation only works in bipolar mode and the current scale is of by a factor of 1000. This patch modifies the driver to report correct offset and scale values in both unipolar and bipolar mode and to report the raw temperature value for manual conversions. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/iio/adc/ad7192.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 73483d26a034..095837285f4f 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -798,6 +798,11 @@ static const struct attribute_group ad7195_attribute_group = {
798 .attrs = ad7195_attributes, 798 .attrs = ad7195_attributes,
799}; 799};
800 800
801static unsigned int ad7192_get_temp_scale(bool unipolar)
802{
803 return unipolar ? 2815 * 2 : 2815;
804}
805
801static int ad7192_read_raw(struct iio_dev *indio_dev, 806static int ad7192_read_raw(struct iio_dev *indio_dev,
802 struct iio_chan_spec const *chan, 807 struct iio_chan_spec const *chan,
803 int *val, 808 int *val,
@@ -824,17 +829,6 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
824 *val = (smpl >> chan->scan_type.shift) & 829 *val = (smpl >> chan->scan_type.shift) &
825 ((1 << (chan->scan_type.realbits)) - 1); 830 ((1 << (chan->scan_type.realbits)) - 1);
826 831
827 switch (chan->type) {
828 case IIO_VOLTAGE:
829 break;
830 case IIO_TEMP:
831 *val -= 0x800000;
832 *val /= 2815; /* temp Kelvin */
833 *val -= 273; /* temp Celsius */
834 break;
835 default:
836 return -EINVAL;
837 }
838 return IIO_VAL_INT; 832 return IIO_VAL_INT;
839 833
840 case IIO_CHAN_INFO_SCALE: 834 case IIO_CHAN_INFO_SCALE:
@@ -846,16 +840,20 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
846 mutex_unlock(&indio_dev->mlock); 840 mutex_unlock(&indio_dev->mlock);
847 return IIO_VAL_INT_PLUS_NANO; 841 return IIO_VAL_INT_PLUS_NANO;
848 case IIO_TEMP: 842 case IIO_TEMP:
849 *val = 1000; 843 *val = 0;
850 return IIO_VAL_INT; 844 *val2 = 1000000000 / ad7192_get_temp_scale(unipolar);
845 return IIO_VAL_INT_PLUS_NANO;
851 default: 846 default:
852 return -EINVAL; 847 return -EINVAL;
853 } 848 }
854 case IIO_CHAN_INFO_OFFSET: 849 case IIO_CHAN_INFO_OFFSET:
855 if (!unipolar) 850 if (!unipolar)
856 *val -= (1 << (chan->scan_type.realbits - 1)); 851 *val = -(1 << (chan->scan_type.realbits - 1));
857 else 852 else
858 *val = 0; 853 *val = 0;
854 /* Kelvin to Celsius */
855 if (chan->type == IIO_TEMP)
856 *val -= 273 * ad7192_get_temp_scale(unipolar);
859 return IIO_VAL_INT; 857 return IIO_VAL_INT;
860 } 858 }
861 859