diff mbox

[RFC,6/9] usb: gadget: udc: adapt to OTG

Message ID 1426686963-11613-7-git-send-email-rogerq@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Quadros March 18, 2015, 1:56 p.m. UTC
Register with OTG core as part of usb_add_gadget_udc_release()
and unregister from it in usb_del_gadget_udc().

In the OTG use case we may not yet be in "b_peripheral"
state so we shouldn't allow starting the UDC till
OTG core says so.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/usb/gadget/udc/udc-core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index 69b4123..aad5173 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@ 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb.h>
+#include <linux/usb/usb-otg.h>
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -237,6 +238,7 @@  static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 static int usb_udc_start(struct usb_udc *udc)
 {
 	int ret;
+	bool otg_can_start;
 
 	if (udc->running) {
 		dev_err(&udc->dev, "%s: not starting as already running\n",
@@ -244,7 +246,8 @@  static int usb_udc_start(struct usb_udc *udc)
 		return -EBUSY;
 	}
 
-	if (udc->driver && udc->softconnect) {
+	otg_can_start = usb_otg_gadget_can_start(udc->gadget);
+	if (otg_can_start && udc->driver && udc->softconnect) {
 		ret = usb_gadget_udc_start(udc);
 		if (ret)
 			return ret;
@@ -432,6 +435,8 @@  int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
 
 	mutex_unlock(&udc_lock);
 
+	usb_otg_register_gadget(gadget);
+
 	return 0;
 
 err4:
@@ -509,6 +514,7 @@  found:
 	if (udc->driver)
 		usb_gadget_remove_driver(udc);
 
+	usb_otg_unregister_gadget(gadget);
 	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
 	flush_work(&gadget->work);
 	device_unregister(&udc->dev);