diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-12-03 19:58:06 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-01-21 08:10:08 -0500 |
commit | b97b662174162b44944abd0fa9faea50006ba711 (patch) | |
tree | 6097e95949df64f7504bff8f09c100a0cd33d2bd /drivers/spi/spi-s3c64xx.c | |
parent | e25d0bf917e8f3b6b5bafdc2fe666ca81eb9099d (diff) |
spi/s3c64xx: Implement runtime PM support
Enable and disable the clocks to the SPI controller using runtime PM. This
serves the dual purpose of reducing power consumption a little and letting
the core know when the device is idle.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Diffstat (limited to 'drivers/spi/spi-s3c64xx.c')
-rw-r--r-- | drivers/spi/spi-s3c64xx.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 56dbdf15cba1..b0b843b321bb 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/clk.h> | 25 | #include <linux/clk.h> |
26 | #include <linux/dma-mapping.h> | 26 | #include <linux/dma-mapping.h> |
27 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | #include <linux/pm_runtime.h> | ||
28 | #include <linux/spi/spi.h> | 29 | #include <linux/spi/spi.h> |
29 | 30 | ||
30 | #include <mach/dma.h> | 31 | #include <mach/dma.h> |
@@ -782,6 +783,8 @@ static void s3c64xx_spi_work(struct work_struct *work) | |||
782 | while (!acquire_dma(sdd)) | 783 | while (!acquire_dma(sdd)) |
783 | msleep(10); | 784 | msleep(10); |
784 | 785 | ||
786 | pm_runtime_get_sync(&sdd->pdev->dev); | ||
787 | |||
785 | spin_lock_irqsave(&sdd->lock, flags); | 788 | spin_lock_irqsave(&sdd->lock, flags); |
786 | 789 | ||
787 | while (!list_empty(&sdd->queue) | 790 | while (!list_empty(&sdd->queue) |
@@ -810,6 +813,8 @@ static void s3c64xx_spi_work(struct work_struct *work) | |||
810 | /* Free DMA channels */ | 813 | /* Free DMA channels */ |
811 | sdd->ops->release(sdd->rx_dma.ch, &s3c64xx_spi_dma_client); | 814 | sdd->ops->release(sdd->rx_dma.ch, &s3c64xx_spi_dma_client); |
812 | sdd->ops->release(sdd->tx_dma.ch, &s3c64xx_spi_dma_client); | 815 | sdd->ops->release(sdd->tx_dma.ch, &s3c64xx_spi_dma_client); |
816 | |||
817 | pm_runtime_put(&sdd->pdev->dev); | ||
813 | } | 818 | } |
814 | 819 | ||
815 | static int s3c64xx_spi_transfer(struct spi_device *spi, | 820 | static int s3c64xx_spi_transfer(struct spi_device *spi, |
@@ -892,6 +897,8 @@ static int s3c64xx_spi_setup(struct spi_device *spi) | |||
892 | goto setup_exit; | 897 | goto setup_exit; |
893 | } | 898 | } |
894 | 899 | ||
900 | pm_runtime_get_sync(&sdd->pdev->dev); | ||
901 | |||
895 | /* Check if we can provide the requested rate */ | 902 | /* Check if we can provide the requested rate */ |
896 | if (!sci->clk_from_cmu) { | 903 | if (!sci->clk_from_cmu) { |
897 | u32 psr, speed; | 904 | u32 psr, speed; |
@@ -924,6 +931,8 @@ static int s3c64xx_spi_setup(struct spi_device *spi) | |||
924 | err = -EINVAL; | 931 | err = -EINVAL; |
925 | } | 932 | } |
926 | 933 | ||
934 | pm_runtime_put(&sdd->pdev->dev); | ||
935 | |||
927 | setup_exit: | 936 | setup_exit: |
928 | 937 | ||
929 | /* setup() returns with device de-selected */ | 938 | /* setup() returns with device de-selected */ |
@@ -1164,6 +1173,8 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev) | |||
1164 | mem_res->end, mem_res->start, | 1173 | mem_res->end, mem_res->start, |
1165 | sdd->rx_dma.dmach, sdd->tx_dma.dmach); | 1174 | sdd->rx_dma.dmach, sdd->tx_dma.dmach); |
1166 | 1175 | ||
1176 | pm_runtime_enable(&pdev->dev); | ||
1177 | |||
1167 | return 0; | 1178 | return 0; |
1168 | 1179 | ||
1169 | err9: | 1180 | err9: |
@@ -1197,6 +1208,8 @@ static int s3c64xx_spi_remove(struct platform_device *pdev) | |||
1197 | struct resource *mem_res; | 1208 | struct resource *mem_res; |
1198 | unsigned long flags; | 1209 | unsigned long flags; |
1199 | 1210 | ||
1211 | pm_runtime_disable(&pdev->dev); | ||
1212 | |||
1200 | spin_lock_irqsave(&sdd->lock, flags); | 1213 | spin_lock_irqsave(&sdd->lock, flags); |
1201 | sdd->state |= SUSPND; | 1214 | sdd->state |= SUSPND; |
1202 | spin_unlock_irqrestore(&sdd->lock, flags); | 1215 | spin_unlock_irqrestore(&sdd->lock, flags); |
@@ -1277,8 +1290,34 @@ static int s3c64xx_spi_resume(struct device *dev) | |||
1277 | } | 1290 | } |
1278 | #endif /* CONFIG_PM */ | 1291 | #endif /* CONFIG_PM */ |
1279 | 1292 | ||
1293 | #ifdef CONFIG_PM_RUNTIME | ||
1294 | static int s3c64xx_spi_runtime_suspend(struct device *dev) | ||
1295 | { | ||
1296 | struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); | ||
1297 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | ||
1298 | |||
1299 | clk_disable(sdd->clk); | ||
1300 | clk_disable(sdd->src_clk); | ||
1301 | |||
1302 | return 0; | ||
1303 | } | ||
1304 | |||
1305 | static int s3c64xx_spi_runtime_resume(struct device *dev) | ||
1306 | { | ||
1307 | struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); | ||
1308 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | ||
1309 | |||
1310 | clk_enable(sdd->src_clk); | ||
1311 | clk_enable(sdd->clk); | ||
1312 | |||
1313 | return 0; | ||
1314 | } | ||
1315 | #endif /* CONFIG_PM_RUNTIME */ | ||
1316 | |||
1280 | static const struct dev_pm_ops s3c64xx_spi_pm = { | 1317 | static const struct dev_pm_ops s3c64xx_spi_pm = { |
1281 | SET_SYSTEM_SLEEP_PM_OPS(s3c64xx_spi_suspend, s3c64xx_spi_resume) | 1318 | SET_SYSTEM_SLEEP_PM_OPS(s3c64xx_spi_suspend, s3c64xx_spi_resume) |
1319 | SET_RUNTIME_PM_OPS(s3c64xx_spi_runtime_suspend, | ||
1320 | s3c64xx_spi_runtime_resume, NULL) | ||
1282 | }; | 1321 | }; |
1283 | 1322 | ||
1284 | static struct platform_driver s3c64xx_spi_driver = { | 1323 | static struct platform_driver s3c64xx_spi_driver = { |