Skip to content

Commit e603e6d

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 e603e6d

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

drivers/dma/dma_silabs_siwx91x.c

Lines changed: 46 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,45 @@ 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+
if (action == 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+
} else if (IS_ENABLED(CONFIG_PM_DEVICE) && (action == PM_DEVICE_ACTION_SUSPEND)) {
95+
return 0;
96+
} else {
97+
return -ENOTSUP;
98+
}
99+
100+
return 0;
101+
}
102+
63103
static enum dma_xfer_dir siwx91x_transfer_direction(uint32_t dir)
64104
{
65105
if (dir == MEMORY_TO_MEMORY) {
@@ -591,7 +631,7 @@ static int siwx91x_dma_init(const struct device *dev)
591631
return -EBUSY;
592632
}
593633

594-
return 0;
634+
return pm_device_driver_init(dev, dma_siwx91x_pm_action);
595635
}
596636

597637
static void siwx91x_dma_isr(const struct device *dev)
@@ -701,7 +741,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701741
(siwx91x_dma_chan_desc##inst)), \
702742
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703743
}; \
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);
744+
PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \
745+
DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \
746+
&dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \
747+
CONFIG_DMA_INIT_PRIORITY, \
748+
&siwx91x_dma_api);
706749

707750
DT_INST_FOREACH_STATUS_OKAY(SIWX91X_DMA_INIT)

0 commit comments

Comments
 (0)