13
13
#include <linux/iopoll.h>
14
14
#include <linux/module.h>
15
15
#include <linux/of_platform.h>
16
+ #include <linux/pinctrl/consumer.h>
16
17
#include <linux/pm_runtime.h>
17
18
#include <linux/reset.h>
18
19
#include <linux/spi/spi.h>
@@ -2007,6 +2008,8 @@ static int stm32_spi_remove(struct platform_device *pdev)
2007
2008
2008
2009
pm_runtime_disable (& pdev -> dev );
2009
2010
2011
+ pinctrl_pm_select_sleep_state (& pdev -> dev );
2012
+
2010
2013
return 0 ;
2011
2014
}
2012
2015
@@ -2018,13 +2021,18 @@ static int stm32_spi_runtime_suspend(struct device *dev)
2018
2021
2019
2022
clk_disable_unprepare (spi -> clk );
2020
2023
2021
- return 0 ;
2024
+ return pinctrl_pm_select_sleep_state ( dev ) ;
2022
2025
}
2023
2026
2024
2027
static int stm32_spi_runtime_resume (struct device * dev )
2025
2028
{
2026
2029
struct spi_master * master = dev_get_drvdata (dev );
2027
2030
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 ;
2028
2036
2029
2037
return clk_prepare_enable (spi -> clk );
2030
2038
}
@@ -2054,10 +2062,23 @@ static int stm32_spi_resume(struct device *dev)
2054
2062
return ret ;
2055
2063
2056
2064
ret = spi_master_resume (master );
2057
- if (ret )
2065
+ if (ret ) {
2058
2066
clk_disable_unprepare (spi -> clk );
2067
+ return ret ;
2068
+ }
2059
2069
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 ;
2061
2082
}
2062
2083
#endif
2063
2084
0 commit comments