From 67f53ba18ff3da5107956d9ef0c8a5a35ced23d9 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Wed, 7 Aug 2019 15:05:23 -0400 Subject: [PATCH] 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 --- scripts/dts/edtlib.py | 51 ++++++++++++++++++++++++++++++++++++-- scripts/dts/gen_defines.py | 13 ++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/scripts/dts/edtlib.py b/scripts/dts/edtlib.py index a0d55a01a212..fc20a3b3dbad 100644 --- a/scripts/dts/edtlib.py +++ b/scripts/dts/edtlib.py @@ -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): @@ -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 @@ 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 @@ -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 # @@ -946,6 +958,41 @@ def __repr__(self): return "".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 "".format(", ".join(fields)) + + class Property: """ Represents a property on a Device, as set in its DT node and with diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 2b3fc2eaea24..3161ae0fea65 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -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