Skip to content

Commit 6f98f25

Browse files
Alain Volmatbroonie
authored andcommitted
spi: stm32: use dma_get_slave_caps prior to configuring dma channel
First check the dma channel capabilities (max burst) before configuring the dma channel. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Link: https://msgid.link/r/20231218155721.359198-2-alain.volmat@foss.st.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 15009a1 commit 6f98f25

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/spi/spi-stm32.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,15 +1157,19 @@ static void stm32_spi_dma_rx_cb(void *data)
11571157
* stm32_spi_dma_config - configure dma slave channel depending on current
11581158
* transfer bits_per_word.
11591159
* @spi: pointer to the spi controller data structure
1160+
* @dma_chan: pointer to the DMA channel
11601161
* @dma_conf: pointer to the dma_slave_config structure
11611162
* @dir: direction of the dma transfer
11621163
*/
11631164
static void stm32_spi_dma_config(struct stm32_spi *spi,
1165+
struct dma_chan *dma_chan,
11641166
struct dma_slave_config *dma_conf,
11651167
enum dma_transfer_direction dir)
11661168
{
11671169
enum dma_slave_buswidth buswidth;
1170+
struct dma_slave_caps caps;
11681171
u32 maxburst;
1172+
int ret;
11691173

11701174
if (spi->cur_bpw <= 8)
11711175
buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
@@ -1184,6 +1188,11 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
11841188
maxburst = 1;
11851189
}
11861190

1191+
/* Get the DMA channel caps, and adjust maxburst if possible */
1192+
ret = dma_get_slave_caps(dma_chan, &caps);
1193+
if (!ret)
1194+
maxburst = min(maxburst, caps.max_burst);
1195+
11871196
memset(dma_conf, 0, sizeof(struct dma_slave_config));
11881197
dma_conf->direction = dir;
11891198
if (dma_conf->direction == DMA_DEV_TO_MEM) { /* RX */
@@ -1366,7 +1375,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
13661375

13671376
rx_dma_desc = NULL;
13681377
if (spi->rx_buf && spi->dma_rx) {
1369-
stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM);
1378+
stm32_spi_dma_config(spi, spi->dma_rx, &rx_dma_conf, DMA_DEV_TO_MEM);
13701379
dmaengine_slave_config(spi->dma_rx, &rx_dma_conf);
13711380

13721381
/* Enable Rx DMA request */
@@ -1382,7 +1391,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
13821391

13831392
tx_dma_desc = NULL;
13841393
if (spi->tx_buf && spi->dma_tx) {
1385-
stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV);
1394+
stm32_spi_dma_config(spi, spi->dma_tx, &tx_dma_conf, DMA_MEM_TO_DEV);
13861395
dmaengine_slave_config(spi->dma_tx, &tx_dma_conf);
13871396

13881397
tx_dma_desc = dmaengine_prep_slave_sg(

0 commit comments

Comments
 (0)