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: <d5kbjtjofknv4qkbak7ujr2lyckpio5kly55hpqlcrkajjzlzn@vr3c27deyumc>
Date: Tue, 24 Jun 2025 21:17:03 -0300
From: Gustavo Silva <gustavograzs@...il.com>
To: Jonathan Cameron <jic23@...nel.org>
Cc: Alex Lanzano <lanzano.alex@...il.com>, 
	David Lechner <dlechner@...libre.com>, Nuno Sá <nuno.sa@...log.com>, 
	Andy Shevchenko <andy@...nel.org>, linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Lothar Rubusch <l.rubusch@...il.com>
Subject: Re: [PATCH v3 3/3] iio: imu: bmi270: add support for motion events

On Sun, Jun 22, 2025 at 02:42:40PM +0100, Jonathan Cameron wrote:
> Hi Gustavo,
> 
> Main question in here is about the scaling of the motion threshold.
> It seems to be based on units of g.  We use m/s^2 for IIO acceleration channels
> and also the expectation is that threshold events match scaling of the main channels
> (_scale applies to them).  Hence here we will need to do something a little
> fiddly to maintain the threshold scale if the main channel scaling changes.
>
Hi Jonathan,

Thanks for the review.
> 
> Jonathan
> 
> 
> > @@ -114,6 +134,10 @@
> >  #define BMI270_STEP_COUNTER_FACTOR			20
> >  #define BMI270_STEP_COUNTER_MAX				20460
> >  
> > +#define BMI270_INT_MICRO_TO_RAW(val, val2, scale) ((val) * (scale) + \
> > +						  ((val2) * (scale)) / MEGA)
> > +#define BMI270_RAW_TO_MICRO(raw, scale) ((((raw) % (scale)) * MEGA) / scale)
> 
> I'm struggling a bit with what this is doing.  Perhaps a comment?
> 
These macros convert register values to the range defined in
'in_accel_{period,value}_available' and vice versa.
The same macros are defined in the bmi323 driver, so I used them here
for the sake of consistency.
> 
> 
> 
> > @@ -827,6 +977,20 @@ static int bmi270_read_avail(struct iio_dev *indio_dev,
> >  	}
> >  }
> >  
> > +static IIO_CONST_ATTR(in_accel_value_available, "[0.0 0.00049 1.0]");
> This aligns with below.  Scaling definitely shouldn't be in g and is likely more
> complex because of the relationship expected with the overall channels scaling
> controls.
> 
> > @@ -848,21 +1016,58 @@ static int bmi270_read_event_config(struct iio_dev *indio_dev,
> >  				    enum iio_event_direction dir)
> >  {
> 
> 
> > +	switch (info) {
> > +	case IIO_EV_INFO_VALUE:
> > +		ret = bmi270_read_feature_reg(data, reg, &regval);
> > +		if (ret)
> > +			return ret;
> > +
> > +		raw = FIELD_GET(BMI270_FEAT_MOTION_THRESHOLD_MSK, regval);
> > +		*val = raw / BMI270_MOTION_THRES_SCALE;
> > +		*val2 = BMI270_RAW_TO_MICRO(raw, BMI270_MOTION_THRES_SCALE);
> 
> Why this particular scaling? Is effectively just dividing 1g / number of
> values and hence providing a scaling to g?
> 
That's correct. In the bmi323 there's an actual scaling factor of 512 to
the register value. In the bmi270 the register value is not scaled.

> Full scale is described as being 1G.
> As this device is providing _RAW data for the relevant channels I'd
> expect this to be scaled to match that. That will be a little fiddly here as
> this is apparently always 0-1g whereas the scaling of the channel varies.
> Thus irritatingly we'd need to adjust the scaling of this so it remains
> consistent as the full scale changes.
> 
> The events ABI documentation is rather weak / wrong on this as it refers to
> both _input_ and _raw_ thresholds whereas the true ABI just has one with
> the scaling always being to match _raw if that is present. So _threshold * _scale
> should be in the standards base units of m/s^2.
> 
Thanks for the clarification. I'll work on that in v4.
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