From 96ca7ee67a36605a33de8d57eb8e8d3998bc6427 Mon Sep 17 00:00:00 2001
From: Michał Masłowski <mtjm@mtjm.eu>
Date: Wed, 03 Sep 2014 14:30:21 -0400
Subject: Merge libreboot-6b6.

Conflicts:
	buildrom-withgrub
---
(limited to 'resources/utilities/i945gpu')

diff --git a/resources/utilities/i945gpu/intel-regs.py b/resources/utilities/i945gpu/intel-regs.py
index f16a8d7..5767d4a 100755
--- a/resources/utilities/i945gpu/intel-regs.py
+++ b/resources/utilities/i945gpu/intel-regs.py
@@ -27,17 +27,31 @@ _MEMORY = re.compile(r"^\s+Memory\s+at\s+([0-9a-f]+)\s+\(32-bit, non-prefetchabl
 
 def get_pci_data():
     # lspci has a machine readable format, but it doesn't have the needed data.
-    for devid in "8086:27a2", "8086:27a6":
+    for devid in ("8086:27a2",):
         lspci = subprocess.Popen(("lspci", "-vn", "-d", devid),
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
+        address = None
+        memory = None
         for line in lspci.communicate()[0].split("\n"):
+            if line and line[0] == "0":
+                address = line.split()[0]
             match = _MEMORY.match(line)
             if match is not None:
-                yield int(match.group(1), 16)
+                memory = int(match.group(1), 16)
                 break
+        yield (address, memory)
 
-func0, func1 = list(get_pci_data())
+
+def config_byte(address, offset):
+    """Return byte at specified offset in PCI config space of device
+    identified by address."""
+    with open("/sys/bus/pci/devices/0000:%s/config" % address, "rb") as f:
+        f.seek(offset)
+        return struct.unpack("=B", f.read(1))
+
+
+addr0, func0 = list(get_pci_data())[0]
 
 
 def read32(fo, base, offset):
@@ -91,3 +105,4 @@ if __name__ == "__main__":
         print "backlight modulation frequency = %f Hz" % mod_freq
         print "duty cycle = %d%%" % (100.0 * (backlight & 0xffff)
                                      / (backlight >> 16))
+        print "legacy backlight brightness = 0x%02x" % config_byte(addr0, 0xf4)
--
cgit v0.9.1