pwm: rcar: Add suspend/resume support

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>
This commit is contained in:
Yoshihiro Shimoda 2018-03-13 17:18:18 +09:00 committed by Thierry Reding
parent f2e6142cdc
commit 6873842235
1 changed files with 42 additions and 0 deletions

View File

@ -258,11 +258,53 @@ static const struct of_device_id rcar_pwm_of_table[] = {
}; };
MODULE_DEVICE_TABLE(of, 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 = { static struct platform_driver rcar_pwm_driver = {
.probe = rcar_pwm_probe, .probe = rcar_pwm_probe,
.remove = rcar_pwm_remove, .remove = rcar_pwm_remove,
.driver = { .driver = {
.name = "pwm-rcar", .name = "pwm-rcar",
.pm = &rcar_pwm_pm_ops,
.of_match_table = of_match_ptr(rcar_pwm_of_table), .of_match_table = of_match_ptr(rcar_pwm_of_table),
} }
}; };