Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp50689pja; Fri, 22 Nov 2019 03:19:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzy2O2fFgJT/+LFnJepF3siL5XUNuv/GFwRIcdRC7YyWPh6D+2r3ddQ9zTkLpozrxMohlMY X-Received: by 2002:a17:906:4c8c:: with SMTP id q12mr21837618eju.256.1574421548791; Fri, 22 Nov 2019 03:19:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421548; cv=none; d=google.com; s=arc-20160816; b=eSCvihI1WDs0Gza9wwRN9rJmlrACZ4ZtLBGc746xrQ6qoIVLt0G+ZQ/SaW7hjlQ5sc +Cz2KPzo/5eqtTmUYt1+bSHGXrJejZ1eQbYN8kk8x3JtV4CBHsYyDeX2xGvB/am5Tq7c whAdXW0oQN+vaX33O5uLlGj8F18ru5fDBZwsuSLNsgTED1EBZ2GPYoswMCSizNsqBCKP qbQWiA/DQNytSlG+wkvKkaKSqm/pScOkfhAQeeDJYKdrwRNxVIlmAAvxYwMAMjxlhI/k cELR00LI1qIW/llNOwSNVSMSpt487V+xE9ZFjE+AIKFVfqTGBt35Y/0mQrH65exBKnQn D8vA== 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=MT2bef/o4c7mT6J+DFSOiat53aA8FJ0KxN35ul5XC4M=; b=pk+OiTbWtL0KSwqqQ7cYr9ViPR0gsFKPLhuxJmi19hnKxqrkaYvls8K1NZvEOjmZgQ i57oFtvFknaljR1+H9Lkpvrpq/F0UFQefuKn7BFaZHrfHFvjT2avyjUJ+KpY06vzf0kn BuBSmFbnbtF93r8k/CADwrXhc5kJwnBjcNo9DIB7w1trbbBygyM7RzaagY0r4r0iS2jo OwiKFbfsfHDm8sstunejf4EVrM6ZDcRZ/d9n9sZpVragiel71NR0LGjhw1qK50qLg6gC eY1d2qySutrpouItcJc7ByIBJTAiykaiE4XD1XeV3xvYh8EbbkKswhzcHsgr/cugBjlh nJKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V8sagXy8; 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 z35si4730134edz.260.2019.11.22.03.18.44; Fri, 22 Nov 2019 03:19:08 -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=V8sagXy8; 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 S1727738AbfKVKup (ORCPT + 99 others); Fri, 22 Nov 2019 05:50:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:60806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726620AbfKVKuj (ORCPT ); Fri, 22 Nov 2019 05:50:39 -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 48999205C9; Fri, 22 Nov 2019 10:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574419838; bh=SFa9Hrg+Z/KkxLOuH+wdWC71jllfBEWNrvKlWM6RZBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V8sagXy8ZPKZz+tO8I1uKecPw3cgk1QPYMzHw0JNJ3BMKIvO/spSLWcf0EXRmm0/z NsKe0yrAobbp/n9OJQZDipSfosPOZfKUYSV255nMNq1CpRIw2LdG2KNVHSxFKmPfTF b0bdV5htoK8cbj7J+DnWiroQu9LFR9+W5i5KP70A= 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.14 026/122] usb: dwc3: gadget: Check ENBLSLPM before sending ep command Date: Fri, 22 Nov 2019 11:27:59 +0100 Message-Id: <20191122100741.290644583@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100722.177052205@linuxfoundation.org> References: <20191122100722.177052205@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 5916340c41621..e96b22d6fa52e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -277,27 +277,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) { @@ -395,9 +404,9 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, } } - 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