drivers: spi_mcux_lpspi: add support dma per instance
Currently, the driver imply understand that all instances will use dma when CONFIG_SPI_MCUX_LPSPI_DMA is set. There might be an instance doesn't need DMA, so instead of enforce spi_transceive API to use DMA, add more flexible to enable DMA only when required Signed-off-by: Dat Nguyen Duy <dat.nguyenduy@nxp.com>
This commit is contained in:
parent
7ce5a2e629
commit
910d417a92
1 changed files with 50 additions and 39 deletions
|
@ -472,7 +472,7 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
#endif
|
||||
|
||||
static int transceive(const struct device *dev,
|
||||
const struct spi_config *spi_cfg,
|
||||
|
@ -505,7 +505,6 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
#endif /*CONFIG_SPI_MCUX_LPSPI_DMA */
|
||||
|
||||
static int spi_mcux_transceive(const struct device *dev,
|
||||
const struct spi_config *spi_cfg,
|
||||
|
@ -513,10 +512,14 @@ static int spi_mcux_transceive(const struct device *dev,
|
|||
const struct spi_buf_set *rx_bufs)
|
||||
{
|
||||
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
|
||||
const struct spi_mcux_data *data = dev->data;
|
||||
|
||||
if (data->dma_rx.dma_dev && data->dma_tx.dma_dev) {
|
||||
return transceive_dma(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL, NULL);
|
||||
#else
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL, NULL);
|
||||
}
|
||||
#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
|
||||
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPI_ASYNC
|
||||
|
@ -559,6 +562,7 @@ static int spi_mcux_init(const struct device *dev)
|
|||
data->dev = dev;
|
||||
|
||||
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
|
||||
if (data->dma_tx.dma_dev && data->dma_rx.dma_dev) {
|
||||
if (!device_is_ready(data->dma_tx.dma_dev)) {
|
||||
LOG_ERR("%s device is not ready", data->dma_tx.dma_dev->name);
|
||||
return -ENODEV;
|
||||
|
@ -568,6 +572,7 @@ static int spi_mcux_init(const struct device *dev)
|
|||
LOG_ERR("%s device is not ready", data->dma_rx.dma_dev->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
|
||||
|
||||
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
|
||||
|
@ -590,6 +595,8 @@ static const struct spi_driver_api spi_mcux_driver_api = {
|
|||
|
||||
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
|
||||
#define SPI_DMA_CHANNELS(n) \
|
||||
IF_ENABLED(DT_INST_DMAS_HAS_NAME(n, tx), \
|
||||
( \
|
||||
.dma_tx = { \
|
||||
.dma_dev = DEVICE_DT_GET(DT_INST_DMAS_CTLR_BY_NAME(n, tx)), \
|
||||
.channel = \
|
||||
|
@ -603,6 +610,9 @@ static const struct spi_driver_api spi_mcux_driver_api = {
|
|||
.dma_slot = DT_INST_DMAS_CELL_BY_NAME(n, tx, source) \
|
||||
} \
|
||||
}, \
|
||||
)) \
|
||||
IF_ENABLED(DT_INST_DMAS_HAS_NAME(n, rx), \
|
||||
( \
|
||||
.dma_rx = { \
|
||||
.dma_dev = DEVICE_DT_GET(DT_INST_DMAS_CTLR_BY_NAME(n, rx)), \
|
||||
.channel = \
|
||||
|
@ -615,7 +625,8 @@ static const struct spi_driver_api spi_mcux_driver_api = {
|
|||
.block_count = 1, \
|
||||
.dma_slot = DT_INST_DMAS_CELL_BY_NAME(n, rx, source) \
|
||||
} \
|
||||
}
|
||||
} \
|
||||
))
|
||||
#else
|
||||
#define SPI_DMA_CHANNELS(n)
|
||||
#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue