Skip to content

Commit ba1ba25

Browse files
committed
drivers: dma: support multiple instances
Support multiple instances for dma. Memset struct data and tcdpool on initialization is not necessary. Therefore remove it. Signed-off-by: Ha Duong Quang <[email protected]>
1 parent 091c666 commit ba1ba25

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

drivers/dma/dma_mcux_edma.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-23 NXP
2+
* Copyright 2020-2024 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -43,11 +43,13 @@ struct dma_mcux_edma_config {
4343
#endif
4444
uint8_t channels_per_mux;
4545
uint8_t dmamux_reg_offset;
46+
int dma_requests;
4647
int dma_channels; /* number of channels */
4748
#if DMA_MCUX_HAS_CHANNEL_GAP
4849
uint32_t channel_gap[2];
4950
#endif
5051
void (*irq_config_func)(const struct device *dev);
52+
edma_tcd_t (*tcdpool)[CONFIG_DMA_TCD_QUEUE_SIZE];
5153
};
5254

5355

@@ -82,9 +84,6 @@ struct dma_mcux_edma_config {
8284

8385
#endif /* CONFIG_HAS_MCUX_CACHE */
8486

85-
static __aligned(32) EDMA_TCDPOOL_CACHE_ATTR edma_tcd_t
86-
tcdpool[DT_INST_PROP(0, dma_channels)][CONFIG_DMA_TCD_QUEUE_SIZE];
87-
8887
struct dma_mcux_channel_transfer_edma_settings {
8988
uint32_t source_data_size;
9089
uint32_t dest_data_size;
@@ -108,8 +107,8 @@ struct call_back {
108107

109108
struct dma_mcux_edma_data {
110109
struct dma_context dma_ctx;
111-
struct call_back data_cb[DT_INST_PROP(0, dma_channels)];
112-
ATOMIC_DEFINE(channels_atomic, DT_INST_PROP(0, dma_channels));
110+
struct call_back *data_cb;
111+
atomic_t *channels_atomic;
113112
};
114113

115114
#define DEV_CFG(dev) \
@@ -256,12 +255,12 @@ static int dma_mcux_edma_configure(const struct device *dev, uint32_t channel,
256255
unsigned int key;
257256
int ret = 0;
258257

259-
if (slot >= DT_INST_PROP(0, dma_requests)) {
258+
if (slot >= DEV_CFG(dev)->dma_requests) {
260259
LOG_ERR("source number is out of scope %d", slot);
261260
return -ENOTSUP;
262261
}
263262

264-
if (channel >= DT_INST_PROP(0, dma_channels)) {
263+
if (channel >= DEV_CFG(dev)->dma_channels) {
265264
LOG_ERR("out of DMA channel %d", channel);
266265
return -EINVAL;
267266
}
@@ -359,7 +358,8 @@ static int dma_mcux_edma_configure(const struct device *dev, uint32_t channel,
359358
EDMA_EnableChannelInterrupts(DEV_BASE(dev), hw_channel, kEDMA_ErrorInterruptEnable);
360359

361360
if (block_config->source_gather_en || block_config->dest_scatter_en) {
362-
EDMA_InstallTCDMemory(p_handle, tcdpool[channel], CONFIG_DMA_TCD_QUEUE_SIZE);
361+
EDMA_InstallTCDMemory(p_handle, DEV_CFG(dev)->tcdpool[channel],
362+
CONFIG_DMA_TCD_QUEUE_SIZE);
363363
while (block_config != NULL) {
364364
EDMA_PrepareTransfer(
365365
&(data->transferConfig),
@@ -627,8 +627,6 @@ static int dma_mcux_edma_init(const struct device *dev)
627627
EDMA_EnableAllChannelLink(DEV_BASE(dev), true);
628628
#endif
629629
config->irq_config_func(dev);
630-
memset(dev->data, 0, sizeof(struct dma_mcux_edma_data));
631-
memset(tcdpool, 0, sizeof(tcdpool));
632630
data->dma_ctx.magic = DMA_MAGIC;
633631
data->dma_ctx.dma_channels = config->dma_channels;
634632
data->dma_ctx.atomic = data->channels_atomic;
@@ -716,17 +714,28 @@ static int dma_mcux_edma_init(const struct device *dev)
716714
#define DMA_INIT(n) \
717715
DMAMUX_BASE_INIT_DEFINE(n) \
718716
static void dma_imx_config_func_##n(const struct device *dev); \
717+
static __aligned(32) EDMA_TCDPOOL_CACHE_ATTR edma_tcd_t \
718+
dma_tcdpool##n[DT_INST_PROP(n, dma_channels)][CONFIG_DMA_TCD_QUEUE_SIZE];\
719719
static const struct dma_mcux_edma_config dma_config_##n = { \
720720
.base = (DMA_Type *)DT_INST_REG_ADDR(n), \
721721
DMAMUX_BASE_INIT(n) \
722+
.dma_requests = DT_INST_PROP(n, dma_requests), \
722723
.dma_channels = DT_INST_PROP(n, dma_channels), \
723724
CHANNELS_PER_MUX(n) \
724725
.irq_config_func = dma_imx_config_func_##n, \
725726
.dmamux_reg_offset = DT_INST_PROP(n, dmamux_reg_offset), \
726727
DMA_MCUX_EDMA_CHANNEL_GAP(n) \
728+
.tcdpool = dma_tcdpool##n, \
727729
}; \
728730
\
729-
struct dma_mcux_edma_data dma_data_##n; \
731+
static struct call_back \
732+
dma_data_callback_##n[DT_INST_PROP(n, dma_channels)]; \
733+
static ATOMIC_DEFINE( \
734+
dma_channels_atomic_##n, DT_INST_PROP(n, dma_channels)); \
735+
static struct dma_mcux_edma_data dma_data_##n = { \
736+
.data_cb = dma_data_callback_##n, \
737+
.channels_atomic = dma_channels_atomic_##n, \
738+
}; \
730739
\
731740
DEVICE_DT_INST_DEFINE(n, \
732741
&dma_mcux_edma_init, NULL, \

0 commit comments

Comments
 (0)