Skip to content

Commit 937a44a

Browse files
bjarki-andreasenkartben
authored andcommitted
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 <bjarki.andreasen@nordicsemi.no>
1 parent acbed8a commit 937a44a

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
@@ -154,7 +154,12 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
154154
void *reg = dev_config->spim.p_reg;
155155

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

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

171174
static inline uint32_t get_nrf_spim_frequency(uint32_t frequency)
@@ -403,7 +406,7 @@ static void finish_transaction(const struct device *dev, int error)
403406
spi_context_complete(ctx, dev, error);
404407
dev_data->busy = false;
405408

406-
finalize_spi_transaction(dev, true);
409+
finalize_spi_transaction(dev, (dev_data->ctx.config->operation & SPI_HOLD_ON_CS) > 0);
407410
}
408411

409412
static void transfer_next_chunk(const struct device *dev)

0 commit comments

Comments
 (0)