All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	corbet@lwn.net, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	eraretuya@gmail.com
Subject: Re: [PATCH v10 4/7] iio: accel: adxl345: add inactivity feature
Date: Mon, 23 Jun 2025 12:44:24 +0300	[thread overview]
Message-ID: <aFkh-E1dG__p_G4m@smile.fi.intel.com> (raw)
In-Reply-To: <20250622155010.164451-5-l.rubusch@gmail.com>

On Sun, Jun 22, 2025 at 03:50:07PM +0000, Lothar Rubusch wrote:
> Add support for the sensor’s inactivity feature in the driver. When both
> activity and inactivity detection are enabled, the sensor sets a link bit
> that ties the two functions together. This also enables auto-sleep mode,
> allowing the sensor to automatically enter sleep state upon detecting
> inactivity.
> 
> Inactivity detection relies on a configurable threshold and a specified
> time period. If sensor measurements remain below the threshold for the
> defined duration, the sensor transitions to the inactivity state.
> 
> When an Output Data Rate (ODR) is set, the inactivity time period is
> automatically adjusted to a sensible default. Higher ODRs result in shorter
> inactivity timeouts, while lower ODRs allow longer durations-within
> reasonable upper and lower bounds. This is important because features like
> auto-sleep operate effectively only between 12.5 Hz and 400 Hz. These
> defaults are applied when the sample rate is modified, but users can
> override them by explicitly setting a custom inactivity timeout.
> 
> Similarly, configuring the g-range provides default threshold values for
> both activity and inactivity detection. These are implicit defaults meant
> to simplify configuration, but they can also be manually overridden as
> needed.

...

> +static int adxl345_set_inact_time(struct adxl345_state *st, u32 val_s)
> +{
> +	int max_boundary = U8_MAX;
> +	int min_boundary = 10;
> +	unsigned int val = min(val_s, U8_MAX);

Wondering if it's possible to refer here to max_boundary?
In any case, split this assignment since it will be easier
to maintain.

> +	enum adxl345_odr odr;
> +	unsigned int regval;
> +	int ret;

	val = min(val_s, max_boundary);

> +	if (val == 0) {
> +		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);
> +	}
> +
> +	return regmap_write(st->regmap, ADXL345_REG_TIME_INACT, val);
> +}

...

> +	case ADXL345_INACTIVITY:
> +		en = FIELD_GET(ADXL345_INACT_X_EN, axis_ctrl) |
> +			FIELD_GET(ADXL345_INACT_Y_EN, axis_ctrl) |
> +			FIELD_GET(ADXL345_INACT_Z_EN, axis_ctrl);

As I pointed out earlier. the indentation is supposed to be on the same colomn
for 'F' letters.

> +		if (!en)
> +			return false;
> +		break;

...

> +			ret = regmap_read(st->regmap,
> +					  ADXL345_REG_TIME_INACT,
> +					  &period);

There is plenty of room on the previous lines. Depending on the next
changes (which I believe unlikely touch this) it may be packed to two
lines with a logical split, like

			ret = regmap_read(st->regmap,
					  ADXL345_REG_TIME_INACT, &period);

It again seems the byproduct of the too strict settings of the wrap limit in
your editor.

...

> +	case ADXL345_INACTIVITY:
> +		axis_ctrl = ADXL345_INACT_X_EN | ADXL345_INACT_Y_EN |
> +				ADXL345_INACT_Z_EN;

Consider
		axis_ctrl =
			ADXL345_INACT_X_EN | ADXL345_INACT_Y_EN | ADXL345_INACT_Z_EN;

(yes, I see that it's longer than 80, but it might worth doing it for the sake of
 consistency with the previous suggestion).


...

>  static int adxl345_set_range(struct adxl345_state *st, enum adxl345_range range)
>  {
> -	return regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT,

> +	int ret;
> +
> +	ret = regmap_update_bits(st->regmap, ADXL345_REG_DATA_FORMAT,
>  				 ADXL345_DATA_FORMAT_RANGE,
>  				 FIELD_PREP(ADXL345_DATA_FORMAT_RANGE, range));
> +	if (ret)
> +		return ret;

If it's a code from the previous patch, it might make sense to introduce ret
there.

>  }

...

> +	case IIO_EV_INFO_PERIOD:
> +		ret = regmap_read(st->regmap,
> +				  ADXL345_REG_TIME_INACT,
> +				  &period);

Too short lines.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-06-23  9:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-22 15:50 [PATCH v10 0/7] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-06-22 15:50 ` [PATCH v10 1/7] iio: accel: adxl345: simplify interrupt mapping Lothar Rubusch
2025-06-23  9:24   ` Andy Shevchenko
2025-06-22 15:50 ` [PATCH v10 2/7] iio: accel: adxl345: simplify reading the FIFO Lothar Rubusch
2025-06-22 15:50 ` [PATCH v10 3/7] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-06-23  9:34   ` Andy Shevchenko
2025-06-23 20:57     ` Lothar Rubusch
2025-06-24  7:28       ` Andy Shevchenko
2025-06-28 16:05       ` Jonathan Cameron
2025-06-22 15:50 ` [PATCH v10 4/7] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-06-23  9:44   ` Andy Shevchenko [this message]
2025-06-23 21:06     ` Lothar Rubusch
2025-06-24  7:33       ` Andy Shevchenko
2025-06-24  8:27         ` Lothar Rubusch
2025-06-28 16:08     ` Jonathan Cameron
2025-06-28 21:10       ` Lothar Rubusch
2025-06-29  7:30         ` Andy Shevchenko
2025-06-29 16:28           ` Jonathan Cameron
2025-06-22 15:50 ` [PATCH v10 5/7] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-06-23 10:11   ` Andy Shevchenko
2025-06-22 15:50 ` [PATCH v10 6/7] iio: accel: adxl345: extend inactivity time for less than 1s Lothar Rubusch
2025-06-23 10:17   ` Andy Shevchenko
2025-06-23 21:21     ` Lothar Rubusch
2025-06-24  7:37       ` Andy Shevchenko
2025-06-24  8:18         ` Lothar Rubusch
2025-06-24  8:36           ` Andy Shevchenko
2025-06-22 15:50 ` [PATCH v10 7/7] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-06-28 16:17   ` Jonathan Cameron
2025-06-23  9:45 ` [PATCH v10 0/7] iio: accel: adxl345: add interrupt based sensor events Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aFkh-E1dG__p_G4m@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dlechner@baylibre.com \
    --cc=eraretuya@gmail.com \
    --cc=jic23@kernel.org \
    --cc=l.rubusch@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.