Skip to content

Commit 847fe7f

Browse files
committed
drivers: dma: cc23x0: Add power management
Add runtime PM support to cc23x0 DMA module. Signed-off-by: Julien Panis <jpanis@baylibre.com>
1 parent 179045e commit 847fe7f

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

drivers/dma/dma_ti_cc23x0.c

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ LOG_MODULE_REGISTER(dma_cc23x0, CONFIG_DMA_LOG_LEVEL);
1212
#include <zephyr/device.h>
1313
#include <zephyr/drivers/dma.h>
1414
#include <zephyr/irq.h>
15+
#include <zephyr/pm/device.h>
16+
#include <zephyr/pm/policy.h>
1517
#include <zephyr/sys/util.h>
1618

1719
#include <driverlib/clkctl.h>
@@ -56,6 +58,18 @@ struct dma_cc23x0_data {
5658
struct dma_cc23x0_channel channels[UDMA_NUM_CHANNELS];
5759
};
5860

61+
static inline void dma_cc23x0_pm_policy_state_lock_get(void)
62+
{
63+
pm_policy_state_lock_get(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES);
64+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
65+
}
66+
67+
static inline void dma_cc23x0_pm_policy_state_lock_put(void)
68+
{
69+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
70+
pm_policy_state_lock_put(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES);
71+
}
72+
5973
/*
6074
* If the channel is a software channel, then the completion will be signaled
6175
* on this DMA dedicated interrupt.
@@ -343,27 +357,38 @@ static int dma_cc23x0_get_status(const struct device *dev, uint32_t channel,
343357
return 0;
344358
}
345359

346-
static int dma_cc23x0_init(const struct device *dev)
360+
static int dma_cc23x0_pm_action(const struct device *dev, enum pm_device_action action)
347361
{
348362
struct dma_cc23x0_data *data = dev->data;
349363

364+
switch (action) {
365+
case PM_DEVICE_ACTION_SUSPEND:
366+
uDMADisable();
367+
CLKCTLDisable(CLKCTL_BASE, CLKCTL_DMA);
368+
dma_cc23x0_pm_policy_state_lock_put();
369+
return 0;
370+
case PM_DEVICE_ACTION_RESUME:
371+
dma_cc23x0_pm_policy_state_lock_get();
372+
CLKCTLEnable(CLKCTL_BASE, CLKCTL_DMA);
373+
uDMAEnable();
374+
/* Set base address for channel control table (descriptors) */
375+
uDMASetControlBase(data->desc);
376+
return 0;
377+
default:
378+
return -ENOTSUP;
379+
}
380+
}
381+
382+
static int dma_cc23x0_init(const struct device *dev)
383+
{
350384
IRQ_CONNECT(DT_INST_IRQN(0),
351385
DT_INST_IRQ(0, priority),
352386
dma_cc23x0_isr,
353387
DEVICE_DT_INST_GET(0),
354388
0);
355389
irq_enable(DT_INST_IRQN(0));
356390

357-
/* Enable clock */
358-
CLKCTLEnable(CLKCTL_BASE, CLKCTL_DMA);
359-
360-
/* Enable DMA */
361-
uDMAEnable();
362-
363-
/* Set base address for channel control table (descriptors) */
364-
uDMASetControlBase(data->desc);
365-
366-
return 0;
391+
return pm_device_driver_init(dev, dma_cc23x0_pm_action);
367392
}
368393

369394
static struct dma_cc23x0_data cc23x0_data;
@@ -376,7 +401,10 @@ static DEVICE_API(dma, dma_cc23x0_api) = {
376401
.get_status = dma_cc23x0_get_status,
377402
};
378403

379-
DEVICE_DT_INST_DEFINE(0, dma_cc23x0_init, NULL,
404+
PM_DEVICE_DT_INST_DEFINE(0, dma_cc23x0_pm_action);
405+
406+
DEVICE_DT_INST_DEFINE(0, dma_cc23x0_init,
407+
PM_DEVICE_DT_INST_GET(0),
380408
&cc23x0_data, NULL,
381409
PRE_KERNEL_1, CONFIG_DMA_INIT_PRIORITY,
382410
&dma_cc23x0_api);

0 commit comments

Comments
 (0)