From patchwork Fri Sep 25 02:44:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11798707 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB08A618 for ; Fri, 25 Sep 2020 02:44:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAC6920EDD for ; Fri, 25 Sep 2020 02:44:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="R2OV0pXw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgIYCoh (ORCPT ); Thu, 24 Sep 2020 22:44:37 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:50948 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgIYCoh (ORCPT ); Thu, 24 Sep 2020 22:44:37 -0400 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id C0804409DD; Fri, 25 Sep 2020 02:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1601001876; bh=GnyFkG80Te1qHRY3OfWmleX7m+WxyzfA3GuWV7NtvMs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=R2OV0pXwWgl4F/dewPON3E17lE4/Nu5ZdqyumorcluoLAvJVUx80vBsR2rfRbUHj4 JCEXJdxTdu7LKCKJRsO3oFByLg5ZzNOjvD8K5W+CY5KDpcjSfhKyXK3C5fhSMeBUaQ vO52WiaamSPWWL06KMBkz/pvGqh0UZJWW52BT8VdOj2qwCC68nEfKTq2NJh4kld0Oh nKRrA+5uBnvzuZHBHV7tS7HUZruM6afdLHbOvmp0ITTGI0+9VZBWjZZVBKNMu77C2O zKBuCQ69uWywA5aO/tJ3T1LFEcelQ0WypLiScHbhT5p5RIW6XvjrbgJOME7gIC06x9 /uvS9yLqzJYUA== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id ABA9EA0072; Fri, 25 Sep 2020 02:44:35 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 19:44:35 -0700 Date: Thu, 24 Sep 2020 19:44:35 -0700 Message-Id: <592cc3c2555a50b3e43cb5bf771079dc6f7037fa.1601001199.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v5 12/12] usb: dwc3: gadget: Set speed only up to the max supported To: Felipe Balbi , Greg Kroah-Hartman , Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org Cc: John Youn Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The setting of device speed should be limited by the device's maximum_speed. This patch adds a check and prevent the driver from attempting to configure higher than the maximum_speed. Signed-off-by: Thinh Nguyen --- Changes in v5: - Rebase on Felipe's testing/next branch - Changed Signed-off-by email to match From: email header Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/usb/dwc3/gadget.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 66b4ea8473a6..b90df29cc23f 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2327,6 +2327,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, enum usb_device_speed speed) { struct dwc3 *dwc = gadget_to_dwc(g); + enum usb_device_speed selected_speed = speed; unsigned long flags; u32 reg; @@ -2351,7 +2352,10 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, !dwc->dis_metastability_quirk) { reg |= DWC3_DCFG_SUPERSPEED; } else { - switch (speed) { + if (speed > dwc->maximum_speed) + selected_speed = dwc->maximum_speed; + + switch (selected_speed) { case USB_SPEED_LOW: reg |= DWC3_DCFG_LOWSPEED; break; @@ -2371,7 +2375,8 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, reg |= DWC3_DCFG_SUPERSPEED_PLUS; break; default: - dev_err(dwc->dev, "invalid speed (%d)\n", speed); + dev_err(dwc->dev, "invalid speed (%d)\n", + selected_speed); if (DWC3_IP_IS(DWC3)) reg |= DWC3_DCFG_SUPERSPEED; @@ -2380,7 +2385,7 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, } } - if (DWC3_IP_IS(DWC32) && speed < USB_SPEED_SUPER_PLUS) + if (DWC3_IP_IS(DWC32) && selected_speed < USB_SPEED_SUPER_PLUS) reg &= ~DWC3_DCFG_NUMLANES(~0); dwc3_writel(dwc->regs, DWC3_DCFG, reg);