Skip to content

Commit

Permalink
dma: dma_nxp_edma: add support for managing per-channel PDs
Browse files Browse the repository at this point in the history
Add support for managing per-channel power domains (1 channel,
1 PD).

Signed-off-by: Laurentiu Mihalcea <[email protected]>
  • Loading branch information
LaurentiuM1234 committed Dec 11, 2024
1 parent 6ac7f5f commit 94fbaed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
26 changes: 25 additions & 1 deletion drivers/dma/dma_nxp_edma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions drivers/dma/dma_nxp_edma.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 94fbaed

Please sign in to comment.