From: Sean Nyekjaer <sean@geanix.com>
To: linux-iio@vger.kernel.org, jic23@kernel.org
Cc: Sean Nyekjaer <sean@geanix.com>, martin@geanix.com
Subject: [PATCH 2/2] iio: imu: st_lsm6dsx: add iio trigger and buffer support
Date: Tue, 7 May 2019 10:02:25 +0200 [thread overview]
Message-ID: <20190507080225.108000-2-sean@geanix.com> (raw)
In-Reply-To: <20190507080225.108000-1-sean@geanix.com>
This adds support for using iio triggers, this is needed because
our hardware guys forgot to connect the irq pins from imu device
to the SoC.
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 37 ++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 1ca69598678f..65ab853202de 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -40,8 +40,11 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
+#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
#include <linux/pm.h>
#include <linux/regmap.h>
#include <linux/bitfield.h>
@@ -945,6 +948,30 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw)
return 0;
}
+static irqreturn_t st_lsm6dsx_trigger_handler(int irq, void *p)
+{
+ struct iio_poll_func *pf = p;
+ struct iio_dev *indio_dev = pf->indio_dev;
+ struct st_lsm6dsx_sensor *sensor = iio_priv(indio_dev);
+ u16 buffer[4 * sizeof(s64)/sizeof(u16)];
+ int tmp, bit;
+
+ memset(buffer, 0, sizeof(buffer));
+
+ for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) {
+ st_lsm6dsx_read_oneshot(sensor,
+ indio_dev->channels[bit].address, &tmp);
+ buffer[bit] = tmp;
+ }
+
+ iio_push_to_buffers_with_timestamp(indio_dev, buffer,
+ iio_get_time_ns(indio_dev));
+
+ iio_trigger_notify_done(indio_dev->trig);
+
+ return IRQ_HANDLED;
+}
+
static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
{
u8 drdy_int_reg;
@@ -1093,6 +1120,16 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
err = st_lsm6dsx_fifo_setup(hw);
if (err < 0)
return err;
+ } else {
+ for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
+ err = devm_iio_triggered_buffer_setup(hw->dev,
+ hw->iio_devs[i], NULL,
+ st_lsm6dsx_trigger_handler, NULL);
+ if (err < 0) {
+ dev_err(hw->dev, "iio triggered buffer setup failed\n");
+ return err;
+ }
+ }
}
for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
--
2.21.0
next prev parent reply other threads:[~2019-05-07 8:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-07 8:02 [PATCH 1/2] iio: imu: st_lsm6dsx: only set available_scan_masks if using device fifo Sean Nyekjaer
2019-05-07 8:02 ` Sean Nyekjaer [this message]
2019-05-11 11:37 ` [PATCH 2/2] iio: imu: st_lsm6dsx: add iio trigger and buffer support Jonathan Cameron
2019-05-11 12:30 ` Lorenzo Bianconi
2019-05-11 12:54 ` Sean Nyekjaer
2019-05-11 17:00 ` Lorenzo Bianconi
2019-05-16 11:46 ` Sean Nyekjaer
2019-05-18 8:38 ` Jonathan Cameron
2019-05-11 12:38 ` Sean Nyekjaer
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=20190507080225.108000-2-sean@geanix.com \
--to=sean@geanix.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--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).