@@ -91,9 +91,6 @@ struct spi_mcux_data {
9191static int spi_mcux_transfer_next_packet (const struct device * dev );
9292#ifdef CONFIG_SPI_RTIO
9393static void spi_mcux_iodev_complete (const struct device * dev , int status );
94- static inline int transceive_rtio (const struct device * dev , const struct spi_config * spi_cfg ,
95- const struct spi_buf_set * tx_bufs ,
96- const struct spi_buf_set * rx_bufs );
9794#endif
9895
9996static void spi_mcux_isr (const struct device * dev )
@@ -588,52 +585,6 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
588585 return ret ;
589586}
590587
591- static int spi_mcux_transceive (const struct device * dev , const struct spi_config * spi_cfg ,
592- const struct spi_buf_set * tx_bufs , const struct spi_buf_set * rx_bufs )
593- {
594- #ifdef CONFIG_SPI_RTIO
595- return transceive_rtio (dev , spi_cfg , tx_bufs , rx_bufs );
596- #endif /* CONFIG_SPI_RTIO */
597- #ifdef CONFIG_SPI_MCUX_LPSPI_DMA
598- const struct spi_mcux_data * data = dev -> data ;
599-
600- if (lpspi_inst_has_dma (data )) {
601- return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
602- }
603- #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
604-
605- return transceive (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
606- }
607-
608- #ifdef CONFIG_SPI_ASYNC
609- static int spi_mcux_transceive_async (const struct device * dev , const struct spi_config * spi_cfg ,
610- const struct spi_buf_set * tx_bufs ,
611- const struct spi_buf_set * rx_bufs , spi_callback_t cb ,
612- void * userdata )
613- {
614- #ifdef CONFIG_SPI_MCUX_LPSPI_DMA
615- struct spi_mcux_data * data = dev -> data ;
616-
617- if (lpspi_inst_has_dma (data )) {
618- spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
619- }
620-
621- return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , true, cb , userdata );
622- #else
623- return transceive (dev , spi_cfg , tx_bufs , rx_bufs , true, cb , userdata );
624- #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
625- }
626- #endif /* CONFIG_SPI_ASYNC */
627-
628- static int spi_mcux_release (const struct device * dev , const struct spi_config * spi_cfg )
629- {
630- struct spi_mcux_data * data = dev -> data ;
631-
632- spi_context_unlock_unconditionally (& data -> ctx );
633-
634- return 0 ;
635- }
636-
637588#ifdef CONFIG_SPI_RTIO
638589static inline int transceive_rtio (const struct device * dev , const struct spi_config * spi_cfg ,
639590 const struct spi_buf_set * tx_bufs ,
@@ -717,17 +668,6 @@ static void spi_mcux_iodev_start(const struct device *dev)
717668 }
718669}
719670
720- static void spi_mcux_iodev_submit (const struct device * dev , struct rtio_iodev_sqe * iodev_sqe )
721- {
722- struct spi_mcux_data * data = dev -> data ;
723- struct spi_rtio * rtio_ctx = data -> rtio_ctx ;
724-
725- if (spi_rtio_submit (rtio_ctx , iodev_sqe )) {
726- spi_mcux_iodev_prepare_start (dev );
727- spi_mcux_iodev_start (dev );
728- }
729- }
730-
731671static void spi_mcux_iodev_complete (const struct device * dev , int status )
732672{
733673 struct spi_mcux_data * data = dev -> data ;
@@ -747,8 +687,77 @@ static void spi_mcux_iodev_complete(const struct device *dev, int status)
747687 spi_mcux_iodev_start (dev );
748688 }
749689}
690+
691+ static void spi_mcux_iodev_submit (const struct device * dev , struct rtio_iodev_sqe * iodev_sqe )
692+ {
693+ struct spi_mcux_data * data = dev -> data ;
694+ struct spi_rtio * rtio_ctx = data -> rtio_ctx ;
695+
696+ if (spi_rtio_submit (rtio_ctx , iodev_sqe )) {
697+ spi_mcux_iodev_prepare_start (dev );
698+ spi_mcux_iodev_start (dev );
699+ }
700+ }
701+
750702#endif /* CONFIG_SPI_RTIO */
751703
704+ static int spi_mcux_transceive (const struct device * dev , const struct spi_config * spi_cfg ,
705+ const struct spi_buf_set * tx_bufs , const struct spi_buf_set * rx_bufs )
706+ {
707+ #ifdef CONFIG_SPI_RTIO
708+ return transceive_rtio (dev , spi_cfg , tx_bufs , rx_bufs );
709+ #endif /* CONFIG_SPI_RTIO */
710+ #ifdef CONFIG_SPI_MCUX_LPSPI_DMA
711+ const struct spi_mcux_data * data = dev -> data ;
712+
713+ if (lpspi_inst_has_dma (data )) {
714+ return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
715+ }
716+ #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
717+
718+ return transceive (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
719+ }
720+
721+ #ifdef CONFIG_SPI_ASYNC
722+ static int spi_mcux_transceive_async (const struct device * dev , const struct spi_config * spi_cfg ,
723+ const struct spi_buf_set * tx_bufs ,
724+ const struct spi_buf_set * rx_bufs , spi_callback_t cb ,
725+ void * userdata )
726+ {
727+ #ifdef CONFIG_SPI_MCUX_LPSPI_DMA
728+ struct spi_mcux_data * data = dev -> data ;
729+
730+ if (lpspi_inst_has_dma (data )) {
731+ spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
732+ }
733+
734+ return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , true, cb , userdata );
735+ #else
736+ return transceive (dev , spi_cfg , tx_bufs , rx_bufs , true, cb , userdata );
737+ #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
738+ }
739+ #endif /* CONFIG_SPI_ASYNC */
740+
741+ static int spi_mcux_release (const struct device * dev , const struct spi_config * spi_cfg )
742+ {
743+ struct spi_mcux_data * data = dev -> data ;
744+
745+ spi_context_unlock_unconditionally (& data -> ctx );
746+
747+ return 0 ;
748+ }
749+
750+ static const struct spi_driver_api spi_mcux_driver_api = {
751+ .transceive = spi_mcux_transceive ,
752+ #ifdef CONFIG_SPI_ASYNC
753+ .transceive_async = spi_mcux_transceive_async ,
754+ #endif
755+ #ifdef CONFIG_SPI_RTIO
756+ .iodev_submit = spi_mcux_iodev_submit ,
757+ #endif
758+ .release = spi_mcux_release ,
759+ };
760+
752761#if defined(CONFIG_SPI_MCUX_LPSPI_DMA )
753762static int lpspi_dma_dev_ready (const struct device * dma_dev )
754763{
@@ -806,17 +815,6 @@ static int spi_mcux_init(const struct device *dev)
806815 return 0 ;
807816}
808817
809- static const struct spi_driver_api spi_mcux_driver_api = {
810- .transceive = spi_mcux_transceive ,
811- #ifdef CONFIG_SPI_ASYNC
812- .transceive_async = spi_mcux_transceive_async ,
813- #endif
814- #ifdef CONFIG_SPI_RTIO
815- .iodev_submit = spi_mcux_iodev_submit ,
816- #endif
817- .release = spi_mcux_release ,
818- };
819-
820818#define SPI_MCUX_RTIO_DEFINE (n ) \
821819 SPI_RTIO_DEFINE(spi_mcux_rtio_##n, CONFIG_SPI_MCUX_RTIO_SQ_SIZE, \
822820 CONFIG_SPI_MCUX_RTIO_SQ_SIZE)
0 commit comments