From e2852308e5df8a19c5181d065a98ee708e4df174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Thu, 10 Apr 2025 12:38:29 +0200 Subject: [PATCH] [nrf fromtree] drivers: spi: nrfx_spis: Fix spis120 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISR safe runtime PM can only be used for all instances except for spis120 which requires standard runtime PM. Added compilation guard against using CONFIG_PM_DEVICE_SYSTEM_MANAGED with spis120. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 8d6ab28ff772a1cb10b53b1db1902d9716edaa13) --- drivers/spi/spi_nrfx_spis.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi_nrfx_spis.c b/drivers/spi/spi_nrfx_spis.c index 049154f791d..1526109865c 100644 --- a/drivers/spi/spi_nrfx_spis.c +++ b/drivers/spi/spi_nrfx_spis.c @@ -24,6 +24,18 @@ LOG_MODULE_REGISTER(spi_nrfx_spis, CONFIG_SPI_LOG_LEVEL); #include #endif +#define SPIS_IS_FAST(idx) IS_EQ(idx, 120) + +#define NRFX_SPIS_IS_FAST(unused, prefix, id, _) SPIS_IS_FAST(prefix##id) + +#if NRFX_FOREACH_ENABLED(SPIS, NRFX_SPIS_IS_FAST, (+), (0), _) +/* If fast instances are used then system managed device PM cannot be used because + * it may call PM actions from locked context and fast SPIM PM actions can only be + * called from a thread context. + */ +BUILD_ASSERT(!IS_ENABLED(CONFIG_PM_DEVICE_SYSTEM_MANAGED)); +#endif + struct spi_nrfx_data { struct spi_context ctx; const struct device *dev; @@ -335,7 +347,7 @@ static void event_handler(const nrfx_spis_evt_t *p_event, void *p_context) spi_context_complete(&dev_data->ctx, dev_data->dev, p_event->rx_amount); - pm_device_runtime_put(dev_data->dev); + pm_device_runtime_put_async(dev_data->dev, K_NO_WAIT); } } @@ -457,7 +469,7 @@ static int spi_nrfx_init(const struct device *dev) * - Name-based HAL IRQ handlers, e.g. nrfx_spis_0_irq_handler */ -#define SPIS_NODE(idx) COND_CODE_1(IS_EQ(idx, 120), (spis##idx), (spi##idx)) +#define SPIS_NODE(idx) COND_CODE_1(SPIS_IS_FAST(idx), (spis##idx), (spi##idx)) #define SPIS(idx) DT_NODELABEL(SPIS_NODE(idx)) @@ -502,7 +514,8 @@ static int spi_nrfx_init(const struct device *dev) BUILD_ASSERT(!DT_NODE_HAS_PROP(SPIS(idx), wake_gpios) || \ !(DT_GPIO_FLAGS(SPIS(idx), wake_gpios) & GPIO_ACTIVE_LOW),\ "WAKE line must be configured as active high"); \ - PM_DEVICE_DT_DEFINE(SPIS(idx), spi_nrfx_pm_action, 1); \ + PM_DEVICE_DT_DEFINE(SPIS(idx), spi_nrfx_pm_action, \ + COND_CODE_1(SPIS_IS_FAST(idx), (0), (PM_DEVICE_ISR_SAFE))); \ SPI_DEVICE_DT_DEFINE(SPIS(idx), \ spi_nrfx_init, \ PM_DEVICE_DT_GET(SPIS(idx)), \