From: Lars-Peter Clausen <lars@metafoo.de>
To: Guillaume Ballet <gballetwork@gmail.com>
Cc: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>,
linux-iio@vger.kernel.org
Subject: Re: Why is only one int returned in iio_read_channel_processed?
Date: Thu, 23 May 2013 15:28:25 +0200 [thread overview]
Message-ID: <519E1979.8070400@metafoo.de> (raw)
In-Reply-To: <CAGi_vri0x77BmteL=+A3-P7Ai3x9NAdBa-HqctaKN9jMt0EN1w@mail.gmail.com>
On 05/23/2013 03:18 PM, Guillaume Ballet wrote:
>>>
>>> - if IIO_INT_VAL_PLUS_NANO is returned (common when dealing with
>>> current sources), 32 bits is a bit tight - which is why the read_raw
>>> function pointer in iio_info has (val, val2) in the first place.
>>> - People like me who do not use the iio_convert_raw_to_processed
>>> path() but need to support IIO_CHAN_INFO_PROCESSED directly in their
>>> driver have an issue: we would need to be passed the scale in the
>>> read_raw function of iio_info. That would impact _all_ IIO drivers.
>>
>> IIO_CHAN_INFO_PROCESSED is by definition supposed to return the value in the
>> proper unit. If that doesn't work for you use IIO_CHAN_INFO_RAW +
>> IIO_CHAN_INFO_SCALE. Think of IIO_CHAN_INFO_PROCESSED as IIO_CHAN_INFO_RAW
>> with the scale set to 1.0
>
> This isn't a unit problem, this is a precision problem: if I want to
> return a current in Ampères, for instance 5.000000001, I can't get
> that by calling iio_read_channel_processed() (or
> iio_read_channel_raw() for that matter) as the precision is too big to
> fit in only one integer. The issue is that the callback that handles
> IIO_CHAN_INFO_PROCESSED and IIO_CHAN_INFO_RAW does allow to return
> such a value. There's an inconsistency in the interface.
I doubt anybody actually cares about the 0.000000001 in that case.
>
>>
>>> - The scale parameter to iio_convert_raw_to_processed() itself is an
>>> int, and IIO_CHAN_INFO_SCALE can return a scale in the
>>> IIO_VAL_INT_PLUS_NANO scheme. It means somewhere along the road,
>>> precision is lost.
>>
>> The scale would be passed in by the consumer, so the consumer is able to
>> specify the amount of precision it wants.
>
> Not if they want a precision as high as the IIO driver is able to
> deliver: the scale returned by a IIO_CHAN_INFO_SCALE is a 64-bits
> fixed point integer. The scaled passed to
> iio_convert_raw_to_processed() is a 32 bit integer. If one needs great
> precision on big numbers, it won't fit.
The problem is that there is no in kernel user who can actually make use of
anything but a 32bit integer. If we need a larger range we should change the
return type to a 64bit integer rather than adopting the val1, val2 scheme
for the in-kernel API.
- Lars
next prev parent reply other threads:[~2013-05-23 13:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-22 7:49 Why is only one int returned in iio_read_channel_processed? Guillaume Ballet
2013-05-22 8:04 ` Jonathan Cameron
2013-05-22 8:19 ` Lars-Peter Clausen
2013-05-22 9:00 ` Jonathan Cameron
2013-05-22 9:37 ` Guillaume Ballet
2013-05-22 11:43 ` Lars-Peter Clausen
2013-05-22 13:29 ` Guillaume Ballet
2013-05-22 13:39 ` Lars-Peter Clausen
2013-05-22 14:00 ` Guillaume Ballet
2013-05-22 14:15 ` Lars-Peter Clausen
2013-05-22 15:24 ` Guillaume Ballet
2013-05-22 17:14 ` Lars-Peter Clausen
2013-05-23 9:52 ` Guillaume Ballet
2013-05-23 10:39 ` Lars-Peter Clausen
2013-05-23 13:18 ` Guillaume Ballet
2013-05-23 13:28 ` Lars-Peter Clausen [this message]
2013-06-02 16:00 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=519E1979.8070400@metafoo.de \
--to=lars@metafoo.de \
--cc=gballetwork@gmail.com \
--cc=jic23@jic23.retrosnub.co.uk \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).