scripts/dts: Support 'io-channels' property just like 'pwms'

This is a direct search-and-replace copy of the PWM code.
The name is chosen to match Linux's iio-bindings.txt.

Signed-off-by: Jim Paris <jim@jtan.com>
This commit is contained in:
Jim Paris 2019-08-07 15:05:23 -04:00 committed by Kumar Gala
commit 67f53ba18f
2 changed files with 62 additions and 2 deletions

View file

@ -236,6 +236,7 @@ class EDT:
dev._init_interrupts()
dev._init_gpios()
dev._init_pwms()
dev._init_iochannels()
dev._init_clocks()
def __repr__(self):
@ -330,6 +331,11 @@ class Device:
A list of PWM objects, derived from the 'pwms' property. The list is
empty if the device has no 'pwms' property.
iochannels:
A list of IOChannel objects, derived from the 'io-channels'
property. The list is empty if the device has no 'io-channels'
property.
clocks:
A list of Clock objects, derived from the 'clocks' property. The list is
empty if the device has no 'clocks' property.
@ -437,8 +443,9 @@ class Device:
def __init__(self, edt, node):
"Private constructor. Not meant to be called by clients."
# Interrupts, GPIOs, PWMs, and clocks are initialized separately,
# because they depend on all Devices existing
# Interrupts, GPIOs, PWMs, io-channels, and clocks are
# initialized separately, because they depend on all Devices
# existing
self.edt = edt
self._node = node
@ -688,6 +695,11 @@ class Device:
self.pwms = self._simple_phandle_val_list("pwm", PWM)
def _init_iochannels(self):
# Initializes self.iochannels
self.iochannels = self._simple_phandle_val_list("io-channel", IOChannel)
def _simple_phandle_val_list(self, name, cls):
# Helper for parsing properties like
#
@ -946,6 +958,41 @@ class PWM:
return "<PWM, {}>".format(", ".join(fields))
class IOChannel:
"""
Represents an IO channel used by a device, similar to the property used
by the Linux IIO bindings and described at:
https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/iio-bindings.txt
These attributes are available on IO channel objects:
dev:
The Device instance that uses the IO channel
name:
The name of the IO channel as given in the 'io-channel-names' property,
or the node name if the 'io-channel-names' property doesn't exist.
controller:
The Device instance for the controller of the IO channel
specifier:
A dictionary that maps names from the #cells portion of the binding to
cell values in the io-channel specifier. 'io-channels = <&adc 3>' might
give {"input": 3}, for example.
"""
def __repr__(self):
fields = []
if self.name is not None:
fields.append("name: " + self.name)
fields.append("target: {}".format(self.controller))
fields.append("specifier: {}".format(self.specifier))
return "<IOChannel, {}>".format(", ".join(fields))
class Property:
"""
Represents a property on a Device, as set in its DT node and with

View file

@ -63,6 +63,7 @@ def main():
write_irqs(dev)
write_gpios(dev)
write_pwms(dev)
write_iochannels(dev)
write_clocks(dev)
write_spi_dev(dev)
write_props(dev)
@ -496,6 +497,18 @@ def write_pwms(dev):
out_dev(dev, "PWMS_" + str2ident(spec), val)
def write_iochannels(dev):
# Writes IO channel controller and specifier info for the IO
# channels in dev's 'io-channels' property
for iochannel in dev.iochannels:
if iochannel.controller.label is not None:
out_dev_s(dev, "IO_CHANNELS_CONTROLLER", iochannel.controller.label)
for spec, val in iochannel.specifier.items():
out_dev(dev, "IO_CHANNELS_" + str2ident(spec), val)
def write_clocks(dev):
# Writes clock controller and specifier info for the clock in dev's 'clock'
# property