13
13
#include <zephyr/drivers/dma.h>
14
14
#include <zephyr/drivers/clock_control.h>
15
15
#include <zephyr/logging/log.h>
16
+ #include <zephyr/pm/device.h>
16
17
#include <zephyr/types.h>
17
18
#include "rsi_rom_udma.h"
18
19
#include "rsi_rom_udma_wrapper.h"
@@ -560,8 +561,7 @@ bool siwx91x_dma_chan_filter(const struct device *dev, int channel, void *filter
560
561
}
561
562
}
562
563
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 )
565
565
{
566
566
const struct dma_siwx91x_config * cfg = dev -> config ;
567
567
struct dma_siwx91x_data * data = dev -> data ;
@@ -573,27 +573,39 @@ static int siwx91x_dma_init(const struct device *dev)
573
573
};
574
574
int ret ;
575
575
576
- ret = clock_control_on (cfg -> clock_dev , cfg -> clock_subsys );
577
- if (ret ) {
578
- return ret ;
579
- }
576
+ if (action == PM_DEVICE_ACTION_RESUME ) {
577
+ ret = clock_control_on (cfg -> clock_dev , cfg -> clock_subsys );
578
+ if (ret ) {
579
+ return ret ;
580
+ }
580
581
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
- }
582
+ udma_handle = UDMAx_Initialize (& udma_resources , udma_resources .desc , NULL ,
583
+ (uint32_t * )& data -> udma_handle );
584
+ if (udma_handle != & data -> udma_handle ) {
585
+ return - EINVAL ;
586
+ }
586
587
587
- /* Connect the DMA interrupt */
588
- cfg -> irq_configure ();
588
+ /* Connect the DMA interrupt */
589
+ cfg -> irq_configure ();
589
590
590
- if (UDMAx_DMAEnable (& udma_resources , udma_handle ) != 0 ) {
591
- return - EBUSY ;
591
+ if (UDMAx_DMAEnable (& udma_resources , udma_handle ) != 0 ) {
592
+ return - EBUSY ;
593
+ }
594
+ } else if (IS_ENABLED (CONFIG_PM_DEVICE ) && (action == PM_DEVICE_ACTION_SUSPEND )) {
595
+ return 0 ;
596
+ } else {
597
+ return - ENOTSUP ;
592
598
}
593
599
594
600
return 0 ;
595
601
}
596
602
603
+ /* Function to initialize DMA peripheral */
604
+ static int siwx91x_dma_init (const struct device * dev )
605
+ {
606
+ return pm_device_driver_init (dev , dma_siwx91x_pm_action );
607
+ }
608
+
597
609
static void siwx91x_dma_isr (const struct device * dev )
598
610
{
599
611
const struct dma_siwx91x_config * cfg = dev -> config ;
@@ -701,7 +713,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701
713
(siwx91x_dma_chan_desc##inst)), \
702
714
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703
715
}; \
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);
716
+ PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \
717
+ DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \
718
+ &dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \
719
+ CONFIG_DMA_INIT_PRIORITY, \
720
+ &siwx91x_dma_api);
706
721
707
722
DT_INST_FOREACH_STATUS_OKAY (SIWX91X_DMA_INIT )
0 commit comments