From patchwork Fri Oct 31 14:02:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 5204741 Return-Path: X-Original-To: patchwork-linux-rockchip@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 EBD129F30B for ; Fri, 31 Oct 2014 14:03:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 196F320154 for ; Fri, 31 Oct 2014 14:03:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1315B20160 for ; Fri, 31 Oct 2014 14:03:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XkCno-0007uM-PP; Fri, 31 Oct 2014 14:03:44 +0000 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XkCnl-0007nn-1x for linux-rockchip@lists.infradead.org; Fri, 31 Oct 2014 14:03:43 +0000 Received: by mail-pa0-f45.google.com with SMTP id lf10so7785168pab.4 for ; Fri, 31 Oct 2014 07:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=flgAxUBah/2MNCRekoarnnFRmCsPMBRXRVZGQSNntrw=; b=sm8TiD2lQHG7zzJPrbrPkte1uCub6P0CKqymBreqxJmsfMY8nw9amBYTBXE2kM7I2n oWK1bhl8nZ7pgBvcwVS3RUHDB/OIlS2gHrb6u7y29KcqE0M4Q2CnlNktvmMiofiEJCZQ AZRHxcFNm7FdWShSI5SSXFqTvA/m3REFbNYeAMma0sMNshif12IBqo/2WS4LuxtCO1t9 kiXeOMS//fzl+0JK+6oqzYKuAFh167sx0Fx//gpqxYJQXIUXYIQtER+jY5boKn6/FT0p 7izGtV8kbZzSV6qy0n0Jt73WzafP6LlcQFPZ1U1LIvK0pbH1VmSV0sXAUhm+nhHHWRBF DVMw== X-Received: by 10.68.200.134 with SMTP id js6mr24677377pbc.20.1414764198933; Fri, 31 Oct 2014 07:03:18 -0700 (PDT) Received: from localhost.localdomain ([173.44.135.206]) by mx.google.com with ESMTPSA id ty8sm10086594pab.26.2014.10.31.07.03.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Oct 2014 07:03:16 -0700 (PDT) From: Kever Yang To: Paul Zimmerman Subject: [PATCH] usb: dwc2: add bus suspend/resume for dwc2 Date: Fri, 31 Oct 2014 22:02:51 +0800 Message-Id: <1414764171-11110-1-git-send-email-kever.yang@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141031_070341_124083_5C67E914 X-CRM114-Status: GOOD ( 12.51 ) X-Spam-Score: -0.7 (/) Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Kever Yang , Felipe Balbi , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, lyz@rock-chips.com, jwerner@chromium.org, cf@rock-chips.com, wulf@rock-chips.com, Dinh Nguyen X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds suspend/resume for dwc2 hcd controller. Signed-off-by: Kever Yang --- drivers/usb/dwc2/hcd.c | 74 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index fa49c72..df68449 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1473,6 +1473,29 @@ static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) } } +static void dwc2_port_resume(struct dwc2_hsotg *hsotg) +{ + u32 hprt0; + + /* After clear the Stop PHY clock bit, we should wait for a moment + * for PLL work stable with clock output. + */ + writel(0, hsotg->regs + PCGCTL); + usleep_range(2000, 4000); + + hprt0 = dwc2_read_hprt0(hsotg); + hprt0 |= HPRT0_RES; + writel(hprt0, hsotg->regs + HPRT0); + hprt0 &= ~HPRT0_SUSP; + /* according to USB2.0 Spec 7.1.7.7, the host most send the resume + * signal for at least 20ms + */ + usleep_range(20000, 25000); + + hprt0 &= ~HPRT0_RES; + writel(hprt0, hsotg->regs + HPRT0); +} + /* Handles hub class-specific requests */ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, u16 wvalue, u16 windex, char *buf, u16 wlength) @@ -1518,17 +1541,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, case USB_PORT_FEAT_SUSPEND: dev_dbg(hsotg->dev, "ClearPortFeature USB_PORT_FEAT_SUSPEND\n"); - writel(0, hsotg->regs + PCGCTL); - usleep_range(20000, 40000); - - hprt0 = dwc2_read_hprt0(hsotg); - hprt0 |= HPRT0_RES; - writel(hprt0, hsotg->regs + HPRT0); - hprt0 &= ~HPRT0_SUSP; - usleep_range(100000, 150000); - - hprt0 &= ~HPRT0_RES; - writel(hprt0, hsotg->regs + HPRT0); + dwc2_port_resume(hsotg); break; case USB_PORT_FEAT_POWER: @@ -2301,6 +2314,42 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd) usleep_range(1000, 3000); } +static int _dwc2_hcd_suspend(struct usb_hcd *hcd) +{ + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); + u32 hprt0; + + if (hsotg->op_state != OTG_STATE_B_HOST) + return 0; + + if (hsotg->lx_state != DWC2_L0) + return 0; + + hprt0 = dwc2_read_hprt0(hsotg); + if (hprt0 & HPRT0_CONNSTS) + dwc2_port_suspend(hsotg, 1); + + return 0; +} + +static int _dwc2_hcd_resume(struct usb_hcd *hcd) +{ + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); + u32 hprt0; + + if (hsotg->op_state != OTG_STATE_B_HOST) + return 0; + + if (hsotg->lx_state != DWC2_L2) + return 0; + + hprt0 = dwc2_read_hprt0(hsotg); + if ((hprt0 | HPRT0_CONNSTS) && (hprt0 | HPRT0_SUSP)) + dwc2_port_resume(hsotg); + + return 0; +} + /* Returns the current frame number */ static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd) { @@ -2671,6 +2720,9 @@ static struct hc_driver dwc2_hc_driver = { .hub_status_data = _dwc2_hcd_hub_status_data, .hub_control = _dwc2_hcd_hub_control, .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete, + + .bus_suspend = _dwc2_hcd_suspend, + .bus_resume = _dwc2_hcd_resume, }; /*