Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Otávio Silva" <otavio.ols@usp.br>
Cc: "Thiago Duvanel" <thiago.duvanel@usp.br>,
	"Felipe Aníbal Brito" <felipeanibal@usp.br>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: adc: use sign_extend32 to provide negative numbers conversion
Date: Sun, 21 Apr 2024 18:38:20 +0100	[thread overview]
Message-ID: <20240421183820.4e2c0133@jic23-huawei> (raw)
In-Reply-To: <20240420233836.24971-1-otavio.ols@usp.br>

On Sat, 20 Apr 2024 20:34:11 -0300
Otávio Silva <otavio.ols@usp.br> wrote:

> This implements the use of the sign_extend32 function to handle the output
> of negative numbers.
> 
> Co-developed-by: Thiago Duvanel <thiago.duvanel@usp.br>
> Signed-off-by: Thiago Duvanel <thiago.duvanel@usp.br>
> Co-developed-by: Felipe Aníbal Brito <felipeanibal@usp.br>
> Signed-off-by: Felipe Aníbal Brito <felipeanibal@usp.br>
> Signed-off-by: Otávio Silva <otavio.ols@usp.br>
Hi All,

What makes you think this is signed?  It might be. If it is
you need to provide that information to justify this change.
It would also be a fix if so and need a fixes tag.

Given this device has a mixture of differential and non differential
channels, the single ended ones are very unlikely to give signed output,
the differential channels 'might' be. The datasheet does refer
to a bipolar mode with 2s complement output, so if that is in use, then the results would be 2s
complement and should be sign extended.

So you need to figure out if that mode is in use or not.

Jonathan


> ---
>  drivers/iio/adc/ltc2309.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ltc2309.c b/drivers/iio/adc/ltc2309.c
> index 8b3a89c1b..cb93dbc94 100644
> --- a/drivers/iio/adc/ltc2309.c
> +++ b/drivers/iio/adc/ltc2309.c
> @@ -124,7 +124,7 @@ static int ltc2309_read_raw_channel(struct ltc2309 *ltc2309,
>  		return ret;
>  	}
>  
> -	*val = be16_to_cpu(buf) >> 4;
> +	*val = sign_extend32(be16_to_cpu(buf) >> 4, 11);
>  
>  	return ret;
>  }


  reply	other threads:[~2024-04-21 17:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-20 23:34 [PATCH] iio: adc: use sign_extend32 to provide negative numbers conversion Otávio Silva
2024-04-21 17:38 ` Jonathan Cameron [this message]
2024-04-28  2:02   ` Otávio Silva

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=20240421183820.4e2c0133@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=felipeanibal@usp.br \
    --cc=linux-iio@vger.kernel.org \
    --cc=otavio.ols@usp.br \
    --cc=thiago.duvanel@usp.br \
    /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