scripts: kconfig: add dt_compat_on_bus() helper
This can be used from Kconfig to detect if any enabled nodes of a
compatible are on a bus. This can be useful if a compatible might
appear on multiple buses, to enable them by default from application
code without having to change prj.conf settings depending on what's in
the devicetree.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py
index 475c713..f571a8f 100644
--- a/scripts/kconfig/kconfigfunctions.py
+++ b/scripts/kconfig/kconfigfunctions.py
@@ -317,6 +317,21 @@
return "n"
+def dt_compat_on_bus(kconf, _, compat, bus):
+ """
+ This function takes a 'compat' and returns "y" if we find an "enabled"
+ compatible node in the EDT which is on bus 'bus'. It returns "n" otherwise.
+ """
+ if doc_mode or edt is None:
+ return "n"
+
+ for node in edt.compat2enabled[compat]:
+ if node.on_bus is not None and node.on_bus == bus:
+ return "y"
+
+ return "n"
+
+
def dt_nodelabel_has_compat(kconf, _, label, compat):
"""
This function takes a 'label' and returns "y" if an "enabled" node with
@@ -349,6 +364,7 @@
functions = {
"dt_compat_enabled": (dt_compat_enabled, 1, 1),
+ "dt_compat_on_bus": (dt_compat_on_bus, 2, 2),
"dt_chosen_label": (dt_chosen_label, 1, 1),
"dt_chosen_enabled": (dt_chosen_enabled, 1, 1),
"dt_nodelabel_enabled": (dt_nodelabel_enabled, 1, 1),