forked from mirrors/linux
		
	spi: stm32: fixes suspend/resume management
This patch adds pinctrl power management, and reconfigure spi controller
in case of resume.
Fixes: 038ac869c9 ("spi: stm32: add runtime PM support")
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
Signed-off-by: Alain Volmat <alain.volmat@st.com>
Link: https://lore.kernel.org/r/1597043558-29668-5-git-send-email-alain.volmat@st.com
Signed-off-by: Mark Brown <broonie@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									9cc61973bf
								
							
						
					
					
						commit
						db96bf976a
					
				
					 1 changed files with 24 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
#include <linux/iopoll.h>
 | 
			
		||||
#include <linux/module.h>
 | 
			
		||||
#include <linux/of_platform.h>
 | 
			
		||||
#include <linux/pinctrl/consumer.h>
 | 
			
		||||
#include <linux/pm_runtime.h>
 | 
			
		||||
#include <linux/reset.h>
 | 
			
		||||
#include <linux/spi/spi.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -2007,6 +2008,8 @@ static int stm32_spi_remove(struct platform_device *pdev)
 | 
			
		|||
 | 
			
		||||
	pm_runtime_disable(&pdev->dev);
 | 
			
		||||
 | 
			
		||||
	pinctrl_pm_select_sleep_state(&pdev->dev);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2018,13 +2021,18 @@ static int stm32_spi_runtime_suspend(struct device *dev)
 | 
			
		|||
 | 
			
		||||
	clk_disable_unprepare(spi->clk);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
	return pinctrl_pm_select_sleep_state(dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int stm32_spi_runtime_resume(struct device *dev)
 | 
			
		||||
{
 | 
			
		||||
	struct spi_master *master = dev_get_drvdata(dev);
 | 
			
		||||
	struct stm32_spi *spi = spi_master_get_devdata(master);
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	ret = pinctrl_pm_select_default_state(dev);
 | 
			
		||||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	return clk_prepare_enable(spi->clk);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2054,11 +2062,24 @@ static int stm32_spi_resume(struct device *dev)
 | 
			
		|||
		return ret;
 | 
			
		||||
 | 
			
		||||
	ret = spi_master_resume(master);
 | 
			
		||||
	if (ret)
 | 
			
		||||
	if (ret) {
 | 
			
		||||
		clk_disable_unprepare(spi->clk);
 | 
			
		||||
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ret = pm_runtime_get_sync(dev);
 | 
			
		||||
	if (ret) {
 | 
			
		||||
		dev_err(dev, "Unable to power device:%d\n", ret);
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	spi->cfg->config(spi);
 | 
			
		||||
 | 
			
		||||
	pm_runtime_mark_last_busy(dev);
 | 
			
		||||
	pm_runtime_put_autosuspend(dev);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static const struct dev_pm_ops stm32_spi_pm_ops = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue