Skip to content
Browse files

scripts/dts: Add support for enum's

Add specific enum generation support related to usb 'maximum-speed'
property.  This will generate a define with _ENUM with the integer
value of the enum as its ordered in the YAML.  The assumption right
now is that there's a matching enum in the code.

Signed-off-by: Kumar Gala <>
  • Loading branch information...
galak committed May 16, 2019
1 parent 852b1dc commit 983b493ac1468e393999d6c7cabf024ab7eabcbc
Showing with 18 additions and 0 deletions.
  1. +18 −0 scripts/dts/extract/
@@ -11,6 +11,21 @@
# @brief Manage directives in a default way.
class DTDefault(DTDirective):
def _extract_enum(self, node_path, prop, prop_values, label):
cell_yaml = get_binding(node_path)['properties'][prop]
if 'enum' in cell_yaml:
if prop_values in cell_yaml['enum']:
if isinstance(cell_yaml['enum'], list):
value = cell_yaml['enum'].index(prop_values)
if isinstance(cell_yaml['enum'], dict):
value = cell_yaml['enum'][prop_values]
label = label + "_ENUM"
return {label:value}
return {}

# @brief Extract directives in a default way
@@ -49,6 +64,9 @@ def extract(self, node_path, prop, prop_type, def_label):
if prop_values == 'parent-label':
prop_values = find_parent_prop(node_path, 'label')

prop_def = self._extract_enum(node_path, prop, prop_values, label)
if prop_def:
add_compat_alias(node_path, prop_name + "_ENUM" , label + "_ENUM", prop_alias)
if isinstance(prop_values, str):
prop_values = "\"" + prop_values + "\""
prop_def[label] = prop_values

0 comments on commit 983b493

Please sign in to comment.
You can’t perform that action at this time.