All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jagath Jog J <jagathjog1996@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: dan@dlrobertson.com, andy.shevchenko@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 5/5] iio: accel: bma400: Add step change event
Date: Tue, 22 Mar 2022 04:22:50 +0530	[thread overview]
Message-ID: <20220321225248.GE10058@jagath-PC> (raw)
In-Reply-To: <20220320173726.5a9c02bb@jic23-huawei>

Hello Jonathan,

On Sun, Mar 20, 2022 at 05:37:26PM +0000, Jonathan Cameron wrote:
> On Sat, 19 Mar 2022 23:40:23 +0530
> Jagath Jog J <jagathjog1996@gmail.com> wrote:
> 
> > Added support for event when there is a detection of single step
> > or double step change.
> 
> This is new - do we have any way of saying if it was single or
> double that was detected?

Sorry, I could have mentioned this properly. Device will detect single step.
If the sensor misses the detection of single step then it will indicate
as double step for the next step. (Register - INT-STAT1)

I will correct this in the next patch.
>   
> > INT1 pin is used to interrupt and event
> > is pushed to userspace.
> 
> My main question in here is the interaction between the event
> enable and the channel enable in the previous patch.

Channel enable will start the counter when sensor detects the steps,
But there will be no interrupts for each step detection since INT pin
mapping is not done here.

> 
> If the channel is enabled, the event will read as enabled but
> it looks to me like the interrupt will never happen...
> 
> So I think you need to also check if the interrupt is enabled.

Sorry my mistake, I will maintain separate member in device
structure for event.
> 
> The other way around is fine as any IIO ABI is allowed to affect
> any other so when you enable the interrupt it can also enable
> the channel in general.

