Skip to contentSkip to conversation

apple-gmux: Fixes related to 'Support for new hardware'

PATCH New Bernhard Froemel 1 participant 3 messages Aug 24, 2012 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

cover apple-gmux: Fixes related to 'Support for new hardware'

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear Seth and Matthew,

the following two patches contain my previous input from:
http://www.mail-archive.com/[email protected]/msg03651.html

Please consider them for the next rc.

Thanks,
Bernhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA3MU0ACgkQ6iVUjPs37Jm1hgCgqWoQfFmw/bJcuG59nLA6c5LG UlkAn2QBEhzDoIwjuKF0bEJ/qoCSwDXv
=vqIy
-----END PGP SIGNATURE-----

#1 lore raw

PATCH 1/2 apple-gmux: fixes concerning access to indexed gmux

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This patch is based on my analysis of the binary Apple gmux OSX driver. Apple apparently follows for byte writes both protocols: the indexed and the direct mapped one.
During my tests, gmux register writes and reads never failed, while without this patch both writes and reads if done consecutively often fail. Failed writes obviously affect switching from one GPU to another (e.g., also during suspend/resume causing all kinds of problems: black screen to complete system lockup).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA3NZ0ACgkQ6iVUjPs37JlpJQCdF1Rla8AE2honZ1efQbWxfLOH 4ZEAnRTY85DDplkCN2yj35jXlWQq6NMO
=Eg8m
-----END PGP SIGNATURE-----

drivers/platform/x86/apple-gmux.c +6 -6
@@ -19,7 +19,6 @@
 #include <linux/pnp.h>
 #include <linux/apple_bl.h>
 #include <linux/slab.h>
-#include <linux/delay.h>
 #include <linux/pci.h>
 #include <linux/vga_switcheroo.h>
 #include <acpi/video.h>
@@ -113,7 +112,6 @@
 	while (i && (gwr & 0x01)) {
 		inb(gmux_data->iostart + GMUX_PORT_READ);
 		gwr = inb(gmux_data->iostart + GMUX_PORT_WRITE);
-		udelay(100);
 		i--;
 	}
 
@@ -127,11 +125,10 @@
 
 	while (i && !(gwr & 0x01)) {
 		gwr = inb(gmux_data->iostart + GMUX_PORT_WRITE);
-		udelay(100);
 		i--;
 	}
 
-	if (gwr & 0x01)
+	if (!(gwr & 0x01))
 		inb(gmux_data->iostart + GMUX_PORT_READ);
 
 	return !!i;
@@ -142,8 +139,9 @@
 	u8 val;
 
 	mutex_lock(&gmux_data->index_lock);
-	outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
 	gmux_index_wait_ready(gmux_data);
+	outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
+	gmux_index_wait_complete(gmux_data);
 	val = inb(gmux_data->iostart + GMUX_PORT_VALUE);
 	mutex_unlock(&gmux_data->index_lock);
 
@@ -153,6 +151,7 @@
 static void gmux_index_write8(struct apple_gmux_data *gmux_data, int port,
 			      u8 val)
 {
+	outb(val, gmux_data->iostart + port);
 	mutex_lock(&gmux_data->index_lock);
 	outb(val, gmux_data->iostart + GMUX_PORT_VALUE);
 	gmux_index_wait_ready(gmux_data);
@@ -166,8 +165,9 @@
 	u32 val;
 
 	mutex_lock(&gmux_data->index_lock);
-	outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
 	gmux_index_wait_ready(gmux_data);
+	outb((port & 0xff), gmux_data->iostart + GMUX_PORT_READ);
+	gmux_index_wait_complete(gmux_data);
 	val = inl(gmux_data->iostart + GMUX_PORT_VALUE);
 	mutex_unlock(&gmux_data->index_lock);
 
#2 lore raw

PATCH 2/2 apple-gmux: obtain version information from indexed gmux

In reply to Bernhard Froemel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

With the introduced read fixes, version information can be extracted from the indexed gmux device.

Quoted 1 line

apple_gmux: Found gmux version 3.2.19 [indexed]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlA3NlwACgkQ6iVUjPs37Jmr4wCfbG0eE8bZFsnZ8t9YxdOH5VII OUsAn04UNm0uPrEMlSc5vFcOAcgNOAz0
=FObp
-----END PGP SIGNATURE-----

drivers/platform/x86/apple-gmux.c +8 -4
@@ -461,18 +461,22 @@
 	ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE);
 	if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
 		if (gmux_is_indexed(gmux_data)) {
+			u32 version;
 			mutex_init(&gmux_data->index_lock);
 			gmux_data->indexed = true;
+			version = gmux_read32(gmux_data,
+				GMUX_PORT_VERSION_MAJOR);
+			ver_major = (version >> 24) & 0xff;
+			ver_minor = (version >> 16) & 0xff;
+			ver_release = (version >> 8) & 0xff;
 		} else {
 			pr_info("gmux device not present\n");
 			ret = -ENODEV;
 			goto err_release;
 		}
-		pr_info("Found indexed gmux\n");
-	} else {
-		pr_info("Found gmux version %d.%d.%d\n", ver_major, ver_minor,
-			ver_release);
 	}
+	pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
+		ver_release, (gmux_data->indexed ? "indexed" : "classic"));
 
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_PLATFORM;