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 <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-05-16 08:26:51 -05:00 committed by Kumar Gala
commit 983b493ac1

View file

@ -11,6 +11,21 @@ from extract.directive import DTDirective
# @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}
else:
print("ERROR")
return {}
##
# @brief Extract directives in a default way
#
@ -49,6 +64,9 @@ class DTDefault(DTDirective):
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