Skip to content

Commit a74e795

Browse files
committed
Merge branch 'topic/stm' into for-linus
2 parents 3de78f4 + 89e987e commit a74e795

File tree

3 files changed

+155
-30
lines changed

3 files changed

+155
-30
lines changed

drivers/dma/stm32-dma.c

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/of_device.h>
2424
#include <linux/of_dma.h>
2525
#include <linux/platform_device.h>
26+
#include <linux/pm_runtime.h>
2627
#include <linux/reset.h>
2728
#include <linux/sched.h>
2829
#include <linux/slab.h>
@@ -641,12 +642,13 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void *devid)
641642
{
642643
struct stm32_dma_chan *chan = devid;
643644
struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan);
644-
u32 status, scr;
645+
u32 status, scr, sfcr;
645646

646647
spin_lock(&chan->vchan.lock);
647648

648649
status = stm32_dma_irq_status(chan);
649650
scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id));
651+
sfcr = stm32_dma_read(dmadev, STM32_DMA_SFCR(chan->id));
650652

651653
if (status & STM32_DMA_TCI) {
652654
stm32_dma_irq_clear(chan, STM32_DMA_TCI);
@@ -661,10 +663,12 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void *devid)
661663
if (status & STM32_DMA_FEI) {
662664
stm32_dma_irq_clear(chan, STM32_DMA_FEI);
663665
status &= ~STM32_DMA_FEI;
664-
if (!(scr & STM32_DMA_SCR_EN))
665-
dev_err(chan2dev(chan), "FIFO Error\n");
666-
else
667-
dev_dbg(chan2dev(chan), "FIFO over/underrun\n");
666+
if (sfcr & STM32_DMA_SFCR_FEIE) {
667+
if (!(scr & STM32_DMA_SCR_EN))
668+
dev_err(chan2dev(chan), "FIFO Error\n");
669+
else
670+
dev_dbg(chan2dev(chan), "FIFO over/underrun\n");
671+
}
668672
}
669673
if (status) {
670674
stm32_dma_irq_clear(chan, status);
@@ -1112,15 +1116,14 @@ static int stm32_dma_alloc_chan_resources(struct dma_chan *c)
11121116
int ret;
11131117

11141118
chan->config_init = false;
1115-
ret = clk_prepare_enable(dmadev->clk);
1116-
if (ret < 0) {
1117-
dev_err(chan2dev(chan), "clk_prepare_enable failed: %d\n", ret);
1119+
1120+
ret = pm_runtime_get_sync(dmadev->ddev.dev);
1121+
if (ret < 0)
11181122
return ret;
1119-
}
11201123

11211124
ret = stm32_dma_disable_chan(chan);
11221125
if (ret < 0)
1123-
clk_disable_unprepare(dmadev->clk);
1126+
pm_runtime_put(dmadev->ddev.dev);
11241127

11251128
return ret;
11261129
}
@@ -1140,7 +1143,7 @@ static void stm32_dma_free_chan_resources(struct dma_chan *c)
11401143
spin_unlock_irqrestore(&chan->vchan.lock, flags);
11411144
}
11421145

1143-
clk_disable_unprepare(dmadev->clk);
1146+
pm_runtime_put(dmadev->ddev.dev);
11441147

11451148
vchan_free_chan_resources(to_virt_chan(c));
11461149
}
@@ -1240,6 +1243,12 @@ static int stm32_dma_probe(struct platform_device *pdev)
12401243
return PTR_ERR(dmadev->clk);
12411244
}
12421245

1246+
ret = clk_prepare_enable(dmadev->clk);
1247+
if (ret < 0) {
1248+
dev_err(&pdev->dev, "clk_prep_enable error: %d\n", ret);
1249+
return ret;
1250+
}
1251+
12431252
dmadev->mem2mem = of_property_read_bool(pdev->dev.of_node,
12441253
"st,mem2mem");
12451254

@@ -1289,7 +1298,7 @@ static int stm32_dma_probe(struct platform_device *pdev)
12891298

12901299
ret = dma_async_device_register(dd);
12911300
if (ret)
1292-
return ret;
1301+
goto clk_free;
12931302

