Re: [PATCH v2 1/2] iio: accel: fxls8962af: add threshold event handling

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

 



On Tue, Aug 24, 2021 at 03:15:28PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 24, 2021 at 2:38 PM Sean Nyekjaer <sean@xxxxxxxxxx> wrote:
> 
> ...
> 
> > Do we have some helper functions to do the 12 bit 2-complement numbers?
> 
> Probably not, look around where sign_extend32() is defined. More on this below.
> 
> ...
> 
> > +       return regmap_update_bits(data->regmap, FXLS8962AF_INT_EN,
> > +                                mask,
> > +                                value);
> 
> One line?
> 
> ...
> 
> > +       /*
> > +        * Add the same value to the lower-threshold register with a reversed sign
> > +        * in 2-complement 12 bit format.
> > +        */
> > +       data->lower_thres = (~val & GENMASK(11, 0)) + 1;
> 
> This looks suspicious.
> 
> 0 => 0xfff + 1 => 0x1000. Is it what is wanted?
> I thought that -val & mask is what you need.
> 
> Can you explain more in the comment (maybe with examples) on what is
> coming and what is expected?

It's a bit messy I know :)

Some examples:
val = 0 => upper = 0x0, lower = 0x0
val = 500 => upper = 0x1F4, lower = 0xe0c
val = 1000 => upper = 0x3e8, lower = 0xc18

Guess it could work if we special case val = 0...

It doesn't even makes sense to write 0 to this register as noise would
trigger events.

> 
> > +       data->upper_thres = val & GENMASK(10, 0);
> 

/Sean



[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