@@ -147,6 +147,7 @@ static void spi_mcux_transfer_next_packet(const struct device *dev)
147
147
LOG_ERR ("Transfer could not start" );
148
148
spi_context_cs_control (& data -> ctx , false);
149
149
spi_context_complete (& data -> ctx , dev , - EIO );
150
+ pm_policy_device_power_lock_put (dev );
150
151
}
151
152
}
152
153
@@ -338,12 +339,14 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg,
338
339
data -> status_flags |= SPI_MCUX_FLEXCOMM_DMA_RX_DONE_FLAG ;
339
340
spi_context_cs_control (& data -> ctx , false);
340
341
spi_context_complete (& data -> ctx , spi_dev , 0 );
342
+ pm_policy_device_power_lock_put (dev );
341
343
} else {
342
344
LOG_ERR ("DMA callback channel %d is not valid." ,
343
345
channel );
344
346
data -> status_flags |= SPI_MCUX_FLEXCOMM_DMA_ERROR_FLAG ;
345
347
spi_context_cs_control (& data -> ctx , false);
346
348
spi_context_complete (& data -> ctx , spi_dev , - EIO );
349
+ pm_policy_device_power_lock_put (dev );
347
350
}
348
351
}
349
352
}
@@ -683,6 +686,10 @@ static int transceive_dma(const struct device *dev,
683
686
spi_context_update_rx (& data -> ctx , data -> word_size_bytes , data -> transfer_len );
684
687
spi_context_cs_control (& data -> ctx , false);
685
688
spi_context_complete (& data -> ctx , dev , 0 );
689
+ /* If asynchronous was true, set to false since transfer is done and we
690
+ * want to release the power lock below.
691
+ */
692
+ asynchronous = false;
686
693
} else {
687
694
/* Enable DMATX/RX. */
688
695
base -> FIFOCFG |= SPI_FIFOCFG_DMARX_MASK | SPI_FIFOCFG_DMATX_MASK ;
@@ -693,12 +700,21 @@ static int transceive_dma(const struct device *dev,
693
700
}
694
701
}
695
702
703
+ /* if asynchronous is true, spi_context_wait_for_completion() just returns 0
704
+ * and spi_context_release() is a noop
705
+ */
696
706
ret = spi_context_wait_for_completion (& data -> ctx );
697
707
698
708
out :
699
709
spi_context_release (& data -> ctx , ret );
700
710
701
- pm_policy_device_power_lock_put (dev );
711
+ if (!asynchronous || (ret != 0 )) {
712
+ /* Only release the power lock if synchronous, or if an error occurred.
713
+ * For asynchronous case, the power_lock is released in
714
+ * when the transfer is done in the dma completion callback
715
+ */
716
+ pm_policy_device_power_lock_put (dev );
717
+ }
702
718
703
719
return ret ;
704
720
}
0 commit comments