lkml.org 
[lkml]   [2024]   [Apr]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] iio: temperature: mcp9600: Fix temperature reading for negative values
Hi Dimitri,

Interesting patch this one.
I think this does apply, although, the cold junction register has for sign bits
so I think we could also have a mask to clear those out.
Some code suggestions inline.

Regards,
Marcelo

On 04/24, Dimitri Fedrau wrote:
> Temperature is stored as 16bit value in two's complement format. Current
> implementation ignores the sign bit. Make it aware of the sign bit by
> using sign_extend32.
>
> Fixes: 3f6b9598b6df ("iio: temperature: Add MCP9600 thermocouple EMF converter")
> Signed-off-by: Dimitri Fedrau <dima.fedrau@gmail.com>
> ---
> drivers/iio/temperature/mcp9600.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c
> index 46845804292b..7a3eef5d5e75 100644
> --- a/drivers/iio/temperature/mcp9600.c
> +++ b/drivers/iio/temperature/mcp9600.c

#define MCP9600_COLD_JUNCTION_SIGN_MSK GENMASK(15,12)
..

> @@ -52,7 +52,8 @@ static int mcp9600_read(struct mcp9600_data *data,
>
> if (ret < 0)
> return ret;
> - *val = ret;
> +
> + *val = sign_extend32(ret, 15);
if (chan->address == MCP9600_COLD_JUNCTION)
*val &= ~MCP9600_COLD_JUNCTION_SIGN_MSK;

>
> return 0;
> }
> --
> 2.39.2
>
>

\
 
 \ /
  Last update: 2024-05-27 18:06    [W:0.248 / U:0.480 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site