Skip to contentSkip to conversation

patch "iio: magnetometer: ak8975: ensure device is awake for buffered" added to char-misc-testing

PATCH [email protected] 1 participant 1 message Jun 8

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

iio: magnetometer: ak8975: ensure device is awake for buffered

to my char-misc git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
in the char-misc-testing branch.

The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)

The patch will be merged to the char-misc-next branch sometime soon, after it passes testing, and the merge window is open.

If you have any questions about this process, please let me know.

From eaead586b3d95890832449f2887283b067426ecc Mon Sep 17 00:00:00 2001
From: Joshua Crofts <[email protected]>
Date: Wed, 13 May 2026 16:35:52 +0200
Subject: iio: magnetometer: ak8975: ensure device is awake for buffered
capture

Currently, the ak8975_start_read_axis() can be called while the device is autosuspended, causing two issues:

1. I2C transfers in the aforementioned function will fail or timeout because ak8975_runtime_suspend() disables the device regulators.
2. Since ak8975_fill_buffer() does not hold runtime references, ak8975_runtime_suspend() can run concurrently, and since PM callbacks do not use a locking mechanism, it may cause a race accessing the control register via the I2C bus.

Fix this issue by adding struct iio_buffer_setup_ops that contains preenable and postdisable functions to ensure correct that device is powered on when running a buffered capture.

---
 drivers/iio/magnetometer/ak8975.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +23 -1
index dbab4d0bba34..0fb2fd03d11c 100644
@@ -899,6 +899,28 @@ static irqreturn_t ak8975_handle_trigger(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
+static int ak8975_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct ak8975_data *data = iio_priv(indio_dev);
+	struct device *dev = &data->client->dev;
+
+	return pm_runtime_resume_and_get(dev);
+}
+
+static int ak8975_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct ak8975_data *data = iio_priv(indio_dev);
+	struct device *dev = &data->client->dev;
+
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+}
+
+static const struct iio_buffer_setup_ops ak8975_buffer_setup_ops = {
+	.preenable = ak8975_buffer_preenable,
+	.postdisable = ak8975_buffer_postdisable,
+};
 static int ak8975_probe(struct i2c_client *client)
 {
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
@@ -992,7 +1014,7 @@ static int ak8975_probe(struct i2c_client *client)
 	indio_dev->name = name;
 
 	ret = iio_triggered_buffer_setup(indio_dev, NULL, ak8975_handle_trigger,
-					 NULL);
+					 &ak8975_buffer_setup_ops);
 	if (ret) {
 		dev_err(&client->dev, "triggered buffer setup failed\n");
 		goto power_off;
Signature · 1 line
2.54.0