@@ -144,6 +144,8 @@ typedef int16_t device_handle_t;
144
144
* device from a devicetree node, use DEVICE_DT_DEINIT_DEFINE() or
145
145
* DEVICE_DT_INST_DEINIT_DEFINE() instead.
146
146
*
147
+ * Note: deinit_fn will only be used if CONFIG_DEVICE_DEINIT_SUPPORT is enabled.
148
+ *
147
149
* @param dev_id A unique token which is used in the name of the global device
148
150
* structure as a C identifier.
149
151
* @param name A string name for the device, which will be stored in
@@ -214,6 +216,8 @@ typedef int16_t device_handle_t;
214
216
* @kconfig{CONFIG_LLEXT_EXPORT_DEVICES} is enabled). Before using the
215
217
* pointer, the referenced object should be checked using device_is_ready().
216
218
*
219
+ * Note: deinit_fn will only be used if CONFIG_DEVICE_DEINIT_SUPPORT is enabled.
220
+ *
217
221
* @param node_id The devicetree node identifier.
218
222
* @param init_fn Pointer to the device's initialization function, which will be
219
223
* run by the kernel during system initialization. Can be `NULL`.
@@ -494,8 +498,10 @@ typedef uint8_t device_flags_t;
494
498
struct device_ops {
495
499
/** Initialization function */
496
500
int (* init )(const struct device * dev );
501
+ #ifdef CONFIG_DEVICE_DEINIT_SUPPORT
497
502
/** De-initialization function */
498
503
int (* deinit )(const struct device * dev );
504
+ #endif /* CONFIG_DEVICE_DEINIT_SUPPORT */
499
505
};
500
506
501
507
/**
@@ -881,14 +887,17 @@ __syscall int device_init(const struct device *dev);
881
887
* acquired (e.g. pins, memory, clocks, DMA channels, etc.) and its status will
882
888
* be left as in its reset state.
883
889
*
890
+ * Note: this will be available if CONFIG_DEVICE_DEINIT_SUPPORT is enabled.
891
+ *
884
892
* @warning It is the responsibility of the caller to ensure that the device is
885
893
* ready to be de-initialized.
886
894
*
887
895
* @param dev device to be de-initialized.
888
896
*
889
897
* @retval 0 If successful
890
898
* @retval -EPERM If device has not been initialized.
891
- * @retval -ENOTSUP If device does not support de-initialization.
899
+ * @retval -ENOTSUP If device does not support de-initialization, or if the
900
+ * feature is not enabled (see CONFIG_DEVICE_DEINIT_SUPPORT)
892
901
* @retval -errno For any other errors.
893
902
*/
894
903
__syscall int device_deinit (const struct device * dev );
@@ -1132,6 +1141,19 @@ device_get_dt_nodelabels(const struct device *dev)
1132
1141
BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1133
1142
Z_STRINGIFY(name) " too long")
1134
1143
1144
+ /**
1145
+ * @brief Fill in the struct device_ops
1146
+ *
1147
+ * @param init_fn_ Initialization function
1148
+ * @param deinit_fn_ De-initialization function
1149
+ */
1150
+ #define Z_DEVICE_OPS (init_fn_ , deinit_fn_ ) \
1151
+ { \
1152
+ .init = (init_fn_), \
1153
+ IF_ENABLED(CONFIG_DEVICE_DEINIT_SUPPORT, \
1154
+ (.deinit = (deinit_fn_),)) \
1155
+ }
1156
+
1135
1157
/**
1136
1158
* @brief Initializer for @ref device.
1137
1159
*
@@ -1156,7 +1178,7 @@ device_get_dt_nodelabels(const struct device *dev)
1156
1178
.api = (api_), \
1157
1179
.state = (state_), \
1158
1180
.data = (data_), \
1159
- .ops = { .init = (init_fn_), .deinit = ( deinit_fn_) }, \
1181
+ .ops = Z_DEVICE_OPS (init_fn_, deinit_fn_), \
1160
1182
.flags = (flags_), \
1161
1183
IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) /**/ \
1162
1184
IF_ENABLED (CONFIG_PM_DEVICE , Z_DEVICE_INIT_PM_BASE (pm_ )) /**/ \
0 commit comments