linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: use sign_extend32 to provide negative numbers conversion
@ 2024-04-20 23:34 Otávio Silva
  2024-04-21 17:38 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Otávio Silva @ 2024-04-20 23:34 UTC (permalink / raw)
  To: jic23
  Cc: Otávio Silva, Thiago Duvanel, Felipe Aníbal Brito, linux-iio

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>
---
 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;
 }
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: use sign_extend32 to provide negative numbers conversion
  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
  2024-04-28  2:02   ` Otávio Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2024-04-21 17:38 UTC (permalink / raw)
  To: Otávio Silva; +Cc: Thiago Duvanel, Felipe Aníbal Brito, linux-iio

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;
>  }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: use sign_extend32 to provide negative numbers conversion
  2024-04-21 17:38 ` Jonathan Cameron
@ 2024-04-28  2:02   ` Otávio Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Otávio Silva @ 2024-04-28  2:02 UTC (permalink / raw)
  To: jic23; +Cc: felipeanibal, linux-iio, otavio.ols, thiago.duvanel

Hello!

Upon further study of the LTC2309 device we realized we were mistaken in
our last patch. It seems that the driver is set to work only on unipolar
mode (despite having support for differential and non-differential input),
so it does not require 2’s complement as we first thought.

We are sorry for the misunderstanding (and for the wrong emails), and
thankful for your attention,
Otávio Silva

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-28  2:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2024-04-28  2:02   ` Otávio Silva

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).