32
32
33
33
struct dma_siwx91x_config {
34
34
UDMA0_Type * reg ; /* UDMA register base address */
35
- uint8_t channels ; /* UDMA channel count */
36
35
uint8_t irq_number ; /* IRQ number */
37
36
RSI_UDMA_DESC_T * sram_desc_addr ; /* SRAM Address for UDMA Descriptor Storage */
38
37
const struct device * clock_dev ;
@@ -41,6 +40,7 @@ struct dma_siwx91x_config {
41
40
};
42
41
43
42
struct dma_siwx91x_data {
43
+ struct dma_context dma_ctx ;
44
44
UDMA_Channel_Info * chan_info ;
45
45
dma_callback_t dma_callback ; /* User callback */
46
46
void * cb_data ; /* User callback data */
@@ -187,13 +187,12 @@ static int siwx91x_channel_config(const struct device *dev, RSI_UDMA_HANDLE_T ud
187
187
static int siwx91x_dma_configure (const struct device * dev , uint32_t channel ,
188
188
struct dma_config * config )
189
189
{
190
- const struct dma_siwx91x_config * cfg = dev -> config ;
191
190
struct dma_siwx91x_data * data = dev -> data ;
192
191
void * udma_handle = & data -> udma_handle ;
193
192
int status ;
194
193
195
194
/* Expecting a fixed channel number between 0-31 for dma0 and 0-11 for ulpdma */
196
- if (channel >= cfg -> channels ) {
195
+ if (channel >= data -> dma_ctx . dma_channels ) {
197
196
return - EINVAL ;
198
197
}
199
198
@@ -216,6 +215,8 @@ static int siwx91x_dma_configure(const struct device *dev, uint32_t channel,
216
215
data -> dma_callback = config -> dma_callback ;
217
216
data -> cb_data = config -> user_data ;
218
217
218
+ atomic_set_bit (data -> dma_ctx .atomic , channel );
219
+
219
220
return 0 ;
220
221
}
221
222
@@ -232,7 +233,7 @@ static int siwx91x_dma_reload(const struct device *dev, uint32_t channel, uint32
232
233
RSI_UDMA_DESC_T * udma_table = cfg -> sram_desc_addr ;
233
234
234
235
/* Expecting a fixed channel number between 0-31 for dma0 and 0-11 for ulpdma */
235
- if (channel >= cfg -> channels ) {
236
+ if (channel >= data -> dma_ctx . dma_channels ) {
236
237
return - EINVAL ;
237
238
}
238
239
@@ -283,7 +284,7 @@ static int siwx91x_dma_start(const struct device *dev, uint32_t channel)
283
284
void * udma_handle = & data -> udma_handle ;
284
285
285
286
/* Expecting a fixed channel number between 0-31 for dma0 and 0-11 for ulpdma */
286
- if (channel >= cfg -> channels ) {
287
+ if (channel >= data -> dma_ctx . dma_channels ) {
287
288
return - EINVAL ;
288
289
}
289
290
@@ -304,12 +305,11 @@ static int siwx91x_dma_start(const struct device *dev, uint32_t channel)
304
305
/* Function to stop a DMA transfer */
305
306
static int siwx91x_dma_stop (const struct device * dev , uint32_t channel )
306
307
{
307
- const struct dma_siwx91x_config * cfg = dev -> config ;
308
308
struct dma_siwx91x_data * data = dev -> data ;
309
309
void * udma_handle = & data -> udma_handle ;
310
310
311
311
/* Expecting a fixed channel number between 0-31 for dma0 and 0-11 for ulpdma */
312
- if (channel >= cfg -> channels ) {
312
+ if (channel >= data -> dma_ctx . dma_channels ) {
313
313
return - EINVAL ;
314
314
}
315
315
@@ -325,10 +325,15 @@ static int siwx91x_dma_get_status(const struct device *dev, uint32_t channel,
325
325
struct dma_status * stat )
326
326
{
327
327
const struct dma_siwx91x_config * cfg = dev -> config ;
328
+ struct dma_siwx91x_data * data = dev -> data ;
328
329
RSI_UDMA_DESC_T * udma_table = cfg -> sram_desc_addr ;
329
330
330
331
/* Expecting a fixed channel number between 0-31 for dma0 and 0-11 for ulpdma */
331
- if (channel >= cfg -> channels ) {
332
+ if (channel >= data -> dma_ctx .dma_channels ) {
333
+ return - EINVAL ;
334
+ }
335
+
336
+ if (!atomic_test_bit (data -> dma_ctx .atomic , channel )) {
332
337
return - EINVAL ;
333
338
}
334
339
@@ -399,7 +404,7 @@ static void siwx91x_dma_isr(const struct device *dev)
399
404
400
405
channel = find_lsb_set (cfg -> reg -> UDMA_DONE_STATUS_REG );
401
406
/* Identify the interrupt channel */
402
- if (!channel || channel > cfg -> channels ) {
407
+ if (!channel || channel > data -> dma_ctx . dma_channels ) {
403
408
goto out ;
404
409
}
405
410
/* find_lsb_set() returns 1 indexed value */
@@ -438,8 +443,12 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
438
443
};
439
444
440
445
#define SIWX91X_DMA_INIT (inst ) \
446
+ static ATOMIC_DEFINE(dma_channels_atomic_##inst, DT_INST_PROP(inst, dma_channels)); \
441
447
static UDMA_Channel_Info dma_channel_info_##inst[DT_INST_PROP(inst, dma_channels)]; \
442
448
static struct dma_siwx91x_data dma_data_##inst = { \
449
+ .dma_ctx.magic = DMA_MAGIC, \
450
+ .dma_ctx.dma_channels = DT_INST_PROP(inst, dma_channels), \
451
+ .dma_ctx.atomic = dma_channels_atomic_##inst, \
443
452
.chan_info = dma_channel_info_##inst, \
444
453
}; \
445
454
static void siwx91x_dma_irq_configure_##inst(void) \
@@ -452,7 +461,6 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
452
461
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(inst)), \
453
462
.clock_subsys = (clock_control_subsys_t)DT_INST_PHA(inst, clocks, clkid), \
454
463
.reg = (UDMA0_Type *)DT_INST_REG_ADDR(inst), \
455
- .channels = DT_INST_PROP(inst, dma_channels), \
456
464
.irq_number = DT_INST_PROP_BY_IDX(inst, interrupts, 0), \
457
465
.sram_desc_addr = (RSI_UDMA_DESC_T *)DT_INST_PROP(inst, silabs_sram_desc_addr), \
458
466
.irq_configure = siwx91x_dma_irq_configure_##inst, \
0 commit comments