From patchwork Thu Sep 20 13:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Petrosyan X-Patchwork-Id: 10607807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FBC66CB for ; Thu, 20 Sep 2018 13:49:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F4452D785 for ; Thu, 20 Sep 2018 13:49:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3394B2D7C3; Thu, 20 Sep 2018 13:49:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C88252D785 for ; Thu, 20 Sep 2018 13:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732393AbeITTd0 (ORCPT ); Thu, 20 Sep 2018 15:33:26 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:48030 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbeITTd0 (ORCPT ); Thu, 20 Sep 2018 15:33:26 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id D983110C1124; Thu, 20 Sep 2018 06:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1537451391; bh=f10tuhOH3rIt0eS7UJoFAV3ThlqtHqps6zt7womiBPg=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=NkOhW+Yie3KUk7/+VNr4PNFHgYqetKe2IWJh4sq6RBQ7ua8fBD3s0TYcUfN7/NbkH 83RNZ/uor8QUa2QQ/CGDaY3k+PwWX1rr3xdeCtEh6YqjJFXo849ahYTwrhM/OS5pYQ mkySK06P1srGHu8ovWLT3LmsgB9MHl6zQi4Yu0kSHfHn3ffTpowQGli/3Ydor8MMtZ Kbnp6xAatLVtFpvyBG0nEjXTPpoWhGN2cP1GuyVlH/7QvUqU3AdekqpjiJ83bF91ge 5/YjkoW70gEJFOvmHnAKaac0CYwADIyRt2o8k9NLGFbLTWBvDtsTGz51encYdxMmBy dlQ5QVRvsY+XQ== Received: from US01WXQAHTC1.internal.synopsys.com (us01wxqahtc1.internal.synopsys.com [10.12.238.230]) by mailhost.synopsys.com (Postfix) with ESMTP id C112A3691; Thu, 20 Sep 2018 06:49:51 -0700 (PDT) Received: from US01WEHTC3.internal.synopsys.com (10.15.84.232) by US01WXQAHTC1.internal.synopsys.com (10.12.238.230) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 20 Sep 2018 06:49:51 -0700 Received: from arturp-ubuntu (10.13.184.20) by US01WEHTC3.internal.synopsys.com (10.15.84.231) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 20 Sep 2018 06:49:50 -0700 Received: by arturp-ubuntu (sSMTP sendmail emulation); Thu, 20 Sep 2018 09:49:45 -0400 Date: Thu, 20 Sep 2018 09:49:45 -0400 Message-ID: In-Reply-To: References: From: Artur Petrosyan Subject: [PATCH 3/3] usb: dwc2: Fix hibernation between host and device modes. To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , CC: John Youn , Artur Petrosyan MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - After entering hibernation both in host and device modes saved GPWRDN register. - In handling status change interrupt checking if current mode differs from the mode when entered hibernation. In case when mode is not changed, exiting device hibernation without remote wake up. On the other hand, if there is device hibernation and changed to host, then exiting hibernation for device mode with remote wake up. - Removed workaround for ignore suspend interrupt before enumeration. Signed-off-by: Artur Petrosyan Signed-off-by: Minas Harutyunyan --- drivers/usb/dwc2/core_intr.c | 19 +++++++++---------- drivers/usb/dwc2/hcd.c | 3 +++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c index 3602aca3316b..47e7dc4100af 100644 --- a/drivers/usb/dwc2/core_intr.c +++ b/drivers/usb/dwc2/core_intr.c @@ -491,12 +491,6 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg) hsotg->hw_params.power_optimized, hsotg->hw_params.hibernation); - /* Ignore suspend request before enumeration */ - if (!dwc2_is_device_connected(hsotg)) { - dev_dbg(hsotg->dev, - "ignore suspend request before enumeration\n"); - return; - } if (dsts & DSTS_SUSPSTS) { switch (hsotg->params.power_down) { case DWC2_POWER_DOWN_PARAM_PARTIAL: @@ -733,21 +727,26 @@ static void dwc2_handle_gpwrdn_intr(struct dwc2_hsotg *hsotg) } } } + if ((gpwrdn & GPWRDN_RST_DET) && (gpwrdn & GPWRDN_RST_DET_MSK)) { dev_dbg(hsotg->dev, "%s: GPWRDN_RST_DET\n", __func__); if (!linestate && (gpwrdn & GPWRDN_BSESSVLD)) dwc2_exit_hibernation(hsotg, 0, 1, 0); } + if ((gpwrdn & GPWRDN_STS_CHGINT) && - (gpwrdn & GPWRDN_STS_CHGINT_MSK) && linestate) { + (gpwrdn & GPWRDN_STS_CHGINT_MSK)) { dev_dbg(hsotg->dev, "%s: GPWRDN_STS_CHGINT\n", __func__); if (hsotg->hw_params.hibernation && hsotg->hibernated) { - if (gpwrdn & GPWRDN_IDSTS) { + if ((gpwrdn & GPWRDN_IDSTS) & + (hsotg->gr_backup.gpwrdn & GPWRDN_IDSTS) && + linestate) { dwc2_exit_hibernation(hsotg, 0, 0, 0); call_gadget(hsotg, resume); - } else { - dwc2_exit_hibernation(hsotg, 1, 0, 1); + } else if (!(gpwrdn & GPWRDN_IDSTS) && !linestate) { + dwc2_exit_hibernation(hsotg, 1, 0, 0); + call_gadget(hsotg, resume); } } } diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 2bd6e6bfc241..0e29b4c4e87b 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5582,6 +5582,9 @@ int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg) gpwrdn |= GPWRDN_PWRDNSWTCH; dwc2_writel(hsotg, gpwrdn, GPWRDN); + /* Save gpwrdn register for further usage if stschng interrupt */ + hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg, GPWRDN); + hsotg->hibernated = 1; hsotg->bus_suspended = 1; dev_dbg(hsotg->dev, "Host hibernation completed\n");