Skip to content

Commit 569979a

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 dddd738 commit 569979a

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

drivers/dma/dma_silabs_siwx91x.c

Lines changed: 37 additions & 17 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"
@@ -560,8 +561,7 @@ bool siwx91x_dma_chan_filter(const struct device *dev, int channel, void *filter
560561
}
561562
}
562563

563-
/* Function to initialize DMA peripheral */
564-
static int siwx91x_dma_init(const struct device *dev)
564+
static int dma_siwx91x_pm_action(const struct device *dev, enum pm_device_action action)
565565
{
566566
const struct dma_siwx91x_config *cfg = dev->config;
567567
struct dma_siwx91x_data *data = dev->data;
@@ -573,27 +573,44 @@ static int siwx91x_dma_init(const struct device *dev)
573573
};
574574
int ret;
575575

576-
ret = clock_control_on(cfg->clock_dev, cfg->clock_subsys);
577-
if (ret) {
578-
return ret;
579-
}
576+
switch (action) {
577+
case PM_DEVICE_ACTION_RESUME:
578+
break;
579+
case PM_DEVICE_ACTION_SUSPEND:
580+
break;
581+
case PM_DEVICE_ACTION_TURN_ON:
582+
ret = clock_control_on(cfg->clock_dev, cfg->clock_subsys);
583+
if (ret < 0 && ret != -EALREADY) {
584+
return ret;
585+
}
580586

581-
udma_handle = UDMAx_Initialize(&udma_resources, udma_resources.desc, NULL,
582-
(uint32_t *)&data->udma_handle);
583-
if (udma_handle != &data->udma_handle) {
584-
return -EINVAL;
585-
}
587+
udma_handle = UDMAx_Initialize(&udma_resources, udma_resources.desc, NULL,
588+
(uint32_t *)&data->udma_handle);
589+
if (udma_handle != &data->udma_handle) {
590+
return -EINVAL;
591+
}
586592

587-
/* Connect the DMA interrupt */
588-
cfg->irq_configure();
593+
cfg->irq_configure();
589594

590-
if (UDMAx_DMAEnable(&udma_resources, udma_handle) != 0) {
591-
return -EBUSY;
595+
if (UDMAx_DMAEnable(&udma_resources, udma_handle) != 0) {
596+
return -EBUSY;
597+
}
598+
break;
599+
case PM_DEVICE_ACTION_TURN_OFF:
600+
break;
601+
default:
602+
return -ENOTSUP;
592603
}
593604

594605
return 0;
595606
}
596607

608+
/* Function to initialize DMA peripheral */
609+
static int siwx91x_dma_init(const struct device *dev)
610+
{
611+
return pm_device_driver_init(dev, dma_siwx91x_pm_action);
612+
}
613+
597614
static void siwx91x_dma_isr(const struct device *dev)
598615
{
599616
const struct dma_siwx91x_config *cfg = dev->config;
@@ -701,7 +718,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701718
(siwx91x_dma_chan_desc##inst)), \
702719
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703720
}; \
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);
721+
PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \
722+
DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \
723+
&dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \
724+
CONFIG_DMA_INIT_PRIORITY, \
725+
&siwx91x_dma_api);
706726

707727
DT_INST_FOREACH_STATUS_OKAY(SIWX91X_DMA_INIT)

dts/arm/silabs/siwg917.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@
304304
clocks = <&clock0 SIWX91X_CLK_DMA0>;
305305
#dma-cells = <1>;
306306
dma-channels = <32>;
307+
power-domains = <&siwx91x_soc_pd>;
308+
zephyr,pm-device-runtime-auto;
307309
status = "disabled";
308310
};
309311

0 commit comments

Comments
 (0)