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>
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))