2828
2929LOG_MODULE_REGISTER (si91x_dma , CONFIG_DMA_LOG_LEVEL );
3030
31- enum {
31+ enum dma_xfer_dir {
3232 TRANSFER_MEM_TO_MEM ,
3333 TRANSFER_TO_OR_FROM_PER ,
34+ TRANSFER_DIR_INVALID = -1 ,
3435};
3536
3637struct dma_siwx91x_channel_info {
3738 dma_callback_t dma_callback ; /* User callback */
3839 void * cb_data ; /* User callback data */
3940 RSI_UDMA_DESC_T * sg_desc_addr_info ; /* Scatter-Gather table start address */
41+ enum dma_xfer_dir xfer_direction ; /* mem<->mem ot per<->mem */
4042};
4143
4244struct dma_siwx91x_config {
@@ -58,7 +60,7 @@ struct dma_siwx91x_data {
5860 */
5961};
6062
61- static int siwx91x_transfer_direction (uint32_t dir )
63+ static enum dma_xfer_dir siwx91x_transfer_direction (uint32_t dir )
6264{
6365 if (dir == MEMORY_TO_MEMORY ) {
6466 return TRANSFER_MEM_TO_MEM ;
@@ -68,7 +70,7 @@ static int siwx91x_transfer_direction(uint32_t dir)
6870 return TRANSFER_TO_OR_FROM_PER ;
6971 }
7072
71- return - EINVAL ;
73+ return TRANSFER_DIR_INVALID ;
7274}
7375
7476static bool siwx91x_is_data_width_valid (uint32_t data_width )
@@ -206,13 +208,17 @@ static int siwx91x_sg_chan_config(const struct device *dev, RSI_UDMA_HANDLE_T ud
206208 struct dma_siwx91x_data * data = dev -> data ;
207209 RSI_UDMA_DESC_T * sg_desc_base_addr = NULL ;
208210 uint8_t transfer_type ;
209- int ret ;
211+ enum dma_xfer_dir xfer_dir ;
210212
211- ret = siwx91x_transfer_direction (config -> channel_direction );
212- if (ret < 0 ) {
213+ xfer_dir = siwx91x_transfer_direction (config -> channel_direction );
214+ if (xfer_dir == TRANSFER_DIR_INVALID ) {
213215 return - EINVAL ;
214216 }
215- transfer_type = ret ? UDMA_MODE_PER_SCATTER_GATHER : UDMA_MODE_MEM_SCATTER_GATHER ;
217+ if (xfer_dir == TRANSFER_TO_OR_FROM_PER ) {
218+ transfer_type = UDMA_MODE_PER_SCATTER_GATHER ;
219+ } else {
220+ transfer_type = UDMA_MODE_MEM_SCATTER_GATHER ;
221+ }
216222
217223 if (!siwx91x_is_data_width_valid (config -> source_data_size ) ||
218224 !siwx91x_is_data_width_valid (config -> dest_data_size )) {
@@ -239,6 +245,12 @@ static int siwx91x_sg_chan_config(const struct device *dev, RSI_UDMA_HANDLE_T ud
239245 */
240246 data -> chan_info [channel ].Cnt = config -> block_count ;
241247 data -> zephyr_channel_info [channel ].sg_desc_addr_info = sg_desc_base_addr ;
248+
249+ /* Store the transfer direction. This is used to trigger SW request for
250+ * Memory to Memory transfers.
251+ */
252+ data -> zephyr_channel_info [channel ].xfer_direction = xfer_dir ;
253+
242254 RSI_UDMA_InterruptClear (udma_handle , channel );
243255 RSI_UDMA_ErrorStatusClear (udma_handle );
244256
@@ -275,9 +287,11 @@ static int siwx91x_direct_chan_config(const struct device *dev, RSI_UDMA_HANDLE_
275287 .transferType = UDMA_MODE_BASIC ,
276288 };
277289 RSI_UDMA_CHA_CFG_T channel_config = {};
290+ enum dma_xfer_dir xfer_dir ;
278291 int status ;
279292
280- if (siwx91x_transfer_direction (config -> channel_direction ) < 0 ) {
293+ xfer_dir = siwx91x_transfer_direction (config -> channel_direction );
294+ if (xfer_dir == TRANSFER_DIR_INVALID ) {
281295 return - EINVAL ;
282296 }
283297
@@ -339,6 +353,11 @@ static int siwx91x_direct_chan_config(const struct device *dev, RSI_UDMA_HANDLE_
339353 return - EIO ;
340354 }
341355
356+ /* Store the transfer direction. This is used to trigger SW request for
357+ * Memory to Memory transfers.
358+ */
359+ data -> zephyr_channel_info [channel ].xfer_direction = xfer_dir ;
360+
342361 return 0 ;
343362}
344363
@@ -450,7 +469,6 @@ static int siwx91x_dma_reload(const struct device *dev, uint32_t channel, uint32
450469static int siwx91x_dma_start (const struct device * dev , uint32_t channel )
451470{
452471 const struct dma_siwx91x_config * cfg = dev -> config ;
453- RSI_UDMA_DESC_T * udma_table = cfg -> sram_desc_addr ;
454472 struct dma_siwx91x_data * data = dev -> data ;
455473 void * udma_handle = & data -> udma_handle ;
456474
@@ -464,8 +482,7 @@ static int siwx91x_dma_start(const struct device *dev, uint32_t channel)
464482 }
465483
466484 /* Check if the transfer type is memory-memory */
467- if (udma_table [channel ].vsUDMAChaConfigData1 .srcInc != UDMA_SRC_INC_NONE &&
468- udma_table [channel ].vsUDMAChaConfigData1 .dstInc != UDMA_DST_INC_NONE ) {
485+ if (data -> zephyr_channel_info [channel ].xfer_direction == TRANSFER_MEM_TO_MEM ) {
469486 /* Apply software trigger to start transfer */
470487 sys_set_bit ((mem_addr_t )& cfg -> reg -> CHNL_SW_REQUEST , channel );
471488 }
0 commit comments