Commit ee89bcd3f109346078aad67909dbc6e9ad7bf9ba
Committed by
Sekhar Nori
1 parent
c385ca68a9
Exists in
ti-linux-3.14.y
and in
2 other branches
usb: dwc3: Add seperate dwc3_gadget object to support gadget release
With the current implementation it's impossible to release the gadget. Add a separate dwc3_gadget object to dwc3 structure so that the same can be freed during the gadget release. This is in prepration to adapt dwc3 gadget driver to drd library. DRD library uses usb_del/add_gadget_udc while switching roles between HOST and DEVICE modes. If the usb_gadget is not released during usb_del_gadget_udc, the subsequent usb_add_gadget_udc would try to initialize an already initialized kobject. To avoid this make sure we have an easily freeable object. Signed-off-by: George Cherian <george.cherian@ti.com> Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Showing 4 changed files with 96 additions and 50 deletions Side-by-side Diff
drivers/usb/dwc3/core.h
... | ... | @@ -600,6 +600,11 @@ |
600 | 600 | __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS]; |
601 | 601 | }; |
602 | 602 | |
603 | +struct dwc3_gadget { | |
604 | + struct usb_gadget gadget; | |
605 | + struct dwc3 *dwc; | |
606 | +}; | |
607 | + | |
603 | 608 | /** |
604 | 609 | * struct dwc3 - representation of our controller |
605 | 610 | * @ctrl_req: usb control request which is used for ep0 |
... | ... | @@ -686,7 +691,7 @@ |
686 | 691 | struct dwc3_event_buffer **ev_buffs; |
687 | 692 | struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; |
688 | 693 | |
689 | - struct usb_gadget gadget; | |
694 | + struct dwc3_gadget *dwc_gadget; | |
690 | 695 | struct usb_gadget_driver *gadget_driver; |
691 | 696 | |
692 | 697 | struct usb_phy *usb2_phy; |
drivers/usb/dwc3/ep0.c
... | ... | @@ -105,6 +105,7 @@ |
105 | 105 | struct dwc3_request *req) |
106 | 106 | { |
107 | 107 | struct dwc3 *dwc = dep->dwc; |
108 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
108 | 109 | |
109 | 110 | req->request.actual = 0; |
110 | 111 | req->request.status = -EINPROGRESS; |
... | ... | @@ -148,7 +149,7 @@ |
148 | 149 | |
149 | 150 | direction = !dwc->ep0_expect_in; |
150 | 151 | dwc->delayed_status = false; |
151 | - usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED); | |
152 | + usb_gadget_set_state(&dwc_gadget->gadget, USB_STATE_CONFIGURED); | |
152 | 153 | |
153 | 154 | if (dwc->ep0state == EP0_STATUS_PHASE) |
154 | 155 | __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); |
... | ... | @@ -384,6 +385,7 @@ |
384 | 385 | struct usb_ctrlrequest *ctrl, int set) |
385 | 386 | { |
386 | 387 | struct dwc3_ep *dep; |
388 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
387 | 389 | u32 recip; |
388 | 390 | u32 wValue; |
389 | 391 | u32 wIndex; |
... | ... | @@ -394,7 +396,7 @@ |
394 | 396 | wValue = le16_to_cpu(ctrl->wValue); |
395 | 397 | wIndex = le16_to_cpu(ctrl->wIndex); |
396 | 398 | recip = ctrl->bRequestType & USB_RECIP_MASK; |
397 | - state = dwc->gadget.state; | |
399 | + state = dwc_gadget->gadget.state; | |
398 | 400 | |
399 | 401 | switch (recip) { |
400 | 402 | case USB_RECIP_DEVICE: |
... | ... | @@ -493,7 +495,8 @@ |
493 | 495 | |
494 | 496 | static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
495 | 497 | { |
496 | - enum usb_device_state state = dwc->gadget.state; | |
498 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
499 | + enum usb_device_state state = dwc_gadget->gadget.state; | |
497 | 500 | u32 addr; |
498 | 501 | u32 reg; |
499 | 502 | |
500 | 503 | |
501 | 504 | |
502 | 505 | |
503 | 506 | |
... | ... | @@ -514,26 +517,28 @@ |
514 | 517 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); |
515 | 518 | |
516 | 519 | if (addr) |
517 | - usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); | |
520 | + usb_gadget_set_state(&dwc_gadget->gadget, USB_STATE_ADDRESS); | |
518 | 521 | else |
519 | - usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); | |
522 | + usb_gadget_set_state(&dwc_gadget->gadget, USB_STATE_DEFAULT); | |
520 | 523 | |
521 | 524 | return 0; |
522 | 525 | } |
523 | 526 | |
524 | 527 | static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
525 | 528 | { |
529 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
526 | 530 | int ret; |
527 | 531 | |
528 | 532 | spin_unlock(&dwc->lock); |
529 | - ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); | |
533 | + ret = dwc->gadget_driver->setup(&dwc_gadget->gadget, ctrl); | |
530 | 534 | spin_lock(&dwc->lock); |
531 | 535 | return ret; |
532 | 536 | } |
533 | 537 | |
534 | 538 | static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
535 | 539 | { |
536 | - enum usb_device_state state = dwc->gadget.state; | |
540 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
541 | + enum usb_device_state state = dwc_gadget->gadget.state; | |
537 | 542 | u32 cfg; |
538 | 543 | int ret; |
539 | 544 | u32 reg; |
... | ... | @@ -558,7 +563,7 @@ |
558 | 563 | * to change the state on the next usb_ep_queue() |
559 | 564 | */ |
560 | 565 | if (ret == 0) |
561 | - usb_gadget_set_state(&dwc->gadget, | |
566 | + usb_gadget_set_state(&dwc_gadget->gadget, | |
562 | 567 | USB_STATE_CONFIGURED); |
563 | 568 | |
564 | 569 | /* |
... | ... | @@ -577,7 +582,7 @@ |
577 | 582 | case USB_STATE_CONFIGURED: |
578 | 583 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
579 | 584 | if (!cfg && !ret) |
580 | - usb_gadget_set_state(&dwc->gadget, | |
585 | + usb_gadget_set_state(&dwc_gadget->gadget, | |
581 | 586 | USB_STATE_ADDRESS); |
582 | 587 | break; |
583 | 588 | default: |
... | ... | @@ -633,7 +638,8 @@ |
633 | 638 | static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
634 | 639 | { |
635 | 640 | struct dwc3_ep *dep; |
636 | - enum usb_device_state state = dwc->gadget.state; | |
641 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
642 | + enum usb_device_state state = dwc_gadget->gadget.state; | |
637 | 643 | u16 wLength; |
638 | 644 | u16 wValue; |
639 | 645 | |
... | ... | @@ -905,6 +911,7 @@ |
905 | 911 | struct dwc3_ep *dep, struct dwc3_request *req) |
906 | 912 | { |
907 | 913 | int ret; |
914 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
908 | 915 | |
909 | 916 | req->direction = !!dep->number; |
910 | 917 | |
... | ... | @@ -917,7 +924,7 @@ |
917 | 924 | u32 transfer_size; |
918 | 925 | u32 maxpacket; |
919 | 926 | |
920 | - ret = usb_gadget_map_request(&dwc->gadget, &req->request, | |
927 | + ret = usb_gadget_map_request(&dwc_gadget->gadget, &req->request, | |
921 | 928 | dep->number); |
922 | 929 | if (ret) { |
923 | 930 | dev_dbg(dwc->dev, "failed to map request\n"); |
... | ... | @@ -940,7 +947,7 @@ |
940 | 947 | dwc->ep0_bounce_addr, transfer_size, |
941 | 948 | DWC3_TRBCTL_CONTROL_DATA); |
942 | 949 | } else { |
943 | - ret = usb_gadget_map_request(&dwc->gadget, &req->request, | |
950 | + ret = usb_gadget_map_request(&dwc_gadget->gadget, &req->request, | |
944 | 951 | dep->number); |
945 | 952 | if (ret) { |
946 | 953 | dev_dbg(dwc->dev, "failed to map request\n"); |
drivers/usb/dwc3/gadget.c
... | ... | @@ -233,6 +233,7 @@ |
233 | 233 | int status) |
234 | 234 | { |
235 | 235 | struct dwc3 *dwc = dep->dwc; |
236 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
236 | 237 | int i; |
237 | 238 | |
238 | 239 | if (req->queued) { |
... | ... | @@ -260,7 +261,7 @@ |
260 | 261 | if (dwc->ep0_bounced && dep->number == 0) |
261 | 262 | dwc->ep0_bounced = false; |
262 | 263 | else |
263 | - usb_gadget_unmap_request(&dwc->gadget, &req->request, | |
264 | + usb_gadget_unmap_request(&dwc_gadget->gadget, &req->request, | |
264 | 265 | req->direction); |
265 | 266 | |
266 | 267 | dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", |
... | ... | @@ -497,6 +498,7 @@ |
497 | 498 | bool ignore) |
498 | 499 | { |
499 | 500 | struct dwc3_gadget_ep_cmd_params params; |
501 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
500 | 502 | |
501 | 503 | memset(¶ms, 0x00, sizeof(params)); |
502 | 504 | |
... | ... | @@ -504,7 +506,7 @@ |
504 | 506 | | DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc)); |
505 | 507 | |
506 | 508 | /* Burst size is only needed in SuperSpeed mode */ |
507 | - if (dwc->gadget.speed == USB_SPEED_SUPER) { | |
509 | + if (dwc_gadget->gadget.speed == USB_SPEED_SUPER) { | |
508 | 510 | u32 burst = dep->endpoint.maxburst - 1; |
509 | 511 | |
510 | 512 | params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst); |
... | ... | @@ -1010,6 +1012,7 @@ |
1010 | 1012 | struct dwc3_gadget_ep_cmd_params params; |
1011 | 1013 | struct dwc3_request *req; |
1012 | 1014 | struct dwc3 *dwc = dep->dwc; |
1015 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
1013 | 1016 | int ret; |
1014 | 1017 | u32 cmd; |
1015 | 1018 | |
... | ... | @@ -1062,7 +1065,7 @@ |
1062 | 1065 | * here and stop, unmap, free and del each of the linked |
1063 | 1066 | * requests instead of what we do now. |
1064 | 1067 | */ |
1065 | - usb_gadget_unmap_request(&dwc->gadget, &req->request, | |
1068 | + usb_gadget_unmap_request(&dwc_gadget->gadget, &req->request, | |
1066 | 1069 | req->direction); |
1067 | 1070 | list_del(&req->list); |
1068 | 1071 | return ret; |
... | ... | @@ -1111,6 +1114,7 @@ |
1111 | 1114 | static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) |
1112 | 1115 | { |
1113 | 1116 | struct dwc3 *dwc = dep->dwc; |
1117 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
1114 | 1118 | int ret; |
1115 | 1119 | |
1116 | 1120 | req->request.actual = 0; |
... | ... | @@ -1130,7 +1134,7 @@ |
1130 | 1134 | * This will also avoid Host cancelling URBs due to too |
1131 | 1135 | * many NAKs. |
1132 | 1136 | */ |
1133 | - ret = usb_gadget_map_request(&dwc->gadget, &req->request, | |
1137 | + ret = usb_gadget_map_request(&dwc_gadget->gadget, &req->request, | |
1134 | 1138 | dep->direction); |
1135 | 1139 | if (ret) |
1136 | 1140 | return ret; |
... | ... | @@ -1399,7 +1403,8 @@ |
1399 | 1403 | |
1400 | 1404 | static int dwc3_gadget_get_frame(struct usb_gadget *g) |
1401 | 1405 | { |
1402 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1406 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1407 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1403 | 1408 | u32 reg; |
1404 | 1409 | |
1405 | 1410 | reg = dwc3_readl(dwc->regs, DWC3_DSTS); |
... | ... | @@ -1408,7 +1413,8 @@ |
1408 | 1413 | |
1409 | 1414 | static int dwc3_gadget_wakeup(struct usb_gadget *g) |
1410 | 1415 | { |
1411 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1416 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1417 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1412 | 1418 | |
1413 | 1419 | unsigned long timeout; |
1414 | 1420 | unsigned long flags; |
... | ... | @@ -1489,7 +1495,8 @@ |
1489 | 1495 | static int dwc3_gadget_set_selfpowered(struct usb_gadget *g, |
1490 | 1496 | int is_selfpowered) |
1491 | 1497 | { |
1492 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1498 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1499 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1493 | 1500 | unsigned long flags; |
1494 | 1501 | |
1495 | 1502 | spin_lock_irqsave(&dwc->lock, flags); |
... | ... | @@ -1555,7 +1562,8 @@ |
1555 | 1562 | |
1556 | 1563 | static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) |
1557 | 1564 | { |
1558 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1565 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1566 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1559 | 1567 | unsigned long flags; |
1560 | 1568 | int ret; |
1561 | 1569 | |
... | ... | @@ -1598,7 +1606,8 @@ |
1598 | 1606 | static int dwc3_gadget_start(struct usb_gadget *g, |
1599 | 1607 | struct usb_gadget_driver *driver) |
1600 | 1608 | { |
1601 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1609 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1610 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1602 | 1611 | struct dwc3_ep *dep; |
1603 | 1612 | unsigned long flags; |
1604 | 1613 | int ret = 0; |
... | ... | @@ -1618,7 +1627,7 @@ |
1618 | 1627 | |
1619 | 1628 | if (dwc->gadget_driver) { |
1620 | 1629 | dev_err(dwc->dev, "%s is already bound to %s\n", |
1621 | - dwc->gadget.name, | |
1630 | + dwc_gadget->gadget.name, | |
1622 | 1631 | dwc->gadget_driver->driver.name); |
1623 | 1632 | ret = -EBUSY; |
1624 | 1633 | goto err1; |
... | ... | @@ -1710,7 +1719,8 @@ |
1710 | 1719 | static int dwc3_gadget_stop(struct usb_gadget *g, |
1711 | 1720 | struct usb_gadget_driver *driver) |
1712 | 1721 | { |
1713 | - struct dwc3 *dwc = gadget_to_dwc(g); | |
1722 | + struct dwc3_gadget *dwc_gadget = gadget_to_dwc_gadget(g); | |
1723 | + struct dwc3 *dwc = dwc_gadget->dwc; | |
1714 | 1724 | unsigned long flags; |
1715 | 1725 | int irq; |
1716 | 1726 | |
... | ... | @@ -1745,6 +1755,7 @@ |
1745 | 1755 | u8 num, u32 direction) |
1746 | 1756 | { |
1747 | 1757 | struct dwc3_ep *dep; |
1758 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
1748 | 1759 | u8 i; |
1749 | 1760 | |
1750 | 1761 | for (i = 0; i < num; i++) { |
... | ... | @@ -1774,7 +1785,7 @@ |
1774 | 1785 | dep->endpoint.maxburst = 1; |
1775 | 1786 | dep->endpoint.ops = &dwc3_gadget_ep0_ops; |
1776 | 1787 | if (!epnum) |
1777 | - dwc->gadget.ep0 = &dep->endpoint; | |
1788 | + dwc_gadget->gadget.ep0 = &dep->endpoint; | |
1778 | 1789 | } else { |
1779 | 1790 | int ret; |
1780 | 1791 | |
... | ... | @@ -1782,7 +1793,7 @@ |
1782 | 1793 | dep->endpoint.max_streams = 15; |
1783 | 1794 | dep->endpoint.ops = &dwc3_gadget_ep_ops; |
1784 | 1795 | list_add_tail(&dep->endpoint.ep_list, |
1785 | - &dwc->gadget.ep_list); | |
1796 | + &dwc_gadget->gadget.ep_list); | |
1786 | 1797 | |
1787 | 1798 | ret = dwc3_alloc_trb_pool(dep); |
1788 | 1799 | if (ret) |
1789 | 1800 | |
... | ... | @@ -1799,8 +1810,9 @@ |
1799 | 1810 | static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) |
1800 | 1811 | { |
1801 | 1812 | int ret; |
1813 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
1802 | 1814 | |
1803 | - INIT_LIST_HEAD(&dwc->gadget.ep_list); | |
1815 | + INIT_LIST_HEAD(&dwc_gadget->gadget.ep_list); | |
1804 | 1816 | |
1805 | 1817 | ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_out_eps, 0); |
1806 | 1818 | if (ret < 0) { |
1807 | 1819 | |
1808 | 1820 | |
1809 | 1821 | |
1810 | 1822 | |
1811 | 1823 | |
... | ... | @@ -2102,27 +2114,33 @@ |
2102 | 2114 | |
2103 | 2115 | static void dwc3_disconnect_gadget(struct dwc3 *dwc) |
2104 | 2116 | { |
2117 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2118 | + | |
2105 | 2119 | if (dwc->gadget_driver && dwc->gadget_driver->disconnect) { |
2106 | 2120 | spin_unlock(&dwc->lock); |
2107 | - dwc->gadget_driver->disconnect(&dwc->gadget); | |
2121 | + dwc->gadget_driver->disconnect(&dwc_gadget->gadget); | |
2108 | 2122 | spin_lock(&dwc->lock); |
2109 | 2123 | } |
2110 | 2124 | } |
2111 | 2125 | |
2112 | 2126 | static void dwc3_suspend_gadget(struct dwc3 *dwc) |
2113 | 2127 | { |
2128 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2129 | + | |
2114 | 2130 | if (dwc->gadget_driver && dwc->gadget_driver->suspend) { |
2115 | 2131 | spin_unlock(&dwc->lock); |
2116 | - dwc->gadget_driver->suspend(&dwc->gadget); | |
2132 | + dwc->gadget_driver->suspend(&dwc_gadget->gadget); | |
2117 | 2133 | spin_lock(&dwc->lock); |
2118 | 2134 | } |
2119 | 2135 | } |
2120 | 2136 | |
2121 | 2137 | static void dwc3_resume_gadget(struct dwc3 *dwc) |
2122 | 2138 | { |
2139 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2140 | + | |
2123 | 2141 | if (dwc->gadget_driver && dwc->gadget_driver->resume) { |
2124 | 2142 | spin_unlock(&dwc->lock); |
2125 | - dwc->gadget_driver->resume(&dwc->gadget); | |
2143 | + dwc->gadget_driver->resume(&dwc_gadget->gadget); | |
2126 | 2144 | spin_lock(&dwc->lock); |
2127 | 2145 | } |
2128 | 2146 | } |
... | ... | @@ -2216,6 +2234,7 @@ |
2216 | 2234 | static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) |
2217 | 2235 | { |
2218 | 2236 | int reg; |
2237 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2219 | 2238 | |
2220 | 2239 | dev_vdbg(dwc->dev, "%s\n", __func__); |
2221 | 2240 | |
2222 | 2241 | |
... | ... | @@ -2229,13 +2248,14 @@ |
2229 | 2248 | dwc3_disconnect_gadget(dwc); |
2230 | 2249 | dwc->start_config_issued = false; |
2231 | 2250 | |
2232 | - dwc->gadget.speed = USB_SPEED_UNKNOWN; | |
2251 | + dwc_gadget->gadget.speed = USB_SPEED_UNKNOWN; | |
2233 | 2252 | dwc->setup_packet_pending = false; |
2234 | 2253 | } |
2235 | 2254 | |
2236 | 2255 | static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) |
2237 | 2256 | { |
2238 | 2257 | u32 reg; |
2258 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2239 | 2259 | |
2240 | 2260 | dev_vdbg(dwc->dev, "%s\n", __func__); |
2241 | 2261 | |
2242 | 2262 | |
... | ... | @@ -2271,9 +2291,9 @@ |
2271 | 2291 | } |
2272 | 2292 | |
2273 | 2293 | /* after reset -> Default State */ |
2274 | - usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); | |
2294 | + usb_gadget_set_state(&dwc_gadget->gadget, USB_STATE_DEFAULT); | |
2275 | 2295 | |
2276 | - if (dwc->gadget.speed != USB_SPEED_UNKNOWN) | |
2296 | + if (dwc_gadget->gadget.speed != USB_SPEED_UNKNOWN) | |
2277 | 2297 | dwc3_disconnect_gadget(dwc); |
2278 | 2298 | |
2279 | 2299 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
... | ... | @@ -2319,6 +2339,7 @@ |
2319 | 2339 | static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) |
2320 | 2340 | { |
2321 | 2341 | struct dwc3_ep *dep; |
2342 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2322 | 2343 | int ret; |
2323 | 2344 | u32 reg; |
2324 | 2345 | u8 speed; |
2325 | 2346 | |
2326 | 2347 | |
2327 | 2348 | |
... | ... | @@ -2350,24 +2371,24 @@ |
2350 | 2371 | dwc3_gadget_reset_interrupt(dwc); |
2351 | 2372 | |
2352 | 2373 | dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); |
2353 | - dwc->gadget.ep0->maxpacket = 512; | |
2354 | - dwc->gadget.speed = USB_SPEED_SUPER; | |
2374 | + dwc_gadget->gadget.ep0->maxpacket = 512; | |
2375 | + dwc_gadget->gadget.speed = USB_SPEED_SUPER; | |
2355 | 2376 | break; |
2356 | 2377 | case DWC3_DCFG_HIGHSPEED: |
2357 | 2378 | dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); |
2358 | - dwc->gadget.ep0->maxpacket = 64; | |
2359 | - dwc->gadget.speed = USB_SPEED_HIGH; | |
2379 | + dwc_gadget->gadget.ep0->maxpacket = 64; | |
2380 | + dwc_gadget->gadget.speed = USB_SPEED_HIGH; | |
2360 | 2381 | break; |
2361 | 2382 | case DWC3_DCFG_FULLSPEED2: |
2362 | 2383 | case DWC3_DCFG_FULLSPEED1: |
2363 | 2384 | dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); |
2364 | - dwc->gadget.ep0->maxpacket = 64; | |
2365 | - dwc->gadget.speed = USB_SPEED_FULL; | |
2385 | + dwc_gadget->gadget.ep0->maxpacket = 64; | |
2386 | + dwc_gadget->gadget.speed = USB_SPEED_FULL; | |
2366 | 2387 | break; |
2367 | 2388 | case DWC3_DCFG_LOWSPEED: |
2368 | 2389 | dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); |
2369 | - dwc->gadget.ep0->maxpacket = 8; | |
2370 | - dwc->gadget.speed = USB_SPEED_LOW; | |
2390 | + dwc_gadget->gadget.ep0->maxpacket = 8; | |
2391 | + dwc_gadget->gadget.speed = USB_SPEED_LOW; | |
2371 | 2392 | break; |
2372 | 2393 | } |
2373 | 2394 | |
... | ... | @@ -2420,6 +2441,8 @@ |
2420 | 2441 | |
2421 | 2442 | static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) |
2422 | 2443 | { |
2444 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2445 | + | |
2423 | 2446 | dev_vdbg(dwc->dev, "%s\n", __func__); |
2424 | 2447 | |
2425 | 2448 | /* |
... | ... | @@ -2427,7 +2450,7 @@ |
2427 | 2450 | * implemented. |
2428 | 2451 | */ |
2429 | 2452 | |
2430 | - dwc->gadget_driver->resume(&dwc->gadget); | |
2453 | + dwc->gadget_driver->resume(&dwc_gadget->gadget); | |
2431 | 2454 | } |
2432 | 2455 | |
2433 | 2456 | static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, |
... | ... | @@ -2740,6 +2763,7 @@ |
2740 | 2763 | int dwc3_gadget_init(struct dwc3 *dwc) |
2741 | 2764 | { |
2742 | 2765 | int ret; |
2766 | + struct dwc3_gadget *dwc_gadget; | |
2743 | 2767 | |
2744 | 2768 | dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), |
2745 | 2769 | &dwc->ctrl_req_addr, GFP_KERNEL); |
2746 | 2770 | |
2747 | 2771 | |
... | ... | @@ -2773,17 +2797,24 @@ |
2773 | 2797 | goto err3; |
2774 | 2798 | } |
2775 | 2799 | |
2776 | - dwc->gadget.ops = &dwc3_gadget_ops; | |
2777 | - dwc->gadget.max_speed = USB_SPEED_SUPER; | |
2778 | - dwc->gadget.speed = USB_SPEED_UNKNOWN; | |
2779 | - dwc->gadget.sg_supported = true; | |
2780 | - dwc->gadget.name = "dwc3-gadget"; | |
2800 | + dwc_gadget = kzalloc(sizeof(*dwc_gadget), GFP_KERNEL); | |
2801 | + if (!dwc_gadget) { | |
2802 | + ret = -ENOMEM; | |
2803 | + goto err3; | |
2804 | + } | |
2781 | 2805 | |
2806 | + dwc_gadget->gadget.ops = &dwc3_gadget_ops; | |
2807 | + dwc_gadget->gadget.max_speed = USB_SPEED_SUPER; | |
2808 | + dwc_gadget->gadget.speed = USB_SPEED_UNKNOWN; | |
2809 | + dwc_gadget->gadget.sg_supported = true; | |
2810 | + dwc_gadget->gadget.name = "dwc3-gadget"; | |
2811 | + dwc_gadget->dwc = dwc; | |
2812 | + | |
2782 | 2813 | /* |
2783 | 2814 | * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize |
2784 | 2815 | * on ep out. |
2785 | 2816 | */ |
2786 | - dwc->gadget.quirk_ep_out_aligned_size = true; | |
2817 | + dwc_gadget->gadget.quirk_ep_out_aligned_size = true; | |
2787 | 2818 | |
2788 | 2819 | /* |
2789 | 2820 | * REVISIT: Here we should clear all pending IRQs to be |
... | ... | @@ -2794,7 +2825,7 @@ |
2794 | 2825 | if (ret) |
2795 | 2826 | goto err4; |
2796 | 2827 | |
2797 | - ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); | |
2828 | + ret = usb_add_gadget_udc(dwc->dev, &dwc_gadget->gadget); | |
2798 | 2829 | if (ret) { |
2799 | 2830 | dev_err(dwc->dev, "failed to register udc\n"); |
2800 | 2831 | goto err4; |
... | ... | @@ -2826,7 +2857,9 @@ |
2826 | 2857 | |
2827 | 2858 | void dwc3_gadget_exit(struct dwc3 *dwc) |
2828 | 2859 | { |
2829 | - usb_del_gadget_udc(&dwc->gadget); | |
2860 | + struct dwc3_gadget *dwc_gadget = dwc->dwc_gadget; | |
2861 | + | |
2862 | + usb_del_gadget_udc(&dwc_gadget->gadget); | |
2830 | 2863 | |
2831 | 2864 | dwc3_gadget_free_endpoints(dwc); |
2832 | 2865 |
drivers/usb/dwc3/gadget.h
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 | struct dwc3; |
27 | 27 | #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint)) |
28 | 28 | #define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget)) |
29 | +#define gadget_to_dwc_gadget(g) (container_of(g, struct dwc3_gadget, gadget)) | |
29 | 30 | |
30 | 31 | /* DEPCFG parameter 1 */ |
31 | 32 | #define DWC3_DEPCFG_INT_NUM(n) ((n) << 0) |