mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Wayne Chang <waynec@nvidia.com>,
	thierry.reding@gmail.com, jckuo@nvidia.com, vkoul@kernel.org,
	kishon@kernel.org, gregkh@linuxfoundation.org
Cc: linux-phy@lists.infradead.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic
Date: Thu, 7 Mar 2024 13:43:28 +0000	[thread overview]
Message-ID: <bcf94732-34c2-4889-b550-76d27bd969bc@nvidia.com> (raw)
In-Reply-To: <20240307030328.1487748-3-waynec@nvidia.com>


On 07/03/2024 03:03, Wayne Chang wrote:
> 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 <waynec@nvidia.com>
> ---
> V1 -> V2:no change
>   drivers/usb/gadget/udc/tegra-xudc.c | 39 ++++++++++++++++++-----------
>   1 file changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c
> index cb85168fd00c..7aa46d426f31 100644
> --- 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_init(struct tegra_xudc *xudc)
>   
>   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 tegra_xudc *xudc)
>   		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 tegra_xudc *xudc)
>   		}
>   
>   		/* 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;


Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>

Thanks!

Jon

-- 
nvpublic

      reply	other threads:[~2024-03-07 13:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07  3:03 [PATCH v2 0/2] Fix incorrect USB3 phy parsing in tegra-xudc Wayne Chang
2024-03-07  3:03 ` [PATCH v2 1/2] phy: tegra: xusb: Add API to retrieve the port number of phy Wayne Chang
2024-03-07 13:43   ` Jon Hunter
2024-04-05 16:59   ` Vinod Koul
2024-03-07  3:03 ` [PATCH v2 2/2] usb: gadget: tegra-xudc: Fix USB3 PHY retrieval logic Wayne Chang
2024-03-07 13:43   ` Jon Hunter [this message]

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=bcf94732-34c2-4889-b550-76d27bd969bc@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jckuo@nvidia.com \
    --cc=kishon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=vkoul@kernel.org \
    --cc=waynec@nvidia.com \
    /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

all inboxes | Powered by JetHome®