From: Liu Yufei <lyf98405@gmail.com>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Alex Lanzano" <lanzano.alex@gmail.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Gustavo Silva" <gustavograzs@gmail.com>,
stable@vger.kernel.org, "Liu Yufei" <lyf98405@gmail.com>
Subject: [PATCH v3] iio: imu: bmi270: fix zero timestamp in triggered buffer
Date: Tue, 24 Nov 2026 17:10:07 +0800 [thread overview]
Message-ID: <20261124-bmi270-fix-timestamp-v3-1-6356a5467d5a@gmail.com> (raw)
The BMI270's own trigger uses iio_trigger_poll_nested() from
the threaded IRQ handler, bypassing the pollfunc top half.
This leaves the buffer timestamp at zero or a stale value.
Capture the timestamp in the hard IRQ handler and use it when
the selected trigger is the BMI270's own trigger. For an
external trigger, take the timestamp in the threaded buffer
handler before reading the sensor. Drop the pollfunc top half
now that the buffer handler always supplies the timestamp.
On an Orange Pi Zero 2W, the original driver produced 256 zero
timestamps in 256 samples with the BMI270's own trigger.
Fixes: a1854d55f54b ("iio: imu: bmi270: add support for data ready interrupt trigger")
Cc: stable@vger.kernel.org
Signed-off-by: Liu Yufei <lyf98405@gmail.com>
---
Changes in v3:
- Timestamp all external triggers in the threaded buffer handler.
- Drop the unused pollfunc top half and the timestamp resets.
- Match the selected trigger against the BMI270 trigger directly.
Codex identified the shared-trigger case during review.
- Link to v2: https://patch.msgid.link/20261106-bmi270-fix-timestamp-v2-1-8a2547e1290b@gmail.com
Changes in v2:
- Capture the timestamp in the hard IRQ handler.
- Use the IRQ timestamp for the device's own trigger.
- Fall back to the current time when no pollfunc timestamp exists.
- Clear the pollfunc timestamp after processing.
- Link to v1: https://patch.msgid.link/20261028-bmi270-fix-timestamp-v1-1-99c0e5fe7d0c@gmail.com
---
drivers/iio/imu/bmi270/bmi270_core.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c
index fbcf6bb87acc..6983d80efee1 100644
--- a/drivers/iio/imu/bmi270/bmi270_core.c
+++ b/drivers/iio/imu/bmi270/bmi270_core.c
@@ -157,6 +157,7 @@ struct bmi270_data {
const struct bmi270_chip_info *chip_info;
enum bmi270_irq_pin irq_pin;
struct iio_trigger *trig;
+ s64 irq_timestamp;
/* Protect device's private data from concurrent access */
struct mutex mutex;
bool steps_enabled;
@@ -755,6 +756,16 @@ static int bmi270_get_odr(struct bmi270_data *data, int chan_type, int *odr,
return -EINVAL;
}
+static irqreturn_t bmi270_irq_handler(int irq, void *private)
+{
+ struct iio_dev *indio_dev = private;
+ struct bmi270_data *data = iio_priv(indio_dev);
+
+ data->irq_timestamp = iio_get_time_ns(indio_dev);
+
+ return IRQ_WAKE_THREAD;
+}
+
static irqreturn_t bmi270_irq_thread_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
@@ -840,8 +851,14 @@ static irqreturn_t bmi270_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct bmi270_data *data = iio_priv(indio_dev);
+ s64 timestamp;
int ret;
+ if (indio_dev->trig == data->trig)
+ timestamp = data->irq_timestamp;
+ else
+ timestamp = iio_get_time_ns(indio_dev);
+
guard(mutex)(&data->mutex);
ret = regmap_bulk_read(data->regmap, BMI270_ACCEL_X_REG,
@@ -852,7 +869,7 @@ static irqreturn_t bmi270_trigger_handler(int irq, void *p)
goto done;
iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer,
- pf->timestamp);
+ timestamp);
done:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
@@ -1430,7 +1447,7 @@ static int bmi270_trigger_probe(struct bmi270_data *data,
data->trig->ops = &bmi270_trigger_ops;
iio_trigger_set_drvdata(data->trig, data);
- ret = devm_request_threaded_irq(data->dev, irq, NULL,
+ ret = devm_request_threaded_irq(data->dev, irq, bmi270_irq_handler,
bmi270_irq_thread_handler,
IRQF_ONESHOT, "bmi270-int", indio_dev);
if (ret)
@@ -1630,8 +1647,7 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap,
if (ret)
return ret;
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- iio_pollfunc_store_time,
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
bmi270_trigger_handler, NULL);
if (ret)
return ret;
---
base-commit: 09f742b49cb2728086d78be2b0b35e4d1d71fc85
change-id: 20261028-bmi270-fix-timestamp-48a194b69db1
Best regards,
--
Liu Yufei <lyf98405@gmail.com>
reply other threads:[~2026-11-24 9:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261124-bmi270-fix-timestamp-v3-1-6356a5467d5a@gmail.com \
--to=lyf98405@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavograzs@gmail.com \
--cc=jic23@kernel.org \
--cc=lanzano.alex@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®