From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: SeungJu Cheon <suunj1331@gmail.com>,
linux-iio@vger.kernel.org, dlechner@baylibre.com,
nuno.sa@analog.com, andy@kernel.org, apokusinski01@gmail.com,
me@brighamcampbell.com, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH 4/4] iio: pressure: mpl3115: add hardware FIFO support
Date: Sat, 30 May 2026 16:43:06 +0100 [thread overview]
Message-ID: <20260530164306.70c9ac71@jic23-huawei> (raw)
In-Reply-To: <CAHp75VcN7B5BdKZGBiw5cbhYesGsO_tStcN3cKgggiHiuSnJ7w@mail.gmail.com>
On Sat, 30 May 2026 15:32:23 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Sat, May 30, 2026 at 1:40 PM SeungJu Cheon <suunj1331@gmail.com> wrote:
> >
> > Add support for the MPL3115A2 hardware FIFO.
> >
> > The device provides a 32-sample FIFO with configurable
> > watermark interrupts, allowing buffered data acquisition
> > with reduced interrupt and CPU overhead.
> >
> > Use a kfifo-backed IIO buffer when a DRDY interrupt and
> > SMBus block reads are available, falling back to the
> > existing triggered buffer implementation otherwise.
> >
> > When enabled, the driver configures the FIFO in circular
> > mode and drains accumulated samples on watermark
> > interrupts.
> >
> > Overflow conditions are handled by flushing available
> > samples before resetting the FIFO, avoiding unnecessary
> > data loss.
> >
> > The hardware always captures pressure and temperature
> > samples together, so FIFO operation requires both channels
> > to be enabled.
> >
> > Register cache updates are performed only after successful
> > I2C writes to keep cached and hardware state consistent.
> >
> > No functional change for non-buffered operation.
>
Some fun stuff that Andy has picked out here, so a few comment on top
(I was wondering some of the same things!)
> ...
>
> > + u8 fifo_buf[MPL3115_FIFO_SIZE * MPL3115_FIFO_SAMPLE_SIZE]
> > + __aligned(IIO_DMA_MINALIGN);
>
> We have a macro for this,
Which one? We have the buffer + timestamp ones for IIO but that' not
relevant here.
>
> ...
>
> > +static int mpl3115_fifo_flush(struct iio_dev *indio_dev)
> > +{
> > + struct mpl3115_data *data = iio_priv(indio_dev);
> > + u8 buffer[MPL3115_BUF_SIZE] __aligned(sizeof(s64)) = { };
>
> Don't we have a macro for this?
This one seems more likely to be one we cover IIO_DECLARE_BUFFER_WITH_TS()
However, looks like the ts is always in the same place and all channels are
captured so I'd prefer this as something like
struct {
__be32 pressure;
__be16 temp;
//there is a gap here hence need to force initialization to avoid stack content leaking.
aligned_s64 ts;
} scan = { };
>
> > + unsigned int sample_count, i;
> > + int ret;
> > + bool overflow;
> > + s64 ts;
> > +
> > + ret = i2c_smbus_read_byte_data(data->client, MPL3115_F_STATUS);
> > + if (ret < 0)
> > + return ret;
> > +
> > + overflow = FIELD_GET(MPL3115_F_STATUS_F_OVF, ret);
> > + sample_count = FIELD_GET(MPL3115_F_STATUS_F_CNT, ret);
> > + if (sample_count == 0)
> > + return overflow ? mpl3115_fifo_reset(data) : 0;
> > +
> > + ret = mpl3115_fifo_transfer(data, sample_count);
> > + if (ret)
> > + return ret;
> > +
> > + ts = iio_get_time_ns(indio_dev);
> > + for (i = 0; i < sample_count; i++) {
>
> for (unsigned int i = 0; ...) {
>
> > + u8 *sample = &data->fifo_buf[i * MPL3115_FIFO_SAMPLE_SIZE];
>
> > + memcpy(&buffer[MPL3115_BUF_PRESS_OFFSET], &sample[0], 3);
> > + memcpy(&buffer[MPL3115_BUF_TEMP_OFFSET], &sample[3], 2);
>
> These two sound to me like something which might require endianness
> handling, but if you put this as CPU native one and leave user space
> to take care of, it may be okay.
They are big endian channels so this 'should' be fine but we should make that explicit.
Not the chan_spec for the 20 bit read has a shift of 12 to get around the last byte
not being filled by this memcpy.
(other stuff Andy pointed out cropped)
J
next prev parent reply other threads:[~2026-05-30 15:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 11:39 [PATCH 0/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 11:39 ` [PATCH 1/4] iio: pressure: mpl3115: convert probe to fully devm managed SeungJu Cheon
2026-05-30 12:12 ` Andy Shevchenko
2026-05-31 10:46 ` SeungJu Cheon
2026-05-30 15:10 ` Jonathan Cameron
2026-05-31 10:49 ` SeungJu Cheon
2026-05-31 14:29 ` Jonathan Cameron
2026-05-30 11:39 ` [PATCH 2/4] iio: pressure: mpl3115: clean up interrupt handling and locking SeungJu Cheon
2026-05-30 12:33 ` Andy Shevchenko
2026-05-31 10:55 ` SeungJu Cheon
2026-05-30 15:23 ` Jonathan Cameron
2026-05-31 10:59 ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 3/4] iio: pressure: mpl3115: generalize interrupt pin routing SeungJu Cheon
2026-05-30 12:39 ` Andy Shevchenko
2026-05-31 11:01 ` SeungJu Cheon
2026-05-30 15:32 ` Jonathan Cameron
2026-05-31 11:08 ` SeungJu Cheon
2026-05-30 11:39 ` [PATCH 4/4] iio: pressure: mpl3115: add hardware FIFO support SeungJu Cheon
2026-05-30 13:32 ` Andy Shevchenko
2026-05-30 15:43 ` Jonathan Cameron [this message]
2026-06-02 10:31 ` Andy Shevchenko
2026-05-31 11:15 ` SeungJu Cheon
2026-05-30 16:05 ` Jonathan Cameron
2026-05-31 12:38 ` SeungJu Cheon
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=20260530164306.70c9ac71@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=apokusinski01@gmail.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=me@brighamcampbell.com \
--cc=nuno.sa@analog.com \
--cc=skhan@linuxfoundation.org \
--cc=suunj1331@gmail.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