Skip to content

Commit 84fa943

Browse files
Wayne Changgregkh
authored andcommitted
usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic
This commit resolves an issue in the tegra-xudc USB gadget driver that incorrectly fetched USB3 PHY instances. The problem stemmed from the assumption of a one-to-one correspondence between USB2 and USB3 PHY names and their association with physical USB ports in the device tree. Previously, the driver associated USB3 PHY names directly with the USB3 instance number, leading to mismatches when mapping the physical USB ports. For instance, if using USB3-1 PHY, the driver expect the corresponding PHY name as 'usb3-1'. However, the physical USB ports in the device tree were designated as USB2-0 and USB3-0 as we only have one device controller, causing a misalignment. This commit rectifies the issue by adjusting the PHY naming logic. Now, the driver correctly correlates the USB2 and USB3 PHY instances, allowing the USB2-0 and USB3-1 PHYs to form a physical USB port pair while accurately reflecting their configuration in the device tree by naming them USB2-0 and USB3-0, respectively. The change ensures that the PHY and PHY names align appropriately, resolving the mismatch between physical USB ports and their associated names in the device tree. Fixes: b4e1993 ("usb: gadget: tegra-xudc: Support multiple device modes") Cc: [email protected] Signed-off-by: Wayne Chang <[email protected]> Reviewed-by: Jon Hunter <[email protected]> Tested-by: Jon Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d843f03 commit 84fa943

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

drivers/usb/gadget/udc/tegra-xudc.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,8 +3491,8 @@ static void tegra_xudc_device_params_init(struct tegra_xudc *xudc)
34913491

34923492
static int tegra_xudc_phy_get(struct tegra_xudc *xudc)
34933493
{
3494-
int err = 0, usb3;
3495-
unsigned int i;
3494+
int err = 0, usb3_companion_port;
3495+
unsigned int i, j;
34963496

34973497
xudc->utmi_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys,
34983498
sizeof(*xudc->utmi_phy), GFP_KERNEL);
@@ -3520,7 +3520,7 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc)
35203520
if (IS_ERR(xudc->utmi_phy[i])) {
35213521
err = PTR_ERR(xudc->utmi_phy[i]);
35223522
dev_err_probe(xudc->dev, err,
3523-
"failed to get usb2-%d PHY\n", i);
3523+
"failed to get PHY for phy-name usb2-%d\n", i);
35243524
goto clean_up;
35253525
} else if (xudc->utmi_phy[i]) {
35263526
/* Get usb-phy, if utmi phy is available */
@@ -3539,19 +3539,30 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc)
35393539
}
35403540

35413541
/* Get USB3 phy */
3542-
usb3 = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i);
3543-
if (usb3 < 0)
3542+
usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i);
3543+
if (usb3_companion_port < 0)
35443544
continue;
35453545

3546-
snprintf(phy_name, sizeof(phy_name), "usb3-%d", usb3);
3547-
xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name);
3548-
if (IS_ERR(xudc->usb3_phy[i])) {
3549-
err = PTR_ERR(xudc->usb3_phy[i]);
3550-
dev_err_probe(xudc->dev, err,
3551-
"failed to get usb3-%d PHY\n", usb3);
3552-
goto clean_up;
3553-
} else if (xudc->usb3_phy[i])
3554-
dev_dbg(xudc->dev, "usb3-%d PHY registered", usb3);
3546+
for (j = 0; j < xudc->soc->num_phys; j++) {
3547+
snprintf(phy_name, sizeof(phy_name), "usb3-%d", j);
3548+
xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name);
3549+
if (IS_ERR(xudc->usb3_phy[i])) {
3550+
err = PTR_ERR(xudc->usb3_phy[i]);
3551+
dev_err_probe(xudc->dev, err,
3552+
"failed to get PHY for phy-name usb3-%d\n", j);
3553+
goto clean_up;
3554+
} else if (xudc->usb3_phy[i]) {
3555+
int usb2_port =
3556+
tegra_xusb_padctl_get_port_number(xudc->utmi_phy[i]);
3557+
int usb3_port =
3558+
tegra_xusb_padctl_get_port_number(xudc->usb3_phy[i]);
3559+
if (usb3_port == usb3_companion_port) {
3560+
dev_dbg(xudc->dev, "USB2 port %d is paired with USB3 port %d for device mode port %d\n",
3561+
usb2_port, usb3_port, i);
3562+
break;
3563+
}
3564+
}
3565+
}
35553566
}
35563567

35573568
return err;

0 commit comments

Comments
 (0)