Re: [PATCH 09/12] iio: imu: inv_icm42600: add buffer support in iio devices
From: Jonathan Cameron
Date: Thu May 21 2020 - 13:57:09 EST
On Mon, 18 May 2020 15:32:27 +0000
Jean-Baptiste Maneyrol <JManeyrol@xxxxxxxxxxxxxx> wrote:
> Hi Jonathan,
>
> no problem with the comments.
>
> fifo_decode_packet will move to source code,Â
>
> For the following sleep comment:
> > +ÂÂÂÂ if (sleep_gyro > sleep_temp)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_gyro;
> > +ÂÂÂÂ else
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_temp;
> > +ÂÂÂÂ if (sleep)
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep);
>
> ÂÂÂÂÂÂÂ if (sleep_gyro > sleep_temp)
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep_gyro);
> ÂÂÂÂÂÂÂ else
> msleep(sleep_temp);
>
> I am using an intermediate local variable to avoid a call to msleep(0) which is in fact sleeping for real for 1 jiffies as far as I understand. So is it OK to keep it as is?
Doh. I missed that for some reason. Absolutely fine as
it is!
J
>
> Thanks,
> JB
>
>
>
> From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
>
> Sent: Friday, May 8, 2020 16:19
>
> To: Jean-Baptiste Maneyrol <JManeyrol@xxxxxxxxxxxxxx>
>
> Cc: jic23@xxxxxxxxxx <jic23@xxxxxxxxxx>; robh+dt@xxxxxxxxxx <robh+dt@xxxxxxxxxx>; robh@xxxxxxxxxx <robh@xxxxxxxxxx>; mchehab+huawei@xxxxxxxxxx <mchehab+huawei@xxxxxxxxxx>; davem@xxxxxxxxxxxxx <davem@xxxxxxxxxxxxx>; gregkh@xxxxxxxxxxxxxxxxxxx <gregkh@xxxxxxxxxxxxxxxxxxx>;
> linux-iio@xxxxxxxxxxxxxxx <linux-iio@xxxxxxxxxxxxxxx>; devicetree@xxxxxxxxxxxxxxx <devicetree@xxxxxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx <linux-kernel@xxxxxxxxxxxxxxx>
>
> Subject: Re: [PATCH 09/12] iio: imu: inv_icm42600: add buffer support in iio devices
>
> Â
>
>
> ÂCAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
>
> On Thu, 7 May 2020 16:42:19 +0200
>
> Jean-Baptiste Maneyrol <jmaneyrol@xxxxxxxxxxxxxx> wrote:
>
>
>
> > Use triggered buffer by parsing FIFO data read in device trigger.
>
> > Support hwfifo watermark by multiplexing gyro and accel settings.
>
> > Support hwfifo flush.
>
> >
>
> > Simply use interrupt timestamp first.
>
> >
>
> > Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@xxxxxxxxxxxxxx>
>
> > ---
>
> >Â drivers/iio/imu/inv_icm42600/KconfigÂÂÂÂÂÂÂÂÂ |ÂÂ 3 +-
>
> >Â drivers/iio/imu/inv_icm42600/MakefileÂÂÂÂÂÂÂÂ |ÂÂ 1 +
>
> >Â drivers/iio/imu/inv_icm42600/inv_icm42600.hÂÂ |ÂÂ 8 +
>
> >Â .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 183 +++++++++
>
> >Â .../imu/inv_icm42600/inv_icm42600_buffer.cÂÂÂ | 353 ++++++++++++++++++
>
> >Â .../imu/inv_icm42600/inv_icm42600_buffer.hÂÂÂ | 162 ++++++++
>
> > .../iio/imu/inv_icm42600/inv_icm42600_core.c | 23 ++
>
> > .../iio/imu/inv_icm42600/inv_icm42600_gyro.c | 183 +++++++++
>
> >Â .../imu/inv_icm42600/inv_icm42600_trigger.cÂÂ |Â 15 +-
>
> >Â 9 files changed, 928 insertions(+), 3 deletions(-)
>
> >Â create mode 100644 drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
>
> >Â create mode 100644 drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h
>
> >
>
> > diff --git a/drivers/iio/imu/inv_icm42600/Kconfig b/drivers/iio/imu/inv_icm42600/Kconfig
>
> > index 7b3eaeb2aa4a..8c0969319c49 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/Kconfig
>
> > +++ b/drivers/iio/imu/inv_icm42600/Kconfig
>
> > @@ -2,7 +2,8 @@
>
> >Â
>
> >Â config INV_ICM42600
>
> >ÂÂÂÂÂÂÂ tristate
>
> > -ÂÂÂÂ select IIO_TRIGGER
>
> > +ÂÂÂÂ select IIO_BUFFER
>
> > +ÂÂÂÂ select IIO_TRIGGERED_BUFFER
>
> >Â
>
> >Â config INV_ICM42600_I2C
>
> >ÂÂÂÂÂÂÂ tristate "InvenSense ICM-426xx I2C driver"
>
> > diff --git a/drivers/iio/imu/inv_icm42600/Makefile b/drivers/iio/imu/inv_icm42600/Makefile
>
> > index e1f2aacbe888..d6732118010c 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/Makefile
>
> > +++ b/drivers/iio/imu/inv_icm42600/Makefile
>
> > @@ -6,6 +6,7 @@ inv-icm42600-y += inv_icm42600_gyro.o
>
> >Â inv-icm42600-y += inv_icm42600_accel.o
>
> >Â inv-icm42600-y += inv_icm42600_temp.o
>
> >Â inv-icm42600-y += inv_icm42600_trigger.o
>
> > +inv-icm42600-y += inv_icm42600_buffer.o
>
> >Â
>
> >Â obj-$(CONFIG_INV_ICM42600_I2C) += inv-icm42600-i2c.o
>
> >Â inv-icm42600-i2c-y += inv_icm42600_i2c.o
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>
> > index 175c1f67faee..947ca4dd245b 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h
>
> > @@ -15,6 +15,8 @@
>
> >Â #include <linux/iio/iio.h>
>
> >Â #include <linux/iio/trigger.h>
>
> >Â
>
> > +#include "inv_icm42600_buffer.h"
>
> > +
>
> >Â enum inv_icm42600_chip {
>
> >ÂÂÂÂÂÂÂ INV_CHIP_ICM42600,
>
> >ÂÂÂÂÂÂÂ INV_CHIP_ICM42602,
>
> > @@ -124,6 +126,7 @@ struct inv_icm42600_suspended {
>
> >ÂÂ *Â @indio_gyro:ÂÂÂÂ gyroscope IIO device.
>
> >ÂÂ *Â @indio_accel:ÂÂÂ accelerometer IIO device.
>
> >ÂÂ *Â @trigger:ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ device internal interrupt trigger
>
> > + *Â @fifo:ÂÂÂÂÂÂÂÂÂÂ FIFO management structure.
>
> >ÂÂ */
>
> >Â struct inv_icm42600_state {
>
> >ÂÂÂÂÂÂÂ struct mutex lock;
>
> > @@ -138,6 +141,7 @@ struct inv_icm42600_state {
>
> >ÂÂÂÂÂÂÂ struct iio_dev *indio_gyro;
>
> >ÂÂÂÂÂÂÂ struct iio_dev *indio_accel;
>
> >ÂÂÂÂÂÂÂ struct iio_trigger *trigger;
>
> > +ÂÂÂÂ struct inv_icm42600_fifo fifo;
>
> >Â };
>
> >Â
>
> >Â /* Virtual register addresses: @bank on MSB (4 upper bits), @address on LSB */
>
> > @@ -378,8 +382,12 @@ int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
>
> >Â
>
> >Â int inv_icm42600_gyro_init(struct inv_icm42600_state *st);
>
> >Â
>
> > +int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev, int64_t ts);
>
> > +
>
> >Â int inv_icm42600_accel_init(struct inv_icm42600_state *st);
>
> >Â
>
> > +int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev, int64_t ts);
>
> > +
>
> >Â int inv_icm42600_trigger_init(struct inv_icm42600_state *st, int irq,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int irq_type);
>
> >Â
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
>
> > index 74dac5f283d4..4206be54d057 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
>
> > @@ -10,9 +10,13 @@
>
> >Â #include <linux/regmap.h>
>
> >Â #include <linux/delay.h>
>
> >Â #include <linux/iio/iio.h>
>
> > +#include <linux/iio/buffer.h>
>
> > +#include <linux/iio/triggered_buffer.h>
>
> > +#include <linux/iio/trigger_consumer.h>
>
> >Â
>
> >Â #include "inv_icm42600.h"
>
> >Â #include "inv_icm42600_temp.h"
>
> > +#include "inv_icm42600_buffer.h"
>
> >Â
>
> >Â #define INV_ICM42600_ACCEL_CHAN(_modifier, _index, _ext_info)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> >ÂÂÂÂÂÂÂ {ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > @@ -46,6 +50,7 @@ enum inv_icm42600_accel_scan {
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_ACCEL_SCAN_Y,
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_ACCEL_SCAN_Z,
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_ACCEL_SCAN_TEMP,
>
> > +ÂÂÂÂ INV_ICM42600_ACCEL_SCAN_TIMESTAMP,
>
> >Â };
>
> >Â
>
> >Â static const struct iio_chan_spec_ext_info inv_icm42600_accel_ext_infos[] = {
>
> > @@ -61,8 +66,100 @@ static const struct iio_chan_spec inv_icm42600_accel_channels[] = {
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_ACCEL_CHAN(IIO_MOD_Z, INV_ICM42600_ACCEL_SCAN_Z,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inv_icm42600_accel_ext_infos),
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_TEMP_CHAN(INV_ICM42600_ACCEL_SCAN_TEMP),
>
> > +ÂÂÂÂ IIO_CHAN_SOFT_TIMESTAMP(INV_ICM42600_ACCEL_SCAN_TIMESTAMP),
>
> >Â };
>
> >Â
>
> > +/* IIO buffer data */
>
> > +struct inv_icm42600_accel_buffer {
>
> > +ÂÂÂÂ struct inv_icm42600_fifo_sensor_data accel;
>
> > +ÂÂÂÂ int8_t temp;
>
> > +ÂÂÂÂ int64_t timestamp;
>
> > +};
>
> > +
>
> > +#define INV_ICM42600_SCAN_MASK_ACCEL_3AXISÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ (BIT(INV_ICM42600_ACCEL_SCAN_X) |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ BIT(INV_ICM42600_ACCEL_SCAN_Y) |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ BIT(INV_ICM42600_ACCEL_SCAN_Z))
>
> > +
>
> > +#define INV_ICM42600_SCAN_MASK_TEMPÂ BIT(INV_ICM42600_ACCEL_SCAN_TEMP)
>
> > +
>
> > +static const unsigned long inv_icm42600_accel_scan_masks[] = {
>
> > +ÂÂÂÂ /* 3-axis accel + temperature */
>
> > +ÂÂÂÂ INV_ICM42600_SCAN_MASK_ACCEL_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
>
> > +ÂÂÂÂ 0,
>
> > +};
>
> > +
>
> > +static irqreturn_t inv_icm42600_accel_handler(int irq, void *_data)
>
> > +{
>
> > +ÂÂÂÂ struct iio_poll_func *pf = _data;
>
> > +ÂÂÂÂ struct iio_dev *indio_dev = pf->indio_dev;
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ const size_t fifo_nb = st->fifo.nb.total;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ /* exit if no sample */
>
> > +ÂÂÂÂ if (fifo_nb == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out;
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_accel_parse_fifo(indio_dev, pf->timestamp);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(regmap_get_device(st->map), "accel fifo error %d\n",
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret);
>
> > +
>
> > +out:
>
> > +ÂÂÂÂ iio_trigger_notify_done(indio_dev->trig);
>
> > +ÂÂÂÂ return IRQ_HANDLED;
>
> > +}
>
> > +
>
> > +/* enable accelerometer sensor and FIFO write */
>
> > +static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const unsigned long *scan_mask)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
>
> > +ÂÂÂÂ unsigned int fifo_en = 0;
>
> > +ÂÂÂÂ unsigned int sleep_temp = 0;
>
> > +ÂÂÂÂ unsigned int sleep_accel = 0;
>
> > +ÂÂÂÂ unsigned int sleep;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* enable temp sensor */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ fifo_en |= INV_ICM42600_SENSOR_TEMP;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ if (*scan_mask & INV_ICM42600_SCAN_MASK_ACCEL_3AXIS) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* enable accel sensor */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_accel);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ fifo_en |= INV_ICM42600_SENSOR_ACCEL;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* update data FIFO write and FIFO watermark */
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_update_watermark(st);
>
> > +
>
> > +out_unlock:
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +ÂÂÂÂ /* sleep maximum required time */
>
> > +ÂÂÂÂ if (sleep_accel > sleep_temp)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_accel;
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_temp;
>
> > +ÂÂÂÂ if (sleep)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep);
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> >Â static int inv_icm42600_accel_read_sensor(struct inv_icm42600_state *st,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct iio_chan_spec const *chan,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int16_t *val)
>
> > @@ -250,6 +347,8 @@ static int inv_icm42600_accel_write_odr(struct inv_icm42600_state *st,
>
> >ÂÂÂÂÂÂÂ mutex_lock(&st->lock);
>
> >ÂÂÂÂÂÂÂ conf.odr = inv_icm42600_accel_odr_conv[idx / 2];
>
> >ÂÂÂÂÂÂÂ ret = inv_icm42600_set_accel_conf(st, &conf, NULL);
>
> > +ÂÂÂÂ inv_icm42600_buffer_update_fifo_period(st);
>
> > +ÂÂÂÂ inv_icm42600_buffer_update_watermark(st);
>
> >ÂÂÂÂÂÂÂ mutex_unlock(&st->lock);
>
> >Â
>
> >ÂÂÂÂÂÂÂ pm_runtime_mark_last_busy(dev);
>
> > @@ -512,12 +611,51 @@ static int inv_icm42600_accel_write_raw_get_fmt(struct iio_dev *indio_dev,
>
> >ÂÂÂÂÂÂÂ }
>
> >Â }
>
> >Â
>
> > +static int inv_icm42600_accel_hwfifo_set_watermark(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int val)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ st->fifo.watermark.accel = val;
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_update_watermark(st);
>
> > +
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> > +static int inv_icm42600_accel_hwfifo_flush(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int count)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ if (count == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_hwfifo_flush(st, count);
>
> > +ÂÂÂÂ if (!ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = st->fifo.nb.accel;
>
> > +
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> >Â static const struct iio_info inv_icm42600_accel_info = {
>
> >ÂÂÂÂÂÂÂ .read_raw = inv_icm42600_accel_read_raw,
>
> >ÂÂÂÂÂÂÂ .read_avail = inv_icm42600_accel_read_avail,
>
> >ÂÂÂÂÂÂÂ .write_raw = inv_icm42600_accel_write_raw,
>
> >ÂÂÂÂÂÂÂ .write_raw_get_fmt = inv_icm42600_accel_write_raw_get_fmt,
>
> >ÂÂÂÂÂÂÂ .debugfs_reg_access = inv_icm42600_debugfs_reg,
>
> > +ÂÂÂÂ .update_scan_mode = inv_icm42600_accel_update_scan_mode,
>
> > +ÂÂÂÂ .hwfifo_set_watermark = inv_icm42600_accel_hwfifo_set_watermark,
>
> > +ÂÂÂÂ .hwfifo_flush_to_buffer = inv_icm42600_accel_hwfifo_flush,
>
> >Â };
>
> >Â
>
> >Â int inv_icm42600_accel_init(struct inv_icm42600_state *st)
>
> > @@ -525,6 +663,7 @@ int inv_icm42600_accel_init(struct inv_icm42600_state *st)
>
> >ÂÂÂÂÂÂÂ struct device *dev = regmap_get_device(st->map);
>
> >ÂÂÂÂÂÂÂ const char *name;
>
> >ÂÂÂÂÂÂÂ struct iio_dev *indio_dev;
>
> > +ÂÂÂÂ int ret;
>
> >Â
>
> >ÂÂÂÂÂÂÂ name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name);
>
> >ÂÂÂÂÂÂÂ if (!name)
>
> > @@ -541,7 +680,51 @@ int inv_icm42600_accel_init(struct inv_icm42600_state *st)
>
> >ÂÂÂÂÂÂÂ indio_dev->modes = INDIO_DIRECT_MODE;
>
> >ÂÂÂÂÂÂÂ indio_dev->channels = inv_icm42600_accel_channels;
>
> >ÂÂÂÂÂÂÂ indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels);
>
> > +ÂÂÂÂ indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
>
> > +
>
> > +ÂÂÂÂ ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inv_icm42600_accel_handler,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &inv_icm42600_buffer_ops);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ indio_dev->trig = iio_trigger_get(st->trigger);
>
> >Â
>
> >ÂÂÂÂÂÂÂ st->indio_accel = indio_dev;
>
> >ÂÂÂÂÂÂÂ return devm_iio_device_register(dev, st->indio_accel);
>
> >Â }
>
> > +
>
> > +int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev, int64_t ts)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ const size_t accel_nb = st->fifo.nb.accel;
>
> > +ÂÂÂÂ ssize_t i, size;
>
> > +ÂÂÂÂ const void *accel, *gyro, *temp, *timestamp;
>
> > +ÂÂÂÂ unsigned int odr;
>
> > +ÂÂÂÂ struct inv_icm42600_accel_buffer buffer;
>
> > +
>
> > +ÂÂÂÂ /* exit if no accel sample */
>
> > +ÂÂÂÂ if (accel_nb == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +
>
> > +ÂÂÂÂ /* parse all fifo packets */
>
> > +ÂÂÂÂ for (i = 0; i < st->fifo.count; i += size) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &accel, &gyro, &temp, ×tamp, &odr);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ dev_dbg(regmap_get_device(st->map), "accel packet size = %zd\n",
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ size);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* quit if error or FIFO is empty */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (size <= 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return size;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* skip packet if no accel data or data is invalid */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (accel == NULL || !inv_icm42600_fifo_is_data_valid(accel)) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_dbg(regmap_get_device(st->map), "skip accel data\n");
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ continue;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ }
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(&buffer.accel, accel, sizeof(buffer.accel));
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(&buffer.temp, temp, sizeof(buffer.temp));
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts);
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
>
> > new file mode 100644
>
> > index 000000000000..b428abdc92ee
>
> > --- /dev/null
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c
>
> > @@ -0,0 +1,353 @@
>
> > +// SPDX-License-Identifier: GPL-2.0-or-later
>
> > +/*
>
> > + * Copyright (C) 2020 Invensense, Inc.
>
> > + */
>
> > +
>
> > +#include <linux/device.h>
>
> > +#include <linux/mutex.h>
>
> > +#include <linux/pm_runtime.h>
>
> > +#include <linux/regmap.h>
>
> > +#include <linux/delay.h>
>
> > +#include <linux/math64.h>
>
> > +#include <linux/iio/iio.h>
>
> > +#include <linux/iio/buffer.h>
>
> > +#include <linux/iio/triggered_buffer.h>
>
> > +#include <linux/iio/trigger_consumer.h>
>
> > +
>
> > +#include "inv_icm42600.h"
>
> > +#include "inv_icm42600_buffer.h"
>
> > +
>
> > +void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st)
>
> > +{
>
> > +ÂÂÂÂ uint32_t period_gyro, period_accel, period;
>
> > +
>
> > +ÂÂÂÂ if (st->fifo.en & INV_ICM42600_SENSOR_GYRO)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr);
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period_gyro = U32_MAX;
>
> > +
>
> > +ÂÂÂÂ if (st->fifo.en & INV_ICM42600_SENSOR_ACCEL)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr);
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period_accel = U32_MAX;
>
> > +
>
> > +ÂÂÂÂ if (period_gyro <= period_accel)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period = period_gyro;
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ period = period_accel;
>
> > +
>
> > +ÂÂÂÂ st->fifo.period = period;
>
> > +}
>
> > +
>
> > +int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int fifo_en)
>
> > +{
>
> > +ÂÂÂÂ unsigned int mask, val;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ /* update only FIFO EN bits */
>
> > +ÂÂÂÂ mask = INV_ICM42600_FIFO_CONFIG1_TMST_FSYNC_EN |
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG1_TEMP_EN |
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG1_GYRO_EN |
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG1_ACCEL_EN;
>
> > +
>
> > +ÂÂÂÂ val = 0;
>
> > +ÂÂÂÂ if (fifo_en & INV_ICM42600_SENSOR_GYRO)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ val |= INV_ICM42600_FIFO_CONFIG1_GYRO_EN;
>
> > +ÂÂÂÂ if (fifo_en & INV_ICM42600_SENSOR_ACCEL)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ val |= INV_ICM42600_FIFO_CONFIG1_ACCEL_EN;
>
> > +ÂÂÂÂ if (fifo_en & INV_ICM42600_SENSOR_TEMP)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ val |= INV_ICM42600_FIFO_CONFIG1_TEMP_EN;
>
> > +
>
> > +ÂÂÂÂ ret = regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mask, val);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ st->fifo.en = fifo_en;
>
> > +ÂÂÂÂ inv_icm42600_buffer_update_fifo_period(st);
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > +
>
> > +static size_t inv_icm42600_get_packet_size(unsigned int fifo_en)
>
> > +{
>
> > +ÂÂÂÂ size_t packet_size;
>
> > +
>
> > +ÂÂÂÂ if ((fifo_en & INV_ICM42600_SENSOR_GYRO) &&
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (fifo_en & INV_ICM42600_SENSOR_ACCEL))
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ packet_size = INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE;
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ packet_size = INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
>
> > +
>
> > +ÂÂÂÂ return packet_size;
>
> > +}
>
> > +
>
> > +static unsigned int inv_icm42600_wm_truncate(unsigned int watermark,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ size_t packet_size)
>
> > +{
>
> > +ÂÂÂÂ size_t wm_size;
>
> > +ÂÂÂÂ unsigned int wm;
>
> > +
>
> > +ÂÂÂÂ wm_size = watermark * packet_size;
>
> > +ÂÂÂÂ if (wm_size > INV_ICM42600_FIFO_WATERMARK_MAX)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ wm_size = INV_ICM42600_FIFO_WATERMARK_MAX;
>
> > +
>
> > +ÂÂÂÂ wm = wm_size / packet_size;
>
> > +
>
> > +ÂÂÂÂ return wm;
>
> > +}
>
> > +
>
> > +int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st)
>
> > +{
>
> > +ÂÂÂÂ size_t packet_size, wm_size;
>
> > +ÂÂÂÂ unsigned int wm_gyro, wm_accel, watermark;
>
> > +ÂÂÂÂ uint32_t period_gyro, period_accel, period;
>
> > +ÂÂÂÂ int64_t latency_gyro, latency_accel, latency;
>
> > +ÂÂÂÂ unsigned int mask, val;
>
> > +ÂÂÂÂ bool restore;
>
> > +ÂÂÂÂ __le16 raw_wm;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ packet_size = inv_icm42600_get_packet_size(st->fifo.en);
>
> > +
>
> > +ÂÂÂÂ /* get minimal latency, depending on sensor watermark and odr */
>
> > +ÂÂÂÂ wm_gyro = inv_icm42600_wm_truncate(st->fifo.watermark.gyro,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ packet_size);
>
> > +ÂÂÂÂ wm_accel = inv_icm42600_wm_truncate(st->fifo.watermark.accel,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ packet_size);
>
> > +ÂÂÂÂ period_gyro = inv_icm42600_odr_to_period(st->conf.gyro.odr);
>
> > +ÂÂÂÂ period_accel = inv_icm42600_odr_to_period(st->conf.accel.odr);
>
> > +ÂÂÂÂ latency_gyro = (int64_t)period_gyro * (int64_t)wm_gyro;
>
> > +ÂÂÂÂ latency_accel = (int64_t)period_accel * (int64_t)wm_accel;
>
> > +ÂÂÂÂ if (latency_gyro == 0) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ latency = latency_accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark = wm_accel;
>
> > +ÂÂÂÂ } else if (latency_accel == 0) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ latency = latency_gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark = wm_gyro;
>
> > +ÂÂÂÂ } else {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* compute the smallest latency that is a multiple of both */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (latency_gyro <= latency_accel) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ latency = latency_gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ latency -= latency_accel % latency_gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ } else {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ latency = latency_accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ latency -= latency_gyro % latency_accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ }
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* use the shortest period */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (period_gyro <= period_accel)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ period = period_gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ period = period_accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* all this works because periods are multiple of each others */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark = div_s64(latency, period);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (watermark < 1)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ watermark = 1;
>
> > +ÂÂÂÂ }
>
> > +ÂÂÂÂ wm_size = watermark * packet_size;
>
> > +ÂÂÂÂ dev_dbg(regmap_get_device(st->map), "watermark: %u (%zu)\n",
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark, wm_size);
>
> > +
>
> > +ÂÂÂÂ /* changing FIFO watermark requires to turn off watermark interrupt */
>
> > +ÂÂÂÂ mask = INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN;
>
> > +ÂÂÂÂ val = 0;
>
> > +ÂÂÂÂ ret = regmap_update_bits_check(st->map, INV_ICM42600_REG_INT_SOURCE0,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mask, val, &restore);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ raw_wm = INV_ICM42600_FIFO_WATERMARK_VAL(wm_size);
>
> > +ÂÂÂÂ ret = regmap_bulk_write(st->map, INV_ICM42600_REG_FIFO_WATERMARK,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &raw_wm, sizeof(raw_wm));
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ /* restore watermark interrupt */
>
> > +ÂÂÂÂ if (restore) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ mask = INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ val = INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_SOURCE0,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mask, val);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > +
>
> > +static int inv_icm42600_buffer_preenable(struct iio_dev *indio_dev)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ struct device *dev = regmap_get_device(st->map);
>
> > +
>
> > +ÂÂÂÂ pm_runtime_get_sync(dev);
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > +
>
> > +static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ struct device *dev = regmap_get_device(st->map);
>
> > +ÂÂÂÂ unsigned int sensor;
>
> > +ÂÂÂÂ unsigned int *watermark;
>
> > +ÂÂÂÂ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
>
> > +ÂÂÂÂ unsigned int sleep = 0;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ if (indio_dev == st->indio_gyro) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sensor = INV_ICM42600_SENSOR_GYRO;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark = &st->fifo.watermark.gyro;
>
> > +ÂÂÂÂ } else if (indio_dev == st->indio_accel) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sensor = INV_ICM42600_SENSOR_ACCEL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ watermark = &st->fifo.watermark.accel;
>
> > +ÂÂÂÂ } else {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_set_fifo_en(st, st->fifo.en & ~sensor);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +
>
> > +ÂÂÂÂ *watermark = 0;
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_update_watermark(st);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +
>
> > +ÂÂÂÂ conf.mode = INV_ICM42600_SENSOR_MODE_OFF;
>
> > +ÂÂÂÂ if (sensor == INV_ICM42600_SENSOR_GYRO)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep);
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_accel_conf(st, &conf, &sleep);
>
> > +
>
> > +out_unlock:
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +ÂÂÂÂ if (sleep)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep);
>
> > +ÂÂÂÂ pm_runtime_mark_last_busy(dev);
>
> > +ÂÂÂÂ pm_runtime_put_autosuspend(dev);
>
> > +
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> > +const struct iio_buffer_setup_ops inv_icm42600_buffer_ops = {
>
> > +ÂÂÂÂ .preenable = inv_icm42600_buffer_preenable,
>
> > +ÂÂÂÂ .postenable = iio_triggered_buffer_postenable,
>
> > +ÂÂÂÂ .predisable = iio_triggered_buffer_predisable,
>
> > +ÂÂÂÂ .postdisable = inv_icm42600_buffer_postdisable,
>
> > +};
>
> > +
>
> > +int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int max)
>
> > +{
>
> > +ÂÂÂÂ struct device *dev = regmap_get_device(st->map);
>
> > +ÂÂÂÂ __be16 raw_fifo_count;
>
> > +ÂÂÂÂ size_t max_count;
>
> > +ÂÂÂÂ ssize_t i, size;
>
> > +ÂÂÂÂ const void *accel, *gyro, *temp, *timestamp;
>
> > +ÂÂÂÂ unsigned int odr;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ /* reset all samples counters */
>
> > +ÂÂÂÂ st->fifo.count = 0;
>
> > +ÂÂÂÂ st->fifo.nb.gyro = 0;
>
> > +ÂÂÂÂ st->fifo.nb.accel = 0;
>
> > +ÂÂÂÂ st->fifo.nb.total = 0;
>
> > +
>
> > +ÂÂÂÂ /* compute maximum FIFO read size */
>
> > +ÂÂÂÂ if (max == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ max_count = sizeof(st->fifo.data);
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ max_count = max * inv_icm42600_get_packet_size(st->fifo.en);
>
> > +
>
> > +ÂÂÂÂ /* read FIFO count value */
>
> > +ÂÂÂÂ ret = regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &raw_fifo_count, sizeof(raw_fifo_count));
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +ÂÂÂÂ st->fifo.count = be16_to_cpu(raw_fifo_count);
>
> > +ÂÂÂÂ dev_dbg(dev, "FIFO count = %zu\n", st->fifo.count);
>
> > +
>
> > +ÂÂÂÂ /* check and sanitize FIFO count value */
>
> > +ÂÂÂÂ if (st->fifo.count == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +ÂÂÂÂ if (st->fifo.count > max_count)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.count = max_count;
>
> > +
>
> > +ÂÂÂÂ /* read all FIFO data in internal buffer */
>
> > +ÂÂÂÂ ret = regmap_noinc_read(st->map, INV_ICM42600_REG_FIFO_DATA,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.data, st->fifo.count);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ /* compute number of samples for each sensor */
>
> > +ÂÂÂÂ for (i = 0; i < st->fifo.count; i += size) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &accel, &gyro, &temp, ×tamp, &odr);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (size <= 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ break;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (gyro != NULL && inv_icm42600_fifo_is_data_valid(gyro))
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.gyro++;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (accel != NULL && inv_icm42600_fifo_is_data_valid(accel))
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.accel++;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.total++;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > +
>
> > +int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int count)
>
> > +{
>
> > +ÂÂÂÂ int64_t ts_gyro, ts_accel;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ dev_dbg(regmap_get_device(st->map), "FIFO flush %u\n", count);
>
> > +
>
> > +ÂÂÂÂ ts_gyro = iio_get_time_ns(st->indio_gyro);
>
> > +ÂÂÂÂ ts_accel = iio_get_time_ns(st->indio_accel);
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_fifo_read(st, count);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ if (st->fifo.nb.total == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_gyro_parse_fifo(st->indio_gyro, ts_gyro);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ return inv_icm42600_accel_parse_fifo(st->indio_accel, ts_accel);
>
> > +}
>
> > +
>
> > +int inv_icm42600_buffer_init(struct inv_icm42600_state *st)
>
> > +{
>
> > +ÂÂÂÂ unsigned int mask, val;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ /*
>
> > +ÂÂÂÂÂ * Default FIFO configuration (bits 7 to 5)
>
> > +ÂÂÂÂÂ * - use invalid value
>
> > +ÂÂÂÂÂ * - FIFO count in bytes
>
> > +ÂÂÂÂÂ * - FIFO count in big endian
>
> > +ÂÂÂÂÂ */
>
> > +ÂÂÂÂ mask = GENMASK(7, 5);
>
> > +ÂÂÂÂ val = INV_ICM42600_INTF_CONFIG0_FIFO_COUNT_ENDIAN;
>
> > +ÂÂÂÂ ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mask, val);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ /*
>
> > +ÂÂÂÂÂ * Enable FIFO partial read and continuous watermark interrupt.
>
> > +ÂÂÂÂÂ * Disable all FIFO EN bits.
>
> > +ÂÂÂÂÂ */
>
> > +ÂÂÂÂ mask = GENMASK(6, 5) | GENMASK(3, 0);
>
> > +ÂÂÂÂ val = INV_ICM42600_FIFO_CONFIG1_RESUME_PARTIAL_RD |
>
> > +ÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG1_WM_GT_TH;
>
> > +ÂÂÂÂ return regmap_update_bits(st->map, INV_ICM42600_REG_FIFO_CONFIG1,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mask, val);
>
> > +}
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h
>
> > new file mode 100644
>
> > index 000000000000..74b91c0e664b
>
> > --- /dev/null
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.h
>
> > @@ -0,0 +1,162 @@
>
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
>
> > +/*
>
> > + * Copyright (C) 2020 Invensense, Inc.
>
> > + */
>
> > +
>
> > +#ifndef INV_ICM42600_BUFFER_H_
>
> > +#define INV_ICM42600_BUFFER_H_
>
> > +
>
> > +#include <linux/kernel.h>
>
> > +#include <linux/bits.h>
>
> > +
>
> > +struct inv_icm42600_state;
>
> > +
>
> > +#define INV_ICM42600_SENSOR_GYROÂÂÂÂ BIT(0)
>
> > +#define INV_ICM42600_SENSOR_ACCELÂÂÂ BIT(1)
>
> > +#define INV_ICM42600_SENSOR_TEMPÂÂÂÂ BIT(2)
>
> > +
>
> > +struct inv_icm42600_fifo {
>
> > +ÂÂÂÂ unsigned int en;
>
> > +ÂÂÂÂ uint32_t period;
>
> > +ÂÂÂÂ struct {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int accel;
>
> > +ÂÂÂÂ } watermark;
>
> > +ÂÂÂÂ size_t count;
>
> > +ÂÂÂÂ struct {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size_t gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size_t accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size_t total;
>
> > +ÂÂÂÂ } nb;
>
> > +ÂÂÂÂ uint8_t data[2080];
>
> > +};
>
> > +
>
> > +/* FIFO header: 1 byte */
>
> > +#define INV_ICM42600_FIFO_HEADER_MSGÂÂÂÂÂÂÂÂ BIT(7)
>
> > +#define INV_ICM42600_FIFO_HEADER_ACCELÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BIT(6)
>
> > +#define INV_ICM42600_FIFO_HEADER_GYROÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BIT(5)
>
> > +#define INV_ICM42600_FIFO_HEADER_TMST_FSYNCÂ GENMASK(3, 2)
>
> > +#define INV_ICM42600_FIFO_HEADER_ODR_ACCELÂÂ BIT(1)
>
> > +#define INV_ICM42600_FIFO_HEADER_ODR_GYROÂÂÂ BIT(0)
>
> > +
>
> > +/* FIFO data packet */
>
> > +struct inv_icm42600_fifo_sensor_data {
>
> > +ÂÂÂÂ __be16 x;
>
> > +ÂÂÂÂ __be16 y;
>
> > +ÂÂÂÂ __be16 z;
>
> > +} __packed;
>
> > +#define INV_ICM42600_FIFO_DATA_INVALIDÂÂÂÂÂÂÂÂÂÂÂÂÂÂ -32768
>
> > +
>
> > +struct inv_icm42600_fifo_1sensor_packet {
>
> > +ÂÂÂÂ uint8_t header;
>
> > +ÂÂÂÂ struct inv_icm42600_fifo_sensor_data data;
>
> > +ÂÂÂÂ int8_t temp;
>
> > +} __packed;
>
> > +#define INV_ICM42600_FIFO_1SENSOR_PACKET_SIZEÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 8
>
> > +
>
> > +struct inv_icm42600_fifo_2sensors_packet {
>
> > +ÂÂÂÂ uint8_t header;
>
> > +ÂÂÂÂ struct inv_icm42600_fifo_sensor_data accel;
>
> > +ÂÂÂÂ struct inv_icm42600_fifo_sensor_data gyro;
>
> > +ÂÂÂÂ int8_t temp;
>
> > +ÂÂÂÂ __be16 timestamp;
>
> > +} __packed;
>
> > +#define INV_ICM42600_FIFO_2SENSORS_PACKET_SIZEÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 16
>
> > +
>
> > +static inline int16_t inv_icm42600_fifo_get_sensor_data(__be16 d)
>
> > +{
>
> > +ÂÂÂÂ return be16_to_cpu(d);
>
> > +}
>
> > +
>
> > +static inline bool
>
> > +inv_icm42600_fifo_is_data_valid(const struct inv_icm42600_fifo_sensor_data *s)
>
> > +{
>
> > +ÂÂÂÂ int16_t x, y, z;
>
> > +
>
> > +ÂÂÂÂ x = inv_icm42600_fifo_get_sensor_data(s->x);
>
> > +ÂÂÂÂ y = inv_icm42600_fifo_get_sensor_data(s->y);
>
> > +ÂÂÂÂ z = inv_icm42600_fifo_get_sensor_data(s->z);
>
> > +
>
> > +ÂÂÂÂ if (x == INV_ICM42600_FIFO_DATA_INVALID &&
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ y == INV_ICM42600_FIFO_DATA_INVALID &&
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ z == INV_ICM42600_FIFO_DATA_INVALID)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return false;
>
> > +
>
> > +ÂÂÂÂ return true;
>
> > +}
>
> > +
>
> > +static inline ssize_t inv_icm42600_fifo_decode_packet(const void *packet,
>
>
>
> Bit big to be in the header..
>
>
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ const void **accel, const void **gyro, const void **temp,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ const void **timestamp, unsigned int *odr)
>
> > +{
>
> > +ÂÂÂÂ const struct inv_icm42600_fifo_1sensor_packet *pack1 = packet;
>
> > +ÂÂÂÂ const struct inv_icm42600_fifo_2sensors_packet *pack2 = packet;
>
> > +ÂÂÂÂ uint8_t header = *((const uint8_t *)packet);
>
> > +
>
> > +ÂÂÂÂ /* FIFO empty */
>
> > +ÂÂÂÂ if (header & INV_ICM42600_FIFO_HEADER_MSG) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *accel = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *gyro = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *temp = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *timestamp = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *odr = 0;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* handle odr flags */
>
> > +ÂÂÂÂ *odr = 0;
>
> > +ÂÂÂÂ if (header & INV_ICM42600_FIFO_HEADER_ODR_GYRO)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *odr |= INV_ICM42600_SENSOR_GYRO;
>
> > +ÂÂÂÂ if (header & INV_ICM42600_FIFO_HEADER_ODR_ACCEL)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *odr |= INV_ICM42600_SENSOR_ACCEL;
>
> > +
>
> > +ÂÂÂÂ /* accel + gyro */
>
> > +ÂÂÂÂ if ((header & INV_ICM42600_FIFO_HEADER_ACCEL) &&
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (header & INV_ICM42600_FIFO_HEADER_GYRO)) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *accel = &pack2->accel;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *gyro = &pack2->gyro;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *temp = &pack2->temp;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *timestamp = &pack2->timestamp;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return INV_ICM42600_FIFO_2SENSORS_PACKET_SIZE;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* accel only */
>
> > +ÂÂÂÂ if (header & INV_ICM42600_FIFO_HEADER_ACCEL) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *accel = &pack1->data;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *gyro = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *temp = &pack1->temp;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *timestamp = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* gyro only */
>
> > +ÂÂÂÂ if (header & INV_ICM42600_FIFO_HEADER_GYRO) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *accel = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *gyro = &pack1->data;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *temp = &pack1->temp;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ *timestamp = NULL;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return INV_ICM42600_FIFO_1SENSOR_PACKET_SIZE;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* invalid packet if here */
>
> > +ÂÂÂÂ return -EINVAL;
>
> > +}
>
> > +
>
> > +extern const struct iio_buffer_setup_ops inv_icm42600_buffer_ops;
>
> > +
>
> > +int inv_icm42600_buffer_init(struct inv_icm42600_state *st);
>
> > +
>
> > +void inv_icm42600_buffer_update_fifo_period(struct inv_icm42600_state *st);
>
> > +
>
> > +int inv_icm42600_buffer_set_fifo_en(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int fifo_en);
>
> > +
>
> > +int inv_icm42600_buffer_update_watermark(struct inv_icm42600_state *st);
>
> > +
>
> > +int inv_icm42600_buffer_fifo_read(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int max);
>
> > +
>
> > +int inv_icm42600_buffer_hwfifo_flush(struct inv_icm42600_state *st,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int count);
>
> > +
>
> > +#endif
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
>
> > index 1102c54396e3..689089065ff9 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c
>
> > @@ -14,6 +14,7 @@
>
> >Â #include <linux/iio/iio.h>
>
> >Â
>
> >Â #include "inv_icm42600.h"
>
> > +#include "inv_icm42600_buffer.h"
>
> >Â
>
> >Â static const struct regmap_range_cfg inv_icm42600_regmap_ranges[] = {
>
> >ÂÂÂÂÂÂÂ {
>
> > @@ -515,6 +516,11 @@ int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq,
>
> >ÂÂÂÂÂÂÂ if (ret)
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> >Â
>
> > +ÂÂÂÂ /* setup FIFO buffer */
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_init(st);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> >ÂÂÂÂÂÂÂ /* setup interrupt trigger */
>
> >ÂÂÂÂÂÂÂ ret = inv_icm42600_trigger_init(st, irq, irq_type);
>
> >ÂÂÂÂÂÂÂ if (ret)
>
> > @@ -559,6 +565,16 @@ static int __maybe_unused inv_icm42600_suspend(struct device *dev)
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> >ÂÂÂÂÂÂÂ }
>
> >Â
>
> > +ÂÂÂÂ /* disable FIFO data streaming */
>
> > +ÂÂÂÂ if (iio_buffer_enabled(st->indio_gyro) ||
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ iio_buffer_enabled(st->indio_accel)) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* set FIFO in bypass mode */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG_BYPASS);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂ }
>
> > +
>
> >ÂÂÂÂÂÂÂ ret = inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_SENSOR_MODE_OFF, false,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ NULL);
>
> > @@ -594,6 +610,13 @@ static int __maybe_unused inv_icm42600_resume(struct device *dev)
>
> >ÂÂÂÂÂÂÂ if (ret)
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> >Â
>
> > +ÂÂÂÂ /* restore FIFO data streaming */
>
> > +ÂÂÂÂ if (iio_buffer_enabled(st->indio_gyro) ||
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ iio_buffer_enabled(st->indio_accel)) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ INV_ICM42600_FIFO_CONFIG_STREAM);
>
> > +ÂÂÂÂ }
>
> > +
>
> >Â out_unlock:
>
> >ÂÂÂÂÂÂÂ mutex_unlock(&st->lock);
>
> >ÂÂÂÂÂÂÂ return ret;
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
>
> > index c0164ab2830e..dafb104abc77 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
>
> > @@ -10,9 +10,13 @@
>
> >Â #include <linux/regmap.h>
>
> >Â #include <linux/delay.h>
>
> >Â #include <linux/iio/iio.h>
>
> > +#include <linux/iio/buffer.h>
>
> > +#include <linux/iio/triggered_buffer.h>
>
> > +#include <linux/iio/trigger_consumer.h>
>
> >Â
>
> >Â #include "inv_icm42600.h"
>
> >Â #include "inv_icm42600_temp.h"
>
> > +#include "inv_icm42600_buffer.h"
>
> >Â
>
> >Â #define INV_ICM42600_GYRO_CHAN(_modifier, _index, _ext_info)ÂÂÂÂÂÂÂÂ \
>
> >ÂÂÂÂÂÂÂ {ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > @@ -46,6 +50,7 @@ enum inv_icm42600_gyro_scan {
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_GYRO_SCAN_Y,
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_GYRO_SCAN_Z,
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_GYRO_SCAN_TEMP,
>
> > +ÂÂÂÂ INV_ICM42600_GYRO_SCAN_TIMESTAMP,
>
> >Â };
>
> >Â
>
> >Â static const struct iio_chan_spec_ext_info inv_icm42600_gyro_ext_infos[] = {
>
> > @@ -61,8 +66,100 @@ static const struct iio_chan_spec inv_icm42600_gyro_channels[] = {
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_GYRO_CHAN(IIO_MOD_Z, INV_ICM42600_GYRO_SCAN_Z,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inv_icm42600_gyro_ext_infos),
>
> >ÂÂÂÂÂÂÂ INV_ICM42600_TEMP_CHAN(INV_ICM42600_GYRO_SCAN_TEMP),
>
> > +ÂÂÂÂ IIO_CHAN_SOFT_TIMESTAMP(INV_ICM42600_GYRO_SCAN_TIMESTAMP),
>
> >Â };
>
> >Â
>
> > +/* IIO buffer data */
>
> > +struct inv_icm42600_gyro_buffer {
>
> > +ÂÂÂÂ struct inv_icm42600_fifo_sensor_data gyro;
>
> > +ÂÂÂÂ int8_t temp;
>
> > +ÂÂÂÂ int64_t timestamp;
>
> > +};
>
> > +
>
> > +#define INV_ICM42600_SCAN_MASK_GYRO_3AXISÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ (BIT(INV_ICM42600_GYRO_SCAN_X) |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ BIT(INV_ICM42600_GYRO_SCAN_Y) |ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>
> > +ÂÂÂÂ BIT(INV_ICM42600_GYRO_SCAN_Z))
>
> > +
>
> > +#define INV_ICM42600_SCAN_MASK_TEMPÂ BIT(INV_ICM42600_GYRO_SCAN_TEMP)
>
> > +
>
> > +static const unsigned long inv_icm42600_gyro_scan_masks[] = {
>
> > +ÂÂÂÂ /* 3-axis gyro + temperature */
>
> > +ÂÂÂÂ INV_ICM42600_SCAN_MASK_GYRO_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
>
> > +ÂÂÂÂ 0,
>
> > +};
>
> > +
>
> > +static irqreturn_t inv_icm42600_gyro_handler(int irq, void *_data)
>
> > +{
>
> > +ÂÂÂÂ struct iio_poll_func *pf = _data;
>
> > +ÂÂÂÂ struct iio_dev *indio_dev = pf->indio_dev;
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ const size_t fifo_nb = st->fifo.nb.total;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ /* exit if no sample */
>
> > +ÂÂÂÂ if (fifo_nb == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out;
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_gyro_parse_fifo(indio_dev, pf->timestamp);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(regmap_get_device(st->map), "gyro fifo error %d\n",
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret);
>
> > +
>
> > +out:
>
> > +ÂÂÂÂ iio_trigger_notify_done(indio_dev->trig);
>
> > +ÂÂÂÂ return IRQ_HANDLED;
>
> > +}
>
> > +
>
> > +/* enable gyroscope sensor and FIFO write */
>
> > +static int inv_icm42600_gyro_update_scan_mode(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const unsigned long *scan_mask)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
>
> > +ÂÂÂÂ unsigned int fifo_en = 0;
>
> > +ÂÂÂÂ unsigned int sleep_gyro = 0;
>
> > +ÂÂÂÂ unsigned int sleep_temp = 0;
>
> > +ÂÂÂÂ unsigned int sleep;
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* enable temp sensor */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ fifo_en |= INV_ICM42600_SENSOR_TEMP;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ if (*scan_mask & INV_ICM42600_SCAN_MASK_GYRO_3AXIS) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* enable gyro sensor */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_gyro);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ fifo_en |= INV_ICM42600_SENSOR_GYRO;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ /* update data FIFO write and FIFO watermark */
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ goto out_unlock;
>
>
>
> blank line
>
>
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_update_watermark(st);
>
> > +
>
> > +out_unlock:
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +ÂÂÂÂ /* sleep maximum required time */
>
> > +ÂÂÂÂ if (sleep_gyro > sleep_temp)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_gyro;
>
> > +ÂÂÂÂ else
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ sleep = sleep_temp;
>
> > +ÂÂÂÂ if (sleep)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep);
>
>
>
> ÂÂÂÂÂÂÂ if (sleep_gyro > sleep_temp)
>
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep_gyro);
>
> ÂÂÂÂÂÂÂ else
>
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ msleep(sleep_temp);
>
>
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> >Â static int inv_icm42600_gyro_read_sensor(struct inv_icm42600_state *st,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct iio_chan_spec const *chan,
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int16_t *val)
>
> > @@ -262,6 +359,8 @@ static int inv_icm42600_gyro_write_odr(struct inv_icm42600_state *st,
>
> >ÂÂÂÂÂÂÂ mutex_lock(&st->lock);
>
> >ÂÂÂÂÂÂÂ conf.odr = inv_icm42600_gyro_odr_conv[idx / 2];
>
> >ÂÂÂÂÂÂÂ ret = inv_icm42600_set_gyro_conf(st, &conf, NULL);
>
> > +ÂÂÂÂ inv_icm42600_buffer_update_fifo_period(st);
>
> > +ÂÂÂÂ inv_icm42600_buffer_update_watermark(st);
>
> >ÂÂÂÂÂÂÂ mutex_unlock(&st->lock);
>
> >Â
>
> >ÂÂÂÂÂÂÂ pm_runtime_mark_last_busy(dev);
>
> > @@ -524,12 +623,51 @@ static int inv_icm42600_gyro_write_raw_get_fmt(struct iio_dev *indio_dev,
>
> >ÂÂÂÂÂÂÂ }
>
> >Â }
>
> >Â
>
> > +static int inv_icm42600_gyro_hwfifo_set_watermark(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int val)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ st->fifo.watermark.gyro = val;
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_update_watermark(st);
>
> > +
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> > +static int inv_icm42600_gyro_hwfifo_flush(struct iio_dev *indio_dev,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned int count)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ int ret;
>
> > +
>
> > +ÂÂÂÂ if (count == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +
>
> > +ÂÂÂÂ mutex_lock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ ret = inv_icm42600_buffer_hwfifo_flush(st, count);
>
> > +ÂÂÂÂ if (!ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = st->fifo.nb.gyro;
>
> > +
>
> > +ÂÂÂÂ mutex_unlock(&st->lock);
>
> > +
>
> > +ÂÂÂÂ return ret;
>
> > +}
>
> > +
>
> >Â static const struct iio_info inv_icm42600_gyro_info = {
>
> >ÂÂÂÂÂÂÂ .read_raw = inv_icm42600_gyro_read_raw,
>
> >ÂÂÂÂÂÂÂ .read_avail = inv_icm42600_gyro_read_avail,
>
> >ÂÂÂÂÂÂÂ .write_raw = inv_icm42600_gyro_write_raw,
>
> >ÂÂÂÂÂÂÂ .write_raw_get_fmt = inv_icm42600_gyro_write_raw_get_fmt,
>
> >ÂÂÂÂÂÂÂ .debugfs_reg_access = inv_icm42600_debugfs_reg,
>
> > +ÂÂÂÂ .update_scan_mode = inv_icm42600_gyro_update_scan_mode,
>
> > +ÂÂÂÂ .hwfifo_set_watermark = inv_icm42600_gyro_hwfifo_set_watermark,
>
> > +ÂÂÂÂ .hwfifo_flush_to_buffer = inv_icm42600_gyro_hwfifo_flush,
>
> >Â };
>
> >Â
>
> >Â int inv_icm42600_gyro_init(struct inv_icm42600_state *st)
>
> > @@ -537,6 +675,7 @@ int inv_icm42600_gyro_init(struct inv_icm42600_state *st)
>
> >ÂÂÂÂÂÂÂ struct device *dev = regmap_get_device(st->map);
>
> >ÂÂÂÂÂÂÂ const char *name;
>
> >ÂÂÂÂÂÂÂ struct iio_dev *indio_dev;
>
> > +ÂÂÂÂ int ret;
>
> >Â
>
> >ÂÂÂÂÂÂÂ name = devm_kasprintf(dev, GFP_KERNEL, "%s-gyro", st->name);
>
> >ÂÂÂÂÂÂÂ if (!name)
>
> > @@ -553,7 +692,51 @@ int inv_icm42600_gyro_init(struct inv_icm42600_state *st)
>
> >ÂÂÂÂÂÂÂ indio_dev->modes = INDIO_DIRECT_MODE;
>
> >ÂÂÂÂÂÂÂ indio_dev->channels = inv_icm42600_gyro_channels;
>
> >ÂÂÂÂÂÂÂ indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_gyro_channels);
>
> > +ÂÂÂÂ indio_dev->available_scan_masks = inv_icm42600_gyro_scan_masks;
>
> > +
>
> > +ÂÂÂÂ ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inv_icm42600_gyro_handler,
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &inv_icm42600_buffer_ops);
>
> > +ÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>
> > +
>
> > +ÂÂÂÂ indio_dev->trig = iio_trigger_get(st->trigger);
>
> >Â
>
> >ÂÂÂÂÂÂÂ st->indio_gyro = indio_dev;
>
> >ÂÂÂÂÂÂÂ return devm_iio_device_register(dev, st->indio_gyro);
>
> >Â }
>
> > +
>
> > +int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev, int64_t ts)
>
> > +{
>
> > +ÂÂÂÂ struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
>
> > +ÂÂÂÂ const size_t gyro_nb = st->fifo.nb.gyro;
>
> > +ÂÂÂÂ ssize_t i, size;
>
> > +ÂÂÂÂ const void *accel, *gyro, *temp, *timestamp;
>
> > +ÂÂÂÂ unsigned int odr;
>
> > +ÂÂÂÂ struct inv_icm42600_gyro_buffer buffer;
>
> > +
>
> > +ÂÂÂÂ /* exit if no gyro sample */
>
> > +ÂÂÂÂ if (gyro_nb == 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ return 0;
>
> > +
>
> > +ÂÂÂÂ /* parse all fifo packets */
>
> > +ÂÂÂÂ for (i = 0; i < st->fifo.count; i += size) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ size = inv_icm42600_fifo_decode_packet(&st->fifo.data[i],
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &accel, &gyro, &temp, ×tamp, &odr);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ dev_dbg(regmap_get_device(st->map), "gyro packet size = %zd\n",
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ size);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* quit if error or FIFO is empty */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (size <= 0)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return size;
>
>
>
> blank line here.
>
>
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ /* skip packet if no gyro data or data is invalid */
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (gyro == NULL || !inv_icm42600_fifo_is_data_valid(gyro)) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_dbg(regmap_get_device(st->map), "skip gyro data\n");
>
>
>
> Very noisy logging. I'd drop it for the final version of the driver.
>
>
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ continue;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ }
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro));
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(&buffer.temp, temp, sizeof(buffer.temp));
>
>
>
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buffer.temp = temp;
>
>
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ iio_push_to_buffers_with_timestamp(indio_dev, &buffer, ts);
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ return 0;
>
> > +}
>
> > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_trigger.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_trigger.c
>
> > index 7a5e76305f0b..5667e0204722 100644
>
> > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_trigger.c
>
> > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_trigger.c
>
> > @@ -13,6 +13,7 @@
>
> >Â #include <linux/iio/trigger_consumer.h>
>
> >Â
>
> >Â #include "inv_icm42600.h"
>
> > +#include "inv_icm42600_buffer.h"
>
> >Â
>
> >Â static irqreturn_t inv_icm42600_trigger_timestamp(int irq, void *_data)
>
> >Â {
>
> > @@ -45,8 +46,18 @@ static irqreturn_t inv_icm42600_trigger_int_handler(int irq, void *_data)
>
> >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_warn(dev, "FIFO full data lost!\n");
>
> >Â
>
> >ÂÂÂÂÂÂÂ /* FIFO threshold reached */
>
> > -ÂÂÂÂ if (status & INV_ICM42600_INT_STATUS_FIFO_THS)
>
> > -ÂÂÂÂÂÂÂÂÂÂÂÂ iio_trigger_poll_chained(st->trigger);
>
> > +ÂÂÂÂ if (status & INV_ICM42600_INT_STATUS_FIFO_THS) {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ ret = inv_icm42600_buffer_fifo_read(st, 0);
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "FIFO read error %d\n", ret);
>
> > +ÂÂÂÂ } else {
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.count = 0;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.gyro = 0;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.accel = 0;
>
> > +ÂÂÂÂÂÂÂÂÂÂÂÂ st->fifo.nb.total = 0;
>
> > +ÂÂÂÂ }
>
> > +
>
> > +ÂÂÂÂ iio_trigger_poll_chained(st->trigger);
>
> >Â
>
> >Â out_unlock:
>
> >ÂÂÂÂÂÂÂ mutex_unlock(&st->lock);
>
>
>
>
>
>