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
206 usb_gadget_unmap_request_by_dev(dwc->sysdev, in dwc3_gadget_del_and_unmap_request()
213 pm_runtime_put(dwc->dev); in dwc3_gadget_del_and_unmap_request()
229 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_giveback() local
234 spin_unlock(&dwc->lock); in dwc3_gadget_giveback()
236 spin_lock(&dwc->lock); in dwc3_gadget_giveback()
241 * @dwc: pointer to the controller context
245 * Caller should take care of locking. Issue @cmd with a given @param to @dwc
248 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, in dwc3_send_gadget_generic_command() argument
256 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); in dwc3_send_gadget_generic_command()
257 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); in dwc3_send_gadget_generic_command()
260 reg = dwc3_readl(dwc->regs, DWC3_DGCMD); in dwc3_send_gadget_generic_command()
279 static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async);
311 struct dwc3 *dwc = dep->dwc; in dwc3_send_gadget_ep_cmd() local
329 if (dwc->gadget->speed <= USB_SPEED_HIGH || in dwc3_send_gadget_ep_cmd()
331 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
343 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
398 dev_WARN(dwc->dev, "No resource for %s\n", in dwc3_send_gadget_ep_cmd()
417 dev_WARN(dwc->dev, "UNKNOWN cmd status\n"); in dwc3_send_gadget_ep_cmd()
445 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_send_gadget_ep_cmd()
447 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_send_gadget_ep_cmd()
455 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd() local
469 (dwc->gadget->speed >= USB_SPEED_SUPER)) in dwc3_send_clear_stall_ep_cmd()
487 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool() local
492 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
496 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
506 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool() local
508 dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, in dwc3_free_trb_pool()
538 * @dwc: pointer to the DWC3 context
547 int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index) in dwc3_gadget_start_config() argument
561 ret = dwc3_send_gadget_ep_cmd(dwc->eps[0], cmd, &params); in dwc3_gadget_start_config()
566 for (i = resource_index; i < dwc->num_eps && dwc->eps[i]; i++) in dwc3_gadget_start_config()
567 dwc->eps[i]->flags &= ~DWC3_EP_RESOURCE_ALLOCATED; in dwc3_gadget_start_config()
577 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config() local
588 if (dwc->gadget->speed >= USB_SPEED_SUPER) { in dwc3_gadget_set_ep_config()
643 dwc->gadget->speed == USB_SPEED_FULL) in dwc3_gadget_set_ep_config()
656 * @dwc: pointer to the DWC3 context
671 static int dwc3_gadget_calc_tx_fifo_size(struct dwc3 *dwc, int mult) in dwc3_gadget_calc_tx_fifo_size() argument
677 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_calc_tx_fifo_size()
691 * @dwc: pointer to the DWC3 context
693 static int dwc3_gadget_calc_ram_depth(struct dwc3 *dwc) in dwc3_gadget_calc_ram_depth() argument
700 is_single_port_ram = DWC3_SPRAM_TYPE(dwc->hwparams.hwparams1); in dwc3_gadget_calc_ram_depth()
706 ram_depth = is_single_port_ram ? DWC3_RAM0_DEPTH(dwc->hwparams.hwparams6) : in dwc3_gadget_calc_ram_depth()
707 DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_calc_ram_depth()
718 reg = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_calc_ram_depth()
729 * @dwc: pointer to the DWC3 context
734 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) in dwc3_gadget_clear_tx_fifos() argument
741 if (!dwc->do_fifo_resize) in dwc3_gadget_clear_tx_fifos()
745 dep = dwc->eps[1]; in dwc3_gadget_clear_tx_fifos()
746 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_clear_tx_fifos()
752 dwc->last_fifo_depth = fifo_depth; in dwc3_gadget_clear_tx_fifos()
754 for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); in dwc3_gadget_clear_tx_fifos()
756 dep = dwc->eps[num]; in dwc3_gadget_clear_tx_fifos()
759 dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & in dwc3_gadget_clear_tx_fifos()
762 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1), size); in dwc3_gadget_clear_tx_fifos()
765 dwc->num_ep_resized = 0; in dwc3_gadget_clear_tx_fifos()
770 * @dwc: pointer to our context structure
791 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_resize_tx_fifos() local
802 if (!dwc->do_fifo_resize) in dwc3_gadget_resize_tx_fifos()
813 ram_depth = dwc3_gadget_calc_ram_depth(dwc); in dwc3_gadget_resize_tx_fifos()
815 switch (dwc->gadget->speed) { in dwc3_gadget_resize_tx_fifos()
822 dwc->tx_fifo_resize_max_num); in dwc3_gadget_resize_tx_fifos()
828 dwc->tx_fifo_resize_max_num); in dwc3_gadget_resize_tx_fifos()
841 fifo = dwc3_gadget_calc_tx_fifo_size(dwc, 1); in dwc3_gadget_resize_tx_fifos()
844 num_in_ep = dwc->max_cfg_eps; in dwc3_gadget_resize_tx_fifos()
845 num_in_ep -= dwc->num_ep_resized; in dwc3_gadget_resize_tx_fifos()
849 remaining = ram_depth - min_depth - dwc->last_fifo_depth; in dwc3_gadget_resize_tx_fifos()
865 tmp = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_resize_tx_fifos()
868 fifo_size |= (fifo_0_start + (dwc->last_fifo_depth << 16)); in dwc3_gadget_resize_tx_fifos()
870 dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
872 dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
875 if (dwc->last_fifo_depth >= ram_depth) { in dwc3_gadget_resize_tx_fifos()
876 dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n", in dwc3_gadget_resize_tx_fifos()
877 dwc->last_fifo_depth, ram_depth, in dwc3_gadget_resize_tx_fifos()
884 dwc->last_fifo_depth -= fifo_size; in dwc3_gadget_resize_tx_fifos()
888 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1), fifo_size); in dwc3_gadget_resize_tx_fifos()
890 dwc->num_ep_resized++; in dwc3_gadget_resize_tx_fifos()
906 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable() local
934 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_enable()
936 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_enable()
1007 !(dwc->hwparams.hwparams9 & in __dwc3_gadget_ep_enable()
1019 void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) in dwc3_remove_requests() argument
1061 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable() local
1071 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_disable()
1073 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_disable()
1075 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in __dwc3_gadget_ep_disable()
1117 struct dwc3 *dwc; in dwc3_gadget_ep_enable() local
1132 dwc = dep->dwc; in dwc3_gadget_ep_enable()
1134 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
1139 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1141 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1149 struct dwc3 *dwc; in dwc3_gadget_ep_disable() local
1159 dwc = dep->dwc; in dwc3_gadget_ep_disable()
1161 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
1166 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1168 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1274 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb() local
1275 struct usb_gadget *gadget = dwc->gadget; in dwc3_prepare_one_trb()
1279 dma = dep->dwc->bounce_addr; in dwc3_prepare_one_trb()
1360 dev_WARN(dwc->dev, "Unknown endpoint type %d\n", in dwc3_prepare_one_trb()
1377 if (dep->stream_capable && DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1386 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_one_trb()
1614 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in dwc3_prepare_trbs()
1619 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs() local
1621 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, in dwc3_prepare_trbs()
1646 !DWC3_MST_CAPABLE(&dwc->hwparams)) in dwc3_prepare_trbs()
1724 !DWC3_MST_CAPABLE(&dep->dwc->hwparams)) in __dwc3_gadget_kick_transfer()
1730 static int __dwc3_gadget_get_frame(struct dwc3 *dwc) in __dwc3_gadget_get_frame() argument
1734 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_get_frame()
1767 if (ret == -ETIMEDOUT && dep->dwc->ep0state != EP0_SETUP_PHASE) { in __dwc3_stop_active_transfer()
1844 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1845 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1901 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc() local
1911 if (!dwc->dis_start_transfer_quirk && in __dwc3_gadget_start_isoc()
1914 if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1919 dwc->gadget->speed >= USB_SPEED_HIGH) { in __dwc3_gadget_start_isoc()
1920 u32 frame = __dwc3_gadget_get_frame(dwc); in __dwc3_gadget_start_isoc()
1966 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue() local
1968 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in __dwc3_gadget_ep_queue()
1969 dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", in __dwc3_gadget_ep_queue()
1983 pm_runtime_get(dwc->dev); in __dwc3_gadget_ep_queue()
2035 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue() local
2041 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2043 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2080 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_cleanup_cancelled_requests() local
2096 dev_err(dwc->dev, "request cancelled with wrong reason:%d\n", req->status); in dwc3_gadget_ep_cleanup_cancelled_requests()
2116 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue() local
2123 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2142 dwc3_ep0_reset_state(dwc); in dwc3_gadget_ep_dequeue()
2168 dev_err(dwc->dev, "request %pK was not queued to %s\n", in dwc3_gadget_ep_dequeue()
2172 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2180 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt() local
2186 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
2201 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
2214 dev_err(dwc->dev, "failed to set STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2238 dwc->clear_stall_protocol = dep->number; in __dwc3_gadget_ep_set_halt()
2247 dev_err(dwc->dev, "failed to clear STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2267 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt() local
2273 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2275 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2283 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge() local
2287 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2294 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2331 static void dwc3_gadget_enable_linksts_evts(struct dwc3 *dwc, bool set) in dwc3_gadget_enable_linksts_evts() argument
2338 reg = dwc3_readl(dwc->regs, DWC3_DEVTEN); in dwc3_gadget_enable_linksts_evts()
2344 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_linksts_evts()
2349 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_get_frame() local
2351 return __dwc3_gadget_get_frame(dwc); in dwc3_gadget_get_frame()
2354 static int __dwc3_gadget_wakeup(struct dwc3 *dwc, bool async) in __dwc3_gadget_wakeup() argument
2369 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2386 dwc3_gadget_enable_linksts_evts(dwc, true); in __dwc3_gadget_wakeup()
2388 ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV); in __dwc3_gadget_wakeup()
2390 dev_err(dwc->dev, "failed to put link in Recovery\n"); in __dwc3_gadget_wakeup()
2391 dwc3_gadget_enable_linksts_evts(dwc, false); in __dwc3_gadget_wakeup()
2398 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in __dwc3_gadget_wakeup()
2400 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in __dwc3_gadget_wakeup()
2414 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2422 dev_err(dwc->dev, "failed to send remote wakeup\n"); in __dwc3_gadget_wakeup()
2431 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_wakeup() local
2435 if (!dwc->wakeup_configured) { in dwc3_gadget_wakeup()
2436 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_wakeup()
2440 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_wakeup()
2441 if (!dwc->gadget->wakeup_armed) { in dwc3_gadget_wakeup()
2442 dev_err(dwc->dev, "not armed for remote wakeup\n"); in dwc3_gadget_wakeup()
2443 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2446 ret = __dwc3_gadget_wakeup(dwc, true); in dwc3_gadget_wakeup()
2448 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2453 static void dwc3_resume_gadget(struct dwc3 *dwc);
2457 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_func_wakeup() local
2462 if (!dwc->wakeup_configured) { in dwc3_gadget_func_wakeup()
2463 dev_err(dwc->dev, "remote wakeup not configured\n"); in dwc3_gadget_func_wakeup()
2467 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2472 link_state = dwc3_gadget_get_link_state(dwc); in dwc3_gadget_func_wakeup()
2474 ret = __dwc3_gadget_wakeup(dwc, false); in dwc3_gadget_func_wakeup()
2476 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2479 dwc3_resume_gadget(dwc); in dwc3_gadget_func_wakeup()
2480 dwc->suspended = false; in dwc3_gadget_func_wakeup()
2481 dwc->link_state = DWC3_LINK_STATE_U0; in dwc3_gadget_func_wakeup()
2484 ret = dwc3_send_gadget_generic_command(dwc, DWC3_DGCMD_DEV_NOTIFICATION, in dwc3_gadget_func_wakeup()
2488 dev_err(dwc->dev, "function remote wakeup failed, ret:%d\n", ret); in dwc3_gadget_func_wakeup()
2490 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_func_wakeup()
2497 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_remote_wakeup() local
2500 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2501 dwc->wakeup_configured = !!set; in dwc3_gadget_set_remote_wakeup()
2502 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_remote_wakeup()
2510 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_selfpowered() local
2513 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2515 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2520 static void dwc3_stop_active_transfers(struct dwc3 *dwc) in dwc3_stop_active_transfers() argument
2524 for (epnum = 2; epnum < dwc->num_eps; epnum++) { in dwc3_stop_active_transfers()
2527 dep = dwc->eps[epnum]; in dwc3_stop_active_transfers()
2531 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in dwc3_stop_active_transfers()
2535 static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) in __dwc3_gadget_set_ssp_rate() argument
2537 enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2541 ssp_rate = dwc->max_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2543 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_ssp_rate()
2549 else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) in __dwc3_gadget_set_ssp_rate()
2553 dwc->max_ssp_rate != USB_SSP_GEN_2x1) in __dwc3_gadget_set_ssp_rate()
2556 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_ssp_rate()
2559 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) in __dwc3_gadget_set_speed() argument
2564 speed = dwc->gadget_max_speed; in __dwc3_gadget_set_speed()
2565 if (speed == USB_SPEED_UNKNOWN || speed > dwc->maximum_speed) in __dwc3_gadget_set_speed()
2566 speed = dwc->maximum_speed; in __dwc3_gadget_set_speed()
2570 __dwc3_gadget_set_ssp_rate(dwc); in __dwc3_gadget_set_speed()
2574 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_speed()
2591 !dwc->dis_metastability_quirk) { in __dwc3_gadget_set_speed()
2611 dev_err(dwc->dev, "invalid speed (%d)\n", speed); in __dwc3_gadget_set_speed()
2625 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_speed()
2628 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) in dwc3_gadget_run_stop() argument
2634 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_run_stop()
2650 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_gadget_run_stop()
2662 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_gadget_run_stop()
2664 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_run_stop()
2675 __dwc3_gadget_set_speed(dwc); in dwc3_gadget_run_stop()
2676 dwc->pullups_connected = true; in dwc3_gadget_run_stop()
2680 dwc->pullups_connected = false; in dwc3_gadget_run_stop()
2683 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_run_stop()
2687 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_run_stop()
2692 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); in dwc3_gadget_run_stop()
2694 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); in dwc3_gadget_run_stop()
2703 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
2704 static void __dwc3_gadget_stop(struct dwc3 *dwc);
2705 static int __dwc3_gadget_start(struct dwc3 *dwc);
2707 static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) in dwc3_gadget_soft_disconnect() argument
2712 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2713 if (!dwc->pullups_connected) { in dwc3_gadget_soft_disconnect()
2714 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2718 dwc->connected = false; in dwc3_gadget_soft_disconnect()
2724 if (dwc->delayed_status) in dwc3_gadget_soft_disconnect()
2725 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_soft_disconnect()
2734 dwc3_stop_active_transfers(dwc); in dwc3_gadget_soft_disconnect()
2735 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2744 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_soft_disconnect()
2745 reinit_completion(&dwc->ep0_in_setup); in dwc3_gadget_soft_disconnect()
2747 ret = wait_for_completion_timeout(&dwc->ep0_in_setup, in dwc3_gadget_soft_disconnect()
2750 dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); in dwc3_gadget_soft_disconnect()
2751 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2752 dwc3_ep0_reset_state(dwc); in dwc3_gadget_soft_disconnect()
2753 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2764 ret = dwc3_gadget_run_stop(dwc, false); in dwc3_gadget_soft_disconnect()
2772 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2773 __dwc3_gadget_stop(dwc); in dwc3_gadget_soft_disconnect()
2774 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2776 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_soft_disconnect()
2781 static int dwc3_gadget_soft_connect(struct dwc3 *dwc) in dwc3_gadget_soft_connect() argument
2791 ret = dwc3_core_soft_reset(dwc); in dwc3_gadget_soft_connect()
2795 dwc3_event_buffers_setup(dwc); in dwc3_gadget_soft_connect()
2796 __dwc3_gadget_start(dwc); in dwc3_gadget_soft_connect()
2797 return dwc3_gadget_run_stop(dwc, true); in dwc3_gadget_soft_connect()
2802 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_pullup() local
2807 dwc->softconnect = is_on; in dwc3_gadget_pullup()
2815 pm_runtime_barrier(dwc->dev); in dwc3_gadget_pullup()
2816 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_pullup()
2825 ret = pm_runtime_get_sync(dwc->dev); in dwc3_gadget_pullup()
2827 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2829 pm_runtime_set_suspended(dwc->dev); in dwc3_gadget_pullup()
2833 if (dwc->pullups_connected == is_on) { in dwc3_gadget_pullup()
2834 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2838 synchronize_irq(dwc->irq_gadget); in dwc3_gadget_pullup()
2841 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_pullup()
2843 ret = dwc3_gadget_soft_connect(dwc); in dwc3_gadget_pullup()
2845 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2850 static void dwc3_gadget_enable_irq(struct dwc3 *dwc) in dwc3_gadget_enable_irq() argument
2870 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_irq()
2873 static void dwc3_gadget_disable_irq(struct dwc3 *dwc) in dwc3_gadget_disable_irq() argument
2876 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); in dwc3_gadget_disable_irq()
2884 * @dwc: pointer to our context structure
2903 static void dwc3_gadget_setup_nump(struct dwc3 *dwc) in dwc3_gadget_setup_nump() argument
2910 ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_setup_nump()
2911 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_setup_nump()
2917 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_setup_nump()
2920 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_setup_nump()
2923 static int __dwc3_gadget_start(struct dwc3 *dwc) in __dwc3_gadget_start() argument
2930 * Use IMOD if enabled via dwc->imod_interval. Otherwise, if in __dwc3_gadget_start()
2933 if (dwc->imod_interval) { in __dwc3_gadget_start()
2934 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in __dwc3_gadget_start()
2935 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in __dwc3_gadget_start()
2936 } else if (dwc3_has_imod(dwc)) { in __dwc3_gadget_start()
2937 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), 0); in __dwc3_gadget_start()
2947 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in __dwc3_gadget_start()
2953 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in __dwc3_gadget_start()
2955 dwc3_gadget_setup_nump(dwc); in __dwc3_gadget_start()
2964 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_start()
2966 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_start()
2969 if (DWC3_MST_CAPABLE(&dwc->hwparams)) { in __dwc3_gadget_start()
2970 reg = dwc3_readl(dwc->regs, DWC3_DCFG1); in __dwc3_gadget_start()
2972 dwc3_writel(dwc->regs, DWC3_DCFG1, reg); in __dwc3_gadget_start()
2978 ret = dwc3_gadget_start_config(dwc, 0); in __dwc3_gadget_start()
2980 dev_err(dwc->dev, "failed to config endpoints\n"); in __dwc3_gadget_start()
2984 dep = dwc->eps[0]; in __dwc3_gadget_start()
2988 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2992 dep = dwc->eps[1]; in __dwc3_gadget_start()
2996 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
3001 dwc->ep0state = EP0_SETUP_PHASE; in __dwc3_gadget_start()
3002 dwc->ep0_bounced = false; in __dwc3_gadget_start()
3003 dwc->link_state = DWC3_LINK_STATE_SS_DIS; in __dwc3_gadget_start()
3004 dwc->delayed_status = false; in __dwc3_gadget_start()
3005 dwc3_ep0_out_start(dwc); in __dwc3_gadget_start()
3007 dwc3_gadget_enable_irq(dwc); in __dwc3_gadget_start()
3008 dwc3_enable_susphy(dwc, true); in __dwc3_gadget_start()
3013 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_start()
3022 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_start() local
3027 irq = dwc->irq_gadget; in dwc3_gadget_start()
3029 IRQF_SHARED, "dwc3", dwc->ev_buf); in dwc3_gadget_start()
3031 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_gadget_start()
3036 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_start()
3037 dwc->gadget_driver = driver; in dwc3_gadget_start()
3038 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
3040 if (dwc->sys_wakeup) in dwc3_gadget_start()
3041 device_wakeup_enable(dwc->sysdev); in dwc3_gadget_start()
3046 static void __dwc3_gadget_stop(struct dwc3 *dwc) in __dwc3_gadget_stop() argument
3048 dwc3_gadget_disable_irq(dwc); in __dwc3_gadget_stop()
3049 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_stop()
3050 __dwc3_gadget_ep_disable(dwc->eps[1]); in __dwc3_gadget_stop()
3055 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_stop() local
3058 if (dwc->sys_wakeup) in dwc3_gadget_stop()
3059 device_wakeup_disable(dwc->sysdev); in dwc3_gadget_stop()
3061 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_stop()
3062 dwc->gadget_driver = NULL; in dwc3_gadget_stop()
3063 dwc->max_cfg_eps = 0; in dwc3_gadget_stop()
3064 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_stop()
3066 free_irq(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_stop()
3074 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_config_params() local
3080 if (!dwc->dis_enblslpm_quirk) { in dwc3_gadget_config_params()
3091 if (dwc->is_utmi_l1_suspend) in dwc3_gadget_config_params()
3093 clamp_t(u8, dwc->hird_threshold, 2, 15); in dwc3_gadget_config_params()
3097 if (dwc->dis_u1_entry_quirk) in dwc3_gadget_config_params()
3103 if (dwc->dis_u2_entry_quirk) in dwc3_gadget_config_params()
3113 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_speed() local
3116 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_speed()
3117 dwc->gadget_max_speed = speed; in dwc3_gadget_set_speed()
3118 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_speed()
3124 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_ssp_rate() local
3127 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3128 dwc->gadget_max_speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_set_ssp_rate()
3129 dwc->gadget_ssp_rate = rate; in dwc3_gadget_set_ssp_rate()
3130 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
3135 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_vbus_draw() local
3139 if (dwc->usb2_phy) in dwc3_gadget_vbus_draw()
3140 return usb_phy_set_power(dwc->usb2_phy, mA); in dwc3_gadget_vbus_draw()
3142 if (!dwc->usb_psy) in dwc3_gadget_vbus_draw()
3146 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_gadget_vbus_draw()
3163 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_check_config() local
3169 if (!dwc->do_fifo_resize) in dwc3_gadget_check_config()
3178 if (ep_num <= dwc->max_cfg_eps) in dwc3_gadget_check_config()
3182 dwc->max_cfg_eps = ep_num; in dwc3_gadget_check_config()
3184 fifo_size = dwc3_gadget_calc_tx_fifo_size(dwc, dwc->max_cfg_eps); in dwc3_gadget_check_config()
3186 fifo_size += dwc->max_cfg_eps; in dwc3_gadget_check_config()
3189 ram_depth = dwc3_gadget_calc_ram_depth(dwc); in dwc3_gadget_check_config()
3198 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_async_callbacks() local
3201 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3202 dwc->async_callbacks = enable; in dwc3_gadget_async_callbacks()
3203 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3227 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint() local
3233 dwc->gadget->ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
3242 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint() local
3247 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_in_endpoint()
3252 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
3281 &dwc->gadget->ep_list); in dwc3_gadget_init_in_endpoint()
3291 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint() local
3295 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_out_endpoint()
3301 size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0)); in dwc3_gadget_init_out_endpoint()
3328 &dwc->gadget->ep_list); in dwc3_gadget_init_out_endpoint()
3340 struct dwc3 *dwc = dep->dwc; in dwc3_nostream_work() local
3343 spin_lock_irqsave(&dwc->lock, flags); in dwc3_nostream_work()
3348 (!DWC3_MST_CAPABLE(&dwc->hwparams) && in dwc3_nostream_work()
3368 dwc3_send_gadget_generic_command(dwc, cmd, dep->number); in dwc3_nostream_work()
3372 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_nostream_work()
3377 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_nostream_work()
3380 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) in dwc3_gadget_init_endpoint() argument
3391 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
3394 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
3395 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
3432 static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) in dwc3_gadget_init_endpoints() argument
3436 INIT_LIST_HEAD(&dwc->gadget->ep_list); in dwc3_gadget_init_endpoints()
3441 ret = dwc3_gadget_init_endpoint(dwc, epnum); in dwc3_gadget_init_endpoints()
3449 static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) in dwc3_gadget_free_endpoints() argument
3455 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
3521 if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && in dwc3_gadget_ep_reclaim_completed_trb()
3522 trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { in dwc3_gadget_ep_reclaim_completed_trb()
3647 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_should_continue() local
3649 if (!dep->endpoint.desc || !dwc->pullups_connected || in dwc3_gadget_ep_should_continue()
3650 !dwc->connected) in dwc3_gadget_ep_should_continue()
3676 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_trbs_complete() local
3705 dep = dwc->eps[i]; in dwc3_gadget_endpoint_trbs_complete()
3714 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_endpoint_trbs_complete()
3715 reg |= dwc->u1u2; in dwc3_gadget_endpoint_trbs_complete()
3716 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_endpoint_trbs_complete()
3718 dwc->u1u2 = 0; in dwc3_gadget_endpoint_trbs_complete()
3798 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_command_complete() local
3802 struct usb_ep *ep0 = &dwc->eps[0]->endpoint; in dwc3_gadget_endpoint_command_complete()
3804 dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); in dwc3_gadget_endpoint_command_complete()
3805 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3811 if (dwc->clear_stall_protocol == dep->number) in dwc3_gadget_endpoint_command_complete()
3812 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_endpoint_command_complete()
3848 static void dwc3_endpoint_interrupt(struct dwc3 *dwc, in dwc3_endpoint_interrupt() argument
3854 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
3867 dwc3_ep0_interrupt(dwc, event); in dwc3_endpoint_interrupt()
3890 dev_err(dwc->dev, "unknown endpoint event %d\n", event->endpoint_event); in dwc3_endpoint_interrupt()
3895 static void dwc3_disconnect_gadget(struct dwc3 *dwc) in dwc3_disconnect_gadget() argument
3897 if (dwc->async_callbacks && dwc->gadget_driver->disconnect) { in dwc3_disconnect_gadget()
3898 spin_unlock(&dwc->lock); in dwc3_disconnect_gadget()
3899 dwc->gadget_driver->disconnect(dwc->gadget); in dwc3_disconnect_gadget()
3900 spin_lock(&dwc->lock); in dwc3_disconnect_gadget()
3904 static void dwc3_suspend_gadget(struct dwc3 *dwc) in dwc3_suspend_gadget() argument
3906 if (dwc->async_callbacks && dwc->gadget_driver->suspend) { in dwc3_suspend_gadget()
3907 spin_unlock(&dwc->lock); in dwc3_suspend_gadget()
3908 dwc->gadget_driver->suspend(dwc->gadget); in dwc3_suspend_gadget()
3909 spin_lock(&dwc->lock); in dwc3_suspend_gadget()
3913 static void dwc3_resume_gadget(struct dwc3 *dwc) in dwc3_resume_gadget() argument
3915 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_resume_gadget()
3916 spin_unlock(&dwc->lock); in dwc3_resume_gadget()
3917 dwc->gadget_driver->resume(dwc->gadget); in dwc3_resume_gadget()
3918 spin_lock(&dwc->lock); in dwc3_resume_gadget()
3922 static void dwc3_reset_gadget(struct dwc3 *dwc) in dwc3_reset_gadget() argument
3924 if (!dwc->gadget_driver) in dwc3_reset_gadget()
3927 if (dwc->async_callbacks && dwc->gadget->speed != USB_SPEED_UNKNOWN) { in dwc3_reset_gadget()
3928 spin_unlock(&dwc->lock); in dwc3_reset_gadget()
3929 usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); in dwc3_reset_gadget()
3930 spin_lock(&dwc->lock); in dwc3_reset_gadget()
3937 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer() local
3945 if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) in dwc3_stop_active_transfer()
3962 if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { in dwc3_stop_active_transfer()
4001 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) in dwc3_clear_stall_all_ep() argument
4009 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
4023 static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) in dwc3_gadget_disconnect_interrupt() argument
4027 dwc->suspended = false; in dwc3_gadget_disconnect_interrupt()
4029 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); in dwc3_gadget_disconnect_interrupt()
4031 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_disconnect_interrupt()
4034 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_disconnect_interrupt()
4036 dwc->connected = false; in dwc3_gadget_disconnect_interrupt()
4038 dwc3_disconnect_gadget(dwc); in dwc3_gadget_disconnect_interrupt()
4040 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_disconnect_interrupt()
4041 dwc->setup_packet_pending = false; in dwc3_gadget_disconnect_interrupt()
4042 dwc->gadget->wakeup_armed = false; in dwc3_gadget_disconnect_interrupt()
4043 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_disconnect_interrupt()
4044 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_disconnect_interrupt()
4046 dwc3_ep0_reset_state(dwc); in dwc3_gadget_disconnect_interrupt()
4051 * interrupt to set dwc->connected to FALSE. in dwc3_gadget_disconnect_interrupt()
4053 pm_request_idle(dwc->dev); in dwc3_gadget_disconnect_interrupt()
4056 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) in dwc3_gadget_reset_interrupt() argument
4060 dwc->suspended = false; in dwc3_gadget_reset_interrupt()
4069 dwc->connected = false; in dwc3_gadget_reset_interrupt()
4098 if (dwc->setup_packet_pending) in dwc3_gadget_reset_interrupt()
4099 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_reset_interrupt()
4102 dwc3_reset_gadget(dwc); in dwc3_gadget_reset_interrupt()
4109 dwc3_ep0_reset_state(dwc); in dwc3_gadget_reset_interrupt()
4117 dwc3_stop_active_transfers(dwc); in dwc3_gadget_reset_interrupt()
4118 dwc->connected = true; in dwc3_gadget_reset_interrupt()
4120 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_reset_interrupt()
4122 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_reset_interrupt()
4123 dwc->test_mode = false; in dwc3_gadget_reset_interrupt()
4124 dwc->gadget->wakeup_armed = false; in dwc3_gadget_reset_interrupt()
4125 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_reset_interrupt()
4126 dwc3_clear_stall_all_ep(dwc); in dwc3_gadget_reset_interrupt()
4129 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_reset_interrupt()
4131 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_reset_interrupt()
4134 static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) in dwc3_gadget_conndone_interrupt() argument
4142 if (!dwc->softconnect) in dwc3_gadget_conndone_interrupt()
4145 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_conndone_interrupt()
4147 dwc->speed = speed; in dwc3_gadget_conndone_interrupt()
4152 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_conndone_interrupt()
4166 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4167 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4170 dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; in dwc3_gadget_conndone_interrupt()
4172 dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; in dwc3_gadget_conndone_interrupt()
4189 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_conndone_interrupt()
4192 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4193 dwc->gadget->speed = USB_SPEED_SUPER; in dwc3_gadget_conndone_interrupt()
4196 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4197 dwc->gadget->ssp_rate = USB_SSP_GEN_1x2; in dwc3_gadget_conndone_interrupt()
4202 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4203 dwc->gadget->speed = USB_SPEED_HIGH; in dwc3_gadget_conndone_interrupt()
4207 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4208 dwc->gadget->speed = USB_SPEED_FULL; in dwc3_gadget_conndone_interrupt()
4212 dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; in dwc3_gadget_conndone_interrupt()
4217 !dwc->usb2_gadget_lpm_disable && in dwc3_gadget_conndone_interrupt()
4220 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4222 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()
4227 reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold | in dwc3_gadget_conndone_interrupt()
4228 (dwc->is_utmi_l1_suspend << 4)); in dwc3_gadget_conndone_interrupt()
4236 WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum, in dwc3_gadget_conndone_interrupt()
4239 if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) { in dwc3_gadget_conndone_interrupt()
4241 reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); in dwc3_gadget_conndone_interrupt()
4244 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4246 if (dwc->usb2_gadget_lpm_disable) { in dwc3_gadget_conndone_interrupt()
4247 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4249 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4252 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4254 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4257 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
4260 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4264 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
4267 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4280 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo) in dwc3_gadget_wakeup_interrupt() argument
4282 dwc->suspended = false; in dwc3_gadget_wakeup_interrupt()
4289 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_gadget_wakeup_interrupt()
4290 spin_unlock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4291 dwc->gadget_driver->resume(dwc->gadget); in dwc3_gadget_wakeup_interrupt()
4292 spin_lock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4295 dwc->link_state = evtinfo & DWC3_LINK_STATE_MASK; in dwc3_gadget_wakeup_interrupt()
4298 static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, in dwc3_gadget_linksts_change_interrupt() argument
4321 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_gadget_linksts_change_interrupt()
4324 if ((dwc->link_state == DWC3_LINK_STATE_U3) && in dwc3_gadget_linksts_change_interrupt()
4353 switch (dwc->link_state) { in dwc3_gadget_linksts_change_interrupt()
4356 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_linksts_change_interrupt()
4362 if (!dwc->u1u2) in dwc3_gadget_linksts_change_interrupt()
4363 dwc->u1u2 = reg & u1u2; in dwc3_gadget_linksts_change_interrupt()
4367 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_linksts_change_interrupt()
4378 if (dwc->gadget->wakeup_armed) { in dwc3_gadget_linksts_change_interrupt()
4379 dwc3_gadget_enable_linksts_evts(dwc, false); in dwc3_gadget_linksts_change_interrupt()
4380 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4381 dwc->suspended = false; in dwc3_gadget_linksts_change_interrupt()
4385 if (dwc->speed == USB_SPEED_SUPER) in dwc3_gadget_linksts_change_interrupt()
4386 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4390 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4393 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4400 dwc->link_state = next; in dwc3_gadget_linksts_change_interrupt()
4403 static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, in dwc3_gadget_suspend_interrupt() argument
4408 if (!dwc->suspended && next == DWC3_LINK_STATE_U3) { in dwc3_gadget_suspend_interrupt()
4409 dwc->suspended = true; in dwc3_gadget_suspend_interrupt()
4410 dwc3_suspend_gadget(dwc); in dwc3_gadget_suspend_interrupt()
4413 dwc->link_state = next; in dwc3_gadget_suspend_interrupt()
4416 static void dwc3_gadget_interrupt(struct dwc3 *dwc, in dwc3_gadget_interrupt() argument
4421 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_interrupt()
4424 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_interrupt()
4427 dwc3_gadget_conndone_interrupt(dwc); in dwc3_gadget_interrupt()
4430 dwc3_gadget_wakeup_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4433 dev_WARN_ONCE(dwc->dev, true, "unexpected hibernation event\n"); in dwc3_gadget_interrupt()
4436 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4441 dwc3_gadget_suspend_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4449 dev_WARN(dwc->dev, "UNKNOWN IRQ %d\n", event->type); in dwc3_gadget_interrupt()
4453 static void dwc3_process_event_entry(struct dwc3 *dwc, in dwc3_process_event_entry() argument
4456 trace_dwc3_event(event->raw, dwc); in dwc3_process_event_entry()
4459 dwc3_endpoint_interrupt(dwc, &event->depevt); in dwc3_process_event_entry()
4461 dwc3_gadget_interrupt(dwc, &event->devt); in dwc3_process_event_entry()
4463 dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); in dwc3_process_event_entry()
4468 struct dwc3 *dwc = evt->dwc; in dwc3_process_event_buf() local
4482 dwc3_process_event_entry(dwc, &event); in dwc3_process_event_buf()
4501 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_process_event_buf()
4511 if (dwc->imod_interval) { in dwc3_process_event_buf()
4512 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in dwc3_process_event_buf()
4513 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in dwc3_process_event_buf()
4522 struct dwc3 *dwc = evt->dwc; in dwc3_thread_interrupt() local
4527 spin_lock_irqsave(&dwc->lock, flags); in dwc3_thread_interrupt()
4529 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_thread_interrupt()
4537 struct dwc3 *dwc = evt->dwc; in dwc3_check_event_buf() local
4541 if (pm_runtime_suspended(dwc->dev)) { in dwc3_check_event_buf()
4542 dwc->pending_events = true; in dwc3_check_event_buf()
4548 pm_runtime_get(dwc->dev); in dwc3_check_event_buf()
4549 disable_irq_nosync(dwc->irq_gadget); in dwc3_check_event_buf()
4562 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_check_event_buf()
4571 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_check_event_buf()
4580 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); in dwc3_check_event_buf()
4592 static int dwc3_gadget_get_irq(struct dwc3 *dwc) in dwc3_gadget_get_irq() argument
4594 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_gadget_get_irq()
4626 * @dwc: pointer to our controller context structure
4630 int dwc3_gadget_init(struct dwc3 *dwc) in dwc3_gadget_init() argument
4636 irq = dwc3_gadget_get_irq(dwc); in dwc3_gadget_init()
4642 dwc->irq_gadget = irq; in dwc3_gadget_init()
4644 dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev, in dwc3_gadget_init()
4645 sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4646 &dwc->ep0_trb_addr, GFP_KERNEL); in dwc3_gadget_init()
4647 if (!dwc->ep0_trb) { in dwc3_gadget_init()
4648 dev_err(dwc->dev, "failed to allocate ep0 trb\n"); in dwc3_gadget_init()
4653 dwc->setup_buf = kzalloc(DWC3_EP0_SETUP_SIZE, GFP_KERNEL); in dwc3_gadget_init()
4654 if (!dwc->setup_buf) { in dwc3_gadget_init()
4659 dwc->bounce = dma_alloc_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, in dwc3_gadget_init()
4660 &dwc->bounce_addr, GFP_KERNEL); in dwc3_gadget_init()
4661 if (!dwc->bounce) { in dwc3_gadget_init()
4666 init_completion(&dwc->ep0_in_setup); in dwc3_gadget_init()
4667 dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); in dwc3_gadget_init()
4668 if (!dwc->gadget) { in dwc3_gadget_init()
4674 usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); in dwc3_gadget_init()
4675 dev = &dwc->gadget->dev; in dwc3_gadget_init()
4676 dev->platform_data = dwc; in dwc3_gadget_init()
4677 dwc->gadget->ops = &dwc3_gadget_ops; in dwc3_gadget_init()
4678 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_init()
4679 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_init()
4680 dwc->gadget->sg_supported = true; in dwc3_gadget_init()
4681 dwc->gadget->name = "dwc3-gadget"; in dwc3_gadget_init()
4682 dwc->gadget->lpm_capable = !dwc->usb2_gadget_lpm_disable; in dwc3_gadget_init()
4683 dwc->gadget->wakeup_capable = true; in dwc3_gadget_init()
4702 !dwc->dis_metastability_quirk) in dwc3_gadget_init()
4703 dev_info(dwc->dev, "changing max_speed on rev %08x\n", in dwc3_gadget_init()
4704 dwc->revision); in dwc3_gadget_init()
4706 dwc->gadget->max_speed = dwc->maximum_speed; in dwc3_gadget_init()
4707 dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; in dwc3_gadget_init()
4714 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); in dwc3_gadget_init()
4718 ret = usb_add_gadget(dwc->gadget); in dwc3_gadget_init()
4720 dev_err(dwc->dev, "failed to add gadget\n"); in dwc3_gadget_init()
4724 if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) in dwc3_gadget_init()
4725 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); in dwc3_gadget_init()
4727 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); in dwc3_gadget_init()
4730 if (dwc->sys_wakeup) in dwc3_gadget_init()
4731 device_wakeup_disable(dwc->sysdev); in dwc3_gadget_init()
4736 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_init()
4738 usb_put_gadget(dwc->gadget); in dwc3_gadget_init()
4739 dwc->gadget = NULL; in dwc3_gadget_init()
4741 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_init()
4742 dwc->bounce_addr); in dwc3_gadget_init()
4745 kfree(dwc->setup_buf); in dwc3_gadget_init()
4748 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4749 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_init()
4757 void dwc3_gadget_exit(struct dwc3 *dwc) in dwc3_gadget_exit() argument
4759 if (!dwc->gadget) in dwc3_gadget_exit()
4762 dwc3_enable_susphy(dwc, false); in dwc3_gadget_exit()
4763 usb_del_gadget(dwc->gadget); in dwc3_gadget_exit()
4764 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_exit()
4765 usb_put_gadget(dwc->gadget); in dwc3_gadget_exit()
4766 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_exit()
4767 dwc->bounce_addr); in dwc3_gadget_exit()
4768 kfree(dwc->setup_buf); in dwc3_gadget_exit()
4769 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_exit()
4770 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_exit()
4773 int dwc3_gadget_suspend(struct dwc3 *dwc) in dwc3_gadget_suspend() argument
4778 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_suspend()
4782 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_suspend()
4783 if (dwc->gadget_driver) in dwc3_gadget_suspend()
4784 dwc3_disconnect_gadget(dwc); in dwc3_gadget_suspend()
4785 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_suspend()
4795 if (dwc->softconnect) in dwc3_gadget_suspend()
4796 dwc3_gadget_soft_connect(dwc); in dwc3_gadget_suspend()
4801 int dwc3_gadget_resume(struct dwc3 *dwc) in dwc3_gadget_resume() argument
4803 if (!dwc->gadget_driver || !dwc->softconnect) in dwc3_gadget_resume()
4806 return dwc3_gadget_soft_connect(dwc); in dwc3_gadget_resume()