mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dimitri Fedrau <dima.fedrau@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: dimitri.fedrau@liebherr.com,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
	"Li peiyu" <579lpy@gmail.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Chris Lesiak" <chris.lesiak@licorbio.com>
Subject: Re: [PATCH v2 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis
Date: Tue, 2 Sep 2025 15:54:04 +0200	[thread overview]
Message-ID: <20250902135404.GA145952@legfed1> (raw)
In-Reply-To: <aLbneKXFd7Nc711T@smile.fi.intel.com>

Hi Andy,

Am Tue, Sep 02, 2025 at 03:47:52PM +0300 schrieb Andy Shevchenko:
> On Mon, Sep 01, 2025 at 07:51:59PM +0200, Dimitri Fedrau via B4 Relay wrote:
> > From: Dimitri Fedrau <dimitri.fedrau@liebherr.com>
> > 
> > According to the ABI the units after application of scale and offset are
> > milli degree celsius for temperature thresholds and milli percent for
> > relative humidity thresholds. Currently the resulting units are degree
> > celsius for temperature thresholds and hysteresis and percent for relative
> > humidity thresholds and hysteresis. Change scale factor to fix this issue.
> 
> ...
> 
> >  	/*
> > -	 * Get the temperature threshold from 9 LSBs, shift them to get
> > -	 * the truncated temperature threshold representation and
> > -	 * calculate the threshold according to the formula in the
> > -	 * datasheet. Result is degree celsius scaled by 65535.
> > +	 * Get the temperature threshold from 9 LSBs, shift them to get the
> > +	 * truncated temperature threshold representation and calculate the
> > +	 * threshold according to the formula in the datasheet and additionally
> 
> Replace "formula in the datasheet" by explicit formula
> 

Ok.
> > +	 * scale by HDC3020_THRESH_FRACTION to avoid precision loss when
> > +	 * calculating threshold and hysteresis values.
> >  	 */
> >  	temp = FIELD_GET(HDC3020_THRESH_TEMP_MASK, thresh) <<
> >  	       HDC3020_THRESH_TEMP_TRUNC_SHIFT;
> >  
> > -	return -2949075 + (175 * temp);
> > +	return -589815 + (35 * temp);
> 
> TBH, I prefer to have the proper units be mentioned in the comment along with
> 
> 	return -2949075 / 5 + ((175 / 5) * temp);
> 

You are right, will add the units again.

> 5 itself can be a definition
> 
> #define ..._PRE_SCALE	5
> 
> and used everywhere.
> 
> ...
> 

The explicit formula in the datasheet:

T(degree celsius) = -45 + (175 * temp) / 65535

The formula before the patch:

T(degree celsius) * 65525 = -2949075 + (175 * temp)

Adding the PRE_SCALE into the formula doesn't improve readability from
my perspective. I would prefer to just scale the result as it has been
done before.

> >  	/*
> >  	 * Get the humidity threshold from 7 MSBs, shift them to get the
> >  	 * truncated humidity threshold representation and calculate the
> > -	 * threshold according to the formula in the datasheet. Result is
> > -	 * percent scaled by 65535.
> > +	 * threshold according to the formula in the datasheet and additionally
> > +	 * scale by HDC3020_THRESH_FRACTION to avoid precision loss when
> > +	 * calculating threshold and hysteresis values.
> >  	 */
> 
> Ditto. "percent scaled by ..." is much better to understand.
> 

Ok.
> >  	hum = FIELD_GET(HDC3020_THRESH_HUM_MASK, thresh) <<
> >  	      HDC3020_THRESH_HUM_TRUNC_SHIFT;
> >  
> > -	return hum * 100;
> > +	return hum * 20;
> >  }

Best regards,
Dimitri Fedrau

  reply	other threads:[~2025-09-02 13:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01 17:51 [PATCH v2 0/2] iio: humditiy: hdc3020: fix units Dimitri Fedrau via B4 Relay
2025-09-01 17:51 ` [PATCH v2 1/2] iio: humditiy: hdc3020: fix units for temperature and humidity measurement Dimitri Fedrau via B4 Relay
2025-09-02 12:05   ` Javier Carrasco
2025-09-01 17:51 ` [PATCH v2 2/2] iio: humditiy: hdc3020: fix units for thresholds and hysteresis Dimitri Fedrau via B4 Relay
2025-09-02 12:04   ` Javier Carrasco
2025-09-02 12:51     ` Dimitri Fedrau
2025-09-02 12:47   ` Andy Shevchenko
2025-09-02 13:54     ` Dimitri Fedrau [this message]
2025-09-02 14:22       ` Andy Shevchenko

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=20250902135404.GA145952@legfed1 \
    --to=dima.fedrau@gmail.com \
    --cc=579lpy@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=chris.lesiak@licorbio.com \
    --cc=dimitri.fedrau@liebherr.com \
    --cc=dlechner@baylibre.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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

all inboxes | Powered by JetHome®