Lines Matching +full:check +full:- +full:common +full:- +full:files

4 # SPDX-License-Identifier: Apache-2.0
10 This script can be used to automatically migrate the Devicetree files of
11 nRF-based boards using the old <signal>-pin properties to select peripheral
13 file by removing old pin-related properties replacing them with pinctrl states.
14 A board-pinctrl.dtsi file will be generated containing the configuration for
15 all pinctrl states. Note that script will also work on files that have been
20 Devicetree files will be converted correctly. **ADJUSTED/GENERATED FILES
28 -i path/to/board.dts
29 [--no-backup]
30 [--skip-nrf-check]
31 [--header ""]
35 .. code-block:: devicetree
41 tx-pin = <5>;
42 rx-pin = <33>;
43 rx-pull-up;
49 #include "board-pinctrl.dtsi"
53 pinctrl-0 = <&uart0_default>;
54 pinctrl-1 = <&uart0_sleep>;
55 pinctrl-names = "default", "sleep";
59 /* Generated board-pinctrl.dtsi */
67 bias-pull-up;
75 low-power-enable;
97 PULL_UP = "bias-pull-up"
98 PULL_DOWN = "bias-pull-down"
99 LOW_POWER = "low-power-enable"
112 ) -> None:
123 def __init__(self, signal: str, pin: int) -> None:
131 def __init__(self, pins: List[SignalMapping], config: List[PIN_CONFIG]) -> None:
139 def __init__(self, mapping: SignalMapping, config: List[PIN_CONFIG]) -> None:
147 def __init__(self, name: str, pins: List[PinConfiguration]) -> None:
151 def add_signal_config(self, signal: str, config: PIN_CONFIG) -> None:
158 self.pins.append(PinConfiguration(SignalMapping(signal, -1), [config]))
160 def set_signal_pin(self, signal: str, pin: int) -> None:
177 ) -> None:
178 """Generate board-pinctrl.dtsi file
187 pinctrl_file = input_file.parent / (input_file.stem + "-pinctrl.dtsi")
191 for i, line in enumerate(content[::-1]):
193 last_line = len(content) - (i + 1)
206 # create pin groups with common configuration (default state)
242 def board_is_nrf(content: List[str]) -> bool:
243 """Check if board is nRF based.
260 def fmt_pinctrl_groups(groups: List[PinGroup]) -> str:
270 bias-pull-up;
285 suffix = ";" if i == len(group.pins) - 1 else ","
289 pin -= 32
294 # write all pin configuration (bias, low-power, etc.)
303 def fmt_states(device: str, indent: str, needs_sleep: bool) -> str:
318 f"{indent}pinctrl-0 = <&{device}_default>;",
319 f"{indent}pinctrl-1 = <&{device}_sleep>;",
320 f'{indent}pinctrl-names = "default", "sleep";\n',
326 f"{indent}pinctrl-0 = <&{device}_default>;",
327 f'{indent}pinctrl-names = "default";\n',
332 def insert_pinctrl_include(content: List[str], board: str) -> None:
341 include_last_line = -1
342 root_line = -1
345 # check if file already includes a board pinctrl file
346 m = re.match(r'^#include\s+".*-pinctrl\.dtsi".*', line)
351 # check if including
357 # check for root entry
370 line = max(0, root_line - 1)
372 content.insert(line, f'#include "{board}-pinctrl.dtsi"\n')
375 def adjust_content(content: List[str], board: str) -> List[DeviceConfiguration]:
393 m = re.match(r"^[^&]*&([a-z0-9]+)\s*{[^}]*$", line)
395 # check if device requires processing
415 level -= 1
419 if re.match(r"[^\/\*]*pinctrl-\d+.*", line):
458 ) -> Optional[str]:
470 # handle qspi special case for io-pins (array case)
471 m = re.match(r"\s*io-pins\s*=\s*([\s<>,0-9]+).*", line)
478 m = re.match(r"\s*([a-z]+\d?)-pins?\s*=\s*<(\d+)>.*", line)
491 def process_uart(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
494 # check if line specifies a pin
498 # check if pull-up is specified
499 m = re.match(r"\s*([a-z]+)-pull-up.*", line)
507 def process_spi(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
510 # check if line specifies a pin
514 # check if pull-up is specified
515 m = re.match(r"\s*miso-pull-up.*", line)
520 # check if pull-down is specified
521 m = re.match(r"\s*miso-pull-down.*", line)
529 def process_pwm(config: DeviceConfiguration, signals, line: str) -> Optional[str]:
532 # check if line specifies a pin
536 # check if channel inversion is specified
537 m = re.match(r"\s*([a-z0-9]+)-inverted.*", line)
635 def main(input_file: Path, no_backup: bool, skip_nrf_check: bool, header: str) -> None:
640 no_backup: Do not create backup files.
670 "-i", "--input", type=Path, required=True, help="Board DTS file"
673 "--no-backup", action="store_true", help="Do not create backup files"
676 "--skip-nrf-check",
678 help="Skip checking if board is nRF-based",
681 "--header", default="", type=str, help="Header to be prepended to pinctrl files"