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);
295 struct dwc3 *dwc = dep->dwc; in dwc3_send_gadget_ep_cmd() local
313 if (dwc->gadget->speed <= USB_SPEED_HIGH || in dwc3_send_gadget_ep_cmd()
315 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
327 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
339 link_state = dwc3_gadget_get_link_state(dwc); in dwc3_send_gadget_ep_cmd()
342 if (dwc->gadget->speed >= USB_SPEED_SUPER) in dwc3_send_gadget_ep_cmd()
347 ret = __dwc3_gadget_wakeup(dwc, false); in dwc3_send_gadget_ep_cmd()
348 dev_WARN_ONCE(dwc->dev, ret, "wakeup failed --> %d\n", in dwc3_send_gadget_ep_cmd()
406 dev_WARN(dwc->dev, "No resource for %s\n", in dwc3_send_gadget_ep_cmd()
425 dev_WARN(dwc->dev, "UNKNOWN cmd status\n"); in dwc3_send_gadget_ep_cmd()
449 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
451 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
459 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd() local
473 (dwc->gadget->speed >= USB_SPEED_SUPER)) in dwc3_send_clear_stall_ep_cmd()
491 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool() local
496 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
500 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
510 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool() local
512 dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, in dwc3_free_trb_pool()
567 struct dwc3 *dwc; in dwc3_gadget_start_config() local
577 dwc = dep->dwc; in dwc3_gadget_start_config()
584 struct dwc3_ep *dep = dwc->eps[i]; in dwc3_gadget_start_config()
602 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config() local
613 if (dwc->gadget->speed >= USB_SPEED_SUPER) { in dwc3_gadget_set_ep_config()
668 dwc->gadget->speed == USB_SPEED_FULL) in dwc3_gadget_set_ep_config()
681 * @dwc: pointer to the DWC3 context
696 static int dwc3_gadget_calc_tx_fifo_size(struct dwc3 *dwc, int mult) in dwc3_gadget_calc_tx_fifo_size() argument
702 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_calc_tx_fifo_size()
716 * @dwc: pointer to the DWC3 context
721 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) in dwc3_gadget_clear_tx_fifos() argument
728 if (!dwc->do_fifo_resize) in dwc3_gadget_clear_tx_fifos()
732 dep = dwc->eps[1]; in dwc3_gadget_clear_tx_fifos()
733 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_clear_tx_fifos()
739 dwc->last_fifo_depth = fifo_depth; in dwc3_gadget_clear_tx_fifos()
741 for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); in dwc3_gadget_clear_tx_fifos()
743 dep = dwc->eps[num]; in dwc3_gadget_clear_tx_fifos()
746 dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & in dwc3_gadget_clear_tx_fifos()
749 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1), size); in dwc3_gadget_clear_tx_fifos()
752 dwc->num_ep_resized = 0; in dwc3_gadget_clear_tx_fifos()
757 * @dwc: pointer to our context structure
778 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_resize_tx_fifos() local
789 if (!dwc->do_fifo_resize) in dwc3_gadget_resize_tx_fifos()
800 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_resize_tx_fifos()
810 num_fifos = dwc->tx_fifo_resize_max_num; in dwc3_gadget_resize_tx_fifos()
813 fifo = dwc3_gadget_calc_tx_fifo_size(dwc, 1); in dwc3_gadget_resize_tx_fifos()
816 num_in_ep = dwc->max_cfg_eps; in dwc3_gadget_resize_tx_fifos()
817 num_in_ep -= dwc->num_ep_resized; in dwc3_gadget_resize_tx_fifos()
821 remaining = ram1_depth - min_depth - dwc->last_fifo_depth; in dwc3_gadget_resize_tx_fifos()
837 tmp = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_resize_tx_fifos()
840 fifo_size |= (fifo_0_start + (dwc->last_fifo_depth << 16)); in dwc3_gadget_resize_tx_fifos()
842 dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
844 dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
847 if (dwc->last_fifo_depth >= ram1_depth) { in dwc3_gadget_resize_tx_fifos()
848 dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n", in dwc3_gadget_resize_tx_fifos()
849 dwc->last_fifo_depth, ram1_depth, in dwc3_gadget_resize_tx_fifos()
856 dwc->last_fifo_depth -= fifo_size; in dwc3_gadget_resize_tx_fifos()
860 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1), fifo_size); in dwc3_gadget_resize_tx_fifos()
862 dwc->num_ep_resized++; in dwc3_gadget_resize_tx_fifos()
878 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable() local
904 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_enable()
906 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_enable()
978 !(dwc->hwparams.hwparams9 & in __dwc3_gadget_ep_enable()
990 void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) in dwc3_remove_requests() argument
1032 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable() local
1042 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_disable()
1044 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_disable()
1046 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in __dwc3_gadget_ep_disable()
1088 struct dwc3 *dwc; in dwc3_gadget_ep_enable() local
1103 dwc = dep->dwc; in dwc3_gadget_ep_enable()
1105 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
1110 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1112 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1120 struct dwc3 *dwc; in dwc3_gadget_ep_disable() local
1130 dwc = dep->dwc; in dwc3_gadget_ep_disable()
1132 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
1137 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1139 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1242 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb() local
1243 struct usb_gadget *gadget = dwc->gadget; in dwc3_prepare_one_trb()
1247 dma = dep->dwc->bounce_addr; in dwc3_prepare_one_trb()
1328 dev_WARN(dwc->dev, "Unknown endpoint type %d\n", in dwc3_prepare_one_trb()
1345 if (dep->stream_capable && DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1354 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1582 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in dwc3_prepare_trbs()
1587 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs() local
1589 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, in dwc3_prepare_trbs()
1616 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_trbs()
1694 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in __dwc3_gadget_kick_transfer()
1700 static int __dwc3_gadget_get_frame(struct dwc3 *dwc) in __dwc3_gadget_get_frame() argument
1704 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_get_frame()
1721 struct dwc3 *dwc = dep->dwc; in __dwc3_stop_active_transfer() local
1738 if (ret == -ETIMEDOUT && dep->dwc->ep0state != EP0_SETUP_PHASE) { in __dwc3_stop_active_transfer()
1818 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1819 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1875 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc() local
1885 if (!dwc->dis_start_transfer_quirk && in __dwc3_gadget_start_isoc()
1888 if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1893 dwc->gadget->speed >= USB_SPEED_HIGH) { in __dwc3_gadget_start_isoc()
1894 u32 frame = __dwc3_gadget_get_frame(dwc); in __dwc3_gadget_start_isoc()
1940 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue() local
1942 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in __dwc3_gadget_ep_queue()
1943 dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", in __dwc3_gadget_ep_queue()
1957 pm_runtime_get(dwc->dev); in __dwc3_gadget_ep_queue()
2009 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue() local
2015 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2017 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2054 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_cleanup_cancelled_requests() local
2070 dev_err(dwc->dev, "request cancelled with wrong reason:%d\n", req->status); in dwc3_gadget_ep_cleanup_cancelled_requests()
2090 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue() local
2097 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2116 dwc3_ep0_reset_state(dwc); in dwc3_gadget_ep_dequeue()
2142 dev_err(dwc->dev, "request %pK was not queued to %s\n", in dwc3_gadget_ep_dequeue()
2146 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2154 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt() local
2160 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
2175 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
2188 dev_err(dwc->dev, "failed to set STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2212 dwc->clear_stall_protocol = dep->number; in __dwc3_gadget_ep_set_halt()
2221 dev_err(dwc->dev, "failed to clear STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2241 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt() local
2247 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2249 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2257 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge() local
2261 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2268 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2305 static void dwc3_gadget_enable_linksts_evts(struct dwc3 *dwc, bool set) in dwc3_gadget_enable_linksts_evts() argument
2312 reg = dwc3_readl(dwc->regs, DWC3_DEVTEN); in dwc3_gadget_enable_linksts_evts()
2318 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_linksts_evts()
2323 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_get_frame() local
2325 return __dwc3_gadget_get_frame(dwc); in dwc3_gadget_get_frame()
2328 static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async) in __dwc3_gadget_wakeup() argument
2343 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2360 dwc3_gadget_enable_linksts_evts(dwc, true); in __dwc3_gadget_wakeup()
2362 ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV); in __dwc3_gadget_wakeup()
2364 dev_err(dwc->dev, "failed to put link in Recovery\n"); in __dwc3_gadget_wakeup()
2365 dwc3_gadget_enable_linksts_evts(dwc, false); in __dwc3_gadget_wakeup()
2372 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in __dwc3_gadget_wakeup()
2374 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in __dwc3_gadget_wakeup()
2388 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2396 dev_err(dwc->dev, "failed to send remote wakeup\n"); in __dwc3_gadget_wakeup()
2405 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_wakeup() local
2409 if (!dwc->wakeup_configured) { in dwc3_gadget_wakeup()
2410 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_wakeup()
2414 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_wakeup()
2415 if (!dwc->gadget->wakeup_armed) { in dwc3_gadget_wakeup()
2416 dev_err(dwc->dev, "not armed for remote wakeup\n"); in dwc3_gadget_wakeup()
2417 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2420 ret = __dwc3_gadget_wakeup(dwc, true); in dwc3_gadget_wakeup()
2422 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2427 static void dwc3_resume_gadget(struct dwc3 *dwc);
2431 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_func_wakeup() local
2436 if (!dwc->wakeup_configured) { in dwc3_gadget_func_wakeup()
2437 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_func_wakeup()
2441 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2446 link_state = dwc3_gadget_get_link_state(dwc); in dwc3_gadget_func_wakeup()
2448 ret = __dwc3_gadget_wakeup(dwc, false); in dwc3_gadget_func_wakeup()
2450 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2453 dwc3_resume_gadget(dwc); in dwc3_gadget_func_wakeup()
2454 dwc->suspended = false; in dwc3_gadget_func_wakeup()
2455 dwc->link_state = DWC3_LINK_STATE_U0; in dwc3_gadget_func_wakeup()
2458 ret = dwc3_send_gadget_generic_command(dwc, DWC3_DGCMD_DEV_NOTIFICATION, in dwc3_gadget_func_wakeup()
2462 dev_err(dwc->dev, "function remote wakeup failed, ret:%d\n", ret); in dwc3_gadget_func_wakeup()
2464 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2471 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_remote_wakeup() local
2474 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2475 dwc->wakeup_configured = !!set; in dwc3_gadget_set_remote_wakeup()
2476 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2484 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_selfpowered() local
2487 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2489 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2494 static void dwc3_stop_active_transfers(struct dwc3 *dwc) in dwc3_stop_active_transfers() argument
2498 for (epnum = 2; epnum < dwc->num_eps; epnum++) { in dwc3_stop_active_transfers()
2501 dep = dwc->eps[epnum]; in dwc3_stop_active_transfers()
2505 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in dwc3_stop_active_transfers()
2509 static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) in __dwc3_gadget_set_ssp_rate() argument
2511 enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2515 ssp_rate = dwc->max_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2517 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_ssp_rate()
2523 else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) in __dwc3_gadget_set_ssp_rate()
2527 dwc->max_ssp_rate != USB_SSP_GEN_2x1) in __dwc3_gadget_set_ssp_rate()
2530 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_ssp_rate()
2533 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) in __dwc3_gadget_set_speed() argument
2538 speed = dwc->gadget_max_speed; in __dwc3_gadget_set_speed()
2539 if (speed == USB_SPEED_UNKNOWN || speed > dwc->maximum_speed) in __dwc3_gadget_set_speed()
2540 speed = dwc->maximum_speed; in __dwc3_gadget_set_speed()
2544 __dwc3_gadget_set_ssp_rate(dwc); in __dwc3_gadget_set_speed()
2548 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_speed()
2565 !dwc->dis_metastability_quirk) { in __dwc3_gadget_set_speed()
2585 dev_err(dwc->dev, "invalid speed (%d)\n", speed); in __dwc3_gadget_set_speed()
2599 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_speed()
2602 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) in dwc3_gadget_run_stop() argument
2607 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_run_stop()
2610 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_run_stop()
2621 __dwc3_gadget_set_speed(dwc); in dwc3_gadget_run_stop()
2622 dwc->pullups_connected = true; in dwc3_gadget_run_stop()
2626 dwc->pullups_connected = false; in dwc3_gadget_run_stop()
2629 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_run_stop()
2633 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_run_stop()
2643 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
2644 static void __dwc3_gadget_stop(struct dwc3 *dwc);
2645 static int __dwc3_gadget_start(struct dwc3 *dwc);
2647 static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) in dwc3_gadget_soft_disconnect() argument
2652 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2653 if (!dwc->pullups_connected) { in dwc3_gadget_soft_disconnect()
2654 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2658 dwc->connected = false; in dwc3_gadget_soft_disconnect()
2664 if (dwc->delayed_status) in dwc3_gadget_soft_disconnect()
2665 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_soft_disconnect()
2674 dwc3_stop_active_transfers(dwc); in dwc3_gadget_soft_disconnect()
2675 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2684 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_soft_disconnect()
2685 reinit_completion(&dwc->ep0_in_setup); in dwc3_gadget_soft_disconnect()
2687 ret = wait_for_completion_timeout(&dwc->ep0_in_setup, in dwc3_gadget_soft_disconnect()
2690 dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); in dwc3_gadget_soft_disconnect()
2691 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2692 dwc3_ep0_reset_state(dwc); in dwc3_gadget_soft_disconnect()
2693 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2704 ret = dwc3_gadget_run_stop(dwc, false); in dwc3_gadget_soft_disconnect()
2712 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2713 __dwc3_gadget_stop(dwc); in dwc3_gadget_soft_disconnect()
2714 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2719 static int dwc3_gadget_soft_connect(struct dwc3 *dwc) in dwc3_gadget_soft_connect() argument
2729 ret = dwc3_core_soft_reset(dwc); in dwc3_gadget_soft_connect()
2733 dwc3_event_buffers_setup(dwc); in dwc3_gadget_soft_connect()
2734 __dwc3_gadget_start(dwc); in dwc3_gadget_soft_connect()
2735 return dwc3_gadget_run_stop(dwc, true); in dwc3_gadget_soft_connect()
2740 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_pullup() local
2745 dwc->softconnect = is_on; in dwc3_gadget_pullup()
2753 pm_runtime_barrier(dwc->dev); in dwc3_gadget_pullup()
2754 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_pullup()
2763 ret = pm_runtime_get_sync(dwc->dev); in dwc3_gadget_pullup()
2765 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2767 pm_runtime_set_suspended(dwc->dev); in dwc3_gadget_pullup()
2771 if (dwc->pullups_connected == is_on) { in dwc3_gadget_pullup()
2772 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2776 synchronize_irq(dwc->irq_gadget); in dwc3_gadget_pullup()
2779 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_pullup()
2781 ret = dwc3_gadget_soft_connect(dwc); in dwc3_gadget_pullup()
2783 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2788 static void dwc3_gadget_enable_irq(struct dwc3 *dwc) in dwc3_gadget_enable_irq() argument
2808 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_irq()
2811 static void dwc3_gadget_disable_irq(struct dwc3 *dwc) in dwc3_gadget_disable_irq() argument
2814 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); in dwc3_gadget_disable_irq()
2822 * @dwc: pointer to our context structure
2841 static void dwc3_gadget_setup_nump(struct dwc3 *dwc) in dwc3_gadget_setup_nump() argument
2848 ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_setup_nump()
2849 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_setup_nump()
2855 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_setup_nump()
2858 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_setup_nump()
2861 static int __dwc3_gadget_start(struct dwc3 *dwc) in __dwc3_gadget_start() argument
2868 * Use IMOD if enabled via dwc->imod_interval. Otherwise, if in __dwc3_gadget_start()
2871 if (dwc->imod_interval) { in __dwc3_gadget_start()
2872 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in __dwc3_gadget_start()
2873 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in __dwc3_gadget_start()
2874 } else if (dwc3_has_imod(dwc)) { in __dwc3_gadget_start()
2875 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), 0); in __dwc3_gadget_start()
2885 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in __dwc3_gadget_start()
2891 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in __dwc3_gadget_start()
2893 dwc3_gadget_setup_nump(dwc); in __dwc3_gadget_start()
2902 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_start()
2904 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_start()
2907 if (DWC3_MST_CAPABLE(&dwc->hwparams)) { in __dwc3_gadget_start()
2908 reg = dwc3_readl(dwc->regs, DWC3_DCFG1); in __dwc3_gadget_start()
2910 dwc3_writel(dwc->regs, DWC3_DCFG1, reg); in __dwc3_gadget_start()
2916 dep = dwc->eps[0]; in __dwc3_gadget_start()
2920 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2924 dep = dwc->eps[1]; in __dwc3_gadget_start()
2928 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2933 dwc->ep0state = EP0_SETUP_PHASE; in __dwc3_gadget_start()
2934 dwc->ep0_bounced = false; in __dwc3_gadget_start()
2935 dwc->link_state = DWC3_LINK_STATE_SS_DIS; in __dwc3_gadget_start()
2936 dwc->delayed_status = false; in __dwc3_gadget_start()
2937 dwc3_ep0_out_start(dwc); in __dwc3_gadget_start()
2939 dwc3_gadget_enable_irq(dwc); in __dwc3_gadget_start()
2944 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_start()
2953 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_start() local
2958 irq = dwc->irq_gadget; in dwc3_gadget_start()
2960 IRQF_SHARED, "dwc3", dwc->ev_buf); in dwc3_gadget_start()
2962 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_gadget_start()
2967 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_start()
2968 dwc->gadget_driver = driver; in dwc3_gadget_start()
2969 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
2974 static void __dwc3_gadget_stop(struct dwc3 *dwc) in __dwc3_gadget_stop() argument
2976 dwc3_gadget_disable_irq(dwc); in __dwc3_gadget_stop()
2977 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_stop()
2978 __dwc3_gadget_ep_disable(dwc->eps[1]); in __dwc3_gadget_stop()
2983 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_stop() local
2986 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_stop()
2987 dwc->gadget_driver = NULL; in dwc3_gadget_stop()
2988 dwc->max_cfg_eps = 0; in dwc3_gadget_stop()
2989 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_stop()
2991 free_irq(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_stop()
2999 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_config_params() local
3005 if (!dwc->dis_enblslpm_quirk) { in dwc3_gadget_config_params()
3016 if (dwc->is_utmi_l1_suspend) in dwc3_gadget_config_params()
3018 clamp_t(u8, dwc->hird_threshold, 2, 15); in dwc3_gadget_config_params()
3022 if (dwc->dis_u1_entry_quirk) in dwc3_gadget_config_params()
3028 if (dwc->dis_u2_entry_quirk) in dwc3_gadget_config_params()
3038 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_speed() local
3041 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_speed()
3042 dwc->gadget_max_speed = speed; in dwc3_gadget_set_speed()
3043 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_speed()
3049 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_ssp_rate() local
3052 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3053 dwc->gadget_max_speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_set_ssp_rate()
3054 dwc->gadget_ssp_rate = rate; in dwc3_gadget_set_ssp_rate()
3055 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3060 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_vbus_draw() local
3064 if (dwc->usb2_phy) in dwc3_gadget_vbus_draw()
3065 return usb_phy_set_power(dwc->usb2_phy, mA); in dwc3_gadget_vbus_draw()
3067 if (!dwc->usb_psy) in dwc3_gadget_vbus_draw()
3071 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_gadget_vbus_draw()
3088 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_check_config() local
3094 if (!dwc->do_fifo_resize) in dwc3_gadget_check_config()
3103 if (ep_num <= dwc->max_cfg_eps) in dwc3_gadget_check_config()
3107 dwc->max_cfg_eps = ep_num; in dwc3_gadget_check_config()
3109 fifo_size = dwc3_gadget_calc_tx_fifo_size(dwc, dwc->max_cfg_eps); in dwc3_gadget_check_config()
3111 fifo_size += dwc->max_cfg_eps; in dwc3_gadget_check_config()
3114 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_check_config()
3123 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_async_callbacks() local
3126 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3127 dwc->async_callbacks = enable; in dwc3_gadget_async_callbacks()
3128 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3152 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint() local
3158 dwc->gadget->ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
3167 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint() local
3172 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_in_endpoint()
3177 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
3206 &dwc->gadget->ep_list); in dwc3_gadget_init_in_endpoint()
3216 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint() local
3220 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_out_endpoint()
3226 size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0)); in dwc3_gadget_init_out_endpoint()
3253 &dwc->gadget->ep_list); in dwc3_gadget_init_out_endpoint()
3261 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) in dwc3_gadget_init_endpoint() argument
3272 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
3275 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
3276 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
3312 static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) in dwc3_gadget_init_endpoints() argument
3316 INIT_LIST_HEAD(&dwc->gadget->ep_list); in dwc3_gadget_init_endpoints()
3321 ret = dwc3_gadget_init_endpoint(dwc, epnum); in dwc3_gadget_init_endpoints()
3329 static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) in dwc3_gadget_free_endpoints() argument
3335 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
3401 if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && in dwc3_gadget_ep_reclaim_completed_trb()
3402 trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { in dwc3_gadget_ep_reclaim_completed_trb()
3552 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_should_continue() local
3554 if (!dep->endpoint.desc || !dwc->pullups_connected || in dwc3_gadget_ep_should_continue()
3555 !dwc->connected) in dwc3_gadget_ep_should_continue()
3581 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_trbs_complete() local
3610 dep = dwc->eps[i]; in dwc3_gadget_endpoint_trbs_complete()
3619 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_endpoint_trbs_complete()
3620 reg |= dwc->u1u2; in dwc3_gadget_endpoint_trbs_complete()
3621 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_endpoint_trbs_complete()
3623 dwc->u1u2 = 0; in dwc3_gadget_endpoint_trbs_complete()
3703 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_command_complete() local
3707 struct usb_ep *ep0 = &dwc->eps[0]->endpoint; in dwc3_gadget_endpoint_command_complete()
3709 dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); in dwc3_gadget_endpoint_command_complete()
3710 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3716 if (dwc->clear_stall_protocol == dep->number) in dwc3_gadget_endpoint_command_complete()
3717 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_endpoint_command_complete()
3730 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_stream_event() local
3758 (!DWC3_MST_CAPABLE(&dwc->hwparams) && in dwc3_gadget_endpoint_stream_event()
3779 dwc3_send_gadget_generic_command(dwc, cmd, dep->number); in dwc3_gadget_endpoint_stream_event()
3792 static void dwc3_endpoint_interrupt(struct dwc3 *dwc, in dwc3_endpoint_interrupt() argument
3798 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
3811 dwc3_ep0_interrupt(dwc, event); in dwc3_endpoint_interrupt()
3834 dev_err(dwc->dev, "unknown endpoint event %d\n", event->endpoint_event); in dwc3_endpoint_interrupt()
3839 static void dwc3_disconnect_gadget(struct dwc3 *dwc) in dwc3_disconnect_gadget() argument
3841 if (dwc->async_callbacks && dwc->gadget_driver->disconnect) { in dwc3_disconnect_gadget()
3842 spin_unlock(&dwc->lock); in dwc3_disconnect_gadget()
3843 dwc->gadget_driver->disconnect(dwc->gadget); in dwc3_disconnect_gadget()
3844 spin_lock(&dwc->lock); in dwc3_disconnect_gadget()
3848 static void dwc3_suspend_gadget(struct dwc3 *dwc) in dwc3_suspend_gadget() argument
3850 if (dwc->async_callbacks && dwc->gadget_driver->suspend) { in dwc3_suspend_gadget()
3851 spin_unlock(&dwc->lock); in dwc3_suspend_gadget()
3852 dwc->gadget_driver->suspend(dwc->gadget); in dwc3_suspend_gadget()
3853 spin_lock(&dwc->lock); in dwc3_suspend_gadget()
3857 static void dwc3_resume_gadget(struct dwc3 *dwc) in dwc3_resume_gadget() argument
3859 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_resume_gadget()
3860 spin_unlock(&dwc->lock); in dwc3_resume_gadget()
3861 dwc->gadget_driver->resume(dwc->gadget); in dwc3_resume_gadget()
3862 spin_lock(&dwc->lock); in dwc3_resume_gadget()
3866 static void dwc3_reset_gadget(struct dwc3 *dwc) in dwc3_reset_gadget() argument
3868 if (!dwc->gadget_driver) in dwc3_reset_gadget()
3871 if (dwc->async_callbacks && dwc->gadget->speed != USB_SPEED_UNKNOWN) { in dwc3_reset_gadget()
3872 spin_unlock(&dwc->lock); in dwc3_reset_gadget()
3873 usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); in dwc3_reset_gadget()
3874 spin_lock(&dwc->lock); in dwc3_reset_gadget()
3881 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer() local
3889 if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) in dwc3_stop_active_transfer()
3906 if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { in dwc3_stop_active_transfer()
3945 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) in dwc3_clear_stall_all_ep() argument
3953 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
3967 static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) in dwc3_gadget_disconnect_interrupt() argument
3971 dwc->suspended = false; in dwc3_gadget_disconnect_interrupt()
3973 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); in dwc3_gadget_disconnect_interrupt()
3975 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_disconnect_interrupt()
3978 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_disconnect_interrupt()
3980 dwc->connected = false; in dwc3_gadget_disconnect_interrupt()
3982 dwc3_disconnect_gadget(dwc); in dwc3_gadget_disconnect_interrupt()
3984 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_disconnect_interrupt()
3985 dwc->setup_packet_pending = false; in dwc3_gadget_disconnect_interrupt()
3986 dwc->gadget->wakeup_armed = false; in dwc3_gadget_disconnect_interrupt()
3987 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_disconnect_interrupt()
3988 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_disconnect_interrupt()
3990 dwc3_ep0_reset_state(dwc); in dwc3_gadget_disconnect_interrupt()
3995 * interrupt to set dwc->connected to FALSE. in dwc3_gadget_disconnect_interrupt()
3997 pm_request_idle(dwc->dev); in dwc3_gadget_disconnect_interrupt()
4000 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) in dwc3_gadget_reset_interrupt() argument
4004 dwc->suspended = false; in dwc3_gadget_reset_interrupt()
4013 dwc->connected = false; in dwc3_gadget_reset_interrupt()
4042 if (dwc->setup_packet_pending) in dwc3_gadget_reset_interrupt()
4043 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_reset_interrupt()
4046 dwc3_reset_gadget(dwc); in dwc3_gadget_reset_interrupt()
4053 dwc3_ep0_reset_state(dwc); in dwc3_gadget_reset_interrupt()
4061 dwc3_stop_active_transfers(dwc); in dwc3_gadget_reset_interrupt()
4062 dwc->connected = true; in dwc3_gadget_reset_interrupt()
4064 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_reset_interrupt()
4066 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_reset_interrupt()
4067 dwc->test_mode = false; in dwc3_gadget_reset_interrupt()
4068 dwc->gadget->wakeup_armed = false; in dwc3_gadget_reset_interrupt()
4069 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_reset_interrupt()
4070 dwc3_clear_stall_all_ep(dwc); in dwc3_gadget_reset_interrupt()
4073 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_reset_interrupt()
4075 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_reset_interrupt()
4078 static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) in dwc3_gadget_conndone_interrupt() argument
4086 if (!dwc->softconnect) in dwc3_gadget_conndone_interrupt()
4089 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_conndone_interrupt()
4091 dwc->speed = speed; in dwc3_gadget_conndone_interrupt()
4096 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_conndone_interrupt()
4110 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4111 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4114 dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; in dwc3_gadget_conndone_interrupt()
4116 dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; in dwc3_gadget_conndone_interrupt()
4133 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_conndone_interrupt()
4136 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4137 dwc->gadget->speed = USB_SPEED_SUPER; in dwc3_gadget_conndone_interrupt()
4140 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4141 dwc->gadget->ssp_rate = USB_SSP_GEN_1x2; in dwc3_gadget_conndone_interrupt()
4146 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4147 dwc->gadget->speed = USB_SPEED_HIGH; in dwc3_gadget_conndone_interrupt()
4151 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4152 dwc->gadget->speed = USB_SPEED_FULL; in dwc3_gadget_conndone_interrupt()
4156 dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; in dwc3_gadget_conndone_interrupt()
4161 !dwc->usb2_gadget_lpm_disable && in dwc3_gadget_conndone_interrupt()
4164 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4166 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4168 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4171 reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold | in dwc3_gadget_conndone_interrupt()
4172 (dwc->is_utmi_l1_suspend << 4)); in dwc3_gadget_conndone_interrupt()
4180 WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum, in dwc3_gadget_conndone_interrupt()
4183 if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) in dwc3_gadget_conndone_interrupt()
4184 reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); in dwc3_gadget_conndone_interrupt()
4186 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4188 if (dwc->usb2_gadget_lpm_disable) { in dwc3_gadget_conndone_interrupt()
4189 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4191 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4194 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4196 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4199 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
4202 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4206 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
4209 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4222 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo) in dwc3_gadget_wakeup_interrupt() argument
4224 dwc->suspended = false; in dwc3_gadget_wakeup_interrupt()
4231 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_gadget_wakeup_interrupt()
4232 spin_unlock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4233 dwc->gadget_driver->resume(dwc->gadget); in dwc3_gadget_wakeup_interrupt()
4234 spin_lock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4237 dwc->link_state = evtinfo & DWC3_LINK_STATE_MASK; in dwc3_gadget_wakeup_interrupt()
4240 static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, in dwc3_gadget_linksts_change_interrupt() argument
4263 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_gadget_linksts_change_interrupt()
4266 if ((dwc->link_state == DWC3_LINK_STATE_U3) && in dwc3_gadget_linksts_change_interrupt()
4295 switch (dwc->link_state) { in dwc3_gadget_linksts_change_interrupt()
4298 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_linksts_change_interrupt()
4304 if (!dwc->u1u2) in dwc3_gadget_linksts_change_interrupt()
4305 dwc->u1u2 = reg & u1u2; in dwc3_gadget_linksts_change_interrupt()
4309 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_linksts_change_interrupt()
4320 if (dwc->gadget->wakeup_armed) { in dwc3_gadget_linksts_change_interrupt()
4321 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_linksts_change_interrupt()
4322 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4323 dwc->suspended = false; in dwc3_gadget_linksts_change_interrupt()
4327 if (dwc->speed == USB_SPEED_SUPER) in dwc3_gadget_linksts_change_interrupt()
4328 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4332 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4335 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4342 dwc->link_state = next; in dwc3_gadget_linksts_change_interrupt()
4345 static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, in dwc3_gadget_suspend_interrupt() argument
4350 if (!dwc->suspended && next == DWC3_LINK_STATE_U3) { in dwc3_gadget_suspend_interrupt()
4351 dwc->suspended = true; in dwc3_gadget_suspend_interrupt()
4352 dwc3_suspend_gadget(dwc); in dwc3_gadget_suspend_interrupt()
4355 dwc->link_state = next; in dwc3_gadget_suspend_interrupt()
4358 static void dwc3_gadget_interrupt(struct dwc3 *dwc, in dwc3_gadget_interrupt() argument
4363 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_interrupt()
4366 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_interrupt()
4369 dwc3_gadget_conndone_interrupt(dwc); in dwc3_gadget_interrupt()
4372 dwc3_gadget_wakeup_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4375 dev_WARN_ONCE(dwc->dev, true, "unexpected hibernation event\n"); in dwc3_gadget_interrupt()
4378 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4383 dwc3_gadget_suspend_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4391 dev_WARN(dwc->dev, "UNKNOWN IRQ %d\n", event->type); in dwc3_gadget_interrupt()
4395 static void dwc3_process_event_entry(struct dwc3 *dwc, in dwc3_process_event_entry() argument
4398 trace_dwc3_event(event->raw, dwc); in dwc3_process_event_entry()
4401 dwc3_endpoint_interrupt(dwc, &event->depevt); in dwc3_process_event_entry()
4403 dwc3_gadget_interrupt(dwc, &event->devt); in dwc3_process_event_entry()
4405 dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); in dwc3_process_event_entry()
4410 struct dwc3 *dwc = evt->dwc; in dwc3_process_event_buf() local
4424 dwc3_process_event_entry(dwc, &event); in dwc3_process_event_buf()
4443 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_process_event_buf()
4446 if (dwc->imod_interval) { in dwc3_process_event_buf()
4447 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in dwc3_process_event_buf()
4448 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in dwc3_process_event_buf()
4460 struct dwc3 *dwc = evt->dwc; in dwc3_thread_interrupt() local
4465 spin_lock_irqsave(&dwc->lock, flags); in dwc3_thread_interrupt()
4467 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_thread_interrupt()
4475 struct dwc3 *dwc = evt->dwc; in dwc3_check_event_buf() local
4479 if (pm_runtime_suspended(dwc->dev)) { in dwc3_check_event_buf()
4480 dwc->pending_events = true; in dwc3_check_event_buf()
4486 pm_runtime_get(dwc->dev); in dwc3_check_event_buf()
4487 disable_irq_nosync(dwc->irq_gadget); in dwc3_check_event_buf()
4500 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_check_event_buf()
4509 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_check_event_buf()
4518 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); in dwc3_check_event_buf()
4530 static int dwc3_gadget_get_irq(struct dwc3 *dwc) in dwc3_gadget_get_irq() argument
4532 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_gadget_get_irq()
4564 * @dwc: pointer to our controller context structure
4568 int dwc3_gadget_init(struct dwc3 *dwc) in dwc3_gadget_init() argument
4574 irq = dwc3_gadget_get_irq(dwc); in dwc3_gadget_init()
4580 dwc->irq_gadget = irq; in dwc3_gadget_init()
4582 dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev, in dwc3_gadget_init()
4583 sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4584 &dwc->ep0_trb_addr, GFP_KERNEL); in dwc3_gadget_init()
4585 if (!dwc->ep0_trb) { in dwc3_gadget_init()
4586 dev_err(dwc->dev, "failed to allocate ep0 trb\n"); in dwc3_gadget_init()
4591 dwc->setup_buf = kzalloc(DWC3_EP0_SETUP_SIZE, GFP_KERNEL); in dwc3_gadget_init()
4592 if (!dwc->setup_buf) { in dwc3_gadget_init()
4597 dwc->bounce = dma_alloc_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, in dwc3_gadget_init()
4598 &dwc->bounce_addr, GFP_KERNEL); in dwc3_gadget_init()
4599 if (!dwc->bounce) { in dwc3_gadget_init()
4604 init_completion(&dwc->ep0_in_setup); in dwc3_gadget_init()
4605 dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); in dwc3_gadget_init()
4606 if (!dwc->gadget) { in dwc3_gadget_init()
4612 usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); in dwc3_gadget_init()
4613 dev = &dwc->gadget->dev; in dwc3_gadget_init()
4614 dev->platform_data = dwc; in dwc3_gadget_init()
4615 dwc->gadget->ops = &dwc3_gadget_ops; in dwc3_gadget_init()
4616 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_init()
4617 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_init()
4618 dwc->gadget->sg_supported = true; in dwc3_gadget_init()
4619 dwc->gadget->name = "dwc3-gadget"; in dwc3_gadget_init()
4620 dwc->gadget->lpm_capable = !dwc->usb2_gadget_lpm_disable; in dwc3_gadget_init()
4621 dwc->gadget->wakeup_capable = true; in dwc3_gadget_init()
4640 !dwc->dis_metastability_quirk) in dwc3_gadget_init()
4641 dev_info(dwc->dev, "changing max_speed on rev %08x\n", in dwc3_gadget_init()
4642 dwc->revision); in dwc3_gadget_init()
4644 dwc->gadget->max_speed = dwc->maximum_speed; in dwc3_gadget_init()
4645 dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; in dwc3_gadget_init()
4652 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); in dwc3_gadget_init()
4656 ret = usb_add_gadget(dwc->gadget); in dwc3_gadget_init()
4658 dev_err(dwc->dev, "failed to add gadget\n"); in dwc3_gadget_init()
4662 if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) in dwc3_gadget_init()
4663 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); in dwc3_gadget_init()
4665 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); in dwc3_gadget_init()
4670 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_init()
4672 usb_put_gadget(dwc->gadget); in dwc3_gadget_init()
4673 dwc->gadget = NULL; in dwc3_gadget_init()
4675 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_init()
4676 dwc->bounce_addr); in dwc3_gadget_init()
4679 kfree(dwc->setup_buf); in dwc3_gadget_init()
4682 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4683 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_init()
4691 void dwc3_gadget_exit(struct dwc3 *dwc) in dwc3_gadget_exit() argument
4693 if (!dwc->gadget) in dwc3_gadget_exit()
4696 usb_del_gadget(dwc->gadget); in dwc3_gadget_exit()
4697 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_exit()
4698 usb_put_gadget(dwc->gadget); in dwc3_gadget_exit()
4699 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_exit()
4700 dwc->bounce_addr); in dwc3_gadget_exit()
4701 kfree(dwc->setup_buf); in dwc3_gadget_exit()
4702 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_exit()
4703 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_exit()
4706 int dwc3_gadget_suspend(struct dwc3 *dwc) in dwc3_gadget_suspend() argument
4711 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_suspend()
4715 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_suspend()
4716 if (dwc->gadget_driver) in dwc3_gadget_suspend()
4717 dwc3_disconnect_gadget(dwc); in dwc3_gadget_suspend()
4718 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_suspend()
4728 if (dwc->softconnect) in dwc3_gadget_suspend()
4729 dwc3_gadget_soft_connect(dwc); in dwc3_gadget_suspend()
4734 int dwc3_gadget_resume(struct dwc3 *dwc) in dwc3_gadget_resume() argument
4736 if (!dwc->gadget_driver || !dwc->softconnect) in dwc3_gadget_resume()
4739 return dwc3_gadget_soft_connect(dwc); in dwc3_gadget_resume()
4742 void dwc3_gadget_process_pending_events(struct dwc3 *dwc) in dwc3_gadget_process_pending_events() argument
4744 if (dwc->pending_events) { in dwc3_gadget_process_pending_events()
4745 dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_process_pending_events()
4746 dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_process_pending_events()
4747 pm_runtime_put(dwc->dev); in dwc3_gadget_process_pending_events()
4748 dwc->pending_events = false; in dwc3_gadget_process_pending_events()
4749 enable_irq(dwc->irq_gadget); in dwc3_gadget_process_pending_events()