@@ -272,7 +272,10 @@ static int spi_mcux_configure(const struct device *dev, const struct spi_config
272
272
}
273
273
274
274
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
275
- static int spi_mcux_dma_rxtx_load (const struct device * dev , size_t * dma_size );
275
+ static bool lpspi_inst_has_dma (const struct spi_mcux_data * data )
276
+ {
277
+ return (data -> dma_tx .dma_dev && data -> dma_rx .dma_dev );
278
+ }
276
279
277
280
/* This function is executed in the interrupt context */
278
281
static void spi_mcux_dma_callback (const struct device * dev , void * arg , uint32_t channel , int status )
@@ -550,7 +553,9 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
550
553
551
554
return ret ;
552
555
}
553
- #endif
556
+ #else
557
+ #define lpspi_inst_has_dma (arg ) arg != arg
558
+ #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
554
559
555
560
#ifdef CONFIG_SPI_RTIO
556
561
@@ -613,7 +618,7 @@ static int spi_mcux_transceive(const struct device *dev, const struct spi_config
613
618
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
614
619
const struct spi_mcux_data * data = dev -> data ;
615
620
616
- if (data -> dma_rx . dma_dev && data -> dma_tx . dma_dev ) {
621
+ if (lpspi_inst_has_dma ( data ) ) {
617
622
return transceive_dma (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
618
623
}
619
624
#endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
@@ -630,7 +635,7 @@ static int spi_mcux_transceive_async(const struct device *dev, const struct spi_
630
635
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
631
636
struct spi_mcux_data * data = dev -> data ;
632
637
633
- if (data -> dma_rx . dma_dev && data -> dma_tx . dma_dev ) {
638
+ if (lpspi_inst_has_dma ( data ) ) {
634
639
spi_context_buffers_setup (& data -> ctx , tx_bufs , rx_bufs , 1 );
635
640
}
636
641
@@ -749,29 +754,42 @@ static void spi_mcux_iodev_complete(const struct device *dev, int status)
749
754
750
755
#endif
751
756
757
+ #if defined(CONFIG_SPI_MCUX_LPSPI_DMA )
758
+ static int lpspi_dma_dev_ready (const struct device * dma_dev )
759
+ {
760
+ if (!device_is_ready (dma_dev )) {
761
+ LOG_ERR ("%s device is not ready" , dma_dev -> name );
762
+ return - ENODEV ;
763
+ }
764
+
765
+ return 0 ;
766
+ }
767
+
768
+ static int lpspi_dma_devs_ready (struct spi_mcux_data * data )
769
+ {
770
+ return lpspi_dma_dev_ready (data -> dma_tx .dma_dev ) |
771
+ lpspi_dma_dev_ready (data -> dma_rx .dma_dev );
772
+ }
773
+ #else
774
+ #define lpspi_dma_devs_ready (...) 0
775
+ #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
776
+
752
777
static int spi_mcux_init (const struct device * dev )
753
778
{
754
779
const struct spi_mcux_config * config = dev -> config ;
755
780
struct spi_mcux_data * data = dev -> data ;
756
- int err ;
781
+ int err = 0 ;
757
782
758
783
DEVICE_MMIO_NAMED_MAP (dev , reg_base , K_MEM_CACHE_NONE | K_MEM_DIRECT_MAP );
759
784
760
785
data -> dev = dev ;
761
786
762
- #ifdef CONFIG_SPI_MCUX_LPSPI_DMA
763
- if (data -> dma_tx .dma_dev && data -> dma_rx .dma_dev ) {
764
- if (!device_is_ready (data -> dma_tx .dma_dev )) {
765
- LOG_ERR ("%s device is not ready" , data -> dma_tx .dma_dev -> name );
766
- return - ENODEV ;
767
- }
768
-
769
- if (!device_is_ready (data -> dma_rx .dma_dev )) {
770
- LOG_ERR ("%s device is not ready" , data -> dma_rx .dma_dev -> name );
771
- return - ENODEV ;
772
- }
787
+ if (IS_ENABLED (CONFIG_SPI_MCUX_LPSPI_DMA ) && lpspi_inst_has_dma (data )) {
788
+ err = lpspi_dma_devs_ready (data );
789
+ }
790
+ if (err < 0 ) {
791
+ return err ;
773
792
}
774
- #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */
775
793
776
794
err = spi_context_cs_configure_all (& data -> ctx );
777
795
if (err < 0 ) {
0 commit comments