Skip to content

Commit 2609cfb

Browse files
bjarki-andreasenkartben
authored andcommitted
drivers: spi: nrfx spim: impl device deinit
Implement device deinit for nRF SPIM device driver. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
1 parent 61694b7 commit 2609cfb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/spi/spi_nrfx_spim.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,28 @@ static int spi_nrfx_init(const struct device *dev)
765765
#endif
766766
return pm_device_driver_init(dev, spim_nrfx_pm_action);
767767
}
768+
769+
static int spi_nrfx_deinit(const struct device *dev)
770+
{
771+
#if defined(CONFIG_PM_DEVICE)
772+
enum pm_device_state state;
773+
774+
/*
775+
* PM must have suspended the device before driver can
776+
* be deinitialized
777+
*/
778+
(void)pm_device_state_get(dev, &state);
779+
return state == PM_DEVICE_STATE_SUSPENDED ||
780+
state == PM_DEVICE_STATE_OFF ?
781+
0 : -EBUSY;
782+
#else
783+
/* PM suspend implementation does everything we need */
784+
spim_suspend(dev);
785+
#endif
786+
787+
return 0;
788+
}
789+
768790
/*
769791
* We use NODELABEL here because the nrfx API requires us to call
770792
* functions which are named according to SoC peripheral instance
@@ -870,8 +892,9 @@ static int spi_nrfx_init(const struct device *dev)
870892
!(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\
871893
"WAKE line must be configured as active high"); \
872894
PM_DEVICE_DT_DEFINE(SPIM(idx), spim_nrfx_pm_action); \
873-
SPI_DEVICE_DT_DEFINE(SPIM(idx), \
895+
SPI_DEVICE_DT_DEINIT_DEFINE(SPIM(idx), \
874896
spi_nrfx_init, \
897+
spi_nrfx_deinit, \
875898
PM_DEVICE_DT_GET(SPIM(idx)), \
876899
&spi_##idx##_data, \
877900
&spi_##idx##z_config, \

0 commit comments

Comments
 (0)