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,44 @@ 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
+ 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
+ }
580
586
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
+ }
586
592
587
- /* Connect the DMA interrupt */
588
- cfg -> irq_configure ();
593
+ cfg -> irq_configure ();
589
594
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 ;
592
603
}
593
604
594
605
return 0 ;
595
606
}
596
607
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
+
597
614
static void siwx91x_dma_isr (const struct device * dev )
598
615
{
599
616
const struct dma_siwx91x_config * cfg = dev -> config ;
@@ -701,7 +718,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
701
718
(siwx91x_dma_chan_desc##inst)), \
702
719
.irq_configure = siwx91x_dma_irq_configure_##inst, \
703
720
}; \
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);
706
726
707
727
DT_INST_FOREACH_STATUS_OKAY (SIWX91X_DMA_INIT )
0 commit comments