Skip to content

Commit 1350f62

Browse files
decsnyEmilioCBen
andcommitted
drivers: dma_mcux_edma: Support EDMAv3 without dmamux
Support EDMAv3 platform that do not have dmamux or always on capability. Therefore, memory to memory transfer is limited in this environment. Signed-off-by: Declan Snyder <[email protected]> Co-authored-by: Emilio Benavente <[email protected]>
1 parent 6d89f1e commit 1350f62

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

drivers/dma/dma_mcux_edma.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ struct dma_mcux_channel_transfer_edma_settings {
6666
uint32_t source_data_size;
6767
uint32_t dest_data_size;
6868
uint32_t source_burst_length;
69-
uint32_t dest_burst_length;
7069
enum dma_channel_direction direction;
7170
edma_transfer_type_t transfer_type;
7271
bool valid;
@@ -462,6 +461,7 @@ static int dma_mcux_edma_configure_basic(const struct device *dev,
462461
{
463462
edma_handle_t *p_handle = DEV_EDMA_HANDLE(dev, channel);
464463
struct call_back *data = DEV_CHANNEL_DATA(dev, channel);
464+
struct dma_mcux_channel_transfer_edma_settings *xfer_settings = &data->transfer_settings;
465465
struct dma_block_config *block_config = config->head_block;
466466
uint32_t hw_channel;
467467
int ret = 0;
@@ -473,7 +473,7 @@ static int dma_mcux_edma_configure_basic(const struct device *dev,
473473
config->source_data_size,
474474
(void *)block_config->dest_address,
475475
config->dest_data_size,
476-
config->source_burst_length,
476+
xfer_settings->source_burst_length,
477477
block_config->block_size, transfer_type);
478478

479479
const status_t submit_status = EDMA_SubmitTransfer(p_handle, &(data->transferConfig));
@@ -488,7 +488,7 @@ static int dma_mcux_edma_configure_basic(const struct device *dev,
488488
return ret;
489489
}
490490

491-
static void dma_mcux_edma_configure_hardware(const struct device *dev, uint32_t channel,
491+
static int dma_mcux_edma_configure_hardware(const struct device *dev, uint32_t channel,
492492
struct dma_config *config)
493493
{
494494
struct call_back *data = DEV_CHANNEL_DATA(dev, channel);
@@ -499,6 +499,14 @@ static void dma_mcux_edma_configure_hardware(const struct device *dev, uint32_t
499499

500500
dma_mcux_edma_configure_muxes(dev, channel, config);
501501

502+
#if defined(CONFIG_DMA_MCUX_EDMA_V3) && \
503+
(!defined(FSL_FEATURE_SOC_DMAMUX_COUNT) || (FSL_FEATURE_SOC_DMAMUX_COUNT == 0))
504+
if (transfer_type == kEDMA_MemoryToMemory && (sg_mode || config->block_count > 1)) {
505+
LOG_WRN("mem2mem xfer scatter gather not supported");
506+
return -ENOTSUP;
507+
}
508+
#endif
509+
502510
if (sg_mode && config->cyclic) {
503511
dma_mcux_edma_configure_sg_loop(dev, channel, config, transfer_type);
504512
} else if (sg_mode) {
@@ -519,6 +527,8 @@ static void dma_mcux_edma_configure_hardware(const struct device *dev, uint32_t
519527
}
520528

521529
EDMA_EnableChannelInterrupts(DEV_BASE(dev), hw_channel, kEDMA_ErrorInterruptEnable);
530+
531+
return 0;
522532
}
523533

524534
static inline int dma_mcux_edma_validate_cfg(const struct device *dev,
@@ -594,7 +604,15 @@ static inline void dma_mcux_edma_set_xfer_settings(const struct device *dev, uin
594604
struct dma_mcux_channel_transfer_edma_settings *xfer_settings = &data->transfer_settings;
595605

596606
xfer_settings->source_burst_length = config->source_burst_length;
597-
xfer_settings->dest_burst_length = config->dest_burst_length;
607+
#if defined(CONFIG_DMA_MCUX_EDMA_V3) && \
608+
(!defined(FSL_FEATURE_SOC_DMAMUX_COUNT) || (FSL_FEATURE_SOC_DMAMUX_COUNT == 0))
609+
struct dma_block_config *block_config = config->head_block;
610+
611+
if (xfer_settings->transfer_type == kEDMA_MemoryToMemory) {
612+
xfer_settings->source_burst_length = block_config->block_size;
613+
614+
}
615+
#endif
598616
xfer_settings->source_data_size = config->source_data_size;
599617
xfer_settings->dest_data_size = config->dest_data_size;
600618
xfer_settings->direction = config->channel_direction;
@@ -644,7 +662,10 @@ static int dma_mcux_edma_configure(const struct device *dev, uint32_t channel,
644662
sizeof(DEV_CFG(dev)->tcdpool[channel][i]));
645663
}
646664

647-
dma_mcux_edma_configure_hardware(dev, channel, config);
665+
ret = dma_mcux_edma_configure_hardware(dev, channel, config);
666+
if (ret) {
667+
return ret;
668+
}
648669

649670
struct call_back *data = DEV_CHANNEL_DATA(dev, channel);
650671

@@ -675,6 +696,14 @@ static int dma_mcux_edma_start(const struct device *dev, uint32_t channel)
675696
#endif
676697
data->busy = true;
677698
EDMA_StartTransfer(DEV_EDMA_HANDLE(dev, channel));
699+
#if defined(CONFIG_DMA_MCUX_EDMA_V3) && \
700+
(!defined(FSL_FEATURE_SOC_DMAMUX_COUNT) || (FSL_FEATURE_SOC_DMAMUX_COUNT == 0))
701+
struct dma_mcux_channel_transfer_edma_settings *xfer_settings = &data->transfer_settings;
702+
703+
if (xfer_settings->transfer_type == kEDMA_MemoryToMemory) {
704+
EDMA_TriggerChannelStart(DEV_BASE(dev), channel);
705+
}
706+
#endif
678707
return 0;
679708
}
680709

@@ -704,6 +733,16 @@ static int dma_mcux_edma_suspend(const struct device *dev, uint32_t channel)
704733
{
705734
struct call_back *data = DEV_CHANNEL_DATA(dev, channel);
706735

736+
#if defined(CONFIG_DMA_MCUX_EDMA_V3) && \
737+
(!defined(FSL_FEATURE_SOC_DMAMUX_COUNT) || (FSL_FEATURE_SOC_DMAMUX_COUNT == 0))
738+
struct dma_mcux_channel_transfer_edma_settings *xfer_settings = &data->transfer_settings;
739+
740+
if (xfer_settings->transfer_type == kEDMA_MemoryToMemory) {
741+
/* can't suspend this transfer, effectively a not implemented function */
742+
return -ENOSYS;
743+
}
744+
#endif
745+
707746
if (!data->busy) {
708747
return -EINVAL;
709748
}

0 commit comments

Comments
 (0)