All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: dri-devel@lists.freedesktop.org
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>,
	platform-driver-x86@vger.kernel.org
Subject: [PATCH 2/5] apple-gmux: Don't switch external DP port on 2011+ MacBook Pros
Date: Fri, 24 Feb 2017 20:19:45 +0100	[thread overview]
Message-ID: <8c06c7eaf3d4a6ec3e2d75191ef26ebd554c24db.1487938188.git.lukas@wunner.de> (raw)
In-Reply-To: <cover.1487938188.git.lukas@wunner.de>

On MacBook Pros introduced 2011 and onward, external DP ports are
combined DP/Thunderbolt ports that are no longer fully switchable
between GPUs, they can only be driven by the discrete GPU.

More specifically, the Main Link pins (which transport the actual video
and audio streams) are soldered to the discrete GPU, whereas the AUX
Channel pins are switchable. Because the integrated GPU is missing the
Main Link, external displays appear to it as phantoms which fail to
link-train.

Force the AUX channel to the discrete GPU on these models to avoid any
confusion. Document the switching policy implemented by this commit.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
 drivers/platform/x86/apple-gmux.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index a66be137324c..623d322447a2 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -60,6 +60,7 @@ struct apple_gmux_data {
 	/* switcheroo data */
 	acpi_handle dhandle;
 	int gpe;
+	bool external_switchable;
 	enum vga_switcheroo_client_id switch_state_display;
 	enum vga_switcheroo_client_id switch_state_ddc;
 	enum vga_switcheroo_client_id switch_state_external;
@@ -358,6 +359,19 @@ static const struct backlight_ops gmux_bl_ops = {
  * ports while the discrete GPU is asleep, but currently we do not make use
  * of this feature.
  *
+ * Our switching policy for the external port is that on those generations
+ * which are able to switch it fully, the port is switched together with the
+ * panel when IGD / DIS commands are issued to vga_switcheroo. It is thus
+ * possible to drive e.g. a beamer on battery power with the integrated GPU.
+ * The user may manually switch to the discrete GPU if more performance is
+ * needed.
+ *
+ * On all newer generations, the external port can only be driven by the
+ * discrete GPU. If a display is plugged in while the panel is switched to
+ * the integrated GPU, *both* GPUs will be in use for maximum performance.
+ * To decrease power consumption, the user may manually switch to the
+ * discrete GPU, thereby suspending the integrated GPU.
+ *
  * gmux' initial switch state on bootup is user configurable via the EFI
  * variable ``gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9`` (5th byte,
  * 1 = IGD, 0 = DIS). Based on this setting, the EFI firmware tells gmux to
@@ -414,7 +428,8 @@ static int gmux_switchto(enum vga_switcheroo_client_id id)
 {
 	apple_gmux_data->switch_state_ddc = id;
 	apple_gmux_data->switch_state_display = id;
-	apple_gmux_data->switch_state_external = id;
+	if (apple_gmux_data->external_switchable)
+		apple_gmux_data->switch_state_external = id;
 
 	gmux_write_switch_state(apple_gmux_data);
 
@@ -601,6 +616,11 @@ static struct pci_dev *gmux_get_io_pdev(void)
 	return NULL;
 }
 
+static int is_thunderbolt(struct device *dev, void *data)
+{
+	return to_pci_dev(dev)->is_thunderbolt;
+}
+
 static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 {
 	struct apple_gmux_data *gmux_data;
@@ -755,6 +775,15 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 		gmux_data->gpe = -1;
 	}
 
+	/*
+	 * If Thunderbolt is present, the external DP port is not fully
+	 * switchable. Force its AUX channel to the discrete GPU.
+	 */
+	gmux_data->external_switchable =
+		!bus_for_each_dev(&pci_bus_type, NULL, NULL, is_thunderbolt);
+	if (!gmux_data->external_switchable)
+		gmux_write8(gmux_data, GMUX_PORT_SWITCH_EXTERNAL, 3);
+
 	apple_gmux_data = gmux_data;
 	init_completion(&gmux_data->powerchange_done);
 	gmux_enable_interrupts(gmux_data);
-- 
2.11.0

  parent reply	other threads:[~2017-02-24 19:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 19:19 [PATCH 0/5] Thunderbolt GPU fixes Lukas Wunner
2017-02-24 19:19 ` Lukas Wunner
2017-02-24 19:19 ` [PATCH 4/5] drm/radeon: Don't register Thunderbolt eGPU with vga_switcheroo Lukas Wunner
     [not found]   ` <d466d25ba40b5289f2cafa881b990bf687b29abd.1487938189.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-03-07 20:30     ` Alex Deucher
2017-03-08  5:01       ` Lukas Wunner
2017-03-08 10:46         ` Peter Wu
2017-03-08 12:22           ` Lukas Wunner
     [not found]         ` <20170308050154.GA4250-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-03-08 20:34           ` Alex Deucher
2017-03-09 10:55             ` Lukas Wunner
2017-03-09 13:57               ` Alex Deucher
2017-02-24 19:19 ` [PATCH 3/5] drm/nouveau: " Lukas Wunner
2017-02-24 20:59   ` Bjorn Helgaas
2017-03-04 10:16     ` Lukas Wunner
2017-02-24 19:19 ` Lukas Wunner [this message]
     [not found] ` <cover.1487938188.git.lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2017-02-24 19:19   ` [PATCH 5/5] drm/amdgpu: " Lukas Wunner
2017-02-24 19:19   ` [PATCH 1/5] PCI: Recognize Thunderbolt devices Lukas Wunner
2017-02-24 19:19     ` Lukas Wunner
2017-02-24 22:17     ` Bjorn Helgaas
2017-02-24 22:17       ` Bjorn Helgaas
2017-02-25  7:40       ` Lukas Wunner
2017-02-25 14:44         ` Bjorn Helgaas
     [not found]       ` <20170224221724.GA26430-1RhO1Y9PlrlHTL0Zs8A6p5iNqAH0jzoTYJqu5kTmcBRl57MIdRCFDg@public.gmane.org>
2017-03-04 11:14         ` Lukas Wunner
2017-03-04 11:14           ` Lukas Wunner
2017-03-09 15:03 ` [PATCH 0/5] Thunderbolt GPU fixes Daniel Vetter
2017-03-09 15:03   ` Daniel Vetter
     [not found]   ` <20170309150347.a4k4w2sclox2365t-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-03-10 12:07     ` Lukas Wunner
2017-03-10 12:07       ` Lukas Wunner
2017-03-10 12:15       ` Andy Shevchenko
2017-03-10 12:15         ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c06c7eaf3d4a6ec3e2d75191ef26ebd554c24db.1487938188.git.lukas@wunner.de \
    --to=lukas@wunner.de \
    --cc=andy@infradead.org \
    --cc=bhelgaas@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dvhart@infradead.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.