dma: dma_nxp_edma: add support for managing per-channel PDs
Add support for managing per-channel power domains (1 channel, 1 PD). Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
This commit is contained in:
parent
520c967c42
commit
8a060ba4a1
2 changed files with 36 additions and 1 deletions
|
|
@ -30,6 +30,11 @@ static void edma_isr(const void *parameter)
|
|||
cfg = chan->dev->config;
|
||||
data = chan->dev->data;
|
||||
|
||||
if (chan->state == CHAN_STATE_RELEASING || chan->state == CHAN_STATE_INIT) {
|
||||
/* skip, not safe to access channel register space */
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EDMA_ChannelRegRead(data->hal_cfg, chan->id, EDMA_TCD_CH_INT)) {
|
||||
/* skip, interrupt was probably triggered by another channel */
|
||||
return;
|
||||
|
|
@ -581,6 +586,7 @@ static int edma_get_attribute(const struct device *dev, uint32_t type, uint32_t
|
|||
static bool edma_channel_filter(const struct device *dev, int chan_id, void *param)
|
||||
{
|
||||
struct edma_channel *chan;
|
||||
int ret;
|
||||
|
||||
if (!param) {
|
||||
return false;
|
||||
|
|
@ -595,6 +601,15 @@ static bool edma_channel_filter(const struct device *dev, int chan_id, void *par
|
|||
return false;
|
||||
}
|
||||
|
||||
if (chan->pd_dev) {
|
||||
ret = pm_device_runtime_get(chan->pd_dev);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("failed to PM get channel %d PD dev: %d",
|
||||
chan_id, ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
irq_enable(chan->irq);
|
||||
|
||||
return true;
|
||||
|
|
@ -604,6 +619,7 @@ static void edma_channel_release(const struct device *dev, uint32_t chan_id)
|
|||
{
|
||||
struct edma_channel *chan;
|
||||
struct edma_data *data;
|
||||
int ret;
|
||||
|
||||
chan = lookup_channel(dev, chan_id);
|
||||
if (!chan) {
|
||||
|
|
@ -626,13 +642,21 @@ static void edma_channel_release(const struct device *dev, uint32_t chan_id)
|
|||
return;
|
||||
}
|
||||
|
||||
/* start the process of disabling IRQ */
|
||||
/* start the process of disabling IRQ and PD */
|
||||
chan->state = CHAN_STATE_RELEASING;
|
||||
|
||||
#ifdef CONFIG_NXP_IRQSTEER
|
||||
irq_disable(chan->irq);
|
||||
#endif /* CONFIG_NXP_IRQSTEER */
|
||||
|
||||
if (chan->pd_dev) {
|
||||
ret = pm_device_runtime_put(chan->pd_dev);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("failed to PM put channel %d PD dev: %d",
|
||||
chan_id, ret);
|
||||
}
|
||||
}
|
||||
|
||||
/* done, proceed with next state */
|
||||
chan->state = CHAN_STATE_INIT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
#include <zephyr/irq.h>
|
||||
#include <zephyr/drivers/dma.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
|
||||
#include "fsl_edma_soc_rev2.h"
|
||||
|
||||
|
|
@ -54,12 +56,18 @@ LOG_MODULE_REGISTER(nxp_edma);
|
|||
0, edma_isr, \
|
||||
&channels_##inst[idx], 0)
|
||||
|
||||
#define _EDMA_CHANNEL_PD_DEVICE_OR_NULL(idx, inst) \
|
||||
COND_CODE_1(CONFIG_PM_DEVICE_POWER_DOMAIN, \
|
||||
(DEVICE_DT_GET_OR_NULL(DT_INST_PHANDLE_BY_IDX(inst, power_domains, idx))), \
|
||||
(NULL))
|
||||
|
||||
/* used to declare a struct edma_channel by the non-explicit macro suite */
|
||||
#define _EDMA_CHANNEL_DECLARE(idx, inst) \
|
||||
{ \
|
||||
.id = DT_INST_PROP_BY_IDX(inst, valid_channels, idx), \
|
||||
.dev = DEVICE_DT_INST_GET(inst), \
|
||||
.irq = DT_INST_IRQN_BY_IDX(inst, idx), \
|
||||
.pd_dev = _EDMA_CHANNEL_PD_DEVICE_OR_NULL(idx, inst), \
|
||||
}
|
||||
|
||||
/* used to declare a struct edma_channel by the explicit macro suite */
|
||||
|
|
@ -68,6 +76,7 @@ LOG_MODULE_REGISTER(nxp_edma);
|
|||
.id = idx, \
|
||||
.dev = DEVICE_DT_INST_GET(inst), \
|
||||
.irq = DT_INST_IRQN_BY_IDX(inst, idx), \
|
||||
.pd_dev = _EDMA_CHANNEL_PD_DEVICE_OR_NULL(idx, inst), \
|
||||
}
|
||||
|
||||
/* used to create an array of channel IDs via the valid-channels property */
|
||||
|
|
@ -183,6 +192,8 @@ struct edma_channel {
|
|||
uint32_t id;
|
||||
/* pointer to device representing the EDMA instance, used by edma_isr */
|
||||
const struct device *dev;
|
||||
/* channel power domain device */
|
||||
const struct device *pd_dev;
|
||||
/* current state of the channel */
|
||||
enum channel_state state;
|
||||
/* type of the channel (PRODUCER/CONSUMER) - only applicable to cyclic
|
||||
|
|
|
|||
Loading…
Reference in a new issue