linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Andrey Smirnov <andrew.smirnov@gmail.com>,
	Felipe Balbi <balbi@kernel.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Subject: Re: [PATCH v2] usb: dwc3: Don't switch OTG -> peripheral if extcon is present
Date: Wed, 23 Feb 2022 00:58:50 +0000	[thread overview]
Message-ID: <b5a2bc30-f017-980e-83ce-f654ca6ae2a0@synopsys.com> (raw)
In-Reply-To: <20220221192020.346622-1-andrew.smirnov@gmail.com>

Hi,

Andrey Smirnov wrote:
> If the extcon device exists, get the mode from the extcon device. If
> the controller is DRD and the driver is unable to determine the mode,
> only then default the dr_mode to USB_DR_MODE_PERIPHERAL.
> 
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Thinh Nguyen <thinhn@synopsys.com>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Reviewed-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> 
> v1 of the patch:
> 
> https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/20220206014532.372109-1-andrew.smirnov@gmail.com/T/*u__;Iw!!A4F2R9G_pg!MkC0ZJrDw6TYoTkd6CcnR0EBo8D-uvDlqJDRFdaR82BX-16j0ydzGz0FJR4z4VQtdKhZ$ 
> 
> previons discussion:
> 
> https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/20220131192102.4115473-1-andrew.smirnov@gmail.com/__;!!A4F2R9G_pg!MkC0ZJrDw6TYoTkd6CcnR0EBo8D-uvDlqJDRFdaR82BX-16j0ydzGz0FJR4z4Syxv17D$ 
> 
> 
>  drivers/usb/dwc3/core.c | 56 ++++++++++++++++++++++++++++++++++++++++-
>  drivers/usb/dwc3/drd.c  | 50 ------------------------------------
>  2 files changed, 55 insertions(+), 51 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index f2448d0a9d39..09f283288ce7 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -23,6 +23,7 @@
>  #include <linux/delay.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/of.h>
> +#include <linux/of_graph.h>
>  #include <linux/acpi.h>
>  #include <linux/pinctrl/consumer.h>
>  #include <linux/reset.h>
> @@ -84,7 +85,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
>  		 * mode. If the controller supports DRD but the dr_mode is not
>  		 * specified or set to OTG, then set the mode to peripheral.
>  		 */
> -		if (mode == USB_DR_MODE_OTG &&
> +		if (mode == USB_DR_MODE_OTG && !dwc->edev &&
>  		    (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
>  		     !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
>  		    !DWC3_VER_IS_PRIOR(DWC3, 330A))
> @@ -1462,6 +1463,51 @@ static void dwc3_check_params(struct dwc3 *dwc)
>  	}
>  }
> 
> +static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
> +{
> +	struct device *dev = dwc->dev;
> +	struct device_node *np_phy;
> +	struct extcon_dev *edev = NULL;
> +	const char *name;
> +
> +	if (device_property_read_bool(dev, "extcon"))
> +		return extcon_get_edev_by_phandle(dev, 0);
> +
> +	/*
> +	 * Device tree platforms should get extcon via phandle.
> +	 * On ACPI platforms, we get the name from a device property.
> +	 * This device property is for kernel internal use only and
> +	 * is expected to be set by the glue code.
> +	 */
> +	if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
> +		edev = extcon_get_extcon_dev(name);
> +		if (!edev)
> +			return ERR_PTR(-EPROBE_DEFER);
> +
> +		return edev;
> +	}
> +
> +	/*
> +	 * 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
> +	 * error message from underlying code, as it's a valid case: extcon
> +	 * device (and "port" node) may be missing in case of "usb-role-switch"
> +	 * or OTG mode.
> +	 */
> +	np_phy = of_parse_phandle(dev->of_node, "phys", 0);
> +	if (of_graph_is_present(np_phy)) {
> +		struct device_node *np_conn;
> +
> +		np_conn = of_graph_get_remote_node(np_phy, -1, -1);
> +		if (np_conn)
> +			edev = extcon_find_edev_by_node(np_conn);
> +		of_node_put(np_conn);
> +	}
> +	of_node_put(np_phy);
> +
> +	return edev;
> +}
> +
>  static int dwc3_probe(struct platform_device *pdev)
>  {
>  	struct device		*dev = &pdev->dev;
> @@ -1561,6 +1607,14 @@ static int dwc3_probe(struct platform_device *pdev)
>  		goto err2;
>  	}
> 
> +	dwc->edev = dwc3_get_extcon(dwc);
> +	if (IS_ERR(dwc->edev)) {
> +		ret = PTR_ERR(dwc->edev);
> +		dev_err_probe(dwc->dev, ret, "failed to get extcon");

My comment earlier was meant to add "\n" to the error message above, not
adding a new line to the code.

Thanks,
Thinh

> +
> +		goto err3;
> +	}
> +
>  	ret = dwc3_get_dr_mode(dwc);
>  	if (ret)
>  		goto err3;

      parent reply	other threads:[~2022-02-23  0:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 19:20 [PATCH v2] usb: dwc3: Don't switch OTG -> peripheral if extcon is present Andrey Smirnov
2022-02-22  6:01 ` Greg KH
2022-02-23  0:58 ` 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=b5a2bc30-f017-980e-83ce-f654ca6ae2a0@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=balbi@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).