From: Jonathan Cameron <jic23@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
eraretuya@gmail.com
Subject: Re: [PATCH v2 05/14] iio: accel: adxl345: add single tap feature
Date: Sun, 16 Feb 2025 17:20:56 +0000 [thread overview]
Message-ID: <20250216172056.37762336@jic23-huawei> (raw)
In-Reply-To: <20250210110119.260858-6-l.rubusch@gmail.com>
On Mon, 10 Feb 2025 11:01:10 +0000
Lothar Rubusch <l.rubusch@gmail.com> wrote:
> Add the single tap feature with a threshold in 62.5mg/LSB points and a
> scaled duration in us. Keep singletap threshold and duration using means
> of IIO ABI. Extend the channels for single enable x/y/z axis of the
> feature but also initialize threshold and duration with reasonable
> content. When an interrupt is caught it will be pushed to the according
> IIO channel.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Hi Lothar,
Various comments inline,
Thanks,
Jonathan
> ---
> drivers/iio/accel/adxl345_core.c | 369 ++++++++++++++++++++++++++++++-
> 1 file changed, 367 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 910ad21279ed..304147a4ca60 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -8,6 +8,7 @@
> */
> +};
> +
> +static const unsigned int adxl345_tap_int_reg[2] = {
Why force 2? Just use []
> + [ADXL345_SINGLE_TAP] = ADXL345_INT_SINGLE_TAP,
> +};
> +
> +enum adxl345_tap_time_type {
> + ADXL345_TAP_TIME_DUR,
> +};
> +
> +static const unsigned int adxl345_tap_time_reg[3] = {
Why force 3?
> + [ADXL345_TAP_TIME_DUR] = ADXL345_REG_DUR,
> +};
> +static int _adxl345_set_tap_int(struct adxl345_state *st,
> + enum adxl345_tap_type type, bool state)
> +{
> + bool axis_valid;
> + bool singletap_args_valid = false;
> + bool en = false;
> +
> + axis_valid = FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, st->tap_axis_ctrl) > 0;
> +
> + /*
> + * Note: A value of 0 for threshold and/or dur may result in undesirable
> + * behavior if single tap/double tap interrupts are enabled.
> + */
> + singletap_args_valid = st->tap_threshold > 0 && st->tap_duration_us > 0;
> +
> + if (type == ADXL345_SINGLE_TAP)
> + en = axis_valid && singletap_args_valid;
> +
> + if (state && en)
> + __set_bit(ilog2(adxl345_tap_int_reg[type]),
> + (unsigned long *)&st->int_map);
That's not a good idea (I think I probably mislead you here). Casting
across integer pointer types isn't a good way to go.
> + else
> + __clear_bit(ilog2(adxl345_tap_int_reg[type]),
> + (unsigned long *)&st->int_map);
> +
> + return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, st->int_map);
As in previous, if we rely on the regmap cache then can just use
the regmap_set_bit() regmap_clear_bit() type helpers here.
> +}
>
> +static int adxl345_read_event_config(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir)
> +{
> + struct adxl345_state *st = iio_priv(indio_dev);
> + bool int_en;
> + bool axis_en;
> + int ret = -EFAULT;
> +
> + switch (type) {
> + case IIO_EV_TYPE_GESTURE:
> + switch (chan->channel2) {
> + case IIO_MOD_X:
> + axis_en = FIELD_GET(ADXL345_X_EN, st->tap_axis_ctrl);
> + break;
> + case IIO_MOD_Y:
> + axis_en = FIELD_GET(ADXL345_Y_EN, st->tap_axis_ctrl);
> + break;
> + case IIO_MOD_Z:
> + axis_en = FIELD_GET(ADXL345_Z_EN, st->tap_axis_ctrl);
> + break;
> + default:
> + axis_en = ADXL345_TAP_SUPPRESS;
Add a break here. Not strictly necessary but hardens against odd code
changes in future.
> + }
> +
> + switch (dir) {
> + case IIO_EV_DIR_SINGLETAP:
> + ret = adxl345_is_tap_en(st, ADXL345_SINGLE_TAP, &int_en);
> + if (ret)
> + return ret;
> + return int_en && axis_en;
> + default:
> + return -EINVAL;
> + }
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int adxl345_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)
My general preference in IIO is to keep to older 80 char line wrap limit unless
longer lines help readability. Even then try to keep them only a little longer.
So I'd prefer these parameters wrapped a bit more!
> +{
> -static int adxl345_get_status(struct adxl345_state *st, unsigned int *int_stat)
> +static int adxl345_get_status(struct adxl345_state *st, unsigned int *int_stat,
> + enum iio_modifier *act_tap_dir)
> {
> + unsigned int regval;
> + bool check_tap_stat;
> + int ret;
> +
> + *act_tap_dir = IIO_NO_MOD;
> + check_tap_stat = FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, st->tap_axis_ctrl) > 0;
> +
> + if (check_tap_stat) {
> + /* ACT_TAP_STATUS should be read before clearing the interrupt */
> + ret = regmap_read(st->regmap, ADXL345_REG_ACT_TAP_STATUS, ®val);
> + if (ret)
> + return ret;
> +
This double bit pattern is odd enough that I think it needs a comment or
separate defines for the ACT_X source and TAP_X source
> + if ((FIELD_GET(ADXL345_Z_EN, regval >> 4)
> + | FIELD_GET(ADXL345_Z_EN, regval)) > 0)
> + *act_tap_dir = IIO_MOD_Z;
> + else if ((FIELD_GET(ADXL345_Y_EN, regval >> 4)
> + | FIELD_GET(ADXL345_Y_EN, regval)) > 0)
> + *act_tap_dir = IIO_MOD_Y;
> + else if ((FIELD_GET(ADXL345_X_EN, regval >> 4)
> + | FIELD_GET(ADXL345_X_EN, regval)) > 0)
> + *act_tap_dir = IIO_MOD_X;
> + }
> +
next prev parent reply other threads:[~2025-02-16 17:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 11:01 [PATCH v2 00/14] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 01/14] iio: accel: adxl345: reorganize measurement enable Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 02/14] iio: accel: adxl345: add debug register access Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 03/14] iio: accel: adxl345: reorganize irq handler Lothar Rubusch
2025-02-16 17:05 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 04/14] iio: accel: adxl345: refac set_interrupts and IRQ map Lothar Rubusch
2025-02-16 17:11 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 05/14] iio: accel: adxl345: add single tap feature Lothar Rubusch
2025-02-16 17:20 ` Jonathan Cameron [this message]
2025-02-10 11:01 ` [PATCH v2 06/14] iio: accel: adxl345: add double " Lothar Rubusch
2025-02-16 17:23 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 07/14] iio: accel: adxl345: add double tap suppress bit Lothar Rubusch
2025-02-16 17:28 ` Jonathan Cameron
2025-02-18 22:29 ` Lothar Rubusch
2025-02-20 17:47 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 08/14] iio: accel: adxl345: add freefall feature Lothar Rubusch
2025-02-16 17:33 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 09/14] iio: accel: adxl345: extend sample frequency adjustments Lothar Rubusch
2025-02-16 17:38 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 10/14] iio: accel: adxl345: add g-range configuration Lothar Rubusch
2025-02-16 17:41 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 11/14] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-02-16 17:43 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 12/14] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-02-16 17:47 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 13/14] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-02-16 17:54 ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 14/14] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-02-16 18:00 ` 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=20250216172056.37762336@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=eraretuya@gmail.com \
--cc=l.rubusch@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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