Skip to content

Commit

Permalink
usb: dwc3: gadget: Set speed only up to the max supported
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/4fae4a9ebb60464d64d8b8f6fdfc2777a2206a69.1611106162.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Thinh Nguyen authored and Greg Kroah-Hartman committed Feb 6, 2021
1 parent f551037 commit 450b9e9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions drivers/usb/dwc3/gadget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 450b9e9

Please sign in to comment.