blob: 0779ab2a1d2e7c5b718dba30993036276a481649 [file] [log] [blame]
#
# Copyright (c) 2018 Bobby Noelte
#
# SPDX-License-Identifier: Apache-2.0
#
from extract.globals import *
from extract.directive import DTDirective
##
# @brief Manage interrupts directives.
#
class DTInterrupts(DTDirective):
def __init__(self):
pass
def _find_parent_irq_node(self, node_address):
address = ''
for comp in node_address.split('/')[1:]:
address += '/' + comp
if 'interrupt-parent' in reduced[address]['props']:
interrupt_parent = reduced[address]['props'][
'interrupt-parent']
return phandles[interrupt_parent]
##
# @brief Extract interrupts
#
# @param node_address Address of node owning the
# interrupts definition.
# @param prop compatible property name
# @param names (unused)
# @param def_label Define label string of node owning the
# compatible definition.
#
def extract(self, node_address, prop, names, def_label):
node = reduced[node_address]
try:
props = list(node['props'].get(prop))
except:
props = [node['props'].get(prop)]
irq_parent = self._find_parent_irq_node(node_address)
l_base = def_label.split('/')
index = 0
while props:
prop_def = {}
prop_alias = {}
l_idx = [str(index)]
try:
name = [str_to_label(names.pop(0))]
except:
name = []
cell_yaml = get_binding(irq_parent)
l_cell_prefix = ['IRQ']
for i in range(reduced[irq_parent]['props']['#interrupt-cells']):
l_cell_name = [cell_yaml['#cells'][i].upper()]
if l_cell_name == l_cell_prefix:
l_cell_name = []
l_fqn = '_'.join(l_base + l_cell_prefix + l_idx + l_cell_name)
prop_def[l_fqn] = props.pop(0)
add_compat_alias(node_address,
'_'.join(l_cell_prefix + l_idx + l_cell_name),
l_fqn, prop_alias)
if len(name):
alias_list = l_base + l_cell_prefix + name + l_cell_name
prop_alias['_'.join(alias_list)] = l_fqn
add_compat_alias(node_address,
'_'.join(l_cell_prefix + name + l_cell_name),
l_fqn, prop_alias)
if node_address in aliases:
add_prop_aliases(
node_address,
lambda alias:
'_'.join([str_to_label(alias)] +
l_cell_prefix + name + l_cell_name),
l_fqn,
prop_alias)
index += 1
insert_defs(node_address, prop_def, prop_alias)
##
# @brief Management information for interrupts.
interrupts = DTInterrupts()