Re: [PATCH 3/6] dma:imx-dma:Use devm_clk_get_enabled() helpers
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Date: 2024-08-23 12:07:04
Also in:
dmaengine, lkml
On Fri, 23 Aug 2024 18:19:30 +0800 Liao Yuanhong [off-list ref] wrote:
Use devm_clk_get_enabled() instead of clk functions in imx-dma. Signed-off-by: Liao Yuanhong <redacted>
Straight forward case, but nice to combine this with use of return dev_err_probe() in the paths where you now have direct returns. Other comments below.
quoted hunk ↗ jump to hunk
--- drivers/dma/imx-dma.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-)diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c index ebf7c115d553..1ef926304d0e 100644 --- a/drivers/dma/imx-dma.c +++ b/drivers/dma/imx-dma.c@@ -1039,6 +1039,8 @@ static int __init imxdma_probe(struct platform_device *pdev) struct imxdma_engine *imxdma; int ret, i; int irq, irq_err; + struct clk *dma_ahb; + struct clk *dma_ipg;
struct clk *dma_ahb, *dma_ipg; should be fine.
quoted hunk ↗ jump to hunk
imxdma = devm_kzalloc(&pdev->dev, sizeof(*imxdma), GFP_KERNEL); if (!imxdma)@@ -1055,20 +1057,13 @@ static int __init imxdma_probe(struct platform_device *pdev) if (irq < 0) return irq; - imxdma->dma_ipg = devm_clk_get(&pdev->dev, "ipg"); - if (IS_ERR(imxdma->dma_ipg)) - return PTR_ERR(imxdma->dma_ipg); + dma_ipg = devm_clk_get_enabled(&pdev->dev, "ipg"); + if (IS_ERR(dma_ipg)) + return PTR_ERR(dma_ipg); - imxdma->dma_ahb = devm_clk_get(&pdev->dev, "ahb"); - if (IS_ERR(imxdma->dma_ahb)) - return PTR_ERR(imxdma->dma_ahb); - - ret = clk_prepare_enable(imxdma->dma_ipg); - if (ret) - return ret; - ret = clk_prepare_enable(imxdma->dma_ahb); - if (ret) - goto disable_dma_ipg_clk; + dma_ahb = devm_clk_get_enabled(&pdev->dev, "ahb"); + if (IS_ERR(dma_ahb)) + return PTR_ERR(dma_ahb); /* reset DMA module */ imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR);@@ -1078,21 +1073,21 @@ static int __init imxdma_probe(struct platform_device *pdev) dma_irq_handler, 0, "DMA", imxdma); if (ret) { dev_warn(imxdma->dev, "Can't register IRQ for DMA\n"); - goto disable_dma_ahb_clk; + return ret;
Odd not to make that a dev_error given driver fails to probe as a result. I'd switch to return dev_err_rpobe()
}
imxdma->irq = irq;
irq_err = platform_get_irq(pdev, 1);
if (irq_err < 0) {
ret = irq_err;
- goto disable_dma_ahb_clk;
+ return ret;
}
ret = devm_request_irq(&pdev->dev, irq_err,
imxdma_err_handler, 0, "DMA", imxdma);
if (ret) {
dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n");
- goto disable_dma_ahb_clk;
+ return ret;Here as well.
quoted hunk ↗ jump to hunk
} imxdma->irq_err = irq_err; }@@ -1130,7 +1125,7 @@ static int __init imxdma_probe(struct platform_device *pdev) dev_warn(imxdma->dev, "Can't register IRQ %d " "for DMA channel %d\n", irq + i, i); - goto disable_dma_ahb_clk; + return ret;
and here.
quoted hunk ↗ jump to hunk
} imxdmac->irq = irq + i;@@ -1174,7 +1169,7 @@ static int __init imxdma_probe(struct platform_device *pdev) ret = dma_async_device_register(&imxdma->dma_device); if (ret) { dev_err(&pdev->dev, "unable to register\n"); - goto disable_dma_ahb_clk; + return ret;
and finaly here.
quoted hunk ↗ jump to hunk
} if (pdev->dev.of_node) {@@ -1190,10 +1185,6 @@ static int __init imxdma_probe(struct platform_device *pdev) err_of_dma_controller: dma_async_device_unregister(&imxdma->dma_device);
Maybe use a local callback and devm_add_action_or_reset() to get automate handling of this call as well.
quoted hunk ↗ jump to hunk
-disable_dma_ahb_clk: - clk_disable_unprepare(imxdma->dma_ahb); -disable_dma_ipg_clk: - clk_disable_unprepare(imxdma->dma_ipg); return ret; }@@ -1226,9 +1217,6 @@ static void imxdma_remove(struct platform_device *pdev) if (pdev->dev.of_node) of_dma_controller_free(pdev->dev.of_node);
The ordering of the two items above here looks suspicious as it doesn't reverse order of probably. Maybe worth cleaning that up whilst here.
-
- clk_disable_unprepare(imxdma->dma_ipg);
- clk_disable_unprepare(imxdma->dma_ahb);
}
static struct platform_driver imxdma_driver = {