Skip to content

Commit 827dca3

Browse files
Dimitri Fedraujic23
authored andcommitted
iio: temperature: mcp9600: Fix temperature reading for negative values
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: 3f6b959 ("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]>
1 parent 51fafb3 commit 827dca3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/iio/temperature/mcp9600.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static int mcp9600_read(struct mcp9600_data *data,
5252

5353
if (ret < 0)
5454
return ret;
55-
*val = ret;
55+
56+
*val = sign_extend32(ret, 15);
5657

5758
return 0;
5859
}

0 commit comments

Comments
 (0)