diff options
Diffstat (limited to 'pysystemmgr')
-rw-r--r-- | pysystemmgr/obmc/system/__init__.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pysystemmgr/obmc/system/__init__.py b/pysystemmgr/obmc/system/__init__.py index 9a2a50a..ff6c537 100644 --- a/pysystemmgr/obmc/system/__init__.py +++ b/pysystemmgr/obmc/system/__init__.py @@ -1,4 +1,18 @@ -GPIO_BASE = 320 +from os.path import join +from glob import glob + +def find_gpio_base(path="/sys/class/gpio/"): + pattern = "gpiochip*" + for gc in glob(join(path, pattern)): + with open(join(gc, "label")) as f: + label = f.readline().strip() + if label == "1e780000.gpio": + with open(join(gc, "base")) as f: + return int(f.readline().strip()) + # trigger a file not found exception + open(join(path, "gpiochip")) + +GPIO_BASE = find_gpio_base() def convertGpio(name): offset = int(filter(str.isdigit, name)) |