Skip to content

Commit e21bf37

Browse files
decsnynashif
authored andcommitted
drivers: spi_mcux_lpspi: Minor RTIO cleanup
Add closing comment for #ifdef and remove unnecessary indentation of an else block. Also move the transcieve_rtio function to be near the other rtio functions. And move function prototypes to top of file. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 5d081c9 commit e21bf37

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

drivers/spi/spi_mcux_lpspi.c

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ struct spi_mcux_data {
8585
#endif
8686
};
8787

88+
#ifdef CONFIG_SPI_RTIO
89+
static void spi_mcux_iodev_complete(const struct device *dev, int status);
90+
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
91+
const struct spi_buf_set *tx_bufs,
92+
const struct spi_buf_set *rx_bufs);
93+
#endif
94+
8895
static int spi_mcux_transfer_next_packet(const struct device *dev)
8996
{
9097
/* const struct spi_mcux_config *config = dev->config; */
@@ -161,10 +168,6 @@ static void spi_mcux_isr(const struct device *dev)
161168
#endif
162169
}
163170

164-
#ifdef CONFIG_SPI_RTIO
165-
static void spi_mcux_iodev_complete(const struct device *dev, int status);
166-
#endif
167-
168171
static void spi_mcux_master_transfer_callback(LPSPI_Type *base, lpspi_master_handle_t *handle,
169172
status_t status, void *userData)
170173
{
@@ -557,27 +560,6 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
557560
#define lpspi_inst_has_dma(arg) arg != arg
558561
#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
559562

560-
#ifdef CONFIG_SPI_RTIO
561-
562-
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
563-
const struct spi_buf_set *tx_bufs,
564-
const struct spi_buf_set *rx_bufs)
565-
{
566-
struct spi_mcux_data *data = dev->data;
567-
struct spi_rtio *rtio_ctx = data->rtio_ctx;
568-
int ret;
569-
570-
spi_context_lock(&data->ctx, false, NULL, NULL, spi_cfg);
571-
572-
ret = spi_rtio_transceive(rtio_ctx, spi_cfg, tx_bufs, rx_bufs);
573-
574-
spi_context_release(&data->ctx, ret);
575-
576-
return ret;
577-
}
578-
579-
#endif /* CONFIG_SPI_RTIO */
580-
581563
static int transceive(const struct device *dev, const struct spi_config *spi_cfg,
582564
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs,
583565
bool asynchronous, spi_callback_t cb, void *userdata)
@@ -614,7 +596,6 @@ static int spi_mcux_transceive(const struct device *dev, const struct spi_config
614596
#ifdef CONFIG_SPI_RTIO
615597
return transceive_rtio(dev, spi_cfg, tx_bufs, rx_bufs);
616598
#endif /* CONFIG_SPI_RTIO */
617-
618599
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
619600
const struct spi_mcux_data *data = dev->data;
620601

@@ -656,6 +637,22 @@ static int spi_mcux_release(const struct device *dev, const struct spi_config *s
656637
}
657638

658639
#ifdef CONFIG_SPI_RTIO
640+
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
641+
const struct spi_buf_set *tx_bufs,
642+
const struct spi_buf_set *rx_bufs)
643+
{
644+
struct spi_mcux_data *data = dev->data;
645+
struct spi_rtio *rtio_ctx = data->rtio_ctx;
646+
int ret;
647+
648+
spi_context_lock(&data->ctx, false, NULL, NULL, spi_cfg);
649+
650+
ret = spi_rtio_transceive(rtio_ctx, spi_cfg, tx_bufs, rx_bufs);
651+
652+
spi_context_release(&data->ctx, ret);
653+
654+
return ret;
655+
}
659656

660657
static inline void spi_mcux_iodev_prepare_start(const struct device *dev)
661658
{
@@ -741,18 +738,18 @@ static void spi_mcux_iodev_complete(const struct device *dev, int status)
741738
if (!status && rtio_ctx->txn_curr->sqe.flags & RTIO_SQE_TRANSACTION) {
742739
rtio_ctx->txn_curr = rtio_txn_next(rtio_ctx->txn_curr);
743740
spi_mcux_iodev_start(dev);
744-
} else {
745-
/** De-assert CS-line to space from next transaction */
746-
spi_context_cs_control(&data->ctx, false);
741+
return;
742+
}
747743

748-
if (spi_rtio_complete(rtio_ctx, status)) {
749-
spi_mcux_iodev_prepare_start(dev);
750-
spi_mcux_iodev_start(dev);
751-
}
744+
/** De-assert CS-line to space from next transaction */
745+
spi_context_cs_control(&data->ctx, false);
746+
747+
if (spi_rtio_complete(rtio_ctx, status)) {
748+
spi_mcux_iodev_prepare_start(dev);
749+
spi_mcux_iodev_start(dev);
752750
}
753751
}
754-
755-
#endif
752+
#endif /* CONFIG_SPI_RTIO */
756753

757754
#if defined(CONFIG_SPI_MCUX_LPSPI_DMA)
758755
static int lpspi_dma_dev_ready(const struct device *dma_dev)

0 commit comments

Comments
 (0)