scripts: dts: add special tooling for handling GPIO hog nodes

GPIO hog nodes contain a "gpios" property, but unlike other "*-gpios"
properties, these are not phandle-arrays as they only carry the data part
(e.g. pin, flags) but lack the phandles to the (parent) GPIO controller.

Add special devicetree tooling to handle the "gpios" property of GPIO hog
nodes and generate special devicetree helper macros as if they were phandle
arrays.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen
2023-01-13 11:32:27 +01:00
committed by Marti Bolivar
parent b208f4da98
commit 28819152cb
3 changed files with 128 additions and 0 deletions

View File

@@ -671,6 +671,11 @@ class Node:
The device's SPI GPIO chip select as a ControllerAndData instance, if it
exists, and None otherwise. See
Documentation/devicetree/bindings/spi/spi-controller.yaml in the Linux kernel.
gpio_hogs:
A list of ControllerAndData objects for the GPIOs hogged by the node. The
list is empty if the node does not hog any GPIOs. Only relevant for GPIO hog
nodes.
"""
@property
def name(self):
@@ -837,6 +842,35 @@ class Node:
return parent_cs_lst[cs_index]
@property
def gpio_hogs(self):
"See the class docstring"
if "gpio-hog" not in self.props:
return []
if not self.parent or not "gpio-controller" in self.parent.props:
_err(f"GPIO hog {self!r} lacks parent GPIO controller node")
if not "#gpio-cells" in self.parent._node.props:
_err(f"GPIO hog {self!r} parent node lacks #gpio-cells")
n_cells = self.parent._node.props["#gpio-cells"].to_num()
res = []
for item in _slice(self._node, "gpios", 4*n_cells,
f"4*(<#gpio-cells> (= {n_cells})"):
entry = ControllerAndData()
entry.node = self
entry.controller = self.parent
entry.data = self._named_cells(entry.controller, item, "gpio")
entry.basename = "gpio"
entry.name = None
res.append(entry)
return res
def __repr__(self):
if self.binding_path:
binding = "binding " + self.binding_path