linux-kernel.vger.kernel.org archive mirror
 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
  2015-06-13 18:30 ` Jonathan Cameron
  0 siblings, 1 reply; 6+ 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] 6+ messages in thread

* Re: [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
  2015-06-11  8:22 [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels Gergely Imreh
@ 2015-06-13 18:30 ` Jonathan Cameron
  2015-06-14  3:15   ` Gergely Imreh
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2015-06-13 18:30 UTC (permalink / raw)
  To: Gergely Imreh
  Cc: michal.simek, linux-iio, linux-arm-kernel, linux-kernel, ola,
	Lars-Peter Clausen

On 11/06/15 09:22, Gergely Imreh wrote:
> 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>
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
> ---
>  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)
> 


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

* Re: [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
  2015-06-13 18:30 ` Jonathan Cameron
@ 2015-06-14  3:15   ` Gergely Imreh
  2015-06-14 15:45     ` Lars-Peter Clausen
  0 siblings, 1 reply; 6+ messages in thread
From: Gergely Imreh @ 2015-06-14  3:15 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: michal.simek, linux-iio, Linux ARM Kernel, linux-kernel, ola,
	Lars-Peter Clausen

On 14 June 2015 at 02:30, Jonathan Cameron <jic23@kernel.org> wrote:
> On 11/06/15 09:22, Gergely Imreh wrote:
>> 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>
> 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?

I'll check it out, and send an updated patch! Thanks for the pointers
to the core of the issue.

>
> If not I can fix it up sometime if no one else beats me to it.
>
> Thanks
>
> Jonathan
>> ---
>>  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)
>>
>

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

* Re: [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
  2015-06-14  3:15   ` Gergely Imreh
@ 2015-06-14 15:45     ` Lars-Peter Clausen
  2015-06-14 15:55       ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2015-06-14 15:45 UTC (permalink / raw)
  To: Gergely Imreh, Jonathan Cameron
  Cc: michal.simek, linux-iio, Linux ARM Kernel, linux-kernel, ola

On 06/14/2015 05:15 AM, Gergely Imreh wrote:
> On 14 June 2015 at 02:30, Jonathan Cameron <jic23@kernel.org> wrote:
>> On 11/06/15 09:22, Gergely Imreh wrote:
>>> 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>
>> 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?
>
> 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

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

* Re: [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
  2015-06-14 15:45     ` Lars-Peter Clausen
@ 2015-06-14 15:55       ` Jonathan Cameron
  2015-06-15  2:07         ` Gergely Imreh
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2015-06-14 15:55 UTC (permalink / raw)
  To: Lars-Peter Clausen, Gergely Imreh
  Cc: michal.simek, linux-iio, Linux ARM Kernel, linux-kernel, ola

On 14/06/15 16:45, Lars-Peter Clausen wrote:
> On 06/14/2015 05:15 AM, Gergely Imreh wrote:
>> On 14 June 2015 at 02:30, Jonathan Cameron <jic23@kernel.org> wrote:
>>> On 11/06/15 09:22, Gergely Imreh wrote:
>>>> 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>
>>> 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?
>>
>> 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.
> 
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
> - Lars

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

* Re: [PATCH 1/1] iio:adc: XADC: Set offset explicitly to zero on voltage channels
  2015-06-14 15:55       ` Jonathan Cameron
@ 2015-06-15  2:07         ` Gergely Imreh
  0 siblings, 0 replies; 6+ messages in thread
From: Gergely Imreh @ 2015-06-15  2:07 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, michal.simek, linux-iio, Linux ARM Kernel,
	linux-kernel, ola

On 14 June 2015 at 23:55, Jonathan Cameron <jic23@kernel.org> wrote:
> On 14/06/15 16:45, Lars-Peter Clausen wrote:
>> On 06/14/2015 05:15 AM, Gergely Imreh wrote:
>>> On 14 June 2015 at 02:30, Jonathan Cameron <jic23@kernel.org> wrote:
>>>> On 11/06/15 09:22, Gergely Imreh wrote:
>>>>> 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>
>>>> 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?
>>>
>>> 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.
>>
> 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

>
> J
>> - Lars

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

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

Thread overview: 6+ 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-13 18:30 ` Jonathan Cameron
2015-06-14  3:15   ` Gergely Imreh
2015-06-14 15:45     ` Lars-Peter Clausen
2015-06-14 15:55       ` Jonathan Cameron
2015-06-15  2:07         ` Gergely Imreh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).