Skip to content

Commit

Permalink
scripts/dts: Support 'io-channels' property just like 'pwms'
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jimparis authored and galak committed Aug 9, 2019
1 parent 9209604 commit 67f53ba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
51 changes: 49 additions & 2 deletions scripts/dts/edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def _init_devices(self):
dev._init_interrupts()
dev._init_gpios()
dev._init_pwms()
dev._init_iochannels()
dev._init_clocks()

def __repr__(self):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -437,8 +443,9 @@ def __repr__(self):
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
Expand Down Expand Up @@ -688,6 +695,11 @@ def _init_pwms(self):

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
#
Expand Down Expand Up @@ -946,6 +958,41 @@ def __repr__(self):
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
Expand Down
13 changes: 13 additions & 0 deletions scripts/dts/gen_defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 67f53ba

Please sign in to comment.