diff options
-rw-r--r-- | drivers/pwm/pwm-atmel-hlcdc.c | 35 |
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 | ||
195 | static 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 | |||
206 | static 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 | |||
225 | static SIMPLE_DEV_PM_OPS(atmel_hlcdc_pwm_pm_ops, | ||
226 | atmel_hlcdc_pwm_suspend, atmel_hlcdc_pwm_resume); | ||
227 | |||
194 | static const struct of_device_id atmel_hlcdc_dt_ids[] = { | 228 | static 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, |