linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	corbet@lwn.net, lucas.p.stankus@gmail.com, lars@metafoo.de,
	Michael.Hennerich@analog.com, bagasdotme@gmail.com,
	linux-iio@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/8] iio: accel: adxl313: add activity sensing
Date: Sat, 28 Jun 2025 18:27:06 +0100	[thread overview]
Message-ID: <20250628182706.2af83c1c@jic23-huawei> (raw)
In-Reply-To: <20250622122937.156930-5-l.rubusch@gmail.com>

On Sun, 22 Jun 2025 12:29:33 +0000
Lothar Rubusch <l.rubusch@gmail.com> wrote:

> Add support for configuring an activity detection threshold. Extend the
> interrupt handler to process activity-related interrupts, and provide
> functions to set the threshold as well as to enable or disable activity
> sensing. Additionally, introduce a virtual channel that represents the
> logical AND of the x, y, and z axes in the IIO channel.
> 
> This patch serves as a preparatory step; some definitions and functions
> introduced here are intended to be extended later to support inactivity
> detection.
> 
> Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Hi Lothar.

I think this is suffering from function naming evolution and we need
to rethink (slightly) what we ended up with.  See inline.
I walked into the same trap recently so was on the look out for it.

> ---
>  drivers/iio/accel/adxl313_core.c | 326 +++++++++++++++++++++++++++++++
>  1 file changed, 326 insertions(+)
> 
> diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
> index ac4cc16399fc..d2c625f27555 100644
> --- a/drivers/iio/accel/adxl313_core.c
> +++ b/drivers/iio/accel/adxl313_core.c
> @@ -13,8 +13,10 @@

