Skip to content

Commit 19c82eb

Browse files
drivers: dma: siwx91x: replace pm_state with pm_device (udma and gpdma)
Removed unnecessary power management state lock calls since the DMA is on a power domain that already handles state locking. It will now managed directly pm_device which will active power_domain and then block pm_state. Signed-off-by: Martin Hoff <[email protected]>
1 parent 241784b commit 19c82eb

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

drivers/dma/dma_silabs_siwx91x.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <zephyr/drivers/clock_control.h>
1515
#include <zephyr/logging/log.h>
1616
#include <zephyr/pm/device.h>
17-
#include <zephyr/pm/policy.h>
17+
#include <zephyr/pm/device_runtime.h>
1818
#include <zephyr/types.h>
1919
#include "rsi_rom_udma.h"
2020
#include "rsi_rom_udma_wrapper.h"
@@ -63,16 +63,6 @@ struct dma_siwx91x_data {
6363
*/
6464
};
6565

66-
static void siwx91x_dma_pm_policy_state_lock_get(void)
67-
{
68-
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
69-
}
70-
71-
static void siwx91x_dma_pm_policy_state_lock_put(void)
72-
{
73-
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE, PM_ALL_SUBSTATES);
74-
}
75-
7666
static enum dma_xfer_dir siwx91x_transfer_direction(uint32_t dir)
7767
{
7868
if (dir == MEMORY_TO_MEMORY) {
@@ -495,15 +485,14 @@ static int siwx91x_dma_start(const struct device *dev, uint32_t channel)
495485
return -EINVAL;
496486
}
497487

498-
/* Get the power management policy state lock */
499488
if (!data->zephyr_channel_info[channel].channel_active) {
500-
siwx91x_dma_pm_policy_state_lock_get();
489+
pm_device_runtime_get(dev);
501490
data->zephyr_channel_info[channel].channel_active = true;
502491
}
503492

504493
if (RSI_UDMA_ChannelEnable(udma_handle, channel) != 0) {
505494
if (data->zephyr_channel_info[channel].channel_active) {
506-
siwx91x_dma_pm_policy_state_lock_put();
495+
pm_device_runtime_put(dev);
507496
data->zephyr_channel_info[channel].channel_active = false;
508497
}
509498
return -EINVAL;
@@ -534,7 +523,7 @@ static int siwx91x_dma_stop(const struct device *dev, uint32_t channel)
534523
}
535524

536525
if (data->zephyr_channel_info[channel].channel_active) {
537-
siwx91x_dma_pm_policy_state_lock_put();
526+
pm_device_runtime_put(dev);
538527
data->zephyr_channel_info[channel].channel_active = false;
539528
}
540529

@@ -680,16 +669,16 @@ static void siwx91x_dma_isr(const struct device *dev)
680669
}
681670

682671
if (data->chan_info[channel].Cnt == data->chan_info[channel].Size) {
672+
if (data->zephyr_channel_info[channel].channel_active) {
673+
pm_device_runtime_put_async(dev, K_NO_WAIT);
674+
data->zephyr_channel_info[channel].channel_active = false;
675+
}
683676
if (data->zephyr_channel_info[channel].dma_callback) {
684677
/* Transfer complete, call user callback */
685678
data->zephyr_channel_info[channel].dma_callback(
686679
dev, data->zephyr_channel_info[channel].cb_data, channel, 0);
687680
}
688681
sys_write32(BIT(channel), (mem_addr_t)&cfg->reg->UDMA_DONE_STATUS_REG);
689-
if (data->zephyr_channel_info[channel].channel_active) {
690-
siwx91x_dma_pm_policy_state_lock_put();
691-
data->zephyr_channel_info[channel].channel_active = false;
692-
}
693682
} else {
694683
/* Call UDMA ROM IRQ handler. */
695684
ROMAPI_UDMA_WRAPPER_API->uDMAx_IRQHandler(&udma_resources, udma_resources.desc,

drivers/dma/dma_silabs_siwx91x_gpdma.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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

4849
struct 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-
7566
static 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

409400
static 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

430424
static 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

Comments
 (0)