From 59167e188835cff9d5db7fec6e3d362e6a28ce42 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sat, 15 Apr 2023 11:24:11 +1000 Subject: [PATCH] scripts: dts: gen_defines: add `ENUM_VAL__EXISTS` define Add a define of the form `DT_N__P__ENUM_VAL__EXISTS` for enumerated devicetree properties. This enables the devicetree API to check whether an enum is a given value directly, without resorting to error-prone checks against the enum index. Example generated defines (int and string): `#define DT_N_S_test_S_enum_4_P_val_ENUM_VAL_5_EXISTS 1` `#define DT_N_S_test_S_enum_6_P_val_ENUM_VAL_zero_EXISTS 1` Signed-off-by: Jordan Yates --- scripts/dts/gen_defines.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 725b077446..85cefe427f 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -657,12 +657,17 @@ def write_vanilla_props(node): if spec.enum_tokenizable: as_token = prop.val_as_token + # DT_N__P__ENUM_VAL__EXISTS 1 + macro2val[macro + f"_ENUM_VAL_{as_token}_EXISTS"] = 1 # DT_N__P__ENUM_TOKEN macro2val[macro + "_ENUM_TOKEN"] = as_token if spec.enum_upper_tokenizable: # DT_N__P__ENUM_UPPER_TOKEN macro2val[macro + "_ENUM_UPPER_TOKEN"] = as_token.upper() + else: + # DT_N__P__ENUM_VAL__EXISTS 1 + macro2val[macro + f"_ENUM_VAL_{prop.val}_EXISTS"] = 1 if "phandle" in prop.type: macro2val.update(phandle_macros(prop, macro))