@@ -657,16 +657,16 @@ struct spi_device_state {
657657 }
658658/** @endcond */
659659
660- #define SPI_DEVICE_DT_DEFINE (node_id , init_fn , pm_device , \
661- data_ptr , cfg_ptr , level , prio , \
662- api_ptr , ...) \
660+ #define SPI_DEVICE_DT_DEINIT_DEFINE (node_id , init_fn , deinit_fn , \
661+ pm_device , data_ptr , cfg_ptr , \
662+ level , prio , api_ptr , ...) \
663663 Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
664664 Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
665665 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
666666 DEVICE_DT_NAME(node_id), \
667667 &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \
668- NULL , Z_DEVICE_DT_FLAGS(node_id), pm_device, \
669- data_ptr, cfg_ptr, level, prio, \
668+ deinit_fn , Z_DEVICE_DT_FLAGS(node_id), \
669+ pm_device, data_ptr, cfg_ptr, level, prio, \
670670 api_ptr, \
671671 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
672672 __VA_ARGS__)
@@ -700,15 +700,17 @@ static inline void spi_transceive_stats(const struct device *dev, int error,
700700 * @name SPI DT Device Macros
701701 * @{
702702 */
703+
703704/**
704- * @brief Like DEVICE_DT_DEFINE () with SPI specifics.
705+ * @brief Like DEVICE_DT_DEINIT_DEFINE () with SPI specifics.
705706 *
706707 * @details Defines a device which implements the SPI API. May
707708 * generate a custom device_state container struct and init_fn
708709 * wrapper when needed depending on SPI @kconfig{CONFIG_SPI_STATS}.
709710 *
710711 * @param node_id The devicetree node identifier.
711712 * @param init_fn Name of the init function of the driver.
713+ * @param deinit_fn Name of the deinit function of the driver.
712714 * @param pm PM device resources reference (NULL if device does not use PM).
713715 * @param data Pointer to the device's private data.
714716 * @param config The address to the structure containing the configuration
@@ -719,16 +721,16 @@ static inline void spi_transceive_stats(const struct device *dev, int error,
719721 * @param api Provides an initial pointer to the API function struct used by
720722 * the driver. Can be NULL.
721723 */
722- #define SPI_DEVICE_DT_DEFINE (node_id , init_fn , pm , \
723- data , config , level , prio , \
724- api , ...) \
724+ #define SPI_DEVICE_DT_DEINIT_DEFINE (node_id , init_fn , deinit_fn , pm , data , \
725+ config , level , prio , api , ...) \
725726 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
726727 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
727- DEVICE_DT_NAME(node_id), init_fn, NULL, \
728+ DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
728729 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \
729730 level, prio, api, \
730731 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
731732 __VA_ARGS__)
733+
732734/** @} */
733735
734736#define SPI_STATS_RX_BYTES_INC (dev_ )
@@ -739,6 +741,40 @@ static inline void spi_transceive_stats(const struct device *dev, int error,
739741
740742#endif /*CONFIG_SPI_STATS*/
741743
744+ /**
745+ * @brief Like DEVICE_DT_DEINIT_DEFINE() without deinit function.
746+ *
747+ * @details Defines a device which implements the SPI API. May
748+ * generate a custom device_state container struct and init_fn
749+ * wrapper when needed depending on SPI @kconfig{CONFIG_SPI_STATS}.
750+ *
751+ * @param node_id The devicetree node identifier.
752+ * @param init_fn Name of the init function of the driver.
753+ * @param pm PM device resources reference (NULL if device does not use PM).
754+ * @param data Pointer to the device's private data.
755+ * @param config The address to the structure containing the configuration
756+ * information for this instance of the driver.
757+ * @param level The initialization level. See SYS_INIT() for details.
758+ * @param prio Priority within the selected initialization level. See SYS_INIT()
759+ * for details.
760+ * @param api Provides an initial pointer to the API function struct used by
761+ * the driver. Can be NULL.
762+ */
763+ #define SPI_DEVICE_DT_DEFINE (node_id , init_fn , pm , data , config , level , prio , \
764+ api , ...) \
765+ SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
766+ level, prio, api, __VA_ARGS__)
767+
768+ /**
769+ * @brief Like SPI_DEVICE_DT_DEINIT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT`
770+ * compatible instead of a node identifier.
771+ *
772+ * @param inst Instance number. The `node_id` argument to SPI_DEVICE_DT_DEINIT_DEFINE() is
773+ * set to `DT_DRV_INST(inst)`.
774+ * @param ... Other parameters as expected by SPI_DEVICE_DT_DEFINE().
775+ */
776+ #define SPI_DEVICE_DT_INST_DEINIT_DEFINE (inst , ...) \
777+ SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
742778
743779/**
744780 * @brief Like SPI_DEVICE_DT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT`
0 commit comments