From 82c9f2e875727ecfa791b387e2bbec234c69dcb6 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Fri, 22 Nov 2024 13:35:07 +0200 Subject: [PATCH] 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 --- drivers/dma/dma_nxp_edma.c | 26 +++++++++++++++++++++++++- drivers/dma/dma_nxp_edma.h | 11 +++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/dma/dma_nxp_edma.c b/drivers/dma/dma_nxp_edma.c index 422b329dd7e7013..73b8a1a42dc412f 100644 --- a/drivers/dma/dma_nxp_edma.c +++ b/drivers/dma/dma_nxp_edma.c @@ -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; } diff --git a/drivers/dma/dma_nxp_edma.h b/drivers/dma/dma_nxp_edma.h index 3a3df771c1490b1..52f65a76938fef3 100644 --- a/drivers/dma/dma_nxp_edma.h +++ b/drivers/dma/dma_nxp_edma.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #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