Skip to content

Commit 038ac86

Browse files
ADESTMbroonie
authored andcommitted
spi: stm32: add runtime PM support
This patch reworks suspend and resume callbacks and add runtime_suspend and runtime_resume callbacks. Signed-off-by: Amelie Delaunay <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 128ebb8 commit 038ac86

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

drivers/spi/spi-stm32.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/iopoll.h>
2828
#include <linux/module.h>
2929
#include <linux/of_platform.h>
30+
#include <linux/pm_runtime.h>
3031
#include <linux/reset.h>
3132
#include <linux/spi/spi.h>
3233

@@ -1164,6 +1165,9 @@ static int stm32_spi_probe(struct platform_device *pdev)
11641165
if (spi->dma_tx || spi->dma_rx)
11651166
master->can_dma = stm32_spi_can_dma;
11661167

1168+
pm_runtime_set_active(&pdev->dev);
1169+
pm_runtime_enable(&pdev->dev);
1170+
11671171
ret = devm_spi_register_master(&pdev->dev, master);
11681172
if (ret) {
11691173
dev_err(&pdev->dev, "spi master registration failed: %d\n",
@@ -1203,6 +1207,8 @@ static int stm32_spi_probe(struct platform_device *pdev)
12031207
dma_release_channel(spi->dma_tx);
12041208
if (spi->dma_rx)
12051209
dma_release_channel(spi->dma_rx);
1210+
1211+
pm_runtime_disable(&pdev->dev);
12061212
err_clk_disable:
12071213
clk_disable_unprepare(spi->clk);
12081214
err_master_put:
@@ -1225,23 +1231,42 @@ static int stm32_spi_remove(struct platform_device *pdev)
12251231

12261232
clk_disable_unprepare(spi->clk);
12271233

1234+
pm_runtime_disable(&pdev->dev);
1235+
12281236
return 0;
12291237
}
12301238

1239+
#ifdef CONFIG_PM
1240+
static int stm32_spi_runtime_suspend(struct device *dev)
1241+
{
1242+
struct spi_master *master = dev_get_drvdata(dev);
1243+
struct stm32_spi *spi = spi_master_get_devdata(master);
1244+
1245+
clk_disable_unprepare(spi->clk);
1246+
1247+
return 0;
1248+
}
1249+
1250+
static int stm32_spi_runtime_resume(struct device *dev)
1251+
{
1252+
struct spi_master *master = dev_get_drvdata(dev);
1253+
struct stm32_spi *spi = spi_master_get_devdata(master);
1254+
1255+
return clk_prepare_enable(spi->clk);
1256+
}
1257+
#endif
1258+
12311259
#ifdef CONFIG_PM_SLEEP
12321260
static int stm32_spi_suspend(struct device *dev)
12331261
{
12341262
struct spi_master *master = dev_get_drvdata(dev);
1235-
struct stm32_spi *spi = spi_master_get_devdata(master);
12361263
int ret;
12371264

12381265
ret = spi_master_suspend(master);
12391266
if (ret)
12401267
return ret;
12411268

1242-
clk_disable_unprepare(spi->clk);
1243-
1244-
return ret;
1269+
return pm_runtime_force_suspend(dev);
12451270
}
12461271

12471272
static int stm32_spi_resume(struct device *dev)
@@ -1250,9 +1275,10 @@ static int stm32_spi_resume(struct device *dev)
12501275
struct stm32_spi *spi = spi_master_get_devdata(master);
12511276
int ret;
12521277

1253-
ret = clk_prepare_enable(spi->clk);
1278+
ret = pm_runtime_force_resume(dev);
12541279
if (ret)
12551280
return ret;
1281+
12561282
ret = spi_master_resume(master);
12571283
if (ret)
12581284
clk_disable_unprepare(spi->clk);
@@ -1261,8 +1287,11 @@ static int stm32_spi_resume(struct device *dev)
12611287
}
12621288
#endif
12631289

1264-
static SIMPLE_DEV_PM_OPS(stm32_spi_pm_ops,
1265-
stm32_spi_suspend, stm32_spi_resume);
1290+
static const struct dev_pm_ops stm32_spi_pm_ops = {
1291+
SET_SYSTEM_SLEEP_PM_OPS(stm32_spi_suspend, stm32_spi_resume)
1292+
SET_RUNTIME_PM_OPS(stm32_spi_runtime_suspend,
1293+
stm32_spi_runtime_resume, NULL)
1294+
};
12661295

12671296
static struct platform_driver stm32_spi_driver = {
12681297
.probe = stm32_spi_probe,

0 commit comments

Comments
 (0)