[PATCH] usb: gadget: use usb_composite_dev for usb_function_{de}activate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



usb_function_{de}activate makes it possible to have several "gadget
functions", inside one composite device, to be able to prevent the gadget
to enumerate until an prepared condition has triggered (i.e. userspace
daemon has started)

This patch simplifies and renames the functions to its actual meaning
usb_cdev_{de}activate and fixes all its users. As the code is counting
the deactivations in the current cdev.

Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>
---
 drivers/usb/gadget/composite.c | 20 +++++++++-----------
 drivers/usb/gadget/f_obex.c    |  6 +++---
 drivers/usb/gadget/f_uvc.c     |  9 ++++++---
 include/linux/usb/composite.h  |  6 +++---
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index d4f0f33..d9378ec 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -234,8 +234,8 @@ void usb_remove_function(struct usb_configuration *c, struct usb_function *f)
 EXPORT_SYMBOL_GPL(usb_remove_function);
 
 /**
- * usb_function_deactivate - prevent function and gadget enumeration
- * @function: the function that isn't yet ready to respond
+ * usb_cdev_deactivate - prevent cdev and gadget enumeration
+ * @cdev: the cdev that isn't yet ready to respond
  *
  * Blocks response of the gadget driver to host enumeration by
  * preventing the data line pullup from being activated.  This is
@@ -252,9 +252,8 @@ EXPORT_SYMBOL_GPL(usb_remove_function);
  *
  * Returns zero on success, else negative errno.
  */
-int usb_function_deactivate(struct usb_function *function)
+int usb_cdev_deactivate(struct usb_composite_dev *cdev)
 {
-	struct usb_composite_dev	*cdev = function->config->cdev;
 	unsigned long			flags;
 	int				status = 0;
 
@@ -268,21 +267,20 @@ int usb_function_deactivate(struct usb_function *function)
 	spin_unlock_irqrestore(&cdev->lock, flags);
 	return status;
 }
-EXPORT_SYMBOL_GPL(usb_function_deactivate);
+EXPORT_SYMBOL_GPL(usb_cdev_deactivate);
 
 /**
- * usb_function_activate - allow function and gadget enumeration
- * @function: function on which usb_function_activate() was called
+ * usb_cdev_activate - allow cdev and gadget enumeration
+ * @cdev: cdev on which usb_cdev_activate() was called
  *
- * Reverses effect of usb_function_deactivate().  If no more functions
+ * Reverses effect of usb_cdev_deactivate().  If no more functions
  * are delaying their activation, the gadget driver will respond to
  * host enumeration procedures.
  *
  * Returns zero on success, else negative errno.
  */
-int usb_function_activate(struct usb_function *function)
+int usb_cdev_activate(struct usb_composite_dev *cdev)
 {
-	struct usb_composite_dev	*cdev = function->config->cdev;
 	unsigned long			flags;
 	int				status = 0;
 
@@ -299,7 +297,7 @@ int usb_function_activate(struct usb_function *function)
 	spin_unlock_irqrestore(&cdev->lock, flags);
 	return status;
 }
-EXPORT_SYMBOL_GPL(usb_function_activate);
+EXPORT_SYMBOL_GPL(usb_cdev_activate);
 
 /**
  * usb_interface_id() - allocate an unused interface ID
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index ad39f1d..48d0b9c 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -267,7 +267,7 @@ static void obex_connect(struct gserial *g)
 	if (!obex->can_activate)
 		return;
 
-	status = usb_function_activate(&g->func);
+	status = usb_cdev_activate(cdev);
 	if (status)
 		DBG(cdev, "obex ttyGS%d function activate --> %d\n",
 			obex->port_num, status);
@@ -282,7 +282,7 @@ static void obex_disconnect(struct gserial *g)
 	if (!obex->can_activate)
 		return;
 
-	status = usb_function_deactivate(&g->func);
+	status = usb_cdev_deactivate(cdev);
 	if (status)
 		DBG(cdev, "obex ttyGS%d function deactivate --> %d\n",
 			obex->port_num, status);
@@ -375,7 +375,7 @@ static int obex_bind(struct usb_configuration *c, struct usb_function *f)
 	/* Avoid letting this gadget enumerate until the userspace
 	 * OBEX server is active.
 	 */
-	status = usb_function_deactivate(f);
+	status = usb_cdev_deactivate(cdev);
 	if (status < 0)
 		WARNING(cdev, "obex ttyGS%d: can't prevent enumeration, %d\n",
 			obex->port_num, status);
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index e2a1f50..1a904eb 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -377,7 +377,8 @@ uvc_function_connect(struct uvc_device *uvc)
 	struct usb_composite_dev *cdev = uvc->func.config->cdev;
 	int ret;
 
-	if ((ret = usb_function_activate(&uvc->func)) < 0)
+	ret = usb_cdev_activate(cdev);
+	if (ret < 0)
 		INFO(cdev, "UVC connect failed with %d\n", ret);
 }
 
@@ -387,7 +388,8 @@ uvc_function_disconnect(struct uvc_device *uvc)
 	struct usb_composite_dev *cdev = uvc->func.config->cdev;
 	int ret;
 
-	if ((ret = usb_function_deactivate(&uvc->func)) < 0)
+	ret = usb_cdev_deactivate(cdev);
+	if (ret < 0)
 		INFO(cdev, "UVC disconnect failed with %d\n", ret);
 }
 
@@ -688,7 +690,8 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
 	/* Avoid letting this gadget enumerate until the userspace server is
 	 * active.
 	 */
-	if ((ret = usb_function_deactivate(f)) < 0)
+	ret = usb_cdev_deactivate(cdev);
+	if (ret < 0)
 		goto error;
 
 	if (v4l2_device_register(&cdev->gadget->dev, &uvc->v4l2_dev)) {
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 5e61589..c853a4e 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -167,9 +167,6 @@ struct usb_function {
 
 int usb_add_function(struct usb_configuration *, struct usb_function *);
 
-int usb_function_deactivate(struct usb_function *);
-int usb_function_activate(struct usb_function *);
-
 int usb_interface_id(struct usb_configuration *, struct usb_function *);
 
 int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
@@ -329,6 +326,9 @@ extern int composite_dev_prepare(struct usb_composite_driver *composite,
 		struct usb_composite_dev *cdev);
 void composite_dev_cleanup(struct usb_composite_dev *cdev);
 
+int usb_cdev_deactivate(struct usb_composite_dev *cdev);
+int usb_cdev_activate(struct usb_composite_dev *cdev);
+
 static inline struct usb_composite_driver *to_cdriver(
 		struct usb_gadget_driver *gdrv)
 {
-- 
1.8.4.rc3

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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux