Skip to contentSkip to conversation

USB OTG/dual-role framework

PATCH Superseded Roger Quadros 6 participants 100 messages Apr 5, 2016 – May 4, 2016 Page 2 of 2

Subsystems (8)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#71 lore raw

Re: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

In reply to Roger Quadros
Quoted 12 lines · Roger Quadros
Quoted 11 lines · Jun Li

Hi

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3024

Quoted 6 lines
drivers/usb/core/hcd.c +5 -0
+
+static struct otg_hcd_ops otg_hcd_intf = {
+	.add = usb_add_hcd,
+	.remove = usb_remove_hcd,
+	.usb_bus_start_enum = usb_bus_start_enum,

Build break if CONFIG_USB_OTG is not enabled:

Quoted 3 lines
Quoted 3 lines

drivers/built-in.o:(.data+0x1db30): undefined reference to `usb_bus_start_enum' Makefile:948: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

I couldn't get this error. Could you please send me your .config? Thanks.

cheers,
-roger

Quoted 16 lines

Thanks. Will fix it.

cheers,
-roger

Quoted 5 lines

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3028

Quoted 4 lines
drivers/usb/core/hcd.c +3 -0
+	.usb_control_msg = usb_control_msg,
+	.usb_hub_find_child = usb_hub_find_child, };
+

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#72 lore raw

RE: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

Hi

Quoted 24 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Wednesday, April 27, 2016 7:12 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

Quoted 12 lines · Roger Quadros
Quoted 11 lines · Jun Li

Hi

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3024

Quoted 6 lines
drivers/usb/core/hcd.c +5 -0
+
+static struct otg_hcd_ops otg_hcd_intf = {
+	.add = usb_add_hcd,
+	.remove = usb_remove_hcd,
+	.usb_bus_start_enum = usb_bus_start_enum,

Build break if CONFIG_USB_OTG is not enabled:

Quoted 6 lines
Quoted 1 line
Quoted 1 line

drivers/built-in.o:(.data+0x1db30): undefined reference to

`usb_bus_start_enum'

Quoted 2 lines
Quoted 2 lines

Makefile:948: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

I couldn't get this error. Could you please send me your .config? Thanks.

imx_v6_v7_defconfig

Quoted 19 lines

cheers,
-roger

Quoted 16 lines

Thanks. Will fix it.

cheers,
-roger

Quoted 5 lines

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3028

Quoted 4 lines
drivers/usb/core/hcd.c +3 -0
+	.usb_control_msg = usb_control_msg,
+	.usb_hub_find_child = usb_hub_find_child, };
+

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#73 lore raw

RE: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

Hi,

Quoted 37 lines

-----Original Message-----
From: Jun Li [mailto:[email protected]]
Sent: Wednesday, April 27, 2016 8:50 PM
To: Roger Quadros <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

Hi

Quoted 25 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Wednesday, April 27, 2016 7:12 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 08/12] usb: hcd: Adapt to OTG core

Quoted 12 lines · Roger Quadros
Quoted 11 lines · Jun Li

Hi

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3024

Quoted 6 lines
drivers/usb/core/hcd.c +5 -0
+
+static struct otg_hcd_ops otg_hcd_intf = {
+	.add = usb_add_hcd,
+	.remove = usb_remove_hcd,
+	.usb_bus_start_enum = usb_bus_start_enum,

Build break if CONFIG_USB_OTG is not enabled:

Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

drivers/built-in.o:(.data+0x1db30): undefined reference to

`usb_bus_start_enum'

Quoted 2 lines
Quoted 2 lines

Makefile:948: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

I couldn't get this error. Could you please send me your .config? Thanks.

imx_v6_v7_defconfig

My bad, no problem now.

Li Jun

Quoted 20 lines
Quoted 20 lines

cheers,
-roger

Quoted 16 lines

Thanks. Will fix it.

cheers,
-roger

Quoted 5 lines

drivers/usb/core/hcd.c void usb_remove_hcd(struct usb_hcd *hcd) · line 3028

Quoted 4 lines
drivers/usb/core/hcd.c +3 -0
+	.usb_control_msg = usb_control_msg,
+	.usb_hub_find_child = usb_hub_find_child, };
+

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#74 lore raw

PATCH v6 9/12 usb: gadget: udc: adapt to OTG core

In reply to Roger Quadros

The OTG state machine needs a mechanism to start and stop the gadget controller. Add usb_gadget_start() and usb_gadget_stop().

Introduce usb_otg_add_gadget_udc() to allow controller drivers to register a gadget controller that is part of an OTG instance.

Register with OTG core when gadget function driver is available and unregister when function driver is unbound.

We need to unlock the usb_lock mutexbefore calling usb_otg_register_gadget() in udc_bind_to_driver() and usb_gadget_remove_driver() else it will cause a circular locking dependency.

Ignore softconnect sysfs control when we're in OTG mode as OTG FSM takes care of gadget softconnect using the b_bus_req mechanism.

---
 drivers/usb/gadget/udc/udc-core.c | 166 +++++++++++++++++++++++++++++++++++---
 include/linux/usb/gadget.h        |   4 +
 2 files changed, 161 insertions(+), 9 deletions(-)
drivers/usb/gadget/udc/udc-core.c +157 -9
index 4151597..9b9702f 100644
@@ -28,6 +28,10 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb.h>
+#include <linux/usb/otg.h>
+
+#include <linux/of.h>
+#include <linux/of_platform.h>
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -304,6 +308,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
  */
 static inline int usb_gadget_udc_start(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
 }
 
@@ -321,10 +326,81 @@ static inline int usb_gadget_udc_start(struct usb_udc *udc)
  */
 static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	udc->gadget->ops->udc_stop(udc->gadget);
 }
 
 /**
+ * usb_gadget_start - start the usb gadget controller and connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget)
+{
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget)
+{
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+
+/**
  * usb_udc_release - release the usb_udc struct
  * @dev: the dev member within usb_udc
  *
@@ -486,6 +562,48 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
 }
 EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
 
+/**
+ * usb_otg_add_gadget_udc - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller
+ * driver's device.
+ * @gadget: the gadget to be added to the list
+ * @otg_dev: the OTG controller device
+ *
+ * If otg_dev is NULL then device tree node is checked
+ * for OTG controller via the otg-controller property.
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_otg_add_gadget_udc(struct device *parent, struct usb_gadget *gadget,
+			   struct device *otg_dev)
+{
+	if (!otg_dev) {
+		struct device_node *np;
+		struct platform_device *pdev;
+
+		np = of_parse_phandle(parent->of_node, "otg-controller", 0);
+		if (!np) {
+			dev_err(parent,
+				"otg_dev is NULL or no otg-controller property in DT\n");
+			return -EINVAL;
+		}
+
+		pdev = of_find_device_by_node(np);
+		of_node_put(np);
+		if (!pdev) {
+			dev_err(parent, "couldn't get otg-controller device\n");
+			return -ENODEV;
+		}
+
+		gadget->otg_dev = &pdev->dev;
+	} else {
+		gadget->otg_dev = otg_dev;
+	}
+
+	return usb_add_gadget_udc_release(parent, gadget, NULL);
+}
+EXPORT_SYMBOL_GPL(usb_otg_add_gadget_udc);
+
+/* udc_lock must be held */
 static void usb_gadget_remove_driver(struct usb_udc *udc)
 {
 	dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
@@ -493,10 +611,18 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
 
 	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
 
-	usb_gadget_disconnect(udc->gadget);
-	udc->driver->disconnect(udc->gadget);
+	/* If OTG, the otg core ensures UDC is stopped on unregister */
+	if (udc->gadget->otg_dev) {
+		mutex_unlock(&udc_lock);
+		usb_otg_unregister_gadget(udc->gadget);
+		mutex_lock(&udc_lock);
+	} else {
+		usb_gadget_disconnect(udc->gadget);
+		udc->driver->disconnect(udc->gadget);
+		usb_gadget_udc_stop(udc);
+	}
+
 	udc->driver->unbind(udc->gadget);
-	usb_gadget_udc_stop(udc);
 
 	udc->driver = NULL;
 	udc->dev.driver = NULL;
@@ -530,6 +656,8 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
 	}
 	mutex_unlock(&udc_lock);
 
+	mutex_unlock(&udc_lock);
+
 	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
 	flush_work(&gadget->work);
 	device_unregister(&udc->dev);
@@ -539,6 +667,12 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* ------------------------------------------------------------------------- */
 
+struct otg_gadget_ops otg_gadget_intf = {
+	.start = usb_gadget_start,
+	.stop = usb_gadget_stop,
+};
+
+/* udc_lock must be held */
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
 {
 	int ret;
@@ -553,12 +687,20 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 	ret = driver->bind(udc->gadget, driver);
 	if (ret)
 		goto err1;
-	ret = usb_gadget_udc_start(udc);
-	if (ret) {
-		driver->unbind(udc->gadget);
-		goto err1;
+
+	/* If OTG, the otg core starts the UDC when needed */
+	if (udc->gadget->otg_dev) {
+		mutex_unlock(&udc_lock);
+		usb_otg_register_gadget(udc->gadget, &otg_gadget_intf);
+		mutex_lock(&udc_lock);
+	} else {
+		ret = usb_gadget_udc_start(udc);
+		if (ret) {
+			driver->unbind(udc->gadget);
+			goto err1;
+		}
+		usb_udc_connect_control(udc);
 	}
-	usb_udc_connect_control(udc);
 
 	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
 	return 0;
@@ -660,9 +802,15 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
 		return -EOPNOTSUPP;
 	}
 
+	/* In OTG mode we don't support softconnect, but b_bus_req */
+	if (udc->gadget->otg_dev) {
+		dev_err(dev, "soft-connect not supported in OTG mode\n");
+		return -EOPNOTSUPP;
+	}
+
 	if (sysfs_streq(buf, "connect")) {
 		usb_gadget_udc_start(udc);
-		usb_gadget_connect(udc->gadget);
+		usb_udc_connect_control(udc);
 	} else if (sysfs_streq(buf, "disconnect")) {
 		usb_gadget_disconnect(udc->gadget);
 		udc->driver->disconnect(udc->gadget);
include/linux/usb/gadget.h +4 -0
index 1878ae1..061f09e4 100644
@@ -1160,6 +1160,10 @@ extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
 extern void usb_del_gadget_udc(struct usb_gadget *gadget);
 extern char *usb_get_gadget_udc_name(void);
 
+extern int usb_otg_add_gadget_udc(struct device *parent,
+				     struct usb_gadget *gadget,
+				     struct device *otg_dev);
+
 /*-------------------------------------------------------------------------*/
 
 /* utility to simplify dealing with string descriptors */
Signature · 1 line
2.5.0
#75 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 11 lines · Roger Quadros

The OTG state machine needs a mechanism to start and stop the gadget controller. Add usb_gadget_start() and usb_gadget_stop().

Introduce usb_otg_add_gadget_udc() to allow controller drivers to register a gadget controller that is part of an OTG instance.

Register with OTG core when gadget function driver is available and unregister when function driver is unbound.

We need to unlock the usb_lock mutexbefore calling

...mutex before...

Quoted 30 lines

usb_otg_register_gadget() in udc_bind_to_driver() and usb_gadget_remove_driver() else it will cause a circular locking dependency.

Ignore softconnect sysfs control when we're in OTG mode as OTG FSM takes care of gadget softconnect using the b_bus_req mechanism.

---
 drivers/usb/gadget/udc/udc-core.c | 166 +++++++++++++++++++++++++++++++++++---
 include/linux/usb/gadget.h        |   4 +
 2 files changed, 161 insertions(+), 9 deletions(-)
drivers/usb/gadget/udc/udc-core.c +4 -0
index 4151597..9b9702f 100644
@@ -28,6 +28,10 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb.h>
+#include <linux/usb/otg.h>
+
+#include <linux/of.h>
+#include <linux/of_platform.h>
 
 /**
  * struct usb_udc - describes one usb device controller

drivers/usb/gadget/udc/udc-core.c EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); · line 313

Quoted 6 lines
drivers/usb/gadget/udc/udc-core.c +1 -0
@@ -304,6 +308,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
  */
 static inline int usb_gadget_udc_start(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
 }

You may delete the debug message next time.

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 331

Quoted 8 lines
drivers/usb/gadget/udc/udc-core.c +1 -0
@@ -321,10 +326,81 @@ static inline int usb_gadget_udc_start(struct usb_udc *udc)
  */
 static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	udc->gadget->ops->udc_stop(udc->gadget);
 }

The same.

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +3 -0
 /**
+ * usb_gadget_start - start the usb gadget controller and connect to bus
+ * @gadget: the gadget device to start
+ *

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 346

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget)
+{
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);

The same

Quoted 27 lines
drivers/usb/gadget/udc/udc-core.c +27 -0
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 383

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget)
+{
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);

The same

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 355

Quoted 9 lines
drivers/usb/gadget/udc/udc-core.c +9 -0
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;

The above finding gadget code is the same with usb_gadget_start, can we use one common API to instead of it?

Quoted 44 lines
drivers/usb/gadget/udc/udc-core.c +37 -0
+
+found:
+	usb_gadget_disconnect(udc->gadget);
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+
+/**
  * usb_udc_release - release the usb_udc struct
  * @dev: the dev member within usb_udc
  *
@@ -486,6 +562,48 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
 }
 EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
 
+/**
+ * usb_otg_add_gadget_udc - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller
+ * driver's device.
+ * @gadget: the gadget to be added to the list
+ * @otg_dev: the OTG controller device
+ *
+ * If otg_dev is NULL then device tree node is checked
+ * for OTG controller via the otg-controller property.
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_otg_add_gadget_udc(struct device *parent, struct usb_gadget *gadget,
+			   struct device *otg_dev)
+{
+	if (!otg_dev) {
+		struct device_node *np;
+		struct platform_device *pdev;
+
+		np = of_parse_phandle(parent->of_node, "otg-controller", 0);
+		if (!np) {
+			dev_err(parent,
+				"otg_dev is NULL or no otg-controller property in DT\n");
+			return -EINVAL;
+		}
+
+		pdev = of_find_device_by_node(np);

drivers/usb/gadget/udc/udc-core.c int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) · line 600

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		of_node_put(np);
+		if (!pdev) {
+			dev_err(parent, "couldn't get otg-controller device\n");
+			return -ENODEV;
+		}
+
+		gadget->otg_dev = &pdev->dev;
+	} else {
+		gadget->otg_dev = otg_dev;
+	}

The above the code is duplicated with hcd's. Can we do something common at usb-otg.c, eg define an API get_usb_otg_dev(struct usb_gadget *gadget, struct usb_hcd *hcd), in this API we can try to get otg_dev for both gadget and hcd, and we can call it at controller driver during register otg.

Signature · 6 lines
Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#76 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 8 lines · Peter Chen
Quoted 7 lines · Roger Quadros

The OTG state machine needs a mechanism to start and stop the gadget controller. Add usb_gadget_start() and usb_gadget_stop().

Introduce usb_otg_add_gadget_udc() to allow controller drivers to register a gadget controller that is part of an OTG instance.

Quoted 6 lines
Quoted 4 lines

Register with OTG core when gadget function driver is available and unregister when function driver is unbound.

We need to unlock the usb_lock mutexbefore calling

...mutex before...

OK.

Quoted 28 lines
Quoted 28 lines

usb_otg_register_gadget() in udc_bind_to_driver() and usb_gadget_remove_driver() else it will cause a circular locking dependency.

Ignore softconnect sysfs control when we're in OTG mode as OTG FSM takes care of gadget softconnect using the b_bus_req mechanism.

---
 drivers/usb/gadget/udc/udc-core.c | 166 +++++++++++++++++++++++++++++++++++---
 include/linux/usb/gadget.h        |   4 +
 2 files changed, 161 insertions(+), 9 deletions(-)
drivers/usb/gadget/udc/udc-core.c +4 -0
index 4151597..9b9702f 100644
@@ -28,6 +28,10 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb.h>
+#include <linux/usb/otg.h>
+
+#include <linux/of.h>
+#include <linux/of_platform.h>
 
Quoted 11 lines

drivers/usb/gadget/udc/udc-core.c EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); · line 313

Quoted 9 lines
drivers/usb/gadget/udc/udc-core.c +1 -0
 /**
  * struct usb_udc - describes one usb device controller
@@ -304,6 +308,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
  */
 static inline int usb_gadget_udc_start(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
 }

You may delete the debug message next time.

OK for this and all the next comments to remove debug messages.

Quoted 70 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 331

Quoted 9 lines
drivers/usb/gadget/udc/udc-core.c +1 -0
@@ -321,10 +326,81 @@ static inline int usb_gadget_udc_start(struct usb_udc *udc)
  */
 static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 {
+	dev_dbg(&udc->dev, "%s\n", __func__);
 	udc->gadget->ops->udc_stop(udc->gadget);
 }

The same.

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +3 -0
 /**
+ * usb_gadget_start - start the usb gadget controller and connect to bus
+ * @gadget: the gadget device to start
+ *

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 346

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget)
+{
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);

The same

Quoted 27 lines
drivers/usb/gadget/udc/udc-core.c +27 -0
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 383

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget)
+{
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);

The same

Quoted 12 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 355

Quoted 9 lines
drivers/usb/gadget/udc/udc-core.c +9 -0
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;

The above finding gadget code is the same with usb_gadget_start, can we use one common API to instead of it?

Sure.

Quoted 52 lines
Quoted 52 lines
drivers/usb/gadget/udc/udc-core.c +44 -0
+
+found:
+	usb_gadget_disconnect(udc->gadget);
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+
+/**
  * usb_udc_release - release the usb_udc struct
  * @dev: the dev member within usb_udc
  *
@@ -486,6 +562,48 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
 }
 EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
 
+/**
+ * usb_otg_add_gadget_udc - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller
+ * driver's device.
+ * @gadget: the gadget to be added to the list
+ * @otg_dev: the OTG controller device
+ *
+ * If otg_dev is NULL then device tree node is checked
+ * for OTG controller via the otg-controller property.
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_otg_add_gadget_udc(struct device *parent, struct usb_gadget *gadget,
+			   struct device *otg_dev)
+{
+	if (!otg_dev) {
+		struct device_node *np;
+		struct platform_device *pdev;
+
+		np = of_parse_phandle(parent->of_node, "otg-controller", 0);
+		if (!np) {
+			dev_err(parent,
+				"otg_dev is NULL or no otg-controller property in DT\n");
+			return -EINVAL;
+		}
+
+		pdev = of_find_device_by_node(np);
+		of_node_put(np);
+		if (!pdev) {
+			dev_err(parent, "couldn't get otg-controller device\n");
+			return -ENODEV;
+		}
+
+		gadget->otg_dev = &pdev->dev;
Quoted 9 lines

drivers/usb/gadget/udc/udc-core.c int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) · line 600

Quoted 3 lines
drivers/usb/gadget/udc/udc-core.c +3 -0
+	} else {
+		gadget->otg_dev = otg_dev;
+	}

The above the code is duplicated with hcd's. Can we do something common at usb-otg.c, eg define an API get_usb_otg_dev(struct usb_gadget *gadget, struct usb_hcd *hcd), in this API we can try to get otg_dev for both gadget and hcd, and we can call it at controller driver during register otg.

Good point. I'll address it in v7.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#77 lore raw

RE: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

In reply to Roger Quadros

Hi,

...

Quoted 22 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect to

drivers/usb/gadget/udc/udc-core.c +19 -0
+bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by loc_conn() instead of gadget start.

Quoted 21 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

#78 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 30 lines · Jun Li

Hi,

...

Quoted 27 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect to

drivers/usb/gadget/udc/udc-core.c +24 -0
+bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
Quoted 8 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +5 -0
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

cheers,
-roger

Quoted 46 lines
Quoted 22 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

#79 lore raw

RE: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi

Quoted 53 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Monday, April 25, 2016 10:04 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 30 lines · Jun Li

Hi,

...

Quoted 27 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect to

drivers/usb/gadget/udc/udc-core.c +24 -0
+bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
Quoted 8 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +5 -0
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by loc_conn() instead of gadget start.

Quoted 5 lines

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

You intend to abstract something common in this api when start gadget, which should be called by otg_set_protocol(fsm, PROTO_GADGET); and drd_set_protocol(fsm, PROTO_GADGET); right?

So you may move usb_udc_connect_control(IMO usb_gadget_connect() is better)out of usb_gadget_start(), then for drd:

case OTG_STATE_B_PERIPHERAL:

     drd_set_protocol(fsm, PROTO_GADGET);
     otg_drv_vbus(otg, 0);
     usb_gadget_connect();

Li Jun

Quoted 50 lines

cheers,
-roger

Quoted 46 lines
Quoted 22 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

#80 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 73 lines · Jun Li

Hi

Quoted 53 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Monday, April 25, 2016 10:04 PM
To: Jun Li <[email protected]>; stern-nwvwT67g6+6dFdvTe/[email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; mathias.nyman-VuQAYsv1563Yd54FQh9/[email protected]; [email protected]; Joao.Pinto-HKixBCOQz3hWk0Htik3J/[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 30 lines · Jun Li

Hi,

...

Quoted 27 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect to

drivers/usb/gadget/udc/udc-core.c +24 -0
+bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
Quoted 8 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +5 -0
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by loc_conn() instead of gadget start.

Quoted 5 lines

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

You intend to abstract something common in this api when start gadget, which should be called by otg_set_protocol(fsm, PROTO_GADGET); and drd_set_protocol(fsm, PROTO_GADGET); right?

Quoted 7 lines

So you may move usb_udc_connect_control(IMO usb_gadget_connect() is better)out of usb_gadget_start(), then for drd:

case OTG_STATE_B_PERIPHERAL:

     drd_set_protocol(fsm, PROTO_GADGET);
     otg_drv_vbus(otg, 0);
     usb_gadget_connect();

OK. I understand now. I'll implement your suggestion. Thanks.

cheers,
-roger

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 22 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#81 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 62 lines · Roger Quadros
Quoted 61 lines · Jun Li

Hi

Quoted 58 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Monday, April 25, 2016 10:04 PM
To: Jun Li <[email protected]>; stern-nwvwT67g6+6dFdvTe/[email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; mathias.nyman-VuQAYsv1563Yd54FQh9/[email protected]; [email protected]; Joao.Pinto-HKixBCOQz3hWk0Htik3J/[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 30 lines · Jun Li

Hi,

...

Quoted 27 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect to

drivers/usb/gadget/udc/udc-core.c +24 -0
+bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
Quoted 8 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 5 lines
drivers/usb/gadget/udc/udc-core.c +5 -0
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull. usb_gadget_stop() implies that gadget controller disables pull and stops.

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

cheers,
-roger

Quoted 64 lines
Quoted 5 lines

You intend to abstract something common in this api when start gadget, which should be called by otg_set_protocol(fsm, PROTO_GADGET); and drd_set_protocol(fsm, PROTO_GADGET); right?

Quoted 7 lines

So you may move usb_udc_connect_control(IMO usb_gadget_connect() is better)out of usb_gadget_start(), then for drd:

case OTG_STATE_B_PERIPHERAL:

     drd_set_protocol(fsm, PROTO_GADGET);
     otg_drv_vbus(otg, 0);
     usb_gadget_connect();

OK. I understand now. I'll implement your suggestion. Thanks.

cheers,
-roger

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 22 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#82 lore raw

RE: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi

Quoted 100 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Thursday, April 28, 2016 5:55 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 43 lines · Roger Quadros
Quoted 42 lines · Jun Li

Hi

Quoted 40 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Monday, April 25, 2016 10:04 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 24 lines · Jun Li

Hi,

...

Quoted 21 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect

drivers/usb/gadget/udc/udc-core.c +18 -0
+to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc)

Quoted 8 lines
drivers/usb/gadget/udc/udc-core.c +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 363

Quoted 3 lines
drivers/usb/gadget/udc/udc-core.c +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and stops.

Quoted 5 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Li Jun

Quoted 73 lines

cheers,
-roger

Quoted 69 lines
Quoted 5 lines

You intend to abstract something common in this api when start gadget, which should be called by otg_set_protocol(fsm, PROTO_GADGET); and drd_set_protocol(fsm, PROTO_GADGET); right?

Quoted 7 lines

So you may move usb_udc_connect_control(IMO usb_gadget_connect() is better)out of usb_gadget_start(), then for drd:

case OTG_STATE_B_PERIPHERAL:

     drd_set_protocol(fsm, PROTO_GADGET);
     otg_drv_vbus(otg, 0);
     usb_gadget_connect();

OK. I understand now. I'll implement your suggestion. Thanks.

cheers,
-roger

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 22 lines
drivers/usb/gadget/udc/udc-core.c +21 -0
+
+	mutex_unlock(&udc_lock);
+
+	return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget) {
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 395

Quoted 10 lines
drivers/usb/gadget/udc/udc-core.c +10 -0
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	usb_gadget_disconnect(udc->gadget);

Likewise, gadget disconnect also should be done by loc_conn() instead of gadget stop.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/usb/gadget/udc/udc-core.c static inline int usb_gadget_udc_start(struct usb_udc *udc) · line 402

Quoted 7 lines
drivers/usb/gadget/udc/udc-core.c +7 -0
+	udc->driver->disconnect(udc->gadget);
+	usb_gadget_udc_stop(udc);
+	mutex_unlock(&udc_lock);
+
+	return 0;
+}
+

Li Jun

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#83 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 108 lines · Jun Li

Hi

Quoted 100 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Thursday, April 28, 2016 5:55 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 43 lines · Roger Quadros
Quoted 42 lines · Jun Li

Hi

Quoted 40 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Monday, April 25, 2016 10:04 PM
To: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 24 lines · Jun Li

Hi,

...

Quoted 21 lines

/**
+ * usb_gadget_start - start the usb gadget controller and connect

(quoted diff) +18 -0
+to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and stops.

Quoted 5 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

As per 7.4.2.3
"loc_conn
The “local connect” (loc_conn) variable is TRUE when the local device has signaled that it is connected to the bus. This variable is FALSE when the local device has signaled that it is disconnected from the bus"

Can you please point me in the specification if there is any place where loc_conn is false and b_peripheral/a_peripheral is true?

cheers,
-roger

#84 lore raw

RE: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

Quoted 12 lines

As per 7.4.2.3
"loc_conn
The "local connect" (loc_conn) variable is TRUE when the local device has signaled that it is connected to the bus. This variable is FALSE when the local device has signaled that it is disconnected from the bus"

Can you please point me in the specification if there is any place where loc_conn is false and b_peripheral/a_peripheral is true?

cheers,
-roger

#85 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Hi,

Quoted 96 lines · Jun Li

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

Quoted 7 lines

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is just complicating things.

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled a connect. So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false otherwise.

Note, OTG specification does not say to take any action based on loc_conn. It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

cheers,
-roger

Quoted 13 lines
Quoted 13 lines

As per 7.4.2.3
"loc_conn
The "local connect" (loc_conn) variable is TRUE when the local device has signaled that it is connected to the bus. This variable is FALSE when the local device has signaled that it is disconnected from the bus"

Can you please point me in the specification if there is any place where loc_conn is false and b_peripheral/a_peripheral is true?

cheers,
-roger

#86 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 123 lines · Roger Quadros

Hi,

Quoted 96 lines · Jun Li

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

Quoted 7 lines

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is just complicating things.

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled a connect. So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false otherwise.

Quoted 7 lines

Note, OTG specification does not say to take any action based on loc_conn. It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

I agree with you, roger.

loc_conn action is only needed for peripheral, we can't do real !loc_conn at host mode. Besides, loc_conn is the output, we need to set/clear it after state has changed, and current gadget framework already takes well for connection and disconnection state, so it is better to delete loc_conn action at otg_fsm->ops, and only keeps it as indicator for OTG FSM reference.

Signature · 6 lines
Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#87 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

In reply to Roger Quadros
Quoted 123 lines · Roger Quadros

Hi,

Quoted 96 lines · Jun Li

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

Quoted 7 lines

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is just complicating things.

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled a connect. So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false otherwise.

Quoted 7 lines

Note, OTG specification does not say to take any action based on loc_conn. It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget, and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)

{
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;

	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:
+		usb_udc_vbus_handler(gadget, false);
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
+		usb_udc_vbus_handler(gadget, true);
		otg_drv_vbus(otg, 0);
		break;
	......
	};

}

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

Signature · 2 lines
Best Regards,
Peter Chen
#88 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Peter,

Quoted 128 lines · Peter Chen
Quoted 127 lines · Roger Quadros

Hi,

Quoted 96 lines · Jun Li

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

Quoted 7 lines

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is just complicating things.

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled a connect. So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false otherwise.

Note, OTG specification does not say to take any action based on loc_conn. It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

Quoted 6 lines
Quoted 3 lines

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget,

Which situations?

Quoted 15 lines

and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)

{
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;

	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, false);

This is redundant, When we switch from PROTO_GADGET to PROTO_UNDEF we do a usb_gadget_stop(), and a usb_gadget_disconnect() is done there.

Review

Quoted 6 lines
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, true);

This is redundant as well since usb_gadget_start() is doing a usb_gadget_connect().

Quoted 10 lines
		otg_drv_vbus(otg, 0);
		break;
	......
	};

}

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

I have no strong opinions for or against usb_fsm->ops->loc_conn. Although strictly speaking, we shouldn't take any action based on loc_conn. It is just a state variable indicator.

cheers,
-roger

#89 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 131 lines · Roger Quadros

Peter,

Quoted 128 lines · Peter Chen
Quoted 127 lines · Roger Quadros

Hi,

Quoted 96 lines · Jun Li

Hi

Quoted 79 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

/**
+ * usb_gadget_start - start the usb gadget controller and +connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable

pull).

Quoted 48 lines
Quoted 48 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

+ */

(quoted diff) +11 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 5 lines
Quoted 5 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common, let's keep them separated.

Quoted 2 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 3 lines

loc_conn is just an internal state variable and it corresponds to our gadget_start/stop() state.

Quoted 7 lines

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is just complicating things.

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled a connect. So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false otherwise.

Note, OTG specification does not say to take any action based on loc_conn. It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget,

Which situations?

Not sure if all SoC works like that.

Quoted 11 lines
Quoted 11 lines

and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)

{
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;
Quoted 9 lines

Review

Quoted 6 lines
	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, false);

This is redundant, When we switch from PROTO_GADGET to PROTO_UNDEF we do a usb_gadget_stop(), and a usb_gadget_disconnect() is done there.

Since fully OTG FSM needs to call usb_gadget_stop too, and it doesn't want need to call usb_gadget_disconnect at usb_gadget_stop, it calls usb_gadget_disconnect at otg_fsm->ops->loc_conn in its FSM.

You current code combines otg_fsm->ops->loc_conn into otg_fsm->ops->start_gadget, but according to spec, ->loc_conn is an action after ->start_gadget.

Keep two actions alone can be flexible.

Quoted 11 lines

Review

Quoted 7 lines
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, true);

This is redundant as well since usb_gadget_start() is doing a usb_gadget_connect().

The same for above.

Quoted 7 lines
Quoted 7 lines
		otg_drv_vbus(otg, 0);
		break;
	......
	};

}

Quoted 8 lines
Quoted 3 lines

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

I have no strong opinions for or against usb_fsm->ops->loc_conn. Although strictly speaking, we shouldn't take any action based on loc_conn. It is just a state variable indicator.

No, please check the six outputs at the spec, all of them need to have an action, but your soc/code can do noop if the action has done at start/stop_role. If it is only a state variable indicator, and we have no code to use it, why it needs to be at fsm structure. We need to use this indicator to know if related action needs to be done again, see below API.

static inline int otg_loc_conn(struct otg_fsm *fsm, int on)

{
	if (!fsm->ops->loc_conn)
		return -EOPNOTSUPP;
	if (fsm->loc_conn != on) {
		fsm->loc_conn = on;
		fsm->ops->loc_conn(fsm, on);
	}
	return 0;
}

Yes, it can work even without loc_conn for fully OTG FSM, but it exists at OTG spec. We'd better to keep it to reflect the spec.

So, since usb_gadget_stop/usb_gadget_start is common API for both drd and fully fsm, we keep the same function for both. For drd, you doesn't need to define otg_fsm->ops->loc_conn at your platform, it calls usb_udc_vbus_handler at drd_set_state.

Signature · 2 lines
Best Regards,
Peter Chen
#90 lore raw

RE: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

In reply to Roger Quadros

Hi

Quoted 156 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Wednesday, May 04, 2016 2:37 PM
To: Peter Chen <[email protected]>
Cc: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Peter,

Quoted 16 lines · Peter Chen
Quoted 15 lines · Roger Quadros

Hi,

Quoted 12 lines · Jun Li

Hi

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines

/**
+ * usb_gadget_start - start the usb gadget controller and

(quoted diff) +7 -0
+connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus
+(enable

pull).

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+ */

(quoted diff) +3 -0
+static int usb_gadget_start(struct usb_gadget *gadget) {
+	int ret;
+	struct usb_udc *udc = NULL;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+
+	dev_dbg(&gadget->dev, "%s\n", __func__);
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "%s: gadget not

registered.\n",

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 36 lines
Quoted 36 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		__func__);
+	mutex_unlock(&udc_lock);
+	return -EINVAL;
+
+found:
+	ret = usb_gadget_udc_start(udc);
+	if (ret)
+		dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+			ret);
+	else
+		usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 6 lines
Quoted 6 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common,

let's keep them separated.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 3 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 4 lines

loc_conn is just an internal state variable and it corresponds to our
gadget_start/stop() state.

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

Quoted 7 lines
Quoted 7 lines

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is

just complicating things.

Quoted 6 lines
Quoted 6 lines

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled

a connect.

Quoted 2 lines
Quoted 2 lines

So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false

otherwise.

Quoted 2 lines
Quoted 2 lines

Note, OTG specification does not say to take any action based on

loc_conn.

Quoted 7 lines
Quoted 6 lines

It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Quoted 5 lines
Quoted 3 lines

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget,

Which situations?

When to pull-up DP is decided by application (while vbus is on), not only by driver state machine.

Quoted 36 lines
Quoted 16 lines

and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state

new_state) {
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;

	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, false);

This is redundant, When we switch from PROTO_GADGET to PROTO_UNDEF we do a usb_gadget_stop(), and a usb_gadget_disconnect() is done there.

Review

Quoted 6 lines
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, true);

This is redundant as well since usb_gadget_start() is doing a usb_gadget_connect().

Quoted 5 lines
		otg_drv_vbus(otg, 0);
		break;
	......
	};
Quoted 8 lines
Quoted 5 lines

}

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

I have no strong opinions for or against usb_fsm->ops->loc_conn. Although strictly speaking, we shouldn't take any action based on loc_conn.

Strictly speaking(OTG spec), all you does is for loc_conn, but you think it's start_gadget.

Quoted 1 line

It is just a state variable indicator.

Nobody check this "indicator".

Of cos, this is not a big deal, you can define the new API as is, do udc_start() + gadget_connect() in one shot, it's up to user to decide if use your usb_otg_start_gadget(), in case of udc_start() followed by gadget_connect() is not wanted, user can/need do udc_start() and something else before do gadget_connect.

Quoted 3 lines

cheers,
-roger

#91 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 158 lines · Jun Li

Hi

Quoted 156 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Wednesday, May 04, 2016 2:37 PM
To: Peter Chen <[email protected]>
Cc: Jun Li <[email protected]>; stern-nwvwT67g6+6dFdvTe/[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; mathias.nyman-VuQAYsv1563Yd54FQh9/[email protected]; [email protected]; Joao.Pinto-HKixBCOQz3hWk0Htik3J/[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Peter,

Quoted 16 lines · Peter Chen
Quoted 15 lines · Roger Quadros

Hi,

Quoted 12 lines · Jun Li

Hi

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

/**
+ * usb_gadget_start - start the usb gadget controller and
+connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus
+(enable

pull).

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+ int ret;
+ struct usb_udc *udc = NULL;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+
+ dev_dbg(&gadget->dev, "%s\n", __func__);
+ mutex_lock(&udc_lock);
+ list_for_each_entry(udc, &udc_list, list)
+ if (udc->gadget == gadget)
+ goto found;
+
+ dev_err(gadget->dev.parent, "%s: gadget not

registered.\n",

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 36 lines
Quoted 36 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+ __func__);
+ mutex_unlock(&udc_lock);
+ return -EINVAL;
+
+found:
+ ret = usb_gadget_udc_start(udc);
+ if (ret)
+ dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines
Quoted 3 lines

+ ret);
+ else
+ usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 6 lines
Quoted 6 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common,

let's keep them separated.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 3 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 4 lines

loc_conn is just an internal state variable and it corresponds to our
gadget_start/stop() state.

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

Quoted 7 lines
Quoted 7 lines

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is

just complicating things.

Quoted 6 lines
Quoted 6 lines

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled

a connect.

Quoted 2 lines
Quoted 2 lines

So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false

otherwise.

Quoted 2 lines
Quoted 2 lines

Note, OTG specification does not say to take any action based on

loc_conn.

Quoted 7 lines
Quoted 6 lines

It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget,

Which situations?

When to pull-up DP is decided by application (while vbus is on), not only by driver state machine.

So when OTG state is B_PERIPHERAL or A_PERIPHERAL we still want DP pull-up to be disabled?

Quoted 51 lines
Quoted 37 lines
Quoted 17 lines

and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state

new_state) {
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;

	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, false);

This is redundant, When we switch from PROTO_GADGET to PROTO_UNDEF we do a usb_gadget_stop(), and a usb_gadget_disconnect() is done there.

Review

Quoted 6 lines
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, true);

This is redundant as well since usb_gadget_start() is doing a usb_gadget_connect().

Quoted 5 lines
		otg_drv_vbus(otg, 0);
		break;
	......
	};
Quoted 8 lines
Quoted 5 lines

}

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

I have no strong opinions for or against usb_fsm->ops->loc_conn. Although strictly speaking, we shouldn't take any action based on loc_conn.

Strictly speaking(OTG spec), all you does is for loc_conn, but you think it's start_gadget.

Quoted 1 line

It is just a state variable indicator.

Quoted 7 lines

Nobody check this "indicator".

Of cos, this is not a big deal, you can define the new API as is, do udc_start() + gadget_connect() in one shot, it's up to user to decide if use your usb_otg_start_gadget(), in case of udc_start() followed by gadget_connect() is not wanted, user can/need do udc_start() and something else before do gadget_connect.

Please don't get me wrong. I want the full OTG state machine to be able to use usb_otg_start/stop_gadget().

Just trying to understand the real problem.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#92 lore raw

Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Quoted 224 lines · Roger Quadros
Quoted 158 lines · Jun Li

Hi

Quoted 156 lines

-----Original Message-----
From: Roger Quadros [mailto:[email protected]]
Sent: Wednesday, May 04, 2016 2:37 PM
To: Peter Chen <[email protected]>
Cc: Jun Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core

Peter,

Quoted 16 lines · Peter Chen
Quoted 15 lines · Roger Quadros

Hi,

Quoted 12 lines · Jun Li

Hi

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

/**
+ * usb_gadget_start - start the usb gadget controller and
+connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus
+(enable

pull).

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+ */
+static int usb_gadget_start(struct usb_gadget *gadget) {
+ int ret;
+ struct usb_udc *udc = NULL;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+
+ dev_dbg(&gadget->dev, "%s\n", __func__);
+ mutex_lock(&udc_lock);
+ list_for_each_entry(udc, &udc_list, list)
+ if (udc->gadget == gadget)
+ goto found;
+
+ dev_err(gadget->dev.parent, "%s: gadget not

registered.\n",

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 36 lines
Quoted 36 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+ __func__);
+ mutex_unlock(&udc_lock);
+ return -EINVAL;
+
+found:
+ ret = usb_gadget_udc_start(udc);
+ if (ret)
+ dev_err(&udc->dev, "USB Device Controller didn't

start: %d\n",

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines

+ ret);
+ else
+ usb_udc_connect_control(udc);

For drd, it's fine, but for real otg, gadget connect should
be done by
loc_conn() instead of gadget start.

It is upto the OTG state machine to call gadget_start() when it needs to connect to the bus (i.e. loc_conn()). I see no point in calling gadget start before.

Do you see any issue in doing so?

Quoted 7 lines
Quoted 7 lines

This is what OTG state machine does:
case OTG_STATE_B_PERIPHERAL:

     otg_chrg_vbus(otg, 0);
     otg_loc_sof(otg, 0);
     otg_set_protocol(fsm, PROTO_GADGET);
     otg_loc_conn(otg, 1);
     break;

On second thoughts, after seen the OTG state machine. otg_set_protocol(fsm, PROTO_GADGET); is always followed by otg_loc_conn(otg, 1); And whenever protocol changes to anything other the PROTO_GADGET, we use otg_loc_conn(otg, 0);

Quoted 6 lines
Quoted 6 lines

So otg_loc_conn seems redundant. Can we just get rid of it?

usb_gadget_start() implies that gadget controller starts up and enables pull.
usb_gadget_stop() implies that gadget controller disables pull and

stops.

Quoted 8 lines
Quoted 7 lines

Can you please explain why just these 2 APIs are not sufficient for full OTG?

Do we want anything to happen between gadget controller start/stop and pull on/off?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

"loc_conn" is a standard output parameter in OTG spec, it deserves a separate api, yes, current implementation of OTG state machine code seems allow you to combine the 2 things into one, but don't do that, because they do not always happen together, e.g. for peripheral only B device (also a part OTG spec: section 7.3), will be fixed in gadget mode, but it will do gadget connect and disconnect in its diff states, so, to make the framework common,

let's keep them separated.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 3 lines

I'm sorry but I didn't understand your comment about "it will do gadget connect and disconnect in its diff states"

Gadget connect means loc_conn(1).

Quoted 3 lines

I am reading the OTG v2.0 specification and loc_conn is always true when b_peripheral or a_peripheral is true and false otherwise.

If you only talk about these 2 states, yes, loc_conn is ture.

Quoted 4 lines

loc_conn is just an internal state variable and it corresponds to our
gadget_start/stop() state.

It's not an internal variable, there are OTG state machine parameters tables(table 7-x) in OTG spec which have clear lists which are "internal variable", which are "input", which are "output"...

Those APIs are driven directly from OTG spec, easily understood so code reader can know what's those APIs for. For real OTG, I don't see the benefit if get rid of it.

Quoted 7 lines
Quoted 7 lines

OK, no issues if we don't get rid of it. But I am still in favor of doing a connect in usb_gadget_start(), because

1) If we split connect/disconnect() and usb_gadget_start/stop() then there is additional overhead of keeping track whether connect was called or not during usb_gadget_stop(). Plus we need to take care that users don't call connect/disconnect outside of start/stop. It is

just complicating things.

Quoted 6 lines
Quoted 6 lines

2) for many controllers there is no difference between run/stop and connect/disconnect. i.e. a single register bit controls both.

3) it fits well with the OTG specification. OTG specification says that loc_conn *variable* must be true *after* the device has signalled

a connect.

Quoted 2 lines
Quoted 2 lines

So OTG state machine can safely set loc_conn variable to true after doing otg_set_protocol(fsm, PROTO_GADGET); and set it to false

otherwise.

Quoted 2 lines
Quoted 2 lines

Note, OTG specification does not say to take any action based on

loc_conn.

Quoted 7 lines
Quoted 6 lines

It is just a connect indicator variable. So we might have to fix this in the OTG state machine.

My suggestion is to keep it simple for now. Try the OTG implementation, and later if we find issues then extend it as required.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Just talked with Jun, he is worried if loc_conn != pullup_dp at some situations. So, how about only calling start gadget at usb_start_gadget,

Which situations?

When to pull-up DP is decided by application (while vbus is on), not only by driver state machine.

So when OTG state is B_PERIPHERAL or A_PERIPHERAL we still want DP pull-up to be disabled?

Quoted 53 lines
Quoted 37 lines
Quoted 17 lines

and pullup_dp at drd_set_state (see below).

static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state

new_state) {
	struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);

	if (otg->state == new_state)
		return;

	fsm->state_changed = 1;
	dev_dbg(otg->dev, "otg: set state: %s\n",
		usb_otg_state_string(new_state));
	switch (new_state) {
	case OTG_STATE_B_IDLE:

Review

Quoted 1 line
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, false);

This is redundant, When we switch from PROTO_GADGET to PROTO_UNDEF we do a usb_gadget_stop(), and a usb_gadget_disconnect() is done there.

Review

Quoted 6 lines
		drd_set_protocol(fsm, PROTO_UNDEF);
		otg_drv_vbus(otg, 0);
		break;
	case OTG_STATE_B_PERIPHERAL:
		drd_set_protocol(fsm, PROTO_GADGET);
(quoted diff) +1 -0
+		usb_udc_vbus_handler(gadget, true);

This is redundant as well since usb_gadget_start() is doing a usb_gadget_connect().

Quoted 5 lines
		otg_drv_vbus(otg, 0);
		break;
	......
	};
Quoted 8 lines
Quoted 5 lines

}

When the OTG FSM is added to this framework, it can keep usb_fsm->ops->loc_conn, and using the current FSM.

I have no strong opinions for or against usb_fsm->ops->loc_conn. Although strictly speaking, we shouldn't take any action based on loc_conn.

Strictly speaking(OTG spec), all you does is for loc_conn, but you think it's start_gadget.

Quoted 1 line

It is just a state variable indicator.

Nobody check this "indicator".

Quoted 9 lines
Quoted 5 lines

Of cos, this is not a big deal, you can define the new API as is, do udc_start() + gadget_connect() in one shot, it's up to user to decide if use your usb_otg_start_gadget(), in case of udc_start() followed by gadget_connect() is not wanted, user can/need do udc_start() and something else before do gadget_connect.

Please don't get me wrong. I want the full OTG state machine to be able to use usb_otg_start/stop_gadget().

Sure, but you may change above APIs a little (delete usb_gadget_connect).

Signature · 2 lines
Best Regards,
Peter Chen
#93 lore raw

PATCH v6 10/12 usb: doc: dt-binding: Add otg-controller property

In reply to Roger Quadros

The otg-controller property is used to link the host/gadget controllers to the otg controller. otg-controller property must contain the phandle of the otg controller.

The otg core uses this property to tie the host/gadget controllres to the correct otg controller.

---
 Documentation/devicetree/bindings/usb/generic.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/usb/generic.txt +3 -0
index bba8257..f6866c1 100644
@@ -24,6 +24,9 @@ Optional properties:
 			optional for OTG device.
  - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is
 			optional for OTG device.
+ - otg-controller: phandle to otg controller. Host or gadget controllers can
+			contain this property to link it to a particular OTG
+			controller.
 
 This is an attribute to a USB controller such as:
 
Signature · 1 line
2.5.0
#94 lore raw

PATCH v6 11/12 usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable

In reply to Roger Quadros

This is the a_set_b_hnp_enable flag in the OTG state machine diagram and must be set when the A-Host has successfully set the b_hnp_enable feature of the OTG-B-Peripheral attached to it.

When this bit changes we kick our OTG FSM to make note of the change and act accordingly.

---
 drivers/usb/core/hub.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +15 -2
index 38cc4ba..27e3b4c 100644
@@ -2273,6 +2273,7 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 			&& udev->parent == udev->bus->root_hub) {
 		struct usb_otg_descriptor	*desc = NULL;
 		struct usb_bus			*bus = udev->bus;
+		struct usb_hcd			*hcd = bus_to_hcd(bus);
 		unsigned			port1 = udev->portnum;
 
 		/* descriptor may appear anywhere in config */
@@ -2302,6 +2303,9 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				dev_err(&udev->dev, "can't set HNP mode: %d\n",
 									err);
 				bus->b_hnp_enable = 0;
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
 			}
 		} else if (desc->bLength == sizeof
 				(struct usb_otg_descriptor)) {
@@ -2312,10 +2316,14 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				USB_DEVICE_A_ALT_HNP_SUPPORT,
 				0, NULL, 0,
 				USB_CTRL_SET_TIMEOUT);
-			if (err < 0)
+			if (err < 0) {
 				dev_err(&udev->dev,
 					"set a_alt_hnp_support failed: %d\n",
 					err);
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
+			}
 		}
 	}
 #endif
@@ -4355,8 +4363,13 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
 	 */
 	if (!hdev->parent) {
 		delay = HUB_ROOT_RESET_TIME;
-		if (port1 == hdev->bus->otg_port)
+		if (port1 == hdev->bus->otg_port) {
 			hdev->bus->b_hnp_enable = 0;
+#ifdef CONFIG_USB_OTG
+			/* notify OTG fsm about a_set_b_hnp_enable change */
+			usb_otg_kick_fsm(hcd->otg_dev);
+#endif
+		}
 	}
 
 	/* Some low speed devices have problems with the quick delay, so */
Signature · 1 line
2.5.0
#95 lore raw

Re: [PATCH v6 11/12] usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable

Quoted 6 lines · Roger Quadros

This is the a_set_b_hnp_enable flag in the OTG state machine diagram and must be set when the A-Host has successfully set the b_hnp_enable feature of the OTG-B-Peripheral attached to it.

When this bit changes we kick our OTG FSM to make note of the change and act accordingly.

Since we have still not added fsm.a_set_b_hnp_en in OTG FSM, and this patch set is mainly for DRD, would you please move out this patch from this set?

Peter

Quoted 66 lines
---
 drivers/usb/core/hub.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +15 -2
index 38cc4ba..27e3b4c 100644
@@ -2273,6 +2273,7 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 			&& udev->parent == udev->bus->root_hub) {
 		struct usb_otg_descriptor	*desc = NULL;
 		struct usb_bus			*bus = udev->bus;
+		struct usb_hcd			*hcd = bus_to_hcd(bus);
 		unsigned			port1 = udev->portnum;
 
 		/* descriptor may appear anywhere in config */
@@ -2302,6 +2303,9 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				dev_err(&udev->dev, "can't set HNP mode: %d\n",
 									err);
 				bus->b_hnp_enable = 0;
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
 			}
 		} else if (desc->bLength == sizeof
 				(struct usb_otg_descriptor)) {
@@ -2312,10 +2316,14 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				USB_DEVICE_A_ALT_HNP_SUPPORT,
 				0, NULL, 0,
 				USB_CTRL_SET_TIMEOUT);
-			if (err < 0)
+			if (err < 0) {
 				dev_err(&udev->dev,
 					"set a_alt_hnp_support failed: %d\n",
 					err);
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
+			}
 		}
 	}
 #endif
@@ -4355,8 +4363,13 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
 	 */
 	if (!hdev->parent) {
 		delay = HUB_ROOT_RESET_TIME;
-		if (port1 == hdev->bus->otg_port)
+		if (port1 == hdev->bus->otg_port) {
 			hdev->bus->b_hnp_enable = 0;
+#ifdef CONFIG_USB_OTG
+			/* notify OTG fsm about a_set_b_hnp_enable change */
+			usb_otg_kick_fsm(hcd->otg_dev);
+#endif
+		}
 	}
 
 	/* Some low speed devices have problems with the quick delay, so */
Signature · 6 lines
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards,
Peter Chen
#96 lore raw

Re: [PATCH v6 11/12] usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable

Quoted 11 lines · Peter Chen
Quoted 6 lines · Roger Quadros

This is the a_set_b_hnp_enable flag in the OTG state machine diagram and must be set when the A-Host has successfully set the b_hnp_enable feature of the OTG-B-Peripheral attached to it.

When this bit changes we kick our OTG FSM to make note of the change and act accordingly.

Since we have still not added fsm.a_set_b_hnp_en in OTG FSM, and this patch set is mainly for DRD, would you please move out this patch from this set?

Sure.

cheers,
-roger

Quoted 68 lines
Quoted 67 lines
---
 drivers/usb/core/hub.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +15 -2
index 38cc4ba..27e3b4c 100644
@@ -2273,6 +2273,7 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 			&& udev->parent == udev->bus->root_hub) {
 		struct usb_otg_descriptor	*desc = NULL;
 		struct usb_bus			*bus = udev->bus;
+		struct usb_hcd			*hcd = bus_to_hcd(bus);
 		unsigned			port1 = udev->portnum;
 
 		/* descriptor may appear anywhere in config */
@@ -2302,6 +2303,9 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				dev_err(&udev->dev, "can't set HNP mode: %d\n",
 									err);
 				bus->b_hnp_enable = 0;
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
 			}
 		} else if (desc->bLength == sizeof
 				(struct usb_otg_descriptor)) {
@@ -2312,10 +2316,14 @@ static int usb_enumerate_device_otg(struct usb_device *udev)
 				USB_DEVICE_A_ALT_HNP_SUPPORT,
 				0, NULL, 0,
 				USB_CTRL_SET_TIMEOUT);
-			if (err < 0)
+			if (err < 0) {
 				dev_err(&udev->dev,
 					"set a_alt_hnp_support failed: %d\n",
 					err);
+			} else {
+				/* notify OTG fsm about a_set_b_hnp_enable */
+				usb_otg_kick_fsm(hcd->otg_dev);
+			}
 		}
 	}
 #endif
@@ -4355,8 +4363,13 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
 	 */
 	if (!hdev->parent) {
 		delay = HUB_ROOT_RESET_TIME;
-		if (port1 == hdev->bus->otg_port)
+		if (port1 == hdev->bus->otg_port) {
 			hdev->bus->b_hnp_enable = 0;
+#ifdef CONFIG_USB_OTG
+			/* notify OTG fsm about a_set_b_hnp_enable change */
+			usb_otg_kick_fsm(hcd->otg_dev);
+#endif
+		}
 	}
 
 	/* Some low speed devices have problems with the quick delay, so */
Signature · 6 lines
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#97 lore raw

PATCH v6 12/12 usb: host: xhci-plat: Add otg device to platform data

In reply to Roger Quadros

Host controllers that are part of an OTG/dual-role instance need to somehow pass the OTG controller device information to the HCD core.

We use platform data to pass the OTG controller device.

---
 drivers/usb/host/xhci-plat.c     | 35 ++++++++++++++++++++++++++++-------
 include/linux/usb/xhci_pdriver.h |  3 +++
 2 files changed, 31 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-plat.c +28 -7
index 5c15e9b..3d0f597 100644
@@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
 			goto put_usb3_hcd;
 	}
 
-	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)
+		ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
+	else
+		ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto disable_usb_phy;
 
-	ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)
+		ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
+				      pdata->otg_dev);
+	else
+		ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto dealloc_usb2_hcd;
 
@@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 
 
 dealloc_usb2_hcd:
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
 
 disable_usb_phy:
 	usb_phy_shutdown(hcd->usb_phy);
@@ -260,16 +272,25 @@ put_hcd:
 	return ret;
 }
 
-static int xhci_plat_remove(struct platform_device *dev)
+static int xhci_plat_remove(struct platform_device *pdev)
 {
-	struct usb_hcd	*hcd = platform_get_drvdata(dev);
+	struct usb_hcd	*hcd = platform_get_drvdata(pdev);
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct clk *clk = xhci->clk;
+	struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+	if (pdata->otg_dev)
+		usb_otg_remove_hcd(xhci->shared_hcd);
+	else
+		usb_remove_hcd(xhci->shared_hcd);
 
-	usb_remove_hcd(xhci->shared_hcd);
 	usb_phy_shutdown(hcd->usb_phy);
 
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
+
 	usb_put_hcd(xhci->shared_hcd);
 
 	if (!IS_ERR(clk))
include/linux/usb/xhci_pdriver.h +3 -0
index 376654b..5c68b83 100644
@@ -18,10 +18,13 @@
  *
  * @usb3_lpm_capable:	determines if this xhci platform supports USB3
  *			LPM capability
+ * @otg_dev:		OTG controller device. Only requied if part of
+ *			OTG/dual-role.
  *
  */
 struct usb_xhci_pdata {
 	unsigned	usb3_lpm_capable:1;
+	struct device	*otg_dev;
 };
 
 #endif /* __USB_CORE_XHCI_PDRIVER_H */
Signature · 6 lines
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#98 lore raw

RE: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data

Hi,

Quoted 19 lines

Sent: Tuesday, April 05, 2016 11:05 PM

Host controllers that are part of an OTG/dual-role instance need to somehow pass the OTG controller device information to the HCD core.

We use platform data to pass the OTG controller device.

---
 drivers/usb/host/xhci-plat.c     | 35 ++++++++++++++++++++++++++++-------
 include/linux/usb/xhci_pdriver.h |  3 +++
 2 files changed, 31 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-plat.c +0 -0
index 5c15e9b..3d0f597 100644

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 233

Quoted 5 lines
drivers/usb/host/xhci-plat.c +1 -1
@@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
 			goto put_usb3_hcd;
 	}
 
-	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)

I think that this should be changed like below:

	if (pdata && pdata->otg_dev)

Otherwise, panic happened on my environment (arm64 / r8a7795 board) because the pdata was NULL.

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 241

Quoted 9 lines
drivers/usb/host/xhci-plat.c +5 -1
+		ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
+	else
+		ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto disable_usb_phy;
 
-	ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)

Ditto.

Quoted 9 lines
drivers/usb/host/xhci-plat.c +5 -0
+		ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
+				      pdata->otg_dev);
+	else
+		ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto dealloc_usb2_hcd;
 

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 254

Quoted 5 lines
drivers/usb/host/xhci-plat.c +1 -1
@@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 
 
 dealloc_usb2_hcd:
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)

Ditto.

Quoted 10 lines
drivers/usb/host/xhci-plat.c +3 -0
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
 
 disable_usb_phy:
 	usb_phy_shutdown(hcd->usb_phy);
@@ -260,16 +272,25 @@ put_hcd:
 	return ret;
 }
 

drivers/usb/host/xhci-plat.c put_hcd: · line 282

Quoted 10 lines
drivers/usb/host/xhci-plat.c +5 -2
-static int xhci_plat_remove(struct platform_device *dev)
+static int xhci_plat_remove(struct platform_device *pdev)
 {
-	struct usb_hcd	*hcd = platform_get_drvdata(dev);
+	struct usb_hcd	*hcd = platform_get_drvdata(pdev);
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct clk *clk = xhci->clk;
+	struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+	if (pdata->otg_dev)

Ditto.

drivers/usb/host/xhci-plat.c put_hcd: · line 289

Quoted 9 lines
drivers/usb/host/xhci-plat.c +4 -2
+		usb_otg_remove_hcd(xhci->shared_hcd);
+	else
+		usb_remove_hcd(xhci->shared_hcd);
 
-	usb_remove_hcd(xhci->shared_hcd);
 	usb_phy_shutdown(hcd->usb_phy);
 
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)

Ditto.

Best regards,
Yoshihiro Shimoda

Quoted 28 lines
drivers/usb/host/xhci-plat.c +4 -0
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
+
 	usb_put_hcd(xhci->shared_hcd);
 
 	if (!IS_ERR(clk))
include/linux/usb/xhci_pdriver.h +3 -1
index 376654b..5c68b83 100644
@@ -18,10 +18,13 @@
  *
  * @usb3_lpm_capable:	determines if this xhci platform supports USB3
  *			LPM capability
+ * @otg_dev:		OTG controller device. Only requied if part of
+ *			OTG/dual-role.
  *
  */
 struct usb_xhci_pdata {
 	unsigned	usb3_lpm_capable:1;
+	struct device	*otg_dev;
 };
 
 #endif /* __USB_CORE_XHCI_PDRIVER_H */
--

2.5.0

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#99 lore raw

Re: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data

Hi,

Quoted 24 lines · Yoshihiro Shimoda

Hi,

Quoted 22 lines

Sent: Tuesday, April 05, 2016 11:05 PM

Host controllers that are part of an OTG/dual-role instance need to somehow pass the OTG controller device information to the HCD core.

We use platform data to pass the OTG controller device.

---
 drivers/usb/host/xhci-plat.c     | 35 ++++++++++++++++++++++++++++-------
 include/linux/usb/xhci_pdriver.h |  3 +++
 2 files changed, 31 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-plat.c +0 -0
index 5c15e9b..3d0f597 100644
@@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
 			goto put_usb3_hcd;
 	}
 
Quoted 5 lines

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 233

Quoted 2 lines
drivers/usb/host/xhci-plat.c +1 -1
-	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)

I think that this should be changed like below:

	if (pdata && pdata->otg_dev)

Indeed, I'll fix this and the remaining occurrences. Thanks.

cheers,
-roger

Quoted 94 lines

Otherwise, panic happened on my environment (arm64 / r8a7795 board) because the pdata was NULL.

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 241

Quoted 9 lines
drivers/usb/host/xhci-plat.c +5 -1
+		ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
+	else
+		ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto disable_usb_phy;
 
-	ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+	if (pdata->otg_dev)

Ditto.

Quoted 9 lines
drivers/usb/host/xhci-plat.c +5 -0
+		ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
+				      pdata->otg_dev);
+	else
+		ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+
 	if (ret)
 		goto dealloc_usb2_hcd;
 

drivers/usb/host/xhci-plat.c static int xhci_plat_probe(struct platform_device *pdev) · line 254

Quoted 5 lines
drivers/usb/host/xhci-plat.c +1 -1
@@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 
 
 dealloc_usb2_hcd:
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)

Ditto.

Quoted 10 lines
drivers/usb/host/xhci-plat.c +3 -0
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
 
 disable_usb_phy:
 	usb_phy_shutdown(hcd->usb_phy);
@@ -260,16 +272,25 @@ put_hcd:
 	return ret;
 }
 

drivers/usb/host/xhci-plat.c put_hcd: · line 282

Quoted 10 lines
drivers/usb/host/xhci-plat.c +5 -2
-static int xhci_plat_remove(struct platform_device *dev)
+static int xhci_plat_remove(struct platform_device *pdev)
 {
-	struct usb_hcd	*hcd = platform_get_drvdata(dev);
+	struct usb_hcd	*hcd = platform_get_drvdata(pdev);
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct clk *clk = xhci->clk;
+	struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+	if (pdata->otg_dev)

Ditto.

drivers/usb/host/xhci-plat.c put_hcd: · line 289

Quoted 9 lines
drivers/usb/host/xhci-plat.c +4 -2
+		usb_otg_remove_hcd(xhci->shared_hcd);
+	else
+		usb_remove_hcd(xhci->shared_hcd);
 
-	usb_remove_hcd(xhci->shared_hcd);
 	usb_phy_shutdown(hcd->usb_phy);
 
-	usb_remove_hcd(hcd);
+	if (pdata->otg_dev)

Ditto.

Best regards,
Yoshihiro Shimoda

Quoted 24 lines
drivers/usb/host/xhci-plat.c +4 -0
+		usb_otg_remove_hcd(hcd);
+	else
+		usb_remove_hcd(hcd);
+
 	usb_put_hcd(xhci->shared_hcd);
 
 	if (!IS_ERR(clk))
include/linux/usb/xhci_pdriver.h +3 -0
index 376654b..5c68b83 100644
@@ -18,10 +18,13 @@
  *
  * @usb3_lpm_capable:	determines if this xhci platform supports USB3
  *			LPM capability
+ * @otg_dev:		OTG controller device. Only requied if part of
+ *			OTG/dual-role.
  *
  */
 struct usb_xhci_pdata {
 	unsigned	usb3_lpm_capable:1;
+	struct device	*otg_dev;
 };
 
Quoted 8 lines
Quoted 8 lines
include/linux/usb/xhci_pdriver.h +0 -1
 #endif /* __USB_CORE_XHCI_PDRIVER_H */
--

2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html