From bb874bc842f94619914fdcb5ce5de87a3edc42b5 Mon Sep 17 00:00:00 2001 From: Bennet Leins Date: Mon, 8 Sep 2025 10:11:21 +0200 Subject: [PATCH 1/2] GPIO: Fix Button detection --- dts2repl/dts2repl.py | 7 ++++++- dts2repl/models.json | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dts2repl/dts2repl.py b/dts2repl/dts2repl.py index 4f7c4bf..5bb6767 100755 --- a/dts2repl/dts2repl.py +++ b/dts2repl/dts2repl.py @@ -1066,11 +1066,16 @@ def generate(filename, override_system_clock_frequency=None): if compatible and 'gpio-leds' in compatible: logging.debug(f'Skipping LED parent node {node.name}') continue + elif compatible and 'gpio-keys' in compatible: + logging.debug(f'Skipping Button parent node {node.name}') + continue else: parent_compat = get_node_prop(node.parent, 'compatible', []) if node.parent else [] # if the paren't compat string is the one for LEDs, move it down to each individual LED if 'gpio-leds' in parent_compat: compatible = parent_compat + if 'gpio-keys' in parent_compat: + compatible = parent_compat if compatible is None: logging.debug(f'Node {node.name} has no compat string. Trying device_type...') @@ -1526,7 +1531,7 @@ def create_per_cpu_model(cpu_name, model_name, csharp_model_name, offset, argume i2c_addr = int(node.unit_addr, 16) regions = [RegistrationRegion(addresses=[i2c_addr], registration_point=i2c_name)] - if model == 'Miscellaneous.LED': + if model in ['Miscellaneous.LED', 'Miscellaneous.Button']: gpios = list(get_node_prop(node, 'gpios')) if not gpios: logging.info(f'LED {node.name} has no gpios property, skipping...') diff --git a/dts2repl/models.json b/dts2repl/models.json index 4923363..27598e5 100644 --- a/dts2repl/models.json +++ b/dts2repl/models.json @@ -188,6 +188,7 @@ "_": "UART.GD32_UART" }, "gpio-leds": "Miscellaneous.LED", + "gpio-keys":"Miscellaneous.Button", "ingenic,jz4780-uart": "UART.NS16550", "microchip,xec-uart": "UART.NS16550", From 7e0d3c464b85a394bad4e1c92d55deae71975e12 Mon Sep 17 00:00:00 2001 From: Bennet Leins Date: Fri, 19 Sep 2025 14:18:07 +0200 Subject: [PATCH 2/2] fixed interrupt connections --- dts2repl/dts2repl.py | 37 ++++++++++++++++++++++++++++++++++++- dts2repl/models.json | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dts2repl/dts2repl.py b/dts2repl/dts2repl.py index 5bb6767..faab385 100755 --- a/dts2repl/dts2repl.py +++ b/dts2repl/dts2repl.py @@ -1531,7 +1531,42 @@ def create_per_cpu_model(cpu_name, model_name, csharp_model_name, offset, argume i2c_addr = int(node.unit_addr, 16) regions = [RegistrationRegion(addresses=[i2c_addr], registration_point=i2c_name)] - if model in ['Miscellaneous.LED', 'Miscellaneous.Button']: + # handle Button + if model == 'Miscellaneous.Button': + gpios = list(get_node_prop(node, 'gpios')) + if not gpios: + logging.info(f'LED {node.name} has no gpios property, skipping...') + continue + gpio, num, gpio_flags = gpios[0][:3] + gpio_compat = get_node_prop(gpio, 'compatible', []) + if 'nxp,s32-gpio' in gpio_compat: + # We have to translate gpio pin to pad + gpio_addr = int(gpio.unit_addr, 16) + gpio_base_addr = gpio_addr & ~0xFFFF + port_index = int((gpio_addr - gpio_base_addr - 0x1700) / 0x4) + num = port_index * 32 + num + gpio = gpio.parent + + gpio_model = get_model(gpio) + if not gpio_model or not gpio_model.startswith("GPIO"): + # don't add invalid GPIO connections + continue + + active_low = (gpio_flags & 1) == 1 + if active_low: + indent.append('invert: true') + gpio_name = name_mapper.get_name(gpio) + regions = [RegistrationRegion(num, registration_point=gpio_name)] + + indent.append(f'-> {name}@{num}') + + # gpio_connection = ReplBlock(gpio_name, None, {gpio_name, name}, set(), + # [f'{gpio_name}:', f' {num} -> {name}@0']) + # repl_file.add_block(gpio_connection) + + + # handle LED + if model == 'Miscellaneous.LED': gpios = list(get_node_prop(node, 'gpios')) if not gpios: logging.info(f'LED {node.name} has no gpios property, skipping...') diff --git a/dts2repl/models.json b/dts2repl/models.json index 27598e5..8e3124d 100644 --- a/dts2repl/models.json +++ b/dts2repl/models.json @@ -188,7 +188,7 @@ "_": "UART.GD32_UART" }, "gpio-leds": "Miscellaneous.LED", - "gpio-keys":"Miscellaneous.Button", + "gpio-keys": "Miscellaneous.Button", "ingenic,jz4780-uart": "UART.NS16550", "microchip,xec-uart": "UART.NS16550",