public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: mcp9600: Fix temperature reading for negative values
@ 2024-04-24 18:59 Dimitri Fedrau
  2024-04-27  8:49 ` Marcelo Schmitt
  0 siblings, 1 reply; 7+ messages in thread
From: Dimitri Fedrau @ 2024-04-24 18:59 UTC (permalink / raw)
  Cc: Dimitri Fedrau, Jonathan Cameron, Lars-Peter Clausen, Andrew Hepp,
	linux-iio, linux-kernel

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


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

end of thread, other threads:[~2024-04-29 19:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-24 18:59 [PATCH] iio: temperature: mcp9600: Fix temperature reading for negative values Dimitri Fedrau
2024-04-27  8:49 ` Marcelo Schmitt
2024-04-27 19:57   ` Dimitri Fedrau
2024-04-28 13:46     ` Jonathan Cameron
2024-04-28 18:46       ` Andrew Hepp
2024-04-29 19:44         ` Jonathan Cameron
2024-04-28 18:53       ` Marcelo Schmitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox