Skip to content

Commit d65e943

Browse files
committed
dts: edtlib: extract gpio led nodes
Extract the gpio led child node of gpio leds controller nodes. Extend the Node class with properties for: gpio_leds: A list of ControllerAndData objects of the leds a gpio leds controller controls. The list is empty if the node is not a gpio leds controller or it does not have gpio led children. Signed-off-by: Bobby Noelte <[email protected]>
1 parent 21790b3 commit d65e943

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

scripts/dts/edtlib.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ def _init_nodes(self):
516516
# These depend on the referenced nodes' props already initialized.
517517
node._init_pinctrls()
518518
node._init_partitions()
519+
node._init_gpio_leds()
519520

520521
def _init_compat2enabled(self):
521522
# Creates self.compat2enabled
@@ -794,6 +795,11 @@ class Node:
794795
node, sorted by index. The list is empty if the node does not have a
795796
#clock-cells property.
796797
798+
gpio_leds:
799+
A list of ControllerAndData objects of the leds a gpio leds controller
800+
controls. The list is empty if the node is not a gpio leds controller or
801+
it does not have and gpio led children.
802+
797803
interrupts:
798804
A list of ControllerAndData objects for the interrupts generated by the
799805
node. The list is empty if the node does not generate interrupts.
@@ -1386,6 +1392,40 @@ def _init_clock_outputs(self):
13861392
clock_outputs_name_indices, clock_output_names,
13871393
clock_frequency, clock_accuracy)
13881394

1395+
def _init_gpio_leds(self):
1396+
# Initializes self.gpio_leds
1397+
1398+
if not hasattr(self, 'gpio_leds'):
1399+
self.gpio_leds = []
1400+
1401+
if not self.parent or "gpio-leds" not in self.parent.compats:
1402+
# Not a child of a gpio leds controller
1403+
return
1404+
1405+
gpio_leds_controller = self.parent
1406+
1407+
gpio_led = ControllerAndData()
1408+
gpio_led.node = self
1409+
gpio_led.name = None
1410+
gpio_led.controller = gpio_leds_controller
1411+
gpio_led.data = {}
1412+
for prop_name, prop_value in self.props.items():
1413+
if prop_name == 'label':
1414+
gpio_led.name = prop_value.val
1415+
else:
1416+
gpio_led.data[prop_name] = prop_value.val
1417+
1418+
# Assure the gpio led gets a name
1419+
if not gpio_led.name:
1420+
# From Linux leds/common.txt: "If omitted, the label is taken from
1421+
# the node name (excluding the unit address)."
1422+
gpio_led.name = self.name.split('@')[0]
1423+
1424+
# Append led to the list of leds of the gpio leds controller
1425+
if not hasattr(gpio_leds_controller, 'gpio_leds'):
1426+
gpio_leds_controller.gpio_leds = []
1427+
gpio_leds_controller.gpio_leds.append(gpio_led)
1428+
13891429
def _init_regs(self):
13901430
# Initializes self.regs
13911431

0 commit comments

Comments
 (0)