Skip to content

Commit d6c57ac

Browse files
committed
gpdma test
1 parent 05ff70c commit d6c57ac

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

drivers/spi/spi_silabs_siwx91x_gspi.c

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ LOG_MODULE_REGISTER(spi_siwx91x_gspi, CONFIG_SPI_LOG_LEVEL);
2323

2424
#define GSPI_MAX_BAUDRATE_FOR_DYNAMIC_CLOCK 110000000
2525
#define GSPI_MAX_BAUDRATE_FOR_POS_EDGE_SAMPLE 40000000
26+
#ifdef CONFIG_DMA_SILABS_SIWX91X_GPDMA
27+
#define GSPI_DMA_MAX_DESCRIPTOR_TRANSFER_SIZE 4092
28+
#define gpdma_buf_is_aligned(buf, len, alignment) ((((uint32_t)(buf)) % (alignment) == 0) && ((len) % (alignment) == 0))
29+
#else
2630
#define GSPI_DMA_MAX_DESCRIPTOR_TRANSFER_SIZE 1024
31+
#endif
2732

2833
/* Warning for unsupported configurations */
2934
#if defined(CONFIG_SPI_ASYNC) && !defined(CONFIG_SPI_SILABS_SIWX91X_GSPI_DMA)
@@ -37,14 +42,17 @@ struct gspi_siwx91x_dma_channel {
3742
#ifdef CONFIG_SPI_SILABS_SIWX91X_GSPI_DMA
3843
struct dma_block_config dma_descriptors[CONFIG_SPI_SILABS_SIWX91X_GSPI_DMA_MAX_BLOCKS];
3944
#endif
45+
#ifdef CONFIG_DMA_SILABS_SIWX91X_GPDMA
46+
uint8_t dma_slot;
47+
#endif
4048
};
4149

4250
struct gspi_siwx91x_config {
4351
GSPI0_Type *reg;
4452
const struct device *clock_dev;
4553
clock_control_subsys_t clock_subsys;
4654
const struct pinctrl_dev_config *pcfg;
47-
uint8_t mosi_overrun;
55+
__aligned(32) uint32_t mosi_overrun;
4856
};
4957

