]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
pwm: rcar: Add suspend/resume support
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tue, 13 Mar 2018 08:18:18 +0000 (17:18 +0900)
committerThierry Reding <thierry.reding@gmail.com>
Tue, 27 Mar 2018 23:27:10 +0000 (01:27 +0200)
This patch adds suspend/resume support for Renesas PWM driver.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-rcar.c

index f4d8767f804e1eebf235814f61e86eae6b321638..91d11f2e2fefd2897a693199bc8c904faf165003 100644 (file)
@@ -258,11 +258,53 @@ static const struct of_device_id rcar_pwm_of_table[] = {
 };
 MODULE_DEVICE_TABLE(of, rcar_pwm_of_table);
 
+#ifdef CONFIG_PM_SLEEP
+static struct pwm_device *rcar_pwm_dev_to_pwm_dev(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct rcar_pwm_chip *rcar_pwm = platform_get_drvdata(pdev);
+       struct pwm_chip *chip = &rcar_pwm->chip;
+
+       return &chip->pwms[0];
+}
+
+static int rcar_pwm_suspend(struct device *dev)
+{
+       struct pwm_device *pwm = rcar_pwm_dev_to_pwm_dev(dev);
+
+       if (!test_bit(PWMF_REQUESTED, &pwm->flags))
+               return 0;
+
+       pm_runtime_put(dev);
+
+       return 0;
+}
+
+static int rcar_pwm_resume(struct device *dev)
+{
+       struct pwm_device *pwm = rcar_pwm_dev_to_pwm_dev(dev);
+
+       if (!test_bit(PWMF_REQUESTED, &pwm->flags))
+               return 0;
+
+       pm_runtime_get_sync(dev);
+
+       rcar_pwm_config(pwm->chip, pwm, pwm->state.duty_cycle,
+                       pwm->state.period);
+       if (pwm_is_enabled(pwm))
+               rcar_pwm_enable(pwm->chip, pwm);
+
+       return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+static SIMPLE_DEV_PM_OPS(rcar_pwm_pm_ops, rcar_pwm_suspend, rcar_pwm_resume);
+
 static struct platform_driver rcar_pwm_driver = {
        .probe = rcar_pwm_probe,
        .remove = rcar_pwm_remove,
        .driver = {
                .name = "pwm-rcar",
+               .pm     = &rcar_pwm_pm_ops,
                .of_match_table = of_match_ptr(rcar_pwm_of_table),
        }
 };