Lines Matching full:dwc

35  * @dwc: pointer to our context structure
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()
67 * @dwc: pointer to our context structure
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()
83 * @dwc: pointer to our context structure
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()
142 static void dwc3_ep0_reset_state(struct dwc3 *dwc) in dwc3_ep0_reset_state() argument
146 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_ep0_reset_state()
147 dir = !!dwc->ep0_expect_in; in dwc3_ep0_reset_state()
148 if (dwc->ep0state == EP0_DATA_PHASE) in dwc3_ep0_reset_state()
149 dwc3_ep0_end_control_data(dwc, dwc->eps[dir]); in dwc3_ep0_reset_state()
151 dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]); in dwc3_ep0_reset_state()
153 dwc->eps[0]->trb_enqueue = 0; in dwc3_ep0_reset_state()
154 dwc->eps[1]->trb_enqueue = 0; in dwc3_ep0_reset_state()
156 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_reset_state()
196 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_del_and_unmap_request() local
207 usb_gadget_unmap_request_by_dev(dwc->sysdev, in dwc3_gadget_del_and_unmap_request()
214 pm_runtime_put(dwc->dev); in dwc3_gadget_del_and_unmap_request()
230 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_giveback() local
235 spin_unlock(&dwc->lock); in dwc3_gadget_giveback()
237 spin_lock(&dwc->lock); in dwc3_gadget_giveback()
242 * @dwc: pointer to the controller context
246 * Caller should take care of locking. Issue @cmd with a given @param to @dwc
249 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, in dwc3_send_gadget_generic_command() argument
257 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); in dwc3_send_gadget_generic_command()
258 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); in dwc3_send_gadget_generic_command()
261 reg = dwc3_readl(dwc->regs, DWC3_DGCMD); in dwc3_send_gadget_generic_command()
280 static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async);
312 struct dwc3 *dwc = dep->dwc; in dwc3_send_gadget_ep_cmd() local
330 if (dwc->gadget->speed <= USB_SPEED_HIGH || in dwc3_send_gadget_ep_cmd()
332 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
344 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
399 dev_WARN(dwc->dev, "No resource for %s\n", in dwc3_send_gadget_ep_cmd()
418 dev_WARN(dwc->dev, "UNKNOWN cmd status\n"); in dwc3_send_gadget_ep_cmd()
446 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
448 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
456 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd() local
470 (dwc->gadget->speed >= USB_SPEED_SUPER)) in dwc3_send_clear_stall_ep_cmd()
488 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool() local
493 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
497 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
507 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool() local
509 dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, in dwc3_free_trb_pool()
539 * @dwc: pointer to the DWC3 context
548 int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index) in dwc3_gadget_start_config() argument
562 ret = dwc3_send_gadget_ep_cmd(dwc->eps[0], cmd, &params); in dwc3_gadget_start_config()
567 for (i = resource_index; i < dwc->num_eps && dwc->eps[i]; i++) in dwc3_gadget_start_config()
568 dwc->eps[i]->flags &= ~DWC3_EP_RESOURCE_ALLOCATED; in dwc3_gadget_start_config()
578 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config() local
589 if (dwc->gadget->speed >= USB_SPEED_SUPER) { in dwc3_gadget_set_ep_config()
644 dwc->gadget->speed == USB_SPEED_FULL) in dwc3_gadget_set_ep_config()
657 * @dwc: pointer to the DWC3 context
672 static int dwc3_gadget_calc_tx_fifo_size(struct dwc3 *dwc, int mult) in dwc3_gadget_calc_tx_fifo_size() argument
678 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_calc_tx_fifo_size()
692 * @dwc: pointer to the DWC3 context
694 static int dwc3_gadget_calc_ram_depth(struct dwc3 *dwc) in dwc3_gadget_calc_ram_depth() argument
701 is_single_port_ram = DWC3_SPRAM_TYPE(dwc->hwparams.hwparams1); in dwc3_gadget_calc_ram_depth()
707 ram_depth = is_single_port_ram ? DWC3_RAM0_DEPTH(dwc->hwparams.hwparams6) : in dwc3_gadget_calc_ram_depth()
708 DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_calc_ram_depth()
719 reg = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_calc_ram_depth()
730 * @dwc: pointer to the DWC3 context
735 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) in dwc3_gadget_clear_tx_fifos() argument
742 if (!dwc->do_fifo_resize) in dwc3_gadget_clear_tx_fifos()
746 dep = dwc->eps[1]; in dwc3_gadget_clear_tx_fifos()
747 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_clear_tx_fifos()
753 dwc->last_fifo_depth = fifo_depth; in dwc3_gadget_clear_tx_fifos()
755 for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); in dwc3_gadget_clear_tx_fifos()
757 dep = dwc->eps[num]; in dwc3_gadget_clear_tx_fifos()
760 dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & in dwc3_gadget_clear_tx_fifos()
763 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1), size); in dwc3_gadget_clear_tx_fifos()
766 dwc->num_ep_resized = 0; in dwc3_gadget_clear_tx_fifos()
771 * @dwc: pointer to our context structure
792 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_resize_tx_fifos() local
803 if (!dwc->do_fifo_resize) in dwc3_gadget_resize_tx_fifos()
814 ram_depth = dwc3_gadget_calc_ram_depth(dwc); in dwc3_gadget_resize_tx_fifos()
824 num_fifos = dwc->tx_fifo_resize_max_num; in dwc3_gadget_resize_tx_fifos()
827 fifo = dwc3_gadget_calc_tx_fifo_size(dwc, 1); in dwc3_gadget_resize_tx_fifos()
830 num_in_ep = dwc->max_cfg_eps; in dwc3_gadget_resize_tx_fifos()
831 num_in_ep -= dwc->num_ep_resized; in dwc3_gadget_resize_tx_fifos()
835 remaining = ram_depth - min_depth - dwc->last_fifo_depth; in dwc3_gadget_resize_tx_fifos()
851 tmp = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_resize_tx_fifos()
854 fifo_size |= (fifo_0_start + (dwc->last_fifo_depth << 16)); in dwc3_gadget_resize_tx_fifos()
856 dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
858 dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
861 if (dwc->last_fifo_depth >= ram_depth) { in dwc3_gadget_resize_tx_fifos()
862 dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n", in dwc3_gadget_resize_tx_fifos()
863 dwc->last_fifo_depth, ram_depth, in dwc3_gadget_resize_tx_fifos()
870 dwc->last_fifo_depth -= fifo_size; in dwc3_gadget_resize_tx_fifos()
874 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1), fifo_size); in dwc3_gadget_resize_tx_fifos()
876 dwc->num_ep_resized++; in dwc3_gadget_resize_tx_fifos()
892 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable() local
920 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_enable()
922 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_enable()
994 !(dwc->hwparams.hwparams9 & in __dwc3_gadget_ep_enable()
1006 void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) in dwc3_remove_requests() argument
1048 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable() local
1058 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_disable()
1060 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_disable()
1062 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in __dwc3_gadget_ep_disable()
1104 struct dwc3 *dwc; in dwc3_gadget_ep_enable() local
1119 dwc = dep->dwc; in dwc3_gadget_ep_enable()
1121 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
1126 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1128 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1136 struct dwc3 *dwc; in dwc3_gadget_ep_disable() local
1146 dwc = dep->dwc; in dwc3_gadget_ep_disable()
1148 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
1153 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1155 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1261 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb() local
1262 struct usb_gadget *gadget = dwc->gadget; in dwc3_prepare_one_trb()
1266 dma = dep->dwc->bounce_addr; in dwc3_prepare_one_trb()
1347 dev_WARN(dwc->dev, "Unknown endpoint type %d\n", in dwc3_prepare_one_trb()
1364 if (dep->stream_capable && DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1373 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1601 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in dwc3_prepare_trbs()
1606 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs() local
1608 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, in dwc3_prepare_trbs()
1635 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_trbs()
1713 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in __dwc3_gadget_kick_transfer()
1719 static int __dwc3_gadget_get_frame(struct dwc3 *dwc) in __dwc3_gadget_get_frame() argument
1723 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_get_frame()
1756 if (ret == -ETIMEDOUT && dep->dwc->ep0state != EP0_SETUP_PHASE) { in __dwc3_stop_active_transfer()
1833 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1834 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1890 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc() local
1900 if (!dwc->dis_start_transfer_quirk && in __dwc3_gadget_start_isoc()
1903 if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1908 dwc->gadget->speed >= USB_SPEED_HIGH) { in __dwc3_gadget_start_isoc()
1909 u32 frame = __dwc3_gadget_get_frame(dwc); in __dwc3_gadget_start_isoc()
1955 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue() local
1957 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in __dwc3_gadget_ep_queue()
1958 dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", in __dwc3_gadget_ep_queue()
1972 pm_runtime_get(dwc->dev); in __dwc3_gadget_ep_queue()
2024 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue() local
2030 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2032 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2069 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_cleanup_cancelled_requests() local
2085 dev_err(dwc->dev, "request cancelled with wrong reason:%d\n", req->status); in dwc3_gadget_ep_cleanup_cancelled_requests()
2105 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue() local
2112 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2131 dwc3_ep0_reset_state(dwc); in dwc3_gadget_ep_dequeue()
2157 dev_err(dwc->dev, "request %pK was not queued to %s\n", in dwc3_gadget_ep_dequeue()
2161 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2169 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt() local
2175 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
2190 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
2203 dev_err(dwc->dev, "failed to set STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2227 dwc->clear_stall_protocol = dep->number; in __dwc3_gadget_ep_set_halt()
2236 dev_err(dwc->dev, "failed to clear STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2256 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt() local
2262 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2264 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2272 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge() local
2276 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2283 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2320 static void dwc3_gadget_enable_linksts_evts(struct dwc3 *dwc, bool set) in dwc3_gadget_enable_linksts_evts() argument
2327 reg = dwc3_readl(dwc->regs, DWC3_DEVTEN); in dwc3_gadget_enable_linksts_evts()
2333 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_linksts_evts()
2338 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_get_frame() local
2340 return __dwc3_gadget_get_frame(dwc); in dwc3_gadget_get_frame()
2343 static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async) in __dwc3_gadget_wakeup() argument
2358 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2375 dwc3_gadget_enable_linksts_evts(dwc, true); in __dwc3_gadget_wakeup()
2377 ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV); in __dwc3_gadget_wakeup()
2379 dev_err(dwc->dev, "failed to put link in Recovery\n"); in __dwc3_gadget_wakeup()
2380 dwc3_gadget_enable_linksts_evts(dwc, false); in __dwc3_gadget_wakeup()
2387 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in __dwc3_gadget_wakeup()
2389 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in __dwc3_gadget_wakeup()
2403 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2411 dev_err(dwc->dev, "failed to send remote wakeup\n"); in __dwc3_gadget_wakeup()
2420 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_wakeup() local
2424 if (!dwc->wakeup_configured) { in dwc3_gadget_wakeup()
2425 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_wakeup()
2429 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_wakeup()
2430 if (!dwc->gadget->wakeup_armed) { in dwc3_gadget_wakeup()
2431 dev_err(dwc->dev, "not armed for remote wakeup\n"); in dwc3_gadget_wakeup()
2432 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2435 ret = __dwc3_gadget_wakeup(dwc, true); in dwc3_gadget_wakeup()
2437 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2442 static void dwc3_resume_gadget(struct dwc3 *dwc);
2446 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_func_wakeup() local
2451 if (!dwc->wakeup_configured) { in dwc3_gadget_func_wakeup()
2452 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_func_wakeup()
2456 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2461 link_state = dwc3_gadget_get_link_state(dwc); in dwc3_gadget_func_wakeup()
2463 ret = __dwc3_gadget_wakeup(dwc, false); in dwc3_gadget_func_wakeup()
2465 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2468 dwc3_resume_gadget(dwc); in dwc3_gadget_func_wakeup()
2469 dwc->suspended = false; in dwc3_gadget_func_wakeup()
2470 dwc->link_state = DWC3_LINK_STATE_U0; in dwc3_gadget_func_wakeup()
2473 ret = dwc3_send_gadget_generic_command(dwc, DWC3_DGCMD_DEV_NOTIFICATION, in dwc3_gadget_func_wakeup()
2477 dev_err(dwc->dev, "function remote wakeup failed, ret:%d\n", ret); in dwc3_gadget_func_wakeup()
2479 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2486 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_remote_wakeup() local
2489 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2490 dwc->wakeup_configured = !!set; in dwc3_gadget_set_remote_wakeup()
2491 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2499 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_selfpowered() local
2502 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2504 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2509 static void dwc3_stop_active_transfers(struct dwc3 *dwc) in dwc3_stop_active_transfers() argument
2513 for (epnum = 2; epnum < dwc->num_eps; epnum++) { in dwc3_stop_active_transfers()
2516 dep = dwc->eps[epnum]; in dwc3_stop_active_transfers()
2520 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in dwc3_stop_active_transfers()
2524 static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) in __dwc3_gadget_set_ssp_rate() argument
2526 enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2530 ssp_rate = dwc->max_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2532 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_ssp_rate()
2538 else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) in __dwc3_gadget_set_ssp_rate()
2542 dwc->max_ssp_rate != USB_SSP_GEN_2x1) in __dwc3_gadget_set_ssp_rate()
2545 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_ssp_rate()
2548 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) in __dwc3_gadget_set_speed() argument
2553 speed = dwc->gadget_max_speed; in __dwc3_gadget_set_speed()
2554 if (speed == USB_SPEED_UNKNOWN || speed > dwc->maximum_speed) in __dwc3_gadget_set_speed()
2555 speed = dwc->maximum_speed; in __dwc3_gadget_set_speed()
2559 __dwc3_gadget_set_ssp_rate(dwc); in __dwc3_gadget_set_speed()
2563 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_speed()
2580 !dwc->dis_metastability_quirk) { in __dwc3_gadget_set_speed()
2600 dev_err(dwc->dev, "invalid speed (%d)\n", speed); in __dwc3_gadget_set_speed()
2614 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_speed()
2617 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) in dwc3_gadget_run_stop() argument
2622 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_run_stop()
2625 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_run_stop()
2636 __dwc3_gadget_set_speed(dwc); in dwc3_gadget_run_stop()
2637 dwc->pullups_connected = true; in dwc3_gadget_run_stop()
2641 dwc->pullups_connected = false; in dwc3_gadget_run_stop()
2644 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_run_stop()
2648 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_run_stop()
2658 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
2659 static void __dwc3_gadget_stop(struct dwc3 *dwc);
2660 static int __dwc3_gadget_start(struct dwc3 *dwc);
2662 static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) in dwc3_gadget_soft_disconnect() argument
2667 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2668 if (!dwc->pullups_connected) { in dwc3_gadget_soft_disconnect()
2669 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2673 dwc->connected = false; in dwc3_gadget_soft_disconnect()
2679 if (dwc->delayed_status) in dwc3_gadget_soft_disconnect()
2680 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_soft_disconnect()
2689 dwc3_stop_active_transfers(dwc); in dwc3_gadget_soft_disconnect()
2690 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2699 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_soft_disconnect()
2700 reinit_completion(&dwc->ep0_in_setup); in dwc3_gadget_soft_disconnect()
2702 ret = wait_for_completion_timeout(&dwc->ep0_in_setup, in dwc3_gadget_soft_disconnect()
2705 dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); in dwc3_gadget_soft_disconnect()
2706 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2707 dwc3_ep0_reset_state(dwc); in dwc3_gadget_soft_disconnect()
2708 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2719 ret = dwc3_gadget_run_stop(dwc, false); in dwc3_gadget_soft_disconnect()
2727 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2728 __dwc3_gadget_stop(dwc); in dwc3_gadget_soft_disconnect()
2729 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2734 static int dwc3_gadget_soft_connect(struct dwc3 *dwc) in dwc3_gadget_soft_connect() argument
2744 ret = dwc3_core_soft_reset(dwc); in dwc3_gadget_soft_connect()
2748 dwc3_event_buffers_setup(dwc); in dwc3_gadget_soft_connect()
2749 __dwc3_gadget_start(dwc); in dwc3_gadget_soft_connect()
2750 return dwc3_gadget_run_stop(dwc, true); in dwc3_gadget_soft_connect()
2755 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_pullup() local
2760 dwc->softconnect = is_on; in dwc3_gadget_pullup()
2768 pm_runtime_barrier(dwc->dev); in dwc3_gadget_pullup()
2769 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_pullup()
2778 ret = pm_runtime_get_sync(dwc->dev); in dwc3_gadget_pullup()
2780 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2782 pm_runtime_set_suspended(dwc->dev); in dwc3_gadget_pullup()
2786 if (dwc->pullups_connected == is_on) { in dwc3_gadget_pullup()
2787 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2791 synchronize_irq(dwc->irq_gadget); in dwc3_gadget_pullup()
2794 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_pullup()
2796 ret = dwc3_gadget_soft_connect(dwc); in dwc3_gadget_pullup()
2798 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2803 static void dwc3_gadget_enable_irq(struct dwc3 *dwc) in dwc3_gadget_enable_irq() argument
2823 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_irq()
2826 static void dwc3_gadget_disable_irq(struct dwc3 *dwc) in dwc3_gadget_disable_irq() argument
2829 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); in dwc3_gadget_disable_irq()
2837 * @dwc: pointer to our context structure
2856 static void dwc3_gadget_setup_nump(struct dwc3 *dwc) in dwc3_gadget_setup_nump() argument
2863 ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_setup_nump()
2864 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_setup_nump()
2870 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_setup_nump()
2873 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_setup_nump()
2876 static int __dwc3_gadget_start(struct dwc3 *dwc) in __dwc3_gadget_start() argument
2883 * Use IMOD if enabled via dwc->imod_interval. Otherwise, if in __dwc3_gadget_start()
2886 if (dwc->imod_interval) { in __dwc3_gadget_start()
2887 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in __dwc3_gadget_start()
2888 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in __dwc3_gadget_start()
2889 } else if (dwc3_has_imod(dwc)) { in __dwc3_gadget_start()
2890 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), 0); in __dwc3_gadget_start()
2900 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in __dwc3_gadget_start()
2906 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in __dwc3_gadget_start()
2908 dwc3_gadget_setup_nump(dwc); in __dwc3_gadget_start()
2917 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_start()
2919 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_start()
2922 if (DWC3_MST_CAPABLE(&dwc->hwparams)) { in __dwc3_gadget_start()
2923 reg = dwc3_readl(dwc->regs, DWC3_DCFG1); in __dwc3_gadget_start()
2925 dwc3_writel(dwc->regs, DWC3_DCFG1, reg); in __dwc3_gadget_start()
2931 ret = dwc3_gadget_start_config(dwc, 0); in __dwc3_gadget_start()
2933 dev_err(dwc->dev, "failed to config endpoints\n"); in __dwc3_gadget_start()
2937 dep = dwc->eps[0]; in __dwc3_gadget_start()
2941 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2945 dep = dwc->eps[1]; in __dwc3_gadget_start()
2949 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2954 dwc->ep0state = EP0_SETUP_PHASE; in __dwc3_gadget_start()
2955 dwc->ep0_bounced = false; in __dwc3_gadget_start()
2956 dwc->link_state = DWC3_LINK_STATE_SS_DIS; in __dwc3_gadget_start()
2957 dwc->delayed_status = false; in __dwc3_gadget_start()
2958 dwc3_ep0_out_start(dwc); in __dwc3_gadget_start()
2960 dwc3_gadget_enable_irq(dwc); in __dwc3_gadget_start()
2961 dwc3_enable_susphy(dwc, true); in __dwc3_gadget_start()
2966 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_start()
2975 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_start() local
2980 irq = dwc->irq_gadget; in dwc3_gadget_start()
2982 IRQF_SHARED, "dwc3", dwc->ev_buf); in dwc3_gadget_start()
2984 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_gadget_start()
2989 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_start()
2990 dwc->gadget_driver = driver; in dwc3_gadget_start()
2991 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
2993 if (dwc->sys_wakeup) in dwc3_gadget_start()
2994 device_wakeup_enable(dwc->sysdev); in dwc3_gadget_start()
2999 static void __dwc3_gadget_stop(struct dwc3 *dwc) in __dwc3_gadget_stop() argument
3001 dwc3_gadget_disable_irq(dwc); in __dwc3_gadget_stop()
3002 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_stop()
3003 __dwc3_gadget_ep_disable(dwc->eps[1]); in __dwc3_gadget_stop()
3008 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_stop() local
3011 if (dwc->sys_wakeup) in dwc3_gadget_stop()
3012 device_wakeup_disable(dwc->sysdev); in dwc3_gadget_stop()
3014 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_stop()
3015 dwc->gadget_driver = NULL; in dwc3_gadget_stop()
3016 dwc->max_cfg_eps = 0; in dwc3_gadget_stop()
3017 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_stop()
3019 free_irq(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_stop()
3027 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_config_params() local
3033 if (!dwc->dis_enblslpm_quirk) { in dwc3_gadget_config_params()
3044 if (dwc->is_utmi_l1_suspend) in dwc3_gadget_config_params()
3046 clamp_t(u8, dwc->hird_threshold, 2, 15); in dwc3_gadget_config_params()
3050 if (dwc->dis_u1_entry_quirk) in dwc3_gadget_config_params()
3056 if (dwc->dis_u2_entry_quirk) in dwc3_gadget_config_params()
3066 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_speed() local
3069 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_speed()
3070 dwc->gadget_max_speed = speed; in dwc3_gadget_set_speed()
3071 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_speed()
3077 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_ssp_rate() local
3080 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3081 dwc->gadget_max_speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_set_ssp_rate()
3082 dwc->gadget_ssp_rate = rate; in dwc3_gadget_set_ssp_rate()
3083 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3088 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_vbus_draw() local
3092 if (dwc->usb2_phy) in dwc3_gadget_vbus_draw()
3093 return usb_phy_set_power(dwc->usb2_phy, mA); in dwc3_gadget_vbus_draw()
3095 if (!dwc->usb_psy) in dwc3_gadget_vbus_draw()
3099 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_gadget_vbus_draw()
3116 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_check_config() local
3122 if (!dwc->do_fifo_resize) in dwc3_gadget_check_config()
3131 if (ep_num <= dwc->max_cfg_eps) in dwc3_gadget_check_config()
3135 dwc->max_cfg_eps = ep_num; in dwc3_gadget_check_config()
3137 fifo_size = dwc3_gadget_calc_tx_fifo_size(dwc, dwc->max_cfg_eps); in dwc3_gadget_check_config()
3139 fifo_size += dwc->max_cfg_eps; in dwc3_gadget_check_config()
3142 ram_depth = dwc3_gadget_calc_ram_depth(dwc); in dwc3_gadget_check_config()
3151 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_async_callbacks() local
3154 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3155 dwc->async_callbacks = enable; in dwc3_gadget_async_callbacks()
3156 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3180 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint() local
3186 dwc->gadget->ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
3195 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint() local
3200 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_in_endpoint()
3205 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
3234 &dwc->gadget->ep_list); in dwc3_gadget_init_in_endpoint()
3244 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint() local
3248 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_out_endpoint()
3254 size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0)); in dwc3_gadget_init_out_endpoint()
3281 &dwc->gadget->ep_list); in dwc3_gadget_init_out_endpoint()
3289 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) in dwc3_gadget_init_endpoint() argument
3300 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
3303 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
3304 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
3340 static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) in dwc3_gadget_init_endpoints() argument
3344 INIT_LIST_HEAD(&dwc->gadget->ep_list); in dwc3_gadget_init_endpoints()
3349 ret = dwc3_gadget_init_endpoint(dwc, epnum); in dwc3_gadget_init_endpoints()
3357 static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) in dwc3_gadget_free_endpoints() argument
3363 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
3429 if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && in dwc3_gadget_ep_reclaim_completed_trb()
3430 trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { in dwc3_gadget_ep_reclaim_completed_trb()
3580 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_should_continue() local
3582 if (!dep->endpoint.desc || !dwc->pullups_connected || in dwc3_gadget_ep_should_continue()
3583 !dwc->connected) in dwc3_gadget_ep_should_continue()
3609 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_trbs_complete() local
3638 dep = dwc->eps[i]; in dwc3_gadget_endpoint_trbs_complete()
3647 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_endpoint_trbs_complete()
3648 reg |= dwc->u1u2; in dwc3_gadget_endpoint_trbs_complete()
3649 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_endpoint_trbs_complete()
3651 dwc->u1u2 = 0; in dwc3_gadget_endpoint_trbs_complete()
3731 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_command_complete() local
3735 struct usb_ep *ep0 = &dwc->eps[0]->endpoint; in dwc3_gadget_endpoint_command_complete()
3737 dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); in dwc3_gadget_endpoint_command_complete()
3738 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3744 if (dwc->clear_stall_protocol == dep->number) in dwc3_gadget_endpoint_command_complete()
3745 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_endpoint_command_complete()
3758 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_stream_event() local
3786 (!DWC3_MST_CAPABLE(&dwc->hwparams) && in dwc3_gadget_endpoint_stream_event()
3807 dwc3_send_gadget_generic_command(dwc, cmd, dep->number); in dwc3_gadget_endpoint_stream_event()
3820 static void dwc3_endpoint_interrupt(struct dwc3 *dwc, in dwc3_endpoint_interrupt() argument
3826 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
3839 dwc3_ep0_interrupt(dwc, event); in dwc3_endpoint_interrupt()
3862 dev_err(dwc->dev, "unknown endpoint event %d\n", event->endpoint_event); in dwc3_endpoint_interrupt()
3867 static void dwc3_disconnect_gadget(struct dwc3 *dwc) in dwc3_disconnect_gadget() argument
3869 if (dwc->async_callbacks && dwc->gadget_driver->disconnect) { in dwc3_disconnect_gadget()
3870 spin_unlock(&dwc->lock); in dwc3_disconnect_gadget()
3871 dwc->gadget_driver->disconnect(dwc->gadget); in dwc3_disconnect_gadget()
3872 spin_lock(&dwc->lock); in dwc3_disconnect_gadget()
3876 static void dwc3_suspend_gadget(struct dwc3 *dwc) in dwc3_suspend_gadget() argument
3878 if (dwc->async_callbacks && dwc->gadget_driver->suspend) { in dwc3_suspend_gadget()
3879 spin_unlock(&dwc->lock); in dwc3_suspend_gadget()
3880 dwc->gadget_driver->suspend(dwc->gadget); in dwc3_suspend_gadget()
3881 spin_lock(&dwc->lock); in dwc3_suspend_gadget()
3885 static void dwc3_resume_gadget(struct dwc3 *dwc) in dwc3_resume_gadget() argument
3887 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_resume_gadget()
3888 spin_unlock(&dwc->lock); in dwc3_resume_gadget()
3889 dwc->gadget_driver->resume(dwc->gadget); in dwc3_resume_gadget()
3890 spin_lock(&dwc->lock); in dwc3_resume_gadget()
3894 static void dwc3_reset_gadget(struct dwc3 *dwc) in dwc3_reset_gadget() argument
3896 if (!dwc->gadget_driver) in dwc3_reset_gadget()
3899 if (dwc->async_callbacks && dwc->gadget->speed != USB_SPEED_UNKNOWN) { in dwc3_reset_gadget()
3900 spin_unlock(&dwc->lock); in dwc3_reset_gadget()
3901 usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); in dwc3_reset_gadget()
3902 spin_lock(&dwc->lock); in dwc3_reset_gadget()
3909 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer() local
3917 if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) in dwc3_stop_active_transfer()
3934 if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { in dwc3_stop_active_transfer()
3973 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) in dwc3_clear_stall_all_ep() argument
3981 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
3995 static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) in dwc3_gadget_disconnect_interrupt() argument
3999 dwc->suspended = false; in dwc3_gadget_disconnect_interrupt()
4001 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); in dwc3_gadget_disconnect_interrupt()
4003 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_disconnect_interrupt()
4006 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_disconnect_interrupt()
4008 dwc->connected = false; in dwc3_gadget_disconnect_interrupt()
4010 dwc3_disconnect_gadget(dwc); in dwc3_gadget_disconnect_interrupt()
4012 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_disconnect_interrupt()
4013 dwc->setup_packet_pending = false; in dwc3_gadget_disconnect_interrupt()
4014 dwc->gadget->wakeup_armed = false; in dwc3_gadget_disconnect_interrupt()
4015 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_disconnect_interrupt()
4016 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_disconnect_interrupt()
4018 dwc3_ep0_reset_state(dwc); in dwc3_gadget_disconnect_interrupt()
4023 * interrupt to set dwc->connected to FALSE. in dwc3_gadget_disconnect_interrupt()
4025 pm_request_idle(dwc->dev); in dwc3_gadget_disconnect_interrupt()
4028 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) in dwc3_gadget_reset_interrupt() argument
4032 dwc->suspended = false; in dwc3_gadget_reset_interrupt()
4041 dwc->connected = false; in dwc3_gadget_reset_interrupt()
4070 if (dwc->setup_packet_pending) in dwc3_gadget_reset_interrupt()
4071 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_reset_interrupt()
4074 dwc3_reset_gadget(dwc); in dwc3_gadget_reset_interrupt()
4081 dwc3_ep0_reset_state(dwc); in dwc3_gadget_reset_interrupt()
4089 dwc3_stop_active_transfers(dwc); in dwc3_gadget_reset_interrupt()
4090 dwc->connected = true; in dwc3_gadget_reset_interrupt()
4092 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_reset_interrupt()
4094 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_reset_interrupt()
4095 dwc->test_mode = false; in dwc3_gadget_reset_interrupt()
4096 dwc->gadget->wakeup_armed = false; in dwc3_gadget_reset_interrupt()
4097 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_reset_interrupt()
4098 dwc3_clear_stall_all_ep(dwc); in dwc3_gadget_reset_interrupt()
4101 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_reset_interrupt()
4103 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_reset_interrupt()
4106 static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) in dwc3_gadget_conndone_interrupt() argument
4114 if (!dwc->softconnect) in dwc3_gadget_conndone_interrupt()
4117 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_conndone_interrupt()
4119 dwc->speed = speed; in dwc3_gadget_conndone_interrupt()
4124 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_conndone_interrupt()
4138 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4139 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4142 dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; in dwc3_gadget_conndone_interrupt()
4144 dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; in dwc3_gadget_conndone_interrupt()
4161 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_conndone_interrupt()
4164 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4165 dwc->gadget->speed = USB_SPEED_SUPER; in dwc3_gadget_conndone_interrupt()
4168 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4169 dwc->gadget->ssp_rate = USB_SSP_GEN_1x2; in dwc3_gadget_conndone_interrupt()
4174 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4175 dwc->gadget->speed = USB_SPEED_HIGH; in dwc3_gadget_conndone_interrupt()
4179 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4180 dwc->gadget->speed = USB_SPEED_FULL; in dwc3_gadget_conndone_interrupt()
4184 dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; in dwc3_gadget_conndone_interrupt()
4189 !dwc->usb2_gadget_lpm_disable && in dwc3_gadget_conndone_interrupt()
4192 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4194 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4196 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4199 reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold | in dwc3_gadget_conndone_interrupt()
4200 (dwc->is_utmi_l1_suspend << 4)); in dwc3_gadget_conndone_interrupt()
4208 WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum, in dwc3_gadget_conndone_interrupt()
4211 if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) { in dwc3_gadget_conndone_interrupt()
4213 reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); in dwc3_gadget_conndone_interrupt()
4216 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4218 if (dwc->usb2_gadget_lpm_disable) { in dwc3_gadget_conndone_interrupt()
4219 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4221 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4224 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4226 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4229 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
4232 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4236 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
4239 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4252 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo) in dwc3_gadget_wakeup_interrupt() argument
4254 dwc->suspended = false; in dwc3_gadget_wakeup_interrupt()
4261 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_gadget_wakeup_interrupt()
4262 spin_unlock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4263 dwc->gadget_driver->resume(dwc->gadget); in dwc3_gadget_wakeup_interrupt()
4264 spin_lock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4267 dwc->link_state = evtinfo & DWC3_LINK_STATE_MASK; in dwc3_gadget_wakeup_interrupt()
4270 static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, in dwc3_gadget_linksts_change_interrupt() argument
4293 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_gadget_linksts_change_interrupt()
4296 if ((dwc->link_state == DWC3_LINK_STATE_U3) && in dwc3_gadget_linksts_change_interrupt()
4325 switch (dwc->link_state) { in dwc3_gadget_linksts_change_interrupt()
4328 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_linksts_change_interrupt()
4334 if (!dwc->u1u2) in dwc3_gadget_linksts_change_interrupt()
4335 dwc->u1u2 = reg & u1u2; in dwc3_gadget_linksts_change_interrupt()
4339 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_linksts_change_interrupt()
4350 if (dwc->gadget->wakeup_armed) { in dwc3_gadget_linksts_change_interrupt()
4351 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_linksts_change_interrupt()
4352 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4353 dwc->suspended = false; in dwc3_gadget_linksts_change_interrupt()
4357 if (dwc->speed == USB_SPEED_SUPER) in dwc3_gadget_linksts_change_interrupt()
4358 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4362 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4365 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4372 dwc->link_state = next; in dwc3_gadget_linksts_change_interrupt()
4375 static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, in dwc3_gadget_suspend_interrupt() argument
4380 if (!dwc->suspended && next == DWC3_LINK_STATE_U3) { in dwc3_gadget_suspend_interrupt()
4381 dwc->suspended = true; in dwc3_gadget_suspend_interrupt()
4382 dwc3_suspend_gadget(dwc); in dwc3_gadget_suspend_interrupt()
4385 dwc->link_state = next; in dwc3_gadget_suspend_interrupt()
4388 static void dwc3_gadget_interrupt(struct dwc3 *dwc, in dwc3_gadget_interrupt() argument
4393 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_interrupt()
4396 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_interrupt()
4399 dwc3_gadget_conndone_interrupt(dwc); in dwc3_gadget_interrupt()
4402 dwc3_gadget_wakeup_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4405 dev_WARN_ONCE(dwc->dev, true, "unexpected hibernation event\n"); in dwc3_gadget_interrupt()
4408 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4413 dwc3_gadget_suspend_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4421 dev_WARN(dwc->dev, "UNKNOWN IRQ %d\n", event->type); in dwc3_gadget_interrupt()
4425 static void dwc3_process_event_entry(struct dwc3 *dwc, in dwc3_process_event_entry() argument
4428 trace_dwc3_event(event->raw, dwc); in dwc3_process_event_entry()
4431 dwc3_endpoint_interrupt(dwc, &event->depevt); in dwc3_process_event_entry()
4433 dwc3_gadget_interrupt(dwc, &event->devt); in dwc3_process_event_entry()
4435 dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); in dwc3_process_event_entry()
4440 struct dwc3 *dwc = evt->dwc; in dwc3_process_event_buf() local
4454 dwc3_process_event_entry(dwc, &event); in dwc3_process_event_buf()
4473 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_process_event_buf()
4476 if (dwc->imod_interval) { in dwc3_process_event_buf()
4477 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in dwc3_process_event_buf()
4478 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in dwc3_process_event_buf()
4490 struct dwc3 *dwc = evt->dwc; in dwc3_thread_interrupt() local
4495 spin_lock_irqsave(&dwc->lock, flags); in dwc3_thread_interrupt()
4497 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_thread_interrupt()
4505 struct dwc3 *dwc = evt->dwc; in dwc3_check_event_buf() local
4509 if (pm_runtime_suspended(dwc->dev)) { in dwc3_check_event_buf()
4510 dwc->pending_events = true; in dwc3_check_event_buf()
4516 pm_runtime_get(dwc->dev); in dwc3_check_event_buf()
4517 disable_irq_nosync(dwc->irq_gadget); in dwc3_check_event_buf()
4530 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_check_event_buf()
4539 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_check_event_buf()
4548 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); in dwc3_check_event_buf()
4560 static int dwc3_gadget_get_irq(struct dwc3 *dwc) in dwc3_gadget_get_irq() argument
4562 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_gadget_get_irq()
4594 * @dwc: pointer to our controller context structure
4598 int dwc3_gadget_init(struct dwc3 *dwc) in dwc3_gadget_init() argument
4604 irq = dwc3_gadget_get_irq(dwc); in dwc3_gadget_init()
4610 dwc->irq_gadget = irq; in dwc3_gadget_init()
4612 dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev, in dwc3_gadget_init()
4613 sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4614 &dwc->ep0_trb_addr, GFP_KERNEL); in dwc3_gadget_init()
4615 if (!dwc->ep0_trb) { in dwc3_gadget_init()
4616 dev_err(dwc->dev, "failed to allocate ep0 trb\n"); in dwc3_gadget_init()
4621 dwc->setup_buf = kzalloc(DWC3_EP0_SETUP_SIZE, GFP_KERNEL); in dwc3_gadget_init()
4622 if (!dwc->setup_buf) { in dwc3_gadget_init()
4627 dwc->bounce = dma_alloc_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, in dwc3_gadget_init()
4628 &dwc->bounce_addr, GFP_KERNEL); in dwc3_gadget_init()
4629 if (!dwc->bounce) { in dwc3_gadget_init()
4634 init_completion(&dwc->ep0_in_setup); in dwc3_gadget_init()
4635 dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); in dwc3_gadget_init()
4636 if (!dwc->gadget) { in dwc3_gadget_init()
4642 usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); in dwc3_gadget_init()
4643 dev = &dwc->gadget->dev; in dwc3_gadget_init()
4644 dev->platform_data = dwc; in dwc3_gadget_init()
4645 dwc->gadget->ops = &dwc3_gadget_ops; in dwc3_gadget_init()
4646 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_init()
4647 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_init()
4648 dwc->gadget->sg_supported = true; in dwc3_gadget_init()
4649 dwc->gadget->name = "dwc3-gadget"; in dwc3_gadget_init()
4650 dwc->gadget->lpm_capable = !dwc->usb2_gadget_lpm_disable; in dwc3_gadget_init()
4651 dwc->gadget->wakeup_capable = true; in dwc3_gadget_init()
4670 !dwc->dis_metastability_quirk) in dwc3_gadget_init()
4671 dev_info(dwc->dev, "changing max_speed on rev %08x\n", in dwc3_gadget_init()
4672 dwc->revision); in dwc3_gadget_init()
4674 dwc->gadget->max_speed = dwc->maximum_speed; in dwc3_gadget_init()
4675 dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; in dwc3_gadget_init()
4682 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); in dwc3_gadget_init()
4686 ret = usb_add_gadget(dwc->gadget); in dwc3_gadget_init()
4688 dev_err(dwc->dev, "failed to add gadget\n"); in dwc3_gadget_init()
4692 if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) in dwc3_gadget_init()
4693 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); in dwc3_gadget_init()
4695 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); in dwc3_gadget_init()
4698 if (dwc->sys_wakeup) in dwc3_gadget_init()
4699 device_wakeup_disable(dwc->sysdev); in dwc3_gadget_init()
4704 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_init()
4706 usb_put_gadget(dwc->gadget); in dwc3_gadget_init()
4707 dwc->gadget = NULL; in dwc3_gadget_init()
4709 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_init()
4710 dwc->bounce_addr); in dwc3_gadget_init()
4713 kfree(dwc->setup_buf); in dwc3_gadget_init()
4716 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4717 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_init()
4725 void dwc3_gadget_exit(struct dwc3 *dwc) in dwc3_gadget_exit() argument
4727 if (!dwc->gadget) in dwc3_gadget_exit()
4730 dwc3_enable_susphy(dwc, false); in dwc3_gadget_exit()
4731 usb_del_gadget(dwc->gadget); in dwc3_gadget_exit()
4732 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_exit()
4733 usb_put_gadget(dwc->gadget); in dwc3_gadget_exit()
4734 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_exit()
4735 dwc->bounce_addr); in dwc3_gadget_exit()
4736 kfree(dwc->setup_buf); in dwc3_gadget_exit()
4737 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_exit()
4738 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_exit()
4741 int dwc3_gadget_suspend(struct dwc3 *dwc) in dwc3_gadget_suspend() argument
4746 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_suspend()
4750 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_suspend()
4751 if (dwc->gadget_driver) in dwc3_gadget_suspend()
4752 dwc3_disconnect_gadget(dwc); in dwc3_gadget_suspend()
4753 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_suspend()
4763 if (dwc->softconnect) in dwc3_gadget_suspend()
4764 dwc3_gadget_soft_connect(dwc); in dwc3_gadget_suspend()
4769 int dwc3_gadget_resume(struct dwc3 *dwc) in dwc3_gadget_resume() argument
4771 if (!dwc->gadget_driver || !dwc->softconnect) in dwc3_gadget_resume()
4774 return dwc3_gadget_soft_connect(dwc); in dwc3_gadget_resume()