dts: edtlib: Turn global spi_dev_cs_gpio() into Node.spi_cs_gpio
spi_dev_cs_gpio() takes a Node and returns the chip select GPIO for it. Having that information available directly from Node is neater, so turn it into a Node.spi_cs_gpio property instead. That gets rid of the only public global function in edtlib, which might make the API design clearer too. Tested with the sensortile_box board, which uses SPI chip select. Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
e2d71c9c77
commit
8cacb9fd8c
2 changed files with 28 additions and 30 deletions
|
@ -789,6 +789,11 @@ class Node:
|
||||||
flash_controller:
|
flash_controller:
|
||||||
The flash controller for the node. Only meaningful for nodes representing
|
The flash controller for the node. Only meaningful for nodes representing
|
||||||
flash partitions.
|
flash partitions.
|
||||||
|
|
||||||
|
spi_cs_gpio:
|
||||||
|
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.
|
||||||
"""
|
"""
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -927,6 +932,28 @@ class Node:
|
||||||
return controller.parent
|
return controller.parent
|
||||||
return controller
|
return controller
|
||||||
|
|
||||||
|
@property
|
||||||
|
def spi_cs_gpio(self):
|
||||||
|
"See the class docstring"
|
||||||
|
|
||||||
|
if not (self.on_bus == "spi" and "cs-gpios" in self.bus_node.props):
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not self.regs:
|
||||||
|
_err("{!r} needs a 'reg' property, to look up the chip select index "
|
||||||
|
"for SPI".format(self))
|
||||||
|
|
||||||
|
parent_cs_lst = self.bus_node.props["cs-gpios"].val
|
||||||
|
|
||||||
|
# cs-gpios is indexed by the unit address
|
||||||
|
cs_index = self.regs[0].addr
|
||||||
|
if cs_index >= len(parent_cs_lst):
|
||||||
|
_err("index from 'regs' in {!r} ({}) is >= number of cs-gpios "
|
||||||
|
"in {!r} ({})".format(
|
||||||
|
self, cs_index, self.bus_node, len(parent_cs_lst)))
|
||||||
|
|
||||||
|
return parent_cs_lst[cs_index]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Node {} in '{}', {}>".format(
|
return "<Node {} in '{}', {}>".format(
|
||||||
self.path, self.edt.dts_path,
|
self.path, self.edt.dts_path,
|
||||||
|
@ -1504,35 +1531,6 @@ class EDTError(Exception):
|
||||||
"Exception raised for devicetree- and binding-related errors"
|
"Exception raised for devicetree- and binding-related errors"
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Public global functions
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
def spi_dev_cs_gpio(node):
|
|
||||||
# Returns an SPI device's GPIO chip select if it exists, as a
|
|
||||||
# ControllerAndData instance, and None otherwise. See
|
|
||||||
# Documentation/devicetree/bindings/spi/spi-bus.txt in the Linux kernel.
|
|
||||||
|
|
||||||
if not (node.on_bus == "spi" and "cs-gpios" in node.bus_node.props):
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not node.regs:
|
|
||||||
_err("{!r} needs a 'reg' property, to look up the chip select index "
|
|
||||||
"for SPI".format(node))
|
|
||||||
|
|
||||||
parent_cs_lst = node.bus_node.props["cs-gpios"].val
|
|
||||||
|
|
||||||
# cs-gpios is indexed by the unit address
|
|
||||||
cs_index = node.regs[0].addr
|
|
||||||
if cs_index >= len(parent_cs_lst):
|
|
||||||
_err("index from 'regs' in {!r} ({}) is >= number of cs-gpios "
|
|
||||||
"in {!r} ({})".format(
|
|
||||||
node, cs_index, node.bus_node, len(parent_cs_lst)))
|
|
||||||
|
|
||||||
return parent_cs_lst[cs_index]
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Private global functions
|
# Private global functions
|
||||||
#
|
#
|
||||||
|
|
|
@ -549,7 +549,7 @@ def write_irqs(node):
|
||||||
def write_spi_dev(node):
|
def write_spi_dev(node):
|
||||||
# Writes SPI device GPIO chip select data if there is any
|
# Writes SPI device GPIO chip select data if there is any
|
||||||
|
|
||||||
cs_gpio = edtlib.spi_dev_cs_gpio(node)
|
cs_gpio = node.spi_cs_gpio
|
||||||
if cs_gpio is not None:
|
if cs_gpio is not None:
|
||||||
write_phandle_val_list_entry(node, cs_gpio, None, "CS_GPIOS")
|
write_phandle_val_list_entry(node, cs_gpio, None, "CS_GPIOS")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue