From 369514a11aaeab1b4c133e36b8cac30d3fb47ed0 Mon Sep 17 00:00:00 2001 From: Steve Jeong Date: Thu, 7 Dec 2023 02:53:15 +0000 Subject: [PATCH] microcontroller/alias: Add new script for link aliased devices. Signed-off-by: Steve Jeong --- src/adafruit_blinka/microcontroller/alias.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/adafruit_blinka/microcontroller/alias.py diff --git a/src/adafruit_blinka/microcontroller/alias.py b/src/adafruit_blinka/microcontroller/alias.py new file mode 100644 index 0000000..7347242 --- /dev/null +++ b/src/adafruit_blinka/microcontroller/alias.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2023 Steve Jeong for Hardkernel +# +# SPDX-License-Identifier: MIT + +from typing import Optional +import os +import re + +def get_dts_alias(device: str) -> Optional[str]: + """Get the Device Tree Alias""" + uevent_path = "/sys/bus/platform/devices/" + device + "/uevent" + if os.path.exists(uevent_path): + with open(uevent_path, "r", encoding="utf-8") as fd: + pattern = r"^OF_ALIAS_0=(.*)$" + uevent = fd.read().split("\n") + for line in uevent: + match = re.search(pattern, line) + if match: + return match.group(1).upper() + return None -- 2.49.0