From: Jonathan Cameron <jic23@kernel.org>
To: "Kim, Milo" <Milo.Kim@ti.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Jonathan Cameron <jic23@cam.ac.uk>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] iio: adc: add new lp8788 adc driver
Date: Sat, 15 Sep 2012 10:05:06 +0100 [thread overview]
Message-ID: <505444C2.5080409@kernel.org> (raw)
In-Reply-To: <A874F61F95741C4A9BA573A70FE3998F41EF4EE3@DQHE02.ent.ti.com>
On 09/15/2012 01:15 AM, Kim, Milo wrote:
>>> The LP8788 has 13 ADC input selection.
>>>
>>> ADC selection:
>>> Battery voltage, general ADC1 and so on.
>>>
>>> ADC result:
>>> Result = MAX_VALUE * (raw + 0.5) / 4095 except ADC is the charger
>> voltage
>>> If the ADC input is the charger voltage,
>>> Result = MAX_VALUE * (raw + 0.5) / (4095 * 0.48)
>>>
>>> The raw value is from the registers.
>>> It has the range between 0 to 4095. (12bits)
>>>
>>> MAX_VALUE is constant for each selection.
>>> For the battery voltage, there are three ADC inputs. 5.0/5.5/6.0V
>>> Battery voltage for Max 5.0V = 5.0
>>> Battery voltage for Max 5.5V = 5.5
>>> Battery voltage for Max 6.0V = 6.0
>>> Charger = 6.0
>>> ADC1 = 2.5
>>>
>>> I'm afraid I still misunderstand how IIO ADC works.
>>> Could you me some guide how to setup the scale in the driver?
>>
>> The scale is a fixpoint value, which should be multiplied with the raw
>> value
>> to get the result in the proper unit. The unit depends on the channel
>> type,
>> e.g. for voltage it is mV and for temperature it is C. The number of
>> decimal
>> places for the fixed point value depends on whether you return
>> INT_PLUS_MICRO it's 6, if you return INT_PLUS_NANO it is 9. The digits
>> before the decimal point are stored in "val" the digits after the
>> decimal
>> point are stored in "val2".
>>
>> E.g. if you have
>> *val = 1;
>> *val2 = 1256;
>> return INT_PLUS_MICRO;
>>
>> your scale factor is 1.001256, if you'd return INT_PLUS_NANO you scale
>> factor would be 1.0000001256 instead.
>>
>> In your case you could for example calculate the voltage scales as:
>>
>> tmp = MAX_VALUE * 1000000 / 4095;
>> *val = tmp / 1000000;
>> *val2 = tmp % 1000000;
>>
>> This assumes that MAX_VALUE is in millivolt.
>>
>> E.g. if MAX_VALUE is 5.0V you should get a scale of 1.220703 (val = 1,
>> val2
>> = 220703). Since your MAX_VALUE is fixed you can probably just pre-
>> calculate
>> the result of MAX_VALUE * 1000000 / 4095 for each channel, similar like
>> you
>> already did with your lp8788_scale table.
>
> Superb! Thanks a lot for your clear explanation.
>
> I have one more question about the temperature ADC.
>
> The LP8788 has no dedicated temperature ADC, but it provides four
> general inputs - ADC1 to 4.
> The IIO consumer can get the battery temperature among general ADC inputs.
> I think the ADC driver should not assume that ADC1..4 is for the temperature,
> because the selection is configurable in the platform side.
>
> Then how can I set the unit of ADC MAX_VALUE?
> I would set the unit of ADC MAX_VALUE to mili (same as voltage) and
> the result is converted by the IIO consumer manually.
> Does it make sense ?
Yes, if there is a temperature sensor attached to an ADC channel it
is not up to the ADC driver to know this, but rather to the consumer driver.
>
> Best Regards,
> Milo
>
next prev parent reply other threads:[~2012-09-15 9:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-10 8:02 [PATCH v5] iio: adc: add new lp8788 adc driver Kim, Milo
2012-09-10 9:07 ` Lars-Peter Clausen
2012-09-14 0:33 ` Kim, Milo
2012-09-14 0:33 ` Kim, Milo
2012-09-14 8:35 ` Lars-Peter Clausen
2012-09-15 0:15 ` Kim, Milo
2012-09-15 0:15 ` Kim, Milo
2012-09-15 9:05 ` Jonathan Cameron [this message]
2012-09-13 12:23 ` Jonathan Cameron
2012-09-14 0:33 ` Kim, Milo
2012-09-14 0:33 ` Kim, Milo
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=505444C2.5080409@kernel.org \
--to=jic23@kernel.org \
--cc=Milo.Kim@ti.com \
--cc=jic23@cam.ac.uk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.