aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorPhilip Avinash <avinashphilip@ti.com>2013-01-17 04:20:03 -0500
committerThierry Reding <thierry.reding@avionic-design.de>2013-01-17 10:52:59 -0500
commit0d75c203effefa4f62ca4d30bf52bd9ec246717f (patch)
tree1584cc1c0f5fc3fb374f006a2cd1a5ede9053629 /drivers/pwm
parent0e2feb17dec9d97f6b44d5af872633f7ffba9ffb (diff)
pwm: pwm-tiecap: Low power sleep support
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for ECAP driver. Signed-off-by: Philip Avinash <avinashphilip@ti.com> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-tiecap.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/pwm/pwm-tiecap.c b/drivers/pwm/pwm-tiecap.c
index 5cf016dd9822..05b676db88e6 100644
--- a/drivers/pwm/pwm-tiecap.c
+++ b/drivers/pwm/pwm-tiecap.c
@@ -41,10 +41,17 @@
41#define ECCTL2_SYNC_SEL_DISA (BIT(7) | BIT(6)) 41#define ECCTL2_SYNC_SEL_DISA (BIT(7) | BIT(6))
42#define ECCTL2_TSCTR_FREERUN BIT(4) 42#define ECCTL2_TSCTR_FREERUN BIT(4)
43 43
44struct ecap_context {
45 u32 cap3;
46 u32 cap4;
47 u16 ecctl2;
48};
49
44struct ecap_pwm_chip { 50struct ecap_pwm_chip {
45 struct pwm_chip chip; 51 struct pwm_chip chip;
46 unsigned int clk_rate; 52 unsigned int clk_rate;
47 void __iomem *mmio_base; 53 void __iomem *mmio_base;
54 struct ecap_context ctx;
48}; 55};
49 56
50static inline struct ecap_pwm_chip *to_ecap_pwm_chip(struct pwm_chip *chip) 57static inline struct ecap_pwm_chip *to_ecap_pwm_chip(struct pwm_chip *chip)
@@ -288,11 +295,57 @@ static int ecap_pwm_remove(struct platform_device *pdev)
288 return pwmchip_remove(&pc->chip); 295 return pwmchip_remove(&pc->chip);
289} 296}
290 297
298void ecap_pwm_save_context(struct ecap_pwm_chip *pc)
299{
300 pm_runtime_get_sync(pc->chip.dev);
301 pc->ctx.ecctl2 = readw(pc->mmio_base + ECCTL2);
302 pc->ctx.cap4 = readl(pc->mmio_base + CAP4);
303 pc->ctx.cap3 = readl(pc->mmio_base + CAP3);
304 pm_runtime_put_sync(pc->chip.dev);
305}
306
307void ecap_pwm_restore_context(struct ecap_pwm_chip *pc)
308{
309 writel(pc->ctx.cap3, pc->mmio_base + CAP3);
310 writel(pc->ctx.cap4, pc->mmio_base + CAP4);
311 writew(pc->ctx.ecctl2, pc->mmio_base + ECCTL2);
312}
313
314static int ecap_pwm_suspend(struct device *dev)
315{
316 struct ecap_pwm_chip *pc = dev_get_drvdata(dev);
317 struct pwm_device *pwm = pc->chip.pwms;
318
319 ecap_pwm_save_context(pc);
320
321 /* Disable explicitly if PWM is running */
322 if (test_bit(PWMF_ENABLED, &pwm->flags))
323 pm_runtime_put_sync(dev);
324
325 return 0;
326}
327
328static int ecap_pwm_resume(struct device *dev)
329{
330 struct ecap_pwm_chip *pc = dev_get_drvdata(dev);
331 struct pwm_device *pwm = pc->chip.pwms;
332
333 /* Enable explicitly if PWM was running */
334 if (test_bit(PWMF_ENABLED, &pwm->flags))
335 pm_runtime_get_sync(dev);
336
337 ecap_pwm_restore_context(pc);
338 return 0;
339}
340
341static SIMPLE_DEV_PM_OPS(ecap_pwm_pm_ops, ecap_pwm_suspend, ecap_pwm_resume);
342
291static struct platform_driver ecap_pwm_driver = { 343static struct platform_driver ecap_pwm_driver = {
292 .driver = { 344 .driver = {
293 .name = "ecap", 345 .name = "ecap",
294 .owner = THIS_MODULE, 346 .owner = THIS_MODULE,
295 .of_match_table = ecap_of_match, 347 .of_match_table = ecap_of_match,
348 .pm = &ecap_pwm_pm_ops,
296 }, 349 },
297 .probe = ecap_pwm_probe, 350 .probe = ecap_pwm_probe,
298 .remove = ecap_pwm_remove, 351 .remove = ecap_pwm_remove,