dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] STM32 DMAMUX driver fixes and improvements
@ 2020-01-28  9:41 Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 1/4] dmaengine: stm32-dmamux: add suspend/resume power management support Amelie Delaunay
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Amelie Delaunay @ 2020-01-28  9:41 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

This series brings improvements to the DMAMUX driver with support of power
management and probe function gets a cleanup.

Etienne Carriere (3):
  dmaengine: stm32-dmamux: fix clock handling in probe sequence
  dmaengine: stm32-dmamux: use reset controller only at probe time
  dmaengine: stm32-dmamux: driver defers probe for clock and reset

Pierre-Yves MORDRET (1):
  dmaengine: stm32-dmamux: add suspend/resume power management support

 drivers/dma/stm32-dmamux.c | 93 +++++++++++++++++++++++++++++++-------
 1 file changed, 77 insertions(+), 16 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] dmaengine: stm32-dmamux: add suspend/resume power management support
  2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
@ 2020-01-28  9:41 ` Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 2/4] dmaengine: stm32-dmamux: fix clock handling in probe sequence Amelie Delaunay
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Amelie Delaunay @ 2020-01-28  9:41 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>

Add suspend/resume power management relying on PM Runtime engine.

Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dmamux.c | 50 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index 3c89bd39e096..08d2395c8943 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -41,6 +41,9 @@ struct stm32_dmamux_data {
 	u32 dmamux_requests; /* Number of DMA requests routed toward DMAs */
 	spinlock_t lock; /* Protects register access */
 	unsigned long *dma_inuse; /* Used DMA channel */
+	u32 ccr[STM32_DMAMUX_MAX_DMA_REQUESTS]; /* Used to backup CCR register
+						 * in suspend
+						 */
 	u32 dma_reqs[]; /* Number of DMA Request per DMA masters.
 			 *  [0] holds number of DMA Masters.
 			 *  To be kept at very end end of this structure
@@ -318,7 +321,54 @@ static int stm32_dmamux_runtime_resume(struct device *dev)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int stm32_dmamux_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+	int i, ret;
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < stm32_dmamux->dma_requests; i++)
+		stm32_dmamux->ccr[i] = stm32_dmamux_read(stm32_dmamux->iomem,
+							 STM32_DMAMUX_CCR(i));
+
+	pm_runtime_put_sync(dev);
+
+	pm_runtime_force_suspend(dev);
+
+	return 0;
+}
+
+static int stm32_dmamux_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
+	int i, ret;
+
+	ret = pm_runtime_force_resume(dev);
+	if (ret < 0)
+		return ret;
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < stm32_dmamux->dma_requests; i++)
+		stm32_dmamux_write(stm32_dmamux->iomem, STM32_DMAMUX_CCR(i),
+				   stm32_dmamux->ccr[i]);
+
+	pm_runtime_put_sync(dev);
+
+	return 0;
+}
+#endif
+
 static const struct dev_pm_ops stm32_dmamux_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(stm32_dmamux_suspend, stm32_dmamux_resume)
 	SET_RUNTIME_PM_OPS(stm32_dmamux_runtime_suspend,
 			   stm32_dmamux_runtime_resume, NULL)
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] dmaengine: stm32-dmamux: fix clock handling in probe sequence
  2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 1/4] dmaengine: stm32-dmamux: add suspend/resume power management support Amelie Delaunay
@ 2020-01-28  9:41 ` Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 3/4] dmaengine: stm32-dmamux: use reset controller only at probe time Amelie Delaunay
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Amelie Delaunay @ 2020-01-28  9:41 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Etienne Carriere <etienne.carriere@st.com>

This change ensures the DMAMUX device is reset only once it is clocked
and that clock is released in a safe state when probe operation fails.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dmamux.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index 08d2395c8943..a862d3339fb7 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -259,6 +259,12 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(stm32_dmamux->clk);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
+		return ret;
+	}
+
 	stm32_dmamux->rst = devm_reset_control_get(&pdev->dev, NULL);
 	if (!IS_ERR(stm32_dmamux->rst)) {
 		reset_control_assert(stm32_dmamux->rst);
@@ -274,14 +280,6 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
-	if (!IS_ERR(stm32_dmamux->clk)) {
-		ret = clk_prepare_enable(stm32_dmamux->clk);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
-			return ret;
-		}
-	}
-
 	pm_runtime_get_noresume(&pdev->dev);
 
 	/* Reset the dmamux */
@@ -290,8 +288,12 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 
 	pm_runtime_put(&pdev->dev);
 
-	return of_dma_router_register(node, stm32_dmamux_route_allocate,
+	ret = of_dma_router_register(node, stm32_dmamux_route_allocate,
 				     &stm32_dmamux->dmarouter);
+	if (ret)
+		clk_disable_unprepare(stm32_dmamux->clk);
+
+	return ret;
 }
 
 #ifdef CONFIG_PM
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] dmaengine: stm32-dmamux: use reset controller only at probe time
  2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 1/4] dmaengine: stm32-dmamux: add suspend/resume power management support Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 2/4] dmaengine: stm32-dmamux: fix clock handling in probe sequence Amelie Delaunay
