Re: [PATCH v3] iio: humidity: hdc3020: fix hysteresis representation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 6 Jun 2024 16:34:39 +0200
Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx> wrote:

> On 05/06/2024 21:21, Dimitri Fedrau wrote:
> > According to the ABI docs hysteresis values are represented as offsets to
> > threshold values. Current implementation represents hysteresis values as
> > absolute values which is wrong. Nevertheless the device stores them as
> > absolute values and the datasheet refers to them as clear thresholds. Fix
> > the reading and writing of hysteresis values by including thresholds into
> > calculations. Hysteresis values that result in threshold clear values
> > that are out of limits will be truncated.
> > 
> > To check that the threshold clear values are correct, registers are read
> > out using i2ctransfer and the corresponding temperature and relative
> > humidity thresholds are calculated using the formulas in the datasheet.
> > 
> > Fixes: 3ad0e7e5f0cb ("iio: humidity: hdc3020: add threshold events support")
> > Signed-off-by: Dimitri Fedrau <dima.fedrau@xxxxxxxxx>
> > ---
> > 
> > Changes in V3:
> >   - Add missing changes
> >   - Remove math.h, already included in math64.h
> >   - Drop range comments
> >   - Fix typo devide divide
> >   - Add empty line before return in hdc3020_write_thresh
> >   - Keep hysteresis value when changing the threshold
> > 
> > ---
> >  drivers/iio/humidity/hdc3020.c | 325 +++++++++++++++++++++++++--------
> >  1 file changed, 249 insertions(+), 76 deletions(-)
> > 
> > diff --git a/drivers/iio/humidity/hdc3020.c b/drivers/iio/humidity/hdc3020.c
> > index cdc4789213ba..cf00999b826d 100644
> > --- a/drivers/iio/humidity/hdc3020.c
> > +++ b/drivers/iio/humidity/hdc3020.c
> > @@ -19,6 +19,7 @@
> >  #include <linux/i2c.h>
> >  #include <linux/init.h>
> >  #include <linux/interrupt.h>
> > +#include <linux/math64.h>
> >  #include <linux/module.h>
> >  #include <linux/mutex.h>
> >  #include <linux/pm.h>
> > @@ -66,8 +67,10 @@
> >  
> >  #define HDC3020_CRC8_POLYNOMIAL		0x31
> >  
> > -#define HDC3020_MIN_TEMP		-40
> > -#define HDC3020_MAX_TEMP		125
> > +#define HDC3020_MIN_TEMP_MICRO		-39872968
> > +#define HDC3020_MAX_TEMP_MICRO		124875639
> > +#define HDC3020_MAX_TEMP_HYST_MICRO	164748607
> > +#define HDC3020_MAX_HUM_MICRO		99220264
> >  
> >  struct hdc3020_data {
> >  	struct i2c_client *client;
> > @@ -368,6 +371,105 @@ static int hdc3020_write_raw(struct iio_dev *indio_dev,
> >  	return -EINVAL;
> >  }
> >    
> 
> Nit: "thresh" instead of "tresh" (applies to several lines of your patch).
I fixed that up whilst applying.
> 
> > +static int hdc3020_tresh_get_temp(u16 thresh)
> > +{
> > +	int temp;
> > +
> > +	/*  
> 
> 
> Reviewed-by: Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
> 
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux