Skip to contentSkip to conversation

pwm: bcm2835: Add support for suspend/resume

PATCH Superseded Florian Fainelli 2 participants 2 messages Oct 9, 2023 – Oct 10, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Florian Fainelli

author maintainer
#0 lore raw

PATCH v2 1/1 pwm: bcm2835: Add support for suspend/resume

Similar to other drivers, we need to make sure that the clock is disabled during suspend and re-enabled during resume.

---
Changes in v2:

- use DEFINE_SIMPLE_DEV_PM_OPS as suggested by Uwe

 drivers/pwm/pwm-bcm2835.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/pwm/pwm-bcm2835.c +20 -0
index bdfc2a5ec0d6..938f993ae746 100644
@@ -182,6 +182,25 @@ static void bcm2835_pwm_remove(struct platform_device *pdev)
 	clk_disable_unprepare(pc->clk);
 }
 
+static int __maybe_unused bcm2835_pwm_suspend(struct device *dev)
+{
+	struct bcm2835_pwm *pc = dev_get_drvdata(dev);
+
+	clk_disable_unprepare(pc->clk);
+
+	return 0;
+}
+
+static int __maybe_unused bcm2835_pwm_resume(struct device *dev)
+{
+	struct bcm2835_pwm *pc = dev_get_drvdata(dev);
+
+	return clk_prepare_enable(pc->clk);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(bcm2835_pwm_pm_ops, bcm2835_pwm_suspend,
+				bcm2835_pwm_resume);
+
 static const struct of_device_id bcm2835_pwm_of_match[] = {
 	{ .compatible = "brcm,bcm2835-pwm", },
 	{ /* sentinel */ }
@@ -192,6 +211,7 @@ static struct platform_driver bcm2835_pwm_driver = {
 	.driver = {
 		.name = "bcm2835-pwm",
 		.of_match_table = bcm2835_pwm_of_match,
+		.pm = &bcm2835_pwm_pm_ops,
 	},
 	.probe = bcm2835_pwm_probe,
 	.remove_new = bcm2835_pwm_remove,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 21 lines · Florian Fainelli

Similar to other drivers, we need to make sure that the clock is disabled during suspend and re-enabled during resume.

---
Changes in v2:

- use DEFINE_SIMPLE_DEV_PM_OPS as suggested by Uwe

 drivers/pwm/pwm-bcm2835.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/pwm/pwm-bcm2835.c +0 -0
index bdfc2a5ec0d6..938f993ae746 100644
@@ -182,6 +182,25 @@ static void bcm2835_pwm_remove(struct platform_device *pdev)
 	clk_disable_unprepare(pc->clk);
 }
 

drivers/pwm/pwm-bcm2835.c static void bcm2835_pwm_remove(struct platform_device *pdev) · line 194

Quoted 10 lines
drivers/pwm/pwm-bcm2835.c +10 -0
+static int __maybe_unused bcm2835_pwm_suspend(struct device *dev)
+{
+	struct bcm2835_pwm *pc = dev_get_drvdata(dev);
+
+	clk_disable_unprepare(pc->clk);
+
+	return 0;
+}
+
+static int __maybe_unused bcm2835_pwm_resume(struct device *dev)

With DEFINE_SIMPLE_DEV_PM_OPS you don't need the __maybe_unused (which is one of the upsides of DEFINE_SIMPLE_DEV_PM_OPS compared to SIMPLE_DEV_PM_OPS)

Quoted 13 lines
drivers/pwm/pwm-bcm2835.c +9 -0
+{
+	struct bcm2835_pwm *pc = dev_get_drvdata(dev);
+
+	return clk_prepare_enable(pc->clk);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(bcm2835_pwm_pm_ops, bcm2835_pwm_suspend,
+				bcm2835_pwm_resume);
+
 static const struct of_device_id bcm2835_pwm_of_match[] = {
 	{ .compatible = "brcm,bcm2835-pwm", },
 	{ /* sentinel */ }

drivers/pwm/pwm-bcm2835.c static struct platform_driver bcm2835_pwm_driver = { · line 214

Quoted 4 lines
drivers/pwm/pwm-bcm2835.c +1 -0
@@ -192,6 +211,7 @@ static struct platform_driver bcm2835_pwm_driver = {
 	.driver = {
 		.name = "bcm2835-pwm",
 		.of_match_table = bcm2835_pwm_of_match,
+		.pm = &bcm2835_pwm_pm_ops,

I think

+ .pm = pm_ptr(&bcm2835_pwm_pm_ops),

is the right thing here.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |