summaryrefslogtreecommitdiffstats
path: root/pysystemmgr
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2017-02-06 15:00:16 +1030
committerAndrew Jeffery <andrew@aj.id.au>2017-02-06 16:14:30 +1030
commited9ff7013e6e74d2ade8b751d7982981fd7387c8 (patch)
tree2f8906802ba1afcfe5914875c04a06ef54d583e5 /pysystemmgr
parent57eea1bfc3ed9a36c7d6ce09208ed82f1afdd045 (diff)
downloadtalos-skeleton-ed9ff7013e6e74d2ade8b751d7982981fd7387c8.tar.gz
talos-skeleton-ed9ff7013e6e74d2ade8b751d7982981fd7387c8.zip
pysystemmgr: Dynamically locate the gpiochip
This is required due to differences in the number of GPIOs between AST2400 and AST2500, which affects base GPIO value in the GPIO number space. Change-Id: I755aa340dc6a06a47a43bff8afb99d3a75f39185 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'pysystemmgr')
-rw-r--r--pysystemmgr/obmc/system/__init__.py16
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))
OpenPOWER on IntegriCloud