From: Jonathan Cameron <jic23@kernel.org>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-iio@vger.kernel.org, Daniel Baluta <daniel.baluta@gmail.com>
Subject: Re: [PATCH v2 02/11] iio: adc: ti-ads1015: fix scale information for ADS1115
Date: Sun, 20 Aug 2017 11:53:13 +0100 [thread overview]
Message-ID: <20170820115313.036063e4@archlinux> (raw)
In-Reply-To: <1500564267-8613-3-git-send-email-akinobu.mita@gmail.com>
On Fri, 21 Jul 2017 00:24:18 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> The ti-ads1015 driver supports ADS1015 and ADS1115 devices. The same
> scale information is used for both devices in this driver, however they
> have actually different values and the ADS1115's one is not correct.
>
> These devices have the same full-scale input voltage range for each PGA
> selection. So instead of adding another hardcoded scale information,
> compute a correct scale on demand from each device's resolution.
>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
> Cc: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Applied to the togreg branch of iio.git and marked for stable.
Jonathan
> ---
> drivers/iio/adc/ti-ads1015.c | 48 ++++++++++++++++++++++----------------------
> 1 file changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 443444c..f32d046 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -81,18 +81,12 @@ static const unsigned int ads1115_data_rate[] = {
> 8, 16, 32, 64, 128, 250, 475, 860
> };
>
> -static const struct {
> - int scale;
> - int uscale;
> -} ads1015_scale[] = {
> - {3, 0},
> - {2, 0},
> - {1, 0},
> - {0, 500000},
> - {0, 250000},
> - {0, 125000},
> - {0, 125000},
> - {0, 125000},
> +/*
> + * Translation from PGA bits to full-scale positive and negative input voltage
> + * range in mV
> + */
> +static int ads1015_fullscale_range[] = {
> + 6144, 4096, 2048, 1024, 512, 256, 256, 256
> };
>
> #define ADS1015_V_CHAN(_chan, _addr) { \
> @@ -300,17 +294,20 @@ static irqreturn_t ads1015_trigger_handler(int irq, void *p)
> return IRQ_HANDLED;
> }
>
> -static int ads1015_set_scale(struct ads1015_data *data, int chan,
> +static int ads1015_set_scale(struct ads1015_data *data,
> + struct iio_chan_spec const *chan,
> int scale, int uscale)
> {
> int i, ret, rindex = -1;
> + int fullscale = div_s64((scale * 1000000LL + uscale) <<
> + (chan->scan_type.realbits - 1), 1000000);
>
> - for (i = 0; i < ARRAY_SIZE(ads1015_scale); i++)
> - if (ads1015_scale[i].scale == scale &&
> - ads1015_scale[i].uscale == uscale) {
> + for (i = 0; i < ARRAY_SIZE(ads1015_fullscale_range); i++) {
> + if (ads1015_fullscale_range[i] == fullscale) {
> rindex = i;
> break;
> }
> + }
> if (rindex < 0)
> return -EINVAL;
>
> @@ -320,7 +317,7 @@ static int ads1015_set_scale(struct ads1015_data *data, int chan,
> if (ret < 0)
> return ret;
>
> - data->channel_data[chan].pga = rindex;
> + data->channel_data[chan->address].pga = rindex;
>
> return 0;
> }
> @@ -378,9 +375,9 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
> }
> case IIO_CHAN_INFO_SCALE:
> idx = data->channel_data[chan->address].pga;
> - *val = ads1015_scale[idx].scale;
> - *val2 = ads1015_scale[idx].uscale;
> - ret = IIO_VAL_INT_PLUS_MICRO;
> + *val = ads1015_fullscale_range[idx];
> + *val2 = chan->scan_type.realbits - 1;
> + ret = IIO_VAL_FRACTIONAL_LOG2;
> break;
> case IIO_CHAN_INFO_SAMP_FREQ:
> idx = data->channel_data[chan->address].data_rate;
> @@ -407,7 +404,7 @@ static int ads1015_write_raw(struct iio_dev *indio_dev,
> mutex_lock(&data->lock);
> switch (mask) {
> case IIO_CHAN_INFO_SCALE:
> - ret = ads1015_set_scale(data, chan->address, val, val2);
> + ret = ads1015_set_scale(data, chan, val, val2);
> break;
> case IIO_CHAN_INFO_SAMP_FREQ:
> ret = ads1015_set_data_rate(data, chan->address, val);
> @@ -439,7 +436,10 @@ static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
> .validate_scan_mask = &iio_validate_scan_mask_onehot,
> };
>
> -static IIO_CONST_ATTR(scale_available, "3 2 1 0.5 0.25 0.125");
> +static IIO_CONST_ATTR_NAMED(ads1015_scale_available, scale_available,
> + "3 2 1 0.5 0.25 0.125");
> +static IIO_CONST_ATTR_NAMED(ads1115_scale_available, scale_available,
> + "0.1875 0.125 0.0625 0.03125 0.015625 0.007813");
>
> static IIO_CONST_ATTR_NAMED(ads1015_sampling_frequency_available,
> sampling_frequency_available, "128 250 490 920 1600 2400 3300");
> @@ -447,7 +447,7 @@ static IIO_CONST_ATTR_NAMED(ads1115_sampling_frequency_available,
> sampling_frequency_available, "8 16 32 64 128 250 475 860");
>
> static struct attribute *ads1015_attributes[] = {
> - &iio_const_attr_scale_available.dev_attr.attr,
> + &iio_const_attr_ads1015_scale_available.dev_attr.attr,
> &iio_const_attr_ads1015_sampling_frequency_available.dev_attr.attr,
> NULL,
> };
> @@ -457,7 +457,7 @@ static const struct attribute_group ads1015_attribute_group = {
> };
>
> static struct attribute *ads1115_attributes[] = {
> - &iio_const_attr_scale_available.dev_attr.attr,
> + &iio_const_attr_ads1115_scale_available.dev_attr.attr,
> &iio_const_attr_ads1115_sampling_frequency_available.dev_attr.attr,
> NULL,
> };
next prev parent reply other threads:[~2017-08-20 11:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 15:24 [PATCH v2 00/11] iio: adc: ti-ads1015: fixes, cleanups, and threshold event support Akinobu Mita
2017-07-20 15:24 ` [PATCH v2 01/11] iio: adc: ti-ads1015: fix incorrect data rate setting update Akinobu Mita
2017-07-23 11:32 ` Jonathan Cameron
2017-08-20 10:51 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 02/11] iio: adc: ti-ads1015: fix scale information for ADS1115 Akinobu Mita
2017-08-20 10:53 ` Jonathan Cameron [this message]
2017-07-20 15:24 ` [PATCH v2 03/11] iio: adc: ti-ads1015: enable conversion when CONFIG_PM is not set Akinobu Mita
2017-08-20 10:54 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 04/11] iio: adc: ti-ads1015: avoid getting stale result after runtime resume Akinobu Mita
2017-08-20 10:55 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 05/11] iio: adc: ti-ads1015: don't return invalid value from buffer setup callbacks Akinobu Mita
2017-08-20 10:56 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 06/11] iio: adc: ti-ads1015: add adequate wait time to get correct conversion Akinobu Mita
2017-07-23 11:36 ` Jonathan Cameron
2017-08-20 10:57 ` Jonathan Cameron
2017-08-21 21:00 ` Ladislav Michl
2017-08-22 10:03 ` Akinobu Mita
2017-08-22 14:36 ` Ladislav Michl
2017-08-23 13:57 ` Akinobu Mita
2017-07-20 15:24 ` [PATCH v2 07/11] iio: adc: ti-ads1015: remove unnecessary config register update Akinobu Mita
2017-08-20 10:58 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 08/11] iio: adc: ti-ads1015: add helper to set conversion mode Akinobu Mita
2017-08-20 10:59 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 09/11] iio: adc: ti-ads1015: use devm_iio_triggered_buffer_setup Akinobu Mita
2017-08-20 11:00 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 10/11] iio: adc: ti-ads1015: use iio_device_claim_direct_mode() Akinobu Mita
2017-08-20 11:00 ` Jonathan Cameron
2017-07-20 15:24 ` [PATCH v2 11/11] iio: adc: ti-ads1015: add threshold event support Akinobu Mita
2017-07-23 12:01 ` Jonathan Cameron
2017-08-20 11:05 ` Jonathan Cameron
2017-08-22 10:20 ` Akinobu Mita
2017-08-22 12:35 ` Jonathan Cameron
2017-08-22 12:38 ` Jonathan Cameron
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=20170820115313.036063e4@archlinux \
--to=jic23@kernel.org \
--cc=akinobu.mita@gmail.com \
--cc=daniel.baluta@gmail.com \
--cc=linux-iio@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).