All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Nyekjaer <sean@geanix.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: 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:38:09 +0200	[thread overview]
Message-ID: <893b615d-693a-3a48-9c91-97559bd247e1@geanix.com> (raw)
In-Reply-To: <20190511123755.2d220233@archlinux>



On 11/05/2019 13.37, Jonathan Cameron wrote:
> 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.
>> ---
>>   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.
Right now we have u16[16], so that quite at bit large :-)

So maybe something like:
/* 3x s16 + 1x s16(padding) + 1x s64 timestamp */
u16 buffer[2 * sizeof(s64)/sizeof(u16)];
Would do it?

> 
>> +	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;
>> +	}
As you pointed out in the
"[PATCH 1/2] iio: adc: ti-ads8688: save values correct in buffer"
When taking this approach it will not shift down.
>> +
>> +	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++) {
> 

      parent reply	other threads:[~2019-05-11 12:38 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
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 [this message]

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=893b615d-693a-3a48-9c91-97559bd247e1@geanix.com \
    --to=sean@geanix.com \
    --cc=denis.ciocca@st.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo.bianconi83@gmail.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 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.