aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Brezillon <boris.brezillon@free-electrons.com>2017-03-01 09:52:27 -0500
committerThierry Reding <thierry.reding@gmail.com>2017-04-06 11:45:02 -0400
commitf9bb9da7c09d76f00c9abdf34cbeaec65e50d78b (patch)
tree474d567c17cbcc1a7c98095e485c13a9fea98a61
parent2267517cd3ee4a1b02c7b9fead051c9d079c9fc3 (diff)
pwm: atmel-hlcdc: Implement the suspend/resume hooks
Implement the suspend/resume hooks to make sure the PWM device is restored to a correct state after a suspend. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r--drivers/pwm/pwm-atmel-hlcdc.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/pwm/pwm-atmel-hlcdc.c b/drivers/pwm/pwm-atmel-hlcdc.c
index bcb6d946131d..54c6633d9b5d 100644
--- a/drivers/pwm/pwm-atmel-hlcdc.c
+++ b/drivers/pwm/pwm-atmel-hlcdc.c
@@ -191,6 +191,40 @@ static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_sama5d3_errata = {
191 .div1_clk_erratum = true, 191 .div1_clk_erratum = true,
192}; 192};
193 193
194#ifdef CONFIG_PM_SLEEP
195static int atmel_hlcdc_pwm_suspend(struct device *dev)
196{
197 struct atmel_hlcdc_pwm *chip = dev_get_drvdata(dev);
198
199 /* Keep the periph clock enabled if the PWM is still running. */
200 if (pwm_is_enabled(&chip->chip.pwms[0]))
201 clk_disable_unprepare(chip->hlcdc->periph_clk);
202
203 return 0;
204}
205
206static int atmel_hlcdc_pwm_resume(struct device *dev)
207{
208 struct atmel_hlcdc_pwm *chip = dev_get_drvdata(dev);
209 struct pwm_state state;
210 int ret;
211
212 pwm_get_state(&chip->chip.pwms[0], &state);
213
214 /* Re-enable the periph clock it was stopped during suspend. */
215 if (!state.enabled) {
216 ret = clk_prepare_enable(chip->hlcdc->periph_clk);
217 if (ret)
218 return ret;
219 }
220
221 return atmel_hlcdc_pwm_apply(&chip->chip, &chip->chip.pwms[0], &state);
222}
223#endif
224
225static SIMPLE_DEV_PM_OPS(atmel_hlcdc_pwm_pm_ops,
226 atmel_hlcdc_pwm_suspend, atmel_hlcdc_pwm_resume);
227
194static const struct of_device_id atmel_hlcdc_dt_ids[] = { 228static const struct of_device_id atmel_hlcdc_dt_ids[] = {
195 { 229 {
196 .compatible = "atmel,at91sam9n12-hlcdc", 230 .compatible = "atmel,at91sam9n12-hlcdc",
@@ -280,6 +314,7 @@ static struct platform_driver atmel_hlcdc_pwm_driver = {
280 .driver = { 314 .driver = {
281 .name = "atmel-hlcdc-pwm", 315 .name = "atmel-hlcdc-pwm",
282 .of_match_table = atmel_hlcdc_pwm_dt_ids, 316 .of_match_table = atmel_hlcdc_pwm_dt_ids,
317 .pm = &atmel_hlcdc_pwm_pm_ops,
283 }, 318 },
284 .probe = atmel_hlcdc_pwm_probe, 319 .probe = atmel_hlcdc_pwm_probe,
285 .remove = atmel_hlcdc_pwm_remove, 320 .remove = atmel_hlcdc_pwm_remove,