@ 2020-01-28  9:41 ` Amelie Delaunay
  2020-01-28  9:41 ` [PATCH 4/4] dmaengine: stm32-dmamux: driver defers probe for clock and reset Amelie Delaunay
  2020-02-24 16:52 ` [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Vinod Koul
  4 siblings, 0 replies; 6+ messages in thread
From: Amelie Delaunay @ 2020-01-28  9:41 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Etienne Carriere <etienne.carriere@st.com>

Remove reset controller reference from device instance since it is
used only at probe time.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dmamux.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index a862d3339fb7..1dfecbac64cf 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -35,7 +35,6 @@ struct stm32_dmamux {
 struct stm32_dmamux_data {
 	struct dma_router dmarouter;
 	struct clk *clk;
-	struct reset_control *rst;
 	void __iomem *iomem;
 	u32 dma_requests; /* Number of DMA requests connected to DMAMUX */
 	u32 dmamux_requests; /* Number of DMA requests routed toward DMAs */
@@ -182,6 +181,7 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 	struct stm32_dmamux_data *stm32_dmamux;
 	struct resource *res;
 	void __iomem *iomem;
+	struct reset_control *rst;
 	int i, count, ret;
 	u32 dma_req;
 
@@ -265,11 +265,11 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	stm32_dmamux->rst = devm_reset_control_get(&pdev->dev, NULL);
-	if (!IS_ERR(stm32_dmamux->rst)) {
-		reset_control_assert(stm32_dmamux->rst);
+	rst = devm_reset_control_get(&pdev->dev, NULL);
+	if (!IS_ERR(rst)) {
+		reset_control_assert(rst);
 		udelay(2);
-		reset_control_deassert(stm32_dmamux->rst);
+		reset_control_deassert(rst);
 	}
 
 	stm32_dmamux->iomem = iomem;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] dmaengine: stm32-dmamux: driver defers probe for clock and reset
  2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
                   ` (2 preceding siblings ...)
  2020-01-28  9:41 ` [PATCH 3/4] dmaengine: stm32-dmamux: use reset controller only at probe time Amelie Delaunay
@ 2020-01-28  9:41 ` Amelie Delaunay
  2020-02-24 16:52 ` [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Vinod Koul
  4 siblings, 0 replies; 6+ messages in thread
From: Amelie Delaunay @ 2020-01-28  9:41 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel,
	Amelie Delaunay, Pierre-Yves MORDRET

From: Etienne Carriere <etienne.carriere@st.com>

Changes STM32 DMAMUX driver to defer its probe operation when
reset controller is expected but has not been probed yet.

Changes error traces when failing to get a system resource so that
it is not printed on failure with deferred probing.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-dmamux.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dmamux.c b/drivers/dma/stm32-dmamux.c
index 1dfecbac64cf..12f7637e13a1 100644
--- a/drivers/dma/stm32-dmamux.c
+++ b/drivers/dma/stm32-dmamux.c
@@ -254,8 +254,8 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 	stm32_dmamux->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(stm32_dmamux->clk)) {
 		ret = PTR_ERR(stm32_dmamux->clk);
-		if (ret == -EPROBE_DEFER)
-			dev_info(&pdev->dev, "Missing controller clock\n");
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "Missing clock controller\n");
 		return ret;
 	}
 
@@ -266,7 +266,11 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 	}
 
 	rst = devm_reset_control_get(&pdev->dev, NULL);
-	if (!IS_ERR(rst)) {
+	if (IS_ERR(rst)) {
+		ret = PTR_ERR(rst);
+		if (ret == -EPROBE_DEFER)
+			goto err_clk;
+	} else {
 		reset_control_assert(rst);
 		udelay(2);
 		reset_control_deassert(rst);
@@ -291,7 +295,12 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
 	ret = of_dma_router_register(node, stm32_dmamux_route_allocate,
 				     &stm32_dmamux->dmarouter);
 	if (ret)
-		clk_disable_unprepare(stm32_dmamux->clk);
+		goto err_clk;
+
+	return 0;
+
+err_clk:
+	clk_disable_unprepare(stm32_dmamux->clk);
 
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] STM32 DMAMUX driver fixes and improvements
  2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
                   ` (3 preceding siblings ...)
  2020-01-28  9:41 ` [PATCH 4/4] dmaengine: stm32-dmamux: driver defers probe for clock and reset Amelie Delaunay
@ 2020-02-24 16:52 ` Vinod Koul
  4 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2020-02-24 16:52 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Dan Williams, Maxime Coquelin, Alexandre Torgue, dmaengine,
	linux-stm32, linux-arm-kernel, linux-kernel, Pierre-Yves MORDRET

On 28-01-20, 10:41, Amelie Delaunay wrote:
> This series brings improvements to the DMAMUX driver with support of power
> management and probe function gets a cleanup.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-24 16:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-28  9:41 [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Amelie Delaunay
2020-01-28  9:41 ` [PATCH 1/4] dmaengine: stm32-dmamux: add suspend/resume power management support Amelie Delaunay
2020-01-28  9:41 ` [PATCH 2/4] dmaengine: stm32-dmamux: fix clock handling in probe sequence Amelie Delaunay
2020-01-28  9:41 ` [PATCH 3/4] dmaengine: stm32-dmamux: use reset controller only at probe time Amelie Delaunay
2020-01-28  9:41 ` [PATCH 4/4] dmaengine: stm32-dmamux: driver defers probe for clock and reset Amelie Delaunay
2020-02-24 16:52 ` [PATCH 0/4] STM32 DMAMUX driver fixes and improvements Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).