From: "Phani A, Rama Krishna" <rphani-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
To: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
cdevired-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
smohanad-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
mgautam-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
sivaa-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
knaack.h-Mmb7MZpHnFY@public.gmane.org,
lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org,
pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org,
Julia.Lawall-L2FTfq7BK8M@public.gmane.org
Subject: Re: [PATCH V4 1/2] iio: adc: spmi-vadc: Update function for generic voltage conversion
Date: Mon, 14 Nov 2016 17:17:25 +0530 [thread overview]
Message-ID: <fc55831c-1826-385e-aecd-83ea0b0c47a9@codeaurora.org> (raw)
In-Reply-To: <38428ee7-5d1b-2b36-99a9-988e0e7d29b5-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Hi Jonathan,
On 12-Nov-16 8:43 PM, Jonathan Cameron wrote:
> On 08/11/16 11:58, Rama Krishna Phani A wrote:
>> Several channels are supported in ADC of PMIC which can be used to
>> measure voltage, temperature, current etc. Hardware provides
>> readings for all channels in adc code. That adc code needs to be
>> converted to voltage. Logic for conversion of adc code to voltage
>> is common for all ADC channels(voltage, temperature, current etc).
>> Implement separate function for generic conversion logic.
>>
>> Signed-off-by: Rama Krishna Phani A <rphani-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
> Looks good to me. Kind of the best we can do with minimal
> ABI changes.
>
> I had applied this but have now backed out to wait for patch 2.
>> ---
>> drivers/iio/adc/qcom-spmi-vadc.c | 52 +++++++++++++++++++++-------------------
>> 1 file changed, 28 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
>> index c2babe5..93c0639 100644
>> --- a/drivers/iio/adc/qcom-spmi-vadc.c
>> +++ b/drivers/iio/adc/qcom-spmi-vadc.c
>> @@ -1,5 +1,5 @@
>> /*
>> - * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
>> + * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
>> *
>> * This program is free software; you can redistribute it and/or modify
>> * it under the terms of the GNU General Public License version 2 and
>> @@ -468,27 +468,38 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
>> return ret;
>> }
>>
>> -static s32 vadc_calibrate(struct vadc_priv *vadc,
>> - const struct vadc_channel_prop *prop, u16 adc_code)
>> +static void vadc_scale_calib(struct vadc_priv *vadc, u16 adc_code,
>> + const struct vadc_channel_prop *prop,
>> + s64 *scale_voltage)
>> {
>> - const struct vadc_prescale_ratio *prescale;
>> - s64 voltage;
>> + *scale_voltage = (adc_code -
>> + vadc->graph[prop->calibration].gnd);
>> + *scale_voltage *= vadc->graph[prop->calibration].dx;
>> + *scale_voltage = div64_s64(*scale_voltage,
>> + vadc->graph[prop->calibration].dy);
>> + if (prop->calibration == VADC_CALIB_ABSOLUTE)
>> + *scale_voltage +=
>> + vadc->graph[prop->calibration].dx;
>>
>> - voltage = adc_code - vadc->graph[prop->calibration].gnd;
>> - voltage *= vadc->graph[prop->calibration].dx;
>> - voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy);
>> + if (*scale_voltage < 0)
>> + *scale_voltage = 0;
>> +}
>>
>> - if (prop->calibration == VADC_CALIB_ABSOLUTE)
>> - voltage += vadc->graph[prop->calibration].dx;
>> +static int vadc_scale_volt(struct vadc_priv *vadc,
>> + const struct vadc_channel_prop *prop, u16 adc_code,
>> + int *result_uv)
>> +{
>> + const struct vadc_prescale_ratio *prescale;
>> + s64 voltage = 0, result = 0;
>>
>> - if (voltage < 0)
>> - voltage = 0;
>> + vadc_scale_calib(vadc, adc_code, prop, &voltage);
>>
>> prescale = &vadc_prescale_ratios[prop->prescale];
>> -
>> voltage = voltage * prescale->den;
>> + result = div64_s64(voltage, prescale->num);
>> + *result_uv = result;
>>
>> - return div64_s64(voltage, prescale->num);
>> + return 0;
>> }
>>
>> static int vadc_decimation_from_dt(u32 value)
>> @@ -552,11 +563,8 @@ static int vadc_read_raw(struct iio_dev *indio_dev,
>> if (ret)
>> break;
>>
>> - *val = vadc_calibrate(vadc, prop, adc_code);
>> + vadc_scale_volt(vadc, prop, adc_code, val);
>>
>> - /* 2mV/K, return milli Celsius */
>> - *val /= 2;
>> - *val -= KELVINMIL_CELSIUSMIL;
>> return IIO_VAL_INT;
>> case IIO_CHAN_INFO_RAW:
>> prop = &vadc->chan_props[chan->address];
>> @@ -564,12 +572,8 @@ static int vadc_read_raw(struct iio_dev *indio_dev,
>> if (ret)
>> break;
>>
>> - *val = vadc_calibrate(vadc, prop, adc_code);
>> + *val = (int)adc_code;
>> return IIO_VAL_INT;
>> - case IIO_CHAN_INFO_SCALE:
>> - *val = 0;
>> - *val2 = 1000;
>> - return IIO_VAL_INT_PLUS_MICRO;
>> default:
>> ret = -EINVAL;
>> break;
>> @@ -617,7 +621,7 @@ struct vadc_channels {
>>
>> #define VADC_CHAN_VOLT(_dname, _pre) \
>> VADC_CHAN(_dname, IIO_VOLTAGE, \
>> - BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
>> + BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED),\
>> _pre) \
> This is still odd, but I guess justifiable from the point of view
> of maintaining backwards compatibility. The scale was simply wrong
> so not much we can do about that other than drop it!
ok., Will retain "IIO_CHAN_INFO_SCALE" to maintain backward
compatibility and include support for "IIO_CHAN_INFO_PROCESSED" as well
in the next patch.
>>
>> /*
>>
>
Thanks,
Ramakrishna
next prev parent reply other threads:[~2016-11-14 11:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 11:58 [PATCH V4 0/2] Changes to support different VADC scaling Rama Krishna Phani A
[not found] ` <1478606334-12394-1-git-send-email-rphani-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-08 11:58 ` [PATCH V4 1/2] iio: adc: spmi-vadc: Update function for generic voltage conversion Rama Krishna Phani A
2016-11-12 15:13 ` Jonathan Cameron
[not found] ` <38428ee7-5d1b-2b36-99a9-988e0e7d29b5-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-11-14 11:47 ` Phani A, Rama Krishna [this message]
2016-11-08 11:58 ` [PATCH V4 2/2] iio: adc: spmi-vadc: Changes to support different scaling Rama Krishna Phani A
[not found] ` <1478606334-12394-3-git-send-email-rphani-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-12 15:02 ` Jonathan Cameron
[not found] ` <bc8b56e3-e1bf-3e92-bdca-cf7b0a13dca1-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-11-14 11:38 ` Phani A, Rama Krishna
[not found] ` <03b97c38-02fb-a727-28a5-298bb240a312-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-19 12:38 ` Jonathan Cameron
[not found] ` <33f02a43-0542-bad1-8c9a-1aa5cb1cef9f-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-11-19 13:36 ` Rama Krishna Phani A
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=fc55831c-1826-385e-aecd-83ea0b0c47a9@codeaurora.org \
--to=rphani-sgv2jx0feol9jmxxk+q4oq@public.gmane.org \
--cc=Julia.Lawall-L2FTfq7BK8M@public.gmane.org \
--cc=cdevired-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
--cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
--cc=linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mgautam-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
--cc=sivaa-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=smohanad-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.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).