12941303
for (i = 0; i < STM32_DMA_MAX_CHANNELS; i++) {
12951304
chan = &dmadev->chan[i];
@@ -1321,20 +1330,58 @@ static int stm32_dma_probe(struct platform_device *pdev)
13211330

13221331
platform_set_drvdata(pdev, dmadev);
13231332

1333+
pm_runtime_set_active(&pdev->dev);
1334+
pm_runtime_enable(&pdev->dev);
1335+
pm_runtime_get_noresume(&pdev->dev);
1336+
pm_runtime_put(&pdev->dev);
1337+
13241338
dev_info(&pdev->dev, "STM32 DMA driver registered\n");
13251339

13261340
return 0;
13271341

13281342
err_unregister:
13291343
dma_async_device_unregister(dd);
1344+
clk_free:
1345+
clk_disable_unprepare(dmadev->clk);
13301346

13311347
return ret;
13321348
}
13331349

1350+
#ifdef CONFIG_PM
1351+
static int stm32_dma_runtime_suspend(struct device *dev)
1352+
{
1353+
struct stm32_dma_device *dmadev = dev_get_drvdata(dev);
1354+
1355+
clk_disable_unprepare(dmadev->clk);
1356+
1357+
return 0;
1358+
}
1359+
1360+
static int stm32_dma_runtime_resume(struct device *dev)
1361+
{
1362+
struct stm32_dma_device *dmadev = dev_get_drvdata(dev);
1363+
int ret;
1364+
1365+
ret = clk_prepare_enable(dmadev->clk);
1366+
if (ret) {
1367+
dev_err(dev, "failed to prepare_enable clock\n");
1368+
return ret;
1369+
}
1370+
1371+
return 0;
1372+
}
1373+
#endif
1374+
1375+
static const struct dev_pm_ops stm32_dma_pm_ops = {
1376+
SET_RUNTIME_PM_OPS(stm32_dma_runtime_suspend,
1377+
stm32_dma_runtime_resume, NULL)
1378+
};
1379+
13341380
static struct platform_driver stm32_dma_driver = {
13351381
.driver = {
13361382
.name = "stm32-dma",
13371383
.of_match_table = stm32_dma_of_match,
1384+
.pm = &stm32_dma_pm_ops,
13381385
},
13391386
};
13401387

drivers/dma/stm32-dmamux.c

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/module.h>
2929
#include <linux/of_device.h>
3030
#include <linux/of_dma.h>
31+
#include <linux/pm_runtime.h>
3132
#include <linux/reset.h>
3233
#include <linux/slab.h>
3334
#include <linux/spinlock.h>
@@ -79,8 +80,7 @@ static void stm32_dmamux_free(struct device *dev, void *route_data)
7980
stm32_dmamux_write(dmamux->iomem, STM32_DMAMUX_CCR(mux->chan_id), 0);
8081
clear_bit(mux->chan_id, dmamux->dma_inuse);
8182

82-
if (!IS_ERR(dmamux->clk))
83-
clk_disable(dmamux->clk);
83+
pm_runtime_put_sync(dev);
8484

8585
spin_unlock_irqrestore(&dmamux->lock, flags);
8686

@@ -146,13 +146,10 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
146146

147147
/* Set dma request */
148148
spin_lock_irqsave(&dmamux->lock, flags);
149-
if (!IS_ERR(dmamux->clk)) {
150-
ret = clk_enable(dmamux->clk);
151-
if (ret < 0) {
152-
spin_unlock_irqrestore(&dmamux->lock, flags);
153-
dev_err(&pdev->dev, "clk_prep_enable issue: %d\n", ret);
154-
goto error;
155-
}
149+
ret = pm_runtime_get_sync(&pdev->dev);
150+
if (ret < 0) {
151+
spin_unlock_irqrestore(&dmamux->lock, flags);
152+
goto error;
156153
}
157154
spin_unlock_irqrestore(&dmamux->lock, flags);
158155

@@ -254,6 +251,7 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
254251
dev_warn(&pdev->dev, "DMAMUX defaulting on %u requests\n",
255252
stm32_dmamux->dmamux_requests);
256253
}
254+
pm_runtime_get_noresume(&pdev->dev);
257255

258256
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
259257
iomem = devm_ioremap_resource(&pdev->dev, res);
@@ -282,6 +280,8 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
282280
stm32_dmamux->dmarouter.route_free = stm32_dmamux_free;
283281

284282
platform_set_drvdata(pdev, stm32_dmamux);
283+
pm_runtime_set_active(&pdev->dev);
284+
pm_runtime_enable(&pdev->dev);
285285