5058
struct gspi_siwx91x_data {
@@ -55,7 +63,7 @@ struct gspi_siwx91x_data {
5563

5664
#ifdef CONFIG_SPI_SILABS_SIWX91X_GSPI_DMA
5765
/* Placeholder buffer for unused RX data */
58-
static volatile uint8_t empty_buffer;
66+
static __aligned(32) volatile uint32_t empty_buffer;
5967
#endif
6068

6169
static bool spi_siwx91x_is_dma_enabled_instance(const struct device *dev)
@@ -178,9 +186,10 @@ static int gspi_siwx91x_config(const struct device *dev, const struct spi_config
178186
return -EAGAIN;
179187
}
180188
}
181-
189+
#ifdef CONFIG_SPI_ASYNC
182190
data->ctx.callback = cb;
183191
data->ctx.callback_data = userdata;
192+
#endif
184193
#endif
185194
data->ctx.config = spi_cfg;
186195

@@ -216,13 +225,17 @@ static int gspi_siwx91x_dma_config(const struct device *dev,
216225
{
217226
struct dma_config cfg = {
218227
.channel_direction = is_tx ? MEMORY_TO_PERIPHERAL : PERIPHERAL_TO_MEMORY,
228+
.channel_priority = 1,
219229
.complete_callback_en = 0,
220230
.source_data_size = dfs,
221231
.dest_data_size = dfs,
222-
.source_burst_length = dfs,
223-
.dest_burst_length = dfs,
232+
.source_burst_length = 1,
233+
.dest_burst_length = 1,
224234
.block_count = block_count,
225235
.head_block = channel->dma_descriptors,
236+
#ifdef CONFIG_DMA_SILABS_SIWX91X_GPDMA
237+
.dma_slot = channel->dma_slot,
238+
#endif
226239
.dma_callback = !is_tx ? &gspi_siwx91x_dma_rx_callback : NULL,
227240
.user_data = (void *)dev,
228241
};
@@ -263,8 +276,13 @@ static uint32_t gspi_siwx91x_fill_desc(const struct gspi_siwx91x_config *cfg,
263276
/* Setup max transfer according to requested transaction size.
264277
* Will top if bigger than the maximum transfer size.
265278
*/
279+
#ifdef CONFIG_DMA_SILABS_SIWX91X_GPDMA
280+
new_blk_cfg->block_size =
281+
MIN(requested_transaction_size, GSPI_DMA_MAX_DESCRIPTOR_TRANSFER_SIZE);
282+
#else
266283
new_blk_cfg->block_size =
267284
MIN(requested_transaction_size, GSPI_DMA_MAX_DESCRIPTOR_TRANSFER_SIZE * dfs);
285+
#endif
268286
return new_blk_cfg->block_size;
269287
}
270288

@@ -407,7 +425,10 @@ static int gspi_siwx91x_transceive_dma(const struct device *dev, const struct sp
407425
}
408426

409427
/* Reset the Rx and Tx FIFO register */
410-
cfg->reg->GSPI_FIFO_THRLD = 0;
428+
cfg->reg->GSPI_FIFO_THRLD_b.RFIFO_RESET = 1;
429+
cfg->reg->GSPI_FIFO_THRLD_b.WFIFO_RESET = 1;
430+
cfg->reg->GSPI_FIFO_THRLD_b.RFIFO_RESET = 0;
431+
cfg->reg->GSPI_FIFO_THRLD_b.WFIFO_RESET = 0;
411432

412433
ret = gspi_siwx91x_prepare_dma_transaction(dev, padded_transaction_size);
413434
if (ret) {
@@ -416,12 +437,12 @@ static int gspi_siwx91x_transceive_dma(const struct device *dev, const struct sp
416437

417438
spi_context_cs_control(ctx, true);
418439

419-
ret = dma_start(dma_dev, data->dma_rx.chan_nb);
440+
ret = dma_start(dma_dev, data->dma_tx.chan_nb);
420441
if (ret) {
421442
return ret;
422443
}
423444

424-
ret = dma_start(dma_dev, data->dma_tx.chan_nb);
445+
ret = dma_start(dma_dev, data->dma_rx.chan_nb);
425446
if (ret) {
426447
return ret;
427448
}
@@ -629,12 +650,20 @@ static DEVICE_API(spi, gspi_siwx91x_driver_api) = {
629650
};
630651

631652
#ifdef CONFIG_SPI_SILABS_SIWX91X_GSPI_DMA
653+
#ifdef CONFIG_DMA_SILABS_SIWX91X_GPDMA
632654
#define SPI_SILABS_SIWX91X_GSPI_DMA_CHANNEL_INIT(index, dir) \
633655
.dma_##dir = { \
634656
.chan_nb = DT_INST_DMAS_CELL_BY_NAME(index, dir, channel), \
635657
.dma_dev = DEVICE_DT_GET(DT_INST_DMAS_CTLR_BY_NAME(index, dir)), \
658+
.dma_slot = DT_INST_DMAS_CELL_BY_NAME(index, dir, slot), \
636659
},
637-
660+
#else
661+
#define SPI_SILABS_SIWX91X_GSPI_DMA_CHANNEL_INIT(index, dir) \
662+
.dma_##dir = { \
663+
.chan_nb = DT_INST_DMAS_CELL_BY_NAME(index, dir, channel), \
664+
.dma_dev = DEVICE_DT_GET(DT_INST_DMAS_CTLR_BY_NAME(index, dir)), \
665+
},
666+
#endif
638667
#define SPI_SILABS_SIWX91X_GSPI_DMA_CHANNEL(index, dir) \
639668
COND_CODE_1(DT_INST_NODE_HAS_PROP(index, dmas), \
640669
(SPI_SILABS_SIWX91X_GSPI_DMA_CHANNEL_INIT(index, dir)), ())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2024 Silicon Laboratories, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_DMA_LOOP_TRANSFER_CHANNEL_NR=0
5+
CONFIG_DMA_LOOP_TRANSFER_SIZE=4095

tests/drivers/dma/loop_transfer/boards/siwx917_rb4338a.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
&dma0 {
6+
&gpdma0 {
77
status = "okay";
88
};
99

10-
tst_dma0: &dma0 { };
10+
tst_dma0: &gpdma0 { };
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CONFIG_DMA_SG_CHANNEL_NR=7
2-
CONFIG_DMA_SG_XFER_SIZE=4096
2+
CONFIG_DMA_SG_XFER_SIZE=4092

tests/drivers/dma/scatter_gather/boards/siwx917_rb4338a.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66
/ {
77
aliases {
8-
dma0 = &dma0;
8+
dma0 = &gpdma0;
99
};
1010
};
11-
&dma0 {
11+
&gpdma0 {
1212
status = "okay";
1313
};

tests/drivers/spi/spi_loopback/boards/siwx917_rb4338a.overlay

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pinctrl-0 = <&spi0_default>;
2222
pinctrl-names = "default";
2323

24-
dmas = <&dma0 11>, <&dma0 10>;
24+
dmas = <&gpdma0 0 11>, <&gpdma0 1 10>;
2525
dma-names = "tx", "rx";
2626

2727
slow@0 {
@@ -36,6 +36,6 @@
3636
};
3737
};
3838

39-
&dma0 {
39+
&gpdma0 {
4040
status = "okay";
4141
};

0 commit comments

Comments
 (0)