Lines Matching +full:pin +full:- +full:header
4 # SPDX-License-Identifier: Apache-2.0
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
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;
95 """Pin configuration attributes"""
97 PULL_UP = "bias-pull-up"
98 PULL_DOWN = "bias-pull-down"
99 LOW_POWER = "low-power-enable"
112 ) -> None:
121 """Signal mapping (signal<>pin)"""
123 def __init__(self, signal: str, pin: int) -> None:
125 self.pin = pin
129 """Pin group"""
131 def __init__(self, pins: List[SignalMapping], config: List[PIN_CONFIG]) -> None:
137 """Pin configuration (mapping and configuration)"""
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:
153 for pin in self.pins:
154 if signal == pin.mapping.signal:
155 pin.config.append(config)
158 self.pins.append(PinConfiguration(SignalMapping(signal, -1), [config]))
160 def set_signal_pin(self, signal: str, pin: int) -> None:
161 """Set signal pin"""
164 pin_.mapping.pin = pin
167 self.pins.append(PinConfiguration(SignalMapping(signal, pin), []))
176 configs: List[DeviceConfiguration], input_file: Path, header: str
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)
199 out.write(header)
206 # create pin groups with common configuration (default state)
208 for pin in config.pins:
211 if group.config == pin.config:
212 group.pins.append(pin.mapping)
216 default_groups.append(PinGroup([pin.mapping], pin.config))
218 # create pin group for low power state
220 for pin in config.pins:
221 group.pins.append(pin.mapping)
242 def board_is_nrf(content: List[str]) -> bool:
260 def fmt_pinctrl_groups(groups: List[PinGroup]) -> str:
270 bias-pull-up;
285 suffix = ";" if i == len(group.pins) - 1 else ","
286 pin = mapping.pin
287 port = 0 if pin < 32 else 1
289 pin -= 32
291 f"\t\t\t{prefix}<NRF_PSEL({mapping.signal}, {port}, {pin})>{suffix}\n"
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
346 m = re.match(r'^#include\s+".*-pinctrl\.dtsi".*', line)
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)
415 level -= 1
419 if re.match(r"[^\/\*]*pinctrl-\d+.*", line):
458 ) -> Optional[str]:
459 """Match and store a pin mapping.
464 line: Line containing potential pin mapping.
467 Line if found a pin mapping, None otherwise.
470 # handle qspi special case for io-pins (array case)
471 m = re.match(r"\s*io-pins\s*=\s*([\s<>,0-9]+).*", line)
474 for i, pin in enumerate(pins):
475 config.set_signal_pin(signals[f"io{i}"], int(pin))
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
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:
660 gen_pinctrl(configs, input_file, header)
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"
685 main(args.input, args.no_backup, args.skip_nrf_check, args.header)