Then I will enable channel also while enabling interrupt.
> 
> > 
> > Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
> > ---
> >  drivers/iio/accel/bma400.h      |  2 +
> >  drivers/iio/accel/bma400_core.c | 72 +++++++++++++++++++++++++++++++++
> >  2 files changed, 74 insertions(+)
> > 
> > diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h
> > index 65bbc80cbb7f..c833119bb42e 100644
> > --- a/drivers/iio/accel/bma400.h
> > +++ b/drivers/iio/accel/bma400.h
> > @@ -39,6 +39,7 @@
> >  #define BMA400_INT_STAT0_REG        0x0e
> >  #define BMA400_INT_STAT1_REG        0x0f
> >  #define BMA400_INT_STAT2_REG        0x10
> > +#define BMA400_INT12_MAP_REG	    0x23
> >  
> >  /* Temperature register */
> >  #define BMA400_TEMP_DATA_REG        0x11
> > @@ -54,6 +55,7 @@
> >  #define BMA400_STEP_CNT3_REG        0x17
> >  #define BMA400_STEP_STAT_REG        0x18
> >  #define BMA400_STEP_INT_MSK         BIT(0)
> > +#define BMA400_STEP_STAT_MASK	    GENMASK(1, 0)
> >  
> >  /*
> >   * Read-write configuration registers
> > diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> > index 305643e99eb5..79321e41df51 100644
> > --- a/drivers/iio/accel/bma400_core.c
> > +++ b/drivers/iio/accel/bma400_core.c
> > @@ -26,6 +26,7 @@
> >  #include <linux/iio/trigger.h>
> >  #include <linux/iio/triggered_buffer.h>
> >  #include <linux/iio/trigger_consumer.h>
> > +#include <linux/iio/events.h>
> >  
> >  #include "bma400.h"
> >  
> > @@ -69,6 +70,7 @@ struct bma400_data {
> >  	int scale;
> >  	struct iio_trigger *trig;
> >  	int steps_enabled;
> > +	bool step_event_en;
> >  	/* Correct time stamp alignment */
> >  	struct {
> >  		__be16 buff[3];
> > @@ -166,6 +168,12 @@ static const struct iio_chan_spec_ext_info bma400_ext_info[] = {
> >  	{ }
> >  };
> >  
> > +static const struct iio_event_spec bma400_step_detect_event = {
> > +	.type = IIO_EV_TYPE_CHANGE,
> > +	.dir = IIO_EV_DIR_NONE,
> > +	.mask_separate = BIT(IIO_EV_INFO_ENABLE),
> > +};
> > +
> >  #define BMA400_ACC_CHANNEL(_index, _axis) { \
> >  	.type = IIO_ACCEL, \
> >  	.modified = 1, \
> > @@ -208,6 +216,8 @@ static const struct iio_chan_spec bma400_channels[] = {
> >  		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> >  				      BIT(IIO_CHAN_INFO_ENABLE),
> >  		.scan_index = -1, /* No buffer support */
> > +		.event_spec = &bma400_step_detect_event,
> > +		.num_event_specs = 1,
> >  	},
> >  
> >  	IIO_CHAN_SOFT_TIMESTAMP(4),
> > @@ -858,6 +868,59 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev,
> >  	}
> >  }
> >  
> > +static int bma400_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 bma400_data *data = iio_priv(indio_dev);
> > +
> > +	switch (chan->type) {
> > +	case IIO_STEPS:
> > +		switch (type) {
> > +		case IIO_EV_TYPE_CHANGE:
> > +			return data->steps_enabled;
> > +		default:
> > +			return -EINVAL;
> > +		}
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +	return 0;
> > +}
> > +
> > +static int bma400_write_event_config(struct iio_dev *indio_dev,
> > +				     const struct iio_chan_spec *chan,
> > +				     enum iio_event_type type,
> > +				     enum iio_event_direction dir, int state)
> > +{
> > +	int ret;
> > +	struct bma400_data *data = iio_priv(indio_dev);
> > +
> > +	switch (chan->type) {
> > +	case IIO_STEPS:
> > +		switch (type) {
> > +		case IIO_EV_TYPE_CHANGE:
> > +			mutex_lock(&data->mutex);
> > +			ret = regmap_update_bits(data->regmap,
> > +						 BMA400_INT12_MAP_REG,
> > +						 BMA400_STEP_INT_MSK,
> > +						 FIELD_PREP(BMA400_STEP_INT_MSK,
> > +							    state));
> > +			mutex_unlock(&data->mutex);
> > +			if (ret)
> > +				return ret;
> > +			data->steps_enabled = state;
> 
> How does this interact with the use in the previous patch?
> 
> > +			return 0;
> > +		default:
> > +			return -EINVAL;
> > +		}
> > +	default:
> > +		return -EINVAL;
> > +	}
> > +	return 0;
> > +}
> > +
> >  static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig,
> >  					     bool state)
> >  {
> > @@ -890,6 +953,8 @@ static const struct iio_info bma400_info = {
> >  	.read_avail        = bma400_read_avail,
> >  	.write_raw         = bma400_write_raw,
> >  	.write_raw_get_fmt = bma400_write_raw_get_fmt,
> > +	.read_event_config = bma400_read_event_config,
> > +	.write_event_config = bma400_write_event_config,
> >  };
> >  
> >  static const struct iio_trigger_ops bma400_trigger_ops = {
> > @@ -945,6 +1010,13 @@ static irqreturn_t bma400_interrupt(int irq, void *private)
> >  	if (status & BMA400_INT_DRDY_MSK)
> >  		iio_trigger_poll_chained(data->trig);
> >  
> > +	if (status & (BMA400_STEP_STAT_MASK << 8)) {
> 
> FIELD_GET() would be cleaner
> 
> > +		iio_push_event(indio_dev,
> > +			       IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
> > +					      IIO_EV_DIR_NONE,
> > +					      IIO_EV_TYPE_CHANGE, 0, 0, 0),
> > +			       iio_get_time_ns(indio_dev));
> > +		}
> >  out:
> >  	return IRQ_HANDLED;
> >  }
> 

  reply	other threads:[~2022-03-21 23:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-19 18:10 [PATCH v1 0/5] iio: accel: bma400: Add support for buffer and step Jagath Jog J
2022-03-19 18:10 ` [PATCH v1 1/5] iio: accel: bma400: conversion to device-managed function Jagath Jog J
2022-03-20 17:14   ` Jonathan Cameron
2022-03-21 21:12     ` Jagath Jog J
2022-03-22 20:41       ` Jonathan Cameron
2022-03-21  8:30   ` Andy Shevchenko
2022-03-21 21:20     ` Jagath Jog J
2022-03-19 18:10 ` [PATCH v1 2/5] iio: accel: bma400: changing scale min and max macro values Jagath Jog J
2022-03-20 17:17   ` Jonathan Cameron
2022-03-19 18:10 ` [PATCH v1 3/5] iio: accel: bma400: Add triggered buffer support Jagath Jog J
2022-03-20  3:30   ` kernel test robot
2022-03-20 17:26   ` Jonathan Cameron
2022-03-21  8:39   ` Andy Shevchenko
2022-03-21 22:21     ` Jagath Jog J
2022-03-22  8:54       ` Andy Shevchenko
2022-03-22 15:40         ` Jagath Jog J
2022-03-22 16:12           ` Andy Shevchenko
2022-03-19 18:10 ` [PATCH v1 4/5] iio: accel: bma400: Add separate channel for step counter Jagath Jog J
2022-03-20 17:30   ` Jonathan Cameron
2022-03-21  8:42   ` Andy Shevchenko
2022-03-21  8:43   ` Andy Shevchenko
2022-03-19 18:10 ` [PATCH v1 5/5] iio: accel: bma400: Add step change event Jagath Jog J
2022-03-20 17:37   ` Jonathan Cameron
2022-03-21 22:52     ` Jagath Jog J [this message]
2022-03-21  8:45   ` 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=20220321225248.GE10058@jagath-PC \
    --to=jagathjog1996@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=dan@dlrobertson.com \
    --cc=jic23@kernel.org \
    --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 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.