> +
> +static int _adxl313_read_mag_value(struct adxl313_data *data,
> +				   enum iio_event_direction dir,
> +				   enum adxl313_activity_type type_act,
> +				   int *val, int *val2)
> +{
> +	unsigned int threshold;
> +	int ret;
> +
> +	switch (dir) {
> +	case IIO_EV_DIR_RISING:
> +		ret = regmap_read(data->regmap,
> +				  adxl313_act_thresh_reg[type_act],
> +				  &threshold);
> +		if (ret)
> +			return ret;
> +		*val = threshold * 15625;
> +		*val2 = MICRO;
> +		return IIO_VAL_FRACTIONAL;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int _adxl313_write_mag_value(struct adxl313_data *data,
> +				    enum iio_event_direction dir,
> +				    enum adxl313_activity_type type_act,
> +				    int val, int val2)
> +{
> +	unsigned int regval;
> +
> +	/* Scale factor 15.625 mg/LSB */
> +	regval = DIV_ROUND_CLOSEST(MICRO * val + val2, 15625);
> +	switch (dir) {
> +	case IIO_EV_DIR_RISING:
> +		return regmap_write(data->regmap,
> +				    adxl313_act_thresh_reg[type_act],
> +				    regval);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int adxl313_read_mag_value(struct adxl313_data *data,
> +				  enum iio_event_direction dir,
> +				  enum iio_event_info info,
> +				  enum adxl313_activity_type type_act,
> +				  int *val, int *val2)
> +{
> +	switch (info) {
> +	case IIO_EV_INFO_VALUE:
> +		return _adxl313_read_mag_value(data, dir,

Same issue as below for read functions.

> +					       type_act,
> +					       val, val2);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int adxl313_write_mag_value(struct adxl313_data *data,

This has me a little confused. It's called
adxl313_write_mag_value() which seems pretty specific but
then calls another level of _adxl313_write_mag_value.

In the next patch (assuming diff isn't leading me astray) we have

@@ -600,13 +687,17 @@ static int adxl313_write_mag_value(struct adxl313_data *data,
 				   enum iio_event_direction dir,
 				   enum iio_event_info info,
 				   enum adxl313_activity_type type_act,
+				   enum adxl313_activity_type type_inact,
 				   int val, int val2)
 {
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
 		return _adxl313_write_mag_value(data, dir,
 						type_act,
+						type_inact,
 						val, val2);
+	case IIO_EV_INFO_PERIOD:
+		return adxl313_set_inact_time_s(data, val);
 	default:
 		return -EINVAL;
 	}


Which is adding PERIOD to something called write_mag_value()

Whilst I can see why you ended up with naming as:

adxl313_write_mag_value() as the magnitude event specific part of
adxl13_event_write_value()

and indeed

_adxl313_write_mag_value() as the thing that writes IIO_EV_INFO_VALUE
value (i.e. the threshold) for the magnitude events.

Last time I hit a similar naming stack, I spinkled in some _info

So have the inner one called something slightly more specific like

adxl313_write_mag_info_value()


> +				   enum iio_event_direction dir,
> +				   enum iio_event_info info,
> +				   enum adxl313_activity_type type_act,
> +				   int val, int val2)
> +{
> +	switch (info) {
> +	case IIO_EV_INFO_VALUE:
> +		return _adxl313_write_mag_value(data, dir,
> +						type_act,
> +						val, val2);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int adxl313_read_event_value(struct iio_dev *indio_dev,
> +				    const struct iio_chan_spec *chan,
> +				    enum iio_event_type type,
> +				    enum iio_event_direction dir,
> +				    enum iio_event_info info,
> +				    int *val, int *val2)
> +{
> +	struct adxl313_data *data = iio_priv(indio_dev);
> +
> +	switch (type) {
> +	case IIO_EV_TYPE_MAG:
> +		return adxl313_read_mag_value(data, dir, info,
> +					      ADXL313_ACTIVITY,
> +					      val, val2);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +static int adxl313_write_event_value(struct iio_dev *indio_dev,
> +				     const struct iio_chan_spec *chan,
> +				     enum iio_event_type type,
> +				     enum iio_event_direction dir,
> +				     enum iio_event_info info,
> +				     int val, int val2)
> +{
> +	struct adxl313_data *data = iio_priv(indio_dev);
> +
> +	switch (type) {
> +	case IIO_EV_TYPE_MAG:
> +		return adxl313_write_mag_value(data, dir, info,
> +					       ADXL313_ACTIVITY,
> +					       val, val2);
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +

Otherwise LGTM

Jonathan

  reply	other threads:[~2025-06-28 17:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-22 12:29 [PATCH v6 0/8] iio: accel: adxl313: add power-save on activity/inactivity Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 1/8] iio: accel: adxl313: make use of regmap cache Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 2/8] iio: accel: adxl313: add function to enable measurement Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 3/8] iio: accel: adxl313: add buffered FIFO watermark with interrupt handling Lothar Rubusch
2025-06-28 17:16   ` Jonathan Cameron
2025-07-01  7:23     ` Lothar Rubusch
2025-07-01 13:53       ` David Lechner
2025-06-22 12:29 ` [PATCH v6 4/8] iio: accel: adxl313: add activity sensing Lothar Rubusch
2025-06-28 17:27   ` Jonathan Cameron [this message]
2025-06-30 22:32     ` Lothar Rubusch
2025-07-01 17:34       ` Jonathan Cameron
2025-06-22 12:29 ` [PATCH v6 5/8] iio: accel: adxl313: add inactivity sensing Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 6/8] iio: accel: adxl313: implement power-save on inactivity Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 7/8] iio: accel: adxl313: add AC coupled activity/inactivity events Lothar Rubusch
2025-06-22 12:29 ` [PATCH v6 8/8] docs: iio: add ADXL313 accelerometer Lothar Rubusch
2025-06-22 14:34 ` [PATCH v6 0/8] iio: accel: adxl313: add power-save on activity/inactivity Jonathan Cameron
2025-06-28 17:29   ` 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=20250628182706.2af83c1c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=bagasdotme@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dlechner@baylibre.com \
    --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=lucas.p.stankus@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).