]> Git Repo - J-linux.git/commitdiff
iio: temperature: mcp9600: Fix temperature reading for negative values
authorDimitri Fedrau <[email protected]>
Wed, 24 Apr 2024 18:59:10 +0000 (20:59 +0200)
committerJonathan Cameron <[email protected]>
Fri, 3 May 2024 10:48:56 +0000 (11:48 +0100)
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 <[email protected]>
Reviewed-by: Marcelo Schmitt <[email protected]>
Tested-by: Andrew Hepp <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Cc: <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
drivers/iio/temperature/mcp9600.c

index 46845804292bf06048a5ef5d976ffb28a83680c0..7a3eef5d5e752a2c4fec1f989311e15977f683e0 100644 (file)
@@ -52,7 +52,8 @@ static int mcp9600_read(struct mcp9600_data *data,
 
        if (ret < 0)
                return ret;
-       *val = ret;
+
+       *val = sign_extend32(ret, 15);
 
        return 0;
 }
This page took 0.05549 seconds and 4 git commands to generate.