Skip to content

Commit

Permalink
dmaengine: stm32-mdma: Add PM Runtime support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pierre-Yves MORDRET authored and Vinod Koul committed Jan 7, 2019
1 parent 4f3ceca commit 89e987e
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions drivers/dma/stm32-mdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <linux/of_device.h>
#include <linux/of_dma.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/slab.h>

Expand Down Expand Up @@ -1456,15 +1457,13 @@ static int stm32_mdma_alloc_chan_resources(struct dma_chan *c)
return -ENOMEM;
}

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

ret = stm32_mdma_disable_chan(chan);
if (ret < 0)
clk_disable_unprepare(dmadev->clk);
pm_runtime_put(dmadev->ddev.dev);

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

clk_disable_unprepare(dmadev->clk);
pm_runtime_put(dmadev->ddev.dev);
vchan_free_chan_resources(to_virt_chan(c));
dmam_pool_destroy(chan->desc_pool);
chan->desc_pool = NULL;
Expand Down Expand Up @@ -1599,6 +1598,12 @@ static int stm32_mdma_probe(struct platform_device *pdev)
return ret;
}

ret = clk_prepare_enable(dmadev->clk);
if (ret < 0) {
dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
return ret;
}

dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
if (!IS_ERR(dmadev->rst)) {
reset_control_assert(dmadev->rst);
Expand Down Expand Up @@ -1670,6 +1675,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
}

platform_set_drvdata(pdev, dmadev);
pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
pm_runtime_get_noresume(&pdev->dev);
pm_runtime_put(&pdev->dev);

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

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

#ifdef CONFIG_PM
static int stm32_mdma_runtime_suspend(struct device *dev)
{
struct stm32_mdma_device *dmadev = dev_get_drvdata(dev);

clk_disable_unprepare(dmadev->clk);

return 0;
}

static int stm32_mdma_runtime_resume(struct device *dev)
{
struct stm32_mdma_device *dmadev = dev_get_drvdata(dev);
int ret;

ret = clk_prepare_enable(dmadev->clk);
if (ret) {
dev_err(dev, "failed to prepare_enable clock\n");
return ret;
}

return 0;
}
#endif

static const struct dev_pm_ops stm32_mdma_pm_ops = {
SET_RUNTIME_PM_OPS(stm32_mdma_runtime_suspend,
stm32_mdma_runtime_resume, NULL)
};

static struct platform_driver stm32_mdma_driver = {
.probe = stm32_mdma_probe,
.driver = {
.name = "stm32-mdma",
.of_match_table = stm32_mdma_of_match,
.pm = &stm32_mdma_pm_ops,
},
};

Expand Down

0 comments on commit 89e987e

Please sign in to comment.