* [PATCH 0/2] iio: fix suspend and resume triggering for bmi160 and bmi270 @ 2025-05-09 17:15 Denis Benato 2025-05-09 17:15 ` [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations Denis Benato 2025-05-09 17:15 ` [PATCH 2/2] iio: bmi160: " Denis Benato 0 siblings, 2 replies; 7+ messages in thread From: Denis Benato @ 2025-05-09 17:15 UTC (permalink / raw) To: Jonathan Cameron Cc: Alex Lanzano, David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, Derek J. Clark, Philip Müller, 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. 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 | 20 ++++++++++++++++++++ drivers/iio/imu/bmi160/bmi160_i2c.c | 1 + drivers/iio/imu/bmi160/bmi160_spi.c | 1 + drivers/iio/imu/bmi270/bmi270.h | 2 ++ drivers/iio/imu/bmi270/bmi270_core.c | 21 +++++++++++++++++++++ drivers/iio/imu/bmi270/bmi270_i2c.c | 1 + drivers/iio/imu/bmi270/bmi270_spi.c | 1 + 8 files changed, 49 insertions(+) -- 2.49.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations 2025-05-09 17:15 [PATCH 0/2] iio: fix suspend and resume triggering for bmi160 and bmi270 Denis Benato @ 2025-05-09 17:15 ` Denis Benato 2025-05-12 8:54 ` Andy Shevchenko 2025-05-09 17:15 ` [PATCH 2/2] iio: bmi160: " Denis Benato 1 sibling, 1 reply; 7+ messages in thread From: Denis Benato @ 2025-05-09 17:15 UTC (permalink / raw) To: Jonathan Cameron Cc: Alex Lanzano, David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, Derek J. Clark, Philip Müller, Denis Benato, Justin Weiss Prevent triggers from stop working after the device has entered sleep: use iio_device_suspend_triggering and iio_device_resume_triggering helpers. Signed-off-by: Denis Benato <benato.denis96@gmail.com> Tested-by: Justin Weiss <justin@justinweiss.com> --- drivers/iio/imu/bmi270/bmi270.h | 2 ++ drivers/iio/imu/bmi270/bmi270_core.c | 21 +++++++++++++++++++++ drivers/iio/imu/bmi270/bmi270_i2c.c | 1 + drivers/iio/imu/bmi270/bmi270_spi.c | 1 + 4 files changed, 25 insertions(+) diff --git a/drivers/iio/imu/bmi270/bmi270.h b/drivers/iio/imu/bmi270/bmi270.h index d94525f6aee8..a6c4204032fc 100644 --- a/drivers/iio/imu/bmi270/bmi270.h +++ b/drivers/iio/imu/bmi270/bmi270.h @@ -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_ */ diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c index 2e4469f30d53..31fd1730a3d3 100644 --- a/drivers/iio/imu/bmi270/bmi270_core.c +++ b/drivers/iio/imu/bmi270/bmi270_core.c @@ -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,26 @@ 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"); diff --git a/drivers/iio/imu/bmi270/bmi270_i2c.c b/drivers/iio/imu/bmi270/bmi270_i2c.c index 44699ab58909..a6e357b97d31 100644 --- a/drivers/iio/imu/bmi270/bmi270_i2c.c +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c @@ -52,6 +52,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, }, diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/bmi270_spi.c index 88a77aba5e4f..b25171413531 100644 --- a/drivers/iio/imu/bmi270/bmi270_spi.c +++ b/drivers/iio/imu/bmi270/bmi270_spi.c @@ -79,6 +79,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, -- 2.49.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations 2025-05-09 17:15 ` [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations Denis Benato @ 2025-05-12 8:54 ` Andy Shevchenko 2025-05-24 20:25 ` Denis Benato 0 siblings, 1 reply; 7+ messages in thread From: Andy Shevchenko @ 2025-05-12 8:54 UTC (permalink / raw) To: Denis Benato Cc: Jonathan Cameron, Alex Lanzano, David Lechner, Nuno Sá, linux-iio, Derek J. Clark, Philip Müller, Justin Weiss On Fri, May 09, 2025 at 07:15:25PM +0200, Denis Benato wrote: > Prevent triggers from stop working after the device has entered sleep: > use iio_device_suspend_triggering and iio_device_resume_triggering helpers. The cover letter call it a fix, where is the Fixes tag? ... > +const struct dev_pm_ops bmi270_core_pm_ops = { > + RUNTIME_PM_OPS(bmi270_core_runtime_suspend, > + bmi270_core_runtime_resume, NULL) One line (it's only 85 characters and it's fine in this case). > +}; ... > --- a/drivers/iio/imu/bmi270/bmi270_i2c.c > +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c > @@ -52,6 +52,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), Is pm.h included? > .acpi_match_table = bmi270_acpi_match, > .of_match_table = bmi270_of_match, > }, > diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/bmi270_spi.c > index 88a77aba5e4f..b25171413531 100644 > --- a/drivers/iio/imu/bmi270/bmi270_spi.c > +++ b/drivers/iio/imu/bmi270/bmi270_spi.c > @@ -79,6 +79,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), Ditto. > .of_match_table = bmi270_of_match, > }, > .probe = bmi270_spi_probe, -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations 2025-05-12 8:54 ` Andy Shevchenko @ 2025-05-24 20:25 ` Denis Benato 2025-05-25 9:33 ` Jonathan Cameron 0 siblings, 1 reply; 7+ messages in thread From: Denis Benato @ 2025-05-24 20:25 UTC (permalink / raw) To: Andy Shevchenko Cc: Jonathan Cameron, Alex Lanzano, David Lechner, Nuno Sá, linux-iio, Derek J. Clark, Philip Müller, Justin Weiss On 5/12/25 10:54, Andy Shevchenko wrote: > On Fri, May 09, 2025 at 07:15:25PM +0200, Denis Benato wrote: >> Prevent triggers from stop working after the device has entered sleep: >> use iio_device_suspend_triggering and iio_device_resume_triggering helpers. > The cover letter call it a fix, where is the Fixes tag? I didn't know if it was okay to use that tag while to root cause is still there and it needs to be fixed for a lot more devices. I was also attempting to make this patch very similar to accepted one: https://lore.kernel.org/all/20240807185619.7261-3-benato.denis96@gmail.com/ Is fixed tag appropriate? > > ... > >> +const struct dev_pm_ops bmi270_core_pm_ops = { >> + RUNTIME_PM_OPS(bmi270_core_runtime_suspend, >> + bmi270_core_runtime_resume, NULL) > One line (it's only 85 characters and it's fine in this case). Okay, will send a new version when I have answer to the above question. >> +}; > ... > >> --- a/drivers/iio/imu/bmi270/bmi270_i2c.c >> +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c >> @@ -52,6 +52,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), > Is pm.h included? I assumed it was not needed since the i2c_driver definition should be enough. I will include pm.h on the next version, thanks. > >> .acpi_match_table = bmi270_acpi_match, >> .of_match_table = bmi270_of_match, >> }, >> diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/bmi270_spi.c >> index 88a77aba5e4f..b25171413531 100644 >> --- a/drivers/iio/imu/bmi270/bmi270_spi.c >> +++ b/drivers/iio/imu/bmi270/bmi270_spi.c >> @@ -79,6 +79,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), > Ditto. >> .of_match_table = bmi270_of_match, >> }, >> .probe = bmi270_spi_probe, I don't know how but your answer was lost in my mail. Sorry for the late response and thank you for your suggestions, Denis ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations 2025-05-24 20:25 ` Denis Benato @ 2025-05-25 9:33 ` Jonathan Cameron 0 siblings, 0 replies; 7+ messages in thread From: Jonathan Cameron @ 2025-05-25 9:33 UTC (permalink / raw) To: Denis Benato Cc: Andy Shevchenko, Alex Lanzano, David Lechner, Nuno Sá, linux-iio, Derek J. Clark, Philip Müller, Justin Weiss On Sat, 24 May 2025 22:25:11 +0200 Denis Benato <benato.denis96@gmail.com> wrote: > On 5/12/25 10:54, Andy Shevchenko wrote: > > On Fri, May 09, 2025 at 07:15:25PM +0200, Denis Benato wrote: > >> Prevent triggers from stop working after the device has entered sleep: > >> use iio_device_suspend_triggering and iio_device_resume_triggering helpers. > > The cover letter call it a fix, where is the Fixes tag? > I didn't know if it was okay to use that tag while to root cause is still there and it needs to be fixed for a lot more devices. > > I was also attempting to make this patch very similar to accepted one: https://lore.kernel.org/all/20240807185619.7261-3-benato.denis96@gmail.com/ > > Is fixed tag appropriate? I think it probably is appropriate given not having a trigger restart after returning from suspend is unlikely to be desired behaviour. Jonathan > > > > > ... > > > >> +const struct dev_pm_ops bmi270_core_pm_ops = { > >> + RUNTIME_PM_OPS(bmi270_core_runtime_suspend, > >> + bmi270_core_runtime_resume, NULL) > > One line (it's only 85 characters and it's fine in this case). > > > Okay, will send a new version when I have answer to the above question. > > > >> +}; > > ... > > > >> --- a/drivers/iio/imu/bmi270/bmi270_i2c.c > >> +++ b/drivers/iio/imu/bmi270/bmi270_i2c.c > >> @@ -52,6 +52,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), > > Is pm.h included? > I assumed it was not needed since the i2c_driver definition should be enough. > > > I will include pm.h on the next version, thanks. > > > > > >> .acpi_match_table = bmi270_acpi_match, > >> .of_match_table = bmi270_of_match, > >> }, > >> diff --git a/drivers/iio/imu/bmi270/bmi270_spi.c b/drivers/iio/imu/bmi270/bmi270_spi.c > >> index 88a77aba5e4f..b25171413531 100644 > >> --- a/drivers/iio/imu/bmi270/bmi270_spi.c > >> +++ b/drivers/iio/imu/bmi270/bmi270_spi.c > >> @@ -79,6 +79,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), > > Ditto. > >> .of_match_table = bmi270_of_match, > >> }, > >> .probe = bmi270_spi_probe, > I don't know how but your answer was lost in my mail. > > Sorry for the late response and thank you for your suggestions, > Denis > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] iio: bmi160: suspend and resume triggering on relevant pm operations 2025-05-09 17:15 [PATCH 0/2] iio: fix suspend and resume triggering for bmi160 and bmi270 Denis Benato 2025-05-09 17:15 ` [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations Denis Benato @ 2025-05-09 17:15 ` Denis Benato 2025-05-12 8:55 ` Andy Shevchenko 1 sibling, 1 reply; 7+ messages in thread From: Denis Benato @ 2025-05-09 17:15 UTC (permalink / raw) To: Jonathan Cameron Cc: Alex Lanzano, David Lechner, Nuno Sá, Andy Shevchenko, linux-iio, Derek J. Clark, Philip Müller, Denis Benato Prevent triggers from stop working after the device has entered sleep: use iio_device_suspend_triggering and iio_device_resume_triggering helpers. Signed-off-by: Denis Benato <benato.denis96@gmail.com> --- drivers/iio/imu/bmi160/bmi160.h | 2 ++ drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++++++++ drivers/iio/imu/bmi160/bmi160_i2c.c | 1 + drivers/iio/imu/bmi160/bmi160_spi.c | 1 + 4 files changed, 24 insertions(+) diff --git a/drivers/iio/imu/bmi160/bmi160.h b/drivers/iio/imu/bmi160/bmi160.h index 32c2ea2d7112..ffbe8205e703 100644 --- a/drivers/iio/imu/bmi160/bmi160.h +++ b/drivers/iio/imu/bmi160/bmi160.h @@ -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_ */ diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index 0423ef6f9571..6233155f1112 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -890,6 +890,26 @@ 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 <daniel.baluta@intel.com>"); MODULE_DESCRIPTION("Bosch BMI160 driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/imu/bmi160/bmi160_i2c.c b/drivers/iio/imu/bmi160/bmi160_i2c.c index 9fa3a19a8977..732191c799dd 100644 --- a/drivers/iio/imu/bmi160/bmi160_i2c.c +++ b/drivers/iio/imu/bmi160/bmi160_i2c.c @@ -69,6 +69,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, }, diff --git a/drivers/iio/imu/bmi160/bmi160_spi.c b/drivers/iio/imu/bmi160/bmi160_spi.c index ebb586904215..8addcf5891ae 100644 --- a/drivers/iio/imu/bmi160/bmi160_spi.c +++ b/drivers/iio/imu/bmi160/bmi160_spi.c @@ -61,6 +61,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); -- 2.49.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] iio: bmi160: suspend and resume triggering on relevant pm operations 2025-05-09 17:15 ` [PATCH 2/2] iio: bmi160: " Denis Benato @ 2025-05-12 8:55 ` Andy Shevchenko 0 siblings, 0 replies; 7+ messages in thread From: Andy Shevchenko @ 2025-05-12 8:55 UTC (permalink / raw) To: Denis Benato Cc: Jonathan Cameron, Alex Lanzano, David Lechner, Nuno Sá, linux-iio, Derek J. Clark, Philip Müller On Fri, May 09, 2025 at 07:15:26PM +0200, Denis Benato wrote: > Prevent triggers from stop working after the device has entered sleep: > use iio_device_suspend_triggering and iio_device_resume_triggering helpers. Same comments as per previous patch. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-05-25 9:33 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-09 17:15 [PATCH 0/2] iio: fix suspend and resume triggering for bmi160 and bmi270 Denis Benato 2025-05-09 17:15 ` [PATCH 1/2] iio: bmi270: suspend and resume triggering on relevant pm operations Denis Benato 2025-05-12 8:54 ` Andy Shevchenko 2025-05-24 20:25 ` Denis Benato 2025-05-25 9:33 ` Jonathan Cameron 2025-05-09 17:15 ` [PATCH 2/2] iio: bmi160: " Denis Benato 2025-05-12 8:55 ` Andy Shevchenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox