dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] STM32 MDMA driver fixes and improvements
@ 2020-01-27  8:53 Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 1/6] dmaengine: stm32-mdma: add suspend/resume power management support Amelie Delaunay
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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 MDMA driver, with support of power
management and descriptor reuse. Probe function gets a cleanup and to avoid
a race with vchan_complete, driver now adopts vchan_terminate_vdesc().

Amelie Delaunay (2):
  dmaengine: stm32-mdma: driver defers probe for clock and reset
  dmaengine: stm32-mdma: use vchan_terminate_vdesc() in .terminate_all

Etienne Carriere (2):
  dmaengine: stm32-mdma: use reset controller only at probe time
  dmaengine: stm32-mdma: disable clock in case of error during probe

Pierre-Yves MORDRET (2):
  dmaengine: stm32-mdma: add suspend/resume power management support
  dmaengine: stm32-mdma: enable descriptor_reuse

 drivers/dma/stm32-mdma.c | 78 +++++++++++++++++++++++++++++++---------
 1 file changed, 62 insertions(+), 16 deletions(-)

-- 
2.17.1


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

* [PATCH 1/6] dmaengine: stm32-mdma: add suspend/resume power management support
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 2/6] dmaengine: stm32-mdma: use reset controller only at probe time Amelie Delaunay
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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-mdma.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 5838311cf990..2898411941d5 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1697,7 +1697,40 @@ static int stm32_mdma_runtime_resume(struct device *dev)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
+static int stm32_mdma_pm_suspend(struct device *dev)
+{
+	struct stm32_mdma_device *dmadev = dev_get_drvdata(dev);
+	u32 ccr, id;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0)
+		return ret;
+
+	for (id = 0; id < dmadev->nr_channels; id++) {
+		ccr = stm32_mdma_read(dmadev, STM32_MDMA_CCR(id));
+		if (ccr & STM32_MDMA_CCR_EN) {
+			dev_warn(dev, "Suspend is prevented by Chan %i\n", id);
+			return -EBUSY;
+		}
+	}
+
+	pm_runtime_put_sync(dev);
+
+	pm_runtime_force_suspend(dev);
+
+	return 0;
+}
+
+static int stm32_mdma_pm_resume(struct device *dev)
+{
+	return pm_runtime_force_resume(dev);
+}
+#endif
+
 static const struct dev_pm_ops stm32_mdma_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(stm32_mdma_pm_suspend, stm32_mdma_pm_resume)
 	SET_RUNTIME_PM_OPS(stm32_mdma_runtime_suspend,
 			   stm32_mdma_runtime_resume, NULL)
 };
-- 
2.17.1


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

* [PATCH 2/6] dmaengine: stm32-mdma: use reset controller only at probe time
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 1/6] dmaengine: stm32-mdma: add suspend/resume power management support Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 3/6] dmaengine: stm32-mdma: disable clock in case of error during probe Amelie Delaunay
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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-mdma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 2898411941d5..a0fb80dfb2e9 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -273,7 +273,6 @@ struct stm32_mdma_device {
 	void __iomem *base;
 	struct clk *clk;
 	int irq;
-	struct reset_control *rst;
 	u32 nr_channels;
 	u32 nr_requests;
 	u32 nr_ahb_addr_masks;
@@ -1532,6 +1531,7 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	struct dma_device *dd;
 	struct device_node *of_node;
 	struct resource *res;
+	struct reset_control *rst;
 	u32 nr_channels, nr_requests;
 	int i, count, ret;
 
@@ -1590,11 +1590,11 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
-	if (!IS_ERR(dmadev->rst)) {
-		reset_control_assert(dmadev->rst);
+	rst = devm_reset_control_get(&pdev->dev, NULL);
+	if (!IS_ERR(rst)) {
+		reset_control_assert(rst);
 		udelay(2);
-		reset_control_deassert(dmadev->rst);
+		reset_control_deassert(rst);
 	}
 
 	dd = &dmadev->ddev;
-- 
2.17.1


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

* [PATCH 3/6] dmaengine: stm32-mdma: disable clock in case of error during probe
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 1/6] dmaengine: stm32-mdma: add suspend/resume power management support Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 2/6] dmaengine: stm32-mdma: use reset controller only at probe time Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 4/6] dmaengine: stm32-mdma: driver defers probe for clock and reset Amelie Delaunay
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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 patch disables the clock in case of error during probe. The unneeded
err_unregister label is renamed err_clk instead.

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

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index a0fb80dfb2e9..f23c82e3990c 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1637,25 +1637,27 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	}
 
 	dmadev->irq = platform_get_irq(pdev, 0);
-	if (dmadev->irq < 0)
-		return dmadev->irq;
+	if (dmadev->irq < 0) {
+		ret = dmadev->irq;
+		goto err_clk;
+	}
 
 	ret = devm_request_irq(&pdev->dev, dmadev->irq, stm32_mdma_irq_handler,
 			       0, dev_name(&pdev->dev), dmadev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to request IRQ\n");
-		return ret;
+		goto err_clk;
 	}
 
 	ret = dmaenginem_async_device_register(dd);
 	if (ret)
-		return ret;
+		goto err_clk;
 
 	ret = of_dma_controller_register(of_node, stm32_mdma_of_xlate, dmadev);
 	if (ret < 0) {
 		dev_err(&pdev->dev,
 			"STM32 MDMA DMA OF registration failed %d\n", ret);
-		goto err_unregister;
+		goto err_clk;
 	}
 
 	platform_set_drvdata(pdev, dmadev);
@@ -1668,7 +1670,9 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 
 	return 0;
 
-err_unregister:
+err_clk:
+	clk_disable_unprepare(dmadev->clk);
+
 	return ret;
 }
 
-- 
2.17.1


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

* [PATCH 4/6] dmaengine: stm32-mdma: driver defers probe for clock and reset
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
                   ` (2 preceding siblings ...)
  2020-01-27  8:53 ` [PATCH 3/6] dmaengine: stm32-mdma: disable clock in case of error during probe Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 5/6] dmaengine: stm32-mdma: enable descriptor_reuse Amelie Delaunay
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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 patch changes error log when failing to get the clock so that it is
not printed on failure with probe deferring.

It also defers probe when reset controller is expected but has not been
probed yet when MDMA device is probed.

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

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index f23c82e3990c..2dbd1f38a6f5 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1579,8 +1579,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	dmadev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dmadev->clk)) {
 		ret = PTR_ERR(dmadev->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;
 	}
 
@@ -1591,7 +1591,11 @@ static int stm32_mdma_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);
-- 
2.17.1


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

* [PATCH 5/6] dmaengine: stm32-mdma: enable descriptor_reuse
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
                   ` (3 preceding siblings ...)
  2020-01-27  8:53 ` [PATCH 4/6] dmaengine: stm32-mdma: driver defers probe for clock and reset Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-01-27  8:53 ` [PATCH 6/6] dmaengine: stm32-mdma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
  2020-02-24 16:50 ` [PATCH 0/6] STM32 MDMA driver fixes and improvements Vinod Koul
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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>

Enable descriptor reuse to allow client to resubmit already processed
descriptors in order to save descriptor creation time.

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

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 2dbd1f38a6f5..f2043f47ae9e 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1618,6 +1618,8 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	dd->device_resume = stm32_mdma_resume;
 	dd->device_terminate_all = stm32_mdma_terminate_all;
 	dd->device_synchronize = stm32_mdma_synchronize;
+	dd->descriptor_reuse = true;
+
 	dd->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
 		BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
 		BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
-- 
2.17.1


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

* [PATCH 6/6] dmaengine: stm32-mdma: use vchan_terminate_vdesc() in .terminate_all
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
                   ` (4 preceding siblings ...)
  2020-01-27  8:53 ` [PATCH 5/6] dmaengine: stm32-mdma: enable descriptor_reuse Amelie Delaunay
