28 #include <linux/module.h>
29 #include <linux/kernel.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
36 #include <linux/list.h>
44 #include <asm/byteorder.h>
47 #include <asm/unaligned.h>
49 #define DRIVER_DESC "USB Host+Gadget Emulator"
50 #define DRIVER_VERSION "02 May 2005"
52 #define POWER_BUDGET 500
55 static const char driver_desc[] =
"USB Host+Gadget Emulator";
57 static const char gadget_name[] =
"dummy_udc";
69 .is_super_speed =
false,
70 .is_high_speed =
true,
97 static inline struct dummy_ep *usb_ep_to_dummy_ep(
struct usb_ep *_ep)
102 static inline struct dummy_request *usb_request_to_dummy_request
124 static const char ep0name[] =
"ep0";
126 static const char *
const ep_name[] = {
130 "ep-a",
"ep-b",
"ep-c",
"ep-d",
"ep-e",
"ep-f",
133 "ep1in-bulk",
"ep2out-bulk",
"ep3in-iso",
"ep4out-iso",
"ep5in-int",
134 "ep6in-bulk",
"ep7out-bulk",
"ep8in-iso",
"ep9out-iso",
"ep10in-int",
135 "ep11in-bulk",
"ep12out-bulk",
"ep13in-iso",
"ep14out-iso",
139 "ep1out-bulk",
"ep2in-bulk",
141 #define DUMMY_ENDPOINTS ARRAY_SIZE(ep_name)
202 static inline struct dummy_hcd *hcd_to_dummy_hcd(
struct usb_hcd *hcd)
204 return (
struct dummy_hcd *) (hcd->hcd_priv);
207 static inline struct usb_hcd *dummy_hcd_to_hcd(
struct dummy_hcd *dum)
209 return container_of((
void *) dum,
struct usb_hcd, hcd_priv);
214 return dummy_hcd_to_hcd(dum)->self.controller;
217 static inline struct device *udc_dev(
struct dummy *dum)
219 return dum->
gadget.dev.parent;
236 static inline struct dummy *gadget_dev_to_dummy(
struct device *
dev)
250 while (!list_empty(&ep->
queue)) {
254 list_del_init(&req->
queue);
257 spin_unlock(&dum->
lock);
258 req->
req.complete(&ep->
ep, &req->
req);
259 spin_lock(&dum->
lock);
264 static void stop_activity(
struct dummy *dum)
290 struct dummy *dum = dum_hcd->dum;
292 if (dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3) {
294 dum_hcd->port_status = 0;
299 if ((dum_hcd->old_status &
301 dum_hcd->port_status |=
307 if ((dum_hcd->old_status &
309 dum_hcd->port_status |=
311 if ((dum_hcd->port_status &
313 (dum_hcd->port_status &
320 dum_hcd->port_status = 0;
328 if ((dum_hcd->old_status &
330 dum_hcd->port_status |=
334 if ((dum_hcd->old_status &
336 dum_hcd->port_status |=
340 else if ((dum_hcd->port_status &
349 static void set_link_state(
struct dummy_hcd *dum_hcd)
355 if ((dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3 &&
357 (dummy_hcd_to_hcd(dum_hcd)->speed != HCD_USB3 &&
361 set_link_state_by_speed(dum_hcd);
378 spin_unlock(&dum->
lock);
380 spin_lock(&dum->
lock);
384 spin_unlock(&dum->
lock);
386 spin_lock(&dum->
lock);
388 spin_unlock(&dum->
lock);
390 spin_lock(&dum->
lock);
407 #define is_enabled(dum) \
408 (dum->port_status & USB_PORT_STAT_ENABLE)
410 static int dummy_enable(
struct usb_ep *_ep,
419 ep = usb_ep_to_dummy_ep(_ep);
420 if (!_ep || !desc || ep->
desc || _ep->
name == ep0name
423 dum = ep_to_dummy(ep);
427 dum_hcd = gadget_to_dummy_hcd(&dum->
gadget);
436 max = usb_endpoint_maxp(desc) & 0x7ff;
447 switch (usb_endpoint_type(desc)) {
453 switch (dum->
gadget.speed) {
463 if (max == 8 || max == 16 || max == 32 || max == 64)
475 switch (dum->
gadget.speed) {
496 switch (dum->
gadget.speed) {
516 if (usb_ss_max_streams(_ep->
comp_desc)) {
517 if (!usb_endpoint_xfer_bulk(desc)) {
518 dev_err(udc_dev(dum),
"Can't enable stream support on "
519 "non-bulk ep %s\n", _ep->
name);
526 dev_dbg(udc_dev(dum),
"enabled %s (ep%d%s-%s) maxpacket %d stream %s\n",
531 switch (usb_endpoint_type(desc)) {
545 max, ep->stream_en ?
"enabled" :
"disabled");
550 ep->halted = ep->wedged = 0;
556 static int dummy_disable(
struct usb_ep *_ep)
563 ep = usb_ep_to_dummy_ep(_ep);
564 if (!_ep || !ep->
desc || _ep->
name == ep0name)
566 dum = ep_to_dummy(ep);
573 spin_unlock_irqrestore(&dum->
lock, flags);
587 ep = usb_ep_to_dummy_ep(_ep);
589 req = kzalloc(
sizeof(*req), mem_flags);
592 INIT_LIST_HEAD(&req->
queue);
605 req = usb_request_to_dummy_request(_req);
623 req = usb_request_to_dummy_request(_req);
627 ep = usb_ep_to_dummy_ep(_ep);
628 if (!_ep || (!ep->
desc && _ep->
name != ep0name))
631 dum = ep_to_dummy(ep);
632 dum_hcd = gadget_to_dummy_hcd(&dum->
gadget);
637 dev_dbg(udc_dev(dum),
"ep %p queue req %p to %s, len %d buf %p\n",
647 list_empty(&ep->
queue) &&
654 req->
req.complete = fifo_complete;
657 spin_unlock(&dum->
lock);
661 spin_lock(&dum->
lock);
664 spin_unlock_irqrestore(&dum->
lock, flags);
682 ep = usb_ep_to_dummy_ep(_ep);
683 dum = ep_to_dummy(ep);
689 spin_lock(&dum->
lock);
691 if (&req->
req == _req) {
692 list_del_init(&req->
queue);
698 spin_unlock(&dum->
lock);
702 "dequeued req %p from %s, len %d buf %p\n",
711 dummy_set_halt_and_wedge(
struct usb_ep *_ep,
int value,
int wedged)
718 ep = usb_ep_to_dummy_ep(_ep);
719 dum = ep_to_dummy(ep);
725 !list_empty(&ep->
queue))
737 dummy_set_halt(
struct usb_ep *_ep,
int value)
739 return dummy_set_halt_and_wedge(_ep, value, 0);
742 static int dummy_set_wedge(
struct usb_ep *_ep)
744 if (!_ep || _ep->
name == ep0name)
746 return dummy_set_halt_and_wedge(_ep, 1, 1);
749 static const struct usb_ep_ops dummy_ep_ops = {
750 .enable = dummy_enable,
751 .disable = dummy_disable,
753 .alloc_request = dummy_alloc_request,
754 .free_request = dummy_free_request,
756 .queue = dummy_queue,
757 .dequeue = dummy_dequeue,
759 .set_halt = dummy_set_halt,
760 .set_wedge = dummy_set_wedge,
766 static int dummy_g_get_frame(
struct usb_gadget *_gadget)
771 return tv.tv_usec / 1000;
774 static int dummy_wakeup(
struct usb_gadget *_gadget)
778 dum_hcd = gadget_to_dummy_hcd(_gadget);
797 static int dummy_set_selfpowered(
struct usb_gadget *_gadget,
int value)
801 dum = gadget_to_dummy_hcd(_gadget)->dum;
809 static void dummy_udc_update_ep0(
struct dummy *dum)
812 dum->
ep[0].ep.maxpacket = 9;
814 dum->
ep[0].ep.maxpacket = 64;
817 static int dummy_pullup(
struct usb_gadget *_gadget,
int value)
823 dum = gadget_dev_to_dummy(&_gadget->
dev);
825 if (value && dum->
driver) {
833 dummy_udc_update_ep0(dum);
836 dev_dbg(udc_dev(dum),
"This device can perform faster"
837 " if you connect it to a %s port...\n",
840 dum_hcd = gadget_to_dummy_hcd(_gadget);
843 dum->
pullup = (value != 0);
844 set_link_state(dum_hcd);
845 spin_unlock_irqrestore(&dum->
lock, flags);
851 static int dummy_udc_start(
struct usb_gadget *g,
853 static int dummy_udc_stop(
struct usb_gadget *g,
857 .get_frame = dummy_g_get_frame,
858 .wakeup = dummy_wakeup,
859 .set_selfpowered = dummy_set_selfpowered,
860 .pullup = dummy_pullup,
861 .udc_start = dummy_udc_start,
862 .udc_stop = dummy_udc_stop,
871 struct dummy *dum = gadget_dev_to_dummy(dev);
895 static int dummy_udc_start(
struct usb_gadget *g,
898 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
913 dev_dbg(udc_dev(dum),
"binding gadget driver '%s'\n",
918 static int dummy_udc_stop(
struct usb_gadget *g,
921 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
924 dev_dbg(udc_dev(dum),
"unregister gadget driver '%s'\n",
937 static void dummy_gadget_release(
struct device *dev)
942 static void init_dummy_udc_hw(
struct dummy *dum)
946 INIT_LIST_HEAD(&dum->
gadget.ep_list);
952 ep->
ep.name = ep_name[
i];
953 ep->
ep.ops = &dummy_ep_ops;
957 ep->
ep.maxpacket = ~0;
958 ep->
ep.max_streams = 16;
962 INIT_LIST_HEAD(&ep->
queue);
966 list_del_init(&dum->
ep[0].ep.ep_list);
967 INIT_LIST_HEAD(&dum->
fifo_req.queue);
969 #ifdef CONFIG_USB_OTG
979 dum->
gadget.name = gadget_name;
980 dum->
gadget.ops = &dummy_ops;
985 dum->
gadget.dev.release = dummy_gadget_release;
992 init_dummy_udc_hw(dum);
1001 platform_set_drvdata(pdev, dum);
1013 struct dummy *dum = platform_get_drvdata(pdev);
1016 platform_set_drvdata(pdev,
NULL);
1022 static void dummy_udc_pm(
struct dummy *dum,
struct dummy_hcd *dum_hcd,
1025 spin_lock_irq(&dum->
lock);
1027 set_link_state(dum_hcd);
1028 spin_unlock_irq(&dum->
lock);
1033 struct dummy *dum = platform_get_drvdata(pdev);
1037 dummy_udc_pm(dum, dum_hcd, 1);
1044 struct dummy *dum = platform_get_drvdata(pdev);
1048 dummy_udc_pm(dum, dum_hcd, 0);
1054 .probe = dummy_udc_probe,
1055 .remove = dummy_udc_remove,
1056 .suspend = dummy_udc_suspend,
1057 .resume = dummy_udc_resume,
1059 .name = (
char *) gadget_name,
1070 index = usb_endpoint_num(desc) << 1;
1071 if (usb_endpoint_dir_in(desc))
1088 static int dummy_ep_stream_en(
struct dummy_hcd *dum_hcd,
struct urb *
urb)
1093 if (!usb_endpoint_xfer_bulk(desc))
1096 index = dummy_get_ep_idx(desc);
1107 static int get_max_streams_for_pipe(
struct dummy_hcd *dum_hcd,
1112 max_streams = dum_hcd->
num_stream[usb_pipeendpoint(pipe)];
1113 if (usb_pipeout(pipe))
1121 static void set_max_streams_for_pipe(
struct dummy_hcd *dum_hcd,
1122 unsigned int pipe,
unsigned int streams)
1127 max_streams = dum_hcd->
num_stream[usb_pipeendpoint(pipe)];
1128 if (usb_pipeout(pipe)) {
1132 max_streams &= 0xf0;
1135 dum_hcd->
num_stream[usb_pipeendpoint(pipe)] = max_streams;
1138 static int dummy_validate_stream(
struct dummy_hcd *dum_hcd,
struct urb *urb)
1140 unsigned int max_streams;
1143 enabled = dummy_ep_stream_en(dum_hcd, urb);
1144 if (!urb->stream_id) {
1152 max_streams = get_max_streams_for_pipe(dum_hcd,
1153 usb_pipeendpoint(urb->pipe));
1154 if (urb->stream_id > max_streams) {
1155 dev_err(dummy_dev(dum_hcd),
"Stream id %d is out of range.\n",
1163 static int dummy_urb_enqueue(
1164 struct usb_hcd *hcd,
1170 unsigned long flags;
1173 urbp =
kmalloc(
sizeof *urbp, mem_flags);
1179 dum_hcd = hcd_to_dummy_hcd(hcd);
1182 rc = dummy_validate_stream(dum_hcd, urb);
1194 if (!dum_hcd->
udev) {
1195 dum_hcd->
udev = urb->dev;
1198 dev_err(dummy_dev(dum_hcd),
"usb_device address has changed!\n");
1202 if (usb_pipetype(urb->pipe) == PIPE_CONTROL)
1203 urb->error_count = 1;
1206 if (!timer_pending(&dum_hcd->
timer))
1210 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
1214 static int dummy_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
1217 unsigned long flags;
1222 dum_hcd = hcd_to_dummy_hcd(hcd);
1230 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
1234 static int dummy_perform_transfer(
struct urb *urb,
struct dummy_request *req,
1238 struct urbp *urbp = urb->hcpriv;
1245 to_host = usb_pipein(urb->pipe);
1246 rbuf = req->
req.buf + req->
req.actual;
1248 if (!urb->num_sgs) {
1249 ubuf = urb->transfer_buffer + urb->actual_length;
1269 if (next_sg ==
false) {
1280 memcpy(ubuf, rbuf, this_sg);
1282 memcpy(rbuf, ubuf, this_sg);
1288 if (next_sg ==
false) {
1301 static int transfer(
struct dummy_hcd *dum_hcd,
struct urb *urb,
1310 unsigned host_len, dev_len, len;
1311 int is_short, to_host;
1314 if (dummy_ep_stream_en(dum_hcd, urb)) {
1315 if ((urb->stream_id != req->
req.stream_id))
1326 host_len = urb->transfer_buffer_length - urb->actual_length;
1327 dev_len = req->
req.length - req->
req.actual;
1328 len =
min(host_len, dev_len);
1332 to_host = usb_pipein(urb->pipe);
1337 if (limit < ep->ep.maxpacket && limit < len)
1339 len =
min_t(
unsigned, len, limit);
1344 if (len > ep->
ep.maxpacket) {
1346 len -= (len % ep->
ep.maxpacket);
1348 is_short = (len % ep->
ep.maxpacket) != 0;
1350 len = dummy_perform_transfer(urb, req, len);
1354 req->
req.status = len;
1357 urb->actual_length += len;
1358 req->
req.actual += len;
1370 if (host_len == dev_len) {
1371 req->
req.status = 0;
1373 }
else if (to_host) {
1374 req->
req.status = 0;
1375 if (dev_len > host_len)
1379 }
else if (!to_host) {
1381 if (host_len > dev_len)
1384 req->
req.status = 0;
1389 if (req->
req.length == req->
req.actual
1391 req->
req.status = 0;
1392 if (urb->transfer_buffer_length == urb->actual_length
1393 && !(urb->transfer_flags
1400 list_del_init(&req->
queue);
1402 spin_unlock(&dum->
lock);
1403 req->
req.complete(&ep->
ep, &req->
req);
1404 spin_lock(&dum->
lock);
1421 static int periodic_bytes(
struct dummy *dum,
struct dummy_ep *ep)
1423 int limit = ep->
ep.maxpacket;
1429 tmp = usb_endpoint_maxp(ep->
desc);
1430 tmp = (tmp >> 11) & 0x03;
1432 limit += limit *
tmp;
1435 switch (usb_endpoint_type(ep->
desc)) {
1438 limit = 3 * 16 * 1024 * 8;
1442 limit = 3 * 1024 * 8;
1452 #define is_active(dum_hcd) ((dum_hcd->port_status & \
1453 (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \
1454 USB_PORT_STAT_SUSPEND)) \
1455 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
1471 if (ep->
desc->bEndpointAddress == address)
1479 #define Dev_Request (USB_TYPE_STANDARD | USB_RECIP_DEVICE)
1480 #define Dev_InRequest (Dev_Request | USB_DIR_IN)
1481 #define Intf_Request (USB_TYPE_STANDARD | USB_RECIP_INTERFACE)
1482 #define Intf_InRequest (Intf_Request | USB_DIR_IN)
1483 #define Ep_Request (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)
1484 #define Ep_InRequest (Ep_Request | USB_DIR_IN)
1499 static int handle_control_request(
struct dummy_hcd *dum_hcd,
struct urb *urb,
1517 dev_dbg(udc_dev(dum),
"set_address = %d\n",
1528 dum->
gadget.b_hnp_enable = 1;
1531 dum->
gadget.a_hnp_support = 1;
1534 dum->
gadget.a_alt_hnp_support = 1;
1537 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1544 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1551 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1566 ep2 = find_endpoint(dum, w_index);
1567 if (!ep2 || ep2->
ep.name == ep0name) {
1584 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1591 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1598 if (dummy_hcd_to_hcd(dum_hcd)->
speed ==
1614 ep2 = find_endpoint(dum, w_index);
1635 buf = (
char *)urb->transfer_buffer;
1636 if (urb->transfer_buffer_length > 0) {
1638 ep2 = find_endpoint(dum, w_index);
1650 if (urb->transfer_buffer_length > 1)
1653 urb->transfer_buffer_length);
1665 static void dummy_timer(
unsigned long _dum_hcd)
1669 struct urbp *urbp, *
tmp;
1670 unsigned long flags;
1675 switch (dum->
gadget.speed) {
1683 total = 512 * 13 * 8;
1690 dev_err(dummy_dev(dum_hcd),
"bogus device speed\n");
1699 if (!dum_hcd->
udev) {
1701 "timer fired with no URBs pending?\n");
1702 spin_unlock_irqrestore(&dum->
lock, flags);
1709 dum->
ep[
i].already_seen = 0;
1726 type = usb_pipetype(urb->pipe);
1732 if (total <= 0 && type == PIPE_BULK)
1736 address = usb_pipeendpoint (urb->pipe);
1737 if (usb_pipein(urb->pipe))
1739 ep = find_endpoint(dum, address);
1743 "no ep configured for urb %p\n",
1752 if (ep == &dum->
ep[0] && urb->error_count) {
1754 urb->error_count = 0;
1758 dev_dbg(dummy_dev(dum_hcd),
"ep %s halted, urb %p\n",
1773 list_del_init(&req->
queue);
1775 dev_dbg(udc_dev(dum),
"stale req = %p\n",
1778 spin_unlock(&dum->
lock);
1779 req->
req.complete(&ep->
ep, &req->
req);
1780 spin_lock(&dum->
lock);
1793 value = handle_control_request(dum_hcd, urb, &
setup,
1800 spin_unlock(&dum->
lock);
1803 spin_lock(&dum->
lock);
1808 goto treat_control_like_bulk;
1819 urb->actual_length = 0;
1827 switch (usb_pipetype(urb->pipe)) {
1828 case PIPE_ISOCHRONOUS:
1834 limit =
max(limit, periodic_bytes(dum, ep));
1838 case PIPE_INTERRUPT:
1842 limit =
max(limit, periodic_bytes(dum, ep));
1846 treat_control_like_bulk:
1848 total = transfer(dum_hcd, urb, ep, limit, &status);
1863 spin_unlock(&dum->
lock);
1865 spin_lock(&dum->
lock);
1878 spin_unlock_irqrestore(&dum->
lock, flags);
1883 #define PORT_C_MASK \
1884 ((USB_PORT_STAT_C_CONNECTION \
1885 | USB_PORT_STAT_C_ENABLE \
1886 | USB_PORT_STAT_C_SUSPEND \
1887 | USB_PORT_STAT_C_OVERCURRENT \
1888 | USB_PORT_STAT_C_RESET) << 16)
1890 static int dummy_hub_status(
struct usb_hcd *hcd,
char *buf)
1893 unsigned long flags;
1896 dum_hcd = hcd_to_dummy_hcd(hcd);
1899 if (!HCD_HW_ACCESSIBLE(hcd))
1905 set_link_state(dum_hcd);
1910 dev_dbg(dummy_dev(dum_hcd),
"port status 0x%08x has changes\n",
1914 usb_hcd_resume_root_hub(hcd);
1917 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
1930 .wTotalLength =
cpu_to_le16(
sizeof(usb3_bos_desc)),
1931 .bNumDeviceCaps = 1,
1945 memset(desc, 0,
sizeof *desc);
1956 memset(desc, 0,
sizeof *desc);
1965 static int dummy_hub_control(
1966 struct usb_hcd *hcd,
1975 unsigned long flags;
1977 if (!HCD_HW_ACCESSIBLE(hcd))
1980 dum_hcd = hcd_to_dummy_hcd(hcd);
1984 case ClearHubFeature:
1986 case ClearPortFeature:
1989 if (hcd->speed == HCD_USB3) {
1991 "USB_PORT_FEAT_SUSPEND req not "
1992 "supported for USB 3.0 roothub\n");
2003 if (hcd->speed == HCD_USB3) {
2015 set_link_state(dum_hcd);
2018 case GetHubDescriptor:
2019 if (hcd->speed == HCD_USB3 &&
2023 "Wrong hub descriptor type for "
2024 "USB 3.0 roothub.\n");
2027 if (hcd->speed == HCD_USB3)
2034 if (hcd->speed != HCD_USB3)
2040 memcpy(buf, &usb3_bos_desc,
sizeof(usb3_bos_desc));
2063 if (dum_hcd->
dum->pullup) {
2066 if (hcd->speed < HCD_USB3) {
2067 switch (dum_hcd->
dum->gadget.speed) {
2073 dum_hcd->
dum->gadget.ep0->
2079 dum_hcd->
dum->gadget.speed =
2086 set_link_state(dum_hcd);
2093 case SetPortFeature:
2096 if (hcd->speed != HCD_USB3) {
2098 "USB_PORT_FEAT_LINK_STATE req not "
2099 "supported for USB 2.0 roothub\n");
2110 if (hcd->speed != HCD_USB3) {
2112 "USB_PORT_FEAT_U1/2_TIMEOUT req not "
2113 "supported for USB 2.0 roothub\n");
2119 if (hcd->speed == HCD_USB3) {
2121 "USB_PORT_FEAT_SUSPEND req not "
2122 "supported for USB 3.0 roothub\n");
2131 set_link_state(dum_hcd);
2133 & dum_hcd->
dum->devstatus) != 0)
2139 if (hcd->speed == HCD_USB3)
2143 set_link_state(dum_hcd);
2147 if (hcd->speed != HCD_USB3) {
2149 "USB_PORT_FEAT_BH_PORT_RESET req not "
2150 "supported for USB 2.0 roothub\n");
2156 if (hcd->speed == HCD_USB3) {
2170 dum_hcd->
dum->devstatus &=
2179 if (hcd->speed == HCD_USB3) {
2183 set_link_state(dum_hcd);
2189 set_link_state(dum_hcd);
2193 case GetPortErrorCount:
2194 if (hcd->speed != HCD_USB3) {
2196 "GetPortErrorCount req not "
2197 "supported for USB 2.0 roothub\n");
2204 if (hcd->speed != HCD_USB3) {
2206 "SetHubDepth req not supported for "
2207 "USB 2.0 roothub\n");
2213 "hub control req%04x v%04x i%04x l%d\n",
2214 typeReq, wValue, wIndex, wLength);
2219 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
2226 static int dummy_bus_suspend(
struct usb_hcd *hcd)
2228 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2230 dev_dbg(&hcd->self.root_hub->dev,
"%s\n", __func__);
2232 spin_lock_irq(&dum_hcd->
dum->lock);
2234 set_link_state(dum_hcd);
2235 hcd->state = HC_STATE_SUSPENDED;
2236 spin_unlock_irq(&dum_hcd->
dum->lock);
2240 static int dummy_bus_resume(
struct usb_hcd *hcd)
2242 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2245 dev_dbg(&hcd->self.root_hub->dev,
"%s\n", __func__);
2247 spin_lock_irq(&dum_hcd->
dum->lock);
2248 if (!HCD_HW_ACCESSIBLE(hcd)) {
2252 set_link_state(dum_hcd);
2255 hcd->state = HC_STATE_RUNNING;
2257 spin_unlock_irq(&dum_hcd->
dum->lock);
2263 static inline ssize_t show_urb(
char *buf,
size_t size,
struct urb *urb)
2265 int ep = usb_pipeendpoint(urb->pipe);
2268 "urb/%p %s ep%d%s%s len %d/%d\n",
2271 switch (urb->dev->speed) {
2288 ep, ep ? (usb_pipein(urb->pipe) ?
"in" :
"out") :
"",
2290 switch (usb_pipetype(urb->pipe)) { \
2291 case PIPE_CONTROL: \
2297 case PIPE_INTERRUPT: \
2304 urb->actual_length, urb->transfer_buffer_length);
2311 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2314 unsigned long flags;
2324 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
2330 static int dummy_start_ss(
struct dummy_hcd *dum_hcd)
2333 dum_hcd->
timer.function = dummy_timer;
2334 dum_hcd->
timer.data = (
unsigned long)dum_hcd;
2338 dummy_hcd_to_hcd(dum_hcd)->power_budget =
POWER_BUDGET;
2339 dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING;
2340 dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1;
2341 #ifdef CONFIG_USB_OTG
2342 dummy_hcd_to_hcd(dum_hcd)->self.otg_port = 1;
2350 static int dummy_start(
struct usb_hcd *hcd)
2352 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2360 return dummy_start_ss(dum_hcd);
2364 dum_hcd->
timer.function = dummy_timer;
2365 dum_hcd->
timer.data = (
unsigned long)dum_hcd;
2371 hcd->state = HC_STATE_RUNNING;
2372 hcd->uses_new_polling = 1;
2374 #ifdef CONFIG_USB_OTG
2375 hcd->self.otg_port = 1;
2382 static void dummy_stop(
struct usb_hcd *hcd)
2386 dum = hcd_to_dummy_hcd(hcd)->dum;
2389 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)),
"stopped\n");
2394 static int dummy_h_get_frame(
struct usb_hcd *hcd)
2396 return dummy_g_get_frame(
NULL);
2399 static int dummy_setup(
struct usb_hcd *hcd)
2401 hcd->self.sg_tablesize = ~0;
2410 hcd->speed = HCD_USB2;
2415 hcd->speed = HCD_USB3;
2422 static int dummy_alloc_streams(
struct usb_hcd *hcd,
struct usb_device *
udev,
2423 struct usb_host_endpoint **eps,
unsigned int num_eps,
2424 unsigned int num_streams,
gfp_t mem_flags)
2426 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2427 unsigned long flags;
2429 int ret_streams = num_streams;
2437 for (i = 0; i < num_eps; i++) {
2438 index = dummy_get_ep_idx(&eps[i]->desc);
2443 max_stream = usb_ss_max_streams(&eps[i]->ss_ep_comp);
2448 if (max_stream < ret_streams) {
2449 dev_dbg(dummy_dev(dum_hcd),
"Ep 0x%x only supports %u "
2453 ret_streams = max_stream;
2457 for (i = 0; i < num_eps; i++) {
2458 index = dummy_get_ep_idx(&eps[i]->desc);
2460 set_max_streams_for_pipe(dum_hcd,
2461 usb_endpoint_num(&eps[i]->desc), ret_streams);
2464 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
2469 static int dummy_free_streams(
struct usb_hcd *hcd,
struct usb_device *udev,
2470 struct usb_host_endpoint **eps,
unsigned int num_eps,
2473 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2474 unsigned long flags;
2480 for (i = 0; i < num_eps; i++) {
2481 index = dummy_get_ep_idx(&eps[i]->desc);
2488 for (i = 0; i < num_eps; i++) {
2489 index = dummy_get_ep_idx(&eps[i]->desc);
2491 set_max_streams_for_pipe(dum_hcd,
2492 usb_endpoint_num(&eps[i]->desc), 0);
2496 spin_unlock_irqrestore(&dum_hcd->
dum->lock, flags);
2502 .product_desc =
"Dummy host controller",
2503 .hcd_priv_size =
sizeof(
struct dummy_hcd),
2505 .flags = HCD_USB3 | HCD_SHARED,
2507 .reset = dummy_setup,
2508 .start = dummy_start,
2511 .urb_enqueue = dummy_urb_enqueue,
2512 .urb_dequeue = dummy_urb_dequeue,
2514 .get_frame_number = dummy_h_get_frame,
2516 .hub_status_data = dummy_hub_status,
2517 .hub_control = dummy_hub_control,
2518 .bus_suspend = dummy_bus_suspend,
2519 .bus_resume = dummy_bus_resume,
2521 .alloc_streams = dummy_alloc_streams,
2522 .free_streams = dummy_free_streams,
2527 struct usb_hcd *hs_hcd;
2528 struct usb_hcd *ss_hcd;
2534 dummy_hcd.flags = HCD_USB2;
2546 dev_name(&pdev->
dev), hs_hcd);
2549 goto dealloc_usb2_hcd;
2572 dum = hcd_to_dummy_hcd(platform_get_drvdata(pdev))->dum;
2590 struct usb_hcd *hcd;
2591 struct dummy_hcd *dum_hcd;
2596 hcd = platform_get_drvdata(pdev);
2597 dum_hcd = hcd_to_dummy_hcd(hcd);
2599 dev_warn(&pdev->
dev,
"Root hub isn't suspended!\n");
2602 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2608 struct usb_hcd *hcd;
2612 hcd = platform_get_drvdata(pdev);
2613 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2619 .probe = dummy_hcd_probe,
2620 .remove = dummy_hcd_remove,
2621 .suspend = dummy_hcd_suspend,
2622 .resume = dummy_hcd_resume,
2653 goto err_register_hcd_driver;
2656 goto err_register_udc_driver;
2673 if (!platform_get_drvdata(the_udc_pdev)) {
2689 err_register_udc_driver:
2691 err_register_hcd_driver:
2699 static void __exit cleanup(
void)