aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanchayan Maity <maitysanchayan@gmail.com>2014-09-19 08:58:00 -0400
committerJonathan Cameron <jic23@kernel.org>2014-09-21 08:25:56 -0400
commit774623ca41280f74f499416fbbba3b1afbdd910e (patch)
tree7805edf5c6f3f4abdde520c64f9410537746e8c5
parentd6be7a02d9cf817d3e3d19167d87e52260620ecd (diff)
iio:adc:vf610-adc: Add temperature sensor support
Vybrid ADC peripheral includes a temperature sensor which is connected to channel number 26. This patch adds support for the sensor. The raw value is read and the temperature calculated in milli degree Celsius, which is returned using IIO_CHAN_INFO_PROCESSED option. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/adc/vf610_adc.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index 4a10ae97dbf2..7ec21b5612ef 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -91,7 +91,7 @@
91#define VF610_ADC_CAL 0x80 91#define VF610_ADC_CAL 0x80
92 92
93/* Other field define */ 93/* Other field define */
94#define VF610_ADC_ADCHC(x) ((x) & 0xF) 94#define VF610_ADC_ADCHC(x) ((x) & 0x1F)
95#define VF610_ADC_AIEN (0x1 << 7) 95#define VF610_ADC_AIEN (0x1 << 7)
96#define VF610_ADC_CONV_DISABLE 0x1F 96#define VF610_ADC_CONV_DISABLE 0x1F
97#define VF610_ADC_HS_COCO0 0x1 97#define VF610_ADC_HS_COCO0 0x1
@@ -153,6 +153,12 @@ struct vf610_adc {
153 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 153 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
154} 154}
155 155
156#define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \
157 .type = (_chan_type), \
158 .channel = (_idx), \
159 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
160}
161
156static const struct iio_chan_spec vf610_adc_iio_channels[] = { 162static const struct iio_chan_spec vf610_adc_iio_channels[] = {
157 VF610_ADC_CHAN(0, IIO_VOLTAGE), 163 VF610_ADC_CHAN(0, IIO_VOLTAGE),
158 VF610_ADC_CHAN(1, IIO_VOLTAGE), 164 VF610_ADC_CHAN(1, IIO_VOLTAGE),
@@ -170,6 +176,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = {
170 VF610_ADC_CHAN(13, IIO_VOLTAGE), 176 VF610_ADC_CHAN(13, IIO_VOLTAGE),
171 VF610_ADC_CHAN(14, IIO_VOLTAGE), 177 VF610_ADC_CHAN(14, IIO_VOLTAGE),
172 VF610_ADC_CHAN(15, IIO_VOLTAGE), 178 VF610_ADC_CHAN(15, IIO_VOLTAGE),
179 VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP),
173 /* sentinel */ 180 /* sentinel */
174}; 181};
175 182
@@ -451,6 +458,7 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
451 458
452 switch (mask) { 459 switch (mask) {
453 case IIO_CHAN_INFO_RAW: 460 case IIO_CHAN_INFO_RAW:
461 case IIO_CHAN_INFO_PROCESSED:
454 mutex_lock(&indio_dev->mlock); 462 mutex_lock(&indio_dev->mlock);
455 reinit_completion(&info->completion); 463 reinit_completion(&info->completion);
456 464
@@ -468,7 +476,23 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
468 return ret; 476 return ret;
469 } 477 }
470 478
471 *val = info->value; 479 switch (chan->type) {
480 case IIO_VOLTAGE:
481 *val = info->value;
482 break;
483 case IIO_TEMP:
484 /*
485 * Calculate in degree Celsius times 1000
486 * Using sensor slope of 1.84 mV/°C and
487 * V at 25°C of 696 mV
488 */
489 *val = 25000 - ((int)info->value - 864) * 1000000 / 1840;
490 break;
491 default:
492 mutex_unlock(&indio_dev->mlock);
493 return -EINVAL;
494 }
495
472 mutex_unlock(&indio_dev->mlock); 496 mutex_unlock(&indio_dev->mlock);
473 return IIO_VAL_INT; 497 return IIO_VAL_INT;
474 498