From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org
Cc: John Youn <John.Youn@synopsys.com>
Subject: [PATCH v7 6/6] usb: dwc3: gadget: Set speed only up to the max supported
Date: Tue, 19 Jan 2021 17:36:40 -0800 [thread overview]
Message-ID: <4fae4a9ebb60464d64d8b8f6fdfc2777a2206a69.1611106162.git.Thinh.Nguyen@synopsys.com> (raw)
In-Reply-To: <cover.1611106162.git.Thinh.Nguyen@synopsys.com>
The setting of the device speed should be limited by the device's
maximum_speed. Check and prevent the driver from attempting to configure
higher than the maximum_speed.
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
Changes in v7:
- Rebase on Greg's usb-testing branch
Changes in v6:
- Rebase on Greg's usb-testing branch
- Update to follow the latest change of dwc3 on Greg's usb-testing branch
- Update commit message
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 | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0aa89e704a55..9acf515f6a67 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2064,9 +2064,14 @@ static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc)
static void __dwc3_gadget_set_speed(struct dwc3 *dwc)
{
+ enum usb_device_speed speed;
u32 reg;
- if (dwc->gadget_max_speed == USB_SPEED_SUPER_PLUS &&
+ speed = dwc->gadget_max_speed;
+ if (speed > dwc->maximum_speed)
+ speed = dwc->maximum_speed;
+
+ if (speed == USB_SPEED_SUPER_PLUS &&
DWC3_IP_IS(DWC32)) {
__dwc3_gadget_set_ssp_rate(dwc);
return;
@@ -2092,7 +2097,7 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc)
!dwc->dis_metastability_quirk) {
reg |= DWC3_DCFG_SUPERSPEED;
} else {
- switch (dwc->gadget_max_speed) {
+ switch (speed) {
case USB_SPEED_LOW:
reg |= DWC3_DCFG_LOWSPEED;
break;
@@ -2112,7 +2117,7 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc)
reg |= DWC3_DCFG_SUPERSPEED_PLUS;
break;
default:
- dev_err(dwc->dev, "invalid speed (%d)\n", dwc->gadget_max_speed);
+ dev_err(dwc->dev, "invalid speed (%d)\n", speed);
if (DWC3_IP_IS(DWC3))
reg |= DWC3_DCFG_SUPERSPEED;
@@ -2122,8 +2127,8 @@ static void __dwc3_gadget_set_speed(struct dwc3 *dwc)
}
if (DWC3_IP_IS(DWC32) &&
- dwc->gadget_max_speed > USB_SPEED_UNKNOWN &&
- dwc->gadget_max_speed < USB_SPEED_SUPER_PLUS)
+ speed > USB_SPEED_UNKNOWN &&
+ speed < USB_SPEED_SUPER_PLUS)
reg &= ~DWC3_DCFG_NUMLANES(~0);
dwc3_writel(dwc->regs, DWC3_DCFG, reg);
--
2.28.0
next prev parent reply other threads:[~2021-01-20 1:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 1:36 [PATCH v7 0/6] usb: Support USB 3.2 multi-lanes Thinh Nguyen
2021-01-20 1:36 ` [PATCH v7 1/6] dt-binding: usb: Include USB SSP rates in GenXxY Thinh Nguyen
2021-02-05 2:32 ` Thinh Nguyen
2021-02-05 20:46 ` Rob Herring
2021-02-06 3:14 ` Thinh Nguyen
2021-01-20 1:36 ` [PATCH v7 2/6] usb: common: Parse for USB SSP genXxY Thinh Nguyen
2021-01-20 1:36 ` [PATCH v7 3/6] usb: dwc3: core: Check maximum_speed " Thinh Nguyen
2021-01-20 1:36 ` [PATCH v7 4/6] usb: dwc3: gadget: Implement setting of SSP rate Thinh Nguyen
2021-01-20 1:36 ` [PATCH v7 5/6] usb: dwc3: gadget: Track connected SSP rate and lane count Thinh Nguyen
2021-01-20 1:36 ` Thinh Nguyen [this message]
2021-02-05 2:39 ` [PATCH v7 0/6] usb: Support USB 3.2 multi-lanes Thinh Nguyen
2021-02-05 6:49 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4fae4a9ebb60464d64d8b8f6fdfc2777a2206a69.1611106162.git.Thinh.Nguyen@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=John.Youn@synopsys.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).