Skip to content

Commit c73b89c

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 c73b89c

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

drivers/dma/dma_silabs_siwx91x.c

Lines changed: 47 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,46 @@ struct dma_siwx91x_data {
6061
*/
6162
};
6263

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

594-
return 0;
635+
return pm_device_driver_init(dev, dma_siwx91x_pm_action);
595636
}
596637

597638
static void siwx91x_dma_isr(const struct device *dev)
@@ -701,7 +742,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701742
(siwx91x_dma_chan_desc##inst)), \
702743
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703744
}; \
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);
745+
PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \
746+
DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \
747+
&dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \
748+
CONFIG_DMA_INIT_PRIORITY, \
749+
&siwx91x_dma_api);
706750

707751
DT_INST_FOREACH_STATUS_OKAY(SIWX91X_DMA_INIT)

0 commit comments

Comments
 (0)