Commit fbe05149 authored by Vignesh Raghavendra's avatar Vignesh Raghavendra Committed by Vinod Koul

dmaengine: ti: k3-udma: Add system suspend/resume support

The K3 platforms configure the DMA resources with the
help of the TI's System Firmware's Device Manager(DM)
over TISCI. The group of DMA related Resource Manager[1]
TISCI messages includes: INTA, RINGACC, UDMAP, and PSI-L.
This configuration however, does not persist in the DM
after leaving from Suspend-to-RAM state. We have to restore
the DMA channel configuration over TISCI for all configured
channels when returning from suspend.

The TISCI resource management calls for each DMA type (UDMA,
PKTDMA, BCDMA) happen in device_free_chan_resources() and
device_alloc_chan_resources(). In pm_suspend() we store
the current udma_chan_config for channels that still have
attached clients and call device_free_chan_resources().
In pm_resume() restore the udma_channel_config from backup
and call device_alloc_chan_resources() for those channels.

Drivers like CPSW that use k3-udma-glue already do their own
DMA resource management so use the late system suspend/resume hooks.

[1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/index.html#resource-management-rmSigned-off-by: default avatarVignesh Raghavendra <vigneshr@ti.com>
[g-vlaev@ti.com: Add patch description and config backup]
[g-vlaev@ti.com: Supend only channels with clients]
Signed-off-by: default avatarGeorgi Vlaev <g-vlaev@ti.com>
Acked-by: default avatarPeter Ujfalusi <peter.ujfalusi@gmail.com>
Link: https://lore.kernel.org/r/20230329155349.2566010-1-vigneshr@ti.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 7511f287
......@@ -305,6 +305,8 @@ struct udma_chan {
/* Channel configuration parameters */
struct udma_chan_config config;
/* Channel configuration parameters (backup) */
struct udma_chan_config backup_config;
/* dmapool for packet mode descriptors */
bool use_dma_pool;
......@@ -5522,11 +5524,63 @@ static int udma_probe(struct platform_device *pdev)
return ret;
}
static int udma_pm_suspend(struct device *dev)
{
struct udma_dev *ud = dev_get_drvdata(dev);
struct dma_device *dma_dev = &ud->ddev;
struct dma_chan *chan;
struct udma_chan *uc;
list_for_each_entry(chan, &dma_dev->channels, device_node) {
if (chan->client_count) {
uc = to_udma_chan(chan);
/* backup the channel configuration */
memcpy(&uc->backup_config, &uc->config,
sizeof(struct udma_chan_config));
dev_dbg(dev, "Suspending channel %s\n",
dma_chan_name(chan));
ud->ddev.device_free_chan_resources(chan);
}
}
return 0;
}
static int udma_pm_resume(struct device *dev)
{
struct udma_dev *ud = dev_get_drvdata(dev);
struct dma_device *dma_dev = &ud->ddev;
struct dma_chan *chan;
struct udma_chan *uc;
int ret;
list_for_each_entry(chan, &dma_dev->channels, device_node) {
if (chan->client_count) {
uc = to_udma_chan(chan);
/* restore the channel configuration */
memcpy(&uc->config, &uc->backup_config,
sizeof(struct udma_chan_config));
dev_dbg(dev, "Resuming channel %s\n",
dma_chan_name(chan));
ret = ud->ddev.device_alloc_chan_resources(chan);
if (ret)
return ret;
}
}
return 0;
}
static const struct dev_pm_ops udma_pm_ops = {
SET_LATE_SYSTEM_SLEEP_PM_OPS(udma_pm_suspend, udma_pm_resume)
};
static struct platform_driver udma_driver = {
.driver = {
.name = "ti-udma",
.of_match_table = udma_of_match,
.suppress_bind_attrs = true,
.pm = &udma_pm_ops,
},
.probe = udma_probe,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment