power: supply: bq27xxx: Stop and start delayed work in suspend and resume
authorMarek Vasut <marex@denx.de>
Sat, 4 Nov 2023 15:49:06 +0000 (16:49 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 15 Nov 2023 22:13:26 +0000 (23:13 +0100)
This driver uses delayed work to perform periodic battery state read out.
This delayed work is not stopped across suspend and resume cycle. The
read out can occur early in the resume cycle. In case of an I2C variant
of this hardware, that read out triggers I2C transfer. That I2C transfer
may happen while the I2C controller is still suspended, which produces a
WARNING in the kernel log.

Fix this by introducing trivial PM ops, which stop the delayed work before
the system enters suspend, and schedule the delayed work right after the
system resumes.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20231104154920.68585-1-marex@denx.de
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/bq27xxx_battery.c
drivers/power/supply/bq27xxx_battery_i2c.c
include/linux/power/bq27xxx_battery.h

index 4296600e8912a3988c45286f58420ffabb547345..1c4a9d1377442ad98f4e3fcb3b1215bf3e49b20b 100644 (file)
@@ -2162,6 +2162,28 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
 }
 EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
 
+#ifdef CONFIG_PM_SLEEP
+static int bq27xxx_battery_suspend(struct device *dev)
+{
+       struct bq27xxx_device_info *di = dev_get_drvdata(dev);
+
+       cancel_delayed_work(&di->work);
+       return 0;
+}
+
+static int bq27xxx_battery_resume(struct device *dev)
+{
+       struct bq27xxx_device_info *di = dev_get_drvdata(dev);
+
+       schedule_delayed_work(&di->work, 0);
+       return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+SIMPLE_DEV_PM_OPS(bq27xxx_battery_battery_pm_ops,
+                 bq27xxx_battery_suspend, bq27xxx_battery_resume);
+EXPORT_SYMBOL_GPL(bq27xxx_battery_battery_pm_ops);
+
 MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
 MODULE_DESCRIPTION("BQ27xxx battery monitor driver");
 MODULE_LICENSE("GPL");
index 9b5475590518fb23153acdc2a9ceea403bc73fef..3a1798b0c1a79f3ed3a3fd0be4d84f6df390b3b4 100644 (file)
@@ -295,6 +295,7 @@ static struct i2c_driver bq27xxx_battery_i2c_driver = {
        .driver = {
                .name = "bq27xxx-battery",
                .of_match_table = of_match_ptr(bq27xxx_battery_i2c_of_match_table),
+               .pm = &bq27xxx_battery_battery_pm_ops,
        },
        .probe = bq27xxx_battery_i2c_probe,
        .remove = bq27xxx_battery_i2c_remove,
index 7c8d65414a70ad5784badca31fedf2c95d44fc0c..7d8025fb74b701d6ac64cd3add0f7ca297fe5413 100644 (file)
@@ -83,5 +83,6 @@ struct bq27xxx_device_info {
 void bq27xxx_battery_update(struct bq27xxx_device_info *di);
 int bq27xxx_battery_setup(struct bq27xxx_device_info *di);
 void bq27xxx_battery_teardown(struct bq27xxx_device_info *di);
+extern const struct dev_pm_ops bq27xxx_battery_battery_pm_ops;
 
 #endif