]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dmaengine: bcm2835-dma: Prevent suspend if DMA channel is busy
authorStefan Wahren <wahrenst@gmx.net>
Wed, 4 Dec 2024 16:55:46 +0000 (17:55 +0100)
committerVinod Koul <vkoul@kernel.org>
Tue, 24 Dec 2024 10:07:19 +0000 (15:37 +0530)
bcm2835-dma provides the service to others, so it should suspend
late and resume early. Suspend should be prevented in case a DMA
channel is still busy.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Link: https://lore.kernel.org/r/20241204165546.77941-1-wahrenst@gmx.net
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/bcm2835-dma.c

index 7ba52dee40a9672891fd60992a48aeb3ae9ef1ce..20b10c15c696781eeb645f70c60657f6b28ee8d7 100644 (file)
@@ -875,6 +875,27 @@ static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
        return chan;
 }
 
+static int bcm2835_dma_suspend_late(struct device *dev)
+{
+       struct bcm2835_dmadev *od = dev_get_drvdata(dev);
+       struct bcm2835_chan *c, *next;
+
+       list_for_each_entry_safe(c, next, &od->ddev.channels,
+                                vc.chan.device_node) {
+               void __iomem *chan_base = c->chan_base;
+
+               /* Check if DMA channel is busy */
+               if (readl(chan_base + BCM2835_DMA_ADDR))
+                       return -EBUSY;
+       }
+
+       return 0;
+}
+
+static const struct dev_pm_ops bcm2835_dma_pm_ops = {
+       SET_LATE_SYSTEM_SLEEP_PM_OPS(bcm2835_dma_suspend_late, NULL)
+};
+
 static int bcm2835_dma_probe(struct platform_device *pdev)
 {
        struct bcm2835_dmadev *od;
@@ -1033,6 +1054,7 @@ static struct platform_driver bcm2835_dma_driver = {
        .driver = {
                .name = "bcm2835-dma",
                .of_match_table = of_match_ptr(bcm2835_dma_of_match),
+               .pm = pm_ptr(&bcm2835_dma_pm_ops),
        },
 };