Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp24450pja; Fri, 22 Nov 2019 02:59:26 -0800 (PST) X-Google-Smtp-Source: APXvYqy3R9SFADd9zvNBykgad78kS5S7hcjH6OQBnPO+XUABStDWiXAuzu2DBKXBk9Z3nDgMjl1c X-Received: by 2002:a50:e619:: with SMTP id y25mr283706edm.204.1574420366123; Fri, 22 Nov 2019 02:59:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574420366; cv=none; d=google.com; s=arc-20160816; b=hVlKSOeuMBq1rWQQUEmtO40R9QGpHv6mdVjyg+L+1tH35yCAt20PNKAGjGp0vKbixj pv6W3ON8bJrEhacpp5FhHfrx0YyEktlFSgH6Yc+8vq7IZUJ8O5uJbcMbm15lKTsNMmbr E8iiuZTMbeiiUTPIfzcrAGqUby8lCVKAmLeElIfw3twEbBw6kadZYl7C1jXNKiofB++q l0fTI4Nmem8xNWHthDK9Zf+Fh5XY9LUhmOHVBXT0xrlgdLit/DZ8RMzHjouE/OkMNfjh ys/xpQxzCf+jXIokYdI8CANgs/T2FHv3+uNhnzXGRL2ocOSHhb3B/i58pQsYOsTzGmz6 bpmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4ebB8fQ9aOXM3pKUy7gLrtlIGLp2xzD7vv5CRnw5Btc=; b=ztmTaMXQEzvIEtdsgnuODrUbJTIaeuYM0166mCuDqLZx5joj4a614SO8QMuHsO7CC7 JfqXRCp40CdRdOPZOvrl3a+TP9tB3oYVKPPgz/Qud0sZxRS1c63blm+oGP9ooypgBghq 67Rr9QNBhqYJkNOVkUbwciS0N3dZPz053U+kk5xAQpiVSPGerWjUQHmHgMVxr5fJAGjZ j+W/2Y673Ys/9zlvpxx0wmW6djCrrn2T27SPD9cUGwzjYMqThQQO0Q1xjfhq0EXgzoJl 34UPS3+1Ck029R5uKM+hjAeViRGRuz/SsEqCEDPBI/0pkXbR4UYjMiWqDXRM803NVAFS R3OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r5tK9uMP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4si3844972eji.269.2019.11.22.02.59.01; Fri, 22 Nov 2019 02:59:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r5tK9uMP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730252AbfKVK5w (ORCPT + 99 others); Fri, 22 Nov 2019 05:57:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:46794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730464AbfKVK5n (ORCPT ); Fri, 22 Nov 2019 05:57:43 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF6672072E; Fri, 22 Nov 2019 10:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574420262; bh=dQt3xAF/0dD9AaQxedCxFQzgzRaMzkywGvh9+OmquuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r5tK9uMPWVn2FXQtpWNWp6HsnmQRn7XWVOuff02icyIIHrtiMmqmTl7HDdMAtrmW+ TLyBIAtb03L2GqNW5BlYcWxhkNX70WdKocxGTzpR26In9SrALEuwKjDqKvAmRu/+Tz M47TMiVpTrIobaC9lOeviTnVkTce/4pwQFmeOGGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Felipe Balbi , Sasha Levin Subject: [PATCH 4.19 047/220] usb: dwc3: gadget: Check ENBLSLPM before sending ep command Date: Fri, 22 Nov 2019 11:26:52 +0100 Message-Id: <20191122100915.601546840@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100912.732983531@linuxfoundation.org> References: <20191122100912.732983531@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thinh Nguyen [ Upstream commit 87dd96111b0bb8e616fcbd74dbf4bb4182f2c596 ] When operating in USB 2.0 speeds (HS/FS), if GUSB2PHYCFG.ENBLSLPM or GUSB2PHYCFG.SUSPHY is set, it must be cleared before issuing an endpoint command. Current implementation only save and restore GUSB2PHYCFG.SUSPHY configuration. We must save and clear both GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY settings. Restore them after the command is completed. DWC_usb3 3.30a and DWC_usb31 1.90a programming guide section 3.2.2 Signed-off-by: Thinh Nguyen Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/dwc3/gadget.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8398c33d08e7c..3e04004b4f1b7 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -271,27 +271,36 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; struct dwc3 *dwc = dep->dwc; u32 timeout = 1000; + u32 saved_config = 0; u32 reg; int cmd_status = 0; - int susphy = false; int ret = -EINVAL; /* - * Synopsys Databook 2.60a states, on section 6.3.2.5.[1-8], that if - * we're issuing an endpoint command, we must check if - * GUSB2PHYCFG.SUSPHY bit is set. If it is, then we need to clear it. + * When operating in USB 2.0 speeds (HS/FS), if GUSB2PHYCFG.ENBLSLPM or + * GUSB2PHYCFG.SUSPHY is set, it must be cleared before issuing an + * endpoint command. * - * We will also set SUSPHY bit to what it was before returning as stated - * by the same section on Synopsys databook. + * Save and clear both GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY + * settings. Restore them after the command is completed. + * + * DWC_usb3 3.30a and DWC_usb31 1.90a programming guide section 3.2.2 */ if (dwc->gadget.speed <= USB_SPEED_HIGH) { reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); if (unlikely(reg & DWC3_GUSB2PHYCFG_SUSPHY)) { - susphy = true; + saved_config |= DWC3_GUSB2PHYCFG_SUSPHY; reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; - dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); } + + if (reg & DWC3_GUSB2PHYCFG_ENBLSLPM) { + saved_config |= DWC3_GUSB2PHYCFG_ENBLSLPM; + reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM; + } + + if (saved_config) + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); } if (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) { @@ -380,9 +389,9 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, dwc3_gadget_ep_get_transfer_index(dep); } - if (unlikely(susphy)) { + if (saved_config) { reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); - reg |= DWC3_GUSB2PHYCFG_SUSPHY; + reg |= saved_config; dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); } -- 2.20.1