Skip to content

Commit 89e987e

Browse files
stmordretvinodkoul
authored andcommitted
dmaengine: stm32-mdma: Add PM Runtime support
Use pm_runtime engine for clock management purpose Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 4f3ceca commit 89e987e

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

drivers/dma/stm32-mdma.c

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/of_device.h>
3838
#include <linux/of_dma.h>
3939
#include <linux/platform_device.h>
40+
#include <linux/pm_runtime.h>
4041
#include <linux/reset.h>
4142
#include <linux/slab.h>
4243

@@ -1456,15 +1457,13 @@ static int stm32_mdma_alloc_chan_resources(struct dma_chan *c)
14561457
return -ENOMEM;
14571458
}
14581459

1459-
ret = clk_prepare_enable(dmadev->clk);
1460-
if (ret < 0) {
1461-
dev_err(chan2dev(chan), "clk_prepare_enable failed: %d\n", ret);
1460+
ret = pm_runtime_get_sync(dmadev->ddev.dev);
1461+
if (ret < 0)
14621462
return ret;
1463-
}
14641463

14651464
ret = stm32_mdma_disable_chan(chan);
14661465
if (ret < 0)
1467-
clk_disable_unprepare(dmadev->clk);
1466+
pm_runtime_put(dmadev->ddev.dev);
14681467

14691468
return ret;
14701469
}
@@ -1484,7 +1483,7 @@ static void stm32_mdma_free_chan_resources(struct dma_chan *c)
14841483
spin_unlock_irqrestore(&chan->vchan.lock, flags);
14851484
}
14861485

1487-
clk_disable_unprepare(dmadev->clk);
1486+
pm_runtime_put(dmadev->ddev.dev);
14881487
vchan_free_chan_resources(to_virt_chan(c));
14891488
dmam_pool_destroy(chan->desc_pool);
14901489
chan->desc_pool = NULL;
@@ -1599,6 +1598,12 @@ static int stm32_mdma_probe(struct platform_device *pdev)
15991598
return ret;
16001599
}
16011600

1601+
ret = clk_prepare_enable(dmadev->clk);
1602+
if (ret < 0) {
1603+
dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
1604+
return ret;
1605+
}
1606+
16021607
dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
16031608
if (!IS_ERR(dmadev->rst)) {
16041609
reset_control_assert(dmadev->rst);
@@ -1670,6 +1675,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
16701675
}
16711676

16721677
platform_set_drvdata(pdev, dmadev);
1678+
pm_runtime_set_active(&pdev->dev);
1679+
pm_runtime_enable(&pdev->dev);
1680+
pm_runtime_get_noresume(&pdev->dev);
1681+
pm_runtime_put(&pdev->dev);
16731682

16741683
dev_info(&pdev->dev, "STM32 MDMA driver registered\n");
16751684

@@ -1679,11 +1688,42 @@ static int stm32_mdma_probe(struct platform_device *pdev)
16791688
return ret;
16801689
}
16811690

1691+
#ifdef CONFIG_PM
1692+
static int stm32_mdma_runtime_suspend(struct device *dev)
1693+
{
1694+
struct stm32_mdma_device *dmadev = dev_get_drvdata(dev);
1695+
1696+
clk_disable_unprepare(dmadev->clk);
1697+
1698+
return 0;
1699+
}
1700+
1701+
static int stm32_mdma_runtime_resume(struct device *dev)
1702+
{
1703+
struct stm32_mdma_device *dmadev = dev_get_drvdata(dev);
1704+
int ret;
1705+
1706+
ret = clk_prepare_enable(dmadev->clk);
1707+
if (ret) {
1708+
dev_err(dev, "failed to prepare_enable clock\n");
1709+
return ret;
1710+
}
1711+
1712+
return 0;
1713+
}
1714+
#endif
1715+
1716+
static const struct dev_pm_ops stm32_mdma_pm_ops = {
1717+
SET_RUNTIME_PM_OPS(stm32_mdma_runtime_suspend,
1718+
stm32_mdma_runtime_resume, NULL)
1719+
};
1720+
16821721
static struct platform_driver stm32_mdma_driver = {
16831722
.probe = stm32_mdma_probe,
16841723
.driver = {
16851724
.name = "stm32-mdma",
16861725
.of_match_table = stm32_mdma_of_match,
1726+
.pm = &stm32_mdma_pm_ops,
16871727
},
16881728
};
16891729

0 commit comments

Comments
 (0)