All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"git@amd.com" <git@amd.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode
Date: Sat, 5 Dec 2026 01:25:14 +0000	[thread overview]
Message-ID: <axNnzvTmpqvVz_q6@vbox> (raw)
In-Reply-To: <20261201171731.730281-1-radhey.shyam.pandey@amd.com>

On Tue, Dec 01, 2026, Radhey Shyam Pandey wrote:
> As a last resort dwc3_get_extcon() walks the OF graph from the "phys"
> phandle and asks extcon for a device bound to the remote node.  A PHY
> "port" node no longer implies an extcon provider though: it may link to
> a Type-C controller for orientation switching.  There
> extcon_find_edev_by_node() returns -EPROBE_DEFER, the same value it uses
> for "not registered yet", so the probe defers forever.
> 
> An extcon is only consulted for role switching in OTG mode, so skip the
> graph walk for a fixed role.  dwc->dr_mode is still the raw device tree
> value here, as dwc3_get_dr_mode() runs later, so also account for the
> roles GHWPARAMS0 and the Kconfig selection force.  Factor those out of
> dwc3_get_dr_mode() into dwc3_get_forced_role() so both callers share
> them.
> 
> Fixes: d182c2e1bc92 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present")
> Cc: stable@vger.kernel.org
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
> ---
> Changes for v2:
> - Add CC stable kernel
> - Trim commit and code comment description
> - Create common wrapper for dwc3_get_dr_mode and reuse it to determine
>   fixed role.
> ---
>  drivers/usb/dwc3/core.c | 76 ++++++++++++++++++++++++++++-------------
>  1 file changed, 53 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index f4aa6a01e500..9146d06e7ee1 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -46,6 +46,31 @@
>  
>  #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
>  
> +/**
> + * dwc3_get_forced_role - Role forced by the hardware and Kconfig
> + * @dwc: pointer to our context structure
> + *
> + * Return: the forced role, or USB_DR_MODE_OTG if the role is not forced.
> + */
> +static enum usb_dr_mode dwc3_get_forced_role(struct dwc3 *dwc)
> +{
> +	unsigned int hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
> +
> +	switch (hw_mode) {
> +	case DWC3_GHWPARAMS0_MODE_GADGET:
> +		return USB_DR_MODE_PERIPHERAL;
> +	case DWC3_GHWPARAMS0_MODE_HOST:
> +		return USB_DR_MODE_HOST;
> +	default:
> +		if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
> +			return USB_DR_MODE_HOST;
> +		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
> +			return USB_DR_MODE_PERIPHERAL;
> +
> +		return USB_DR_MODE_OTG;
> +	}
> +}
> +
>  /**
>   * dwc3_get_dr_mode - Validates and sets dr_mode
>   * @dwc: pointer to our context structure
> @@ -59,31 +84,23 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
>  	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
>  		dwc->dr_mode = USB_DR_MODE_OTG;
>  
> -	mode = dwc->dr_mode;
>  	hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
>  
> -	switch (hw_mode) {
> -	case DWC3_GHWPARAMS0_MODE_GADGET:
> -		if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
> -			dev_err(dev,
> -				"Controller does not support host mode.\n");
> -			return -EINVAL;
> -		}
> -		mode = USB_DR_MODE_PERIPHERAL;
> -		break;
> -	case DWC3_GHWPARAMS0_MODE_HOST:
> -		if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
> -			dev_err(dev,
> -				"Controller does not support device mode.\n");
> -			return -EINVAL;
> -		}
> -		mode = USB_DR_MODE_HOST;
> -		break;
> -	default:
> -		if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
> -			mode = USB_DR_MODE_HOST;
> -		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
> -			mode = USB_DR_MODE_PERIPHERAL;
> +	if (hw_mode == DWC3_GHWPARAMS0_MODE_GADGET &&
> +	    IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
> +		dev_err(dev, "Controller does not support host mode.\n");
> +		return -EINVAL;
> +	}
> +
> +	if (hw_mode == DWC3_GHWPARAMS0_MODE_HOST &&
> +	    IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
> +		dev_err(dev, "Controller does not support device mode.\n");
> +		return -EINVAL;
> +	}
> +
> +	mode = dwc3_get_forced_role(dwc);
> +	if (mode == USB_DR_MODE_OTG) {
> +		mode = dwc->dr_mode;
>  
>  		/*
>  		 * DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
> @@ -2003,6 +2020,15 @@ static void dwc3_check_params(struct dwc3 *dwc)
>  	}
>  }
>  
> +static bool dwc3_role_is_fixed(struct dwc3 *dwc)
> +{
> +	if (dwc->dr_mode == USB_DR_MODE_HOST ||
> +	    dwc->dr_mode == USB_DR_MODE_PERIPHERAL)
> +		return true;
> +
> +	return dwc3_get_forced_role(dwc) != USB_DR_MODE_OTG;
> +}
> +
>  static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
>  {
>  	struct device *dev = dwc->dev;
> @@ -2032,6 +2058,10 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
>  	    device_property_read_bool(dev, "usb-role-switch"))
>  		return NULL;
>  
> +	/* An extcon is only used for role switching in OTG mode */
> +	if (dwc3_role_is_fixed(dwc))
> +		return NULL;
> +
>  	/*
>  	 * Try to get an extcon device from the USB PHY controller's "port"
>  	 * node. Check if it has the "port" node first, to avoid printing the
> 
> base-commit: 3a8ea89f018971d8b595ebf61022871d991a0299
> -- 
> 2.43.0
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

      parent reply	other threads:[~2026-12-05  1:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 17:17 [PATCH v2] usb: dwc3: skip extcon lookup for fixed-role mode Radhey Shyam Pandey
2026-12-01 17:22 ` sashiko-bot
2026-12-05  1:25 ` Thinh Nguyen [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=axNnzvTmpqvVz_q6@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=git@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.