Re: [PATCH v10 6/7] iio: accel: adxl345: extend inactivity time for less than 1s

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

 



On Sun, Jun 22, 2025 at 03:50:09PM +0000, Lothar Rubusch wrote:
> Inactivity and free-fall events are essentially the same type of sensor
> events. Therefore, inactivity detection (normally set for periods between 1
> and 255 seconds) can be extended for shorter durations to support free-fall
> detection.
> 
> For periods shorter than 1 second, the driver automatically configures the
> threshold and duration using the free-fall register. For periods longer
> than 1 second, it uses the inactivity threshold and duration using the
> inactivity registers.
> 
> When using the free-fall register, the link bit is not set, which means
> auto-sleep cannot be enabled if activity detection is also active.

...

> -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) {
> +		/* Generated inactivity time based on ODR */
>  		ret = regmap_read(st->regmap, ADXL345_REG_BW_RATE, &regval);
>  		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.

> +		/* 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?

> +		/* 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






[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux