diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2014-10-10 10:03:56 (GMT) |
---|---|---|
committer | Matthew Weigel <Matthew.Weigel@freescale.com> | 2014-12-11 18:38:08 (GMT) |
commit | a353bd9f81e225e29d15a5d59363f53324ac808e (patch) | |
tree | b53f8cf4c58992c3dba1a291afbba37ef20dd618 /drivers/pwm | |
parent | f84d9a26b0f971658a1355e990a8551096ab4f6c (diff) | |
download | linux-fsl-qoriq-a353bd9f81e225e29d15a5d59363f53324ac808e.tar.xz |
pwm: ftm: add Power Management support for FTM pwm.
Add PM support for FTM pwm driver using callback function suspend
and resume in .driver.pm of platform_driver.
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
upstream link: http://patchwork.ozlabs.org/patch/399748/
it is under discussion.
Change-Id: I0c558dffdb9c40d66e4a55d5ce3e8685fe4f1ecf
Reviewed-on: http://git.am.freescale.net:8181/21350
Tested-by: Review Code-CDREVIEW <CDREVIEW@freescale.com>
Reviewed-by: Dongsheng Wang <dongsheng.wang@freescale.com>
Reviewed-by: Zhengxiong Jin <Jason.Jin@freescale.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r-- | drivers/pwm/pwm-fsl-ftm.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c index 9bfbea5..666e1be 100644 --- a/drivers/pwm/pwm-fsl-ftm.c +++ b/drivers/pwm/pwm-fsl-ftm.c @@ -17,6 +17,7 @@ #include <linux/mutex.h> #include <linux/of_address.h> #include <linux/platform_device.h> +#include <linux/pm.h> #include <linux/pwm.h> #include <linux/regmap.h> #include <linux/slab.h> @@ -436,7 +437,7 @@ static int fsl_pwm_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - fpc->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, + fpc->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "ftm_sys", base, &fsl_pwm_regmap_config); if (IS_ERR(fpc->regmap)) { dev_err(&pdev->dev, "regmap init failed\n"); @@ -487,6 +488,51 @@ static int fsl_pwm_remove(struct platform_device *pdev) return pwmchip_remove(&fpc->chip); } +#ifdef CONFIG_PM_SLEEP +static int fsl_pwm_suspend(struct device *dev) +{ + struct fsl_pwm_chip *fpc = dev_get_drvdata(dev); + u32 val; + + regcache_cache_only(fpc->regmap, true); + regcache_mark_dirty(fpc->regmap); + + /* read from cache */ + regmap_read(fpc->regmap, FTM_OUTMASK, &val); + if ((val & 0xFF) != 0xFF) { + clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_CNTEN]); + clk_disable_unprepare(fpc->clk[fpc->cnt_select]); + clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); + } + + return 0; +} + +static int fsl_pwm_resume(struct device *dev) +{ + struct fsl_pwm_chip *fpc = dev_get_drvdata(dev); + u32 val; + + /* read from cache */ + regmap_read(fpc->regmap, FTM_OUTMASK, &val); + if ((val & 0xFF) != 0xFF) { + clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); + clk_prepare_enable(fpc->clk[fpc->cnt_select]); + clk_prepare_enable(fpc->clk[FSL_PWM_CLK_CNTEN]); + } + + /* restore all registers from cache */ + regcache_cache_only(fpc->regmap, false); + regcache_sync(fpc->regmap); + + return 0; +} +#endif + +static const struct dev_pm_ops fsl_pwm_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(fsl_pwm_suspend, fsl_pwm_resume) +}; + static const struct of_device_id fsl_pwm_dt_ids[] = { { .compatible = "fsl,vf610-ftm-pwm", }, { /* sentinel */ } @@ -497,6 +543,7 @@ static struct platform_driver fsl_pwm_driver = { .driver = { .name = "fsl-ftm-pwm", .of_match_table = fsl_pwm_dt_ids, + .pm = &fsl_pwm_pm_ops, }, .probe = fsl_pwm_probe, .remove = fsl_pwm_remove, |