286286
if (!IS_ERR(stm32_dmamux->clk)) {
287287
ret = clk_prepare_enable(stm32_dmamux->clk);
@@ -291,17 +291,52 @@ static int stm32_dmamux_probe(struct platform_device *pdev)
291291
}
292292
}
293293

294+
pm_runtime_get_noresume(&pdev->dev);
295+
294296
/* Reset the dmamux */
295297
for (i = 0; i < stm32_dmamux->dma_requests; i++)
296298
stm32_dmamux_write(stm32_dmamux->iomem, STM32_DMAMUX_CCR(i), 0);
297299

298-
if (!IS_ERR(stm32_dmamux->clk))
299-
clk_disable(stm32_dmamux->clk);
300+
pm_runtime_put(&pdev->dev);
300301

301302
return of_dma_router_register(node, stm32_dmamux_route_allocate,
302303
&stm32_dmamux->dmarouter);
303304
}
304305

306+
#ifdef CONFIG_PM
307+
static int stm32_dmamux_runtime_suspend(struct device *dev)
308+
{
309+
struct platform_device *pdev =
310+
container_of(dev, struct platform_device, dev);
311+
struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
312+
313+
clk_disable_unprepare(stm32_dmamux->clk);
314+
315+
return 0;
316+
}
317+
318+
static int stm32_dmamux_runtime_resume(struct device *dev)
319+
{
320+
struct platform_device *pdev =
321+
container_of(dev, struct platform_device, dev);
322+
struct stm32_dmamux_data *stm32_dmamux = platform_get_drvdata(pdev);
323+
int ret;
324+
325+
ret = clk_prepare_enable(stm32_dmamux->clk);
326+
if (ret) {
327+
dev_err(&pdev->dev, "failed to prepare_enable clock\n");
328+
return ret;
329+
}
330+
331+
return 0;
332+
}
333+
#endif
334+
335+
static const struct dev_pm_ops stm32_dmamux_pm_ops = {
336+
SET_RUNTIME_PM_OPS(stm32_dmamux_runtime_suspend,
337+
stm32_dmamux_runtime_resume, NULL)
338+
};
339+
305340
static const struct of_device_id stm32_dmamux_match[] = {
306341
{ .compatible = "st,stm32h7-dmamux" },
307342
{},
@@ -312,6 +347,7 @@ static struct platform_driver stm32_dmamux_driver = {
312347
.driver = {
313348
.name = "stm32-dmamux",
314349
.of_match_table = stm32_dmamux_match,
350+
.pm = &stm32_dmamux_pm_ops,
315351
},
316352
};
317353

drivers/dma/stm32-mdma.c

Lines changed: 49 additions & 7 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;
@@ -1579,9 +1578,11 @@ static int stm32_mdma_probe(struct platform_device *pdev)
15791578

15801579
dmadev->nr_channels = nr_channels;
15811580
dmadev->nr_requests = nr_requests;
1582-
device_property_read_u32_array(&pdev->dev, "st,ahb-addr-masks",
1581+
ret = device_property_read_u32_array(&pdev->dev, "st,ahb-addr-masks",
15831582
dmadev->ahb_addr_masks,
15841583
count);
1584+
if (ret)
1585+
return ret;
15851586
dmadev->nr_ahb_addr_masks = count;
15861587

15871588
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1597,6 +1598,12 @@ static int stm32_mdma_probe(struct platform_device *pdev)
15971598
return ret;
15981599
}
15991600

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+
16001607
dmadev->rst = devm_reset_control_get(&pdev->dev, NULL);
16011608
if (!IS_ERR(dmadev->rst)) {
16021609
reset_control_assert(dmadev->rst);
@@ -1668,6 +1675,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
16681675
}
16691676

16701677
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);
16711682

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

@@ -1677,11 +1688,42 @@ static int stm32_mdma_probe(struct platform_device *pdev)
16771688
return ret;
16781689
}
16791690

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+
16801721
static struct platform_driver stm32_mdma_driver = {
16811722
.probe = stm32_mdma_probe,
16821723
.driver = {
16831724
.name = "stm32-mdma",
16841725
.of_match_table = stm32_mdma_of_match,
1726+
.pm = &stm32_mdma_pm_ops,
16851727
},
16861728
};
16871729

0 commit comments

Comments
 (0)