2 * dummy_hcd.c -- Dummy/Loopback USB host and device emulator driver.
4 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
6 * Copyright (C) 2003 David Brownell
7 * Copyright (C) 2003-2005 Alan Stern
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * This exposes a device side "USB gadget" API, driven by requests to a
27 * Linux-USB host controller driver. USB traffic is simulated; there's
28 * no need for USB hardware. Use this with two other drivers:
30 * - Gadget driver, responding to requests (slave);
31 * - Host-side device driver, as already familiar in Linux.
33 * Having this all in one kernel can help some stages of development,
34 * bypassing some hardware (and driver) issues. UML could help too.
39 #include <linux/config.h>
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/delay.h>
43 #include <linux/ioport.h>
44 #include <linux/sched.h>
45 #include <linux/slab.h>
46 #include <linux/smp_lock.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/timer.h>
50 #include <linux/list.h>
51 #include <linux/interrupt.h>
52 #include <linux/version.h>
54 #include <linux/usb.h>
55 #include <linux/usb_gadget.h>
57 #include <asm/byteorder.h>
60 #include <asm/system.h>
61 #include <asm/unaligned.h>
64 #include "../core/hcd.h"
67 #define DRIVER_DESC "USB Host+Gadget Emulator"
68 #define DRIVER_VERSION "17 Dec 2004"
70 static const char driver_name [] = "dummy_hcd";
71 static const char driver_desc [] = "USB Host+Gadget Emulator";
73 static const char gadget_name [] = "dummy_udc";
75 MODULE_DESCRIPTION (DRIVER_DESC);
76 MODULE_AUTHOR ("David Brownell");
77 MODULE_LICENSE ("GPL");
79 /*-------------------------------------------------------------------------*/
81 /* gadget side driver data structres */
83 struct list_head queue;
84 unsigned long last_io; /* jiffies timestamp */
85 struct usb_gadget *gadget;
86 const struct usb_endpoint_descriptor *desc;
89 unsigned already_seen : 1;
90 unsigned setup_stage : 1;
93 struct dummy_request {
94 struct list_head queue; /* ep's requests */
95 struct usb_request req;
98 static inline struct dummy_ep *usb_ep_to_dummy_ep (struct usb_ep *_ep)
100 return container_of (_ep, struct dummy_ep, ep);
103 static inline struct dummy_request *usb_request_to_dummy_request
104 (struct usb_request *_req)
106 return container_of (_req, struct dummy_request, req);
109 /*-------------------------------------------------------------------------*/
112 * Every device has ep0 for control requests, plus up to 30 more endpoints,
113 * in one of two types:
115 * - Configurable: direction (in/out), type (bulk, iso, etc), and endpoint
116 * number can be changed. Names like "ep-a" are used for this type.
118 * - Fixed Function: in other cases. some characteristics may be mutable;
119 * that'd be hardware-specific. Names like "ep12out-bulk" are used.
121 * Gadget drivers are responsible for not setting up conflicting endpoint
122 * configurations, illegal or unsupported packet lengths, and so on.
125 static const char ep0name [] = "ep0";
127 static const char *const ep_name [] = {
128 ep0name, /* everyone has ep0 */
130 /* act like a net2280: high speed, six configurable endpoints */
131 "ep-a", "ep-b", "ep-c", "ep-d", "ep-e", "ep-f",
133 /* or like pxa250: fifteen fixed function endpoints */
134 "ep1in-bulk", "ep2out-bulk", "ep3in-iso", "ep4out-iso", "ep5in-int",
135 "ep6in-bulk", "ep7out-bulk", "ep8in-iso", "ep9out-iso", "ep10in-int",
136 "ep11in-bulk", "ep12out-bulk", "ep13in-iso", "ep14out-iso",
139 /* or like sa1100: two fixed function endpoints */
140 "ep1out-bulk", "ep2in-bulk",
142 #define DUMMY_ENDPOINTS (sizeof(ep_name)/sizeof(char *))
144 /*-------------------------------------------------------------------------*/
150 struct list_head urbp_list;
157 * SLAVE/GADGET side support
159 struct dummy_ep ep [DUMMY_ENDPOINTS];
161 struct usb_gadget gadget;
162 struct usb_gadget_driver *driver;
163 struct dummy_request fifo_req;
164 u8 fifo_buf [FIFO_SIZE];
168 unsigned old_active:1;
171 * MASTER/HOST side support
173 struct timer_list timer;
177 unsigned long re_timeout;
179 struct usb_device *udev;
180 struct list_head urbp_list;
183 static inline struct dummy *hcd_to_dummy (struct usb_hcd *hcd)
185 return (struct dummy *) (hcd->hcd_priv);
188 static inline struct usb_hcd *dummy_to_hcd (struct dummy *dum)
190 return container_of((void *) dum, struct usb_hcd, hcd_priv);
193 static inline struct device *dummy_dev (struct dummy *dum)
195 return dummy_to_hcd(dum)->self.controller;
198 static inline struct device *udc_dev (struct dummy *dum)
200 return dum->gadget.dev.parent;
203 static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
205 return container_of (ep->gadget, struct dummy, gadget);
208 static inline struct dummy *gadget_to_dummy (struct usb_gadget *gadget)
210 return container_of (gadget, struct dummy, gadget);
213 static inline struct dummy *gadget_dev_to_dummy (struct device *dev)
215 return container_of (dev, struct dummy, gadget.dev);
218 static struct dummy *the_controller;
220 /*-------------------------------------------------------------------------*/
222 /* SLAVE/GADGET SIDE UTILITY ROUTINES */
224 /* called with spinlock held */
225 static void nuke (struct dummy *dum, struct dummy_ep *ep)
227 while (!list_empty (&ep->queue)) {
228 struct dummy_request *req;
230 req = list_entry (ep->queue.next, struct dummy_request, queue);
231 list_del_init (&req->queue);
232 req->req.status = -ESHUTDOWN;
234 spin_unlock (&dum->lock);
235 req->req.complete (&ep->ep, &req->req);
236 spin_lock (&dum->lock);
240 /* caller must hold lock */
242 stop_activity (struct dummy *dum)
246 /* prevent any more requests */
249 /* The timer is left running so that outstanding URBs can fail */
251 /* nuke any pending requests first, so driver i/o is quiesced */
252 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
255 /* driver now does any non-usb quiescing necessary */
258 /* caller must hold lock */
260 set_link_state (struct dummy *dum)
263 if ((dum->port_status & USB_PORT_STAT_POWER) == 0)
264 dum->port_status = 0;
265 else if (!dum->pullup) {
266 dum->port_status &= ~(USB_PORT_STAT_CONNECTION |
267 USB_PORT_STAT_ENABLE |
268 USB_PORT_STAT_LOW_SPEED |
269 USB_PORT_STAT_HIGH_SPEED |
270 USB_PORT_STAT_SUSPEND);
271 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0)
272 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
274 dum->port_status |= USB_PORT_STAT_CONNECTION;
275 if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0)
276 dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16);
277 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0)
278 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
279 else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0)
283 if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active)
286 if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
287 (dum->port_status & USB_PORT_STAT_RESET) != 0) {
288 if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
289 (dum->old_status & USB_PORT_STAT_RESET) == 0 &&
292 spin_unlock (&dum->lock);
293 dum->driver->disconnect (&dum->gadget);
294 spin_lock (&dum->lock);
296 } else if (dum->active != dum->old_active) {
297 if (dum->old_active && dum->driver->suspend) {
298 spin_unlock (&dum->lock);
299 dum->driver->suspend (&dum->gadget);
300 spin_lock (&dum->lock);
301 } else if (!dum->old_active && dum->driver->resume) {
302 spin_unlock (&dum->lock);
303 dum->driver->resume (&dum->gadget);
304 spin_lock (&dum->lock);
308 dum->old_status = dum->port_status;
309 dum->old_active = dum->active;
312 /*-------------------------------------------------------------------------*/
314 /* SLAVE/GADGET SIDE DRIVER
316 * This only tracks gadget state. All the work is done when the host
317 * side tries some (emulated) i/o operation. Real device controller
318 * drivers would do real i/o using dma, fifos, irqs, timers, etc.
321 #define is_enabled(dum) \
322 (dum->port_status & USB_PORT_STAT_ENABLE)
325 dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
332 ep = usb_ep_to_dummy_ep (_ep);
333 if (!_ep || !desc || ep->desc || _ep->name == ep0name
334 || desc->bDescriptorType != USB_DT_ENDPOINT)
336 dum = ep_to_dummy (ep);
337 if (!dum->driver || !is_enabled (dum))
339 max = le16_to_cpu(desc->wMaxPacketSize) & 0x3ff;
341 /* drivers must not request bad settings, since lower levels
342 * (hardware or its drivers) may not check. some endpoints
343 * can't do iso, many have maxpacket limitations, etc.
345 * since this "hardware" driver is here to help debugging, we
346 * have some extra sanity checks. (there could be more though,
347 * especially for "ep9out" style fixed function ones.)
350 switch (desc->bmAttributes & 0x03) {
351 case USB_ENDPOINT_XFER_BULK:
352 if (strstr (ep->ep.name, "-iso")
353 || strstr (ep->ep.name, "-int")) {
356 switch (dum->gadget.speed) {
360 /* conserve return statements */
363 case 8: case 16: case 32: case 64:
364 /* we'll fake any legal size */
372 case USB_ENDPOINT_XFER_INT:
373 if (strstr (ep->ep.name, "-iso")) /* bulk is ok */
375 /* real hardware might not handle all packet sizes */
376 switch (dum->gadget.speed) {
380 /* save a return statement */
384 /* save a return statement */
391 case USB_ENDPOINT_XFER_ISOC:
392 if (strstr (ep->ep.name, "-bulk")
393 || strstr (ep->ep.name, "-int"))
395 /* real hardware might not handle all packet sizes */
396 switch (dum->gadget.speed) {
400 /* save a return statement */
404 /* save a return statement */
410 /* few chips support control except on ep0 */
414 _ep->maxpacket = max;
417 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n",
419 desc->bEndpointAddress & 0x0f,
420 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
422 switch (desc->bmAttributes & 0x03) {
423 case USB_ENDPOINT_XFER_BULK: val = "bulk"; break;
424 case USB_ENDPOINT_XFER_ISOC: val = "iso"; break;
425 case USB_ENDPOINT_XFER_INT: val = "intr"; break;
426 default: val = "ctrl"; break;
430 /* at this point real hardware should be NAKing transfers
431 * to that endpoint, until a buffer is queued to it.
438 static int dummy_disable (struct usb_ep *_ep)
445 ep = usb_ep_to_dummy_ep (_ep);
446 if (!_ep || !ep->desc || _ep->name == ep0name)
448 dum = ep_to_dummy (ep);
450 spin_lock_irqsave (&dum->lock, flags);
454 spin_unlock_irqrestore (&dum->lock, flags);
456 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name);
460 static struct usb_request *
461 dummy_alloc_request (struct usb_ep *_ep, int mem_flags)
464 struct dummy_request *req;
468 ep = usb_ep_to_dummy_ep (_ep);
470 req = kmalloc (sizeof *req, mem_flags);
473 memset (req, 0, sizeof *req);
474 INIT_LIST_HEAD (&req->queue);
479 dummy_free_request (struct usb_ep *_ep, struct usb_request *_req)
482 struct dummy_request *req;
484 ep = usb_ep_to_dummy_ep (_ep);
485 if (!ep || !_req || (!ep->desc && _ep->name != ep0name))
488 req = usb_request_to_dummy_request (_req);
489 WARN_ON (!list_empty (&req->queue));
504 ep = usb_ep_to_dummy_ep (_ep);
505 dum = ep_to_dummy (ep);
509 retval = kmalloc (bytes, mem_flags);
510 *dma = (dma_addr_t) retval;
526 fifo_complete (struct usb_ep *ep, struct usb_request *req)
531 dummy_queue (struct usb_ep *_ep, struct usb_request *_req, int mem_flags)
534 struct dummy_request *req;
538 req = usb_request_to_dummy_request (_req);
539 if (!_req || !list_empty (&req->queue) || !_req->complete)
542 ep = usb_ep_to_dummy_ep (_ep);
543 if (!_ep || (!ep->desc && _ep->name != ep0name))
546 dum = ep_to_dummy (ep);
547 if (!dum->driver || !is_enabled (dum))
551 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
552 ep, _req, _ep->name, _req->length, _req->buf);
555 _req->status = -EINPROGRESS;
557 spin_lock_irqsave (&dum->lock, flags);
559 /* implement an emulated single-request FIFO */
560 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
561 list_empty (&dum->fifo_req.queue) &&
562 list_empty (&ep->queue) &&
563 _req->length <= FIFO_SIZE) {
564 req = &dum->fifo_req;
566 req->req.buf = dum->fifo_buf;
567 memcpy (dum->fifo_buf, _req->buf, _req->length);
568 req->req.context = dum;
569 req->req.complete = fifo_complete;
571 spin_unlock (&dum->lock);
572 _req->actual = _req->length;
574 _req->complete (_ep, _req);
575 spin_lock (&dum->lock);
577 list_add_tail (&req->queue, &ep->queue);
578 spin_unlock_irqrestore (&dum->lock, flags);
580 /* real hardware would likely enable transfers here, in case
581 * it'd been left NAKing.
586 static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
590 int retval = -EINVAL;
592 struct dummy_request *req = NULL;
596 ep = usb_ep_to_dummy_ep (_ep);
597 dum = ep_to_dummy (ep);
602 spin_lock_irqsave (&dum->lock, flags);
603 list_for_each_entry (req, &ep->queue, queue) {
604 if (&req->req == _req) {
605 list_del_init (&req->queue);
606 _req->status = -ECONNRESET;
611 spin_unlock_irqrestore (&dum->lock, flags);
614 dev_dbg (udc_dev(dum),
615 "dequeued req %p from %s, len %d buf %p\n",
616 req, _ep->name, _req->length, _req->buf);
617 _req->complete (_ep, _req);
623 dummy_set_halt (struct usb_ep *_ep, int value)
630 ep = usb_ep_to_dummy_ep (_ep);
631 dum = ep_to_dummy (ep);
636 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
637 !list_empty (&ep->queue))
641 /* FIXME clear emulated data toggle too */
645 static const struct usb_ep_ops dummy_ep_ops = {
646 .enable = dummy_enable,
647 .disable = dummy_disable,
649 .alloc_request = dummy_alloc_request,
650 .free_request = dummy_free_request,
652 .alloc_buffer = dummy_alloc_buffer,
653 .free_buffer = dummy_free_buffer,
654 /* map, unmap, ... eventually hook the "generic" dma calls */
656 .queue = dummy_queue,
657 .dequeue = dummy_dequeue,
659 .set_halt = dummy_set_halt,
662 /*-------------------------------------------------------------------------*/
664 /* there are both host and device side versions of this call ... */
665 static int dummy_g_get_frame (struct usb_gadget *_gadget)
669 do_gettimeofday (&tv);
670 return tv.tv_usec / 1000;
673 static int dummy_wakeup (struct usb_gadget *_gadget)
677 dum = gadget_to_dummy (_gadget);
678 if (!(dum->port_status & USB_PORT_STAT_SUSPEND)
679 || !(dum->devstatus &
680 ( (1 << USB_DEVICE_B_HNP_ENABLE)
681 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
684 /* hub notices our request, issues downstream resume, etc */
686 dum->re_timeout = jiffies + msecs_to_jiffies(20);
690 static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
694 dum = gadget_to_dummy (_gadget);
696 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED);
698 dum->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED);
702 static int dummy_pullup (struct usb_gadget *_gadget, int value)
707 dum = gadget_to_dummy (_gadget);
708 spin_lock_irqsave (&dum->lock, flags);
709 dum->pullup = (value != 0);
710 set_link_state (dum);
711 spin_unlock_irqrestore (&dum->lock, flags);
715 static const struct usb_gadget_ops dummy_ops = {
716 .get_frame = dummy_g_get_frame,
717 .wakeup = dummy_wakeup,
718 .set_selfpowered = dummy_set_selfpowered,
719 .pullup = dummy_pullup,
722 /*-------------------------------------------------------------------------*/
724 /* "function" sysfs attribute */
726 show_function (struct device *dev, struct device_attribute *attr, char *buf)
728 struct dummy *dum = gadget_dev_to_dummy (dev);
730 if (!dum->driver || !dum->driver->function)
732 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
734 DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
736 /*-------------------------------------------------------------------------*/
739 * Driver registration/unregistration.
741 * This is basically hardware-specific; there's usually only one real USB
742 * device (not host) controller since that's how USB devices are intended
743 * to work. So most implementations of these api calls will rely on the
744 * fact that only one driver will ever bind to the hardware. But curious
745 * hardware can be built with discrete components, so the gadget API doesn't
746 * require that assumption.
748 * For this emulator, it might be convenient to create a usb slave device
749 * for each driver that registers: just add to a big root hub.
753 usb_gadget_register_driver (struct usb_gadget_driver *driver)
755 struct dummy *dum = the_controller;
762 if (!driver->bind || !driver->unbind || !driver->setup
763 || driver->speed == USB_SPEED_UNKNOWN)
767 * SLAVE side init ... the layer above hardware, which
768 * can't enumerate without help from the driver we're binding.
773 INIT_LIST_HEAD (&dum->gadget.ep_list);
774 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
775 struct dummy_ep *ep = &dum->ep [i];
779 ep->ep.name = ep_name [i];
780 ep->ep.ops = &dummy_ep_ops;
781 list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list);
782 ep->halted = ep->already_seen = ep->setup_stage = 0;
783 ep->ep.maxpacket = ~0;
784 ep->last_io = jiffies;
785 ep->gadget = &dum->gadget;
787 INIT_LIST_HEAD (&ep->queue);
790 dum->gadget.ep0 = &dum->ep [0].ep;
791 dum->ep [0].ep.maxpacket = 64;
792 list_del_init (&dum->ep [0].ep.ep_list);
793 INIT_LIST_HEAD(&dum->fifo_req.queue);
795 dum->driver = driver;
796 dum->gadget.dev.driver = &driver->driver;
797 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
798 driver->driver.name);
799 if ((retval = driver->bind (&dum->gadget)) != 0) {
801 dum->gadget.dev.driver = NULL;
805 driver->driver.bus = dum->gadget.dev.parent->bus;
806 driver_register (&driver->driver);
807 device_bind_driver (&dum->gadget.dev);
809 /* khubd will enumerate this in a while */
810 spin_lock_irq (&dum->lock);
812 set_link_state (dum);
813 spin_unlock_irq (&dum->lock);
816 EXPORT_SYMBOL (usb_gadget_register_driver);
819 usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
821 struct dummy *dum = the_controller;
826 if (!driver || driver != dum->driver)
829 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
830 driver->driver.name);
832 spin_lock_irqsave (&dum->lock, flags);
834 set_link_state (dum);
835 spin_unlock_irqrestore (&dum->lock, flags);
837 driver->unbind (&dum->gadget);
840 device_release_driver (&dum->gadget.dev);
841 driver_unregister (&driver->driver);
843 spin_lock_irqsave (&dum->lock, flags);
845 set_link_state (dum);
846 spin_unlock_irqrestore (&dum->lock, flags);
850 EXPORT_SYMBOL (usb_gadget_unregister_driver);
854 int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
858 EXPORT_SYMBOL (net2280_set_fifo_mode);
861 /* The gadget structure is stored inside the hcd structure and will be
862 * released along with it. */
864 dummy_gadget_release (struct device *dev)
866 #if 0 /* usb_bus_put isn't EXPORTed! */
867 struct dummy *dum = gadget_dev_to_dummy (dev);
869 usb_bus_put (&dummy_to_hcd (dum)->self);
873 static int dummy_udc_probe (struct device *dev)
875 struct dummy *dum = the_controller;
878 dum->gadget.name = gadget_name;
879 dum->gadget.ops = &dummy_ops;
880 dum->gadget.is_dualspeed = 1;
882 /* maybe claim OTG support, though we won't complete HNP */
883 dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0);
885 strcpy (dum->gadget.dev.bus_id, "gadget");
886 dum->gadget.dev.parent = dev;
887 dum->gadget.dev.release = dummy_gadget_release;
888 rc = device_register (&dum->gadget.dev);
892 #if 0 /* usb_bus_get isn't EXPORTed! */
893 usb_bus_get (&dummy_to_hcd (dum)->self);
896 dev_set_drvdata (dev, dum);
897 device_create_file (&dum->gadget.dev, &dev_attr_function);
901 static int dummy_udc_remove (struct device *dev)
903 struct dummy *dum = dev_get_drvdata (dev);
905 dev_set_drvdata (dev, NULL);
906 device_remove_file (&dum->gadget.dev, &dev_attr_function);
907 device_unregister (&dum->gadget.dev);
911 static struct device_driver dummy_udc_driver = {
912 .name = (char *) gadget_name,
913 .bus = &platform_bus_type,
914 .probe = dummy_udc_probe,
915 .remove = dummy_udc_remove,
918 /*-------------------------------------------------------------------------*/
920 /* MASTER/HOST SIDE DRIVER
922 * this uses the hcd framework to hook up to host side drivers.
923 * its root hub will only have one device, otherwise it acts like
924 * a normal host controller.
926 * when urbs are queued, they're just stuck on a list that we
927 * scan in a timer callback. that callback connects writes from
928 * the host with reads from the device, and so on, based on the
932 static int dummy_urb_enqueue (
934 struct usb_host_endpoint *ep,
942 if (!urb->transfer_buffer && urb->transfer_buffer_length)
945 urbp = kmalloc (sizeof *urbp, mem_flags);
950 dum = hcd_to_dummy (hcd);
951 spin_lock_irqsave (&dum->lock, flags);
954 dum->udev = urb->dev;
955 usb_get_dev (dum->udev);
956 } else if (unlikely (dum->udev != urb->dev))
957 dev_err (dummy_dev(dum), "usb_device address has changed!\n");
959 list_add_tail (&urbp->urbp_list, &dum->urbp_list);
961 if (usb_pipetype (urb->pipe) == PIPE_CONTROL)
962 urb->error_count = 1; /* mark as a new urb */
964 /* kick the scheduler, it'll do the rest */
965 if (!timer_pending (&dum->timer))
966 mod_timer (&dum->timer, jiffies + 1);
968 spin_unlock_irqrestore (&dum->lock, flags);
972 static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
974 /* giveback happens automatically in timer callback */
978 static void maybe_set_status (struct urb *urb, int status)
980 spin_lock (&urb->lock);
981 if (urb->status == -EINPROGRESS)
982 urb->status = status;
983 spin_unlock (&urb->lock);
986 /* transfer up to a frame's worth; caller must own lock */
988 transfer (struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit)
990 struct dummy_request *req;
993 /* if there's no request queued, the device is NAKing; return */
994 list_for_each_entry (req, &ep->queue, queue) {
995 unsigned host_len, dev_len, len;
996 int is_short, to_host;
999 /* 1..N packets of ep->ep.maxpacket each ... the last one
1000 * may be short (including zero length).
1002 * writer can send a zlp explicitly (length 0) or implicitly
1003 * (length mod maxpacket zero, and 'zero' flag); they always
1006 host_len = urb->transfer_buffer_length - urb->actual_length;
1007 dev_len = req->req.length - req->req.actual;
1008 len = min (host_len, dev_len);
1010 /* FIXME update emulated data toggle too */
1012 to_host = usb_pipein (urb->pipe);
1013 if (unlikely (len == 0))
1018 /* not enough bandwidth left? */
1019 if (limit < ep->ep.maxpacket && limit < len)
1021 len = min (len, (unsigned) limit);
1025 /* use an extra pass for the final short packet */
1026 if (len > ep->ep.maxpacket) {
1028 len -= (len % ep->ep.maxpacket);
1030 is_short = (len % ep->ep.maxpacket) != 0;
1032 /* else transfer packet(s) */
1033 ubuf = urb->transfer_buffer + urb->actual_length;
1034 rbuf = req->req.buf + req->req.actual;
1036 memcpy (ubuf, rbuf, len);
1038 memcpy (rbuf, ubuf, len);
1039 ep->last_io = jiffies;
1042 urb->actual_length += len;
1043 req->req.actual += len;
1046 /* short packets terminate, maybe with overflow/underflow.
1047 * it's only really an error to write too much.
1049 * partially filling a buffer optionally blocks queue advances
1050 * (so completion handlers can clean up the queue) but we don't
1051 * need to emulate such data-in-flight. so we only show part
1052 * of the URB_SHORT_NOT_OK effect: completion status.
1055 if (host_len == dev_len) {
1056 req->req.status = 0;
1057 maybe_set_status (urb, 0);
1058 } else if (to_host) {
1059 req->req.status = 0;
1060 if (dev_len > host_len)
1061 maybe_set_status (urb, -EOVERFLOW);
1063 maybe_set_status (urb,
1064 (urb->transfer_flags
1067 } else if (!to_host) {
1068 maybe_set_status (urb, 0);
1069 if (host_len > dev_len)
1070 req->req.status = -EOVERFLOW;
1072 req->req.status = 0;
1075 /* many requests terminate without a short packet */
1077 if (req->req.length == req->req.actual
1079 req->req.status = 0;
1080 if (urb->transfer_buffer_length == urb->actual_length
1081 && !(urb->transfer_flags
1082 & URB_ZERO_PACKET)) {
1083 maybe_set_status (urb, 0);
1087 /* device side completion --> continuable */
1088 if (req->req.status != -EINPROGRESS) {
1089 list_del_init (&req->queue);
1091 spin_unlock (&dum->lock);
1092 req->req.complete (&ep->ep, &req->req);
1093 spin_lock (&dum->lock);
1095 /* requests might have been unlinked... */
1099 /* host side completion --> terminate */
1100 if (urb->status != -EINPROGRESS)
1103 /* rescan to continue with any other queued i/o */
1110 static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1112 int limit = ep->ep.maxpacket;
1114 if (dum->gadget.speed == USB_SPEED_HIGH) {
1117 /* high bandwidth mode */
1118 tmp = le16_to_cpu(ep->desc->wMaxPacketSize);
1119 tmp = le16_to_cpu (tmp);
1120 tmp = (tmp >> 11) & 0x03;
1121 tmp *= 8 /* applies to entire frame */;
1122 limit += limit * tmp;
1127 #define is_active(dum) ((dum->port_status & \
1128 (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \
1129 USB_PORT_STAT_SUSPEND)) \
1130 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
1132 static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1136 if (!is_active (dum))
1138 if ((address & ~USB_DIR_IN) == 0)
1139 return &dum->ep [0];
1140 for (i = 1; i < DUMMY_ENDPOINTS; i++) {
1141 struct dummy_ep *ep = &dum->ep [i];
1145 if (ep->desc->bEndpointAddress == address)
1153 #define Dev_Request (USB_TYPE_STANDARD | USB_RECIP_DEVICE)
1154 #define Dev_InRequest (Dev_Request | USB_DIR_IN)
1155 #define Intf_Request (USB_TYPE_STANDARD | USB_RECIP_INTERFACE)
1156 #define Intf_InRequest (Intf_Request | USB_DIR_IN)
1157 #define Ep_Request (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)
1158 #define Ep_InRequest (Ep_Request | USB_DIR_IN)
1160 /* drive both sides of the transfers; looks like irq handlers to
1161 * both drivers except the callbacks aren't in_irq().
1163 static void dummy_timer (unsigned long _dum)
1165 struct dummy *dum = (struct dummy *) _dum;
1166 struct urbp *urbp, *tmp;
1167 unsigned long flags;
1171 /* simplistic model for one frame's bandwidth */
1172 switch (dum->gadget.speed) {
1174 total = 8/*bytes*/ * 12/*packets*/;
1176 case USB_SPEED_FULL:
1177 total = 64/*bytes*/ * 19/*packets*/;
1179 case USB_SPEED_HIGH:
1180 total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/;
1183 dev_err (dummy_dev(dum), "bogus device speed\n");
1187 /* FIXME if HZ != 1000 this will probably misbehave ... */
1189 /* look at each urb queued by the host side driver */
1190 spin_lock_irqsave (&dum->lock, flags);
1193 dev_err (dummy_dev(dum),
1194 "timer fired with no URBs pending?\n");
1195 spin_unlock_irqrestore (&dum->lock, flags);
1199 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
1202 dum->ep [i].already_seen = 0;
1206 list_for_each_entry_safe (urbp, tmp, &dum->urbp_list, urbp_list) {
1208 struct dummy_request *req;
1210 struct dummy_ep *ep = NULL;
1214 if (urb->status != -EINPROGRESS) {
1215 /* likely it was just unlinked */
1218 type = usb_pipetype (urb->pipe);
1220 /* used up this frame's non-periodic bandwidth?
1221 * FIXME there's infinite bandwidth for control and
1222 * periodic transfers ... unrealistic.
1224 if (total <= 0 && type == PIPE_BULK)
1227 /* find the gadget's ep for this request (if configured) */
1228 address = usb_pipeendpoint (urb->pipe);
1229 if (usb_pipein (urb->pipe))
1230 address |= USB_DIR_IN;
1231 ep = find_endpoint(dum, address);
1233 /* set_configuration() disagreement */
1234 dev_dbg (dummy_dev(dum),
1235 "no ep configured for urb %p\n",
1237 maybe_set_status (urb, -EPROTO);
1241 if (ep->already_seen)
1243 ep->already_seen = 1;
1244 if (ep == &dum->ep [0] && urb->error_count) {
1245 ep->setup_stage = 1; /* a new urb */
1246 urb->error_count = 0;
1248 if (ep->halted && !ep->setup_stage) {
1249 /* NOTE: must not be iso! */
1250 dev_dbg (dummy_dev(dum), "ep %s halted, urb %p\n",
1252 maybe_set_status (urb, -EPIPE);
1255 /* FIXME make sure both ends agree on maxpacket */
1257 /* handle control requests */
1258 if (ep == &dum->ep [0] && ep->setup_stage) {
1259 struct usb_ctrlrequest setup;
1261 struct dummy_ep *ep2;
1263 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1264 le16_to_cpus (&setup.wIndex);
1265 le16_to_cpus (&setup.wValue);
1266 le16_to_cpus (&setup.wLength);
1267 if (setup.wLength != urb->transfer_buffer_length) {
1268 maybe_set_status (urb, -EOVERFLOW);
1272 /* paranoia, in case of stale queued data */
1273 list_for_each_entry (req, &ep->queue, queue) {
1274 list_del_init (&req->queue);
1275 req->req.status = -EOVERFLOW;
1276 dev_dbg (udc_dev(dum), "stale req = %p\n",
1279 spin_unlock (&dum->lock);
1280 req->req.complete (&ep->ep, &req->req);
1281 spin_lock (&dum->lock);
1282 ep->already_seen = 0;
1286 /* gadget driver never sees set_address or operations
1287 * on standard feature flags. some hardware doesn't
1290 ep->last_io = jiffies;
1291 ep->setup_stage = 0;
1293 switch (setup.bRequest) {
1294 case USB_REQ_SET_ADDRESS:
1295 if (setup.bRequestType != Dev_Request)
1297 dum->address = setup.wValue;
1298 maybe_set_status (urb, 0);
1299 dev_dbg (udc_dev(dum), "set_address = %d\n",
1303 case USB_REQ_SET_FEATURE:
1304 if (setup.bRequestType == Dev_Request) {
1306 switch (setup.wValue) {
1307 case USB_DEVICE_REMOTE_WAKEUP:
1309 case USB_DEVICE_B_HNP_ENABLE:
1310 dum->gadget.b_hnp_enable = 1;
1312 case USB_DEVICE_A_HNP_SUPPORT:
1313 dum->gadget.a_hnp_support = 1;
1315 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1316 dum->gadget.a_alt_hnp_support
1320 value = -EOPNOTSUPP;
1324 (1 << setup.wValue);
1325 maybe_set_status (urb, 0);
1328 } else if (setup.bRequestType == Ep_Request) {
1330 ep2 = find_endpoint (dum,
1333 value = -EOPNOTSUPP;
1338 maybe_set_status (urb, 0);
1341 case USB_REQ_CLEAR_FEATURE:
1342 if (setup.bRequestType == Dev_Request) {
1343 switch (setup.wValue) {
1344 case USB_DEVICE_REMOTE_WAKEUP:
1345 dum->devstatus &= ~(1 <<
1346 USB_DEVICE_REMOTE_WAKEUP);
1348 maybe_set_status (urb, 0);
1351 value = -EOPNOTSUPP;
1354 } else if (setup.bRequestType == Ep_Request) {
1356 ep2 = find_endpoint (dum,
1359 value = -EOPNOTSUPP;
1364 maybe_set_status (urb, 0);
1367 case USB_REQ_GET_STATUS:
1368 if (setup.bRequestType == Dev_InRequest
1369 || setup.bRequestType
1371 || setup.bRequestType
1376 // device: remote wakeup, selfpowered
1377 // interface: nothing
1379 buf = (char *)urb->transfer_buffer;
1380 if (urb->transfer_buffer_length > 0) {
1381 if (setup.bRequestType ==
1383 ep2 = find_endpoint (dum, setup.wIndex);
1385 value = -EOPNOTSUPP;
1388 buf [0] = ep2->halted;
1389 } else if (setup.bRequestType ==
1396 if (urb->transfer_buffer_length > 1)
1398 urb->actual_length = min (2,
1399 urb->transfer_buffer_length);
1401 maybe_set_status (urb, 0);
1406 /* gadget driver handles all other requests. block
1407 * until setup() returns; no reentrancy issues etc.
1410 spin_unlock (&dum->lock);
1411 value = dum->driver->setup (&dum->gadget,
1413 spin_lock (&dum->lock);
1416 /* no delays (max 64KB data stage) */
1418 goto treat_control_like_bulk;
1420 /* error, see below */
1424 if (value != -EOPNOTSUPP)
1425 dev_dbg (udc_dev(dum),
1428 maybe_set_status (urb, -EPIPE);
1429 urb->actual_length = 0;
1435 /* non-control requests */
1437 switch (usb_pipetype (urb->pipe)) {
1438 case PIPE_ISOCHRONOUS:
1439 /* FIXME is it urb->interval since the last xfer?
1440 * use urb->iso_frame_desc[i].
1441 * complete whether or not ep has requests queued.
1442 * report random errors, to debug drivers.
1444 limit = max (limit, periodic_bytes (dum, ep));
1445 maybe_set_status (urb, -ENOSYS);
1448 case PIPE_INTERRUPT:
1449 /* FIXME is it urb->interval since the last xfer?
1450 * this almost certainly polls too fast.
1452 limit = max (limit, periodic_bytes (dum, ep));
1455 // case PIPE_BULK: case PIPE_CONTROL:
1457 treat_control_like_bulk:
1458 ep->last_io = jiffies;
1459 total = transfer (dum, urb, ep, limit);
1463 /* incomplete transfer? */
1464 if (urb->status == -EINPROGRESS)
1469 list_del (&urbp->urbp_list);
1472 ep->already_seen = ep->setup_stage = 0;
1474 spin_unlock (&dum->lock);
1475 usb_hcd_giveback_urb (dummy_to_hcd(dum), urb, NULL);
1476 spin_lock (&dum->lock);
1481 /* want a 1 msec delay here */
1482 if (!list_empty (&dum->urbp_list))
1483 mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1));
1485 usb_put_dev (dum->udev);
1489 spin_unlock_irqrestore (&dum->lock, flags);
1492 /*-------------------------------------------------------------------------*/
1494 #define PORT_C_MASK \
1495 ((USB_PORT_STAT_C_CONNECTION \
1496 | USB_PORT_STAT_C_ENABLE \
1497 | USB_PORT_STAT_C_SUSPEND \
1498 | USB_PORT_STAT_C_OVERCURRENT \
1499 | USB_PORT_STAT_C_RESET) << 16)
1501 static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1504 unsigned long flags;
1507 dum = hcd_to_dummy (hcd);
1509 spin_lock_irqsave (&dum->lock, flags);
1511 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
1512 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1513 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1514 set_link_state (dum);
1517 if (!(dum->port_status & PORT_C_MASK))
1521 dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n",
1525 spin_unlock_irqrestore (&dum->lock, flags);
1530 hub_descriptor (struct usb_hub_descriptor *desc)
1532 memset (desc, 0, sizeof *desc);
1533 desc->bDescriptorType = 0x29;
1534 desc->bDescLength = 9;
1535 desc->wHubCharacteristics = __constant_cpu_to_le16 (0x0001);
1536 desc->bNbrPorts = 1;
1537 desc->bitmap [0] = 0xff;
1538 desc->bitmap [1] = 0xff;
1541 static int dummy_hub_control (
1542 struct usb_hcd *hcd,
1551 unsigned long flags;
1553 dum = hcd_to_dummy (hcd);
1554 spin_lock_irqsave (&dum->lock, flags);
1556 case ClearHubFeature:
1558 case ClearPortFeature:
1560 case USB_PORT_FEAT_SUSPEND:
1561 if (dum->port_status & USB_PORT_STAT_SUSPEND) {
1562 /* 20msec resume signaling */
1564 dum->re_timeout = jiffies +
1565 msecs_to_jiffies(20);
1568 case USB_PORT_FEAT_POWER:
1569 if (dum->port_status & USB_PORT_STAT_POWER)
1570 dev_dbg (dummy_dev(dum), "power-off\n");
1573 dum->port_status &= ~(1 << wValue);
1574 set_link_state (dum);
1577 case GetHubDescriptor:
1578 hub_descriptor ((struct usb_hub_descriptor *) buf);
1581 *(u32 *) buf = __constant_cpu_to_le32 (0);
1587 /* whoever resets or resumes must GetPortStatus to
1590 if (dum->resuming &&
1591 time_after_eq (jiffies, dum->re_timeout)) {
1592 dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1593 dum->port_status &= ~USB_PORT_STAT_SUSPEND;
1595 if ((dum->port_status & USB_PORT_STAT_RESET) != 0 &&
1596 time_after_eq (jiffies, dum->re_timeout)) {
1597 dum->port_status |= (USB_PORT_STAT_C_RESET << 16);
1598 dum->port_status &= ~USB_PORT_STAT_RESET;
1600 dum->port_status |= USB_PORT_STAT_ENABLE;
1601 /* give it the best speed we agree on */
1602 dum->gadget.speed = dum->driver->speed;
1603 dum->gadget.ep0->maxpacket = 64;
1604 switch (dum->gadget.speed) {
1605 case USB_SPEED_HIGH:
1607 USB_PORT_STAT_HIGH_SPEED;
1610 dum->gadget.ep0->maxpacket = 8;
1612 USB_PORT_STAT_LOW_SPEED;
1615 dum->gadget.speed = USB_SPEED_FULL;
1620 set_link_state (dum);
1621 ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status);
1622 ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16);
1627 case SetPortFeature:
1629 case USB_PORT_FEAT_SUSPEND:
1631 dum->port_status |= USB_PORT_STAT_SUSPEND;
1633 /* HNP would happen here; for now we
1634 * assume b_bus_req is always true.
1636 set_link_state (dum);
1637 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1638 & dum->devstatus) != 0)
1639 dev_dbg (dummy_dev(dum),
1643 case USB_PORT_FEAT_POWER:
1644 dum->port_status |= USB_PORT_STAT_POWER;
1645 set_link_state (dum);
1647 case USB_PORT_FEAT_RESET:
1648 /* if it's already enabled, disable */
1649 dum->port_status &= ~(USB_PORT_STAT_ENABLE
1650 | USB_PORT_STAT_LOW_SPEED
1651 | USB_PORT_STAT_HIGH_SPEED);
1652 /* 50msec reset signaling */
1653 dum->re_timeout = jiffies + msecs_to_jiffies(50);
1656 if ((dum->port_status & USB_PORT_STAT_POWER) != 0) {
1657 dum->port_status |= (1 << wValue);
1658 set_link_state (dum);
1664 dev_dbg (dummy_dev(dum),
1665 "hub control req%04x v%04x i%04x l%d\n",
1666 typeReq, wValue, wIndex, wLength);
1668 /* "protocol stall" on error */
1671 spin_unlock_irqrestore (&dum->lock, flags);
1676 /*-------------------------------------------------------------------------*/
1678 static inline ssize_t
1679 show_urb (char *buf, size_t size, struct urb *urb)
1681 int ep = usb_pipeendpoint (urb->pipe);
1683 return snprintf (buf, size,
1684 "urb/%p %s ep%d%s%s len %d/%d\n",
1687 switch (urb->dev->speed) {
1688 case USB_SPEED_LOW: s = "ls"; break;
1689 case USB_SPEED_FULL: s = "fs"; break;
1690 case USB_SPEED_HIGH: s = "hs"; break;
1691 default: s = "?"; break;
1693 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "",
1695 switch (usb_pipetype (urb->pipe)) { \
1696 case PIPE_CONTROL: s = ""; break; \
1697 case PIPE_BULK: s = "-bulk"; break; \
1698 case PIPE_INTERRUPT: s = "-int"; break; \
1699 default: s = "-iso"; break; \
1701 urb->actual_length, urb->transfer_buffer_length);
1705 show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
1707 struct usb_hcd *hcd = dev_get_drvdata (dev);
1708 struct dummy *dum = hcd_to_dummy (hcd);
1711 unsigned long flags;
1713 spin_lock_irqsave (&dum->lock, flags);
1714 list_for_each_entry (urbp, &dum->urbp_list, urbp_list) {
1717 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb);
1721 spin_unlock_irqrestore (&dum->lock, flags);
1725 static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
1727 static int dummy_start (struct usb_hcd *hcd)
1731 dum = hcd_to_dummy (hcd);
1734 * MASTER side init ... we emulate a root hub that'll only ever
1735 * talk to one device (the slave side). Also appears in sysfs,
1736 * just like more familiar pci-based HCDs.
1738 spin_lock_init (&dum->lock);
1739 init_timer (&dum->timer);
1740 dum->timer.function = dummy_timer;
1741 dum->timer.data = (unsigned long) dum;
1743 INIT_LIST_HEAD (&dum->urbp_list);
1745 /* only show a low-power port: just 8mA */
1746 hcd->power_budget = 8;
1747 hcd->state = HC_STATE_RUNNING;
1749 #ifdef CONFIG_USB_OTG
1750 hcd->self.otg_port = 1;
1753 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1754 device_create_file (dummy_dev(dum), &dev_attr_urbs);
1758 static void dummy_stop (struct usb_hcd *hcd)
1762 dum = hcd_to_dummy (hcd);
1764 device_remove_file (dummy_dev(dum), &dev_attr_urbs);
1765 usb_gadget_unregister_driver (dum->driver);
1766 dev_info (dummy_dev(dum), "stopped\n");
1769 /*-------------------------------------------------------------------------*/
1771 static int dummy_h_get_frame (struct usb_hcd *hcd)
1773 return dummy_g_get_frame (NULL);
1776 static const struct hc_driver dummy_hcd = {
1777 .description = (char *) driver_name,
1778 .product_desc = "Dummy host controller",
1779 .hcd_priv_size = sizeof(struct dummy),
1783 .start = dummy_start,
1786 .urb_enqueue = dummy_urb_enqueue,
1787 .urb_dequeue = dummy_urb_dequeue,
1789 .get_frame_number = dummy_h_get_frame,
1791 .hub_status_data = dummy_hub_status,
1792 .hub_control = dummy_hub_control,
1795 static int dummy_hcd_probe (struct device *dev)
1797 struct usb_hcd *hcd;
1800 dev_info (dev, "%s, driver " DRIVER_VERSION "\n", driver_desc);
1802 hcd = usb_create_hcd (&dummy_hcd, dev, dev->bus_id);
1805 the_controller = hcd_to_dummy (hcd);
1807 retval = usb_add_hcd(hcd, 0, 0);
1810 the_controller = NULL;
1815 static int dummy_hcd_remove (struct device *dev)
1817 struct usb_hcd *hcd;
1819 hcd = dev_get_drvdata (dev);
1820 usb_remove_hcd (hcd);
1822 the_controller = NULL;
1826 static struct device_driver dummy_hcd_driver = {
1827 .name = (char *) driver_name,
1828 .bus = &platform_bus_type,
1829 .probe = dummy_hcd_probe,
1830 .remove = dummy_hcd_remove,
1833 /*-------------------------------------------------------------------------*/
1835 /* These don't need to do anything because the pdev structures are
1836 * statically allocated. */
1838 dummy_udc_release (struct device *dev) {}
1841 dummy_hcd_release (struct device *dev) {}
1843 static struct platform_device the_udc_pdev = {
1844 .name = (char *) gadget_name,
1847 .release = dummy_udc_release,
1851 static struct platform_device the_hcd_pdev = {
1852 .name = (char *) driver_name,
1855 .release = dummy_hcd_release,
1859 static int __init init (void)
1863 if (usb_disabled ())
1866 retval = driver_register (&dummy_hcd_driver);
1870 retval = driver_register (&dummy_udc_driver);
1872 goto err_register_udc_driver;
1874 retval = platform_device_register (&the_hcd_pdev);
1876 goto err_register_hcd;
1878 retval = platform_device_register (&the_udc_pdev);
1880 goto err_register_udc;
1884 platform_device_unregister (&the_hcd_pdev);
1886 driver_unregister (&dummy_udc_driver);
1887 err_register_udc_driver:
1888 driver_unregister (&dummy_hcd_driver);
1893 static void __exit cleanup (void)
1895 platform_device_unregister (&the_udc_pdev);
1896 platform_device_unregister (&the_hcd_pdev);
1897 driver_unregister (&dummy_udc_driver);
1898 driver_unregister (&dummy_hcd_driver);
1900 module_exit (cleanup);