1212#include <zephyr/drivers/clock_control.h>
1313#include <zephyr/logging/log.h>
1414#include <zephyr/pm/device.h>
15- #include <zephyr/pm/policy .h>
15+ #include <zephyr/pm/device_runtime .h>
1616#include "rsi_gpdma.h"
1717#include "rsi_rom_gpdma.h"
1818
@@ -43,6 +43,7 @@ struct siwx91x_gpdma_channel_info {
4343 void * cb_data ;
4444 RSI_GPDMA_DESC_T * desc ;
4545 enum gpdma_xfer_dir xfer_direction ;
46+ bool channel_active ;
4647};
4748
4849struct siwx91x_gpdma_config {
@@ -62,16 +63,6 @@ struct siwx19x_gpdma_data {
6263 uint8_t reload_compatible ;
6364};
6465
65- static void siwx91x_gpdma_pm_policy_state_lock_get (void )
66- {
67- pm_policy_state_lock_get (PM_STATE_SUSPEND_TO_IDLE , PM_ALL_SUBSTATES );
68- }
69-
70- static void siwx91x_gpdma_pm_policy_state_lock_put (void )
71- {
72- pm_policy_state_lock_put (PM_STATE_SUSPEND_TO_IDLE , PM_ALL_SUBSTATES );
73- }
74-
7566static bool siwx91x_gpdma_is_priority_valid (uint32_t channel_priority )
7667{
7768 return (channel_priority >= GPDMA_MIN_PRIORITY && channel_priority <= GPDMA_MAX_PRIORITY );
@@ -408,19 +399,22 @@ static int siwx91x_gpdma_reload(const struct device *dev, uint32_t channel, uint
408399
409400static int siwx91x_gpdma_start (const struct device * dev , uint32_t channel )
410401{
411- const struct siwx91x_gpdma_config * cfg = dev -> config ;
412402 struct siwx19x_gpdma_data * data = dev -> data ;
413403
414404 if (channel >= data -> dma_ctx .dma_channels ) {
415405 return - EINVAL ;
416406 }
417407
418- if (!sys_test_bit ((mem_addr_t )& cfg -> reg -> GLOBAL .DMA_CHNL_ENABLE_REG , channel )) {
419- siwx91x_gpdma_pm_policy_state_lock_get ();
408+ if (data -> chan_info [channel ].channel_active ) {
409+ pm_device_runtime_get (dev );
410+ data -> chan_info [channel ].channel_active = true;
420411 }
421412
422413 if (RSI_GPDMA_DMAChannelTrigger (& data -> hal_ctx , channel )) {
423- siwx91x_gpdma_pm_policy_state_lock_put ();
414+ if (data -> chan_info [channel ].channel_active ) {
415+ pm_device_runtime_put (dev );
416+ data -> chan_info [channel ].channel_active = false;
417+ }
424418 return - EINVAL ;
425419 }
426420
@@ -429,18 +423,13 @@ static int siwx91x_gpdma_start(const struct device *dev, uint32_t channel)
429423
430424static int siwx91x_gpdma_stop (const struct device * dev , uint32_t channel )
431425{
432- const struct siwx91x_gpdma_config * cfg = dev -> config ;
433426 struct siwx19x_gpdma_data * data = dev -> data ;
434427 k_spinlock_key_t key ;
435428
436429 if (channel >= data -> dma_ctx .dma_channels ) {
437430 return - EINVAL ;
438431 }
439432
440- if (sys_test_bit ((mem_addr_t )& cfg -> reg -> GLOBAL .DMA_CHNL_ENABLE_REG , channel )) {
441- siwx91x_gpdma_pm_policy_state_lock_put ();
442- }
443-
444433 if (RSI_GPDMA_AbortChannel (& data -> hal_ctx , channel )) {
445434 return - EINVAL ;
446435 }
@@ -449,6 +438,11 @@ static int siwx91x_gpdma_stop(const struct device *dev, uint32_t channel)
449438 siwx91x_gpdma_free_desc (data -> desc_pool , data -> chan_info [channel ].desc );
450439 k_spin_unlock (& data -> desc_pool_lock , key );
451440
441+ if (data -> chan_info [channel ].channel_active ) {
442+ pm_device_runtime_put (dev );
443+ data -> chan_info [channel ].channel_active = false;
444+ }
445+
452446 return 0 ;
453447}
454448
@@ -552,7 +546,6 @@ static void siwx91x_gpdma_isr(const struct device *dev)
552546 if (channel_int_status & abort_mask ) {
553547 RSI_GPDMA_AbortChannel (& data -> hal_ctx , channel );
554548 cfg -> reg -> GLOBAL .INTERRUPT_STAT_REG = abort_mask ;
555- siwx91x_gpdma_pm_policy_state_lock_put ();
556549 }
557550
558551 if (channel_int_status & desc_fetch_mask ) {
@@ -569,11 +562,16 @@ static void siwx91x_gpdma_isr(const struct device *dev)
569562 k_spin_unlock (& data -> desc_pool_lock , key );
570563 data -> chan_info [channel ].desc = NULL ;
571564 cfg -> reg -> GLOBAL .INTERRUPT_STAT_REG = done_mask ;
565+
566+ if (data -> chan_info [channel ].channel_active ) {
567+ pm_device_runtime_put_async (dev , K_NO_WAIT );
568+ data -> chan_info [channel ].channel_active = false;
569+ }
570+
572571 if (data -> chan_info [channel ].cb ) {
573572 data -> chan_info [channel ].cb (dev , data -> chan_info [channel ].cb_data , channel ,
574573 0 );
575574 }
576- siwx91x_gpdma_pm_policy_state_lock_put ();
577575 }
578576}
579577
0 commit comments