From a0a576d3845ebf2afff13e3a4f81721e53ccc562 Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Mon, 19 Aug 2019 10:52:58 -0500 Subject: [PATCH] scripts/dts/gen_defines.py: Fix generation for multiple IO Channels If there is more than one IO Channel than generate a define with a trailing index for the IO Channel. This matches what we do for GPIOs and PWMs. So something like: DT_FOOBAR_IO_CHANNELS_CONTROLLER_0 DT_FOOBAR_IO_CHANNELS_CONTROLLER_1 ... DT_FOOBAR_IO_CHANNELS_CONTROLLER_ Fixes #18352 Signed-off-by: Kumar Gala --- scripts/dts/gen_defines.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 7736b50b157..8cd7b8eb330 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -520,12 +520,26 @@ 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 io_ch_i, io_ch in enumerate(dev.iochannels): + write_iochannel(dev, io_ch, io_ch_i if len(dev.iochannels) > 1 else None) - for spec, val in iochannel.specifier.items(): - out_dev(dev, "IO_CHANNELS_" + str2ident(spec), val) + +def write_iochannel(dev, iochannel, index=None): + # Writes IO channel controller & data for the IO channel object 'iochannel' + # If 'index' is not None, it is added as a suffix to identifiers. + + if iochannel.controller.label is not None: + ctrl_ident = "IO_CHANNELS_CONTROLLER" + if index is not None: + ctrl_ident += "_{}".format(index) + out_dev_s(dev, ctrl_ident, iochannel.controller.label) + + for cell, val in iochannel.specifier.items(): + cell_ident = "IO_CHANNELS_" + str2ident(cell) + if index is not None: + cell_ident += "_{}".format(index) + + out_dev(dev, cell_ident, val) def write_clocks(dev):