diff mbox

[00/11] Enable gpu switching on the MacBook Pro

Message ID 20150425142004.GA1108@wunner.de (mailing list archive)
State New, archived
Headers show

Commit Message

Lukas Wunner April 25, 2015, 2:20 p.m. UTC
Hi,

On Tue, Apr 21, 2015 at 08:49:35PM +0100, Matthew Garrett wrote:
> My testing suggested that changing the DDC lines didn't change auxch, so
> this approach doesn't work for eDP. Have you found otherwise?

Disassembling the OS X gmux driver (AppleMuxControl 3.6.22) revealed
that register 0x7F is set prior to accessing the eDP connector.
It seems plausible that this register switches the AUX channel
between GPUs.

More specifically, there's a method AppleMuxControl::TickleStateMachine()
which puts the gmux into various states. The code to switch only the
DDC lines starts at address d4bc and sets register 0x7F, then calls
AppleMuxControl::copyEDPConfig(), then sets register 0x28 (DDC).

Likewise, the code to switch the entire display starts at address db6a,
it sets registers 0x10 (DISPLAY), 0x28 (DDC), 0x40 (EXTERNAL) and 0x7F,
then calls calling AppleMuxControl::fbDoEDPLinkConfig().

Included below is a tentative patch to set register 0x7F when switching
the DDC lines. It would be great if someone with a retina could test
the patchset I've posted plus this tentative patch since I can't test it
myself.

Here's the lowdown on which patches are needed for each MBP generation:

* MacBookPro6 / 8 / 9 (pre-retina):
  The patchset I've posted plus this one to enable dual channel LVDS:
  http://lists.freedesktop.org/archives/intel-gfx/2015-April/064850.html
  (This obviates the need to specify i915.lvds_channel_mode=2)

* MacBookPro10 (first-gen retina):
  The patchset I've posted plus the tentative patch below.

* MacBookPro11 (second-gen retina):
  The patchset I've posted plus the tentative patch below.
  Fellow gmux hackers Andreas Heider and Bruno Bierbaumer tell me that
  additionally, this patch is needed otherwise the i915 gpu is turned off:
  https://www.marc.info/?l=grub-deavel&m=141586614924917&w=2

Kind regards,

Lukas

-- >8 --

Comments

Lu, Ran May 2, 2015, 7:03 p.m. UTC | #1
Hi Lukas,

Lukas Wunner wrote:
> Included below is a tentative patch to set register 0x7F when switching
> the DDC lines. It would be great if someone with a retina could test
> the patchset I've posted plus this tentative patch since I can't test it
> myself.
> 
> * MacBookPro11 (second-gen retina):
>   The patchset I've posted plus the tentative patch below.
>   Fellow gmux hackers Andreas Heider and Bruno Bierbaumer tell me that
>   additionally, this patch is needed otherwise the i915 gpu is turned off:
>   https://www.marc.info/?l=grub-deavel&m=141586614924917&w=2

Thank you very much for your effort of bringing gpu switching to RMBP, I 
tried your patchset, including the one in this email, on my laptop. It is a 
Retina MacBookPro, late 2013 version, which is how ifixit calls it. It seems 
to work at least partially. Here is the results I observed.

First of all, I use gfxstatus in OSX to force the system to use the intel 
gpu. So when I boot into Linux the intel gpu will be activated and I can 
turn of the discrete nvidia gpu to save power.

After booted with the patched kernel (on top of v4.0). I can use "echo DIS > 
/sys/kernel/debug/vgaswitcheroo/switch" to switch to the nvidia gpu. The 
console turned black, I guess the system is incapable of switching to the 
nouveau's framebuffer at this moment. But after I startx through ssh, I can 
use everything without any problem. After quit the X the framebuffer is 
recovered as well. I can switch back to intel gpu and start X again no 
problem. However when I activated the discrete gpu again, I got a black 
screen after startx, the log of X seems normal, just no display on the 
screen.

I also tried to use the gfxstatus to resume the "normal" (dynamical 
switching) behavior in OSX. Then the nvidia gpu will be used when booting to 
linux. I switched to the intel gpu but it appears the gpu did not find the 
correct screen. After startx I got a black screen, xrandr does not give me 
the eDP output, only some Virtual and VGA outputs.

I hope these information can help to improve those patches. I am happy to 
try any (hopefully not dangerous) patches if you have any new ones.
diff mbox

Patch

diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 05bba92..719cfd3 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -60,6 +60,7 @@  static struct apple_gmux_data *apple_gmux_data;
 #define GMUX_PORT_DISCRETE_POWER	0x50
 #define GMUX_PORT_MAX_BRIGHTNESS	0x70
 #define GMUX_PORT_BRIGHTNESS		0x74
+#define GMUX_PORT_SWITCH_AUXCH		0x7F
 #define GMUX_PORT_VALUE			0xc2
 #define GMUX_PORT_READ			0xd0
 #define GMUX_PORT_WRITE			0xd4
@@ -285,10 +286,13 @@  static int gmux_switch_ddc(enum vga_switcheroo_client_id id)
 	if (id == old_ddc_owner)
 		return old_ddc_owner;
 
-	if (id == VGA_SWITCHEROO_IGD)
+	if (id == VGA_SWITCHEROO_IGD) {
+		gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_AUXCH, 1);
 		gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_DDC, 1);
-	else
+	} else {
+		gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_AUXCH, 2);
 		gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_DDC, 2);
+	}
 
 	return old_ddc_owner;
 }