All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Mathias Duckeck <m.duckeck@kunbus.de>,
	Phil Elwell <phil@raspberrypi.org>,
	Oskar Andero <oskar.andero@gmail.com>,
	Andrea Galbusera <gizero@gmail.com>,
	Akinobu Mita <akinobu.mita@gmail.com>,
	Manfred Schlaegl <manfred.schlaegl@gmx.at>,
	Michael Welling <mwelling@ieee.org>,
	Soeren Andersen <san@rosetechnology.dk>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/6] iio: adc: mcp320x: Fix readout of negative voltages
Date: Sun, 3 Sep 2017 14:44:06 +0100	[thread overview]
Message-ID: <20170903144406.4619cb60@archlinux> (raw)
In-Reply-To: <a47443b08deb1a159ec0b2943465907b681b5863.1503407738.git.lukas@wunner.de>

On Tue, 22 Aug 2017 15:33:00 +0200
Lukas Wunner <lukas@wunner.de> wrote:

> Commit f686a36b4b79 ("iio: adc: mcp320x: Add support for mcp3301")
> returns a signed voltage from mcp320x_adc_conversion() but neglects that
> the caller interprets a negative return value as failure.  Only mcp3301
> (and the upcoming mcp3550/1/3) is affected as the other chips are
> incapable of measuring negative voltages.
> 
> Fix and while at it, add mcp3301 to the list of supported chips at the
> top of the file.
> 
> Fixes: f686a36b4b79 ("iio: adc: mcp320x: Add support for mcp3301")
> Cc: Andrea Galbusera <gizero@gmail.com>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/mcp320x.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
> index 45d043c9a888..071dd23a33d9 100644
> --- a/drivers/iio/adc/mcp320x.c
> +++ b/drivers/iio/adc/mcp320x.c
> @@ -17,6 +17,8 @@
>   * MCP3204
>   * MCP3208
>   * ------------
> + * 13 bit converter
> + * MCP3301
>   *
>   * Datasheet can be found here:
>   * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf  mcp3001
> @@ -96,7 +98,7 @@ static int mcp320x_channel_to_tx_data(int device_index,
>  }
>  
>  static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
> -				  bool differential, int device_index)
> +				  bool differential, int device_index, int *val)
>  {
>  	int ret;
>  
> @@ -117,19 +119,25 @@ static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
>  
>  	switch (device_index) {
>  	case mcp3001:
> -		return (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
> +		*val = (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
> +		return 0;
>  	case mcp3002:
>  	case mcp3004:
>  	case mcp3008:
> -		return (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
> +		*val = (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
> +		return 0;
>  	case mcp3201:
> -		return (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
> +		*val = (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
> +		return 0;
>  	case mcp3202:
>  	case mcp3204:
>  	case mcp3208:
> -		return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
> +		*val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
> +		return 0;
>  	case mcp3301:
> -		return sign_extend32((adc->rx_buf[0] & 0x1f) << 8 | adc->rx_buf[1], 12);
> +		*val = sign_extend32((adc->rx_buf[0] & 0x1f) << 8
> +				    | adc->rx_buf[1], 12);
> +		return 0;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -150,12 +158,10 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
>  		ret = mcp320x_adc_conversion(adc, channel->address,
> -			channel->differential, device_index);
> -
> +			channel->differential, device_index, val);
>  		if (ret < 0)
>  			goto out;
>  
> -		*val = ret;
>  		ret = IIO_VAL_INT;
>  		break;
>  


  reply	other threads:[~2017-09-03 13:44 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-22 13:33 [PATCH 0/6] IIO driver for MCP3550/1/3 Lukas Wunner
2017-08-22 13:33 ` Lukas Wunner
2017-08-22 13:33 ` [PATCH 5/6] dt-bindings: iio: adc: mcp320x: Update for mcp3550/1/3 Lukas Wunner
2017-08-22 13:33   ` Lukas Wunner
2017-08-25 19:59   ` Rob Herring
2017-08-25 19:59     ` Rob Herring
2017-08-27 15:34     ` Lukas Wunner
2017-08-27 15:34       ` Lukas Wunner
2017-08-29  7:21       ` Adriana Reus
2017-08-29  7:21         ` Adriana Reus
2017-09-03 13:37         ` Jonathan Cameron
2017-09-03 13:37           ` Jonathan Cameron
2017-09-03 18:20           ` Lukas Wunner
2017-09-03 18:20             ` Lukas Wunner
2017-09-04 12:36             ` Jonathan Cameron
2017-09-04 12:36               ` Jonathan Cameron
2017-09-04 12:36               ` Jonathan Cameron
2017-09-04 17:22           ` Mark Brown
2017-09-04 17:22             ` Mark Brown
2017-09-10 13:36             ` Jonathan Cameron
2017-09-10 13:36               ` Jonathan Cameron
2017-09-05 18:49       ` Rob Herring
2017-09-05 18:49         ` Rob Herring
2017-08-22 13:33 ` [PATCH 3/6] iio: adc: mcp320x: Speed up readout of single-channel ADCs Lukas Wunner
2017-09-03 13:48   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 6/6] iio: adc: mcp320x: Add support for mcp3550/1/3 Lukas Wunner
2017-08-22 13:33   ` Lukas Wunner
2017-09-03 14:22   ` Jonathan Cameron
2017-09-03 14:22     ` Jonathan Cameron
2017-09-07  6:44     ` Lukas Wunner
2017-09-10 13:40       ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 2/6] iio: adc: mcp320x: Fix readout of negative voltages Lukas Wunner
2017-09-03 13:44   ` Jonathan Cameron [this message]
2017-08-22 13:33 ` [PATCH 4/6] iio: adc: mcp320x: Drop unnecessary of_device_id attributes Lukas Wunner
2017-09-03 13:59   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 1/6] iio: adc: mcp320x: Fix oops on module unload Lukas Wunner
2017-09-03 13:41   ` 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=20170903144406.4619cb60@archlinux \
    --to=jic23@kernel.org \
    --cc=akinobu.mita@gmail.com \
    --cc=gizero@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=m.duckeck@kunbus.de \
    --cc=manfred.schlaegl@gmx.at \
    --cc=mwelling@ieee.org \
    --cc=oskar.andero@gmail.com \
    --cc=phil@raspberrypi.org \
    --cc=pmeerw@pmeerw.net \
    --cc=san@rosetechnology.dk \
    /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.