diff --git a/include/zephyr/drivers/spi.h b/include/zephyr/drivers/spi.h index 8e8cdb5a994..08a3f03137b 100644 --- a/include/zephyr/drivers/spi.h +++ b/include/zephyr/drivers/spi.h @@ -657,16 +657,16 @@ struct spi_device_state { } /** @endcond */ -#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm_device, \ - data_ptr, cfg_ptr, level, prio, \ - api_ptr, ...) \ +#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, \ + pm_device, data_ptr, cfg_ptr, \ + level, prio, api_ptr, ...) \ Z_SPI_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \ Z_SPI_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \ Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \ DEVICE_DT_NAME(node_id), \ &UTIL_CAT(Z_DEVICE_DT_DEV_ID(node_id), _init), \ - NULL, Z_DEVICE_DT_FLAGS(node_id), pm_device, \ - data_ptr, cfg_ptr, level, prio, \ + deinit_fn, Z_DEVICE_DT_FLAGS(node_id), \ + pm_device, data_ptr, cfg_ptr, level, prio, \ api_ptr, \ &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \ __VA_ARGS__) @@ -700,8 +700,49 @@ static inline void spi_transceive_stats(const struct device *dev, int error, * @name SPI DT Device Macros * @{ */ + /** - * @brief Like DEVICE_DT_DEFINE() with SPI specifics. + * @brief Like DEVICE_DT_DEINIT_DEFINE() with SPI specifics. + * + * @details Defines a device which implements the SPI API. May + * generate a custom device_state container struct and init_fn + * wrapper when needed depending on SPI @kconfig{CONFIG_SPI_STATS}. + * + * @param node_id The devicetree node identifier. + * @param init_fn Name of the init function of the driver. + * @param deinit_fn Name of the deinit function of the driver. + * @param pm PM device resources reference (NULL if device does not use PM). + * @param data Pointer to the device's private data. + * @param config The address to the structure containing the configuration + * information for this instance of the driver. + * @param level The initialization level. See SYS_INIT() for details. + * @param prio Priority within the selected initialization level. See SYS_INIT() + * for details. + * @param api Provides an initial pointer to the API function struct used by + * the driver. Can be NULL. + */ +#define SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, \ + config, level, prio, api, ...) \ + Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \ + Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \ + DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \ + Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \ + level, prio, api, \ + &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \ + __VA_ARGS__) + +/** @} */ + +#define SPI_STATS_RX_BYTES_INC(dev_) +#define SPI_STATS_TX_BYTES_INC(dev_) +#define SPI_STATS_TRANSFER_ERROR_INC(dev_) + +#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs) + +#endif /*CONFIG_SPI_STATS*/ + +/** + * @brief Like DEVICE_DT_DEINIT_DEFINE() without deinit function. * * @details Defines a device which implements the SPI API. May * generate a custom device_state container struct and init_fn @@ -719,26 +760,21 @@ static inline void spi_transceive_stats(const struct device *dev, int error, * @param api Provides an initial pointer to the API function struct used by * the driver. Can be NULL. */ -#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, \ - data, config, level, prio, \ - api, ...) \ - Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \ - Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \ - DEVICE_DT_NAME(node_id), init_fn, NULL, \ - Z_DEVICE_DT_FLAGS(node_id), pm, data, config, \ - level, prio, api, \ - &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \ - __VA_ARGS__) -/** @} */ - -#define SPI_STATS_RX_BYTES_INC(dev_) -#define SPI_STATS_TX_BYTES_INC(dev_) -#define SPI_STATS_TRANSFER_ERROR_INC(dev_) - -#define spi_transceive_stats(dev, error, tx_bufs, rx_bufs) - -#endif /*CONFIG_SPI_STATS*/ +#define SPI_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, \ + api, ...) \ + SPI_DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \ + level, prio, api, __VA_ARGS__) +/** + * @brief Like SPI_DEVICE_DT_DEINIT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT` + * compatible instead of a node identifier. + * + * @param inst Instance number. The `node_id` argument to SPI_DEVICE_DT_DEINIT_DEFINE() is + * set to `DT_DRV_INST(inst)`. + * @param ... Other parameters as expected by SPI_DEVICE_DT_DEFINE(). + */ +#define SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \ + SPI_DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) /** * @brief Like SPI_DEVICE_DT_DEFINE(), but uses an instance of a `DT_DRV_COMPAT`