mirror of https://lore.kernel.org/lkml/
 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 v9 07/11] iio: accel: adxl345: add activity event feature
Date: Thu, 12 Jun 2025 14:51:36 +0300	[thread overview]
Message-ID: <aEq_SJMDzPYGSMu6@smile.fi.intel.com> (raw)
In-Reply-To: <20250610215933.84795-8-l.rubusch@gmail.com>

On Tue, Jun 10, 2025 at 09:59:29PM +0000, Lothar Rubusch wrote:
> Make the sensor detect and issue interrupts at activity. Activity
> events are configured by a threshold. Initialize the activity threshold
> register to a reasonable default value in probe. The value is taken from
> the older ADXL345 input driver, to provide a similar behavior.
> 
> Activity, ODR configuration together with the range setting prepare the
> activity/inactivity hysteresis setup, implemented in a follow up patch.
> Thus parts of this patch prepare switch/case setups for the follow up
> patches.

...

> +/* act/inact */

Useless comment. If you want it to stay, decrypt it and make it useful.

...

> +static int adxl345_is_act_inact_en(struct adxl345_state *st,
> +				   enum adxl345_activity_type type)
> +{
> +	unsigned int regval;
> +	u32 axis_ctrl;
> +	bool en;
> +	int ret;
> +
> +	ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &axis_ctrl);
> +	if (ret)
> +		return ret;
> +
> +	switch (type) {
> +	case ADXL345_ACTIVITY:
> +		en = FIELD_GET(ADXL345_ACT_X_EN, axis_ctrl) |
> +			FIELD_GET(ADXL345_ACT_Y_EN, axis_ctrl) |
> +			FIELD_GET(ADXL345_ACT_Z_EN, axis_ctrl);

Something happened to the indentation.
Ditto for several places in the code (upper and lower from this).

> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	if (!en)
> +		return en;
> +
> +	/* Check if corresponding interrupts are enabled */
> +	ret = regmap_read(st->regmap, ADXL345_REG_INT_ENABLE, &regval);
> +	if (ret)
> +		return ret;
> +
> +	return adxl345_act_int_reg[type] & regval;
> +}

...

> +	if (type == ADXL345_ACTIVITY) {
> +		axis_ctrl = ADXL345_ACT_X_EN | ADXL345_ACT_Y_EN |
> +				ADXL345_ACT_Z_EN;
> +	} else {
> +		axis_ctrl = 0x00;
> +	}

Besides an indentation issue, {} are redundant.

...

> +	en = false;

This line makes no sense. When it will, it should be there, not in this change.

> +	switch (type) {
> +	case ADXL345_ACTIVITY:
> +		en = FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl) &&
> +			threshold;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}

...

>  	switch (type) {
> +	case IIO_EV_TYPE_MAG:
> +		switch (info) {
> +		case IIO_EV_INFO_VALUE:
> +			switch (dir) {
> +			case IIO_EV_DIR_RISING:
> +				ret = regmap_read(st->regmap,
> +						  adxl345_act_thresh_reg[ADXL345_ACTIVITY],
> +						  &act_threshold);
> +				if (ret)
> +					return ret;
> +				*val = 62500 * act_threshold;
> +				*val2 = MICRO;
> +				return IIO_VAL_FRACTIONAL;
> +			default:
> +				return -EINVAL;
> +			}
> +		default:
> +			return -EINVAL;
> +		}

As I mentioned before, try to avoid nested switch cases like this. Use helpers
to make this gone to 1 level or so.

>  	case IIO_EV_TYPE_GESTURE:
>  		switch (info) {
>  		case IIO_EV_INFO_VALUE:

Ditto for other similar cases.

...

>  static int adxl345_push_event(struct iio_dev *indio_dev, int int_stat,
> -			      enum iio_modifier tap_dir)
> +			      enum iio_modifier tap_dir,
> +			      enum iio_modifier act_dir)

If the order of parameters is not so important, I would squeeze new one to be
before the last argument.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-06-12 11:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 21:59 [PATCH v9 00/11] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 01/11] iio: accel: adxl345: apply scale factor to tap threshold Lothar Rubusch
2025-06-14 13:42   ` Jonathan Cameron
2025-06-15 22:20     ` Lothar Rubusch
2025-06-21 16:55       ` Jonathan Cameron
2025-06-21 18:14         ` Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 02/11] iio: accel: adxl345: make data struct variable irq function local Lothar Rubusch
2025-06-14 13:43   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 03/11] iio: accel: adxl345: simplify measure enable Lothar Rubusch
2025-06-14 13:45   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 04/11] iio: accel: adxl345: simplify interrupt mapping Lothar Rubusch
2025-06-11 15:20   ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 05/11] iio: accel: adxl345: simplify reading the FIFO Lothar Rubusch
2025-06-14 13:47   ` Jonathan Cameron
2025-06-15 22:14     ` Lothar Rubusch
2025-06-21 16:58       ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 06/11] iio: accel: adxl345: replace magic numbers by unit expressions Lothar Rubusch
2025-06-14 13:49   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 07/11] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-06-12 11:51   ` Andy Shevchenko [this message]
2025-06-21 18:06     ` Lothar Rubusch
2025-06-21 19:55       ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 08/11] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-06-12 12:15   ` Andy Shevchenko
2025-06-14 13:55     ` Jonathan Cameron
2025-06-14 19:02       ` Andy Shevchenko
2025-06-21 18:53     ` Lothar Rubusch
2025-06-21 19:24       ` Andy Shevchenko
2025-06-21 19:28         ` Andy Shevchenko
2025-06-14 14:00   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 09/11] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-06-14 14:04   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 10/11] iio: accel: adxl345: extend inactivity time for less than 1s Lothar Rubusch
2025-06-14 14:10   ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 11/11] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-06-14 14:17   ` Jonathan Cameron

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=aEq_SJMDzPYGSMu6@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®