Skip to content

Commit db96bf9

Browse files
ADESTMbroonie
authored andcommitted
spi: stm32: fixes suspend/resume management
This patch adds pinctrl power management, and reconfigure spi controller in case of resume. Fixes: 038ac86 ("spi: stm32: add runtime PM support") Signed-off-by: Amelie Delaunay <[email protected]> Signed-off-by: Alain Volmat <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9cc6197 commit db96bf9

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

drivers/spi/spi-stm32.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/iopoll.h>
1414
#include <linux/module.h>
1515
#include <linux/of_platform.h>
16+
#include <linux/pinctrl/consumer.h>
1617
#include <linux/pm_runtime.h>
1718
#include <linux/reset.h>
1819
#include <linux/spi/spi.h>
@@ -2007,6 +2008,8 @@ static int stm32_spi_remove(struct platform_device *pdev)
20072008

20082009
pm_runtime_disable(&pdev->dev);
20092010

2011+
pinctrl_pm_select_sleep_state(&pdev->dev);
2012+
20102013
return 0;
20112014
}
20122015

@@ -2018,13 +2021,18 @@ static int stm32_spi_runtime_suspend(struct device *dev)
20182021

20192022
clk_disable_unprepare(spi->clk);
20202023

2021-
return 0;
2024+
return pinctrl_pm_select_sleep_state(dev);
20222025
}
20232026

20242027
static int stm32_spi_runtime_resume(struct device *dev)
20252028
{
20262029
struct spi_master *master = dev_get_drvdata(dev);
20272030
struct stm32_spi *spi = spi_master_get_devdata(master);
2031+
int ret;
2032+
2033+
ret = pinctrl_pm_select_default_state(dev);
2034+
if (ret)
2035+
return ret;
20282036

20292037
return clk_prepare_enable(spi->clk);
20302038
}
@@ -2054,10 +2062,23 @@ static int stm32_spi_resume(struct device *dev)
20542062
return ret;
20552063

20562064
ret = spi_master_resume(master);
2057-
if (ret)
2065+
if (ret) {
20582066
clk_disable_unprepare(spi->clk);
2067+
return ret;
2068+
}
20592069

2060-
return ret;
2070+
ret = pm_runtime_get_sync(dev);
2071+
if (ret) {
2072+
dev_err(dev, "Unable to power device:%d\n", ret);
2073+
return ret;
2074+
}
2075+
2076+
spi->cfg->config(spi);
2077+
2078+
pm_runtime_mark_last_busy(dev);
2079+
pm_runtime_put_autosuspend(dev);
2080+
2081+
return 0;
20612082
}
20622083
#endif
20632084

0 commit comments

Comments
 (0)