Linux IIO development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Vidhu Sarwal <vidhu.linux@gmail.com>
Cc: "Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Matti Vaittinen" <mazziesaccount@gmail.com>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Siratul Islam" <email@sirat.me>,
	"Tiberiu Breana" <tiberiu.a.breana@intel.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org
Subject: Re: [PATCH] iio: humidity: am2315: fix negative temperature decoding
Date: Tue, 29 Sep 2026 00:45:52 +0300	[thread overview]
Message-ID: <arrgEPs779q9ck8q@ashevche-desk.local> (raw)
In-Reply-To: <CAFqz8LL0bgOu3TKfxz0Ri=qw09wVHC68CbVS2yZZjv7oKTGwVw@mail.gmail.com>

On Tue, Sep 29, 2026 at 02:37:41AM +0530, Vidhu Sarwal wrote:
> On Mon, Sep 28, 2026 at 9:01 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:

...

> > Can you use sign_extend32()?

> I checked whether sign_extend32() can be used here, but I don't
> think itcan be applied since as per datasheet [1], The temperature value
> is sign-magnitude such that bit 15 is the sign and bits 14 to 0
> contain the magnitude. For eg., 0x8065 represents -101.
> sign_extend32(temp_raw, 15) would instead interpret 0x8065 as a
> two's-complement value, giving us -32667.
> 
> So I think the sign bit needs to be decoded explicitly by masking
> bit 15 and negating the magnitude when set.

Oh, okay, we (IIO community) already discussed the possibility to have a helper
like sign_extend32() for this type of cases, but it appears not so worth it,
IIRC.

> [1] https://cdn-shop.adafruit.com/datasheets/AM2315.pdf

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-09-28 21:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 14:24 [PATCH] iio: humidity: am2315: fix negative temperature decoding Vidhu Sarwal
2026-09-28 15:30 ` Andy Shevchenko
2026-09-28 21:07   ` Vidhu Sarwal
2026-09-28 21:45     ` Andy Shevchenko [this message]

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=arrgEPs779q9ck8q@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=email@sirat.me \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tiberiu.a.breana@intel.com \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=vidhu.linux@gmail.com \
    /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