Skip to content

Commit d6c80e5

Browse files
drivers: spi: nrfx_spim: impl spi_context_cs_get_all/put_all
Implement calling spi_context_cs_get_all() and spi_context_cs_put_all() in line with pm resume/suspend. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 906d5ef commit d6c80e5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/spi/spi_nrfx_spim.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
154154

155155
if (deactivate_cs) {
156156
spi_context_cs_control(&dev_data->ctx, false);
157+
pm_device_runtime_put_async(dev, K_NO_WAIT);
157158
}
158159

159160
if (NRF_SPIM_IS_320MHZ_SPIM(reg) && !(dev_data->ctx.config->operation & SPI_HOLD_ON_CS)) {
@@ -163,8 +164,6 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
163164
if (!IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
164165
release_clock(dev);
165166
}
166-
167-
pm_device_runtime_put_async(dev, K_NO_WAIT);
168167
}
169168

170169
static inline uint32_t get_nrf_spim_frequency(uint32_t frequency)
@@ -398,7 +397,7 @@ static void finish_transaction(const struct device *dev, int error)
398397
spi_context_complete(ctx, dev, error);
399398
dev_data->busy = false;
400399

401-
finalize_spi_transaction(dev, true);
400+
finalize_spi_transaction(dev, (dev_data->ctx.config->operation & SPI_HOLD_ON_CS) > 0);
402401
}
403402

404403
static void transfer_next_chunk(const struct device *dev)
@@ -657,12 +656,17 @@ static DEVICE_API(spi, spi_nrfx_driver_api) = {
657656
static int spim_resume(const struct device *dev)
658657
{
659658
const struct spi_nrfx_config *dev_config = dev->config;
659+
struct spi_nrfx_data *dev_data = dev->data;
660660

661661
(void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT);
662662
/* nrfx_spim_init() will be called at configuration before
663663
* the next transfer.
664664
*/
665665

666+
if (spi_context_cs_get_all(&dev_data->ctx)) {
667+
return -EAGAIN;
668+
}
669+
666670
#ifdef CONFIG_SOC_NRF54H20_GPD
667671
nrf_gpd_retain_pins_set(dev_config->pcfg, false);
668672
#endif
@@ -684,6 +688,8 @@ static void spim_suspend(const struct device *dev)
684688
release_clock(dev);
685689
}
686690

691+
spi_context_cs_put_all(&dev_data->ctx);
692+
687693
#ifdef CONFIG_SOC_NRF54H20_GPD
688694
nrf_gpd_retain_pins_set(dev_config->pcfg, true);
689695
#endif

0 commit comments

Comments
 (0)