Commit 97d0b42e authored by Xiubo Li's avatar Xiubo Li Committed by Thierry Reding

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: default avatarXiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 49599cf6
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/pwm.h> #include <linux/pwm.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -436,7 +437,7 @@ static int fsl_pwm_probe(struct platform_device *pdev) ...@@ -436,7 +437,7 @@ static int fsl_pwm_probe(struct platform_device *pdev)
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_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); &fsl_pwm_regmap_config);
if (IS_ERR(fpc->regmap)) { if (IS_ERR(fpc->regmap)) {
dev_err(&pdev->dev, "regmap init failed\n"); dev_err(&pdev->dev, "regmap init failed\n");
...@@ -487,6 +488,51 @@ static int fsl_pwm_remove(struct platform_device *pdev) ...@@ -487,6 +488,51 @@ static int fsl_pwm_remove(struct platform_device *pdev)
return pwmchip_remove(&fpc->chip); 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[] = { static const struct of_device_id fsl_pwm_dt_ids[] = {
{ .compatible = "fsl,vf610-ftm-pwm", }, { .compatible = "fsl,vf610-ftm-pwm", },
{ /* sentinel */ } { /* sentinel */ }
...@@ -497,6 +543,7 @@ static struct platform_driver fsl_pwm_driver = { ...@@ -497,6 +543,7 @@ static struct platform_driver fsl_pwm_driver = {
.driver = { .driver = {
.name = "fsl-ftm-pwm", .name = "fsl-ftm-pwm",
.of_match_table = fsl_pwm_dt_ids, .of_match_table = fsl_pwm_dt_ids,
.pm = &fsl_pwm_pm_ops,
}, },
.probe = fsl_pwm_probe, .probe = fsl_pwm_probe,
.remove = fsl_pwm_remove, .remove = fsl_pwm_remove,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment