[RFC/PATCH 7/8] usb: gadget: dummy: use new interfaces

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

 



use new interfaces from udc-core on dummy_hcd
testing driver.

Signed-off-by: Felipe Balbi <balbi@xxxxxx>
---
 drivers/usb/gadget/Kconfig     |    1 +
 drivers/usb/gadget/dummy_hcd.c |   99 +++++++++++++--------------------------
 2 files changed, 34 insertions(+), 66 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 8628d4e..4e1c75c 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -20,6 +20,7 @@ menuconfig USB_GADGET
 	tristate "USB Gadget Support"
 	select USB_UDC_CORE if (USB_GADGET_MUSB_HDRC || USB_GADGET_AMD5536UDC)
 	select USB_UDC_CORE if (USB_GADGET_AT91 || USB_GADGET_GOKU)
+	select USB_UDC_CORE if (USB_GADGET_DUMMY_HCD)
 	help
 	   USB is a master/slave protocol, organized with one master
 	   host (such as a PC) controlling up to 127 peripheral devices.
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index dc65462..6b28d3f 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -46,6 +46,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/usb.h>
+#include <linux/usb/udc.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/hcd.h>
 
@@ -160,8 +161,8 @@ struct dummy {
 	 */
 	struct dummy_ep			ep [DUMMY_ENDPOINTS];
 	int				address;
+	struct usb_udc			udc;
 	struct usb_gadget		gadget;
-	struct usb_gadget_driver	*driver;
 	struct dummy_request		fifo_req;
 	u8				fifo_buf [FIFO_SIZE];
 	u16				devstatus;
@@ -294,20 +295,20 @@ set_link_state (struct dummy *dum)
 			(dum->port_status & USB_PORT_STAT_RESET) != 0) {
 		if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
 				(dum->old_status & USB_PORT_STAT_RESET) == 0 &&
-				dum->driver) {
+				dum->udc.driver) {
 			stop_activity (dum);
 			spin_unlock (&dum->lock);
-			dum->driver->disconnect (&dum->gadget);
+			dum->udc.driver->disconnect (&dum->gadget);
 			spin_lock (&dum->lock);
 		}
 	} else if (dum->active != dum->old_active) {
-		if (dum->old_active && dum->driver->suspend) {
+		if (dum->old_active && dum->udc.driver->suspend) {
 			spin_unlock (&dum->lock);
-			dum->driver->suspend (&dum->gadget);
+			dum->udc.driver->suspend (&dum->gadget);
 			spin_lock (&dum->lock);
-		} else if (!dum->old_active && dum->driver->resume) {
+		} else if (!dum->old_active && dum->udc.driver->resume) {
 			spin_unlock (&dum->lock);
-			dum->driver->resume (&dum->gadget);
+			dum->udc.driver->resume (&dum->gadget);
 			spin_lock (&dum->lock);
 		}
 	}
@@ -341,7 +342,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
 			|| desc->bDescriptorType != USB_DT_ENDPOINT)
 		return -EINVAL;
 	dum = ep_to_dummy (ep);
-	if (!dum->driver || !is_enabled (dum))
+	if (!dum->udc.driver || !is_enabled (dum))
 		return -ESHUTDOWN;
 	max = le16_to_cpu(desc->wMaxPacketSize) & 0x3ff;
 
@@ -518,7 +519,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
 		return -EINVAL;
 
 	dum = ep_to_dummy (ep);
-	if (!dum->driver || !is_enabled (dum))
+	if (!dum->udc.driver || !is_enabled (dum))
 		return -ESHUTDOWN;
 
 #if 0
@@ -571,7 +572,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
 	ep = usb_ep_to_dummy_ep (_ep);
 	dum = ep_to_dummy (ep);
 
-	if (!dum->driver)
+	if (!dum->udc.driver)
 		return -ESHUTDOWN;
 
 	local_irq_save (flags);
@@ -606,7 +607,7 @@ dummy_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
 		return -EINVAL;
 	ep = usb_ep_to_dummy_ep (_ep);
 	dum = ep_to_dummy (ep);
-	if (!dum->driver)
+	if (!dum->udc.driver)
 		return -ESHUTDOWN;
 	if (!value)
 		ep->halted = ep->wedged = 0;
@@ -710,11 +711,16 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value)
 	return 0;
 }
 
+static int dummy_gadget_start(struct usb_gadget *driver);
+static void dummy_gadget_stop(struct usb_gadget *driver);
+
 static const struct usb_gadget_ops dummy_ops = {
 	.get_frame	= dummy_g_get_frame,
 	.wakeup		= dummy_wakeup,
 	.set_selfpowered = dummy_set_selfpowered,
 	.pullup		= dummy_pullup,
+	.start		= dummy_gadget_start,
+	.stop		= dummy_gadget_stop,
 };
 
 /*-------------------------------------------------------------------------*/
@@ -725,9 +731,9 @@ show_function (struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct dummy	*dum = gadget_dev_to_dummy (dev);
 
-	if (!dum->driver || !dum->driver->function)
+	if (!dum->udc.driver || !dum->udc.driver->function)
 		return 0;
-	return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
+	return scnprintf (buf, PAGE_SIZE, "%s\n", dum->udc.driver->function);
 }
 static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
 
@@ -747,19 +753,14 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
  * for each driver that registers:  just add to a big root hub.
  */
 
-int
-usb_gadget_register_driver (struct usb_gadget_driver *driver)
+static int
+dummy_gadget_start(struct usb_gadget *gadget)
 {
 	struct dummy	*dum = the_controller;
-	int		retval, i;
+	int		i;
 
 	if (!dum)
 		return -EINVAL;
-	if (dum->driver)
-		return -EBUSY;
-	if (!driver->bind || !driver->setup
-			|| driver->speed == USB_SPEED_UNKNOWN)
-		return -EINVAL;
 
 	/*
 	 * SLAVE side init ... the layer above hardware, which
@@ -786,23 +787,11 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
 		INIT_LIST_HEAD (&ep->queue);
 	}
 
-	dum->gadget.ep0 = &dum->ep [0].ep;
+	gadget->ep0 = &dum->ep [0].ep;
 	dum->ep [0].ep.maxpacket = 64;
 	list_del_init (&dum->ep [0].ep.ep_list);
 	INIT_LIST_HEAD(&dum->fifo_req.queue);
 
-	driver->driver.bus = NULL;
-	dum->driver = driver;
-	dum->gadget.dev.driver = &driver->driver;
-	dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
-			driver->driver.name);
-	retval = driver->bind(&dum->gadget);
-	if (retval) {
-		dum->driver = NULL;
-		dum->gadget.dev.driver = NULL;
-		return retval;
-	}
-
 	/* khubd will enumerate this in a while */
 	spin_lock_irq (&dum->lock);
 	dum->pullup = 1;
@@ -812,40 +801,28 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
 	usb_hcd_poll_rh_status (dummy_to_hcd (dum));
 	return 0;
 }
-EXPORT_SYMBOL (usb_gadget_register_driver);
 
-int
-usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
+static void
+dummy_gadget_stop(struct usb_gadget *gadget)
 {
 	struct dummy	*dum = the_controller;
 	unsigned long	flags;
 
 	if (!dum)
-		return -ENODEV;
-	if (!driver || driver != dum->driver || !driver->unbind)
-		return -EINVAL;
-
-	dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
-			driver->driver.name);
+		return;
 
 	spin_lock_irqsave (&dum->lock, flags);
 	dum->pullup = 0;
 	set_link_state (dum);
 	spin_unlock_irqrestore (&dum->lock, flags);
 
-	driver->unbind (&dum->gadget);
-	dum->gadget.dev.driver = NULL;
-	dum->driver = NULL;
-
 	spin_lock_irqsave (&dum->lock, flags);
 	dum->pullup = 0;
 	set_link_state (dum);
 	spin_unlock_irqrestore (&dum->lock, flags);
 
 	usb_hcd_poll_rh_status (dummy_to_hcd (dum));
-	return 0;
 }
-EXPORT_SYMBOL (usb_gadget_unregister_driver);
 
 #undef is_enabled
 
@@ -859,32 +836,22 @@ int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
 EXPORT_SYMBOL (net2280_set_fifo_mode);
 
 
-/* The gadget structure is stored inside the hcd structure and will be
- * released along with it. */
-static void
-dummy_gadget_release (struct device *dev)
-{
-	struct dummy	*dum = gadget_dev_to_dummy (dev);
-
-	usb_put_hcd (dummy_to_hcd (dum));
-}
-
 static int dummy_udc_probe (struct platform_device *pdev)
 {
 	struct dummy	*dum = the_controller;
 	int		rc;
 
+	dum->udc.name = gadget_name;
 	dum->gadget.name = gadget_name;
 	dum->gadget.ops = &dummy_ops;
 	dum->gadget.is_dualspeed = 1;
+	dum->udc.gadget = &dum->gadget;
 
 	/* maybe claim OTG support, though we won't complete HNP */
 	dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
 
 	dev_set_name(&dum->gadget.dev, "gadget");
-	dum->gadget.dev.parent = &pdev->dev;
-	dum->gadget.dev.release = dummy_gadget_release;
-	rc = device_register (&dum->gadget.dev);
+	rc = usb_add_udc(&pdev->dev, &dum->udc);
 	if (rc < 0)
 		return rc;
 
@@ -903,7 +870,7 @@ static int dummy_udc_remove (struct platform_device *pdev)
 
 	platform_set_drvdata (pdev, NULL);
 	device_remove_file (&dum->gadget.dev, &dev_attr_function);
-	device_unregister (&dum->gadget.dev);
+	usb_del_udc(&dum->udc);
 	return 0;
 }
 
@@ -1443,7 +1410,7 @@ restart:
 			 */
 			if (value > 0) {
 				spin_unlock (&dum->lock);
-				value = dum->driver->setup (&dum->gadget,
+				value = dum->udc.driver->setup (&dum->gadget,
 						&setup);
 				spin_lock (&dum->lock);
 
@@ -1640,7 +1607,7 @@ static int dummy_hub_control (
 			if (dum->pullup) {
 				dum->port_status |= USB_PORT_STAT_ENABLE;
 				/* give it the best speed we agree on */
-				dum->gadget.speed = dum->driver->speed;
+				dum->gadget.speed = dum->udc.driver->speed;
 				dum->gadget.ep0->maxpacket = 64;
 				switch (dum->gadget.speed) {
 				case USB_SPEED_HIGH:
@@ -1841,7 +1808,7 @@ static void dummy_stop (struct usb_hcd *hcd)
 	dum = hcd_to_dummy (hcd);
 
 	device_remove_file (dummy_dev(dum), &dev_attr_urbs);
-	usb_gadget_unregister_driver (dum->driver);
+	usb_gadget_unregister_driver (dum->udc.driver);
 	dev_info (dummy_dev(dum), "stopped\n");
 }
 
-- 
1.7.3.rc0.35.g8ac8c

--
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