@@ -517,6 +517,36 @@ static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent,
517517 (node_id)).devstate), \
518518 __VA_ARGS__)
519519
520+ /**
521+ * @brief Like DEVICE_INSTANCE() with SMBus specifics.
522+ *
523+ * @details Defines a device which implements the SMBus API. May
524+ * generate a custom device_state container struct and init_fn
525+ * wrapper when needed depending on SMBus @kconfig{CONFIG_SMBUS_STATS}.
526+ *
527+ * @param node_id The devicetree node identifier.
528+ * @param init_fn Name of the init function of the driver.
529+ * @param pm_device PM device resources reference
530+ * (NULL if device does not use PM).
531+ * @param data_ptr Pointer to the device's private data.
532+ * @param cfg_ptr The address to the structure containing the
533+ * configuration information for this instance of the driver.
534+ * @param level The initialization level. See SYS_INIT() for
535+ * details.
536+ * @param api_ptr Provides an initial pointer to the API function struct
537+ * used by the driver. Can be NULL.
538+ */
539+ #define SMBUS_DEVICE_INSTANCE (node_id , init_fn , pm_device , \
540+ data_ptr , cfg_ptr , level , api_ptr ) \
541+ Z_SMBUS_DEVICE_STATE_DEFINE(node_id, \
542+ Z_DEVICE_DT_DEV_NAME(node_id)); \
543+ Z_SMBUS_INIT_FN(Z_DEVICE_DT_DEV_NAME(node_id), init_fn) \
544+ DEVICE_INSTANCE_EXTERNAL_STATE(node_id, init_fn, pm_device, \
545+ data_ptr, cfg_ptr, level, api_ptr,\
546+ &(Z_DEVICE_STATE_NAME( \
547+ Z_DEVICE_DT_DEV_NAME \
548+ (node_id)).devstate))
549+
520550#else /* CONFIG_SMBUS_STATS */
521551
522552static inline void smbus_xfer_stats (const struct device * dev , uint8_t sent ,
@@ -534,6 +564,11 @@ static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent,
534564 data_ptr, cfg_ptr, level, prio, \
535565 api_ptr, __VA_ARGS__)
536566
567+ #define SMBUS_DEVICE_INSTANCE (node_id , init_fn , pm_device , \
568+ data_ptr , cfg_ptr , level , api_ptr ) \
569+ DEVICE_INSTANCE(node_id, init_fn, pm_device, data_ptr, cfg_ptr, \
570+ level, api_ptr)
571+
537572#endif /* CONFIG_SMBUS_STATS */
538573
539574/**
@@ -548,6 +583,16 @@ static inline void smbus_xfer_stats(const struct device *dev, uint8_t sent,
548583#define SMBUS_DEVICE_DT_INST_DEFINE (inst , ...) \
549584 SMBUS_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
550585
586+ /**
587+ * @brief Like SMBUS_DEVICE_INSTANCE() for an instance of a DT_DRV_COMPAT
588+ * compatible
589+ *
590+ * @param inst instance number. This is replaced by
591+ * <tt>DT_DRV_COMPAT(inst)</tt> in the call to SMBUS_DEVICE_INSTANCE().
592+ * @param ... other parameters as expected by SMBUS_DEVICE_INSTANCE().
593+ */
594+ #define SMBUS_DEVICE_INSTANCE_FROM_DT_INST (inst , ...) \
595+ SMBUS_DEVICE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
551596/**
552597 * @brief Configure operation of a SMBus host controller.
553598 *
0 commit comments