Skip to contentSkip to conversation

iio: fix suspend and resume triggering for bmi160 and bmi270

PATCH In review Denis Benato 3 participants 8 messages May 25, 2025 – May 31, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover iio: fix suspend and resume triggering for bmi160 and bmi270

Two imu devices bmi160 and bmi270 are similar to bmi323, with the same bug and a common usecase: fix the aforementioned bug about triggering not resuming after sleep in the same way it was solved for the bmi323 device driver.

The bmi270 patch has been tested on a device where the device irq pin is connected to the CPU ensuring it doesn't cause harm to devices that do not use hrtimer or other external triggers.

Changelog from v1 [1]
- include linux/pm.h where needed
- used "Closed" to reference the solved issue for each driver
- merged two lines into one (on both drivers)

[1] https://lore.kernel.org/all/[email protected]

Denis Benato (2):
iio: bmi270: suspend and resume triggering on relevant pm operations
iio: bmi160: suspend and resume triggering on relevant pm operations

 drivers/iio/imu/bmi160/bmi160.h      |  2 ++
 drivers/iio/imu/bmi160/bmi160_core.c | 19 +++++++++++++++++++
 drivers/iio/imu/bmi160/bmi160_i2c.c  |  2 ++
 drivers/iio/imu/bmi160/bmi160_spi.c  |  2 ++
 drivers/iio/imu/bmi270/bmi270.h      |  2 ++
 drivers/iio/imu/bmi270/bmi270_core.c | 20 ++++++++++++++++++++
 drivers/iio/imu/bmi270/bmi270_i2c.c  |  2 ++
 drivers/iio/imu/bmi270/bmi270_spi.c  |  2 ++
 8 files changed, 51 insertions(+)
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 1/2 iio: bmi270: suspend and resume triggering on relevant pm operations

Prevent triggers from stop working after the device has entered sleep:
use iio_device_suspend_triggering and iio_device_resume_triggering helpers.

---
 drivers/iio/imu/bmi270/bmi270.h      |  2 ++
 drivers/iio/imu/bmi270/bmi270_core.c | 20 ++++++++++++++++++++
 drivers/iio/imu/bmi270/bmi270_i2c.c  |  2 ++
 drivers/iio/imu/bmi270/bmi270_spi.c  |  2 ++
 4 files changed, 26 insertions(+)
drivers/iio/imu/bmi270/bmi270.h +2 -0
index d94525f6aee8..a6c4204032fc 100644
@@ -20,4 +20,6 @@ struct device;
 int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 		      const struct bmi270_chip_info *chip_info);
 
+extern const struct dev_pm_ops bmi270_core_pm_ops;
+
 #endif  /* BMI270_H_ */
drivers/iio/imu/bmi270/bmi270_core.c +20 -0
index 2e4469f30d53..b54658f972ad 100644
@@ -982,6 +982,7 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 	indio_dev->available_scan_masks = bmi270_avail_scan_masks;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &bmi270_info;
+	dev_set_drvdata(data->dev, indio_dev);
 
 	ret = bmi270_trigger_probe(data, indio_dev);
 	if (ret)
@@ -997,6 +998,25 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 }
 EXPORT_SYMBOL_NS_GPL(bmi270_core_probe, "IIO_BMI270");
 
+static int bmi270_core_runtime_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_suspend_triggering(indio_dev);
+}
+
+static int bmi270_core_runtime_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_resume_triggering(indio_dev);
+}
+
+const struct dev_pm_ops bmi270_core_pm_ops = {
+	RUNTIME_PM_OPS(bmi270_core_runtime_suspend, bmi270_core_runtime_resume, NULL)
+};
+EXPORT_SYMBOL_NS_GPL(bmi270_core_pm_ops, "IIO_BMI270");
+
 MODULE_AUTHOR("Alex Lanzano");
 MODULE_DESCRIPTION("BMI270 driver");
 MODULE_LICENSE("GPL");
