Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Boris Brezillon and committed by
Thierry Reding
f9bb9da7 2267517c

+35
+35
drivers/pwm/pwm-atmel-hlcdc.c
··· 191 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 228 static const struct of_device_id atmel_hlcdc_dt_ids[] = { 195 229 { 196 230 .compatible = "atmel,at91sam9n12-hlcdc", ··· 314 280 .driver = { 315 281 .name = "atmel-hlcdc-pwm", 316 282 .of_match_table = atmel_hlcdc_pwm_dt_ids, 283 + .pm = &atmel_hlcdc_pwm_pm_ops, 317 284 }, 318 285 .probe = atmel_hlcdc_pwm_probe, 319 286 .remove = atmel_hlcdc_pwm_remove,