mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v2] iio: adc: New driver for TI ADS7950 chips
Date: Tue, 22 Nov 2016 12:23:46 -0600	[thread overview]
Message-ID: <748ee481-eb9a-28f2-2c8b-214eea63c2b0@lechnology.com> (raw)
In-Reply-To: <04F737B2-EB34-47DB-A913-C7D0A987E9AA@jic23.retrosnub.co.uk>

On 11/22/2016 01:23 AM, Jonathan Cameron wrote:
>
>
> On 21 November 2016 22:54:24 GMT+00:00, Peter Meerwald-Stadler <pmeerw@pmeerw.net> wrote:
>>
>>>> +static int ti_ads7950_read_raw(struct iio_dev *indio_dev,
>>>> +			       struct iio_chan_spec const *chan,
>>>> +			       int *val, int *val2, long m)
>>>> +{
>>>> +	struct ti_ads7950_state *st = iio_priv(indio_dev);
>>>> +	int ret;
>>>> +
>>>> +	switch (m) {
>>>> +	case IIO_CHAN_INFO_RAW:
>>>> +
>>>> +		ret = iio_device_claim_direct_mode(indio_dev);
>>>> +		if (ret < 0)
>>>> +			return ret;
>>>> +
>>>> +		ret = ti_ads7950_scan_direct(st, chan->address);
>>>> +		iio_device_release_direct_mode(indio_dev);
>>>> +		if (ret < 0)
>>>> +			return ret;
>>>> +
>>>> +		if (chan->address != TI_ADS7950_EXTRACT(ret, 12, 4))
>>>> +			return -EIO;
>>>> +
>>>> +		*val = TI_ADS7950_EXTRACT(ret, 0, 12);
>>>
>>> I'm not sure if I am doing this right. There are 8- 10- and 12-bit
>> versions of
>>> this chip. The 8- and 10-bit versions still return a 12-bit number
>> where the
>>> last 4 or 2 bits are always 0. Should I be shifting the 12-bit value
>> here
>>> based on the chip being used so that *val is 0-255 for 8-bit and
>> 0-1023 for
>>> 10-bit? Or should this be *really* raw and not even use
>> TI_ADS7950_EXTRACT()
>>> to mask the channel address bits?
>>
>> I'd shift and adjust _SCALE so that *val * scale gives mV
> It would also be fine to not do anything and let userspace deal with shifting and masking for
> buffered data.  Non buffered obviously still needs shifting and masking though!

I have sent a v3 patch already that does exactly this. Buffered data is 
untouched and unbuffered data is now correct with shifting and masking.

>
> I'd slightly prefer the doing nothing route but don't really care as both are valid uses of the ABI.
>
> Jonathan
>>
>>>> +
>>>> +		return IIO_VAL_INT;
>>>> +	case IIO_CHAN_INFO_SCALE:
>>>> +		ret = ti_ads7950_get_range(st);
>>>> +		if (ret < 0)
>>>> +			return ret;
>>>> +
>>>> +		*val = ret;
>>>> +		*val2 = chan->scan_type.realbits;
>>>> +
>>>> +		return IIO_VAL_FRACTIONAL_LOG2;
>>>> +	}
>>>> +
>>>> +	return -EINVAL;
>>>> +}
>

  reply	other threads:[~2016-11-22 18:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-20 18:28 David Lechner
2016-11-21 19:52 ` David Lechner
2016-11-21 22:54   ` Peter Meerwald-Stadler
2016-11-22  7:23     ` Jonathan Cameron
2016-11-22 18:23       ` David Lechner [this message]
2016-11-24 20:35   ` 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=748ee481-eb9a-28f2-2c8b-214eea63c2b0@lechnology.com \
    --to=david@lechnology.com \
    --cc=jic23@jic23.retrosnub.co.uk \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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

Powered by JetHome