Skip to content

Commit 0338efd

Browse files
committed
scripts: gen_pinctrl: Support fixed GPIO routes
Add support for generating fixed GPIO routes, mainly used for debug and trace signals. Signed-off-by: Aksel Skauge Mellbye <[email protected]>
1 parent 40a0237 commit 0338efd

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/gen_pinctrl.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
"ANTTRIGSTOP": "ANT_TRIG_STOP",
9494
"BUFOUTREQINASYNC": "BUFOUT_REQ_IN_ASYNC",
9595
"USBVBUSSENSE": "USB_VBUS_SENSE",
96+
"SWCLKTCK": "SWCLK",
97+
"SWDIOTMS": "SWDIO",
9698
}
9799

98100
# Expected offset of DBGROUTEPEN register across all of Series 2.
@@ -109,12 +111,12 @@ def __init__(self, name, offset):
109111
def max_signal_len(self):
110112
return max(len(s.name) for s in self.signals)
111113

112-
def set_signal_enable(self, name, bit):
114+
def set_signal_enable(self, name, bit, offset=0):
113115
for signal in self.signals:
114116
if signal.name == name:
115117
break
116118
else:
117-
signal = Signal(name, self)
119+
signal = Signal(name, self, offset)
118120
self.signals.append(signal)
119121

120122
signal.have_enable = True
@@ -132,8 +134,9 @@ def set_signal_route(self, name, offset):
132134

133135

134136
class Signal:
135-
def __init__(self, name, peripheral):
137+
def __init__(self, name, peripheral, offset=0):
136138
self.peripheral = peripheral
139+
self.offset = offset
137140
self.name = name
138141
self.route = None
139142
self.have_enable = False
@@ -189,6 +192,18 @@ def parse_svd(peripherals, path: Path, family: str) -> None:
189192

190193
reg_offset_word = (reg.address_offset - PINCTRL_GPIO_OFFSET) // 4
191194

195+
if reg.name.endswith("ROUTEPEN"):
196+
peripheral = "GPIO"
197+
if peripheral not in peripherals:
198+
peripherals[peripheral] = Peripheral(peripheral, reg_offset_word)
199+
200+
for field in reg.fields:
201+
if field.name.endswith("PEN"):
202+
signal = field.name[:-3]
203+
signal = SIGNAL_ALIAS.get(signal, signal)
204+
signal = SIGNAL_ALIAS.get(f"{peripheral}::{signal}", signal)
205+
peripherals[peripheral].set_signal_enable(signal, field.bit_offset, reg_offset_word)
206+
192207
if reg.name.endswith("_ROUTEEN"):
193208
peripheral = reg.name[:-8]
194209
peripheral = PERIPHERAL_ALIAS.get(peripheral, peripheral)
@@ -289,8 +304,12 @@ def write_header(path: Path, family, peripherals: dict, abuses: list) -> None:
289304
for port, pins in signal.pinout.items():
290305
for pin in sorted(pins):
291306
pad = peripheral.max_signal_len() - len(signal.name) + 1
292-
lines.append(f"#define {signal.display_name()}_P{chr(65 + port)}{pin}{' ' * pad}"
293-
f"SILABS_DBUS_{signal.display_name()}(0x{port:x}, 0x{pin:x})")
307+
if signal.route is not None:
308+
lines.append(f"#define {signal.display_name()}_P{chr(65 + port)}{pin}{' ' * pad}"
309+
f"SILABS_DBUS_{signal.display_name()}(0x{port:x}, 0x{pin:x})")
310+
else:
311+
lines.append(f"#define {signal.display_name()}_P{chr(65 + port)}{pin}{' ' * pad}"
312+
f"SILABS_FIXED_ROUTE(0x{port:x}, 0x{pin:x}, {signal.offset}, {signal.enable})")
294313
have_content = True
295314
if have_content:
296315
lines.append("")

0 commit comments

Comments
 (0)