Skip to content

Commit e73c363

Browse files
MaureenHelmmbolivar-nordic
authored andcommitted
scripts: edtlib: gen_defines: Add model name macros based on compat
Follow up to 5b5aa6e adding model name and existence macros for all compatibles of a node that match an entry in vendor prefixes. Signed-off-by: Maureen Helm <maureen.helm@intel.com>
1 parent a7c801f commit e73c363

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/build/dts/macros.bnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ node-macro =/ %s"DT_N" path-id %s"_PARTITION_ID" DIGIT
5757
node-macro =/ %s"DT_N" path-id %s"_COMPAT_MATCHES_" dt-name
5858
node-macro =/ %s"DT_N" path-id %s"_COMPAT_VENDOR_IDX_" DIGIT "_EXISTS"
5959
node-macro =/ %s"DT_N" path-id %s"_COMPAT_VENDOR_IDX_" DIGIT
60+
node-macro =/ %s"DT_N" path-id %s"_COMPAT_MODEL_IDX_" DIGIT "_EXISTS"
61+
node-macro =/ %s"DT_N" path-id %s"_COMPAT_MODEL_IDX_" DIGIT
6062
; Every non-root node gets one of these macros, which expands to the node
6163
; identifier for that node's parent in the devicetree.
6264
node-macro =/ %s"DT_N" path-id %s"_PARENT"

scripts/dts/gen_defines.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ def write_compatibles(node):
519519
out_dt_define(f"{node.z_path_id}_COMPAT_VENDOR_IDX_{i}",
520520
quote_str(node.edt.compat2vendor[compat]))
521521

522+
if node.edt.compat2model[compat]:
523+
out_dt_define(f"{node.z_path_id}_COMPAT_MODEL_IDX_{i}_EXISTS", 1)
524+
out_dt_define(f"{node.z_path_id}_COMPAT_MODEL_IDX_{i}",
525+
quote_str(node.edt.compat2model[compat]))
526+
522527
def write_children(node):
523528
# Writes helper macros for dealing with node's children.
524529

scripts/dts/python-devicetree/src/devicetree/edtlib.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class EDT:
110110
A collections.defaultdict that maps each 'compatible' string that appears
111111
on some Node to a vendor name parsed from vendor_prefixes.
112112
113+
compat2model:
114+
A collections.defaultdict that maps each 'compatible' string that appears
115+
on some Node to a model name parsed from that compatible.
116+
113117
label2node:
114118
A collections.OrderedDict that maps a node label to the node with
115119
that label.
@@ -455,6 +459,7 @@ def _init_luts(self):
455459
self.compat2nodes = defaultdict(list)
456460
self.compat2okay = defaultdict(list)
457461
self.compat2vendor = defaultdict(str)
462+
self.compat2model = defaultdict(str)
458463

459464
for node in self.nodes:
460465
for label in node.labels:
@@ -477,9 +482,10 @@ def _init_luts(self):
477482
f"'{compat_re}'")
478483

479484
if ',' in compat and self._vendor_prefixes:
480-
vendor = compat.split(',', 1)[0]
485+
vendor, model = compat.split(',', 1)
481486
if vendor in self._vendor_prefixes:
482487
self.compat2vendor[compat] = self._vendor_prefixes[vendor]
488+
self.compat2model[compat] = model
483489

484490
# As an exception, the root node can have whatever
485491
# compatibles it wants. Other nodes get checked.

0 commit comments

Comments
 (0)