From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Sean Nyekjaer <sean@geanix.com>,
linux-iio@vger.kernel.org, martin@geanix.com,
Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>,
Denis CIOCCA <denis.ciocca@st.com>
Subject: Re: [PATCH 2/2] iio: imu: st_lsm6dsx: add iio trigger and buffer support
Date: Sat, 11 May 2019 14:30:56 +0200 [thread overview]
Message-ID: <20190511123054.GA14837@localhost.localdomain> (raw)
In-Reply-To: <20190511123755.2d220233@archlinux>
[-- Attachment #1: Type: text/plain, Size: 3969 bytes --]
> On Tue, 7 May 2019 10:02:25 +0200
> Sean Nyekjaer <sean@geanix.com> wrote:
>
> > 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>
> Hi Sean
>
> A small question on the size of the buffer needed inline. Otherwise looks
> good to me.
Hi Sean,
this patch does not make sense to me since running st_lsm6dsx_read_oneshot
you need to wait to power up the device (and you will power it down at the
end). I guess you will not be able to read at a given ODR (e.g. 416Hz).
Moreover you can't read from the hw fifo without the irq line since
you need to read a full pattern from it in order to maintain the alignment.
From my point of view you have 2 possibility:
- poll the output registers from userspace (this is what you are actually
doing from inside the kernel, what is the advantage of doing so?)
- fix the hw bug
Moreover if I read the patch correctly it has a NULL pointer dereference bug
since hw->iio_devs[i] can be NULL (e.g. if sensor hub is disabled)
Regards,
Lorenzo
> > ---
> > 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)];
> The size may well be correct, but that particular way of expressing it doesn't make
> it terribly clear.
>
> It seems a bit large... You need the space for the timestamp, so it needs to be
> padded to a u64, but that would still require your other channels to need
> more than 2*sizeof(s64)/sizeof(u16) u16s which is 9 or more of them.
>
> > + 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);
I guess hw->iio_devs[i] can be NULL here
> > + if (err < 0) {
> > + dev_err(hw->dev, "iio triggered buffer setup failed\n");
> > + return err;
> > + }
> > + }
> > }
> >
> > for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2019-05-11 12:31 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 ` [PATCH 2/2] iio: imu: st_lsm6dsx: add iio trigger and buffer support Sean Nyekjaer
2019-05-11 11:37 ` Jonathan Cameron
2019-05-11 12:30 ` Lorenzo Bianconi [this message]
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=20190511123054.GA14837@localhost.localdomain \
--to=lorenzo@kernel.org \
--cc=denis.ciocca@st.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi83@gmail.com \
--cc=martin@geanix.com \
--cc=sean@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 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.