28
28
29
29
LOG_MODULE_REGISTER (si91x_dma , CONFIG_DMA_LOG_LEVEL );
30
30
31
- enum {
31
+ enum dma_xfer_dir {
32
32
TRANSFER_MEM_TO_MEM ,
33
33
TRANSFER_TO_OR_FROM_PER ,
34
+ TRANSFER_DIR_INVALID = -1 ,
34
35
};
35
36
36
37
struct dma_siwx91x_channel_info {
37
38
dma_callback_t dma_callback ; /* User callback */
38
39
void * cb_data ; /* User callback data */
39
40
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 */
40
42
};
41
43
42
44
struct dma_siwx91x_config {
@@ -58,7 +60,7 @@ struct dma_siwx91x_data {
58
60
*/
59
61
};
60
62
61
- static int siwx91x_transfer_direction (uint32_t dir )
63
+ static enum dma_xfer_dir siwx91x_transfer_direction (uint32_t dir )
62
64
{
63
65
if (dir == MEMORY_TO_MEMORY ) {
64
66
return TRANSFER_MEM_TO_MEM ;
@@ -68,7 +70,7 @@ static int siwx91x_transfer_direction(uint32_t dir)
68
70
return TRANSFER_TO_OR_FROM_PER ;
69
71
}
70
72
71
- return - EINVAL ;
73
+ return TRANSFER_DIR_INVALID ;
72
74
}
73
75
74
76
static 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
206
208
struct dma_siwx91x_data * data = dev -> data ;
207
209
RSI_UDMA_DESC_T * sg_desc_base_addr = NULL ;
208
210
uint8_t transfer_type ;
209
- int ret ;
211
+ enum dma_xfer_dir xfer_dir ;
210
212
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 ) {
213
215
return - EINVAL ;
214
216
}
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
+ }
216
222
217
223
if (!siwx91x_is_data_width_valid (config -> source_data_size ) ||
218
224
!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
239
245
*/
240
246
data -> chan_info [channel ].Cnt = config -> block_count ;
241
247
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
+
242
254
RSI_UDMA_InterruptClear (udma_handle , channel );
243
255
RSI_UDMA_ErrorStatusClear (udma_handle );
244
256
@@ -275,9 +287,11 @@ static int siwx91x_direct_chan_config(const struct device *dev, RSI_UDMA_HANDLE_
275
287
.transferType = UDMA_MODE_BASIC ,
276
288
};
277
289
RSI_UDMA_CHA_CFG_T channel_config = {};
290
+ enum dma_xfer_dir xfer_dir ;
278
291
int status ;
279
292
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 ) {
281
295
return - EINVAL ;
282
296
}
283
297
@@ -339,6 +353,11 @@ static int siwx91x_direct_chan_config(const struct device *dev, RSI_UDMA_HANDLE_
339
353
return - EIO ;
340
354
}
341
355
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
+
342
361
return 0 ;
343
362
}
344
363
@@ -450,7 +469,6 @@ static int siwx91x_dma_reload(const struct device *dev, uint32_t channel, uint32
450
469
static int siwx91x_dma_start (const struct device * dev , uint32_t channel )
451
470
{
452
471
const struct dma_siwx91x_config * cfg = dev -> config ;
453
- RSI_UDMA_DESC_T * udma_table = cfg -> sram_desc_addr ;
454
472
struct dma_siwx91x_data * data = dev -> data ;
455
473
void * udma_handle = & data -> udma_handle ;
456
474
@@ -464,8 +482,7 @@ static int siwx91x_dma_start(const struct device *dev, uint32_t channel)
464
482
}
465
483
466
484
/* 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 ) {
469
486
/* Apply software trigger to start transfer */
470
487
sys_set_bit ((mem_addr_t )& cfg -> reg -> CHNL_SW_REQUEST , channel );
471
488
}
0 commit comments