diff --git a/doc/build/kconfig/preprocessor-functions.rst b/doc/build/kconfig/preprocessor-functions.rst index e3ed5f40636..ab742996340 100644 --- a/doc/build/kconfig/preprocessor-functions.rst +++ b/doc/build/kconfig/preprocessor-functions.rst @@ -42,6 +42,7 @@ while the ``*_hex`` version returns a hexadecimal value starting with ``0x``. $(dt_compat_any_has_prop,,[,]) $(dt_compat_any_on_bus,,) $(dt_compat_enabled,) + $(dt_compat_enabled_num,) $(dt_compat_on_bus,,) $(dt_gpio_hogs_enabled) $(dt_has_compat,) diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py index 4b42ce30cef..ed237687aca 100644 --- a/scripts/kconfig/kconfigfunctions.py +++ b/scripts/kconfig/kconfigfunctions.py @@ -771,6 +771,17 @@ def dt_compat_enabled(kconf, _, compat): return "y" if compat in edt.compat2okay else "n" +def dt_compat_enabled_num(kconf, _, compat): + """ + This function takes a 'compat' and the returns number of status "okay" + compatible nodes in the EDT. + """ + if doc_mode or edt is None: + return "0" + + return str(len(edt.compat2okay[compat])) + + def dt_compat_on_bus(kconf, _, compat, bus): """ This function takes a 'compat' and returns "y" if we find an enabled @@ -1074,6 +1085,7 @@ def inc_dec(kconf, name, *args): functions = { "dt_has_compat": (dt_has_compat, 1, 1), "dt_compat_enabled": (dt_compat_enabled, 1, 1), + "dt_compat_enabled_num": (dt_compat_enabled_num, 1, 1), "dt_compat_on_bus": (dt_compat_on_bus, 2, 2), "dt_compat_any_has_prop": (dt_compat_any_has_prop, 2, 3), "dt_compat_any_not_has_prop": (dt_compat_any_not_has_prop, 2, 2),