All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
@ 2015-06-11  8:22 ` Gergely Imreh
  0 siblings, 0 replies; 12+ messages in thread
From: Gergely Imreh @ 2015-06-11  8:22 UTC (permalink / raw)
  To: jic23
  Cc: michal.simek, imrehg, linux-iio, linux-arm-kernel, linux-kernel, ola

The Xilinx XADC driver has both a temperature channel and 8 voltage
channels. The voltage channels have no offset, but actually were still
set the same offset as the temperature channel. This did not cause
problems in /sys/bus/iio/ but can cause problems with other drivers
using iio data. For example iio-hwmon did return wrong voltage values
because of the offset.

Change tested with the Parallella board.

Signed-off-by: Gergely Imreh <imrehg@gmail.com>
---
 drivers/iio/adc/xilinx-xadc-core.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index ab52be2..36efab7 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -877,9 +877,17 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
 			return -EINVAL;
 		}
 	case IIO_CHAN_INFO_OFFSET:
-		/* Only the temperature channel has an offset */
-		*val = -((273150 << 12) / 503975);
-		return IIO_VAL_INT;
+		switch (chan->type) {
+		case IIO_VOLTAGE:
+			*val = 0;
+			return IIO_VAL_INT;
+		case IIO_TEMP:
+			/* Only the temperature channel has an offset */
+			*val = -((273150 << 12) / 503975);
+			return IIO_VAL_INT;
+		default:
+			return -EINVAL;
+		}
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		ret = xadc_read_adc_reg(xadc, XADC_REG_CONF2, &val16);
 		if (ret)
-- 
2.4.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-06-15  2:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11  8:22 [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels Gergely Imreh
2015-06-11  8:22 ` Gergely Imreh
2015-06-13 18:30 ` Jonathan Cameron
2015-06-13 18:30   ` Jonathan Cameron
2015-06-14  3:15   ` Gergely Imreh
2015-06-14  3:15     ` Gergely Imreh
2015-06-14 15:45     ` Lars-Peter Clausen
2015-06-14 15:45       ` Lars-Peter Clausen
2015-06-14 15:55       ` Jonathan Cameron
2015-06-14 15:55         ` Jonathan Cameron
2015-06-15  2:07         ` Gergely Imreh
2015-06-15  2:07           ` Gergely Imreh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.