Lines Matching refs:dwc
41 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) in dwc3_gadget_set_test_mode() argument
45 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_set_test_mode()
60 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_set_test_mode()
72 int dwc3_gadget_get_link_state(struct dwc3 *dwc) in dwc3_gadget_get_link_state() argument
76 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_get_link_state()
89 int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) in dwc3_gadget_set_link_state() argument
100 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_set_link_state()
111 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_set_link_state()
115 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_set_link_state()
119 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_set_link_state()
131 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_set_link_state()
178 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_del_and_unmap_request() local
188 usb_gadget_unmap_request_by_dev(dwc->sysdev, in dwc3_gadget_del_and_unmap_request()
195 pm_runtime_put(dwc->dev); in dwc3_gadget_del_and_unmap_request()
211 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_giveback() local
216 spin_unlock(&dwc->lock); in dwc3_gadget_giveback()
218 spin_lock(&dwc->lock); in dwc3_gadget_giveback()
230 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, in dwc3_send_gadget_generic_command() argument
238 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); in dwc3_send_gadget_generic_command()
239 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); in dwc3_send_gadget_generic_command()
242 reg = dwc3_readl(dwc->regs, DWC3_DGCMD); in dwc3_send_gadget_generic_command()
261 static int __dwc3_gadget_wakeup(struct dwc3 *dwc);
276 struct dwc3 *dwc = dep->dwc; in dwc3_send_gadget_ep_cmd() local
294 if (dwc->gadget->speed <= USB_SPEED_HIGH || in dwc3_send_gadget_ep_cmd()
296 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
308 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
320 link_state = dwc3_gadget_get_link_state(dwc); in dwc3_send_gadget_ep_cmd()
323 if (dwc->gadget->speed >= USB_SPEED_SUPER) in dwc3_send_gadget_ep_cmd()
328 ret = __dwc3_gadget_wakeup(dwc); in dwc3_send_gadget_ep_cmd()
329 dev_WARN_ONCE(dwc->dev, ret, "wakeup failed --> %d\n", in dwc3_send_gadget_ep_cmd()
387 dev_WARN(dwc->dev, "No resource for %s\n", in dwc3_send_gadget_ep_cmd()
406 dev_WARN(dwc->dev, "UNKNOWN cmd status\n"); in dwc3_send_gadget_ep_cmd()
430 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
432 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
440 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd() local
454 (dwc->gadget->speed >= USB_SPEED_SUPER)) in dwc3_send_clear_stall_ep_cmd()
472 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool() local
477 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
481 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
491 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool() local
493 dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, in dwc3_free_trb_pool()
548 struct dwc3 *dwc; in dwc3_gadget_start_config() local
558 dwc = dep->dwc; in dwc3_gadget_start_config()
565 struct dwc3_ep *dep = dwc->eps[i]; in dwc3_gadget_start_config()
583 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config() local
594 if (dwc->gadget->speed >= USB_SPEED_SUPER) { in dwc3_gadget_set_ep_config()
649 dwc->gadget->speed == USB_SPEED_FULL) in dwc3_gadget_set_ep_config()
677 static int dwc3_gadget_calc_tx_fifo_size(struct dwc3 *dwc, int mult) in dwc3_gadget_calc_tx_fifo_size() argument
683 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_calc_tx_fifo_size()
702 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) in dwc3_gadget_clear_tx_fifos() argument
709 if (!dwc->do_fifo_resize) in dwc3_gadget_clear_tx_fifos()
713 dep = dwc->eps[1]; in dwc3_gadget_clear_tx_fifos()
714 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_clear_tx_fifos()
720 dwc->last_fifo_depth = fifo_depth; in dwc3_gadget_clear_tx_fifos()
722 for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); in dwc3_gadget_clear_tx_fifos()
724 dep = dwc->eps[num]; in dwc3_gadget_clear_tx_fifos()
727 dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & in dwc3_gadget_clear_tx_fifos()
730 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1), size); in dwc3_gadget_clear_tx_fifos()
733 dwc->num_ep_resized = 0; in dwc3_gadget_clear_tx_fifos()
759 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_resize_tx_fifos() local
770 if (!dwc->do_fifo_resize) in dwc3_gadget_resize_tx_fifos()
781 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_resize_tx_fifos()
791 num_fifos = dwc->tx_fifo_resize_max_num; in dwc3_gadget_resize_tx_fifos()
794 fifo = dwc3_gadget_calc_tx_fifo_size(dwc, 1); in dwc3_gadget_resize_tx_fifos()
797 num_in_ep = dwc->max_cfg_eps; in dwc3_gadget_resize_tx_fifos()
798 num_in_ep -= dwc->num_ep_resized; in dwc3_gadget_resize_tx_fifos()
802 remaining = ram1_depth - min_depth - dwc->last_fifo_depth; in dwc3_gadget_resize_tx_fifos()
818 tmp = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_resize_tx_fifos()
821 fifo_size |= (fifo_0_start + (dwc->last_fifo_depth << 16)); in dwc3_gadget_resize_tx_fifos()
823 dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
825 dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
828 if (dwc->last_fifo_depth >= ram1_depth) { in dwc3_gadget_resize_tx_fifos()
829 dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n", in dwc3_gadget_resize_tx_fifos()
830 dwc->last_fifo_depth, ram1_depth, in dwc3_gadget_resize_tx_fifos()
837 dwc->last_fifo_depth -= fifo_size; in dwc3_gadget_resize_tx_fifos()
841 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1), fifo_size); in dwc3_gadget_resize_tx_fifos()
843 dwc->num_ep_resized++; in dwc3_gadget_resize_tx_fifos()
859 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable() local
885 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_enable()
887 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_enable()
959 !(dwc->hwparams.hwparams9 & in __dwc3_gadget_ep_enable()
971 void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) in dwc3_remove_requests() argument
1013 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable() local
1023 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_disable()
1025 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_disable()
1027 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in __dwc3_gadget_ep_disable()
1069 struct dwc3 *dwc; in dwc3_gadget_ep_enable() local
1084 dwc = dep->dwc; in dwc3_gadget_ep_enable()
1086 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
1091 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1093 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1101 struct dwc3 *dwc; in dwc3_gadget_ep_disable() local
1111 dwc = dep->dwc; in dwc3_gadget_ep_disable()
1113 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
1118 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1120 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1223 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb() local
1224 struct usb_gadget *gadget = dwc->gadget; in dwc3_prepare_one_trb()
1228 dma = dep->dwc->bounce_addr; in dwc3_prepare_one_trb()
1309 dev_WARN(dwc->dev, "Unknown endpoint type %d\n", in dwc3_prepare_one_trb()
1326 if (dep->stream_capable && DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1335 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1553 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in dwc3_prepare_trbs()
1558 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs() local
1560 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, in dwc3_prepare_trbs()
1587 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_trbs()
1665 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in __dwc3_gadget_kick_transfer()
1671 static int __dwc3_gadget_get_frame(struct dwc3 *dwc) in __dwc3_gadget_get_frame() argument
1675 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_get_frame()
1708 if (ret == -ETIMEDOUT && dep->dwc->ep0state != EP0_SETUP_PHASE) { in __dwc3_stop_active_transfer()
1785 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1786 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1842 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc() local
1852 if (!dwc->dis_start_transfer_quirk && in __dwc3_gadget_start_isoc()
1855 if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1860 dwc->gadget->speed >= USB_SPEED_HIGH) { in __dwc3_gadget_start_isoc()
1861 u32 frame = __dwc3_gadget_get_frame(dwc); in __dwc3_gadget_start_isoc()
1907 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue() local
1909 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in __dwc3_gadget_ep_queue()
1910 dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", in __dwc3_gadget_ep_queue()
1924 pm_runtime_get(dwc->dev); in __dwc3_gadget_ep_queue()
1976 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue() local
1982 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_queue()
1984 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2021 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_cleanup_cancelled_requests() local
2037 dev_err(dwc->dev, "request cancelled with wrong reason:%d\n", req->status); in dwc3_gadget_ep_cleanup_cancelled_requests()
2057 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue() local
2064 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2099 dev_err(dwc->dev, "request %pK was not queued to %s\n", in dwc3_gadget_ep_dequeue()
2103 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2111 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt() local
2117 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
2132 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
2145 dev_err(dwc->dev, "failed to set STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2169 dwc->clear_stall_protocol = dep->number; in __dwc3_gadget_ep_set_halt()
2178 dev_err(dwc->dev, "failed to clear STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2198 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt() local
2204 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2206 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2214 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge() local
2218 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2225 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2264 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_get_frame() local
2266 return __dwc3_gadget_get_frame(dwc); in dwc3_gadget_get_frame()
2269 static int __dwc3_gadget_wakeup(struct dwc3 *dwc) in __dwc3_gadget_wakeup() argument
2284 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2300 ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV); in __dwc3_gadget_wakeup()
2302 dev_err(dwc->dev, "failed to put link in Recovery\n"); in __dwc3_gadget_wakeup()
2309 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in __dwc3_gadget_wakeup()
2311 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in __dwc3_gadget_wakeup()
2318 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2326 dev_err(dwc->dev, "failed to send remote wakeup\n"); in __dwc3_gadget_wakeup()
2335 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_wakeup() local
2339 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_wakeup()
2340 ret = __dwc3_gadget_wakeup(dwc); in dwc3_gadget_wakeup()
2341 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2349 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_selfpowered() local
2352 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2354 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2359 static void dwc3_stop_active_transfers(struct dwc3 *dwc) in dwc3_stop_active_transfers() argument
2363 for (epnum = 2; epnum < dwc->num_eps; epnum++) { in dwc3_stop_active_transfers()
2366 dep = dwc->eps[epnum]; in dwc3_stop_active_transfers()
2370 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in dwc3_stop_active_transfers()
2374 static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) in __dwc3_gadget_set_ssp_rate() argument
2376 enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2380 ssp_rate = dwc->max_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2382 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_ssp_rate()
2388 else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) in __dwc3_gadget_set_ssp_rate()
2392 dwc->max_ssp_rate != USB_SSP_GEN_2x1) in __dwc3_gadget_set_ssp_rate()
2395 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_ssp_rate()
2398 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) in __dwc3_gadget_set_speed() argument
2403 speed = dwc->gadget_max_speed; in __dwc3_gadget_set_speed()
2404 if (speed == USB_SPEED_UNKNOWN || speed > dwc->maximum_speed) in __dwc3_gadget_set_speed()
2405 speed = dwc->maximum_speed; in __dwc3_gadget_set_speed()
2409 __dwc3_gadget_set_ssp_rate(dwc); in __dwc3_gadget_set_speed()
2413 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_speed()
2430 !dwc->dis_metastability_quirk) { in __dwc3_gadget_set_speed()
2450 dev_err(dwc->dev, "invalid speed (%d)\n", speed); in __dwc3_gadget_set_speed()
2464 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_speed()
2467 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) in dwc3_gadget_run_stop() argument
2472 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_run_stop()
2475 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_run_stop()
2486 if (dwc->has_hibernation) in dwc3_gadget_run_stop()
2489 __dwc3_gadget_set_speed(dwc); in dwc3_gadget_run_stop()
2490 dwc->pullups_connected = true; in dwc3_gadget_run_stop()
2494 if (dwc->has_hibernation && !suspend) in dwc3_gadget_run_stop()
2497 dwc->pullups_connected = false; in dwc3_gadget_run_stop()
2500 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_run_stop()
2504 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_run_stop()
2514 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
2515 static void __dwc3_gadget_stop(struct dwc3 *dwc);
2516 static int __dwc3_gadget_start(struct dwc3 *dwc);
2518 static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) in dwc3_gadget_soft_disconnect() argument
2522 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2523 dwc->connected = false; in dwc3_gadget_soft_disconnect()
2529 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_soft_disconnect()
2532 if (dwc->delayed_status) in dwc3_gadget_soft_disconnect()
2533 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_soft_disconnect()
2535 reinit_completion(&dwc->ep0_in_setup); in dwc3_gadget_soft_disconnect()
2537 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2538 ret = wait_for_completion_timeout(&dwc->ep0_in_setup, in dwc3_gadget_soft_disconnect()
2540 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2542 dev_warn(dwc->dev, "timed out waiting for SETUP phase\n"); in dwc3_gadget_soft_disconnect()
2552 dwc3_stop_active_transfers(dwc); in dwc3_gadget_soft_disconnect()
2553 __dwc3_gadget_stop(dwc); in dwc3_gadget_soft_disconnect()
2554 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2563 return dwc3_gadget_run_stop(dwc, false, false); in dwc3_gadget_soft_disconnect()
2568 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_pullup() local
2573 dwc->softconnect = is_on; in dwc3_gadget_pullup()
2581 pm_runtime_barrier(dwc->dev); in dwc3_gadget_pullup()
2582 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_pullup()
2591 ret = pm_runtime_get_sync(dwc->dev); in dwc3_gadget_pullup()
2593 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2597 if (dwc->pullups_connected == is_on) { in dwc3_gadget_pullup()
2598 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2602 synchronize_irq(dwc->irq_gadget); in dwc3_gadget_pullup()
2605 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_pullup()
2613 dwc3_core_soft_reset(dwc); in dwc3_gadget_pullup()
2615 dwc3_event_buffers_setup(dwc); in dwc3_gadget_pullup()
2616 __dwc3_gadget_start(dwc); in dwc3_gadget_pullup()
2617 ret = dwc3_gadget_run_stop(dwc, true, false); in dwc3_gadget_pullup()
2620 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2625 static void dwc3_gadget_enable_irq(struct dwc3 *dwc) in dwc3_gadget_enable_irq() argument
2645 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_irq()
2648 static void dwc3_gadget_disable_irq(struct dwc3 *dwc) in dwc3_gadget_disable_irq() argument
2651 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); in dwc3_gadget_disable_irq()
2678 static void dwc3_gadget_setup_nump(struct dwc3 *dwc) in dwc3_gadget_setup_nump() argument
2685 ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_setup_nump()
2686 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_setup_nump()
2692 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_setup_nump()
2695 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_setup_nump()
2698 static int __dwc3_gadget_start(struct dwc3 *dwc) in __dwc3_gadget_start() argument
2708 if (dwc->imod_interval) { in __dwc3_gadget_start()
2709 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in __dwc3_gadget_start()
2710 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in __dwc3_gadget_start()
2711 } else if (dwc3_has_imod(dwc)) { in __dwc3_gadget_start()
2712 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), 0); in __dwc3_gadget_start()
2722 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in __dwc3_gadget_start()
2728 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in __dwc3_gadget_start()
2730 dwc3_gadget_setup_nump(dwc); in __dwc3_gadget_start()
2739 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_start()
2741 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_start()
2744 if (DWC3_MST_CAPABLE(&dwc->hwparams)) { in __dwc3_gadget_start()
2745 reg = dwc3_readl(dwc->regs, DWC3_DCFG1); in __dwc3_gadget_start()
2747 dwc3_writel(dwc->regs, DWC3_DCFG1, reg); in __dwc3_gadget_start()
2753 dep = dwc->eps[0]; in __dwc3_gadget_start()
2757 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2761 dep = dwc->eps[1]; in __dwc3_gadget_start()
2765 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2770 dwc->ep0state = EP0_SETUP_PHASE; in __dwc3_gadget_start()
2771 dwc->ep0_bounced = false; in __dwc3_gadget_start()
2772 dwc->link_state = DWC3_LINK_STATE_SS_DIS; in __dwc3_gadget_start()
2773 dwc->delayed_status = false; in __dwc3_gadget_start()
2774 dwc3_ep0_out_start(dwc); in __dwc3_gadget_start()
2776 dwc3_gadget_enable_irq(dwc); in __dwc3_gadget_start()
2781 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_start()
2790 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_start() local
2795 irq = dwc->irq_gadget; in dwc3_gadget_start()
2797 IRQF_SHARED, "dwc3", dwc->ev_buf); in dwc3_gadget_start()
2799 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_gadget_start()
2804 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_start()
2805 dwc->gadget_driver = driver; in dwc3_gadget_start()
2806 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
2811 static void __dwc3_gadget_stop(struct dwc3 *dwc) in __dwc3_gadget_stop() argument
2813 dwc3_gadget_disable_irq(dwc); in __dwc3_gadget_stop()
2814 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_stop()
2815 __dwc3_gadget_ep_disable(dwc->eps[1]); in __dwc3_gadget_stop()
2820 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_stop() local
2823 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_stop()
2824 dwc->gadget_driver = NULL; in dwc3_gadget_stop()
2825 dwc->max_cfg_eps = 0; in dwc3_gadget_stop()
2826 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_stop()
2828 free_irq(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_stop()
2836 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_config_params() local
2842 if (!dwc->dis_enblslpm_quirk) { in dwc3_gadget_config_params()
2853 if (dwc->is_utmi_l1_suspend) in dwc3_gadget_config_params()
2855 clamp_t(u8, dwc->hird_threshold, 2, 15); in dwc3_gadget_config_params()
2859 if (dwc->dis_u1_entry_quirk) in dwc3_gadget_config_params()
2865 if (dwc->dis_u2_entry_quirk) in dwc3_gadget_config_params()
2875 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_speed() local
2878 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_speed()
2879 dwc->gadget_max_speed = speed; in dwc3_gadget_set_speed()
2880 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_speed()
2886 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_ssp_rate() local
2889 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
2890 dwc->gadget_max_speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_set_ssp_rate()
2891 dwc->gadget_ssp_rate = rate; in dwc3_gadget_set_ssp_rate()
2892 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
2897 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_vbus_draw() local
2901 if (dwc->usb2_phy) in dwc3_gadget_vbus_draw()
2902 return usb_phy_set_power(dwc->usb2_phy, mA); in dwc3_gadget_vbus_draw()
2904 if (!dwc->usb_psy) in dwc3_gadget_vbus_draw()
2908 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_gadget_vbus_draw()
2925 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_check_config() local
2931 if (!dwc->do_fifo_resize) in dwc3_gadget_check_config()
2940 if (ep_num <= dwc->max_cfg_eps) in dwc3_gadget_check_config()
2944 dwc->max_cfg_eps = ep_num; in dwc3_gadget_check_config()
2946 fifo_size = dwc3_gadget_calc_tx_fifo_size(dwc, dwc->max_cfg_eps); in dwc3_gadget_check_config()
2948 fifo_size += dwc->max_cfg_eps; in dwc3_gadget_check_config()
2951 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_check_config()
2960 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_async_callbacks() local
2963 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
2964 dwc->async_callbacks = enable; in dwc3_gadget_async_callbacks()
2965 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
2987 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint() local
2993 dwc->gadget->ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
3002 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint() local
3007 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_in_endpoint()
3012 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
3041 &dwc->gadget->ep_list); in dwc3_gadget_init_in_endpoint()
3051 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint() local
3055 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_out_endpoint()
3061 size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0)); in dwc3_gadget_init_out_endpoint()
3088 &dwc->gadget->ep_list); in dwc3_gadget_init_out_endpoint()
3096 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) in dwc3_gadget_init_endpoint() argument
3107 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
3110 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
3111 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
3147 static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) in dwc3_gadget_init_endpoints() argument
3151 INIT_LIST_HEAD(&dwc->gadget->ep_list); in dwc3_gadget_init_endpoints()
3156 ret = dwc3_gadget_init_endpoint(dwc, epnum); in dwc3_gadget_init_endpoints()
3164 static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) in dwc3_gadget_free_endpoints() argument
3170 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
3188 debugfs_lookup(dev_name(dep->dwc->dev), in dwc3_gadget_free_endpoints()
3238 if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && in dwc3_gadget_ep_reclaim_completed_trb()
3239 trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { in dwc3_gadget_ep_reclaim_completed_trb()
3389 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_should_continue() local
3391 if (!dep->endpoint.desc || !dwc->pullups_connected || in dwc3_gadget_ep_should_continue()
3392 !dwc->connected) in dwc3_gadget_ep_should_continue()
3418 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_trbs_complete() local
3447 dep = dwc->eps[i]; in dwc3_gadget_endpoint_trbs_complete()
3456 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_endpoint_trbs_complete()
3457 reg |= dwc->u1u2; in dwc3_gadget_endpoint_trbs_complete()
3458 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_endpoint_trbs_complete()
3460 dwc->u1u2 = 0; in dwc3_gadget_endpoint_trbs_complete()
3540 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_command_complete() local
3544 struct usb_ep *ep0 = &dwc->eps[0]->endpoint; in dwc3_gadget_endpoint_command_complete()
3546 dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); in dwc3_gadget_endpoint_command_complete()
3547 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3553 if (dwc->clear_stall_protocol == dep->number) in dwc3_gadget_endpoint_command_complete()
3554 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_endpoint_command_complete()
3567 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_stream_event() local
3595 (!DWC3_MST_CAPABLE(&dwc->hwparams) && in dwc3_gadget_endpoint_stream_event()
3616 dwc3_send_gadget_generic_command(dwc, cmd, dep->number); in dwc3_gadget_endpoint_stream_event()
3629 static void dwc3_endpoint_interrupt(struct dwc3 *dwc, in dwc3_endpoint_interrupt() argument
3635 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
3648 dwc3_ep0_interrupt(dwc, event); in dwc3_endpoint_interrupt()
3673 static void dwc3_disconnect_gadget(struct dwc3 *dwc) in dwc3_disconnect_gadget() argument
3675 if (dwc->async_callbacks && dwc->gadget_driver->disconnect) { in dwc3_disconnect_gadget()
3676 spin_unlock(&dwc->lock); in dwc3_disconnect_gadget()
3677 dwc->gadget_driver->disconnect(dwc->gadget); in dwc3_disconnect_gadget()
3678 spin_lock(&dwc->lock); in dwc3_disconnect_gadget()
3682 static void dwc3_suspend_gadget(struct dwc3 *dwc) in dwc3_suspend_gadget() argument
3684 if (dwc->async_callbacks && dwc->gadget_driver->suspend) { in dwc3_suspend_gadget()
3685 spin_unlock(&dwc->lock); in dwc3_suspend_gadget()
3686 dwc->gadget_driver->suspend(dwc->gadget); in dwc3_suspend_gadget()
3687 spin_lock(&dwc->lock); in dwc3_suspend_gadget()
3691 static void dwc3_resume_gadget(struct dwc3 *dwc) in dwc3_resume_gadget() argument
3693 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_resume_gadget()
3694 spin_unlock(&dwc->lock); in dwc3_resume_gadget()
3695 dwc->gadget_driver->resume(dwc->gadget); in dwc3_resume_gadget()
3696 spin_lock(&dwc->lock); in dwc3_resume_gadget()
3700 static void dwc3_reset_gadget(struct dwc3 *dwc) in dwc3_reset_gadget() argument
3702 if (!dwc->gadget_driver) in dwc3_reset_gadget()
3705 if (dwc->async_callbacks && dwc->gadget->speed != USB_SPEED_UNKNOWN) { in dwc3_reset_gadget()
3706 spin_unlock(&dwc->lock); in dwc3_reset_gadget()
3707 usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); in dwc3_reset_gadget()
3708 spin_lock(&dwc->lock); in dwc3_reset_gadget()
3715 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer() local
3723 if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) in dwc3_stop_active_transfer()
3740 if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { in dwc3_stop_active_transfer()
3775 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) in dwc3_clear_stall_all_ep() argument
3783 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
3797 static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) in dwc3_gadget_disconnect_interrupt() argument
3801 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); in dwc3_gadget_disconnect_interrupt()
3803 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_disconnect_interrupt()
3806 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_disconnect_interrupt()
3808 dwc->connected = false; in dwc3_gadget_disconnect_interrupt()
3810 dwc3_disconnect_gadget(dwc); in dwc3_gadget_disconnect_interrupt()
3812 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_disconnect_interrupt()
3813 dwc->setup_packet_pending = false; in dwc3_gadget_disconnect_interrupt()
3814 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_disconnect_interrupt()
3816 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_disconnect_interrupt()
3819 dir = !!dwc->ep0_expect_in; in dwc3_gadget_disconnect_interrupt()
3820 if (dwc->ep0state == EP0_DATA_PHASE) in dwc3_gadget_disconnect_interrupt()
3821 dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); in dwc3_gadget_disconnect_interrupt()
3823 dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); in dwc3_gadget_disconnect_interrupt()
3824 dwc3_ep0_stall_and_restart(dwc); in dwc3_gadget_disconnect_interrupt()
3828 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) in dwc3_gadget_reset_interrupt() argument
3839 dwc->connected = false; in dwc3_gadget_reset_interrupt()
3868 if (dwc->setup_packet_pending) in dwc3_gadget_reset_interrupt()
3869 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_reset_interrupt()
3872 dwc3_reset_gadget(dwc); in dwc3_gadget_reset_interrupt()
3879 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_reset_interrupt()
3882 dir = !!dwc->ep0_expect_in; in dwc3_gadget_reset_interrupt()
3883 if (dwc->ep0state == EP0_DATA_PHASE) in dwc3_gadget_reset_interrupt()
3884 dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); in dwc3_gadget_reset_interrupt()
3886 dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); in dwc3_gadget_reset_interrupt()
3888 dwc->eps[0]->trb_enqueue = 0; in dwc3_gadget_reset_interrupt()
3889 dwc->eps[1]->trb_enqueue = 0; in dwc3_gadget_reset_interrupt()
3891 dwc3_ep0_stall_and_restart(dwc); in dwc3_gadget_reset_interrupt()
3900 dwc3_stop_active_transfers(dwc); in dwc3_gadget_reset_interrupt()
3901 dwc->connected = true; in dwc3_gadget_reset_interrupt()
3903 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_reset_interrupt()
3905 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_reset_interrupt()
3906 dwc->test_mode = false; in dwc3_gadget_reset_interrupt()
3907 dwc3_clear_stall_all_ep(dwc); in dwc3_gadget_reset_interrupt()
3910 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_reset_interrupt()
3912 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_reset_interrupt()
3915 static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) in dwc3_gadget_conndone_interrupt() argument
3923 if (!dwc->softconnect) in dwc3_gadget_conndone_interrupt()
3926 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_conndone_interrupt()
3928 dwc->speed = speed; in dwc3_gadget_conndone_interrupt()
3933 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_conndone_interrupt()
3947 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
3948 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
3951 dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; in dwc3_gadget_conndone_interrupt()
3953 dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; in dwc3_gadget_conndone_interrupt()
3970 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_conndone_interrupt()
3973 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
3974 dwc->gadget->speed = USB_SPEED_SUPER; in dwc3_gadget_conndone_interrupt()
3977 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
3978 dwc->gadget->ssp_rate = USB_SSP_GEN_1x2; in dwc3_gadget_conndone_interrupt()
3983 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
3984 dwc->gadget->speed = USB_SPEED_HIGH; in dwc3_gadget_conndone_interrupt()
3988 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
3989 dwc->gadget->speed = USB_SPEED_FULL; in dwc3_gadget_conndone_interrupt()
3993 dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; in dwc3_gadget_conndone_interrupt()
3998 !dwc->usb2_gadget_lpm_disable && in dwc3_gadget_conndone_interrupt()
4001 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4003 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4005 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4008 reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold | in dwc3_gadget_conndone_interrupt()
4009 (dwc->is_utmi_l1_suspend << 4)); in dwc3_gadget_conndone_interrupt()
4017 WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum, in dwc3_gadget_conndone_interrupt()
4020 if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) in dwc3_gadget_conndone_interrupt()
4021 reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); in dwc3_gadget_conndone_interrupt()
4023 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4025 if (dwc->usb2_gadget_lpm_disable) { in dwc3_gadget_conndone_interrupt()
4026 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4028 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4031 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4033 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4036 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
4039 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4043 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
4046 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4059 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) in dwc3_gadget_wakeup_interrupt() argument
4066 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_gadget_wakeup_interrupt()
4067 spin_unlock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4068 dwc->gadget_driver->resume(dwc->gadget); in dwc3_gadget_wakeup_interrupt()
4069 spin_lock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4073 static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, in dwc3_gadget_linksts_change_interrupt() argument
4096 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_gadget_linksts_change_interrupt()
4099 if ((dwc->link_state == DWC3_LINK_STATE_U3) && in dwc3_gadget_linksts_change_interrupt()
4128 switch (dwc->link_state) { in dwc3_gadget_linksts_change_interrupt()
4131 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_linksts_change_interrupt()
4137 if (!dwc->u1u2) in dwc3_gadget_linksts_change_interrupt()
4138 dwc->u1u2 = reg & u1u2; in dwc3_gadget_linksts_change_interrupt()
4142 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_linksts_change_interrupt()
4153 if (dwc->speed == USB_SPEED_SUPER) in dwc3_gadget_linksts_change_interrupt()
4154 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4158 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4161 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4168 dwc->link_state = next; in dwc3_gadget_linksts_change_interrupt()
4171 static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, in dwc3_gadget_suspend_interrupt() argument
4176 if (dwc->link_state != next && next == DWC3_LINK_STATE_U3) in dwc3_gadget_suspend_interrupt()
4177 dwc3_suspend_gadget(dwc); in dwc3_gadget_suspend_interrupt()
4179 dwc->link_state = next; in dwc3_gadget_suspend_interrupt()
4182 static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc, in dwc3_gadget_hibernation_interrupt() argument
4200 if (is_ss ^ (dwc->speed == USB_SPEED_SUPER)) in dwc3_gadget_hibernation_interrupt()
4206 static void dwc3_gadget_interrupt(struct dwc3 *dwc, in dwc3_gadget_interrupt() argument
4211 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_interrupt()
4214 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_interrupt()
4217 dwc3_gadget_conndone_interrupt(dwc); in dwc3_gadget_interrupt()
4220 dwc3_gadget_wakeup_interrupt(dwc); in dwc3_gadget_interrupt()
4223 if (dev_WARN_ONCE(dwc->dev, !dwc->has_hibernation, in dwc3_gadget_interrupt()
4227 dwc3_gadget_hibernation_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4230 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4239 if (dwc->gadget->state >= USB_STATE_CONFIGURED) in dwc3_gadget_interrupt()
4240 dwc3_gadget_suspend_interrupt(dwc, in dwc3_gadget_interrupt()
4250 dev_WARN(dwc->dev, "UNKNOWN IRQ %d\n", event->type); in dwc3_gadget_interrupt()
4254 static void dwc3_process_event_entry(struct dwc3 *dwc, in dwc3_process_event_entry() argument
4257 trace_dwc3_event(event->raw, dwc); in dwc3_process_event_entry()
4260 dwc3_endpoint_interrupt(dwc, &event->depevt); in dwc3_process_event_entry()
4262 dwc3_gadget_interrupt(dwc, &event->devt); in dwc3_process_event_entry()
4264 dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); in dwc3_process_event_entry()
4269 struct dwc3 *dwc = evt->dwc; in dwc3_process_event_buf() local
4283 dwc3_process_event_entry(dwc, &event); in dwc3_process_event_buf()
4302 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_process_event_buf()
4305 if (dwc->imod_interval) { in dwc3_process_event_buf()
4306 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in dwc3_process_event_buf()
4307 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in dwc3_process_event_buf()
4319 struct dwc3 *dwc = evt->dwc; in dwc3_thread_interrupt() local
4324 spin_lock_irqsave(&dwc->lock, flags); in dwc3_thread_interrupt()
4326 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_thread_interrupt()
4334 struct dwc3 *dwc = evt->dwc; in dwc3_check_event_buf() local
4338 if (pm_runtime_suspended(dwc->dev)) { in dwc3_check_event_buf()
4339 pm_runtime_get(dwc->dev); in dwc3_check_event_buf()
4340 disable_irq_nosync(dwc->irq_gadget); in dwc3_check_event_buf()
4341 dwc->pending_events = true; in dwc3_check_event_buf()
4354 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_check_event_buf()
4363 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_check_event_buf()
4372 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); in dwc3_check_event_buf()
4384 static int dwc3_gadget_get_irq(struct dwc3 *dwc) in dwc3_gadget_get_irq() argument
4386 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_gadget_get_irq()
4427 int dwc3_gadget_init(struct dwc3 *dwc) in dwc3_gadget_init() argument
4433 irq = dwc3_gadget_get_irq(dwc); in dwc3_gadget_init()
4439 dwc->irq_gadget = irq; in dwc3_gadget_init()
4441 dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev, in dwc3_gadget_init()
4442 sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4443 &dwc->ep0_trb_addr, GFP_KERNEL); in dwc3_gadget_init()
4444 if (!dwc->ep0_trb) { in dwc3_gadget_init()
4445 dev_err(dwc->dev, "failed to allocate ep0 trb\n"); in dwc3_gadget_init()
4450 dwc->setup_buf = kzalloc(DWC3_EP0_SETUP_SIZE, GFP_KERNEL); in dwc3_gadget_init()
4451 if (!dwc->setup_buf) { in dwc3_gadget_init()
4456 dwc->bounce = dma_alloc_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, in dwc3_gadget_init()
4457 &dwc->bounce_addr, GFP_KERNEL); in dwc3_gadget_init()
4458 if (!dwc->bounce) { in dwc3_gadget_init()
4463 init_completion(&dwc->ep0_in_setup); in dwc3_gadget_init()
4464 dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); in dwc3_gadget_init()
4465 if (!dwc->gadget) { in dwc3_gadget_init()
4471 usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); in dwc3_gadget_init()
4472 dev = &dwc->gadget->dev; in dwc3_gadget_init()
4473 dev->platform_data = dwc; in dwc3_gadget_init()
4474 dwc->gadget->ops = &dwc3_gadget_ops; in dwc3_gadget_init()
4475 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_init()
4476 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_init()
4477 dwc->gadget->sg_supported = true; in dwc3_gadget_init()
4478 dwc->gadget->name = "dwc3-gadget"; in dwc3_gadget_init()
4479 dwc->gadget->lpm_capable = !dwc->usb2_gadget_lpm_disable; in dwc3_gadget_init()
4498 !dwc->dis_metastability_quirk) in dwc3_gadget_init()
4499 dev_info(dwc->dev, "changing max_speed on rev %08x\n", in dwc3_gadget_init()
4500 dwc->revision); in dwc3_gadget_init()
4502 dwc->gadget->max_speed = dwc->maximum_speed; in dwc3_gadget_init()
4503 dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; in dwc3_gadget_init()
4510 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); in dwc3_gadget_init()
4514 ret = usb_add_gadget(dwc->gadget); in dwc3_gadget_init()
4516 dev_err(dwc->dev, "failed to add gadget\n"); in dwc3_gadget_init()
4520 if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) in dwc3_gadget_init()
4521 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); in dwc3_gadget_init()
4523 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); in dwc3_gadget_init()
4528 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_init()
4530 usb_put_gadget(dwc->gadget); in dwc3_gadget_init()
4531 dwc->gadget = NULL; in dwc3_gadget_init()
4533 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_init()
4534 dwc->bounce_addr); in dwc3_gadget_init()
4537 kfree(dwc->setup_buf); in dwc3_gadget_init()
4540 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4541 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_init()
4549 void dwc3_gadget_exit(struct dwc3 *dwc) in dwc3_gadget_exit() argument
4551 if (!dwc->gadget) in dwc3_gadget_exit()
4554 usb_del_gadget(dwc->gadget); in dwc3_gadget_exit()
4555 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_exit()
4556 usb_put_gadget(dwc->gadget); in dwc3_gadget_exit()
4557 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_exit()
4558 dwc->bounce_addr); in dwc3_gadget_exit()
4559 kfree(dwc->setup_buf); in dwc3_gadget_exit()
4560 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_exit()
4561 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_exit()
4564 int dwc3_gadget_suspend(struct dwc3 *dwc) in dwc3_gadget_suspend() argument
4568 if (!dwc->gadget_driver) in dwc3_gadget_suspend()
4571 dwc3_gadget_run_stop(dwc, false, false); in dwc3_gadget_suspend()
4573 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_suspend()
4574 dwc3_disconnect_gadget(dwc); in dwc3_gadget_suspend()
4575 __dwc3_gadget_stop(dwc); in dwc3_gadget_suspend()
4576 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_suspend()
4581 int dwc3_gadget_resume(struct dwc3 *dwc) in dwc3_gadget_resume() argument
4585 if (!dwc->gadget_driver || !dwc->softconnect) in dwc3_gadget_resume()
4588 ret = __dwc3_gadget_start(dwc); in dwc3_gadget_resume()
4592 ret = dwc3_gadget_run_stop(dwc, true, false); in dwc3_gadget_resume()
4599 __dwc3_gadget_stop(dwc); in dwc3_gadget_resume()
4605 void dwc3_gadget_process_pending_events(struct dwc3 *dwc) in dwc3_gadget_process_pending_events() argument
4607 if (dwc->pending_events) { in dwc3_gadget_process_pending_events()
4608 dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_process_pending_events()
4609 dwc->pending_events = false; in dwc3_gadget_process_pending_events()
4610 enable_irq(dwc->irq_gadget); in dwc3_gadget_process_pending_events()