@@ -73,6 +73,15 @@ static bool shim_nrf_twis_is_resumed(const struct device *dev)
73
73
(void )pm_device_state_get (dev , & state );
74
74
return state == PM_DEVICE_STATE_ACTIVE ;
75
75
}
76
+
77
+ static bool shim_nrf_twis_is_suspended (const struct device * dev )
78
+ {
79
+ enum pm_device_state state ;
80
+
81
+ (void )pm_device_state_get (dev , & state );
82
+ return state == PM_DEVICE_STATE_SUSPENDED ||
83
+ state == PM_DEVICE_STATE_OFF ;
84
+ }
76
85
#else
77
86
static bool shim_nrf_twis_is_resumed (const struct device * dev )
78
87
{
@@ -199,7 +208,7 @@ static int shim_nrf_twis_pm_action_cb(const struct device *dev,
199
208
200
209
#if CONFIG_PM_DEVICE
201
210
case PM_DEVICE_ACTION_SUSPEND :
202
- shim_nrf_twis_disable ();
211
+ shim_nrf_twis_disable (dev );
203
212
break ;
204
213
#endif
205
214
@@ -283,6 +292,35 @@ static int shim_nrf_twis_init(const struct device *dev)
283
292
return pm_device_driver_init (dev , shim_nrf_twis_pm_action_cb );
284
293
}
285
294
295
+ static int shim_nrf_twis_deinit (const struct device * dev )
296
+ {
297
+ const struct shim_nrf_twis_config * dev_config = dev -> config ;
298
+ struct shim_nrf_twis_data * dev_data = dev -> data ;
299
+
300
+ if (dev_data -> target_config != NULL ) {
301
+ LOG_ERR ("target registered" );
302
+ return - EPERM ;
303
+ }
304
+
305
+ #if CONFIG_PM_DEVICE
306
+ /*
307
+ * PM must have suspended the device before driver can
308
+ * be deinitialized
309
+ */
310
+ if (!shim_nrf_twis_is_suspended (dev )) {
311
+ LOG_ERR ("device active" );
312
+ return - EBUSY ;
313
+ }
314
+ #else
315
+ /* Suspend device */
316
+ shim_nrf_twis_disable (dev );
317
+ #endif
318
+
319
+ /* Uninit device hardware */
320
+ nrfx_twis_uninit (& dev_config -> twis );
321
+ return 0 ;
322
+ }
323
+
286
324
#define SHIM_NRF_TWIS_NAME (id , name ) \
287
325
_CONCAT_4(shim_nrf_twis_, name, _, id)
288
326
@@ -323,9 +361,10 @@ static int shim_nrf_twis_init(const struct device *dev)
323
361
shim_nrf_twis_pm_action_cb, \
324
362
); \
325
363
\
326
- DEVICE_DT_DEFINE( \
364
+ DEVICE_DT_DEINIT_DEFINE( \
327
365
SHIM_NRF_TWIS_NODE(id), \
328
366
shim_nrf_twis_init, \
367
+ shim_nrf_twis_deinit, \
329
368
PM_DEVICE_DT_GET(SHIM_NRF_TWIS_NODE(id)), \
330
369
&SHIM_NRF_TWIS_NAME(id, data), \
331
370
&SHIM_NRF_TWIS_NAME(id, config), \
0 commit comments