linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Nyekjaer <sean@geanix.com>
To: linux-iio@vger.kernel.org, jic23@kernel.org,
	lorenzo.bianconi83@gmail.com
Cc: Sean Nyekjaer <sean@geanix.com>,
	denis.ciocca@st.com, mario.tesi@st.com, armando.visconti@st.com,
	martin@geanix.com
Subject: [RFC PATCH] iio: imu: st_lsm6dsx: filter motion events in driver
Date: Mon, 16 Sep 2019 11:02:22 +0200	[thread overview]
Message-ID: <20190916090222.597444-1-sean@geanix.com> (raw)
In-Reply-To: <20190915143548.25383eb4@archlinux>

Do not report non enabled motion events.
Wakeup will still be on all channels as it's not possible to do the
filtering in hw.

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
Hope it's okay to do this as an RFC. To get the most obvious stuff
reviewed before v9

 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 20 ++++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 938192212485..dd46209f94e8 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -362,6 +362,7 @@ struct st_lsm6dsx_hw {
 
 	u8 event_threshold;
 	bool enable_event;
+	u8 event_en_mask;
 	struct st_lsm6dsx_reg irq_routing;
 
 	u8 *buff;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 7596a6ed7d97..2d66e3758921 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1377,9 +1377,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
 	if (type != IIO_EV_TYPE_THRESH)
 		return -EINVAL;
 
+	if (hw->event_en_mask & BIT(chan->channel2))
+		goto out;
+
 	/* do not enable events if they are already enabled */
 	if (state && hw->enable_event)
-		return 0;
+		goto out;
 
 	err = st_lsm6dsx_event_setup(hw, state);
 	if (err < 0)
@@ -1391,6 +1394,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,
 
 	hw->enable_event = state;
 
+out:
+	if (state)
+		hw->event_en_mask |= BIT(chan->channel2);
+	else
+		hw->event_en_mask &= ~BIT(chan->channel2);
+
 	return 0;
 }
 
@@ -1746,7 +1755,8 @@ void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
 {
 	s64 timestamp = iio_get_time_ns(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
 
-	if (data & hw->settings->event_settings.wakeup_src_z_mask)
+	if (data & hw->settings->event_settings.wakeup_src_z_mask &&
+	    hw->event_en_mask & BIT(IIO_MOD_Z))
 		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
 			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
 						  0,
@@ -1755,7 +1765,8 @@ void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
 						  IIO_EV_DIR_EITHER),
 						  timestamp);
 
-	if (data & hw->settings->event_settings.wakeup_src_y_mask)
+	if (data & hw->settings->event_settings.wakeup_src_y_mask &&
+	    hw->event_en_mask & BIT(IIO_MOD_Y))
 		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
 			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
 						  0,
@@ -1764,7 +1775,8 @@ void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data)
 						  IIO_EV_DIR_EITHER),
 						  timestamp);
 
-	if (data & hw->settings->event_settings.wakeup_src_x_mask)
+	if (data & hw->settings->event_settings.wakeup_src_x_mask &&
+	    hw->event_en_mask & BIT(IIO_MOD_X))
 		iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC],
 			       IIO_MOD_EVENT_CODE(IIO_ACCEL,
 						  0,
-- 
2.23.0


  reply	other threads:[~2019-09-16  9:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13  9:07 [PATCH v8 0/5] enable motion events for st_lsm6dsx Sean Nyekjaer
2019-09-13  9:07 ` [PATCH v8 1/5] iio: imu: st_lsm6dsx: move interrupt thread to core Sean Nyekjaer
2019-09-13  9:07 ` [PATCH v8 2/5] iio: imu: st_lsm6dsx: add motion events Sean Nyekjaer
2019-09-13  9:07 ` [PATCH v8 3/5] iio: imu: st_lsm6dsx: add wakeup-source option Sean Nyekjaer
2019-09-15 13:42   ` Lorenzo Bianconi
2019-09-13  9:07 ` [PATCH v8 4/5] iio: imu: st_lsm6dsx: always enter interrupt thread Sean Nyekjaer
2019-09-15 12:33   ` Jonathan Cameron
2019-09-15 12:48     ` Lorenzo Bianconi
2019-09-15 13:00       ` Jonathan Cameron
2019-09-15 13:07         ` Lorenzo Bianconi
2019-09-13  9:07 ` [PATCH v8 5/5] iio: imu: st_lsm6dsx: add motion report function and call from interrupt Sean Nyekjaer
2019-09-15 12:30   ` Jonathan Cameron
2019-09-15 13:05     ` Lorenzo Bianconi
2019-09-15 13:18       ` Jonathan Cameron
2019-09-15 13:22         ` Sean Nyekjaer
2019-09-15 13:35           ` Jonathan Cameron
2019-09-16  9:02             ` Sean Nyekjaer [this message]
2019-09-16  9:16               ` [RFC PATCH] iio: imu: st_lsm6dsx: filter motion events in driver Lorenzo Bianconi
2019-09-16 11:29                 ` Sean Nyekjaer
2019-09-16 11:55                   ` Lorenzo Bianconi
2019-09-16 12:09                     ` Sean Nyekjaer
2019-09-16 12:22                       ` Lorenzo Bianconi
2019-09-15 13:41         ` [PATCH v8 5/5] iio: imu: st_lsm6dsx: add motion report function and call from interrupt Lorenzo Bianconi

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=20190916090222.597444-1-sean@geanix.com \
    --to=sean@geanix.com \
    --cc=armando.visconti@st.com \
    --cc=denis.ciocca@st.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=mario.tesi@st.com \
    --cc=martin@geanix.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).