From f62ae3e8efb6556934189db2babe9ab12a541e22 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Thu, 22 Aug 2019 09:41:38 -0500 Subject: [PATCH] scripts/dts/gen_defines.py: generate initializers for phandle/val lists When a phandle-array (compound) has multiple members generate a define that says how many there are; generate an initializer for each individual member; and generate an initializer for the sequence of members. This allows drivers that expect multiple values in a compound to process them without horrendous conditional compilation code attempting to detect the number of elements in the compound. It also eliminates the need to repeat the long prefix when initializing a structure with the fields of a single compound. Signed-off-by: Peter A. Bigot --- scripts/dts/gen_defines.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index b221fd5fd54..072890797fe 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -492,29 +492,43 @@ def write_phandle_val_list(dev, entries, ident): # # entries: # List of entries (two for 'pwms' above). This might be a list of - # edtlib.PWM instances, for example. + # edtlib.PWM instances, for example. If only one entry is given it + # does not have a suffix '_0', and the '_COUNT' and group initializer + # are not emitted. # # ident: # Base identifier. For example, "PWM" generates output like this: # # #define _PWMS_CONTROLLER_0 "PWM_0" (name taken from 'label = ...') # #define _PWMS_CHANNEL_0 123 (name taken from #cells in binding) + # #define _PWMS_0 {"PWM_0", 123} # #define _PWMS_CONTROLLER_1 "PWM_1" # #define _PWMS_CHANNEL_1 456 + # #define _PWMS_1 {"PWM_1", 456} + # #define _PWMS_COUNT 2 + # #define _PWMS {_PWMS_0, _PWMS_1} # ... # # Note: Do not add an "S" to 'ident'. It's added automatically, which # forces consistency. + initializer_vals = [] for i, entry in enumerate(entries): - write_phandle_val_list_entry( - dev, entry, i if len(entries) > 1 else None, ident) + initializer_vals.append(write_phandle_val_list_entry( + dev, entry, i if len(entries) > 1 else None, ident)) + if len(entries) > 1: + out_dev(dev, ident + "S_COUNT", len(initializer_vals)) + out_dev(dev, ident + "S", "{" + ", ".join(initializer_vals) + "}") def write_phandle_val_list_entry(dev, entry, i, ident): # write_phandle_val_list() helper. We could get rid of it if it wasn't for # write_spi_dev(). Adds 'i' as an index to identifiers unless it's None. + # + # Returns the identifier for the macro that provides the + # initializer for the entire entry. + initializer_vals = [] if entry.controller.label is not None: ctrl_ident = ident + "S_CONTROLLER" # e.g. PWMS_CONTROLLER if entry.name: @@ -523,6 +537,7 @@ def write_phandle_val_list_entry(dev, entry, i, ident): # more than one entry. if i is not None: ctrl_ident += "_{}".format(i) + initializer_vals.append(quote_str(entry.controller.label)) out_dev_s(dev, ctrl_ident, entry.controller.label) for cell, val in entry.specifier.items(): @@ -535,6 +550,16 @@ def write_phandle_val_list_entry(dev, entry, i, ident): cell_ident += "_{}".format(i) out_dev(dev, cell_ident, val) + initializer_vals += entry.specifier.values() + + initializer_ident = ident + "S" + if entry.name: + initializer_ident += "_" + str2ident(entry.name) + if i is not None: + initializer_ident += "_{}".format(i) + return out_dev(dev, initializer_ident, + "{" + ", ".join(map(str, initializer_vals)) + "}") + def write_clocks(dev): # Writes clock controller and specifier info for the clock in dev's 'clock'