apple-gmux: Track switch state
gmux has 3 switch registers:
* GMUX_PORT_SWITCH_DISPLAY switches the panel
* GMUX_PORT_SWITCH_DDC switches the panel's DDC lines
(only on pre-retinas; on retinas this is a no-op)
* GMUX_PORT_SWITCH_EXTERNAL switches the external DP port(s)
(only on models without Thunderbolt, i.e. introduced before 2011;
those with Thunderbolt switch only HPD/AUX, not the main link)
Currently we switch all 3 registers in unison.
gmux does not preserve the switch state during suspend, so we currently
read GMUX_PORT_SWITCH_DISPLAY before suspend and restore all 3 registers
to this value on resume.
With the upcoming ->switch_ddc callback, GMUX_PORT_SWITCH_DDC may
temporarily contain a different value than the other 2 registers.
If we happen to suspend at this moment, we'll write an incorrect
value to GMUX_PORT_SWITCH_DDC on resume.
Also, on models with Thunderbolt the integrated GPU is unable to drive
the external DP port(s), so we want to keep GMUX_PORT_SWITCH_EXTERNAL
permanently switched to the discrete GPU on those machines.
Consequently we can no longer assume that GMUX_PORT_SWITCH_DISPLAY
represents the correct value for all 3 registers on suspend.
Track the state of all 3 registers: Add gmux_read_switch_state() and
gmux_write_switch_state(). Instead of reading the switch state on
every suspend, read it once on driver initialization so that we know
the current switch state all the time. (This allows us to use some
optimizations and shortcuts, e.g. we can skip switching DDC if we
know that it's already switched to the requested GPU.) Change the
->switchto callback to use gmux_write_switch_state().
Tested-by: Lukas Wunner <lukas@wunner.de>
[MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/5679f414cb0ddf1654dcc359571f3764b275edf0.1452525860.git.lukas@wunner.de