On Mon, Jun 23, 2025 at 11:21:01PM +0200, Lothar Rubusch wrote: > On Mon, Jun 23, 2025 at 12:17 PM Andy Shevchenko > <andriy.shevchenko@xxxxxxxxx> wrote: > > On Sun, Jun 22, 2025 at 03:50:09PM +0000, Lothar Rubusch wrote: ... > > > -static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_s) > > > +static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_int, > > > + u32 val_fract) > > > { > > > int max_boundary = U8_MAX; > > > int min_boundary = 10; > > > - unsigned int val = min(val_s, U8_MAX); > > > + unsigned int val; > > > > You see, I even suggested splitting this assignment to begin with. > > The change will be clearer with that done. > > > > > enum adxl345_odr odr; > > > unsigned int regval; > > > int ret; > > > > > > - if (val == 0) { > > > + if (val_int == 0 && val_fract == 0) { > > The case for 0sec, 0.0 or setting "0" and fract will consequently be > "0". 0 is an invalid input for this period and sensor, so it will > default to an optimized period based on given ODR. > > > > + /* Generated inactivity time based on ODR */ > > > ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, ®val); > > > if (ret) > > > return ret; > > > > > odr = FIELD_GET(ADXL345_BW_RATE_MSK, regval); > > > val = clamp(max_boundary - adxl345_odr_tbl[odr][0], > > > min_boundary, max_boundary); > > > + st->inact_time_ms = MILLI * val; > > > + > > > + /* Inactivity time in s */ > > > + return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); > > > + } else if (val_int == 0 && val_fract > 0) { > > > > val_fract check is not needed here. > > Case for e.g. 0.123, numbers under 1s. This goes into the free-fall register. 0.0 is already checked above, and since the val_fract is unsigned this is check is redundant. > > > + /* time < 1s, free-fall */ > > > + > > > + /* > > > + * Datasheet max. value is 255 * 5000 us = 1.275000 seconds. > > > + * > > > + * Recommended values between 100ms and 350ms (0x14 to 0x46) > > > + */ > > > + st->inact_time_ms = DIV_ROUND_UP(val_fract, MILLI); > > > + > > > + return regmap_write(st->regmap, ADXL345_REG_TIME_FF, > > > + DIV_ROUND_CLOSEST(val_fract, 5)); > > > + } else if (val_int > 0) { > > > > if now is redundant here, right? > > So, this will be 1s through 255s. Periods above 1sec. This goes into > the inactivity register. See above, > > > + /* Time >= 1s, inactivity */ > > > + st->inact_time_ms = MILLI * val_int; > > > + > > > + return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val_int); > > > } > > > > > > - return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val); > > > + /* Do not support negative or wrong input. */ > > > + return -EINVAL; > > > } -- With Best Regards, Andy Shevchenko