Skip to content

Commit 620f008

Browse files
committed
driver: dma: dma_silabs_siwx91x: Add pm device support for dma driver
This commit enables the pm device driver support for the dma_silabs_siwx91x driver. Signed-off-by: S Mohamed Fiaz <[email protected]>
1 parent add9e60 commit 620f008

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

drivers/dma/dma_silabs_siwx91x.c

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/drivers/dma.h>
1414
#include <zephyr/drivers/clock_control.h>
1515
#include <zephyr/logging/log.h>
16+
#include <zephyr/pm/device.h>
1617
#include <zephyr/types.h>
1718
#include "rsi_rom_udma.h"
1819
#include "rsi_rom_udma_wrapper.h"
@@ -60,6 +61,47 @@ struct dma_siwx91x_data {
6061
*/
6162
};
6263

64+
__maybe_unused static int dma_siwx91x_pm_action(const struct device *dev,
65+
enum pm_device_action action)
66+
{
67+
const struct dma_siwx91x_config *cfg = dev->config;
68+
struct dma_siwx91x_data *data = dev->data;
69+
void *udma_handle = NULL;
70+
UDMA_RESOURCES udma_resources = {
71+
.reg = cfg->reg,
72+
.udma_irq_num = cfg->irq_number,
73+
.desc = cfg->sram_desc_addr,
74+
};
75+
int ret;
76+
77+
switch (action) {
78+
case PM_DEVICE_ACTION_RESUME:
79+
ret = clock_control_on(cfg->clock_dev, cfg->clock_subsys);
80+
if (ret) {
81+
return ret;
82+
}
83+
84+
udma_handle = UDMAx_Initialize(&udma_resources, udma_resources.desc, NULL,
85+
(uint32_t *)&data->udma_handle);
86+
if (udma_handle != &data->udma_handle) {
87+
return -EINVAL;
88+
}
89+
90+
cfg->irq_configure();
91+
92+
if (UDMAx_DMAEnable(&udma_resources, udma_handle) != 0) {
93+
return -EBUSY;
94+
}
95+
96+
break;
97+
case PM_DEVICE_ACTION_SUSPEND:
98+
return 0;
99+
default:
100+
return -ENOTSUP;
101+
}
102+
return 0;
103+
}
104+
63105
static enum dma_xfer_dir siwx91x_transfer_direction(uint32_t dir)
64106
{
65107
if (dir == MEMORY_TO_MEMORY) {
@@ -591,7 +633,7 @@ static int siwx91x_dma_init(const struct device *dev)
591633
return -EBUSY;
592634
}
593635

594-
return 0;
636+
return pm_device_driver_init(dev, dma_siwx91x_pm_action);
595637
}
596638

597639
static void siwx91x_dma_isr(const struct device *dev)
@@ -701,7 +743,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701743
(siwx91x_dma_chan_desc##inst)), \
702744
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703745
}; \
704-
DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, NULL, &dma_data_##inst, &dma_cfg_##inst, \
705-
POST_KERNEL, CONFIG_DMA_INIT_PRIORITY, &siwx91x_dma_api);
746+
PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \
747+
DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \
748+
&dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \
749+
CONFIG_DMA_INIT_PRIORITY, \
750+
&siwx91x_dma_api);
706751

707752
DT_INST_FOREACH_STATUS_OKAY(SIWX91X_DMA_INIT)

0 commit comments

Comments
 (0)