public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: hcd: add OTG ID signal sensing
@ 2014-12-16 23:16 Sergei Shtylyov
  2014-12-17  2:08 ` Peter Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2014-12-16 23:16 UTC (permalink / raw)
  To: gregkh, linux-usb; +Cc: linux-sh, linux-kernel

On the Renesas R8A7791 SoC based boards there's MAX3355 USB OTG chip and mini-AB
USB connector corresponding to USB port 0 driven either by EHCI/OHCI or  Renesas
USBHS gadget controller. And we'd like the  host/gadget drivers to work based on
the cable type connected. An 'extcon' driver for MAX3355 has been written, so we
only need to bind  to it via device tree which I'm doing in this patch.

I wasn't able to find a solution better than checking the cable type at the host
driver probe time and refusing to drive a host if B-cable is connected.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
The patch is against the 'usb-next' branch of Greg KH's 'usb.git' repo.
It needs the recent 'extcon' core in order to properly handle probe deferral.  

 drivers/usb/core/hcd.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Index: usb/drivers/usb/core/hcd.c
===================================================================
--- usb.orig/drivers/usb/core/hcd.c
+++ usb/drivers/usb/core/hcd.c
@@ -42,6 +42,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/types.h>
 
+#include <linux/extcon.h>
 #include <linux/phy/phy.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
@@ -2632,6 +2633,23 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	int retval;
 	struct usb_device *rhdev;
 
+	if (IS_ENABLED(CONFIG_EXTCON) &&
+	    of_property_read_bool(hcd->self.controller->of_node, "extcon")) {
+		struct extcon_dev *edev;
+
+		edev = extcon_get_edev_by_phandle(hcd->self.controller, 0);
+		if (IS_ERR(edev))
+			return PTR_ERR(edev);
+
+		retval = extcon_get_cable_state(edev, "USB-HOST");
+		if (!retval) {
+			dev_err(hcd->self.controller,
+				"OTG B-cable plugged in, host driver won't load\n");
+			return -EINVAL;
+		} else if (retval < 0)
+			return retval;
+	}
+
 	if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->usb_phy) {
 		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] usb: hcd: add OTG ID signal sensing
  2014-12-16 23:16 [PATCH] usb: hcd: add OTG ID signal sensing Sergei Shtylyov
@ 2014-12-17  2:08 ` Peter Chen
  2014-12-17 11:35   ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Chen @ 2014-12-17  2:08 UTC (permalink / raw)
  To: Sergei Shtylyov, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org
  Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org

 
> 
> On the Renesas R8A7791 SoC based boards there's MAX3355 USB OTG chip and
> mini-AB USB connector corresponding to USB port 0 driven either by EHCI/OHCI
> or  Renesas USBHS gadget controller. And we'd like the  host/gadget drivers to
> work based on the cable type connected. An 'extcon' driver for MAX3355 has
> been written, so we only need to bind  to it via device tree which I'm doing in
> this patch.
> 
> I wasn't able to find a solution better than checking the cable type at the host
> driver probe time and refusing to drive a host if B-cable is connected.
> 

You may need a dual-role/otg driver to do it, which can enable host/device function
according to ID pin.

Peter

> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 
> ---
> The patch is against the 'usb-next' branch of Greg KH's 'usb.git' repo.
> It needs the recent 'extcon' core in order to properly handle probe deferral.
> 
>  drivers/usb/core/hcd.c |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> Index: usb/drivers/usb/core/hcd.c
> ============================================================
> =======
> --- usb.orig/drivers/usb/core/hcd.c
> +++ usb/drivers/usb/core/hcd.c
> @@ -42,6 +42,7 @@
>  #include <linux/pm_runtime.h>
>  #include <linux/types.h>
> 
> +#include <linux/extcon.h>
>  #include <linux/phy/phy.h>
>  #include <linux/usb.h>
>  #include <linux/usb/hcd.h>
> @@ -2632,6 +2633,23 @@ int usb_add_hcd(struct usb_hcd *hcd,
>  	int retval;
>  	struct usb_device *rhdev;
> 
> +	if (IS_ENABLED(CONFIG_EXTCON) &&
> +	    of_property_read_bool(hcd->self.controller->of_node, "extcon")) {
> +		struct extcon_dev *edev;
> +
> +		edev = extcon_get_edev_by_phandle(hcd->self.controller, 0);
> +		if (IS_ERR(edev))
> +			return PTR_ERR(edev);
> +
> +		retval = extcon_get_cable_state(edev, "USB-HOST");
> +		if (!retval) {
> +			dev_err(hcd->self.controller,
> +				"OTG B-cable plugged in, host driver won't
> load\n");
> +			return -EINVAL;
> +		} else if (retval < 0)
> +			return retval;
> +	}
> +
>  	if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->usb_phy) {
>  		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller,
> 0);
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body
> of a message to majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: hcd: add OTG ID signal sensing
  2014-12-17  2:08 ` Peter Chen
@ 2014-12-17 11:35   ` Sergei Shtylyov
  0 siblings, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2014-12-17 11:35 UTC (permalink / raw)
  To: Peter Chen, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org
  Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org

Hello.

On 12/17/2014 5:08 AM, Peter Chen wrote:

>> On the Renesas R8A7791 SoC based boards there's MAX3355 USB OTG chip and
>> mini-AB USB connector corresponding to USB port 0 driven either by EHCI/OHCI
>> or  Renesas USBHS gadget controller. And we'd like the  host/gadget drivers to
>> work based on the cable type connected. An 'extcon' driver for MAX3355 has
>> been written, so we only need to bind  to it via device tree which I'm doing in
>> this patch.

>> I wasn't able to find a solution better than checking the cable type at the host
>> driver probe time and refusing to drive a host if B-cable is connected.

> You may need a dual-role/otg driver to do it, which can enable host/device function
> according to ID pin.

    It would have been too good if I had a dual-role controller. :-)
    But I have what I have. IIUC, such configuration (OHCI and UDC sharing a 
USB port) has been used on OMAP1.

WBR, Sergei


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-17 11:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-16 23:16 [PATCH] usb: hcd: add OTG ID signal sensing Sergei Shtylyov
2014-12-17  2:08 ` Peter Chen
2014-12-17 11:35   ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox