Skip to content

Commit 779a448

Browse files
nunojsavinodkoul
authored andcommitted
dmaengine: axi-dmac: move to device managed probe
In axi_dmac_probe(), there's a mix in using device managed APIs and explicitly cleaning things in the driver .remove() hook. Move to use device managed APIs and thus drop the .remove() hook. Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20240328-axi-dmac-devm-probe-v3-2-523c0176df70@analog.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 1bc3144 commit 779a448

1 file changed

Lines changed: 34 additions & 44 deletions

File tree

drivers/dma/dma-axi-dmac.c

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,16 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac, unsigned int version)
10021002
return 0;
10031003
}
10041004

1005+
static void axi_dmac_tasklet_kill(void *task)
1006+
{
1007+
tasklet_kill(task);
1008+
}
1009+
1010+
static void axi_dmac_free_dma_controller(void *of_node)
1011+
{
1012+
of_dma_controller_free(of_node);
1013+
}
1014+
10051015
static int axi_dmac_probe(struct platform_device *pdev)
10061016
{
10071017
struct dma_device *dma_dev;
@@ -1025,14 +1035,10 @@ static int axi_dmac_probe(struct platform_device *pdev)
10251035
if (IS_ERR(dmac->base))
10261036
return PTR_ERR(dmac->base);
10271037

1028-
dmac->clk = devm_clk_get(&pdev->dev, NULL);
1038+
dmac->clk = devm_clk_get_enabled(&pdev->dev, NULL);
10291039
if (IS_ERR(dmac->clk))
10301040
return PTR_ERR(dmac->clk);
10311041

1032-
ret = clk_prepare_enable(dmac->clk);
1033-
if (ret < 0)
1034-
return ret;
1035-
10361042
version = axi_dmac_read(dmac, ADI_AXI_REG_VERSION);
10371043

10381044
if (version >= ADI_AXI_PCORE_VER(4, 3, 'a'))
@@ -1041,7 +1047,7 @@ static int axi_dmac_probe(struct platform_device *pdev)
10411047
ret = axi_dmac_parse_dt(&pdev->dev, dmac);
10421048

10431049
if (ret < 0)
1044-
goto err_clk_disable;
1050+
return ret;
10451051

10461052
INIT_LIST_HEAD(&dmac->chan.active_descs);
10471053

@@ -1072,7 +1078,7 @@ static int axi_dmac_probe(struct platform_device *pdev)
10721078

10731079
ret = axi_dmac_detect_caps(dmac, version);
10741080
if (ret)
1075-
goto err_clk_disable;
1081+
return ret;
10761082

10771083
dma_dev->copy_align = (dmac->chan.address_align_mask + 1);
10781084

@@ -1088,57 +1094,42 @@ static int axi_dmac_probe(struct platform_device *pdev)
10881094
!AXI_DMAC_DST_COHERENT_GET(ret)) {
10891095
dev_err(dmac->dma_dev.dev,
10901096
"Coherent DMA not supported in hardware");
1091-
ret = -EINVAL;
1092-
goto err_clk_disable;
1097+
return -EINVAL;
10931098
}
10941099
}
10951100

1096-
ret = dma_async_device_register(dma_dev);
1101+
ret = dmaenginem_async_device_register(dma_dev);
1102+
if (ret)
1103+
return ret;
1104+
1105+
/*
1106+
* Put the action in here so it get's done before unregistering the DMA
1107+
* device.
1108+
*/
1109+
ret = devm_add_action_or_reset(&pdev->dev, axi_dmac_tasklet_kill,
1110+
&dmac->chan.vchan.task);
10971111
if (ret)
1098-
goto err_clk_disable;
1112+
return ret;
10991113

11001114
ret = of_dma_controller_register(pdev->dev.of_node,
11011115
of_dma_xlate_by_chan_id, dma_dev);
11021116
if (ret)
1103-
goto err_unregister_device;
1117+
return ret;
11041118

1105-
ret = request_irq(dmac->irq, axi_dmac_interrupt_handler, IRQF_SHARED,
1106-
dev_name(&pdev->dev), dmac);
1119+
ret = devm_add_action_or_reset(&pdev->dev, axi_dmac_free_dma_controller,
1120+
pdev->dev.of_node);
11071121
if (ret)
1108-
goto err_unregister_of;
1122+
return ret;
11091123

1110-
platform_set_drvdata(pdev, dmac);
1124+
ret = devm_request_irq(&pdev->dev, dmac->irq, axi_dmac_interrupt_handler,
1125+
IRQF_SHARED, dev_name(&pdev->dev), dmac);
1126+
if (ret)
1127+
return ret;
11111128

11121129
regmap = devm_regmap_init_mmio(&pdev->dev, dmac->base,
11131130
&axi_dmac_regmap_config);
1114-
if (IS_ERR(regmap)) {
1115-
ret = PTR_ERR(regmap);
1116-
goto err_free_irq;
1117-
}
1118-
1119-
return 0;
1120-
1121-
err_free_irq:
1122-
free_irq(dmac->irq, dmac);
1123-
err_unregister_of:
1124-
of_dma_controller_free(pdev->dev.of_node);
1125-
err_unregister_device:
1126-
dma_async_device_unregister(&dmac->dma_dev);
1127-
err_clk_disable:
1128-
clk_disable_unprepare(dmac->clk);
1129-
1130-
return ret;
1131-
}
1132-
1133-
static void axi_dmac_remove(struct platform_device *pdev)
1134-
{
1135-
struct axi_dmac *dmac = platform_get_drvdata(pdev);
11361131

1137-
free_irq(dmac->irq, dmac);
1138-
of_dma_controller_free(pdev->dev.of_node);
1139-
tasklet_kill(&dmac->chan.vchan.task);
1140-
dma_async_device_unregister(&dmac->dma_dev);
1141-
clk_disable_unprepare(dmac->clk);
1132+
return PTR_ERR_OR_ZERO(regmap);
11421133
}
11431134

11441135
static const struct of_device_id axi_dmac_of_match_table[] = {
@@ -1153,7 +1144,6 @@ static struct platform_driver axi_dmac_driver = {
11531144
.of_match_table = axi_dmac_of_match_table,
11541145
},
11551146
.probe = axi_dmac_probe,
1156-
.remove_new = axi_dmac_remove,
11571147
};
11581148
module_platform_driver(axi_dmac_driver);
11591149

0 commit comments

Comments
 (0)