diff options
author | Han Xu <han.xu@nxp.com> | 2017-11-08 15:52:58 -0600 |
---|---|---|
committer | Leonard Crestez <leonard.crestez@nxp.com> | 2018-08-24 12:41:33 +0300 |
commit | 6a1dc694bd0e6dd833a08682663e68c13823262f (patch) | |
tree | 6f8871583fc5349520a8a80b93077a02cf1ae4a3 /drivers/spi/spi-fsl-lpspi.c | |
parent | 66fbf4490ba76e6483cc2e9659b2713ffe2af58f (diff) |
MLK-16785: spi: lpspi: enable runtime pm for lpspi
enable the runtime pm for lpspi module
BuildInfo:
- SCFW 66189d08, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_4.9.51_8qm_beta1_8qxp_alpha+g325ac1e
Signed-off-by: Han Xu <han.xu@nxp.com>
Reviewed-by: Frank Li <frank.li@nxp.com>
Diffstat (limited to 'drivers/spi/spi-fsl-lpspi.c')
-rw-r--r-- | drivers/spi/spi-fsl-lpspi.c | 92 |
1 files changed, 66 insertions, 26 deletions
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 11e300f939eb..0872607280bf 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c @@ -35,9 +35,12 @@ #include <linux/of.h> #include <linux/of_device.h> #include <linux/of_gpio.h> +#include <linux/pm_runtime.h> #define DRIVER_NAME "fsl_lpspi" +#define FSL_LPSPI_RPM_TIMEOUT 50 /* 50ms */ + /* i.MX7ULP LPSPI registers */ #define IMX7ULP_VERID 0x0 #define IMX7ULP_PARAM 0x4 @@ -393,6 +396,31 @@ fsl_lpspi_prepare_message(struct spi_master *master, struct spi_message *msg) struct fsl_lpspi_data *fsl_lpspi = spi_master_get_devdata(master); int ret; + ret = pm_runtime_get_sync(fsl_lpspi->dev); + if (ret < 0) { + dev_err(fsl_lpspi->dev, "failed to enable clock\n"); + return ret; + } + + return 0; +} + +static int +fsl_lpspi_unprepare_message(struct spi_master *master, struct spi_message *msg) +{ + struct fsl_lpspi_data *fsl_lpspi = spi_master_get_devdata(master); + + pm_runtime_mark_last_busy(fsl_lpspi->dev); + pm_runtime_put_autosuspend(fsl_lpspi->dev); + + return 0; +} + +int fsl_lpspi_runtime_resume(struct device *dev) +{ + struct fsl_lpspi_data *fsl_lpspi = dev_get_drvdata(dev); + int ret; + ret = clk_prepare_enable(fsl_lpspi->clk_per); if (ret) return ret; @@ -406,10 +434,9 @@ fsl_lpspi_prepare_message(struct spi_master *master, struct spi_message *msg) return 0; } -static int -fsl_lpspi_unprepare_message(struct spi_master *master, struct spi_message *msg) +int fsl_lpspi_runtime_suspend(struct device *dev) { - struct fsl_lpspi_data *fsl_lpspi = spi_master_get_devdata(master); + struct fsl_lpspi_data *fsl_lpspi = dev_get_drvdata(dev); clk_disable_unprepare(fsl_lpspi->clk_per); clk_disable_unprepare(fsl_lpspi->clk_ipg); @@ -417,6 +444,17 @@ fsl_lpspi_unprepare_message(struct spi_master *master, struct spi_message *msg) return 0; } +static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi) +{ + struct device *dev = fsl_lpspi->dev; + + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, FSL_LPSPI_RPM_TIMEOUT); + pm_runtime_use_autosuspend(dev); + + return 0; +} + static int fsl_lpspi_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -439,6 +477,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev) fsl_lpspi = spi_master_get_devdata(master); fsl_lpspi->bitbang.master = master; fsl_lpspi->dev = &pdev->dev; + dev_set_drvdata(&pdev->dev, fsl_lpspi); for (i = 0; i < master->num_chipselect; i++) { int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); @@ -496,38 +535,28 @@ static int fsl_lpspi_probe(struct platform_device *pdev) } /* enable the clock */ - ret = clk_prepare_enable(fsl_lpspi->clk_per); + ret = fsl_lpspi_init_rpm(fsl_lpspi); if (ret) - goto out_clk_per; - - ret = clk_prepare_enable(fsl_lpspi->clk_ipg); - if (ret) - goto out_clk_ipg; + goto out_master_put; ret = devm_request_irq(&pdev->dev, irq, fsl_lpspi_isr, 0, dev_name(&pdev->dev), fsl_lpspi); if (ret) { dev_err(&pdev->dev, "can't get irq%d: %d\n", irq, ret); - goto out_clk_ipg; + goto out_master_put; } master->dev.of_node = pdev->dev.of_node; ret = spi_bitbang_start(&fsl_lpspi->bitbang); if (ret) { dev_err(&pdev->dev, "bitbang start failed with %d\n", ret); - goto out_clk_ipg; + goto out_master_put; } dev_info(fsl_lpspi->dev, "lpspi probed\n"); - clk_disable_unprepare(fsl_lpspi->clk_ipg); - clk_disable_unprepare(fsl_lpspi->clk_per); return ret; -out_clk_ipg: - clk_disable_unprepare(fsl_lpspi->clk_ipg); -out_clk_per: - clk_disable_unprepare(fsl_lpspi->clk_per); out_master_put: spi_master_put(master); @@ -540,9 +569,8 @@ static int fsl_lpspi_remove(struct platform_device *pdev) struct fsl_lpspi_data *fsl_lpspi = spi_master_get_devdata(master); spi_bitbang_stop(&fsl_lpspi->bitbang); + pm_runtime_disable(fsl_lpspi->dev); - clk_unprepare(fsl_lpspi->clk_per); - clk_unprepare(fsl_lpspi->clk_ipg); spi_master_put(master); return 0; @@ -551,27 +579,39 @@ static int fsl_lpspi_remove(struct platform_device *pdev) #ifdef CONFIG_PM_SLEEP static int fsl_lpspi_suspend(struct device *dev) { + int ret; + pinctrl_pm_select_sleep_state(dev); - return 0; + ret = pm_runtime_force_suspend(dev); + return ret; } static int fsl_lpspi_resume(struct device *dev) { + int ret; + + ret = pm_runtime_force_resume(dev); + if (ret) { + dev_err(dev, "Error in resume: %d\n", ret); + return ret; + } + pinctrl_pm_select_default_state(dev); + return 0; } +#endif /* CONFIG_PM_SLEEP */ -static SIMPLE_DEV_PM_OPS(imx_lpspi_pm, fsl_lpspi_suspend, fsl_lpspi_resume); -#define IMX_LPSPI_PM (&imx_lpspi_pm) -#else -#define IMX_LPSPI_PM NULL -#endif +static const struct dev_pm_ops fsl_lpspi_pm_ops = { + SET_RUNTIME_PM_OPS(fsl_lpspi_runtime_suspend, fsl_lpspi_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(fsl_lpspi_suspend, fsl_lpspi_resume) +}; static struct platform_driver fsl_lpspi_driver = { .driver = { .name = DRIVER_NAME, .of_match_table = fsl_lpspi_dt_ids, - .pm = IMX_LPSPI_PM, + .pm = &fsl_lpspi_pm_ops, }, .probe = fsl_lpspi_probe, .remove = fsl_lpspi_remove, |