Skip to content

Commit 324d04e

Browse files
committed
spi_nxp_lpspi: Convert DMA version to native code
Convert the DMA-based LPSPI driver to native code. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 3e3d7c4 commit 324d04e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_dma.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static int spi_mcux_dma_tx_load(const struct device *dev, const uint8_t *buf, si
6464
stream->dma_cfg.channel_direction = MEMORY_TO_PERIPHERAL;
6565
}
6666

67-
/* Dest is always LPSPI tx fifo */
68-
blk_cfg->dest_address = LPSPI_GetTxRegisterAddress(base);
67+
blk_cfg->dest_address = (uint32_t) &(base->TDR);
6968

7069
return dma_config(stream->dma_dev, stream->channel, &stream->dma_cfg);
7170
}
@@ -87,7 +86,7 @@ static int spi_mcux_dma_rx_load(const struct device *dev, uint8_t *buf, size_t l
8786
blk_cfg->dest_address = (uint32_t)buf;
8887
}
8988

90-
blk_cfg->source_address = LPSPI_GetRxRegisterAddress(base);
89+
blk_cfg->source_address = (uint32_t) &(base->RDR);
9190

9291
return dma_config(stream->dma_dev, stream->channel, &stream->dma_cfg);
9392
}
@@ -172,8 +171,10 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg, uint32_t
172171
return;
173172
}
174173

175-
while ((IS_ENABLED(CONFIG_SOC_FAMILY_NXP_IMXRT) || IS_ENABLED(CONFIG_SOC_FAMILY_KINETIS)) &&
176-
(LPSPI_GetStatusFlags(base) & kLPSPI_ModuleBusyFlag)) {
174+
175+
while ((IS_ENABLED(CONFIG_SOC_FAMILY_NXP_IMXRT) ||
176+
IS_ENABLED(CONFIG_SOC_FAMILY_KINETIS)) &&
177+
(base->SR & LPSPI_SR_MBF_MASK)) {
177178
/* wait until module is idle */
178179
}
179180

@@ -190,11 +191,11 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg, uint32_t
190191
error:
191192
LOG_ERR("DMA callback error with channel %d err %d.", channel, status);
192193
done:
193-
LPSPI_DisableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
194+
base->DER &= ~(LPSPI_DER_TDDE_MASK | LPSPI_DER_RDDE_MASK);
194195
base->TCR &= ~LPSPI_TCR_CONT_MASK;
195196
lpspi_wait_tx_fifo_empty(spi_dev);
196197
spi_context_cs_control(ctx, false);
197-
LPSPI_FlushFifo(base, true, true);
198+
base->CR |= LPSPI_CR_RTF_MASK | LPSPI_CR_RRF_MASK;
198199
spi_context_complete(ctx, spi_dev, status);
199200
}
200201

@@ -227,9 +228,9 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
227228
goto out;
228229
}
229230

230-
LPSPI_FlushFifo(base, true, true);
231+
base->CR |= LPSPI_CR_RTF_MASK | LPSPI_CR_RRF_MASK;
231232

232-
LPSPI_EnableDMA(base, kLPSPI_TxDmaEnable | kLPSPI_RxDmaEnable);
233+
base->DER |= LPSPI_DER_TDDE_MASK | LPSPI_DER_RDDE_MASK;
233234

234235
ret = spi_context_wait_for_completion(ctx);
235236
out:

0 commit comments

Comments
 (0)