Skip to content

Commit 08175f8

Browse files
henrikbrixandersendanieldegrasse
authored andcommitted
scripts: kconfig: functions: add dt_compat_enabled_num function
Add dt_compat_enabled_num Kconfig helper function for counting the number of compatible nodes with status okay. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
1 parent 76f107b commit 08175f8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/build/kconfig/preprocessor-functions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ while the ``*_hex`` version returns a hexadecimal value starting with ``0x``.
4242
$(dt_compat_any_has_prop,<compatible string>,<prop>[,<value>])
4343
$(dt_compat_any_on_bus,<compatible string>,<prop>)
4444
$(dt_compat_enabled,<compatible string>)
45+
$(dt_compat_enabled_num,<compatible string>)
4546
$(dt_compat_on_bus,<compatible string>,<bus>)
4647
$(dt_gpio_hogs_enabled)
4748
$(dt_has_compat,<compatible string>)

scripts/kconfig/kconfigfunctions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,17 @@ def dt_compat_enabled(kconf, _, compat):
771771
return "y" if compat in edt.compat2okay else "n"
772772

773773

774+
def dt_compat_enabled_num(kconf, _, compat):
775+
"""
776+
This function takes a 'compat' and the returns number of status "okay"
777+
compatible nodes in the EDT.
778+
"""
779+
if doc_mode or edt is None:
780+
return "0"
781+
782+
return str(len(edt.compat2okay[compat]))
783+
784+
774785
def dt_compat_on_bus(kconf, _, compat, bus):
775786
"""
776787
This function takes a 'compat' and returns "y" if we find an enabled
@@ -1074,6 +1085,7 @@ def inc_dec(kconf, name, *args):
10741085
functions = {
10751086
"dt_has_compat": (dt_has_compat, 1, 1),
10761087
"dt_compat_enabled": (dt_compat_enabled, 1, 1),
1088+
"dt_compat_enabled_num": (dt_compat_enabled_num, 1, 1),
10771089
"dt_compat_on_bus": (dt_compat_on_bus, 2, 2),
10781090
"dt_compat_any_has_prop": (dt_compat_any_has_prop, 2, 3),
10791091
"dt_compat_any_not_has_prop": (dt_compat_any_not_has_prop, 2, 2),

0 commit comments

Comments
 (0)