浏览代码

usb: renesas_usbhs: add OTG ID signal sensing

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.

(Perhaps, it would also make sense to use OTG HNP when the USBHS host mode is
active and a B-cable is connected but I don't have access to host-capable USBHS,
so  wouldn't be able to test it.)

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Sergei Shtylyov 10 年之前
父节点
当前提交
d7b3968dbc
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 17 0
      drivers/usb/renesas_usbhs/common.c
  2. 3 0
      drivers/usb/renesas_usbhs/common.h

+ 17 - 0
drivers/usb/renesas_usbhs/common.c

@@ -363,6 +363,7 @@ static void usbhsc_hotplug(struct usbhs_priv *priv)
 	struct usbhs_mod *mod = usbhs_mod_get_current(priv);
 	struct usbhs_mod *mod = usbhs_mod_get_current(priv);
 	int id;
 	int id;
 	int enable;
 	int enable;
+	int cable;
 	int ret;
 	int ret;
 
 
 	/*
 	/*
@@ -376,6 +377,16 @@ static void usbhsc_hotplug(struct usbhs_priv *priv)
 	id = usbhs_platform_call(priv, get_id, pdev);
 	id = usbhs_platform_call(priv, get_id, pdev);
 
 
 	if (enable && !mod) {
 	if (enable && !mod) {
+		if (priv->edev) {
+			cable = extcon_get_cable_state(priv->edev, "USB-HOST");
+			if ((cable > 0 && id != USBHS_HOST) ||
+			    (!cable && id != USBHS_GADGET)) {
+				dev_info(&pdev->dev,
+					 "USB cable plugged in doesn't match the selected role!\n");
+				return;
+			}
+		}
+
 		ret = usbhs_mod_change(priv, id);
 		ret = usbhs_mod_change(priv, id);
 		if (ret < 0)
 		if (ret < 0)
 			return;
 			return;
@@ -514,6 +525,12 @@ static int usbhs_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->base))
 	if (IS_ERR(priv->base))
 		return PTR_ERR(priv->base);
 		return PTR_ERR(priv->base);
 
 
+	if (of_property_read_bool(pdev->dev.of_node, "extcon")) {
+		priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
+		if (IS_ERR(priv->edev))
+			return PTR_ERR(priv->edev);
+	}
+
 	/*
 	/*
 	 * care platform info
 	 * care platform info
 	 */
 	 */

+ 3 - 0
drivers/usb/renesas_usbhs/common.h

@@ -17,6 +17,7 @@
 #ifndef RENESAS_USB_DRIVER_H
 #ifndef RENESAS_USB_DRIVER_H
 #define RENESAS_USB_DRIVER_H
 #define RENESAS_USB_DRIVER_H
 
 
+#include <linux/extcon.h>
 #include <linux/platform_device.h>
 #include <linux/platform_device.h>
 #include <linux/usb/renesas_usbhs.h>
 #include <linux/usb/renesas_usbhs.h>
 
 
@@ -254,6 +255,8 @@ struct usbhs_priv {
 	struct delayed_work notify_hotplug_work;
 	struct delayed_work notify_hotplug_work;
 	struct platform_device *pdev;
 	struct platform_device *pdev;
 
 
+	struct extcon_dev *edev;
+
 	spinlock_t		lock;
 	spinlock_t		lock;
 
 
 	u32 flags;
 	u32 flags;