devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Hector Palacios <hector.palacios@digi.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org,
	alexandre.belloni@free-electrons.com, jic23@kernel.org,
	lars@metafoo.de, fabio.estevam@freescale.com
Subject: Re: [PATCH v3 4/5] iio: mxs-lradc: add scale_available file to channels
Date: Tue, 23 Jul 2013 00:36:41 +0200	[thread overview]
Message-ID: <201307230036.42046.marex@denx.de> (raw)
In-Reply-To: <1374501843-19651-5-git-send-email-hector.palacios@digi.com>

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.



> +			lradc->scale_avail[i][s].nano =
> +					do_div(scale_uv, 100000000) * 10;

Are we not loosing precission here?

> +			lradc->scale_avail[i][s].integer = scale_uv;
> +		}
> +	}
> +
>  	/* Configure the hardware. */
>  	mxs_lradc_hw_init(lradc);

Best regards,
Marek Vasut

  reply	other threads:[~2013-07-22 22:36 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
     [not found]   ` <1374501843-19651-2-git-send-email-hector.palacios-i7dp0qKlBMg@public.gmane.org>
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
     [not found]   ` <1374501843-19651-3-git-send-email-hector.palacios-i7dp0qKlBMg@public.gmane.org>
2013-07-22 18:34     ` Lars-Peter Clausen
     [not found]       ` <51ED7B47.2090104-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-07-22 22:06         ` Marek Vasut
     [not found]           ` <201307230006.53434.marex-ynQEQJNshbs@public.gmane.org>
2013-07-26  9:23             ` Alexandre Belloni
2013-08-13 21:23     ` Jonathan Cameron
     [not found]       ` <520AA3CD.1040008-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-08-14 14:44         ` Pawel Moll
2013-08-21 22:13           ` Alexandre Belloni
     [not found]             ` <52153B8E.7050309-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2013-08-22  6:17               ` Jonathan Cameron
2013-08-22 16:51                 ` Pawel Moll
2013-08-23 23:00                   ` Jonathan Cameron
     [not found]                     ` <5217E999.7020408-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-09-23 12:47                       ` Alexandre Belloni
     [not found]                         ` <52403845.5020002-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2013-09-23 13:39                           ` Hector Palacios
2013-08-22  8:05               ` Hector Palacios
     [not found]                 ` <5215C64D.3040004-i7dp0qKlBMg@public.gmane.org>
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 [this message]
     [not found]     ` <201307230036.42046.marex-ynQEQJNshbs@public.gmane.org>
2013-07-23  7:00       ` Hector Palacios
     [not found]   ` <1374501843-19651-5-git-send-email-hector.palacios-i7dp0qKlBMg@public.gmane.org>
2013-07-23  8:46     ` Lars-Peter Clausen
     [not found]       ` <51EE4300.7070802-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-07-23 13:25         ` Hector Palacios
     [not found]           ` <51EE8445.6070603-i7dp0qKlBMg@public.gmane.org>
2013-07-26 13:17             ` Alexandre Belloni
     [not found]               ` <51F276D8.9090906-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2013-07-26 16:13                 ` Jonathan Cameron
     [not found]                   ` <d838f30e-30ca-49ca-a9f3-ebf4e523c7eb-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org>
2013-08-07  7:50                     ` Alexandre Belloni
     [not found]                       ` <5201FC55.5080304-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
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
     [not found]   ` <1374501843-19651-6-git-send-email-hector.palacios-i7dp0qKlBMg@public.gmane.org>
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=201307230036.42046.marex@denx.de \
    --to=marex@denx.de \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=fabio.estevam@freescale.com \
    --cc=hector.palacios@digi.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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).