From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Hector Palacios <hector.palacios@digi.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"marex@denx.de" <marex@denx.de>,
"fabio.estevam@freescale.com" <fabio.estevam@freescale.com>
Subject: Re: [PATCH RFC] iio: mxs-lradc: add scaling to enable divide_by_two operation
Date: Thu, 04 Jul 2013 11:17:05 +0200 [thread overview]
Message-ID: <51D53D91.8020201@free-electrons.com> (raw)
In-Reply-To: <51D5392C.4020309@digi.com>
Hi,
On 04/07/2013 10:58, Hector Palacios wrote:
>
> The field of the register that stores the sample is 18 bits, but each
> sample is only 12 bits. The read_raw of a given channel will only read
> one sample and thus returns a value between 0 and 4095.
> If I use realbits here it will divide the Vref_mv by (1 << 18) and will
> give me a wrong scale value.
> Either we change the 'realbits' to 12 which is the real resolution of
> the ADC, or we leave it as 18 and use a 12 in this operation.
>
As said I didn't have a deep look at it so you are probably right.
>> Using IIO_VAL_FRACTIONAL_LOG2 allows you to avoid doing that computation
>> in your driver (sometimes, it is actually difficult to get it right
>> because you have to use 64 bits numbers).
>>
>> Also, it simplifies things a bit, you can then use something like:
>>
>> case IIO_CHAN_INFO_SCALE:
>> *val = lut[chan->channel];
>> *val2 = chan->scan_type.realbits - is_divide_by_two;
>> return IIO_VAL_FRACTIONAL_LOG2;
>
> Yes, but not all channels have a by two divisor. Some have a by 4, so
> I'll need to work out a formula per channel divisor.
> When using IIO_VAL_FRACTIONAL_LOG2, val must be given in mV?
>
val is in mV indeed.
My first go at it was something along the lines:
*val = 1850;
*val2 = 12 - divider[chan->channel] - is_divide_by_two;
But as Lars suggested you could also have something like:
*val = Vmax[chan->channel];
*val2 = 12 - is_divide_by_two;
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
next prev parent reply other threads:[~2013-07-04 9:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 10:06 [PATCH RFC] iio: mxs-lradc: add scaling to enable divide_by_two operation Hector Palacios
2013-07-03 10:25 ` Alexandre Belloni
2013-07-03 10:39 ` Hector Palacios
2013-07-03 10:46 ` Lars-Peter Clausen
2013-07-03 16:39 ` Hector Palacios
2013-07-03 16:54 ` Alexandre Belloni
2013-07-03 17:01 ` Lars-Peter Clausen
2013-07-04 8:58 ` Hector Palacios
2013-07-04 9:10 ` Lars-Peter Clausen
2013-07-04 9:17 ` Alexandre Belloni [this message]
2013-07-04 14:50 ` Hector Palacios
2013-07-03 11:25 ` Marek Vasut
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=51D53D91.8020201@free-electrons.com \
--to=alexandre.belloni@free-electrons.com \
--cc=fabio.estevam@freescale.com \
--cc=hector.palacios@digi.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=marex@denx.de \
/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