From patchwork Sun Jun 1 16:38:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 4279491 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7711B9F326 for ; Mon, 2 Jun 2014 00:52:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1BA7203AD for ; Mon, 2 Jun 2014 00:52:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D3D3A2039E for ; Mon, 2 Jun 2014 00:52:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 95A116E4BD; Sun, 1 Jun 2014 17:52:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 2722 seconds by postgrey-1.34 at gabe; Sun, 01 Jun 2014 10:24:18 PDT Received: from cavan.codon.org.uk (cavan.codon.org.uk [93.93.128.6]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B8C66E08B for ; Sun, 1 Jun 2014 10:24:18 -0700 (PDT) Received: from 209-6-207-143.c3-0.smr-ubr2.sbo-smr.ma.cable.rcn.com ([209.6.207.143] helo=localhost.lan) by cavan.codon.org.uk with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Wr8nI-00062c-6o; Sun, 01 Jun 2014 17:39:39 +0100 From: Matthew Garrett To: airlied@gmail.com Date: Sun, 1 Jun 2014 12:38:43 -0400 Message-Id: <1401640723-2058-12-git-send-email-matthew.garrett@nebula.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1401640723-2058-1-git-send-email-matthew.garrett@nebula.com> References: <1401640723-2058-1-git-send-email-matthew.garrett@nebula.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 209.6.207.143 X-SA-Exim-Mail-From: matthew.garrett@nebula.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-ASN: Subject: [PATCH 11/11] apple_gmux: Wait for switch completion X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:54:46 +0000) X-SA-Exim-Scanned: Yes (on cavan.codon.org.uk) X-Mailman-Approved-At: Sun, 01 Jun 2014 17:52:06 -0700 Cc: Matthew Garrett , dri-devel@lists.freedesktop.org, platform-driver-x86@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The GMUX doesn't appear to switch instantly, which can trigger problems in panel detection and setup. Wait for an interrupt or 200msec, whichever comes first. Signed-off-by: Matthew Garrett --- drivers/platform/x86/apple-gmux.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 17f906d..6826ede 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -38,6 +38,7 @@ struct apple_gmux_data { int gpe; enum vga_switcheroo_client_id resume_client_id; enum vga_switcheroo_state power_state; + struct completion switch_done; struct completion powerchange_done; }; @@ -283,6 +284,8 @@ static int gmux_switch_ddc(enum vga_switcheroo_client_id id) static int gmux_switchto(enum vga_switcheroo_client_id id) { + reinit_completion(&apple_gmux_data->switch_done); + if (id == VGA_SWITCHEROO_IGD) { gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_DDC, 1); gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_DISPLAY, 2); @@ -293,6 +296,11 @@ static int gmux_switchto(enum vga_switcheroo_client_id id) gmux_write8(apple_gmux_data, GMUX_PORT_SWITCH_EXTERNAL, 3); } + if (apple_gmux_data->gpe >= 0 && + !wait_for_completion_interruptible_timeout(&apple_gmux_data->switch_done, + msecs_to_jiffies(200))) + pr_warn("Timeout waiting for gmux GPU switch to complete\n"); + return 0; } @@ -401,6 +409,9 @@ static void gmux_notify_handler(acpi_handle device, u32 value, void *context) gmux_clear_interrupts(gmux_data); gmux_enable_interrupts(gmux_data); + if (status & GMUX_INTERRUPT_STATUS_DISPLAY) + complete(&gmux_data->switch_done); + if (status & GMUX_INTERRUPT_STATUS_POWER) complete(&gmux_data->powerchange_done); } @@ -565,6 +576,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) } apple_gmux_data = gmux_data; + init_completion(&gmux_data->switch_done); init_completion(&gmux_data->powerchange_done); gmux_enable_interrupts(gmux_data);