Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 1 | # Copyright (c) 2018-2019 Linaro |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019 Nordic Semiconductor ASA |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
Keith Short | df0942f | 2023-03-24 15:22:42 -0600 | [diff] [blame] | 6 | import inspect |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 7 | import os |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 8 | import pickle |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 9 | import sys |
Henrik Brix Andersen | c6b3094 | 2022-05-18 17:35:23 +0200 | [diff] [blame] | 10 | from pathlib import Path |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 11 | |
Henrik Brix Andersen | c6b3094 | 2022-05-18 17:35:23 +0200 | [diff] [blame] | 12 | ZEPHYR_BASE = str(Path(__file__).resolve().parents[2]) |
Martí Bolívar | 5332847 | 2021-03-26 16:18:58 -0700 | [diff] [blame] | 13 | sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts", |
| 14 | "python-devicetree", "src")) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 15 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 16 | # Types we support |
| 17 | # 'string', 'int', 'hex', 'bool' |
| 18 | |
Carles Cufi | fa26ef0 | 2019-01-30 17:54:21 +0100 | [diff] [blame] | 19 | doc_mode = os.environ.get('KCONFIG_DOC_MODE') == "1" |
Sebastian Bøe | cd43543 | 2019-02-11 15:57:34 +0100 | [diff] [blame] | 20 | |
Ulf Magnusson | ba312fe | 2019-03-20 19:30:29 +0100 | [diff] [blame] | 21 | if not doc_mode: |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 22 | EDT_PICKLE = os.environ.get("EDT_PICKLE") |
Kumar Gala | 9aefdaf | 2020-04-15 10:32:41 -0500 | [diff] [blame] | 23 | |
Martí Bolívar | 269f350 | 2020-07-01 12:17:02 -0700 | [diff] [blame] | 24 | # The "if" handles a missing dts. |
| 25 | if EDT_PICKLE is not None and os.path.isfile(EDT_PICKLE): |
| 26 | with open(EDT_PICKLE, 'rb') as f: |
| 27 | edt = pickle.load(f) |
Keith Short | df0942f | 2023-03-24 15:22:42 -0600 | [diff] [blame] | 28 | edtlib = inspect.getmodule(edt) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 29 | else: |
| 30 | edt = None |
| 31 | |
Kumar Gala | 1baf2f3 | 2019-09-04 14:14:26 -0500 | [diff] [blame] | 32 | |
| 33 | def _warn(kconf, msg): |
| 34 | print("{}:{}: WARNING: {}".format(kconf.filename, kconf.linenr, msg)) |
| 35 | |
| 36 | |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 37 | def _dt_units_to_scale(unit): |
| 38 | if not unit: |
| 39 | return 0 |
| 40 | if unit in {'k', 'K'}: |
| 41 | return 10 |
| 42 | if unit in {'m', 'M'}: |
| 43 | return 20 |
| 44 | if unit in {'g', 'G'}: |
| 45 | return 30 |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 46 | if unit in {'kb', 'Kb'}: |
| 47 | return 13 |
| 48 | if unit in {'mb', 'Mb'}: |
| 49 | return 23 |
| 50 | if unit in {'gb', 'Gb'}: |
| 51 | return 33 |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 52 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 53 | |
| 54 | def dt_chosen_label(kconf, _, chosen): |
| 55 | """ |
| 56 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 57 | to an EDT node. If it finds an EDT node, it will look to see if that node |
Martí Bolívar | b3151bc | 2022-08-18 16:13:50 -0700 | [diff] [blame] | 58 | has a "label" property and return the value of that "label". If not, we |
| 59 | return the node's name in the devicetree. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 60 | """ |
| 61 | if doc_mode or edt is None: |
| 62 | return "" |
| 63 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 64 | node = edt.chosen_node(chosen) |
| 65 | if not node: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 66 | return "" |
| 67 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 68 | if "label" not in node.props: |
Kumar Gala | 5753826 | 2022-08-04 11:23:13 -0500 | [diff] [blame] | 69 | return node.name |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 70 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 71 | return node.props["label"].val |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 72 | |
| 73 | |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 74 | def dt_chosen_enabled(kconf, _, chosen): |
| 75 | """ |
| 76 | This function returns "y" if /chosen contains a property named 'chosen' |
| 77 | that points to an enabled node, and "n" otherwise |
| 78 | """ |
| 79 | if doc_mode or edt is None: |
| 80 | return "n" |
| 81 | |
| 82 | node = edt.chosen_node(chosen) |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 83 | return "y" if node and node.status == "okay" else "n" |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 84 | |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 85 | |
Martí Bolívar | 7ff3ebc | 2020-04-23 12:28:06 -0700 | [diff] [blame] | 86 | def dt_chosen_path(kconf, _, chosen): |
| 87 | """ |
| 88 | This function takes a /chosen node property and returns the path |
| 89 | to the node in the property value, or the empty string. |
| 90 | """ |
| 91 | if doc_mode or edt is None: |
| 92 | return "n" |
| 93 | |
| 94 | node = edt.chosen_node(chosen) |
| 95 | |
| 96 | return node.path if node else "" |
| 97 | |
Daniel DeGrasse | fbefc50 | 2022-04-11 11:53:03 -0500 | [diff] [blame] | 98 | def dt_chosen_has_compat(kconf, _, chosen, compat): |
| 99 | """ |
| 100 | This function takes a /chosen node property and returns 'y' if the |
| 101 | chosen node has the provided compatible string 'compat' |
| 102 | """ |
| 103 | if doc_mode or edt is None: |
| 104 | return "n" |
| 105 | |
| 106 | node = edt.chosen_node(chosen) |
| 107 | |
| 108 | if node is None: |
| 109 | return "n" |
| 110 | |
| 111 | if compat in node.compats: |
| 112 | return "y" |
| 113 | |
| 114 | return "n" |
Martí Bolívar | 7ff3ebc | 2020-04-23 12:28:06 -0700 | [diff] [blame] | 115 | |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 116 | def dt_node_enabled(kconf, name, node): |
| 117 | """ |
| 118 | This function is used to test if a node is enabled (has status |
| 119 | 'okay') or not. |
| 120 | |
| 121 | The 'node' argument is a string which is either a path or an |
| 122 | alias, or both, depending on 'name'. |
| 123 | |
| 124 | If 'name' is 'dt_path_enabled', 'node' is an alias or a path. If |
| 125 | 'name' is 'dt_alias_enabled, 'node' is an alias. |
| 126 | """ |
| 127 | |
| 128 | if doc_mode or edt is None: |
| 129 | return "n" |
| 130 | |
| 131 | if name == "dt_alias_enabled": |
| 132 | if node.startswith("/"): |
| 133 | # EDT.get_node() works with either aliases or paths. If we |
| 134 | # are specifically being asked about an alias, reject paths. |
| 135 | return "n" |
| 136 | else: |
| 137 | # Make sure this is being called appropriately. |
| 138 | assert name == "dt_path_enabled" |
| 139 | |
| 140 | try: |
| 141 | node = edt.get_node(node) |
| 142 | except edtlib.EDTError: |
| 143 | return "n" |
| 144 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 145 | return "y" if node and node.status == "okay" else "n" |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 146 | |
| 147 | |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 148 | def dt_nodelabel_enabled(kconf, _, label): |
| 149 | """ |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 150 | This function is like dt_node_enabled(), but the 'label' argument |
| 151 | should be a node label, like "foo" is here: |
| 152 | |
| 153 | foo: some-node { ... }; |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 154 | """ |
| 155 | if doc_mode or edt is None: |
| 156 | return "n" |
| 157 | |
Martí Bolívar | 0682c46 | 2020-04-22 17:59:23 -0700 | [diff] [blame] | 158 | node = edt.label2node.get(label) |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 159 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 160 | return "y" if node and node.status == "okay" else "n" |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 161 | |
| 162 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 163 | def _node_reg_addr(node, index, unit): |
| 164 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 165 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 166 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 167 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 168 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 169 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 170 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 171 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 172 | |
Kumar Gala | 8af311a | 2020-03-13 12:43:56 -0500 | [diff] [blame] | 173 | if node.regs[int(index)].addr is None: |
| 174 | return 0 |
| 175 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 176 | return node.regs[int(index)].addr >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 177 | |
| 178 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 179 | def _node_reg_size(node, index, unit): |
| 180 | if not node: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 181 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 182 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 183 | if not node.regs: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 184 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 185 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 186 | if int(index) >= len(node.regs): |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 187 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 188 | |
Kumar Gala | 8af311a | 2020-03-13 12:43:56 -0500 | [diff] [blame] | 189 | if node.regs[int(index)].size is None: |
| 190 | return 0 |
| 191 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 192 | return node.regs[int(index)].size >> _dt_units_to_scale(unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 193 | |
| 194 | |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 195 | def _node_int_prop(node, prop, unit=None): |
| 196 | """ |
| 197 | This function takes a 'node' and will look to see if that 'node' has a |
| 198 | property called 'prop' and if that 'prop' is an integer type will return |
| 199 | the value of the property 'prop' as either a string int or string hex |
| 200 | value, if not we return 0. |
| 201 | |
| 202 | The function will divide the value based on 'unit': |
| 203 | None No division |
| 204 | 'k' or 'K' divide by 1024 (1 << 10) |
| 205 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 206 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 207 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 208 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 209 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 210 | """ |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 211 | if not node: |
| 212 | return 0 |
| 213 | |
| 214 | if prop not in node.props: |
| 215 | return 0 |
| 216 | |
| 217 | if node.props[prop].type != "int": |
| 218 | return 0 |
| 219 | |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 220 | return node.props[prop].val >> _dt_units_to_scale(unit) |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 221 | |
| 222 | |
Eivind Jølsgard | 3865e08 | 2022-03-18 10:50:00 +0100 | [diff] [blame] | 223 | def _node_array_prop(node, prop, index=0, unit=None): |
| 224 | """ |
| 225 | This function takes a 'node' and will look to see if that 'node' has a |
| 226 | property called 'prop' and if that 'prop' is an array type will return |
| 227 | the value of the property 'prop' at the given 'index' as either a string int |
| 228 | or string hex value. If the property 'prop' is not found or the given 'index' |
| 229 | is out of range it will return 0. |
| 230 | |
| 231 | The function will divide the value based on 'unit': |
| 232 | None No division |
| 233 | 'k' or 'K' divide by 1024 (1 << 10) |
| 234 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 235 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 236 | """ |
| 237 | if not node: |
| 238 | return 0 |
| 239 | |
| 240 | if prop not in node.props: |
| 241 | return 0 |
| 242 | if node.props[prop].type != "array": |
| 243 | return 0 |
| 244 | if int(index) >= len(node.props[prop].val): |
| 245 | return 0 |
| 246 | return node.props[prop].val[int(index)] >> _dt_units_to_scale(unit) |
| 247 | |
Erwan Gouriou | a59e01d | 2023-12-18 12:03:43 +0100 | [diff] [blame] | 248 | def _node_ph_array_prop(node, prop, index, cell, unit=None): |
| 249 | """ |
| 250 | This function takes a 'node', a property name ('prop'), index ('index') and |
| 251 | a cell ('cell') and it will look to see if that node has a property |
| 252 | called 'prop' and if that 'prop' is an phandle-array type. |
| 253 | Then it will check if that phandle array has a cell matching the given index |
| 254 | and then return the value of the cell named 'cell' in this array index. |
| 255 | If not found it will return 0. |
| 256 | |
| 257 | The function will divide the value based on 'unit': |
| 258 | None No division |
| 259 | 'k' or 'K' divide by 1024 (1 << 10) |
| 260 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 261 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 262 | """ |
| 263 | if not node: |
| 264 | return 0 |
| 265 | |
| 266 | if prop not in node.props: |
| 267 | return 0 |
| 268 | if node.props[prop].type != "phandle-array": |
| 269 | return 0 |
| 270 | if int(index) >= len(node.props[prop].val): |
| 271 | return 0 |
| 272 | if cell not in node.props[prop].val[int(index)].data.keys(): |
| 273 | return 0 |
| 274 | return node.props[prop].val[int(index)].data[cell] >> _dt_units_to_scale(unit) |
Eivind Jølsgard | 3865e08 | 2022-03-18 10:50:00 +0100 | [diff] [blame] | 275 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 276 | def _dt_chosen_reg_addr(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 277 | """ |
| 278 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 279 | to an EDT node. If it finds an EDT node, it will look to see if that |
Nazar Kazakov | f483b1b | 2022-03-16 21:07:43 +0000 | [diff] [blame] | 280 | node has a register at the given 'index' and return the address value of |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 281 | that reg, if not we return 0. |
| 282 | |
| 283 | The function will divide the value based on 'unit': |
| 284 | None No division |
| 285 | 'k' or 'K' divide by 1024 (1 << 10) |
| 286 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 287 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 288 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 289 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 290 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 291 | """ |
| 292 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 293 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 294 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 295 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 296 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 297 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 298 | |
| 299 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 300 | def _dt_chosen_reg_size(kconf, chosen, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 301 | """ |
| 302 | This function takes a 'chosen' property and treats that property as a path |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 303 | to an EDT node. If it finds an EDT node, it will look to see if that node |
| 304 | has a register at the given 'index' and return the size value of that reg, |
| 305 | if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 306 | |
| 307 | The function will divide the value based on 'unit': |
| 308 | None No division |
| 309 | 'k' or 'K' divide by 1024 (1 << 10) |
| 310 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 311 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 312 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 313 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 314 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 315 | """ |
| 316 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 317 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 318 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 319 | node = edt.chosen_node(chosen) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 320 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 321 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 322 | |
| 323 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 324 | def dt_chosen_reg(kconf, name, chosen, index=0, unit=None): |
| 325 | """ |
| 326 | This function just routes to the proper function and converts |
| 327 | the result to either a string int or string hex value. |
| 328 | """ |
| 329 | if name == "dt_chosen_reg_size_int": |
| 330 | return str(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 331 | if name == "dt_chosen_reg_size_hex": |
| 332 | return hex(_dt_chosen_reg_size(kconf, chosen, index, unit)) |
| 333 | if name == "dt_chosen_reg_addr_int": |
| 334 | return str(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 335 | if name == "dt_chosen_reg_addr_hex": |
| 336 | return hex(_dt_chosen_reg_addr(kconf, chosen, index, unit)) |
| 337 | |
| 338 | |
| 339 | def _dt_node_reg_addr(kconf, path, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 340 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 341 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 342 | finds an EDT node, it will look to see if that node has a register at the |
| 343 | given 'index' and return the address value of that reg, if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 344 | |
| 345 | The function will divide the value based on 'unit': |
| 346 | None No division |
| 347 | 'k' or 'K' divide by 1024 (1 << 10) |
| 348 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 349 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 350 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 351 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 352 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 353 | """ |
| 354 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 355 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 356 | |
| 357 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 358 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 359 | except edtlib.EDTError: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 360 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 361 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 362 | return _node_reg_addr(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 363 | |
| 364 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 365 | def _dt_node_reg_size(kconf, path, index=0, unit=None): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 366 | """ |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 367 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 368 | finds an EDT node, it will look to see if that node has a register at the |
| 369 | given 'index' and return the size value of that reg, if not we return 0. |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 370 | |
| 371 | The function will divide the value based on 'unit': |
| 372 | None No division |
| 373 | 'k' or 'K' divide by 1024 (1 << 10) |
| 374 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 375 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 376 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 377 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 378 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 379 | """ |
| 380 | if doc_mode or edt is None: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 381 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 382 | |
| 383 | try: |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 384 | node = edt.get_node(path) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 385 | except edtlib.EDTError: |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 386 | return 0 |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 387 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 388 | return _node_reg_size(node, index, unit) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 389 | |
| 390 | |
Kumar Gala | 22e7449 | 2019-10-23 15:15:59 -0500 | [diff] [blame] | 391 | def dt_node_reg(kconf, name, path, index=0, unit=None): |
| 392 | """ |
| 393 | This function just routes to the proper function and converts |
| 394 | the result to either a string int or string hex value. |
| 395 | """ |
| 396 | if name == "dt_node_reg_size_int": |
| 397 | return str(_dt_node_reg_size(kconf, path, index, unit)) |
| 398 | if name == "dt_node_reg_size_hex": |
| 399 | return hex(_dt_node_reg_size(kconf, path, index, unit)) |
| 400 | if name == "dt_node_reg_addr_int": |
| 401 | return str(_dt_node_reg_addr(kconf, path, index, unit)) |
| 402 | if name == "dt_node_reg_addr_hex": |
| 403 | return hex(_dt_node_reg_addr(kconf, path, index, unit)) |
| 404 | |
Jordan Yates | 999afdc | 2023-07-30 13:33:33 +1000 | [diff] [blame] | 405 | def dt_nodelabel_reg(kconf, name, label, index=0, unit=None): |
| 406 | """ |
| 407 | This function is like dt_node_reg(), but the 'label' argument |
| 408 | should be a node label, like "foo" is here: |
| 409 | |
| 410 | foo: some-node { ... }; |
| 411 | """ |
| 412 | if doc_mode or edt is None: |
| 413 | node = None |
| 414 | else: |
| 415 | node = edt.label2node.get(label) |
| 416 | |
| 417 | if name == "dt_nodelabel_reg_size_int": |
| 418 | return str(_dt_node_reg_size(kconf, node.path, index, unit)) if node else "0" |
| 419 | if name == "dt_nodelabel_reg_size_hex": |
| 420 | return hex(_dt_node_reg_size(kconf, node.path, index, unit)) if node else "0x0" |
| 421 | if name == "dt_nodelabel_reg_addr_int": |
| 422 | return str(_dt_node_reg_addr(kconf, node.path, index, unit)) if node else "0" |
| 423 | if name == "dt_nodelabel_reg_addr_hex": |
| 424 | return hex(_dt_node_reg_addr(kconf, node.path, index, unit)) if node else "0x0" |
| 425 | |
| 426 | |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 427 | def _dt_node_bool_prop_generic(node_search_function, search_arg, prop): |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 428 | """ |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 429 | This function takes the 'node_search_function' and uses it to search for |
| 430 | a node with 'search_arg' and if node exists, checks if 'prop' exists |
| 431 | inside the node and is a boolean, if it is true, returns "y". |
| 432 | Otherwise, it returns "n". |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 433 | """ |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 434 | try: |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 435 | node = node_search_function(search_arg) |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 436 | except edtlib.EDTError: |
| 437 | return "n" |
| 438 | |
Andrzej Głąbek | 2399433 | 2022-03-23 14:45:11 +0100 | [diff] [blame] | 439 | if node is None: |
| 440 | return "n" |
| 441 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 442 | if prop not in node.props: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 443 | return "n" |
| 444 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 445 | if node.props[prop].type != "boolean": |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 446 | return "n" |
| 447 | |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 448 | if node.props[prop].val: |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 449 | return "y" |
| 450 | |
| 451 | return "n" |
| 452 | |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 453 | def dt_node_bool_prop(kconf, _, path, prop): |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 454 | """ |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 455 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 456 | finds an EDT node, it will look to see if that node has a boolean property |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 457 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 458 | we return "n". |
| 459 | """ |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 460 | if doc_mode or edt is None: |
| 461 | return "n" |
| 462 | |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 463 | return _dt_node_bool_prop_generic(edt.get_node, path, prop) |
| 464 | |
| 465 | def dt_nodelabel_bool_prop(kconf, _, label, prop): |
| 466 | """ |
| 467 | This function takes a 'label' and looks for an EDT node with that label. |
| 468 | If it finds an EDT node, it will look to see if that node has a boolean |
| 469 | property by the name of 'prop'. If the 'prop' exists it will return "y" |
| 470 | otherwise we return "n". |
| 471 | """ |
| 472 | if doc_mode or edt is None: |
| 473 | return "n" |
| 474 | |
| 475 | return _dt_node_bool_prop_generic(edt.label2node.get, label, prop) |
| 476 | |
Stephen Stauts | d4b8db7 | 2022-12-27 11:40:17 +0100 | [diff] [blame] | 477 | def dt_chosen_bool_prop(kconf, _, chosen, prop): |
| 478 | """ |
| 479 | This function takes a /chosen node property named 'chosen', and |
| 480 | looks for the chosen node. If that node exists and has a boolean |
| 481 | property 'prop', it returns "y". Otherwise, it returns "n". |
| 482 | """ |
| 483 | if doc_mode or edt is None: |
| 484 | return "n" |
| 485 | |
| 486 | return _dt_node_bool_prop_generic(edt.chosen_node, chosen, prop) |
| 487 | |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 488 | def _dt_node_has_prop_generic(node_search_function, search_arg, prop): |
| 489 | """ |
| 490 | This function takes the 'node_search_function' and uses it to search for |
| 491 | a node with 'search_arg' and if node exists, then checks if 'prop' |
| 492 | exists inside the node and returns "y". Otherwise, it returns "n". |
| 493 | """ |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 494 | try: |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 495 | node = node_search_function(search_arg) |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 496 | except edtlib.EDTError: |
| 497 | return "n" |
| 498 | |
| 499 | if node is None: |
| 500 | return "n" |
| 501 | |
| 502 | if prop in node.props: |
| 503 | return "y" |
| 504 | |
| 505 | return "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 506 | |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 507 | def dt_node_has_prop(kconf, _, path, prop): |
| 508 | """ |
| 509 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 510 | finds an EDT node, it will look to see if that node has a property |
| 511 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 512 | it returns "n". |
| 513 | """ |
| 514 | if doc_mode or edt is None: |
| 515 | return "n" |
| 516 | |
| 517 | return _dt_node_has_prop_generic(edt.get_node, path, prop) |
| 518 | |
| 519 | def dt_nodelabel_has_prop(kconf, _, label, prop): |
| 520 | """ |
| 521 | This function takes a 'label' and looks for an EDT node with that label. |
| 522 | If it finds an EDT node, it will look to see if that node has a property |
| 523 | by the name of 'prop'. If the 'prop' exists it will return "y" otherwise |
| 524 | it returns "n". |
| 525 | """ |
| 526 | if doc_mode or edt is None: |
| 527 | return "n" |
| 528 | |
| 529 | return _dt_node_has_prop_generic(edt.label2node.get, label, prop) |
| 530 | |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 531 | def dt_node_int_prop(kconf, name, path, prop, unit=None): |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 532 | """ |
| 533 | This function takes a 'path' and property name ('prop') looks for an EDT |
| 534 | node at that path. If it finds an EDT node, it will look to see if that |
| 535 | node has a property called 'prop' and if that 'prop' is an integer type |
| 536 | will return the value of the property 'prop' as either a string int or |
| 537 | string hex value, if not we return 0. |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 538 | |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 539 | The function will divide the value based on 'unit': |
| 540 | None No division |
| 541 | 'k' or 'K' divide by 1024 (1 << 10) |
| 542 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 543 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
Daniel DeGrasse | 6064da8 | 2022-05-25 17:38:59 -0500 | [diff] [blame] | 544 | 'kb' or 'Kb' divide by 8192 (1 << 13) |
| 545 | 'mb' or 'Mb' divide by 8,388,608 (1 << 23) |
| 546 | 'gb' or 'Gb' divide by 8,589,934,592 (1 << 33) |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 547 | """ |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 548 | if doc_mode or edt is None: |
| 549 | return "0" |
| 550 | |
| 551 | try: |
| 552 | node = edt.get_node(path) |
| 553 | except edtlib.EDTError: |
| 554 | return "0" |
| 555 | |
| 556 | if name == "dt_node_int_prop_int": |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 557 | return str(_node_int_prop(node, prop, unit)) |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 558 | if name == "dt_node_int_prop_hex": |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 559 | return hex(_node_int_prop(node, prop, unit)) |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 560 | |
Eivind Jølsgard | 3865e08 | 2022-03-18 10:50:00 +0100 | [diff] [blame] | 561 | |
| 562 | def dt_node_array_prop(kconf, name, path, prop, index, unit=None): |
| 563 | """ |
| 564 | This function takes a 'path', property name ('prop') and index ('index') |
| 565 | and looks for an EDT node at that path. If it finds an EDT node, it will |
| 566 | look to see if that node has a property called 'prop' and if that 'prop' |
| 567 | is an array type will return the value of the property 'prop' at the given |
| 568 | 'index' as either a string int or string hex value. If not found we return 0. |
| 569 | |
| 570 | The function will divide the value based on 'unit': |
| 571 | None No division |
| 572 | 'k' or 'K' divide by 1024 (1 << 10) |
| 573 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 574 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 575 | """ |
| 576 | if doc_mode or edt is None: |
| 577 | return "0" |
| 578 | |
| 579 | try: |
| 580 | node = edt.get_node(path) |
| 581 | except edtlib.EDTError: |
| 582 | return "0" |
| 583 | if name == "dt_node_array_prop_int": |
| 584 | return str(_node_array_prop(node, prop, index, unit)) |
| 585 | if name == "dt_node_array_prop_hex": |
| 586 | return hex(_node_array_prop(node, prop, index, unit)) |
| 587 | |
| 588 | |
Erwan Gouriou | a59e01d | 2023-12-18 12:03:43 +0100 | [diff] [blame] | 589 | def dt_node_ph_array_prop(kconf, name, path, prop, index, cell, unit=None): |
| 590 | """ |
| 591 | This function takes a 'path', property name ('prop'), index ('index') and |
| 592 | a cell ('cell') and looks for an EDT node at that path. |
| 593 | If it finds an EDT node, it will look to see if that node has a property |
| 594 | called 'prop' and if that 'prop' is an phandle-array type. |
| 595 | Then it will check if that phandle array has a cell matching the given index |
| 596 | and ten return the value of the cell named 'cell' in this array index as |
| 597 | either a string int or string hex value. If not found we return 0. |
| 598 | |
| 599 | The function will divide the value based on 'unit': |
| 600 | None No division |
| 601 | 'k' or 'K' divide by 1024 (1 << 10) |
| 602 | 'm' or 'M' divide by 1,048,576 (1 << 20) |
| 603 | 'g' or 'G' divide by 1,073,741,824 (1 << 30) |
| 604 | """ |
| 605 | if doc_mode or edt is None: |
| 606 | return "0" |
| 607 | |
| 608 | try: |
| 609 | node = edt.get_node(path) |
| 610 | except edtlib.EDTError: |
| 611 | return "0" |
| 612 | if name == "dt_node_ph_array_prop_int": |
| 613 | return str(_node_ph_array_prop(node, prop, index, cell, unit)) |
| 614 | if name == "dt_node_ph_array_prop_hex": |
| 615 | return hex(_node_ph_array_prop(node, prop, index, cell, unit)) |
| 616 | |
Johann Fischer | 73199f2 | 2021-11-18 17:12:23 +0100 | [diff] [blame] | 617 | def dt_node_str_prop_equals(kconf, _, path, prop, val): |
| 618 | """ |
| 619 | This function takes a 'path' and property name ('prop') looks for an EDT |
| 620 | node at that path. If it finds an EDT node, it will look to see if that |
| 621 | node has a property 'prop' of type string. If that 'prop' is equal to 'val' |
| 622 | it will return "y" otherwise return "n". |
| 623 | """ |
| 624 | |
| 625 | if doc_mode or edt is None: |
| 626 | return "n" |
| 627 | |
| 628 | try: |
| 629 | node = edt.get_node(path) |
| 630 | except edtlib.EDTError: |
| 631 | return "n" |
| 632 | |
| 633 | if prop not in node.props: |
| 634 | return "n" |
| 635 | |
| 636 | if node.props[prop].type != "string": |
| 637 | return "n" |
| 638 | |
| 639 | if node.props[prop].val == val: |
| 640 | return "y" |
| 641 | |
| 642 | return "n" |
Kumar Gala | 338b4319 | 2020-04-03 05:02:35 -0500 | [diff] [blame] | 643 | |
Andrzej Głąbek | 9f2a27b | 2022-03-15 14:08:21 +0100 | [diff] [blame] | 644 | |
| 645 | def dt_has_compat(kconf, _, compat): |
| 646 | """ |
| 647 | This function takes a 'compat' and returns "y" if any compatible node |
| 648 | can be found in the EDT, otherwise it returns "n". |
| 649 | """ |
| 650 | if doc_mode or edt is None: |
| 651 | return "n" |
| 652 | |
| 653 | return "y" if compat in edt.compat2nodes else "n" |
| 654 | |
| 655 | |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 656 | def dt_compat_enabled(kconf, _, compat): |
| 657 | """ |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 658 | This function takes a 'compat' and returns "y" if we find a status "okay" |
Ulf Magnusson | 73ac146 | 2019-09-23 05:14:18 +0200 | [diff] [blame] | 659 | compatible node in the EDT otherwise we return "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 660 | """ |
| 661 | if doc_mode or edt is None: |
| 662 | return "n" |
| 663 | |
Martí Bolívar | 8165008 | 2020-10-05 20:02:13 -0700 | [diff] [blame] | 664 | return "y" if compat in edt.compat2okay else "n" |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 665 | |
| 666 | |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 667 | def dt_compat_on_bus(kconf, _, compat, bus): |
| 668 | """ |
| 669 | This function takes a 'compat' and returns "y" if we find an "enabled" |
| 670 | compatible node in the EDT which is on bus 'bus'. It returns "n" otherwise. |
| 671 | """ |
| 672 | if doc_mode or edt is None: |
| 673 | return "n" |
| 674 | |
Andrzej Głąbek | f9c1f89 | 2021-02-03 13:53:48 +0100 | [diff] [blame] | 675 | if compat in edt.compat2okay: |
| 676 | for node in edt.compat2okay[compat]: |
Daniel Leung | 418c915 | 2022-08-26 10:52:32 -0700 | [diff] [blame] | 677 | if node.on_buses is not None and bus in node.on_buses: |
Andrzej Głąbek | f9c1f89 | 2021-02-03 13:53:48 +0100 | [diff] [blame] | 678 | return "y" |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 679 | |
| 680 | return "n" |
| 681 | |
| 682 | |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 683 | def dt_nodelabel_has_compat(kconf, _, label, compat): |
| 684 | """ |
Andrzej Głąbek | cd00a3a | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 685 | This function takes a 'label' and looks for an EDT node with that label. |
| 686 | If it finds such node, it returns "y" if this node is compatible with |
| 687 | the provided 'compat'. Otherwise, it return "n" . |
| 688 | """ |
| 689 | if doc_mode or edt is None: |
| 690 | return "n" |
| 691 | |
| 692 | node = edt.label2node.get(label) |
| 693 | |
| 694 | if node and compat in node.compats: |
| 695 | return "y" |
| 696 | |
| 697 | return "n" |
| 698 | |
Daniel DeGrasse | 6aa7194 | 2022-08-26 12:12:24 -0500 | [diff] [blame] | 699 | def dt_node_has_compat(kconf, _, path, compat): |
| 700 | """ |
| 701 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 702 | finds an EDT node, it returns "y" if this node is compatible with |
| 703 | the provided 'compat'. Otherwise, it return "n" . |
| 704 | """ |
| 705 | |
| 706 | if doc_mode or edt is None: |
| 707 | return "n" |
| 708 | |
| 709 | try: |
| 710 | node = edt.get_node(path) |
| 711 | except edtlib.EDTError: |
| 712 | return "n" |
| 713 | |
| 714 | if node and compat in node.compats: |
| 715 | return "y" |
| 716 | |
| 717 | return "n" |
Andrzej Głąbek | cd00a3a | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 718 | |
| 719 | def dt_nodelabel_enabled_with_compat(kconf, _, label, compat): |
| 720 | """ |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 721 | This function takes a 'label' and returns "y" if an "enabled" node with |
| 722 | such label can be found in the EDT and that node is compatible with the |
| 723 | provided 'compat', otherwise it returns "n". |
| 724 | """ |
| 725 | if doc_mode or edt is None: |
| 726 | return "n" |
| 727 | |
Andrzej Głąbek | f9c1f89 | 2021-02-03 13:53:48 +0100 | [diff] [blame] | 728 | if compat in edt.compat2okay: |
| 729 | for node in edt.compat2okay[compat]: |
| 730 | if label in node.labels: |
| 731 | return "y" |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 732 | |
| 733 | return "n" |
| 734 | |
| 735 | |
Stephen Stauts | d4b8db7 | 2022-12-27 11:40:17 +0100 | [diff] [blame] | 736 | def dt_nodelabel_array_prop_has_val(kconf, _, label, prop, val): |
| 737 | """ |
| 738 | This function looks for a node with node label 'label'. |
| 739 | If the node exists, it checks if the node node has a property |
| 740 | 'prop' with type "array". If so, and the property contains |
| 741 | an element equal to the integer 'val', it returns "y". |
| 742 | Otherwise, it returns "n". |
| 743 | """ |
| 744 | if doc_mode or edt is None: |
| 745 | return "n" |
| 746 | |
| 747 | node = edt.label2node.get(label) |
| 748 | |
| 749 | if not node or (prop not in node.props) or (node.props[prop].type != "array"): |
| 750 | return "n" |
| 751 | else: |
| 752 | return "y" if int(val, base=0) in node.props[prop].val else "n" |
| 753 | |
| 754 | |
Martí Bolívar | 1fff235 | 2020-04-22 18:06:18 -0700 | [diff] [blame] | 755 | def dt_nodelabel_path(kconf, _, label): |
| 756 | """ |
| 757 | This function takes a node label (not a label property) and |
| 758 | returns the path to the node which has that label, or an empty |
| 759 | string if there is no such node. |
| 760 | """ |
| 761 | if doc_mode or edt is None: |
| 762 | return "" |
| 763 | |
| 764 | node = edt.label2node.get(label) |
| 765 | |
| 766 | return node.path if node else "" |
| 767 | |
Daniel DeGrasse | db9bcd9 | 2022-08-26 12:10:14 -0500 | [diff] [blame] | 768 | def dt_node_parent(kconf, _, path): |
| 769 | """ |
| 770 | This function takes a 'path' and looks for an EDT node at that path. If it |
| 771 | finds an EDT node, it will look for the parent of that node. If the parent |
| 772 | exists, it will return the path to that parent. Otherwise, an empty string |
| 773 | will be returned. |
| 774 | """ |
| 775 | if doc_mode or edt is None: |
| 776 | return "" |
| 777 | |
| 778 | try: |
| 779 | node = edt.get_node(path) |
| 780 | except edtlib.EDTError: |
| 781 | return "" |
| 782 | |
| 783 | if node is None: |
| 784 | return "" |
| 785 | |
| 786 | return node.parent.path if node.parent else "" |
Martí Bolívar | 1fff235 | 2020-04-22 18:06:18 -0700 | [diff] [blame] | 787 | |
Henrik Brix Andersen | fba6c7f | 2023-01-18 17:43:02 +0100 | [diff] [blame] | 788 | def dt_gpio_hogs_enabled(kconf, _): |
| 789 | """ |
| 790 | Return "y" if any GPIO hog node is enabled. Otherwise, return "n". |
| 791 | """ |
| 792 | if doc_mode or edt is None: |
| 793 | return "n" |
| 794 | |
| 795 | for node in edt.nodes: |
| 796 | if node.gpio_hogs and node.status == "okay": |
| 797 | return "y" |
| 798 | |
| 799 | return "n" |
| 800 | |
Erwan Gouriou | 17537c7 | 2019-11-22 10:06:57 +0100 | [diff] [blame] | 801 | def shields_list_contains(kconf, _, shield): |
| 802 | """ |
| 803 | Return "n" if cmake environment variable 'SHIELD_AS_LIST' doesn't exist. |
| 804 | Return "y" if 'shield' is present list obtained after 'SHIELD_AS_LIST' |
| 805 | has been split using ";" as a separator and "n" otherwise. |
| 806 | """ |
| 807 | try: |
| 808 | list = os.environ['SHIELD_AS_LIST'] |
| 809 | except KeyError: |
| 810 | return "n" |
| 811 | |
| 812 | return "y" if shield in list.split(";") else "n" |
| 813 | |
| 814 | |
Martí Bolívar | 006319f | 2020-07-21 15:20:18 -0700 | [diff] [blame] | 815 | # Keys in this dict are the function names as they appear |
| 816 | # in Kconfig files. The values are tuples in this form: |
| 817 | # |
| 818 | # (python_function, minimum_number_of_args, maximum_number_of_args) |
| 819 | # |
| 820 | # Each python function is given a kconf object and its name in the |
| 821 | # Kconfig file, followed by arguments from the Kconfig file. |
| 822 | # |
| 823 | # See the kconfiglib documentation for more details. |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 824 | functions = { |
Andrzej Głąbek | 9f2a27b | 2022-03-15 14:08:21 +0100 | [diff] [blame] | 825 | "dt_has_compat": (dt_has_compat, 1, 1), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 826 | "dt_compat_enabled": (dt_compat_enabled, 1, 1), |
Martí Bolívar | 3cd4f6c | 2020-04-10 15:37:58 -0700 | [diff] [blame] | 827 | "dt_compat_on_bus": (dt_compat_on_bus, 2, 2), |
Kumar Gala | 5735397 | 2019-08-28 09:30:23 -0500 | [diff] [blame] | 828 | "dt_chosen_label": (dt_chosen_label, 1, 1), |
Kumar Gala | 07e5d89 | 2019-11-04 10:20:59 -0600 | [diff] [blame] | 829 | "dt_chosen_enabled": (dt_chosen_enabled, 1, 1), |
Martí Bolívar | 7ff3ebc | 2020-04-23 12:28:06 -0700 | [diff] [blame] | 830 | "dt_chosen_path": (dt_chosen_path, 1, 1), |
Daniel DeGrasse | fbefc50 | 2022-04-11 11:53:03 -0500 | [diff] [blame] | 831 | "dt_chosen_has_compat": (dt_chosen_has_compat, 2, 2), |
Martí Bolívar | 24677f9 | 2020-04-28 16:52:35 -0700 | [diff] [blame] | 832 | "dt_path_enabled": (dt_node_enabled, 1, 1), |
| 833 | "dt_alias_enabled": (dt_node_enabled, 1, 1), |
Kumar Gala | 0353d22 | 2020-02-13 23:43:42 -0600 | [diff] [blame] | 834 | "dt_nodelabel_enabled": (dt_nodelabel_enabled, 1, 1), |
Andrzej Głąbek | cd00a3a | 2022-03-28 12:16:51 +0200 | [diff] [blame] | 835 | "dt_nodelabel_enabled_with_compat": (dt_nodelabel_enabled_with_compat, 2, 2), |
Ulf Magnusson | b4e1807 | 2019-12-23 11:07:27 +0100 | [diff] [blame] | 836 | "dt_chosen_reg_addr_int": (dt_chosen_reg, 1, 3), |
| 837 | "dt_chosen_reg_addr_hex": (dt_chosen_reg, 1, 3), |
| 838 | "dt_chosen_reg_size_int": (dt_chosen_reg, 1, 3), |
| 839 | "dt_chosen_reg_size_hex": (dt_chosen_reg, 1, 3), |
| 840 | "dt_node_reg_addr_int": (dt_node_reg, 1, 3), |
| 841 | "dt_node_reg_addr_hex": (dt_node_reg, 1, 3), |
| 842 | "dt_node_reg_size_int": (dt_node_reg, 1, 3), |
| 843 | "dt_node_reg_size_hex": (dt_node_reg, 1, 3), |
Jordan Yates | 999afdc | 2023-07-30 13:33:33 +1000 | [diff] [blame] | 844 | "dt_nodelabel_reg_addr_int": (dt_nodelabel_reg, 1, 3), |
| 845 | "dt_nodelabel_reg_addr_hex": (dt_nodelabel_reg, 1, 3), |
| 846 | "dt_nodelabel_reg_size_int": (dt_nodelabel_reg, 1, 3), |
| 847 | "dt_nodelabel_reg_size_hex": (dt_nodelabel_reg, 1, 3), |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 848 | "dt_node_bool_prop": (dt_node_bool_prop, 2, 2), |
| 849 | "dt_nodelabel_bool_prop": (dt_nodelabel_bool_prop, 2, 2), |
Stephen Stauts | d4b8db7 | 2022-12-27 11:40:17 +0100 | [diff] [blame] | 850 | "dt_chosen_bool_prop": (dt_chosen_bool_prop, 2, 2), |
Erwan Gouriou | b711028 | 2021-01-07 12:06:31 +0100 | [diff] [blame] | 851 | "dt_node_has_prop": (dt_node_has_prop, 2, 2), |
Michał Barnaś | a1ab8da | 2022-03-08 17:44:04 +0100 | [diff] [blame] | 852 | "dt_nodelabel_has_prop": (dt_nodelabel_has_prop, 2, 2), |
David Leach | 1e5a830 | 2021-11-08 23:24:22 -0600 | [diff] [blame] | 853 | "dt_node_int_prop_int": (dt_node_int_prop, 2, 3), |
| 854 | "dt_node_int_prop_hex": (dt_node_int_prop, 2, 3), |
Eivind Jølsgard | 3865e08 | 2022-03-18 10:50:00 +0100 | [diff] [blame] | 855 | "dt_node_array_prop_int": (dt_node_array_prop, 3, 4), |
| 856 | "dt_node_array_prop_hex": (dt_node_array_prop, 3, 4), |
Erwan Gouriou | a59e01d | 2023-12-18 12:03:43 +0100 | [diff] [blame] | 857 | "dt_node_ph_array_prop_int": (dt_node_ph_array_prop, 4, 5), |
| 858 | "dt_node_ph_array_prop_hex": (dt_node_ph_array_prop, 4, 5), |
Johann Fischer | 73199f2 | 2021-11-18 17:12:23 +0100 | [diff] [blame] | 859 | "dt_node_str_prop_equals": (dt_node_str_prop_equals, 3, 3), |
Andrzej Głąbek | 3331a20 | 2020-02-14 11:53:21 +0100 | [diff] [blame] | 860 | "dt_nodelabel_has_compat": (dt_nodelabel_has_compat, 2, 2), |
Daniel DeGrasse | 6aa7194 | 2022-08-26 12:12:24 -0500 | [diff] [blame] | 861 | "dt_node_has_compat": (dt_node_has_compat, 2, 2), |
Martí Bolívar | 1fff235 | 2020-04-22 18:06:18 -0700 | [diff] [blame] | 862 | "dt_nodelabel_path": (dt_nodelabel_path, 1, 1), |
Daniel DeGrasse | db9bcd9 | 2022-08-26 12:10:14 -0500 | [diff] [blame] | 863 | "dt_node_parent": (dt_node_parent, 1, 1), |
Stephen Stauts | d4b8db7 | 2022-12-27 11:40:17 +0100 | [diff] [blame] | 864 | "dt_nodelabel_array_prop_has_val": (dt_nodelabel_array_prop_has_val, 3, 3), |
Henrik Brix Andersen | fba6c7f | 2023-01-18 17:43:02 +0100 | [diff] [blame] | 865 | "dt_gpio_hogs_enabled": (dt_gpio_hogs_enabled, 0, 0), |
Erwan Gouriou | 17537c7 | 2019-11-22 10:06:57 +0100 | [diff] [blame] | 866 | "shields_list_contains": (shields_list_contains, 1, 1), |
Kumar Gala | 87915cd | 2018-11-15 11:51:50 -0600 | [diff] [blame] | 867 | } |