diff --git a/include/zephyr/device.h b/include/zephyr/device.h index cd282c3f0de421..2862c0befd38b4 100644 --- a/include/zephyr/device.h +++ b/include/zephyr/device.h @@ -1008,10 +1008,11 @@ device_get_dt_nodelabels(const struct device *dev) * @param api_ Reference to device API ops. * @param state_ Reference to device state. * @param deps_ Reference to device dependencies. + * @param node_id_ Devicetree node identifier * @param dev_id_ Device identifier token, as passed to Z_DEVICE_BASE_DEFINE */ -#define Z_DEVICE_INIT(name_, pm_, data_, config_, api_, state_, deps_, \ - dev_id_) \ +#define Z_DEVICE_INIT(name_, pm_, data_, config_, api_, state_, deps_, node_id_, \ + dev_id_) \ { \ .name = name_, \ .config = (config_), \ @@ -1021,7 +1022,9 @@ device_get_dt_nodelabels(const struct device *dev) IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) /**/ \ IF_ENABLED(CONFIG_PM_DEVICE, ({ .pm_base = (pm_),},)) /**/ \ IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \ - (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET(dev_id_),)) \ + (IF_ENABLED(DT_NODE_EXISTS(node_id_), \ + (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \ + dev_id_),)))) \ } /** @@ -1056,7 +1059,7 @@ device_get_dt_nodelabels(const struct device *dev) STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \ device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \ Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \ - Z_DEVICE_INIT(name, pm, data, config, api, state, deps, dev_id) + Z_DEVICE_INIT(name, pm, data, config, api, state, deps, node_id, dev_id) /* deprecated device initialization levels */ #define Z_DEVICE_LEVEL_DEPRECATED_EARLY \ @@ -1142,7 +1145,8 @@ device_get_dt_nodelabels(const struct device *dev) (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \ \ IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \ - (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);)) \ + (IF_ENABLED(DT_NODE_EXISTS(node_id), \ + (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\ \ Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \ prio, api, state, Z_DEVICE_DEPS_NAME(dev_id)); \