From patchwork Tue Feb 5 08:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minas Harutyunyan X-Patchwork-Id: 10796985 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 3E5526C2 for ; Tue, 5 Feb 2019 08:09:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FEC52ADE0 for ; Tue, 5 Feb 2019 08:09:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 233AA2ADF3; Tue, 5 Feb 2019 08:09:28 +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 74E0A2ADE0 for ; Tue, 5 Feb 2019 08:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726955AbfBEIJ0 (ORCPT ); Tue, 5 Feb 2019 03:09:26 -0500 Received: from smtprelay.synopsys.com ([198.182.47.9]:49076 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726646AbfBEIJ0 (ORCPT ); Tue, 5 Feb 2019 03:09:26 -0500 Received: from mailhost.synopsys.com (dc8-mailhost1.synopsys.com [10.13.135.209]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtprelay.synopsys.com (Postfix) with ESMTPS id 0693C24E2824; Tue, 5 Feb 2019 00:09:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1549354166; bh=jP4KndN7qD0FJT0dW5PU+7xJAB/M2v5fWshTZDdOL6w=; h=Date:From:Subject:To:CC:From; b=BplDLFfMdx9HzqQcpb+HUF0+3R5A0jl3b3QPX3yuuhqojpGHrwVu5FSSUSjxgbrHI Lzlfas3JWbBp/OPJdQW6DYV8Bd+yidKsjXAwdaACqjJl5H3S9Qsinksbh+BoWlkGU5 /1fMs3oUy9A03LSSULewOQuPFcdcaz602FsKucNkCmLSpg7iNQqQWvysIjUtAUqlIP AXlWGFwieFDrU08WyzFGIBwEE7yqEOsIem0rrUVMfkvNeB0dDs+FpCEY4vs8ycs9Fd RNv6S00nZtpB3RNN9laKEe01qMfVZ57VgKwyG2Idut9ToEF+JXKiAZOJJVBh78O3aL bZF19ZnY3hYWQ== Received: from US01WXQAHTC1.internal.synopsys.com (us01wxqahtc1.internal.synopsys.com [10.12.238.230]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPS id E842AA006A; Tue, 5 Feb 2019 08:09:25 +0000 (UTC) Received: from US01WEHTC2.internal.synopsys.com (10.12.239.238) by US01WXQAHTC1.internal.synopsys.com (10.12.238.230) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 5 Feb 2019 00:08:56 -0800 Received: from hminas-z420 (10.13.184.20) by US01WEHTC2.internal.synopsys.com (10.12.239.238) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 5 Feb 2019 00:08:53 -0800 Received: by hminas-z420 (sSMTP sendmail emulation); Tue, 05 Feb 2019 12:08:48 +0400 Date: Tue, 5 Feb 2019 12:08:48 +0400 Message-ID: <3df661ea3e29360def73170ca3a55e7c7fb41ad2.1549353978.git.hminas@synopsys.com> From: Minas Harutyunyan Subject: [PATCH] usb: dwc2: gadget: Consider VBUS discharge time in disconnect flow To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , CC: John Youn 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 If VBUS discharge time > 3ms then on device cable disconnect, core asserted Early Suspend then Suspend interrupts which no need to handle. VBUS discharge time depend on PHY schematic implementation. Can be up to 1 sec. To unambiguous recognize disconnect event on Early_Suspend interrupt added delay to allow VBUS fully discharge and as result GOTGCTL_BSESVLD goes to 0. If GOTGCTL_BSESVLD after delay still set to 1 that mean Suspend initiated by host, not by disconnect. In case of disconnect after Early_Suspend core asserting Suspend, Reset Detect and Reset interrupts which no any meaning, so these interrupts no need to handle and resetting in GINTSTS. Signed-off-by: Minas Harutyunyan --- drivers/usb/dwc2/core.h | 4 ++++ drivers/usb/dwc2/debugfs.c | 2 ++ drivers/usb/dwc2/gadget.c | 8 ++++++++ drivers/usb/dwc2/params.c | 1 + 4 files changed, 15 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 30bab8463c96..4a4a196ef214 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -433,6 +433,8 @@ enum dwc2_ep0_state { * @service_interval: Enable service interval based scheduling. * 0 - No * 1 - Yes + * @vbus_discharge_time: VBUS discharge time (msec) depend on PHY + * implementation and can be up to 1 sec. * * The following parameters may be specified when starting the module. These * parameters define how the DWC_otg controller should be configured. A @@ -511,6 +513,8 @@ struct dwc2_core_params { u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; bool change_speed_quirk; + + u32 vbus_discharge_time; }; /** diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c index 7f62f4cdc265..a0c62511b481 100644 --- a/drivers/usb/dwc2/debugfs.c +++ b/drivers/usb/dwc2/debugfs.c @@ -707,6 +707,8 @@ static int params_show(struct seq_file *seq, void *v) print_param(seq, p, g_dma_desc); print_param(seq, p, g_rx_fifo_size); print_param(seq, p, g_np_tx_fifo_size); + print_param(seq, p, vbus_discharge_time); + for (i = 0; i < MAX_EPS_CHANNELS; i++) { char str[32]; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 68ad75a7460d..eab1da4c0beb 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3689,6 +3689,14 @@ static irqreturn_t dwc2_hsotg_irq(int irq, void *pw) if (gintsts & GINTSTS_ERLYSUSP) { dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); dwc2_writel(hsotg, GINTSTS_ERLYSUSP, GINTSTS); + + mdelay(hsotg->params.vbus_discharge_time); + if (!(dwc2_readl(hsotg, GOTGCTL) & GOTGCTL_BSESVLD)) { + /* Clear Suspend, Reset Detect and Reset interrupts */ + dwc2_writel(hsotg, GINTSTS_USBSUSP | GINTSTS_RESETDET | + GINTSTS_USBRST, GINTSTS); + dwc2_hsotg_disconnect(hsotg); + } } /* diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c index 24ff5f21cb25..c1912627a032 100644 --- a/drivers/usb/dwc2/params.c +++ b/drivers/usb/dwc2/params.c @@ -315,6 +315,7 @@ static void dwc2_set_default_params(struct dwc2_hsotg *hsotg) p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT; p->ref_clk_per = 33333; p->sof_cnt_wkup_alert = 100; + p->vbus_discharge_time = 1000; if ((hsotg->dr_mode == USB_DR_MODE_HOST) || (hsotg->dr_mode == USB_DR_MODE_OTG)) {