From 24e3b199ebca228fd9b11fd2dd39bb98aa84a0fa Mon Sep 17 00:00:00 2001 From: Stanimir Varbanov Date: Mar 28 2024 07:12:24 +0000 Subject: usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic (bsc#1221491) --- diff --git a/patches.suse/usb-gadget-tegra-xudc-Fix-USB3-PHY-retrieval-logic.patch b/patches.suse/usb-gadget-tegra-xudc-Fix-USB3-PHY-retrieval-logic.patch new file mode 100644 index 0000000..09b5b5b --- /dev/null +++ b/patches.suse/usb-gadget-tegra-xudc-Fix-USB3-PHY-retrieval-logic.patch @@ -0,0 +1,105 @@ +From: Wayne Chang +Date: Thu, 7 Mar 2024 11:03:28 +0800 +Subject: usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic +Git-commit: 84fa943d93c31ee978355e6c6c69592dae3c9f59 +Patch-mainline: v6.9-rc1 +References: bsc#1221491 + +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: b4e19931c98a ("usb: gadget: tegra-xudc: Support multiple device modes") +Cc: stable@vger.kernel.org +Signed-off-by: Wayne Chang +Reviewed-by: Jon Hunter +Tested-by: Jon Hunter +Link: https://lore.kernel.org/r/20240307030328.1487748-3-waynec@nvidia.com +Signed-off-by: Greg Kroah-Hartman +Acked-by: Stanimir Varbanov +--- + drivers/usb/gadget/udc/tegra-xudc.c | 39 +++++++++++++++++++++++------------- + 1 file changed, 25 insertions(+), 14 deletions(-) + +--- a/drivers/usb/gadget/udc/tegra-xudc.c ++++ b/drivers/usb/gadget/udc/tegra-xudc.c +@@ -3491,8 +3491,8 @@ static void tegra_xudc_device_params_ini + + static int tegra_xudc_phy_get(struct tegra_xudc *xudc) + { +- int err = 0, usb3; +- unsigned int i; ++ int err = 0, usb3_companion_port; ++ unsigned int i, j; + + xudc->utmi_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, + sizeof(*xudc->utmi_phy), GFP_KERNEL); +@@ -3520,7 +3520,7 @@ static int tegra_xudc_phy_get(struct teg + if (IS_ERR(xudc->utmi_phy[i])) { + err = PTR_ERR(xudc->utmi_phy[i]); + dev_err_probe(xudc->dev, err, +- "failed to get usb2-%d PHY\n", i); ++ "failed to get PHY for phy-name usb2-%d\n", i); + goto clean_up; + } else if (xudc->utmi_phy[i]) { + /* Get usb-phy, if utmi phy is available */ +@@ -3539,19 +3539,30 @@ static int tegra_xudc_phy_get(struct teg + } + + /* Get USB3 phy */ +- usb3 = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); +- if (usb3 < 0) ++ usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); ++ if (usb3_companion_port < 0) + continue; + +- snprintf(phy_name, sizeof(phy_name), "usb3-%d", usb3); +- xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); +- if (IS_ERR(xudc->usb3_phy[i])) { +- err = PTR_ERR(xudc->usb3_phy[i]); +- dev_err_probe(xudc->dev, err, +- "failed to get usb3-%d PHY\n", usb3); +- goto clean_up; +- } else if (xudc->usb3_phy[i]) +- dev_dbg(xudc->dev, "usb3-%d PHY registered", usb3); ++ for (j = 0; j < xudc->soc->num_phys; j++) { ++ snprintf(phy_name, sizeof(phy_name), "usb3-%d", j); ++ xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); ++ if (IS_ERR(xudc->usb3_phy[i])) { ++ err = PTR_ERR(xudc->usb3_phy[i]); ++ dev_err_probe(xudc->dev, err, ++ "failed to get PHY for phy-name usb3-%d\n", j); ++ goto clean_up; ++ } else if (xudc->usb3_phy[i]) { ++ int usb2_port = ++ tegra_xusb_padctl_get_port_number(xudc->utmi_phy[i]); ++ int usb3_port = ++ tegra_xusb_padctl_get_port_number(xudc->usb3_phy[i]); ++ if (usb3_port == usb3_companion_port) { ++ dev_dbg(xudc->dev, "USB2 port %d is paired with USB3 port %d for device mode port %d\n", ++ usb2_port, usb3_port, i); ++ break; ++ } ++ } ++ } + } + + return err; diff --git a/series.conf b/series.conf index 26e9a65..ea10daf 100644 --- a/series.conf +++ b/series.conf @@ -20046,6 +20046,7 @@ patches.suse/soc-fsl-dpio-fix-kcalloc-argument-order.patch patches.suse/usb-typec-ucsi-Update-connector-cap-and-status.patch patches.suse/phy-tegra-xusb-Add-API-to-retrieve-the-port-number-of-phy.patch + patches.suse/usb-gadget-tegra-xudc-Fix-USB3-PHY-retrieval-logic.patch patches.suse/uio-introduce-uio_mem_dma_coherent-type.patch patches.suse/cnic-bnx2-bnx2x-use-uio_mem_dma_coherent.patch patches.suse/uio_pruss-uio_mem_dma_coherent-conversion.patch