From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Dimitri Fedrau <dima.fedrau@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Andrew Hepp <andrew.hepp@ahepp.dev>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: temperature: mcp9600: Fix temperature reading for negative values
Date: Sat, 27 Apr 2024 05:49:18 -0300 [thread overview]
Message-ID: <Ziy8DsMCeAGK79E7@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <20240424185913.1177127-1-dima.fedrau@gmail.com>
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
>
>
next prev parent reply other threads:[~2024-04-27 8:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-24 18:59 [PATCH] iio: temperature: mcp9600: Fix temperature reading for negative values Dimitri Fedrau
2024-04-27 8:49 ` Marcelo Schmitt [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ziy8DsMCeAGK79E7@debian-BULLSEYE-live-builder-AMD64 \
--to=marcelo.schmitt1@gmail.com \
--cc=andrew.hepp@ahepp.dev \
--cc=dima.fedrau@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).