Skip to content

Commit 025a5e3

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 025a5e3

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

drivers/dma/dma_ti_cc23x0.c

Lines changed: 55 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,20 @@ struct dma_cc23x0_data {
5658
struct dma_cc23x0_channel channels[UDMA_NUM_CHANNELS];
5759
};
5860

61+
#ifdef CONFIG_PM_DEVICE
62+
static inline void dma_cc23x0_pm_policy_state_lock_get(void)
63+
{
64+
pm_policy_state_lock_get(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES);
65+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
66+
}
67+
68+
static inline void dma_cc23x0_pm_policy_state_lock_put(void)
69+
{
70+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
71+
pm_policy_state_lock_put(PM_STATE_RUNTIME_IDLE, PM_ALL_SUBSTATES);
72+
}
73+
#endif /* CONFIG_PM_DEVICE */
74+
5975
/*
6076
* If the channel is a software channel, then the completion will be signaled
6177
* on this DMA dedicated interrupt.
@@ -343,27 +359,51 @@ static int dma_cc23x0_get_status(const struct device *dev, uint32_t channel,
343359
return 0;
344360
}
345361

346-
static int dma_cc23x0_init(const struct device *dev)
362+
static int dma_cc23x0_enable(struct dma_cc23x0_data *data)
363+
{
364+
CLKCTLEnable(CLKCTL_BASE, CLKCTL_DMA);
365+
366+
uDMAEnable();
367+
368+
/* Set base address for channel control table (descriptors) */
369+
uDMASetControlBase(data->desc);
370+
371+
return 0;
372+
}
373+
374+
#ifdef CONFIG_PM_DEVICE
375+
376+
static int dma_cc23x0_pm_action(const struct device *dev, enum pm_device_action action)
347377
{
348378
struct dma_cc23x0_data *data = dev->data;
349379

380+
switch (action) {
381+
case PM_DEVICE_ACTION_SUSPEND:
382+
uDMADisable();
383+
CLKCTLDisable(CLKCTL_BASE, CLKCTL_DMA);
384+
dma_cc23x0_pm_policy_state_lock_put();
385+
return 0;
386+
case PM_DEVICE_ACTION_RESUME:
387+
dma_cc23x0_pm_policy_state_lock_get();
388+
dma_cc23x0_enable(data);
389+
return 0;
390+
default:
391+
return -ENOTSUP;
392+
}
393+
}
394+
395+
#endif /* CONFIG_PM_DEVICE */
396+
397+
static int dma_cc23x0_init(const struct device *dev)
398+
{
350399
IRQ_CONNECT(DT_INST_IRQN(0),
351400
DT_INST_IRQ(0, priority),
352401
dma_cc23x0_isr,
353402
DEVICE_DT_INST_GET(0),
354403
0);
355404
irq_enable(DT_INST_IRQN(0));
356405

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;
406+
return pm_device_driver_init(dev, dma_cc23x0_pm_action);
367407
}
368408

369409
static struct dma_cc23x0_data cc23x0_data;
@@ -376,7 +416,10 @@ static DEVICE_API(dma, dma_cc23x0_api) = {
376416
.get_status = dma_cc23x0_get_status,
377417
};
378418

379-
DEVICE_DT_INST_DEFINE(0, dma_cc23x0_init, NULL,
419+
PM_DEVICE_DT_INST_DEFINE(0, dma_cc23x0_pm_action);
420+
421+
DEVICE_DT_INST_DEFINE(0, dma_cc23x0_init,
422+
PM_DEVICE_DT_INST_GET(0),
380423
&cc23x0_data, NULL,
381424
PRE_KERNEL_1, CONFIG_DMA_INIT_PRIORITY,
382425
&dma_cc23x0_api);

0 commit comments

Comments
 (0)