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:
parent
852b1dca55
commit
983b493ac1
1 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue