From: Hector Palacios <hector.palacios@digi.com>
To: Marek Vasut <marex@denx.de>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"devicetree-discuss@lists.ozlabs.org"
<devicetree-discuss@lists.ozlabs.org>,
"alexandre.belloni@free-electrons.com"
<alexandre.belloni@free-electrons.com>,
"jic23@kernel.org" <jic23@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"fabio.estevam@freescale.com" <fabio.estevam@freescale.com>,
<michael.hennerich@analog.com>
Subject: Re: [PATCH v3 4/5] iio: mxs-lradc: add scale_available file to channels
Date: Tue, 23 Jul 2013 09:00:13 +0200 [thread overview]
Message-ID: <51EE29FD.5070901@digi.com> (raw)
In-Reply-To: <201307230036.42046.marex@denx.de>
Hello Marek,
On 07/23/2013 12:36 AM, Marek Vasut wrote:
> Dear Hector Palacios,
>
>> Adds in_voltageX_scale_available file for every channel to read
>> the different available scales.
>> There are two scales per channel:
>> [0] = divider_by_two disabled (default)
>> [1] = divider_by_two enabled
>> The scale is a struct made of integer and nano parts to build
>> a long decimal number.
>>
>> Signed-off-by: Hector Palacios <hector.palacios@digi.com>
>> ---
>
> [...]
>
>> @@ -1008,6 +1098,26 @@ static int mxs_lradc_probe(struct platform_device
>> *pdev) if (ret)
>> goto err_trig;
>>
>> + /* Populate available ADC input ranges */
>> + for (i = 0; i < LRADC_MAX_TOTAL_CHANS; i++) {
>> + for (s = 0; s < ARRAY_SIZE(lradc->scale_avail[i]); s++) {
>> + /*
>> + * [s=0] = optional divider by two disabled (default)
>> + * [s=1] = optional divider by two enabled
>> + *
>> + * The scale is calculated by doing:
>> + * Vref >> (realbits - s)
>> + * which multiplies by two on the second component
>> + * of the array.
>> + */
>> + scale_uv = ((u64)lradc->vref_mv[i] * 100000000) >>
>> + (iio->channels[i].scan_type.realbits - s);
>
> Thinking about this, this is basically
>
> vref_mv[CHANNEL] * 100 000 000
> scale_uv = --------------------------------
> 2^(12 - s)
>
> Where s can be either 0 or 1.
>
> Why do you multiply it by 100000000 I don't quite understand, but maybe it's
> fully obvious. It should be documented though.
I copied Michael Hennerich in CC who was the author of this math in
drivers/iio/adc/ad7793.c
drivers/staging/iio/adc/ad7192.c
which I copied. Maybe he can explain. It looks like it is just a question of having a
intermediate large enough number to later do the do_div operation, rather than having
a meaningful figure.
>> + lradc->scale_avail[i][s].nano =
>> + do_div(scale_uv, 100000000) * 10;
>
> Are we not loosing precission here?
Yes, but the do_div is modifying the scale_uv parameter with the integer part so I
guess it might be somewhat justified.
As I said before, I tried to do my own math without success so I just copied what was
in other drivers.
>
>> + lradc->scale_avail[i][s].integer = scale_uv;
>> + }
>> + }
>> +
>> /* Configure the hardware. */
>> mxs_lradc_hw_init(lradc);
>
> Best regards,
> Marek Vasut
>
Best regards,
--
Hector Palacios
next prev parent reply other threads:[~2013-07-23 7:00 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-22 14:03 [PATCH v3 0/5] iio: mxs-lradc: add support to optional divider_by_two Hector Palacios
2013-07-22 14:03 ` [PATCH v3 1/5] iio: mxs-lradc: change the realbits to 12 Hector Palacios
2013-08-13 21:24 ` Jonathan Cameron
2013-07-22 14:04 ` [PATCH v3 2/5] ARM: dts: add reference voltage property for MXS LRADC Hector Palacios
2013-07-22 18:34 ` Lars-Peter Clausen
2013-07-22 22:06 ` Marek Vasut
2013-07-26 9:23 ` Alexandre Belloni
2013-08-13 21:23 ` Jonathan Cameron
2013-08-14 14:44 ` Pawel Moll
2013-08-21 22:13 ` Alexandre Belloni
2013-08-22 6:17 ` Jonathan Cameron
2013-08-22 16:51 ` Pawel Moll
2013-08-23 23:00 ` Jonathan Cameron
2013-09-23 12:47 ` Alexandre Belloni
2013-09-23 13:39 ` Hector Palacios
2013-08-22 8:05 ` Hector Palacios
2013-08-22 16:50 ` Pawel Moll
2013-08-22 16:41 ` Pawel Moll
2013-08-22 17:00 ` Lars-Peter Clausen
2013-07-22 14:04 ` [PATCH v3 3/5] iio: mxs-lradc: add scale attribute to channels Hector Palacios
2013-07-22 14:04 ` [PATCH v3 4/5] iio: mxs-lradc: add scale_available file " Hector Palacios
2013-07-22 22:36 ` Marek Vasut
2013-07-23 7:00 ` Hector Palacios [this message]
2013-07-23 8:46 ` Lars-Peter Clausen
2013-07-23 13:25 ` Hector Palacios
2013-07-26 13:17 ` Alexandre Belloni
2013-07-26 16:13 ` Jonathan Cameron
2013-08-07 7:50 ` Alexandre Belloni
2013-08-13 21:26 ` Jonathan Cameron
2013-07-22 14:04 ` [PATCH v3 5/5] iio: mxs-lradc: add write_raw function to modify scale Hector Palacios
2013-07-22 22:37 ` 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=51EE29FD.5070901@digi.com \
--to=hector.palacios@digi.com \
--cc=alexandre.belloni@free-electrons.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=fabio.estevam@freescale.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marex@denx.de \
--cc=michael.hennerich@analog.com \
/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