@ 2020-01-27  8:53 ` Amelie Delaunay
  2020-02-24 16:50 ` [PATCH 0/6] STM32 MDMA driver fixes and improvements Vinod Koul
  6 siblings, 0 replies; 8+ messages in thread
From: Amelie Delaunay @ 2020-01-27  8:53 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

To avoid race with vchan_complete, use the race free way to terminate
running transfer.

Move vdesc->node list_del in stm32_mdma_start_transfer instead of in
stm32_mdma_xfer_end to avoid another race in vchan_dma_desc_free_list.

Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/dma/stm32-mdma.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index f2043f47ae9e..5469563703d1 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -1126,6 +1126,8 @@ static void stm32_mdma_start_transfer(struct stm32_mdma_chan *chan)
 		return;
 	}
 
+	list_del(&vdesc->node);
+
 	chan->desc = to_stm32_mdma_desc(vdesc);
 	hwdesc = chan->desc->node[0].hwdesc;
 	chan->curr_hwdesc = 0;
@@ -1241,8 +1243,10 @@ static int stm32_mdma_terminate_all(struct dma_chan *c)
 	LIST_HEAD(head);
 
 	spin_lock_irqsave(&chan->vchan.lock, flags);
-	if (chan->busy) {
-		stm32_mdma_stop(chan);
+	if (chan->desc) {
+		vchan_terminate_vdesc(&chan->desc->vdesc);
+		if (chan->busy)
+			stm32_mdma_stop(chan);
 		chan->desc = NULL;
 	}
 	vchan_get_all_descriptors(&chan->vchan, &head);
@@ -1330,7 +1334,6 @@ static enum dma_status stm32_mdma_tx_status(struct dma_chan *c,
 
 static void stm32_mdma_xfer_end(struct stm32_mdma_chan *chan)
 {
-	list_del(&chan->desc->vdesc.node);
 	vchan_cookie_complete(&chan->desc->vdesc);
 	chan->desc = NULL;
 	chan->busy = false;
-- 
2.17.1


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

* Re: [PATCH 0/6] STM32 MDMA driver fixes and improvements
  2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
                   ` (5 preceding siblings ...)
  2020-01-27  8:53 ` [PATCH 6/6] dmaengine: stm32-mdma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
@ 2020-02-24 16:50 ` Vinod Koul
  6 siblings, 0 replies; 8+ messages in thread
From: Vinod Koul @ 2020-02-24 16:50 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 27-01-20, 09:53, Amelie Delaunay wrote:
> This series brings improvements to the MDMA driver, with support of power
> management and descriptor reuse. Probe function gets a cleanup and to avoid
> a race with vchan_complete, driver now adopts vchan_terminate_vdesc().

Applied, thanks

-- 
~Vinod

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-27  8:53 [PATCH 0/6] STM32 MDMA driver fixes and improvements Amelie Delaunay
2020-01-27  8:53 ` [PATCH 1/6] dmaengine: stm32-mdma: add suspend/resume power management support Amelie Delaunay
2020-01-27  8:53 ` [PATCH 2/6] dmaengine: stm32-mdma: use reset controller only at probe time Amelie Delaunay
2020-01-27  8:53 ` [PATCH 3/6] dmaengine: stm32-mdma: disable clock in case of error during probe Amelie Delaunay
2020-01-27  8:53 ` [PATCH 4/6] dmaengine: stm32-mdma: driver defers probe for clock and reset Amelie Delaunay
2020-01-27  8:53 ` [PATCH 5/6] dmaengine: stm32-mdma: enable descriptor_reuse Amelie Delaunay
2020-01-27  8:53 ` [PATCH 6/6] dmaengine: stm32-mdma: use vchan_terminate_vdesc() in .terminate_all Amelie Delaunay
2020-02-24 16:50 ` [PATCH 0/6] STM32 MDMA 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).