iio:adc: XADC: Set offset explicitly to zero on voltage channels
Subsystems (2)
PATCH 1/1 iio:adc: XADC: Set offset explicitly to zero on voltage channels
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.
--- drivers/iio/adc/xilinx-xadc-core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/iio/adc/xilinx-xadc-core.c +11 -3
@@ -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)
Signature · 1 line
2.4.2
Jonathan Cameron
maintainerQuoted 10 lines · Gergely Imreh
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 <[email protected]>
Well spotted on the bug, but I think we are better off fixing this at the true source of the problem which is in drivers/iio/inkern.c iio_convert_raw_to_processed_unlocked which does a call to iio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET) then uses the error return to check if the offset parameter is available. It should be checking that before making this call with a call to iio_channel_has_info.
I don't suppose you could prepare a patch fixing that as you found the problem?
If not I can fix it up sometime if no one else beats me to it.
Thanks
Jonathan
Quoted 30 lines
--- drivers/iio/adc/xilinx-xadc-core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/iio/adc/xilinx-xadc-core.c +11
-3@@ -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)
Quoted 11 lines · Jonathan Cameron
Quoted 10 lines · Gergely Imreh
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 <[email protected]>
Quoted 8 lines
Well spotted on the bug, but I think we are better off fixing this at the true source of the problem which is in
drivers/iio/inkern.ciio_convert_raw_to_processed_unlockedwhich does a call toiio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET)then uses the error return to check if the offset parameter is available. It should be checking that before making this call with a call toiio_channel_has_info.I don't suppose you could prepare a patch fixing that as you found the problem?
I'll check it out, and send an updated patch! Thanks for the pointers to the core of the issue.
Quoted 37 lines
If not I can fix it up sometime if no one else beats me to it.
Thanks
Jonathan
Quoted 30 lines
--- drivers/iio/adc/xilinx-xadc-core.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/iio/adc/xilinx-xadc-core.c +11
-3@@ -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)
Quoted 19 lines · Gergely Imreh
Quoted 18 lines · Jonathan Cameron
Quoted 10 lines · Gergely Imreh
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 <[email protected]>Well spotted on the bug, but I think we are better off fixing this at the true source of the problem which is in
drivers/iio/inkern.ciio_convert_raw_to_processed_unlockedwhich does a call toiio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET)then uses the error return to check if the offset parameter is available. It should be checking that before making this call with a call toiio_channel_has_info.
Quoted 4 lines
Quoted 1 line
I don't suppose you could prepare a patch fixing that as you found the problem?
I'll check it out, and send an updated patch! Thanks for the pointers to the core of the issue.
The issue was already fixed a while ago, see this patch:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=65de7654d39c70c2b942f801cea01590cf7e3458
Starting with that commit iio_channel_read() returns an error when the attribute is not available, which causes iio_convert_raw_to_processed_unlocked() to skip the offset if it is not available.
- Lars
Jonathan Cameron
maintainerQuoted 25 lines · Lars-Peter Clausen
Quoted 19 lines · Gergely Imreh
Quoted 18 lines · Jonathan Cameron
Quoted 10 lines · Gergely Imreh
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 <[email protected]>Well spotted on the bug, but I think we are better off fixing this at the true source of the problem which is in
drivers/iio/inkern.ciio_convert_raw_to_processed_unlockedwhich does a call toiio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET)then uses the error return to check if the offset parameter is available. It should be checking that before making this call with a call toiio_channel_has_info.Quoted 4 lines
Quoted 1 line
I don't suppose you could prepare a patch fixing that as you found the problem?
I'll check it out, and send an updated patch! Thanks for the pointers to the core of the issue.
Quoted 8 lines
The issue was already fixed a while ago, see this patch:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=65de7654d39c70c2b942f801cea01590cf7e3458Starting with that commit
iio_channel_read()returns an error when
the attribute is not available, which causesiio_convert_raw_to_processed_unlocked()to skip the offset if it is not available.
oops. Good spot. I'd completely forgotten about that and failed to spot the check when looking at the code yesterday.
Glad you were keeping an eagle eye on things ;)
J
Quoted 1 line
- Lars
Quoted 34 lines · Jonathan Cameron
Quoted 25 lines · Lars-Peter Clausen
Quoted 19 lines · Gergely Imreh
Quoted 18 lines · Jonathan Cameron
Quoted 10 lines · Gergely Imreh
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 <[email protected]>Well spotted on the bug, but I think we are better off fixing this at the true source of the problem which is in
drivers/iio/inkern.ciio_convert_raw_to_processed_unlockedwhich does a call toiio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET)then uses the error return to check if the offset parameter is available. It should be checking that before making this call with a call toiio_channel_has_info.Quoted 4 lines
Quoted 1 line
I don't suppose you could prepare a patch fixing that as you found the problem?
I'll check it out, and send an updated patch! Thanks for the pointers to the core of the issue.
Quoted 8 lines
The issue was already fixed a while ago, see this patch:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=65de7654d39c70c2b942f801cea01590cf7e3458Starting with that commit
iio_channel_read()returns an error when
the attribute is not available, which causesiio_convert_raw_to_processed_unlocked()to skip the offset if it is not available.
Quoted 4 lines
oops. Good spot. I'd completely forgotten about that and failed to spot the check when looking at the code yesterday.
Glad you were keeping an eagle eye on things ;)
Okay, thanks, then it's all good, scrub this patch! That linked change was not backported to the Parallella yet, and missed it. Looks like it's going to be included now.
Thanks for the feedback!
Greg
Quoted 3 lines
J
Quoted 1 line
- Lars