From 9df0493dc3c22c2a5677e440dc978313c75b587b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 11 Aug 2021 15:43:24 -0700 Subject: [PATCH] scripts: gen_defines: emit pinctrl helper macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to be able to access pinctrl- property contents by name, convert names to indexes, convert indexes to names, and perform existence checks by name and by index. This is currently not possible because we don't track these properties the same way we do other named properties. That in turn is because they are different then the usual named properties. The usual case looks like this, picking DMAs just for the sake of example: dmas = <&dma0 ...>, <&dma1 ...>; dma-names = "tx", "rx"; So "tx" is the name for the <&dma0 ...> element, and "rx" is the name for the <&dma1 ...> element, all in a single "dmas" property. By contrast, pinctrl properties look like this: pinctrl-0 = <&foo &bar ...>; pinctrl-1 = <&baz &blub ...>; pinctrl-names = "default", "sleep"; Here, "default" is the name for the entire pinctrl-0 property. Similarly, "sleep" is the name of the pinctrl-1 property. It's a strange situation where the node itself is kind of a container for an array of pin control properties, which Zephyr's bindings language can't really capture and has some special case handling in edtlib. This is easiest to handle with ad-hoc code. Add special case macros for pinctrls. Signed-off-by: Martí Bolívar --- scripts/dts/gen_defines.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 365e950fc82..99cf392e057 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -361,6 +361,7 @@ def write_special_props(node): # Macros that are special to bindings inherited from Linux, which # we can't capture with the current bindings language. + write_pinctrls(node) write_fixed_partitions(node) def write_regs(node): @@ -509,6 +510,36 @@ def write_status(node): out_dt_define(f"{node.z_path_id}_STATUS_{str2ident(node.status)}", 1) +def write_pinctrls(node): + # Write special macros for pinctrl- and pinctrl-names properties. + + out_comment("Pin control (pinctrl-, pinctrl-names) properties:") + + out_dt_define(f"{node.z_path_id}_PINCTRL_NUM", len(node.pinctrls)) + + if not node.pinctrls: + return + + for pc_idx, pinctrl in enumerate(node.pinctrls): + out_dt_define(f"{node.z_path_id}_PINCTRL_IDX_{pc_idx}_EXISTS", 1) + + if not pinctrl.name: + continue + + name = pinctrl.name_as_token + + # Below we rely on the fact that edtlib ensures the + # pinctrl- properties are contiguous, start from 0, + # and contain only phandles. + out_dt_define(f"{node.z_path_id}_PINCTRL_IDX_{pc_idx}_TOKEN", name) + out_dt_define(f"{node.z_path_id}_PINCTRL_IDX_{pc_idx}_UPPER_TOKEN", name.upper()) + out_dt_define(f"{node.z_path_id}_PINCTRL_NAME_{name}_EXISTS", 1) + out_dt_define(f"{node.z_path_id}_PINCTRL_NAME_{name}_IDX", pc_idx) + for idx, ph in enumerate(pinctrl.conf_nodes): + out_dt_define(f"{node.z_path_id}_PINCTRL_NAME_{name}_IDX_{idx}_PH", + f"DT_{ph.z_path_id}") + + def write_fixed_partitions(node): # Macros for child nodes of each fixed-partitions node.