@@ -553,56 +553,10 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
553553}
554554#else
555555#define lpspi_inst_has_dma (arg ) arg != arg
556+ #define transceive_dma (...) 0
556557#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
557558
558- static int transceive (const struct device * dev , const struct spi_config * spi_cfg ,
559- const struct spi_buf_set * tx_bufs , const struct spi_buf_set * rx_bufs ,
560- bool asynchronous , spi_callback_t cb , void * userdata )
561- {
562- struct spi_mcux_data * data = dev -> data ;
563- int ret ;
564-
565- spi_context_lock (& data -> ctx , asynchronous , cb , userdata , spi_cfg );
566-
567- ret = spi_mcux_configure (dev , spi_cfg );
568- if (ret ) {
569- goto out ;
570- }
571-
572- spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
573-
574- spi_context_cs_control (& data -> ctx , true);
575-
576- ret = spi_mcux_transfer_next_packet (dev );
577- if (ret ) {
578- goto out ;
579- }
580-
581- ret = spi_context_wait_for_completion (& data -> ctx );
582- out :
583- spi_context_release (& data -> ctx , ret );
584-
585- return ret ;
586- }
587-
588559#ifdef CONFIG_SPI_RTIO
589- static inline int transceive_rtio (const struct device * dev , const struct spi_config * spi_cfg ,
590- const struct spi_buf_set * tx_bufs ,
591- const struct spi_buf_set * rx_bufs )
592- {
593- struct spi_mcux_data * data = dev -> data ;
594- struct spi_rtio * rtio_ctx = data -> rtio_ctx ;
595- int ret ;
596-
597- spi_context_lock (& data -> ctx , false, NULL , NULL , spi_cfg );
598-
599- ret = spi_rtio_transceive (rtio_ctx , spi_cfg , tx_bufs , rx_bufs );
600-
601- spi_context_release (& data -> ctx , ret );
602-
603- return ret ;
604- }
605-
606560static inline void spi_mcux_iodev_prepare_start (const struct device * dev )
607561{
608562 struct spi_mcux_data * data = dev -> data ;
@@ -699,23 +653,81 @@ static void spi_mcux_iodev_submit(const struct device *dev, struct rtio_iodev_sq
699653 }
700654}
701655
656+ static inline int transceive_rtio (const struct device * dev , const struct spi_config * spi_cfg ,
657+ const struct spi_buf_set * tx_bufs ,
658+ const struct spi_buf_set * rx_bufs )
659+ {
660+ struct spi_mcux_data * data = dev -> data ;
661+ struct spi_rtio * rtio_ctx = data -> rtio_ctx ;
662+ int ret ;
663+
664+ spi_context_lock (& data -> ctx , false, NULL , NULL , spi_cfg );
665+
666+ ret = spi_rtio_transceive (rtio_ctx , spi_cfg , tx_bufs , rx_bufs );
667+
668+ spi_context_release (& data -> ctx , ret );
669+
670+ return ret ;
671+ }
672+ #else
673+ #define transceive_rtio (...) 0
702674#endif /* CONFIG_SPI_RTIO */
703675
676+ static int transceive (const struct device * dev , const struct spi_config * spi_cfg ,
677+ const struct spi_buf_set * tx_bufs , const struct spi_buf_set * rx_bufs ,
678+ bool asynchronous , spi_callback_t cb , void * userdata )
679+ {
680+ struct spi_mcux_data * data = dev -> data ;
681+ int ret ;
682+
683+ spi_context_lock (& data -> ctx , asynchronous , cb , userdata , spi_cfg );
684+
685+ ret = spi_mcux_configure (dev , spi_cfg );
686+ if (ret ) {
687+ goto out ;
688+ }
689+
690+ spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
691+
692+ spi_context_cs_control (& data -> ctx , true);
693+
694+ ret = spi_mcux_transfer_next_packet (dev );
695+ if (ret ) {
696+ goto out ;
697+ }
698+
699+ ret = spi_context_wait_for_completion (& data -> ctx );
700+ out :
701+ spi_context_release (& data -> ctx , ret );
702+
703+ return ret ;
704+ }
705+
704706static 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 )
707+ const struct spi_buf_set * tx_bufs , const struct spi_buf_set * rx_bufs ,
708+ spi_callback_t cb , void * userdata , bool async )
706709{
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 ;
710+ struct spi_mcux_data * data = dev -> data ;
712711
713712 if (lpspi_inst_has_dma (data )) {
714- return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
713+ if (async ) {
714+ spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
715+ }
716+ return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , async , cb , userdata );
715717 }
716- #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
717718
718- return transceive (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
719+ if (IS_ENABLED (CONFIG_SPI_RTIO )) {
720+ return transceive_rtio (dev , spi_cfg , tx_bufs , rx_bufs );
721+ }
722+
723+ return transceive (dev , spi_cfg , tx_bufs , rx_bufs , async , cb , userdata );
724+ }
725+
726+ static int spi_mcux_transceive_sync (const struct device * dev , const struct spi_config * spi_cfg ,
727+ const struct spi_buf_set * tx_bufs ,
728+ const struct spi_buf_set * rx_bufs )
729+ {
730+ return spi_mcux_transceive (dev , spi_cfg , tx_bufs , rx_bufs , NULL , NULL , false);
719731}
720732
721733#ifdef CONFIG_SPI_ASYNC
@@ -724,17 +736,7 @@ static int spi_mcux_transceive_async(const struct device *dev, const struct spi_
724736 const struct spi_buf_set * rx_bufs , spi_callback_t cb ,
725737 void * userdata )
726738{
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 */
739+ return spi_mcux_transceive (dev , spi_cfg , tx_bufs , rx_bufs , cb , userdata , true);
738740}
739741#endif /* CONFIG_SPI_ASYNC */
740742
@@ -748,7 +750,7 @@ static int spi_mcux_release(const struct device *dev, const struct spi_config *s
748750}
749751
750752static const struct spi_driver_api spi_mcux_driver_api = {
751- .transceive = spi_mcux_transceive ,
753+ .transceive = spi_mcux_transceive_sync ,
752754#ifdef CONFIG_SPI_ASYNC
753755 .transceive_async = spi_mcux_transceive_async ,
754756#endif
0 commit comments