drivers/iio/imu/bmi270/bmi270_i2c.c +2 -0
index 44699ab58909..c77839b03a96 100644
@@ -4,6 +4,7 @@
 #include <linux/iio/iio.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 
 #include "bmi270.h"
@@ -52,6 +53,7 @@ static const struct of_device_id bmi270_of_match[] = {
 static struct i2c_driver bmi270_i2c_driver = {
 	.driver = {
 		.name = "bmi270_i2c",
+		.pm = pm_ptr(&bmi270_core_pm_ops),
 		.acpi_match_table = bmi270_acpi_match,
 		.of_match_table = bmi270_of_match,
 	},
drivers/iio/imu/bmi270/bmi270_spi.c +2 -0
index 88a77aba5e4f..19dd7734f9d0 100644
@@ -3,6 +3,7 @@
 #include <linux/iio/iio.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 
@@ -79,6 +80,7 @@ static const struct of_device_id bmi270_of_match[] = {
 static struct spi_driver bmi270_spi_driver = {
 	.driver = {
 		.name = "bmi270",
+		.pm = pm_ptr(&bmi270_core_pm_ops),
 		.of_match_table = bmi270_of_match,
 	},
 	.probe = bmi270_spi_probe,
Signature · 1 line
2.49.0
maintainer
#2 lore raw

Re: [PATCH v2 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations

Quoted 4 lines · On Sun, 25 May 2025 16:25:29 +0200 Denis Benato <[email protected]>…

Prevent triggers from stop working after the device has entered sleep:
use iio_device_suspend_triggering and iio_device_resume_triggering helpers.

This is a tag, so no blank line here.

I've fixed this in both patches and applied them to the to testing branch of iio. Currently I'm not planning to rush these in but I could treat them as fixes if general view is that I should.

Quoted 99 lines
---
 drivers/iio/imu/bmi270/bmi270.h      |  2 ++
 drivers/iio/imu/bmi270/bmi270_core.c | 20 ++++++++++++++++++++
 drivers/iio/imu/bmi270/bmi270_i2c.c  |  2 ++
 drivers/iio/imu/bmi270/bmi270_spi.c  |  2 ++
 4 files changed, 26 insertions(+)
drivers/iio/imu/bmi270/bmi270.h +2 -0
index d94525f6aee8..a6c4204032fc 100644
@@ -20,4 +20,6 @@ struct device;
 int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 		      const struct bmi270_chip_info *chip_info);
 
+extern const struct dev_pm_ops bmi270_core_pm_ops;
+
 #endif  /* BMI270_H_ */
drivers/iio/imu/bmi270/bmi270_core.c +20 -0
index 2e4469f30d53..b54658f972ad 100644
@@ -982,6 +982,7 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 	indio_dev->available_scan_masks = bmi270_avail_scan_masks;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &bmi270_info;
+	dev_set_drvdata(data->dev, indio_dev);
 
 	ret = bmi270_trigger_probe(data, indio_dev);
 	if (ret)
@@ -997,6 +998,25 @@ int bmi270_core_probe(struct device *dev, struct regmap *regmap,
 }
 EXPORT_SYMBOL_NS_GPL(bmi270_core_probe, "IIO_BMI270");
 
+static int bmi270_core_runtime_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_suspend_triggering(indio_dev);
+}
+
+static int bmi270_core_runtime_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_resume_triggering(indio_dev);
+}
+
+const struct dev_pm_ops bmi270_core_pm_ops = {
+	RUNTIME_PM_OPS(bmi270_core_runtime_suspend, bmi270_core_runtime_resume, NULL)
+};
+EXPORT_SYMBOL_NS_GPL(bmi270_core_pm_ops, "IIO_BMI270");
+
 MODULE_AUTHOR("Alex Lanzano");
 MODULE_DESCRIPTION("BMI270 driver");
 MODULE_LICENSE("GPL");
drivers/iio/imu/bmi270/bmi270_i2c.c +2 -0
index 44699ab58909..c77839b03a96 100644
@@ -4,6 +4,7 @@
 #include <linux/iio/iio.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 
 #include "bmi270.h"
@@ -52,6 +53,7 @@ static const struct of_device_id bmi270_of_match[] = {
 static struct i2c_driver bmi270_i2c_driver = {
 	.driver = {
 		.name = "bmi270_i2c",
+		.pm = pm_ptr(&bmi270_core_pm_ops),
 		.acpi_match_table = bmi270_acpi_match,
 		.of_match_table = bmi270_of_match,
 	},
drivers/iio/imu/bmi270/bmi270_spi.c +2 -0
index 88a77aba5e4f..19dd7734f9d0 100644
@@ -3,6 +3,7 @@
 #include <linux/iio/iio.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 
@@ -79,6 +80,7 @@ static const struct of_device_id bmi270_of_match[] = {
 static struct spi_driver bmi270_spi_driver = {
 	.driver = {
 		.name = "bmi270",
+		.pm = pm_ptr(&bmi270_core_pm_ops),
 		.of_match_table = bmi270_of_match,
 	},
 	.probe = bmi270_spi_probe,
#3 lore raw

PATCH v2 2/2 iio: bmi160: suspend and resume triggering on relevant pm operations

In reply to Denis Benato

Prevent triggers from stop working after the device has entered sleep:
use iio_device_suspend_triggering and iio_device_resume_triggering helpers.

---
 drivers/iio/imu/bmi160/bmi160.h      |  2 ++
 drivers/iio/imu/bmi160/bmi160_core.c | 19 +++++++++++++++++++
 drivers/iio/imu/bmi160/bmi160_i2c.c  |  2 ++
 drivers/iio/imu/bmi160/bmi160_spi.c  |  2 ++
 4 files changed, 25 insertions(+)
drivers/iio/imu/bmi160/bmi160.h +2 -0
index 32c2ea2d7112..ffbe8205e703 100644
@@ -28,4 +28,6 @@ int bmi160_enable_irq(struct regmap *regmap, bool enable);
 
 int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type);
 
+extern const struct dev_pm_ops bmi160_core_pm_ops;
+
 #endif  /* BMI160_H_ */
drivers/iio/imu/bmi160/bmi160_core.c +19 -0
index 0423ef6f9571..9aa54b95b89f 100644
@@ -890,6 +890,25 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,
 }
 EXPORT_SYMBOL_NS_GPL(bmi160_core_probe, "IIO_BMI160");
 
+static int bmi160_core_runtime_suspend(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_suspend_triggering(indio_dev);
+}
+
+static int bmi160_core_runtime_resume(struct device *dev)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+
+	return iio_device_resume_triggering(indio_dev);
+}
+
+const struct dev_pm_ops bmi160_core_pm_ops = {
+	RUNTIME_PM_OPS(bmi160_core_runtime_suspend, bmi160_core_runtime_resume, NULL)
+};
+EXPORT_SYMBOL_NS_GPL(bmi160_core_pm_ops, "IIO_BMI160");
+
 MODULE_AUTHOR("Daniel Baluta <[email protected]>");
 MODULE_DESCRIPTION("Bosch BMI160 driver");
 MODULE_LICENSE("GPL v2");
drivers/iio/imu/bmi160/bmi160_i2c.c +2 -0
index 9fa3a19a8977..3e2758f4e0d3 100644
@@ -11,6 +11,7 @@
 #include <linux/i2c.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 
 #include "bmi160.h"
@@ -69,6 +70,7 @@ MODULE_DEVICE_TABLE(of, bmi160_of_match);
 static struct i2c_driver bmi160_i2c_driver = {
 	.driver = {
 		.name			= "bmi160_i2c",
+		.pm			= pm_ptr(&bmi160_core_pm_ops),
 		.acpi_match_table	= bmi160_acpi_match,
 		.of_match_table		= bmi160_of_match,
 	},
drivers/iio/imu/bmi160/bmi160_spi.c +2 -0
index ebb586904215..3581bd788483 100644
@@ -7,6 +7,7 @@
  */
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 
@@ -61,6 +62,7 @@ static struct spi_driver bmi160_spi_driver = {
 		.acpi_match_table	= bmi160_acpi_match,
 		.of_match_table		= bmi160_of_match,
 		.name			= "bmi160_spi",
+		.pm			= pm_ptr(&bmi160_core_pm_ops),
 	},
 };
 module_spi_driver(bmi160_spi_driver);
Signature · 1 line
2.49.0
#4 lore raw
In reply to Denis Benato
Quoted 4 lines · Denis Benato

Two imu devices bmi160 and bmi270 are similar to bmi323, with the same bug and a common usecase: fix the aforementioned bug about triggering not resuming after sleep in the same way it was solved for the bmi323 device driver.

Quoted 8 lines

The bmi270 patch has been tested on a device where the device irq pin is connected to the CPU ensuring it doesn't cause harm to devices that do not use hrtimer or other external triggers.

Changelog from v1 [1]
- include linux/pm.h where needed
- used "Closed" to reference the solved issue for each driver
- merged two lines into one (on both drivers)

I got this series twice without any (?) difference in the versions. Care to explain what's going on?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Denis Benato

Two imu devices bmi160 and bmi270 are similar to bmi323, with the same bug and a common usecase: fix the aforementioned bug about triggering not resuming after sleep in the same way it was solved for the bmi323 device driver.

The bmi270 patch has been tested on a device where the device irq pin is connected to the CPU ensuring it doesn't cause harm to devices that do not use hrtimer or other external triggers.

Quoted 8 lines
Quoted 4 lines

Changelog from v1 [1]
- include linux/pm.h where needed
- used "Closed" to reference the solved issue for each driver
- merged two lines into one (on both drivers)

I got this series twice without any (?) difference in the versions. Care to explain what's going on?

I am sorry: mails were not being sent to the main lkml nor the iio mailing list and so I resent to everybody, otherwise doing "answer to all" would have created a mess where discussions would get lost.

#6 lore raw
Quoted 14 lines · Denis Benato
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Denis Benato

Two imu devices bmi160 and bmi270 are similar to bmi323, with the same bug and a common usecase: fix the aforementioned bug about triggering not resuming after sleep in the same way it was solved for the bmi323 device driver.

The bmi270 patch has been tested on a device where the device irq pin is connected to the CPU ensuring it doesn't cause harm to devices that do not use hrtimer or other external triggers.

Changelog from v1 [1]
- include linux/pm.h where needed
- used "Closed" to reference the solved issue for each driver
- merged two lines into one (on both drivers)

Quoted 6 lines
Quoted 3 lines

I got this series twice without any (?) difference in the versions. Care to explain what's going on?

I am sorry: mails were not being sent to the main lkml nor the iio mailing list and so I resent to everybody, otherwise doing "answer to all" would have created a mess where discussions would get lost.

Always mention this kind of things in a cover letter when resending and ideally add a word 'resend' to the Subject.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Denis Benato
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Denis Benato

Two imu devices bmi160 and bmi270 are similar to bmi323, with the same bug and a common usecase: fix the aforementioned bug about triggering not resuming after sleep in the same way it was solved for the bmi323 device driver.

The bmi270 patch has been tested on a device where the device irq pin is connected to the CPU ensuring it doesn't cause harm to devices that do not use hrtimer or other external triggers.

Changelog from v1 [1]
- include linux/pm.h where needed
- used "Closed" to reference the solved issue for each driver
- merged two lines into one (on both drivers)

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I got this series twice without any (?) difference in the versions. Care to explain what's going on?

I am sorry: mails were not being sent to the main lkml nor the iio mailing list and so I resent to everybody, otherwise doing "answer to all" would have created a mess where discussions would get lost.

Always mention this kind of things in a cover letter when resending and ideally add a word 'resend' to the Subject.

Thank you. I wasn't sure if using RESEND was a good idea because I have only read about it being mentioned in the context of the original being lost and was thinking about the mailing list receiving a RESEND without the original one. I will keep this in mind for the future, hoping I won't do this silly mistake again.

Thanks for you patience.