Skip to content

Commit c29e54c

Browse files
drivers: spi: nrfx_spim: prevent self suspend until spi_release()
In case the SPI transaction has SPI_HOLD_ON_CS set, we need to keep SPI resumed until spi_release() is called. This is required as we now need to keep the CS GPIO port resumed until transaction is complete. Suspending CS GPIO is not allowed from ISR in some cases (H20 fast GPIO instance) so we have to defer CS GPIO suspend to some thread context (put_async or spi_release()). Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 532f189 commit c29e54c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/spi/spi_nrfx_spim.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
153153
void *reg = dev_config->spim.p_reg;
154154

155155
if (deactivate_cs) {
156+
/*
157+
* We may suspend SPI only if we don't have to keep CS asserted, as we
158+
* need to keep the CS GPIO port resumed until spi_release() in this case.
159+
*/
156160
spi_context_cs_control(&dev_data->ctx, false);
161+
pm_device_runtime_put_async(dev, K_NO_WAIT);
157162
}
158163

159164
if (NRF_SPIM_IS_320MHZ_SPIM(reg) && !(dev_data->ctx.config->operation & SPI_HOLD_ON_CS)) {
@@ -163,8 +168,6 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
163168
if (!IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
164169
release_clock(dev);
165170
}
166-
167-
pm_device_runtime_put_async(dev, K_NO_WAIT);
168171
}
169172

170173
static inline uint32_t get_nrf_spim_frequency(uint32_t frequency)
@@ -402,7 +405,7 @@ static void finish_transaction(const struct device *dev, int error)
402405
spi_context_complete(ctx, dev, error);
403406
dev_data->busy = false;
404407

405-
finalize_spi_transaction(dev, true);
408+
finalize_spi_transaction(dev, (dev_data->ctx.config->operation & SPI_HOLD_ON_CS) > 0);
406409
}
407410

408411
static void transfer_next_chunk(const struct device *dev)

0 commit comments

Comments
 (0)