lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251015144019.GA2207492@legfed1>
Date: Wed, 15 Oct 2025 16:40:19 +0200
From: Dimitri Fedrau <dima.fedrau@...il.com>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: dimitri.fedrau@...bherr.com,
	Javier Carrasco <javier.carrasco.cruz@...il.com>,
	Li peiyu <579lpy@...il.com>, Jonathan Cameron <jic23@...nel.org>,
	David Lechner <dlechner@...libre.com>,
	Nuno Sá <nuno.sa@...log.com>,
	Andy Shevchenko <andy@...nel.org>,
	Jonathan Cameron <Jonathan.Cameron@...wei.com>,
	linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
	Chris Lesiak <chris.lesiak@...orbio.com>
Subject: Re: [PATCH v3 2/2] iio: humditiy: hdc3020: fix units for thresholds
 and hysteresis

Am Wed, Oct 15, 2025 at 12:45:31PM +0300 schrieb Andy Shevchenko:
> On Mon, Oct 13, 2025 at 11:12 AM Dimitri Fedrau via B4 Relay
> <devnull+dimitri.fedrau.liebherr.com@...nel.org> wrote:
> >
> > 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.
> 
> ...
> 
> 
> > -       return -2949075 + (175 * temp);
> > +       return -589815 + (35 * temp);
> 
> I was under the impression that we agreed on the explicit division by 5.
> 
>   return -2949075 / 5 + (175 / 5 * temp);
>

I wanted to scale the formula as it has been done before, but didn't make
it really clear. After thinking about it again, I think you are right,
will add the explicit division by 5.

> ...
> 
> > -       return hum * 100;
> > +       return hum * 20;
> 
> And in a similar way here.
> 

Ok.

> 
> >                         s_clr = max(s_clr, HDC3020_MIN_TEMP_MICRO);
> >                         s_clr = min(s_clr, HDC3020_MAX_TEMP_MICRO);
> > @@ -565,7 +574,8 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev,
> >                         /* Calculate old hysteresis */
> >                         s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000;
> >                         s_clr = (s64)hdc3020_thresh_get_hum(clr) * 1000000;
> > -                       s_hyst = div_s64(abs(s_thresh - s_clr), 65535);
> > +                       s_hyst = div_s64(abs(s_thresh - s_clr),
> > +                                        HDC3020_THRESH_FRACTION);
> >                         /* Set new threshold */
> >                         thresh = reg_val;
> >                         /* Try to set old hysteresis */
> > @@ -574,15 +584,16 @@ static int hdc3020_write_thresh(struct iio_dev *indio_dev,
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         /*
> >                          * Function hdc3020_thresh_get_hum returns relative
> > -                        * humidity in percent scaled by 65535. Scale by 1000000
> > -                        * to be able to subtract scaled hysteresis value.
> > +                        * humidity in percent scaled by HDC3020_THRESH_FRACTION.
> > +                        * Scale by 1000000 to be able to subtract scaled
> > +                        * hysteresis value.
> >                          */
> >                         s_thresh = (s64)hdc3020_thresh_get_hum(thresh) * 1000000;
> >                         /*
> > -                        * Units of s_val are in micro percent, scale by 65535
> > -                        * to get same units as s_thresh.
> > +                        * Units of s_val are in micro percent, scale by
> > +                        * HDC3020_THRESH_FRACTION to get same units as s_thresh.
> >                          */
> > -                       s_hyst = (s64)s_val * 65535;
> > +                       s_hyst = (s64)s_val * HDC3020_THRESH_FRACTION;
> >                         s_clr = hdc3020_thresh_clr(s_thresh, s_hyst, dir);
> >                         s_clr = max(s_clr, 0);
> >                         s_clr = min(s_clr, HDC3020_MAX_HUM_MICRO);
> > @@ -630,7 +641,7 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                 thresh = hdc3020_thresh_get_temp(ret);
> >                 switch (info) {
> >                 case IIO_EV_INFO_VALUE:
> > -                       *val = thresh;
> > +                       *val = thresh * MILLI;
> >                         break;
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         ret = hdc3020_read_be16(data, reg_clr);
> > @@ -638,18 +649,18 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                                 return ret;
> >
> >                         clr = hdc3020_thresh_get_temp(ret);
> > -                       *val = abs(thresh - clr);
> > +                       *val = abs(thresh - clr) * MILLI;
> >                         break;
> >                 default:
> >                         return -EOPNOTSUPP;
> >                 }
> > -               *val2 = 65535;
> > +               *val2 = HDC3020_THRESH_FRACTION;
> >                 return IIO_VAL_FRACTIONAL;
> >         case IIO_HUMIDITYRELATIVE:
> >                 thresh = hdc3020_thresh_get_hum(ret);
> >                 switch (info) {
> >                 case IIO_EV_INFO_VALUE:
> > -                       *val = thresh;
> > +                       *val = thresh * MILLI;
> >                         break;
> >                 case IIO_EV_INFO_HYSTERESIS:
> >                         ret = hdc3020_read_be16(data, reg_clr);
> > @@ -657,12 +668,12 @@ static int hdc3020_read_thresh(struct iio_dev *indio_dev,
> >                                 return ret;
> >
> >                         clr = hdc3020_thresh_get_hum(ret);
> > -                       *val = abs(thresh - clr);
> > +                       *val = abs(thresh - clr) * MILLI;
> >                         break;
> >                 default:
> >                         return -EOPNOTSUPP;
> >                 }
> > -               *val2 = 65535;
> > +               *val2 = HDC3020_THRESH_FRACTION;
> >                 return IIO_VAL_FRACTIONAL;
> >         default:
> >                 return -EOPNOTSUPP;
> >
> > --
> > 2.39.5
> >
> >
> 
>
Best regards,
Dimitri Fedrau

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