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.
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/delay.h>
40 #include <linux/ioport.h>
41 #include <linux/slab.h>
42 #include <linux/errno.h>
43 #include <linux/init.h>
44 #include <linux/timer.h>
45 #include <linux/list.h>
46 #include <linux/interrupt.h>
47 #include <linux/platform_device.h>
48 #include <linux/usb.h>
49 #include <linux/usb/gadget.h>
50 #include <linux/usb/hcd.h>
52 #include <asm/byteorder.h>
55 #include <asm/system.h>
56 #include <asm/unaligned.h>
59 #define DRIVER_DESC "USB Host+Gadget Emulator"
60 #define DRIVER_VERSION "02 May 2005"
62 #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
64 static const char driver_name [] = "dummy_hcd";
65 static const char driver_desc [] = "USB Host+Gadget Emulator";
67 static const char gadget_name [] = "dummy_udc";
69 MODULE_DESCRIPTION (DRIVER_DESC);
70 MODULE_AUTHOR ("David Brownell");
71 MODULE_LICENSE ("GPL");
73 struct dummy_hcd_module_parameters {
77 static struct dummy_hcd_module_parameters mod_data = {
78 .is_super_speed = false
80 module_param_named(is_super_speed, mod_data.is_super_speed, bool, S_IRUGO);
81 MODULE_PARM_DESC(is_super_speed, "true to simulate SuperSpeed connection");
82 /*-------------------------------------------------------------------------*/
84 /* gadget side driver data structres */
86 struct list_head queue;
87 unsigned long last_io; /* jiffies timestamp */
88 struct usb_gadget *gadget;
89 const struct usb_endpoint_descriptor *desc;
93 unsigned already_seen : 1;
94 unsigned setup_stage : 1;
97 struct dummy_request {
98 struct list_head queue; /* ep's requests */
99 struct usb_request req;
102 static inline struct dummy_ep *usb_ep_to_dummy_ep (struct usb_ep *_ep)
104 return container_of (_ep, struct dummy_ep, ep);
107 static inline struct dummy_request *usb_request_to_dummy_request
108 (struct usb_request *_req)
110 return container_of (_req, struct dummy_request, req);
113 /*-------------------------------------------------------------------------*/
116 * Every device has ep0 for control requests, plus up to 30 more endpoints,
117 * in one of two types:
119 * - Configurable: direction (in/out), type (bulk, iso, etc), and endpoint
120 * number can be changed. Names like "ep-a" are used for this type.
122 * - Fixed Function: in other cases. some characteristics may be mutable;
123 * that'd be hardware-specific. Names like "ep12out-bulk" are used.
125 * Gadget drivers are responsible for not setting up conflicting endpoint
126 * configurations, illegal or unsupported packet lengths, and so on.
129 static const char ep0name [] = "ep0";
131 static const char *const ep_name [] = {
132 ep0name, /* everyone has ep0 */
134 /* act like a net2280: high speed, six configurable endpoints */
135 "ep-a", "ep-b", "ep-c", "ep-d", "ep-e", "ep-f",
137 /* or like pxa250: fifteen fixed function endpoints */
138 "ep1in-bulk", "ep2out-bulk", "ep3in-iso", "ep4out-iso", "ep5in-int",
139 "ep6in-bulk", "ep7out-bulk", "ep8in-iso", "ep9out-iso", "ep10in-int",
140 "ep11in-bulk", "ep12out-bulk", "ep13in-iso", "ep14out-iso",
143 /* or like sa1100: two fixed function endpoints */
144 "ep1out-bulk", "ep2in-bulk",
146 #define DUMMY_ENDPOINTS ARRAY_SIZE(ep_name)
148 /*-------------------------------------------------------------------------*/
154 struct list_head urbp_list;
158 enum dummy_rh_state {
166 enum dummy_rh_state rh_state;
167 struct timer_list timer;
170 unsigned long re_timeout;
172 struct usb_device *udev;
173 struct list_head urbp_list;
176 unsigned old_active:1;
184 * SLAVE/GADGET side support
186 struct dummy_ep ep [DUMMY_ENDPOINTS];
188 struct usb_gadget gadget;
189 struct usb_gadget_driver *driver;
190 struct dummy_request fifo_req;
191 u8 fifo_buf [FIFO_SIZE];
193 unsigned udc_suspended:1;
197 * MASTER/HOST side support
199 struct dummy_hcd *hs_hcd;
200 struct dummy_hcd *ss_hcd;
203 static inline struct dummy_hcd *hcd_to_dummy_hcd(struct usb_hcd *hcd)
205 return (struct dummy_hcd *) (hcd->hcd_priv);
208 static inline struct usb_hcd *dummy_hcd_to_hcd(struct dummy_hcd *dum)
210 return container_of((void *) dum, struct usb_hcd, hcd_priv);
213 static inline struct device *dummy_dev(struct dummy_hcd *dum)
215 return dummy_hcd_to_hcd(dum)->self.controller;
218 static inline struct device *udc_dev (struct dummy *dum)
220 return dum->gadget.dev.parent;
223 static inline struct dummy *ep_to_dummy (struct dummy_ep *ep)
225 return container_of (ep->gadget, struct dummy, gadget);
228 static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
230 struct dummy *dum = container_of(gadget, struct dummy, gadget);
231 if (dum->gadget.speed == USB_SPEED_SUPER)
237 static inline struct dummy *gadget_dev_to_dummy (struct device *dev)
239 return container_of (dev, struct dummy, gadget.dev);
242 static struct dummy the_controller;
244 /*-------------------------------------------------------------------------*/
246 /* SLAVE/GADGET SIDE UTILITY ROUTINES */
248 /* called with spinlock held */
249 static void nuke (struct dummy *dum, struct dummy_ep *ep)
251 while (!list_empty (&ep->queue)) {
252 struct dummy_request *req;
254 req = list_entry (ep->queue.next, struct dummy_request, queue);
255 list_del_init (&req->queue);
256 req->req.status = -ESHUTDOWN;
258 spin_unlock (&dum->lock);
259 req->req.complete (&ep->ep, &req->req);
260 spin_lock (&dum->lock);
264 /* caller must hold lock */
266 stop_activity (struct dummy *dum)
270 /* prevent any more requests */
273 /* The timer is left running so that outstanding URBs can fail */
275 /* nuke any pending requests first, so driver i/o is quiesced */
276 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list)
279 /* driver now does any non-usb quiescing necessary */
283 * set_link_state_by_speed() - Sets the current state of the link according to
285 * @dum_hcd: pointer to the dummy_hcd structure to update the link state for
287 * This function updates the port_status according to the link state and the
290 static void set_link_state_by_speed(struct dummy_hcd *dum_hcd)
292 struct dummy *dum = dum_hcd->dum;
294 if (dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3) {
295 if ((dum_hcd->port_status & USB_SS_PORT_STAT_POWER) == 0) {
296 dum_hcd->port_status = 0;
297 } else if (!dum->pullup || dum->udc_suspended) {
298 /* UDC suspend must cause a disconnect */
299 dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION |
300 USB_PORT_STAT_ENABLE);
301 if ((dum_hcd->old_status &
302 USB_PORT_STAT_CONNECTION) != 0)
303 dum_hcd->port_status |=
304 (USB_PORT_STAT_C_CONNECTION << 16);
306 /* device is connected and not suspended */
307 dum_hcd->port_status |= (USB_PORT_STAT_CONNECTION |
308 USB_PORT_STAT_SPEED_5GBPS) ;
309 if ((dum_hcd->old_status &
310 USB_PORT_STAT_CONNECTION) == 0)
311 dum_hcd->port_status |=
312 (USB_PORT_STAT_C_CONNECTION << 16);
313 if ((dum_hcd->port_status &
314 USB_PORT_STAT_ENABLE) == 1 &&
315 (dum_hcd->port_status &
316 USB_SS_PORT_LS_U0) == 1 &&
317 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
321 if ((dum_hcd->port_status & USB_PORT_STAT_POWER) == 0) {
322 dum_hcd->port_status = 0;
323 } else if (!dum->pullup || dum->udc_suspended) {
324 /* UDC suspend must cause a disconnect */
325 dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION |
326 USB_PORT_STAT_ENABLE |
327 USB_PORT_STAT_LOW_SPEED |
328 USB_PORT_STAT_HIGH_SPEED |
329 USB_PORT_STAT_SUSPEND);
330 if ((dum_hcd->old_status &
331 USB_PORT_STAT_CONNECTION) != 0)
332 dum_hcd->port_status |=
333 (USB_PORT_STAT_C_CONNECTION << 16);
335 dum_hcd->port_status |= USB_PORT_STAT_CONNECTION;
336 if ((dum_hcd->old_status &
337 USB_PORT_STAT_CONNECTION) == 0)
338 dum_hcd->port_status |=
339 (USB_PORT_STAT_C_CONNECTION << 16);
340 if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0)
341 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
342 else if ((dum_hcd->port_status &
343 USB_PORT_STAT_SUSPEND) == 0 &&
344 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
350 /* caller must hold lock */
351 static void set_link_state(struct dummy_hcd *dum_hcd)
353 struct dummy *dum = dum_hcd->dum;
357 if ((dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3 &&
358 dum->gadget.speed != USB_SPEED_SUPER) ||
359 (dummy_hcd_to_hcd(dum_hcd)->speed != HCD_USB3 &&
360 dum->gadget.speed == USB_SPEED_SUPER))
363 set_link_state_by_speed(dum_hcd);
365 if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0 ||
367 dum_hcd->resuming = 0;
369 /* if !connected or reset */
370 if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0 ||
371 (dum_hcd->port_status & USB_PORT_STAT_RESET) != 0) {
373 * We're connected and not reset (reset occurred now),
374 * and driver attached - disconnect!
376 if ((dum_hcd->old_status & USB_PORT_STAT_CONNECTION) != 0 &&
377 (dum_hcd->old_status & USB_PORT_STAT_RESET) == 0 &&
380 spin_unlock(&dum->lock);
381 dum->driver->disconnect(&dum->gadget);
382 spin_lock(&dum->lock);
384 } else if (dum_hcd->active != dum_hcd->old_active) {
385 if (dum_hcd->old_active && dum->driver->suspend) {
386 spin_unlock(&dum->lock);
387 dum->driver->suspend(&dum->gadget);
388 spin_lock(&dum->lock);
389 } else if (!dum_hcd->old_active && dum->driver->resume) {
390 spin_unlock(&dum->lock);
391 dum->driver->resume(&dum->gadget);
392 spin_lock(&dum->lock);
396 dum_hcd->old_status = dum_hcd->port_status;
397 dum_hcd->old_active = dum_hcd->active;
400 /*-------------------------------------------------------------------------*/
402 /* SLAVE/GADGET SIDE DRIVER
404 * This only tracks gadget state. All the work is done when the host
405 * side tries some (emulated) i/o operation. Real device controller
406 * drivers would do real i/o using dma, fifos, irqs, timers, etc.
409 #define is_enabled(dum) \
410 (dum->port_status & USB_PORT_STAT_ENABLE)
413 dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
416 struct dummy_hcd *dum_hcd;
421 ep = usb_ep_to_dummy_ep (_ep);
422 if (!_ep || !desc || ep->desc || _ep->name == ep0name
423 || desc->bDescriptorType != USB_DT_ENDPOINT)
425 dum = ep_to_dummy (ep);
428 if (dum->gadget.speed == USB_SPEED_SUPER)
429 dum_hcd = dum->ss_hcd;
431 dum_hcd = dum->hs_hcd;
432 if (!is_enabled(dum_hcd))
436 * For HS/FS devices only bits 0..10 of the wMaxPacketSize represent the
437 * maximum packet size.
438 * For SS devices the wMaxPacketSize is limited by 1024.
440 max = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff;
442 /* drivers must not request bad settings, since lower levels
443 * (hardware or its drivers) may not check. some endpoints
444 * can't do iso, many have maxpacket limitations, etc.
446 * since this "hardware" driver is here to help debugging, we
447 * have some extra sanity checks. (there could be more though,
448 * especially for "ep9out" style fixed function ones.)
451 switch (desc->bmAttributes & 0x03) {
452 case USB_ENDPOINT_XFER_BULK:
453 if (strstr (ep->ep.name, "-iso")
454 || strstr (ep->ep.name, "-int")) {
457 switch (dum->gadget.speed) {
458 case USB_SPEED_SUPER:
467 if (max == 8 || max == 16 || max == 32 || max == 64)
468 /* we'll fake any legal size */
470 /* save a return statement */
475 case USB_ENDPOINT_XFER_INT:
476 if (strstr (ep->ep.name, "-iso")) /* bulk is ok */
478 /* real hardware might not handle all packet sizes */
479 switch (dum->gadget.speed) {
480 case USB_SPEED_SUPER:
484 /* save a return statement */
488 /* save a return statement */
495 case USB_ENDPOINT_XFER_ISOC:
496 if (strstr (ep->ep.name, "-bulk")
497 || strstr (ep->ep.name, "-int"))
499 /* real hardware might not handle all packet sizes */
500 switch (dum->gadget.speed) {
501 case USB_SPEED_SUPER:
505 /* save a return statement */
509 /* save a return statement */
515 /* few chips support control except on ep0 */
519 _ep->maxpacket = max;
522 dev_dbg (udc_dev(dum), "enabled %s (ep%d%s-%s) maxpacket %d\n",
524 desc->bEndpointAddress & 0x0f,
525 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
527 switch (desc->bmAttributes & 0x03) {
528 case USB_ENDPOINT_XFER_BULK:
531 case USB_ENDPOINT_XFER_ISOC:
534 case USB_ENDPOINT_XFER_INT:
543 /* at this point real hardware should be NAKing transfers
544 * to that endpoint, until a buffer is queued to it.
546 ep->halted = ep->wedged = 0;
552 static int dummy_disable (struct usb_ep *_ep)
559 ep = usb_ep_to_dummy_ep (_ep);
560 if (!_ep || !ep->desc || _ep->name == ep0name)
562 dum = ep_to_dummy (ep);
564 spin_lock_irqsave (&dum->lock, flags);
568 spin_unlock_irqrestore (&dum->lock, flags);
570 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name);
574 static struct usb_request *
575 dummy_alloc_request (struct usb_ep *_ep, gfp_t mem_flags)
578 struct dummy_request *req;
582 ep = usb_ep_to_dummy_ep (_ep);
584 req = kzalloc(sizeof(*req), mem_flags);
587 INIT_LIST_HEAD (&req->queue);
592 dummy_free_request (struct usb_ep *_ep, struct usb_request *_req)
595 struct dummy_request *req;
597 ep = usb_ep_to_dummy_ep (_ep);
598 if (!ep || !_req || (!ep->desc && _ep->name != ep0name))
601 req = usb_request_to_dummy_request (_req);
602 WARN_ON (!list_empty (&req->queue));
607 fifo_complete (struct usb_ep *ep, struct usb_request *req)
612 dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
616 struct dummy_request *req;
618 struct dummy_hcd *dum_hcd;
621 req = usb_request_to_dummy_request (_req);
622 if (!_req || !list_empty (&req->queue) || !_req->complete)
625 ep = usb_ep_to_dummy_ep (_ep);
626 if (!_ep || (!ep->desc && _ep->name != ep0name))
629 dum = ep_to_dummy (ep);
630 if (dum->gadget.speed == USB_SPEED_SUPER)
631 dum_hcd = dum->ss_hcd;
633 dum_hcd = dum->hs_hcd;
634 if (!dum->driver || !is_enabled(dum_hcd))
638 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
639 ep, _req, _ep->name, _req->length, _req->buf);
642 _req->status = -EINPROGRESS;
644 spin_lock_irqsave (&dum->lock, flags);
646 /* implement an emulated single-request FIFO */
647 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
648 list_empty (&dum->fifo_req.queue) &&
649 list_empty (&ep->queue) &&
650 _req->length <= FIFO_SIZE) {
651 req = &dum->fifo_req;
653 req->req.buf = dum->fifo_buf;
654 memcpy (dum->fifo_buf, _req->buf, _req->length);
655 req->req.context = dum;
656 req->req.complete = fifo_complete;
658 list_add_tail(&req->queue, &ep->queue);
659 spin_unlock (&dum->lock);
660 _req->actual = _req->length;
662 _req->complete (_ep, _req);
663 spin_lock (&dum->lock);
665 list_add_tail(&req->queue, &ep->queue);
666 spin_unlock_irqrestore (&dum->lock, flags);
668 /* real hardware would likely enable transfers here, in case
669 * it'd been left NAKing.
674 static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
678 int retval = -EINVAL;
680 struct dummy_request *req = NULL;
684 ep = usb_ep_to_dummy_ep (_ep);
685 dum = ep_to_dummy (ep);
690 local_irq_save (flags);
691 spin_lock (&dum->lock);
692 list_for_each_entry (req, &ep->queue, queue) {
693 if (&req->req == _req) {
694 list_del_init (&req->queue);
695 _req->status = -ECONNRESET;
700 spin_unlock (&dum->lock);
703 dev_dbg (udc_dev(dum),
704 "dequeued req %p from %s, len %d buf %p\n",
705 req, _ep->name, _req->length, _req->buf);
706 _req->complete (_ep, _req);
708 local_irq_restore (flags);
713 dummy_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
720 ep = usb_ep_to_dummy_ep (_ep);
721 dum = ep_to_dummy (ep);
725 ep->halted = ep->wedged = 0;
726 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
727 !list_empty (&ep->queue))
734 /* FIXME clear emulated data toggle too */
739 dummy_set_halt(struct usb_ep *_ep, int value)
741 return dummy_set_halt_and_wedge(_ep, value, 0);
744 static int dummy_set_wedge(struct usb_ep *_ep)
746 if (!_ep || _ep->name == ep0name)
748 return dummy_set_halt_and_wedge(_ep, 1, 1);
751 static const struct usb_ep_ops dummy_ep_ops = {
752 .enable = dummy_enable,
753 .disable = dummy_disable,
755 .alloc_request = dummy_alloc_request,
756 .free_request = dummy_free_request,
758 .queue = dummy_queue,
759 .dequeue = dummy_dequeue,
761 .set_halt = dummy_set_halt,
762 .set_wedge = dummy_set_wedge,
765 /*-------------------------------------------------------------------------*/
767 /* there are both host and device side versions of this call ... */
768 static int dummy_g_get_frame (struct usb_gadget *_gadget)
772 do_gettimeofday (&tv);
773 return tv.tv_usec / 1000;
776 static int dummy_wakeup (struct usb_gadget *_gadget)
778 struct dummy_hcd *dum_hcd;
780 dum_hcd = gadget_to_dummy_hcd(_gadget);
781 if (!(dum_hcd->dum->devstatus & ((1 << USB_DEVICE_B_HNP_ENABLE)
782 | (1 << USB_DEVICE_REMOTE_WAKEUP))))
784 if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0)
786 if ((dum_hcd->port_status & USB_PORT_STAT_SUSPEND) == 0 &&
787 dum_hcd->rh_state != DUMMY_RH_SUSPENDED)
790 /* FIXME: What if the root hub is suspended but the port isn't? */
792 /* hub notices our request, issues downstream resume, etc */
793 dum_hcd->resuming = 1;
794 dum_hcd->re_timeout = jiffies + msecs_to_jiffies(20);
795 mod_timer(&dummy_hcd_to_hcd(dum_hcd)->rh_timer, dum_hcd->re_timeout);
799 static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value)
803 dum = (gadget_to_dummy_hcd(_gadget))->dum;
805 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED);
807 dum->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED);
811 static int dummy_pullup (struct usb_gadget *_gadget, int value)
816 dum = gadget_to_dummy_hcd(_gadget)->dum;
817 spin_lock_irqsave (&dum->lock, flags);
818 dum->pullup = (value != 0);
819 set_link_state((dum->gadget.speed == USB_SPEED_SUPER ?
820 dum->ss_hcd : dum->hs_hcd));
821 spin_unlock_irqrestore (&dum->lock, flags);
822 usb_hcd_poll_rh_status((dum->gadget.speed == USB_SPEED_SUPER ?
823 dummy_hcd_to_hcd(dum->ss_hcd) :
824 dummy_hcd_to_hcd(dum->hs_hcd)));
828 static int dummy_udc_start(struct usb_gadget_driver *driver,
829 int (*bind)(struct usb_gadget *));
830 static int dummy_udc_stop(struct usb_gadget_driver *driver);
832 static const struct usb_gadget_ops dummy_ops = {
833 .get_frame = dummy_g_get_frame,
834 .wakeup = dummy_wakeup,
835 .set_selfpowered = dummy_set_selfpowered,
836 .pullup = dummy_pullup,
837 .start = dummy_udc_start,
838 .stop = dummy_udc_stop,
841 /*-------------------------------------------------------------------------*/
843 /* "function" sysfs attribute */
845 show_function (struct device *dev, struct device_attribute *attr, char *buf)
847 struct dummy *dum = gadget_dev_to_dummy (dev);
849 if (!dum->driver || !dum->driver->function)
851 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function);
853 static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
855 /*-------------------------------------------------------------------------*/
858 * Driver registration/unregistration.
860 * This is basically hardware-specific; there's usually only one real USB
861 * device (not host) controller since that's how USB devices are intended
862 * to work. So most implementations of these api calls will rely on the
863 * fact that only one driver will ever bind to the hardware. But curious
864 * hardware can be built with discrete components, so the gadget API doesn't
865 * require that assumption.
867 * For this emulator, it might be convenient to create a usb slave device
868 * for each driver that registers: just add to a big root hub.
871 static int dummy_udc_start(struct usb_gadget_driver *driver,
872 int (*bind)(struct usb_gadget *))
874 struct dummy *dum = &the_controller;
881 if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN)
885 * SLAVE side init ... the layer above hardware, which
886 * can't enumerate without help from the driver we're binding.
891 INIT_LIST_HEAD (&dum->gadget.ep_list);
892 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
893 struct dummy_ep *ep = &dum->ep [i];
897 ep->ep.name = ep_name [i];
898 ep->ep.ops = &dummy_ep_ops;
899 list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list);
900 ep->halted = ep->wedged = ep->already_seen =
902 ep->ep.maxpacket = ~0;
903 ep->last_io = jiffies;
904 ep->gadget = &dum->gadget;
906 INIT_LIST_HEAD (&ep->queue);
909 dum->gadget.ep0 = &dum->ep [0].ep;
910 if (mod_data.is_super_speed)
911 dum->gadget.speed = driver->speed;
913 dum->gadget.speed = min((u8)USB_SPEED_HIGH, (u8)driver->speed);
914 if (dum->gadget.speed < driver->speed)
915 dev_dbg(udc_dev(dum), "This device can perform faster if"
916 " you connect it to a "
917 "SupeSpeed port...\n");
919 if (dum->gadget.speed == USB_SPEED_SUPER) {
920 for (i = 0; i < DUMMY_ENDPOINTS; i++)
921 dum->ep[i].ep.max_streams = 0x10;
922 dum->ep[0].ep.maxpacket = 9;
924 dum->ep[0].ep.maxpacket = 64;
925 list_del_init (&dum->ep [0].ep.ep_list);
926 INIT_LIST_HEAD(&dum->fifo_req.queue);
928 driver->driver.bus = NULL;
929 dum->driver = driver;
930 dum->gadget.dev.driver = &driver->driver;
931 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
932 driver->driver.name);
933 retval = bind(&dum->gadget);
936 dum->gadget.dev.driver = NULL;
940 /* khubd will enumerate this in a while */
941 spin_lock_irq (&dum->lock);
943 if (dum->gadget.speed == USB_SPEED_SUPER) {
945 (dummy_hcd_to_hcd(dum->ss_hcd)->self.otg_port != 0);
946 set_link_state(dum->ss_hcd);
949 (dummy_hcd_to_hcd(dum->hs_hcd)->self.otg_port != 0);
950 set_link_state(dum->hs_hcd);
953 spin_unlock_irq (&dum->lock);
955 usb_hcd_poll_rh_status((dum->gadget.speed == USB_SPEED_SUPER ?
956 dummy_hcd_to_hcd(dum->ss_hcd) :
957 dummy_hcd_to_hcd(dum->hs_hcd)));
961 static int dummy_udc_stop(struct usb_gadget_driver *driver)
963 struct dummy *dum = &the_controller;
968 if (!driver || driver != dum->driver || !driver->unbind)
971 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
972 driver->driver.name);
974 spin_lock_irqsave (&dum->lock, flags);
976 set_link_state((dum->gadget.speed == USB_SPEED_SUPER ?
977 dum->ss_hcd : dum->hs_hcd));
978 spin_unlock_irqrestore (&dum->lock, flags);
980 driver->unbind (&dum->gadget);
981 dum->gadget.dev.driver = NULL;
983 spin_lock_irqsave (&dum->lock, flags);
985 set_link_state((dum->gadget.speed == USB_SPEED_SUPER ?
986 dum->ss_hcd : dum->hs_hcd));
987 spin_unlock_irqrestore (&dum->lock, flags);
988 usb_hcd_poll_rh_status((dum->gadget.speed == USB_SPEED_SUPER ?
989 dummy_hcd_to_hcd(dum->ss_hcd) :
990 dummy_hcd_to_hcd(dum->hs_hcd)));
996 /* just declare this in any driver that really need it */
997 extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode);
999 int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode)
1003 EXPORT_SYMBOL (net2280_set_fifo_mode);
1006 /* The gadget structure is stored inside the hcd structure and will be
1007 * released along with it. */
1009 dummy_gadget_release (struct device *dev)
1014 static int dummy_udc_probe (struct platform_device *pdev)
1016 struct dummy *dum = &the_controller;
1019 dum->gadget.name = gadget_name;
1020 dum->gadget.ops = &dummy_ops;
1021 dum->gadget.is_dualspeed = 1;
1023 dev_set_name(&dum->gadget.dev, "gadget");
1024 dum->gadget.dev.parent = &pdev->dev;
1025 dum->gadget.dev.release = dummy_gadget_release;
1026 rc = device_register (&dum->gadget.dev);
1028 put_device(&dum->gadget.dev);
1032 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget);
1036 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
1039 platform_set_drvdata(pdev, dum);
1043 usb_del_gadget_udc(&dum->gadget);
1045 device_unregister(&dum->gadget.dev);
1049 static int dummy_udc_remove (struct platform_device *pdev)
1051 struct dummy *dum = platform_get_drvdata (pdev);
1053 usb_del_gadget_udc(&dum->gadget);
1054 platform_set_drvdata (pdev, NULL);
1055 device_remove_file (&dum->gadget.dev, &dev_attr_function);
1056 device_unregister (&dum->gadget.dev);
1060 static int dummy_udc_suspend (struct platform_device *pdev, pm_message_t state)
1062 struct dummy *dum = platform_get_drvdata(pdev);
1064 dev_dbg (&pdev->dev, "%s\n", __func__);
1065 spin_lock_irq (&dum->lock);
1066 dum->udc_suspended = 1;
1067 set_link_state((dum->gadget.speed == USB_SPEED_SUPER ?
1068 dum->ss_hcd : dum->hs_hcd));
1069 spin_unlock_irq (&dum->lock);
1071 usb_hcd_poll_rh_status((dum->gadget.speed == USB_SPEED_SUPER ?
1072 dummy_hcd_to_hcd(dum->ss_hcd) :
1073 dummy_hcd_to_hcd(dum->hs_hcd)));
1077 static int dummy_udc_resume (struct platform_device *pdev)
1079 struct dummy *dum = platform_get_drvdata(pdev);
1081 dev_dbg (&pdev->dev, "%s\n", __func__);
1082 spin_lock_irq (&dum->lock);
1083 dum->udc_suspended = 0;
1084 set_link_state((dum->gadget.speed == USB_SPEED_SUPER ?
1085 dum->ss_hcd : dum->hs_hcd));
1086 spin_unlock_irq (&dum->lock);
1088 usb_hcd_poll_rh_status((dum->gadget.speed == USB_SPEED_SUPER ?
1089 dummy_hcd_to_hcd(dum->ss_hcd) :
1090 dummy_hcd_to_hcd(dum->hs_hcd)));
1094 static struct platform_driver dummy_udc_driver = {
1095 .probe = dummy_udc_probe,
1096 .remove = dummy_udc_remove,
1097 .suspend = dummy_udc_suspend,
1098 .resume = dummy_udc_resume,
1100 .name = (char *) gadget_name,
1101 .owner = THIS_MODULE,
1105 /*-------------------------------------------------------------------------*/
1107 /* MASTER/HOST SIDE DRIVER
1109 * this uses the hcd framework to hook up to host side drivers.
1110 * its root hub will only have one device, otherwise it acts like
1111 * a normal host controller.
1113 * when urbs are queued, they're just stuck on a list that we
1114 * scan in a timer callback. that callback connects writes from
1115 * the host with reads from the device, and so on, based on the
1119 static int dummy_urb_enqueue (
1120 struct usb_hcd *hcd,
1124 struct dummy_hcd *dum_hcd;
1126 unsigned long flags;
1129 if (!urb->transfer_buffer && urb->transfer_buffer_length)
1132 urbp = kmalloc (sizeof *urbp, mem_flags);
1137 dum_hcd = hcd_to_dummy_hcd(hcd);
1138 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1139 rc = usb_hcd_link_urb_to_ep(hcd, urb);
1145 if (!dum_hcd->udev) {
1146 dum_hcd->udev = urb->dev;
1147 usb_get_dev(dum_hcd->udev);
1148 } else if (unlikely(dum_hcd->udev != urb->dev))
1149 dev_err(dummy_dev(dum_hcd), "usb_device address has changed!\n");
1151 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list);
1153 if (usb_pipetype (urb->pipe) == PIPE_CONTROL)
1154 urb->error_count = 1; /* mark as a new urb */
1156 /* kick the scheduler, it'll do the rest */
1157 if (!timer_pending(&dum_hcd->timer))
1158 mod_timer(&dum_hcd->timer, jiffies + 1);
1161 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1165 static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1167 struct dummy_hcd *dum_hcd;
1168 unsigned long flags;
1171 /* giveback happens automatically in timer callback,
1172 * so make sure the callback happens */
1173 dum_hcd = hcd_to_dummy_hcd(hcd);
1174 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1176 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1177 if (!rc && dum_hcd->rh_state != DUMMY_RH_RUNNING &&
1178 !list_empty(&dum_hcd->urbp_list))
1179 mod_timer(&dum_hcd->timer, jiffies);
1181 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1185 /* transfer up to a frame's worth; caller must own lock */
1187 transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit,
1190 struct dummy_request *req;
1193 /* if there's no request queued, the device is NAKing; return */
1194 list_for_each_entry (req, &ep->queue, queue) {
1195 unsigned host_len, dev_len, len;
1196 int is_short, to_host;
1199 /* 1..N packets of ep->ep.maxpacket each ... the last one
1200 * may be short (including zero length).
1202 * writer can send a zlp explicitly (length 0) or implicitly
1203 * (length mod maxpacket zero, and 'zero' flag); they always
1206 host_len = urb->transfer_buffer_length - urb->actual_length;
1207 dev_len = req->req.length - req->req.actual;
1208 len = min (host_len, dev_len);
1210 /* FIXME update emulated data toggle too */
1212 to_host = usb_pipein (urb->pipe);
1213 if (unlikely (len == 0))
1218 /* not enough bandwidth left? */
1219 if (limit < ep->ep.maxpacket && limit < len)
1221 len = min (len, (unsigned) limit);
1225 /* use an extra pass for the final short packet */
1226 if (len > ep->ep.maxpacket) {
1228 len -= (len % ep->ep.maxpacket);
1230 is_short = (len % ep->ep.maxpacket) != 0;
1232 /* else transfer packet(s) */
1233 ubuf = urb->transfer_buffer + urb->actual_length;
1234 rbuf = req->req.buf + req->req.actual;
1236 memcpy (ubuf, rbuf, len);
1238 memcpy (rbuf, ubuf, len);
1239 ep->last_io = jiffies;
1242 urb->actual_length += len;
1243 req->req.actual += len;
1246 /* short packets terminate, maybe with overflow/underflow.
1247 * it's only really an error to write too much.
1249 * partially filling a buffer optionally blocks queue advances
1250 * (so completion handlers can clean up the queue) but we don't
1251 * need to emulate such data-in-flight.
1254 if (host_len == dev_len) {
1255 req->req.status = 0;
1257 } else if (to_host) {
1258 req->req.status = 0;
1259 if (dev_len > host_len)
1260 *status = -EOVERFLOW;
1263 } else if (!to_host) {
1265 if (host_len > dev_len)
1266 req->req.status = -EOVERFLOW;
1268 req->req.status = 0;
1271 /* many requests terminate without a short packet */
1273 if (req->req.length == req->req.actual
1275 req->req.status = 0;
1276 if (urb->transfer_buffer_length == urb->actual_length
1277 && !(urb->transfer_flags
1282 /* device side completion --> continuable */
1283 if (req->req.status != -EINPROGRESS) {
1284 list_del_init (&req->queue);
1286 spin_unlock (&dum->lock);
1287 req->req.complete (&ep->ep, &req->req);
1288 spin_lock (&dum->lock);
1290 /* requests might have been unlinked... */
1294 /* host side completion --> terminate */
1295 if (*status != -EINPROGRESS)
1298 /* rescan to continue with any other queued i/o */
1305 static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1307 int limit = ep->ep.maxpacket;
1309 if (dum->gadget.speed == USB_SPEED_HIGH) {
1312 /* high bandwidth mode */
1313 tmp = le16_to_cpu(ep->desc->wMaxPacketSize);
1314 tmp = (tmp >> 11) & 0x03;
1315 tmp *= 8 /* applies to entire frame */;
1316 limit += limit * tmp;
1318 if (dum->gadget.speed == USB_SPEED_SUPER) {
1319 switch (ep->desc->bmAttributes & 0x03) {
1320 case USB_ENDPOINT_XFER_ISOC:
1321 /* Sec. 4.4.8.2 USB3.0 Spec */
1322 limit = 3 * 16 * 1024 * 8;
1324 case USB_ENDPOINT_XFER_INT:
1325 /* Sec. 4.4.7.2 USB3.0 Spec */
1326 limit = 3 * 1024 * 8;
1328 case USB_ENDPOINT_XFER_BULK:
1336 #define is_active(dum_hcd) ((dum_hcd->port_status & \
1337 (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \
1338 USB_PORT_STAT_SUSPEND)) \
1339 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
1341 static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1345 if (!is_active((dum->gadget.speed == USB_SPEED_SUPER ?
1346 dum->ss_hcd : dum->hs_hcd)))
1348 if ((address & ~USB_DIR_IN) == 0)
1349 return &dum->ep [0];
1350 for (i = 1; i < DUMMY_ENDPOINTS; i++) {
1351 struct dummy_ep *ep = &dum->ep [i];
1355 if (ep->desc->bEndpointAddress == address)
1363 #define Dev_Request (USB_TYPE_STANDARD | USB_RECIP_DEVICE)
1364 #define Dev_InRequest (Dev_Request | USB_DIR_IN)
1365 #define Intf_Request (USB_TYPE_STANDARD | USB_RECIP_INTERFACE)
1366 #define Intf_InRequest (Intf_Request | USB_DIR_IN)
1367 #define Ep_Request (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)
1368 #define Ep_InRequest (Ep_Request | USB_DIR_IN)
1372 * handle_control_request() - handles all control transfers
1373 * @dum: pointer to dummy (the_controller)
1374 * @urb: the urb request to handle
1375 * @setup: pointer to the setup data for a USB device control
1377 * @status: pointer to request handling status
1379 * Return 0 - if the request was handled
1380 * 1 - if the request wasn't handles
1381 * error code on error
1383 static int handle_control_request(struct dummy_hcd *dum_hcd, struct urb *urb,
1384 struct usb_ctrlrequest *setup,
1387 struct dummy_ep *ep2;
1388 struct dummy *dum = dum_hcd->dum;
1393 w_index = le16_to_cpu(setup->wIndex);
1394 w_value = le16_to_cpu(setup->wValue);
1395 switch (setup->bRequest) {
1396 case USB_REQ_SET_ADDRESS:
1397 if (setup->bRequestType != Dev_Request)
1399 dum->address = w_value;
1401 dev_dbg(udc_dev(dum), "set_address = %d\n",
1405 case USB_REQ_SET_FEATURE:
1406 if (setup->bRequestType == Dev_Request) {
1409 case USB_DEVICE_REMOTE_WAKEUP:
1411 case USB_DEVICE_B_HNP_ENABLE:
1412 dum->gadget.b_hnp_enable = 1;
1414 case USB_DEVICE_A_HNP_SUPPORT:
1415 dum->gadget.a_hnp_support = 1;
1417 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1418 dum->gadget.a_alt_hnp_support = 1;
1420 case USB_DEVICE_U1_ENABLE:
1421 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1423 w_value = USB_DEV_STAT_U1_ENABLED;
1425 ret_val = -EOPNOTSUPP;
1427 case USB_DEVICE_U2_ENABLE:
1428 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1430 w_value = USB_DEV_STAT_U2_ENABLED;
1432 ret_val = -EOPNOTSUPP;
1434 case USB_DEVICE_LTM_ENABLE:
1435 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1437 w_value = USB_DEV_STAT_LTM_ENABLED;
1439 ret_val = -EOPNOTSUPP;
1442 ret_val = -EOPNOTSUPP;
1445 dum->devstatus |= (1 << w_value);
1448 } else if (setup->bRequestType == Ep_Request) {
1450 ep2 = find_endpoint(dum, w_index);
1451 if (!ep2 || ep2->ep.name == ep0name) {
1452 ret_val = -EOPNOTSUPP;
1460 case USB_REQ_CLEAR_FEATURE:
1461 if (setup->bRequestType == Dev_Request) {
1464 case USB_DEVICE_REMOTE_WAKEUP:
1465 w_value = USB_DEVICE_REMOTE_WAKEUP;
1467 case USB_DEVICE_U1_ENABLE:
1468 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1470 w_value = USB_DEV_STAT_U1_ENABLED;
1472 ret_val = -EOPNOTSUPP;
1474 case USB_DEVICE_U2_ENABLE:
1475 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1477 w_value = USB_DEV_STAT_U2_ENABLED;
1479 ret_val = -EOPNOTSUPP;
1481 case USB_DEVICE_LTM_ENABLE:
1482 if (dummy_hcd_to_hcd(dum_hcd)->speed ==
1484 w_value = USB_DEV_STAT_LTM_ENABLED;
1486 ret_val = -EOPNOTSUPP;
1489 ret_val = -EOPNOTSUPP;
1493 dum->devstatus &= ~(1 << w_value);
1496 } else if (setup->bRequestType == Ep_Request) {
1498 ep2 = find_endpoint(dum, w_index);
1500 ret_val = -EOPNOTSUPP;
1509 case USB_REQ_GET_STATUS:
1510 if (setup->bRequestType == Dev_InRequest
1511 || setup->bRequestType == Intf_InRequest
1512 || setup->bRequestType == Ep_InRequest) {
1515 * device: remote wakeup, selfpowered
1516 * interface: nothing
1519 buf = (char *)urb->transfer_buffer;
1520 if (urb->transfer_buffer_length > 0) {
1521 if (setup->bRequestType == Ep_InRequest) {
1522 ep2 = find_endpoint(dum, w_index);
1524 ret_val = -EOPNOTSUPP;
1527 buf[0] = ep2->halted;
1528 } else if (setup->bRequestType ==
1530 buf[0] = (u8)dum->devstatus;
1534 if (urb->transfer_buffer_length > 1)
1536 urb->actual_length = min_t(u32, 2,
1537 urb->transfer_buffer_length);
1546 /* drive both sides of the transfers; looks like irq handlers to
1547 * both drivers except the callbacks aren't in_irq().
1549 static void dummy_timer(unsigned long _dum_hcd)
1551 struct dummy_hcd *dum_hcd = (struct dummy_hcd *) _dum_hcd;
1552 struct dummy *dum = dum_hcd->dum;
1553 struct urbp *urbp, *tmp;
1554 unsigned long flags;
1558 /* simplistic model for one frame's bandwidth */
1559 switch (dum->gadget.speed) {
1561 total = 8/*bytes*/ * 12/*packets*/;
1563 case USB_SPEED_FULL:
1564 total = 64/*bytes*/ * 19/*packets*/;
1566 case USB_SPEED_HIGH:
1567 total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/;
1569 case USB_SPEED_SUPER:
1570 /* Bus speed is 500000 bytes/ms, so use a little less */
1574 dev_err(dummy_dev(dum_hcd), "bogus device speed\n");
1578 /* FIXME if HZ != 1000 this will probably misbehave ... */
1580 /* look at each urb queued by the host side driver */
1581 spin_lock_irqsave (&dum->lock, flags);
1583 if (!dum_hcd->udev) {
1584 dev_err(dummy_dev(dum_hcd),
1585 "timer fired with no URBs pending?\n");
1586 spin_unlock_irqrestore (&dum->lock, flags);
1590 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
1593 dum->ep [i].already_seen = 0;
1597 list_for_each_entry_safe(urbp, tmp, &dum_hcd->urbp_list, urbp_list) {
1599 struct dummy_request *req;
1601 struct dummy_ep *ep = NULL;
1603 int status = -EINPROGRESS;
1608 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING)
1610 type = usb_pipetype (urb->pipe);
1612 /* used up this frame's non-periodic bandwidth?
1613 * FIXME there's infinite bandwidth for control and
1614 * periodic transfers ... unrealistic.
1616 if (total <= 0 && type == PIPE_BULK)
1619 /* find the gadget's ep for this request (if configured) */
1620 address = usb_pipeendpoint (urb->pipe);
1621 if (usb_pipein (urb->pipe))
1622 address |= USB_DIR_IN;
1623 ep = find_endpoint(dum, address);
1625 /* set_configuration() disagreement */
1626 dev_dbg(dummy_dev(dum_hcd),
1627 "no ep configured for urb %p\n",
1633 if (ep->already_seen)
1635 ep->already_seen = 1;
1636 if (ep == &dum->ep [0] && urb->error_count) {
1637 ep->setup_stage = 1; /* a new urb */
1638 urb->error_count = 0;
1640 if (ep->halted && !ep->setup_stage) {
1641 /* NOTE: must not be iso! */
1642 dev_dbg(dummy_dev(dum_hcd), "ep %s halted, urb %p\n",
1647 /* FIXME make sure both ends agree on maxpacket */
1649 /* handle control requests */
1650 if (ep == &dum->ep [0] && ep->setup_stage) {
1651 struct usb_ctrlrequest setup;
1654 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1655 /* paranoia, in case of stale queued data */
1656 list_for_each_entry (req, &ep->queue, queue) {
1657 list_del_init (&req->queue);
1658 req->req.status = -EOVERFLOW;
1659 dev_dbg (udc_dev(dum), "stale req = %p\n",
1662 spin_unlock (&dum->lock);
1663 req->req.complete (&ep->ep, &req->req);
1664 spin_lock (&dum->lock);
1665 ep->already_seen = 0;
1669 /* gadget driver never sees set_address or operations
1670 * on standard feature flags. some hardware doesn't
1673 ep->last_io = jiffies;
1674 ep->setup_stage = 0;
1677 value = handle_control_request(dum_hcd, urb, &setup,
1680 /* gadget driver handles all other requests. block
1681 * until setup() returns; no reentrancy issues etc.
1684 spin_unlock (&dum->lock);
1685 value = dum->driver->setup (&dum->gadget,
1687 spin_lock (&dum->lock);
1690 /* no delays (max 64KB data stage) */
1692 goto treat_control_like_bulk;
1694 /* error, see below */
1698 if (value != -EOPNOTSUPP)
1699 dev_dbg (udc_dev(dum),
1703 urb->actual_length = 0;
1709 /* non-control requests */
1711 switch (usb_pipetype (urb->pipe)) {
1712 case PIPE_ISOCHRONOUS:
1713 /* FIXME is it urb->interval since the last xfer?
1714 * use urb->iso_frame_desc[i].
1715 * complete whether or not ep has requests queued.
1716 * report random errors, to debug drivers.
1718 limit = max (limit, periodic_bytes (dum, ep));
1722 case PIPE_INTERRUPT:
1723 /* FIXME is it urb->interval since the last xfer?
1724 * this almost certainly polls too fast.
1726 limit = max (limit, periodic_bytes (dum, ep));
1729 // case PIPE_BULK: case PIPE_CONTROL:
1731 treat_control_like_bulk:
1732 ep->last_io = jiffies;
1733 total = transfer(dum, urb, ep, limit, &status);
1737 /* incomplete transfer? */
1738 if (status == -EINPROGRESS)
1742 list_del (&urbp->urbp_list);
1745 ep->already_seen = ep->setup_stage = 0;
1747 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb);
1748 spin_unlock (&dum->lock);
1749 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status);
1750 spin_lock (&dum->lock);
1755 if (list_empty(&dum_hcd->urbp_list)) {
1756 usb_put_dev(dum_hcd->udev);
1757 dum_hcd->udev = NULL;
1758 } else if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
1759 /* want a 1 msec delay here */
1760 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1));
1763 spin_unlock_irqrestore (&dum->lock, flags);
1766 /*-------------------------------------------------------------------------*/
1768 #define PORT_C_MASK \
1769 ((USB_PORT_STAT_C_CONNECTION \
1770 | USB_PORT_STAT_C_ENABLE \
1771 | USB_PORT_STAT_C_SUSPEND \
1772 | USB_PORT_STAT_C_OVERCURRENT \
1773 | USB_PORT_STAT_C_RESET) << 16)
1775 static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1777 struct dummy_hcd *dum_hcd;
1778 unsigned long flags;
1781 dum_hcd = hcd_to_dummy_hcd(hcd);
1783 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1784 if (!HCD_HW_ACCESSIBLE(hcd))
1787 if (dum_hcd->resuming && time_after_eq(jiffies, dum_hcd->re_timeout)) {
1788 dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1789 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
1790 set_link_state(dum_hcd);
1793 if ((dum_hcd->port_status & PORT_C_MASK) != 0) {
1795 dev_dbg(dummy_dev(dum_hcd), "port status 0x%08x has changes\n",
1796 dum_hcd->port_status);
1798 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED)
1799 usb_hcd_resume_root_hub (hcd);
1802 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1807 ss_hub_descriptor(struct usb_hub_descriptor *desc)
1809 memset(desc, 0, sizeof *desc);
1810 desc->bDescriptorType = 0x2a;
1811 desc->bDescLength = 12;
1812 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1813 desc->bNbrPorts = 1;
1814 desc->u.ss.bHubHdrDecLat = 0x04; /* Worst case: 0.4 micro sec*/
1815 desc->u.ss.DeviceRemovable = 0xffff;
1819 hub_descriptor (struct usb_hub_descriptor *desc)
1821 memset (desc, 0, sizeof *desc);
1822 desc->bDescriptorType = 0x29;
1823 desc->bDescLength = 9;
1824 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1825 desc->bNbrPorts = 1;
1826 desc->u.hs.DeviceRemovable[0] = 0xff;
1827 desc->u.hs.DeviceRemovable[1] = 0xff;
1830 static int dummy_hub_control (
1831 struct usb_hcd *hcd,
1838 struct dummy_hcd *dum_hcd;
1840 unsigned long flags;
1842 if (!HCD_HW_ACCESSIBLE(hcd))
1845 dum_hcd = hcd_to_dummy_hcd(hcd);
1847 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1849 case ClearHubFeature:
1851 case ClearPortFeature:
1853 case USB_PORT_FEAT_SUSPEND:
1854 if (hcd->speed == HCD_USB3) {
1855 dev_dbg(dummy_dev(dum_hcd),
1856 "USB_PORT_FEAT_SUSPEND req not "
1857 "supported for USB 3.0 roothub\n");
1860 if (dum_hcd->port_status & USB_PORT_STAT_SUSPEND) {
1861 /* 20msec resume signaling */
1862 dum_hcd->resuming = 1;
1863 dum_hcd->re_timeout = jiffies +
1864 msecs_to_jiffies(20);
1867 case USB_PORT_FEAT_POWER:
1868 if (hcd->speed == HCD_USB3) {
1869 if (dum_hcd->port_status & USB_PORT_STAT_POWER)
1870 dev_dbg(dummy_dev(dum_hcd),
1873 if (dum_hcd->port_status &
1874 USB_SS_PORT_STAT_POWER)
1875 dev_dbg(dummy_dev(dum_hcd),
1879 dum_hcd->port_status &= ~(1 << wValue);
1880 set_link_state(dum_hcd);
1883 case GetHubDescriptor:
1884 if (hcd->speed == HCD_USB3 &&
1885 (wLength < USB_DT_SS_HUB_SIZE ||
1886 wValue != (USB_DT_SS_HUB << 8))) {
1887 dev_dbg(dummy_dev(dum_hcd),
1888 "Wrong hub descriptor type for "
1889 "USB 3.0 roothub.\n");
1892 if (hcd->speed == HCD_USB3)
1893 ss_hub_descriptor((struct usb_hub_descriptor *) buf);
1895 hub_descriptor((struct usb_hub_descriptor *) buf);
1898 *(__le32 *) buf = cpu_to_le32 (0);
1904 /* whoever resets or resumes must GetPortStatus to
1907 if (dum_hcd->resuming &&
1908 time_after_eq(jiffies, dum_hcd->re_timeout)) {
1909 dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16);
1910 dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND;
1912 if ((dum_hcd->port_status & USB_PORT_STAT_RESET) != 0 &&
1913 time_after_eq(jiffies, dum_hcd->re_timeout)) {
1914 dum_hcd->port_status |= (USB_PORT_STAT_C_RESET << 16);
1915 dum_hcd->port_status &= ~USB_PORT_STAT_RESET;
1916 if (dum_hcd->dum->pullup) {
1917 dum_hcd->port_status |= USB_PORT_STAT_ENABLE;
1919 if (hcd->speed < HCD_USB3) {
1920 switch (dum_hcd->dum->gadget.speed) {
1921 case USB_SPEED_HIGH:
1922 dum_hcd->port_status |=
1923 USB_PORT_STAT_HIGH_SPEED;
1926 dum_hcd->dum->gadget.ep0->
1928 dum_hcd->port_status |=
1929 USB_PORT_STAT_LOW_SPEED;
1932 dum_hcd->dum->gadget.speed =
1939 set_link_state(dum_hcd);
1940 ((__le16 *) buf)[0] = cpu_to_le16 (dum_hcd->port_status);
1941 ((__le16 *) buf)[1] = cpu_to_le16 (dum_hcd->port_status >> 16);
1946 case SetPortFeature:
1948 case USB_PORT_FEAT_LINK_STATE:
1949 if (hcd->speed != HCD_USB3) {
1950 dev_dbg(dummy_dev(dum_hcd),
1951 "USB_PORT_FEAT_LINK_STATE req not "
1952 "supported for USB 2.0 roothub\n");
1956 * Since this is dummy we don't have an actual link so
1957 * there is nothing to do for the SET_LINK_STATE cmd
1960 case USB_PORT_FEAT_U1_TIMEOUT:
1961 case USB_PORT_FEAT_U2_TIMEOUT:
1962 /* TODO: add suspend/resume support! */
1963 if (hcd->speed != HCD_USB3) {
1964 dev_dbg(dummy_dev(dum_hcd),
1965 "USB_PORT_FEAT_U1/2_TIMEOUT req not "
1966 "supported for USB 2.0 roothub\n");
1970 case USB_PORT_FEAT_SUSPEND:
1971 /* Applicable only for USB2.0 hub */
1972 if (hcd->speed == HCD_USB3) {
1973 dev_dbg(dummy_dev(dum_hcd),
1974 "USB_PORT_FEAT_SUSPEND req not "
1975 "supported for USB 3.0 roothub\n");
1978 if (dum_hcd->active) {
1979 dum_hcd->port_status |= USB_PORT_STAT_SUSPEND;
1981 /* HNP would happen here; for now we
1982 * assume b_bus_req is always true.
1984 set_link_state(dum_hcd);
1985 if (((1 << USB_DEVICE_B_HNP_ENABLE)
1986 & dum_hcd->dum->devstatus) != 0)
1987 dev_dbg(dummy_dev(dum_hcd),
1991 case USB_PORT_FEAT_POWER:
1992 if (hcd->speed == HCD_USB3)
1993 dum_hcd->port_status |= USB_SS_PORT_STAT_POWER;
1995 dum_hcd->port_status |= USB_PORT_STAT_POWER;
1996 set_link_state(dum_hcd);
1998 case USB_PORT_FEAT_BH_PORT_RESET:
1999 /* Applicable only for USB3.0 hub */
2000 if (hcd->speed != HCD_USB3) {
2001 dev_dbg(dummy_dev(dum_hcd),
2002 "USB_PORT_FEAT_BH_PORT_RESET req not "
2003 "supported for USB 2.0 roothub\n");
2007 case USB_PORT_FEAT_RESET:
2008 /* if it's already enabled, disable */
2009 if (hcd->speed == HCD_USB3) {
2010 dum_hcd->port_status = 0;
2011 dum_hcd->port_status =
2012 (USB_SS_PORT_STAT_POWER |
2013 USB_PORT_STAT_CONNECTION |
2014 USB_PORT_STAT_RESET);
2016 dum_hcd->port_status &= ~(USB_PORT_STAT_ENABLE
2017 | USB_PORT_STAT_LOW_SPEED
2018 | USB_PORT_STAT_HIGH_SPEED);
2020 * We want to reset device status. All but the
2021 * Self powered feature
2023 dum_hcd->dum->devstatus &=
2024 (1 << USB_DEVICE_SELF_POWERED);
2026 * FIXME USB3.0: what is the correct reset signaling
2027 * interval? Is it still 50msec as for HS?
2029 dum_hcd->re_timeout = jiffies + msecs_to_jiffies(50);
2032 if (hcd->speed == HCD_USB3) {
2033 if ((dum_hcd->port_status &
2034 USB_SS_PORT_STAT_POWER) != 0) {
2035 dum_hcd->port_status |= (1 << wValue);
2036 set_link_state(dum_hcd);
2039 if ((dum_hcd->port_status &
2040 USB_PORT_STAT_POWER) != 0) {
2041 dum_hcd->port_status |= (1 << wValue);
2042 set_link_state(dum_hcd);
2046 case GetPortErrorCount:
2047 if (hcd->speed != HCD_USB3) {
2048 dev_dbg(dummy_dev(dum_hcd),
2049 "GetPortErrorCount req not "
2050 "supported for USB 2.0 roothub\n");
2053 /* We'll always return 0 since this is a dummy hub */
2054 *(__le32 *) buf = cpu_to_le32(0);
2057 if (hcd->speed != HCD_USB3) {
2058 dev_dbg(dummy_dev(dum_hcd),
2059 "SetHubDepth req not supported for "
2060 "USB 2.0 roothub\n");
2065 dev_dbg(dummy_dev(dum_hcd),
2066 "hub control req%04x v%04x i%04x l%d\n",
2067 typeReq, wValue, wIndex, wLength);
2069 /* "protocol stall" on error */
2072 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2074 if ((dum_hcd->port_status & PORT_C_MASK) != 0)
2075 usb_hcd_poll_rh_status (hcd);
2079 static int dummy_bus_suspend (struct usb_hcd *hcd)
2081 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2083 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
2085 spin_lock_irq(&dum_hcd->dum->lock);
2086 dum_hcd->rh_state = DUMMY_RH_SUSPENDED;
2087 set_link_state(dum_hcd);
2088 hcd->state = HC_STATE_SUSPENDED;
2089 spin_unlock_irq(&dum_hcd->dum->lock);
2093 static int dummy_bus_resume (struct usb_hcd *hcd)
2095 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2098 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
2100 spin_lock_irq(&dum_hcd->dum->lock);
2101 if (!HCD_HW_ACCESSIBLE(hcd)) {
2104 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2105 set_link_state(dum_hcd);
2106 if (!list_empty(&dum_hcd->urbp_list))
2107 mod_timer(&dum_hcd->timer, jiffies);
2108 hcd->state = HC_STATE_RUNNING;
2110 spin_unlock_irq(&dum_hcd->dum->lock);
2114 /*-------------------------------------------------------------------------*/
2116 static inline ssize_t
2117 show_urb (char *buf, size_t size, struct urb *urb)
2119 int ep = usb_pipeendpoint (urb->pipe);
2121 return snprintf (buf, size,
2122 "urb/%p %s ep%d%s%s len %d/%d\n",
2125 switch (urb->dev->speed) {
2129 case USB_SPEED_FULL:
2132 case USB_SPEED_HIGH:
2135 case USB_SPEED_SUPER:
2142 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "",
2144 switch (usb_pipetype (urb->pipe)) { \
2145 case PIPE_CONTROL: \
2151 case PIPE_INTERRUPT: \
2158 urb->actual_length, urb->transfer_buffer_length);
2162 show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
2164 struct usb_hcd *hcd = dev_get_drvdata (dev);
2165 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2168 unsigned long flags;
2170 spin_lock_irqsave(&dum_hcd->dum->lock, flags);
2171 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) {
2174 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb);
2178 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2182 static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL);
2184 static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2186 init_timer(&dum_hcd->timer);
2187 dum_hcd->timer.function = dummy_timer;
2188 dum_hcd->timer.data = (unsigned long)dum_hcd;
2189 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2190 INIT_LIST_HEAD(&dum_hcd->urbp_list);
2191 dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET;
2192 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
2193 dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
2194 #ifdef CONFIG_USB_OTG
2195 dummy_hcd_to_hcd(dum_hcd)->self.otg_port = 1;
2199 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
2200 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
2203 static int dummy_start(struct usb_hcd *hcd)
2205 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2208 * MASTER side init ... we emulate a root hub that'll only ever
2209 * talk to one device (the slave side). Also appears in sysfs,
2210 * just like more familiar pci-based HCDs.
2212 if (!usb_hcd_is_primary_hcd(hcd))
2213 return dummy_start_ss(dum_hcd);
2215 spin_lock_init(&dum_hcd->dum->lock);
2216 init_timer(&dum_hcd->timer);
2217 dum_hcd->timer.function = dummy_timer;
2218 dum_hcd->timer.data = (unsigned long)dum_hcd;
2219 dum_hcd->rh_state = DUMMY_RH_RUNNING;
2221 INIT_LIST_HEAD(&dum_hcd->urbp_list);
2223 hcd->power_budget = POWER_BUDGET;
2224 hcd->state = HC_STATE_RUNNING;
2225 hcd->uses_new_polling = 1;
2227 #ifdef CONFIG_USB_OTG
2228 hcd->self.otg_port = 1;
2231 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
2232 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
2235 static void dummy_stop (struct usb_hcd *hcd)
2239 dum = (hcd_to_dummy_hcd(hcd))->dum;
2240 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs);
2241 usb_gadget_unregister_driver(dum->driver);
2242 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n");
2245 /*-------------------------------------------------------------------------*/
2247 static int dummy_h_get_frame (struct usb_hcd *hcd)
2249 return dummy_g_get_frame (NULL);
2252 static int dummy_setup(struct usb_hcd *hcd)
2254 if (usb_hcd_is_primary_hcd(hcd)) {
2255 the_controller.hs_hcd = hcd_to_dummy_hcd(hcd);
2256 the_controller.hs_hcd->dum = &the_controller;
2258 * Mark the first roothub as being USB 2.0.
2259 * The USB 3.0 roothub will be registered later by
2262 hcd->speed = HCD_USB2;
2263 hcd->self.root_hub->speed = USB_SPEED_HIGH;
2265 the_controller.ss_hcd = hcd_to_dummy_hcd(hcd);
2266 the_controller.ss_hcd->dum = &the_controller;
2267 hcd->speed = HCD_USB3;
2268 hcd->self.root_hub->speed = USB_SPEED_SUPER;
2273 /* Change a group of bulk endpoints to support multiple stream IDs */
2274 int dummy_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
2275 struct usb_host_endpoint **eps, unsigned int num_eps,
2276 unsigned int num_streams, gfp_t mem_flags)
2278 if (hcd->speed != HCD_USB3)
2279 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)),
2280 "%s() - ERROR! Not supported for USB2.0 roothub\n",
2285 /* Reverts a group of bulk endpoints back to not using stream IDs. */
2286 int dummy_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
2287 struct usb_host_endpoint **eps, unsigned int num_eps,
2290 if (hcd->speed != HCD_USB3)
2291 dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)),
2292 "%s() - ERROR! Not supported for USB2.0 roothub\n",
2297 static struct hc_driver dummy_hcd = {
2298 .description = (char *) driver_name,
2299 .product_desc = "Dummy host controller",
2300 .hcd_priv_size = sizeof(struct dummy_hcd),
2302 .flags = HCD_USB3 | HCD_SHARED,
2304 .reset = dummy_setup,
2305 .start = dummy_start,
2308 .urb_enqueue = dummy_urb_enqueue,
2309 .urb_dequeue = dummy_urb_dequeue,
2311 .get_frame_number = dummy_h_get_frame,
2313 .hub_status_data = dummy_hub_status,
2314 .hub_control = dummy_hub_control,
2315 .bus_suspend = dummy_bus_suspend,
2316 .bus_resume = dummy_bus_resume,
2318 .alloc_streams = dummy_alloc_streams,
2319 .free_streams = dummy_free_streams,
2322 static int dummy_hcd_probe(struct platform_device *pdev)
2324 struct usb_hcd *hs_hcd;
2325 struct usb_hcd *ss_hcd;
2328 dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc);
2330 if (!mod_data.is_super_speed)
2331 dummy_hcd.flags = HCD_USB2;
2332 hs_hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev));
2337 retval = usb_add_hcd(hs_hcd, 0, 0);
2339 usb_put_hcd(hs_hcd);
2343 if (mod_data.is_super_speed) {
2344 ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev,
2345 dev_name(&pdev->dev), hs_hcd);
2348 goto dealloc_usb2_hcd;
2351 retval = usb_add_hcd(ss_hcd, 0, 0);
2358 usb_put_hcd(ss_hcd);
2360 usb_put_hcd(hs_hcd);
2361 the_controller.hs_hcd = the_controller.ss_hcd = NULL;
2365 static int dummy_hcd_remove(struct platform_device *pdev)
2369 dum = (hcd_to_dummy_hcd(platform_get_drvdata(pdev)))->dum;
2372 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
2373 usb_put_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
2376 usb_remove_hcd(dummy_hcd_to_hcd(dum->hs_hcd));
2377 usb_put_hcd(dummy_hcd_to_hcd(dum->hs_hcd));
2379 the_controller.hs_hcd = NULL;
2380 the_controller.ss_hcd = NULL;
2385 static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
2387 struct usb_hcd *hcd;
2388 struct dummy_hcd *dum_hcd;
2391 dev_dbg (&pdev->dev, "%s\n", __func__);
2393 hcd = platform_get_drvdata (pdev);
2394 dum_hcd = hcd_to_dummy_hcd(hcd);
2395 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
2396 dev_warn(&pdev->dev, "Root hub isn't suspended!\n");
2399 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2403 static int dummy_hcd_resume (struct platform_device *pdev)
2405 struct usb_hcd *hcd;
2407 dev_dbg (&pdev->dev, "%s\n", __func__);
2409 hcd = platform_get_drvdata (pdev);
2410 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2411 usb_hcd_poll_rh_status (hcd);
2415 static struct platform_driver dummy_hcd_driver = {
2416 .probe = dummy_hcd_probe,
2417 .remove = dummy_hcd_remove,
2418 .suspend = dummy_hcd_suspend,
2419 .resume = dummy_hcd_resume,
2421 .name = (char *) driver_name,
2422 .owner = THIS_MODULE,
2426 /*-------------------------------------------------------------------------*/
2428 static struct platform_device *the_udc_pdev;
2429 static struct platform_device *the_hcd_pdev;
2431 static int __init init (void)
2433 int retval = -ENOMEM;
2435 if (usb_disabled ())
2438 the_hcd_pdev = platform_device_alloc(driver_name, -1);
2441 the_udc_pdev = platform_device_alloc(gadget_name, -1);
2445 retval = platform_driver_register(&dummy_hcd_driver);
2447 goto err_register_hcd_driver;
2448 retval = platform_driver_register(&dummy_udc_driver);
2450 goto err_register_udc_driver;
2452 retval = platform_device_add(the_hcd_pdev);
2455 if (!the_controller.hs_hcd ||
2456 (!the_controller.ss_hcd && mod_data.is_super_speed)) {
2458 * The hcd was added successfully but its probe function failed
2464 retval = platform_device_add(the_udc_pdev);
2467 if (!platform_get_drvdata(the_udc_pdev)) {
2469 * The udc was added successfully but its probe function failed
2478 platform_device_del(the_udc_pdev);
2480 platform_device_del(the_hcd_pdev);
2482 platform_driver_unregister(&dummy_udc_driver);
2483 err_register_udc_driver:
2484 platform_driver_unregister(&dummy_hcd_driver);
2485 err_register_hcd_driver:
2486 platform_device_put(the_udc_pdev);
2488 platform_device_put(the_hcd_pdev);
2493 static void __exit cleanup (void)
2495 platform_device_unregister(the_udc_pdev);
2496 platform_device_unregister(the_hcd_pdev);
2497 platform_driver_unregister(&dummy_udc_driver);
2498 platform_driver_unregister(&dummy_hcd_driver);
2500 module_exit (cleanup);