• Home
  • Raw
  • Download

Lines Matching refs:dwc

41 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)  in dwc3_gadget_set_test_mode()  argument
45 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_set_test_mode()
60 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_set_test_mode()
72 int dwc3_gadget_get_link_state(struct dwc3 *dwc) in dwc3_gadget_get_link_state() argument
76 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_get_link_state()
89 int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) in dwc3_gadget_set_link_state() argument
100 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_set_link_state()
111 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_set_link_state()
115 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_set_link_state()
119 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_set_link_state()
131 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_set_link_state()
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()
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);
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); 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()
460 struct dwc3 *dwc = dep->dwc; in dwc3_send_clear_stall_ep_cmd() local
474 (dwc->gadget->speed >= USB_SPEED_SUPER)) in dwc3_send_clear_stall_ep_cmd()
492 struct dwc3 *dwc = dep->dwc; in dwc3_alloc_trb_pool() local
497 dep->trb_pool = dma_alloc_coherent(dwc->sysdev, in dwc3_alloc_trb_pool()
501 dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", in dwc3_alloc_trb_pool()
511 struct dwc3 *dwc = dep->dwc; in dwc3_free_trb_pool() local
513 dma_free_coherent(dwc->sysdev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, in dwc3_free_trb_pool()
568 struct dwc3 *dwc; in dwc3_gadget_start_config() local
578 dwc = dep->dwc; in dwc3_gadget_start_config()
585 struct dwc3_ep *dep = dwc->eps[i]; in dwc3_gadget_start_config()
603 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_set_ep_config() local
614 if (dwc->gadget->speed >= USB_SPEED_SUPER) { in dwc3_gadget_set_ep_config()
669 dwc->gadget->speed == USB_SPEED_FULL) in dwc3_gadget_set_ep_config()
697 static int dwc3_gadget_calc_tx_fifo_size(struct dwc3 *dwc, int mult) in dwc3_gadget_calc_tx_fifo_size() argument
703 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_calc_tx_fifo_size()
722 void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) in dwc3_gadget_clear_tx_fifos() argument
729 if (!dwc->do_fifo_resize) in dwc3_gadget_clear_tx_fifos()
733 dep = dwc->eps[1]; in dwc3_gadget_clear_tx_fifos()
734 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_clear_tx_fifos()
740 dwc->last_fifo_depth = fifo_depth; in dwc3_gadget_clear_tx_fifos()
742 for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); in dwc3_gadget_clear_tx_fifos()
744 dep = dwc->eps[num]; in dwc3_gadget_clear_tx_fifos()
747 dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & in dwc3_gadget_clear_tx_fifos()
750 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1), size); in dwc3_gadget_clear_tx_fifos()
753 dwc->num_ep_resized = 0; in dwc3_gadget_clear_tx_fifos()
779 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_resize_tx_fifos() local
790 if (!dwc->do_fifo_resize) in dwc3_gadget_resize_tx_fifos()
801 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_resize_tx_fifos()
811 num_fifos = dwc->tx_fifo_resize_max_num; in dwc3_gadget_resize_tx_fifos()
814 fifo = dwc3_gadget_calc_tx_fifo_size(dwc, 1); in dwc3_gadget_resize_tx_fifos()
817 num_in_ep = dwc->max_cfg_eps; in dwc3_gadget_resize_tx_fifos()
818 num_in_ep -= dwc->num_ep_resized; in dwc3_gadget_resize_tx_fifos()
822 remaining = ram1_depth - min_depth - dwc->last_fifo_depth; in dwc3_gadget_resize_tx_fifos()
838 tmp = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)); in dwc3_gadget_resize_tx_fifos()
841 fifo_size |= (fifo_0_start + (dwc->last_fifo_depth << 16)); in dwc3_gadget_resize_tx_fifos()
843 dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
845 dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEP(fifo_size); in dwc3_gadget_resize_tx_fifos()
848 if (dwc->last_fifo_depth >= ram1_depth) { in dwc3_gadget_resize_tx_fifos()
849 dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n", in dwc3_gadget_resize_tx_fifos()
850 dwc->last_fifo_depth, ram1_depth, in dwc3_gadget_resize_tx_fifos()
857 dwc->last_fifo_depth -= fifo_size; in dwc3_gadget_resize_tx_fifos()
861 dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1), fifo_size); in dwc3_gadget_resize_tx_fifos()
863 dwc->num_ep_resized++; in dwc3_gadget_resize_tx_fifos()
879 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_enable() local
905 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_enable()
907 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_enable()
979 !(dwc->hwparams.hwparams9 & in __dwc3_gadget_ep_enable()
991 void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) in dwc3_remove_requests() argument
1033 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_disable() local
1043 reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); in __dwc3_gadget_ep_disable()
1045 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); in __dwc3_gadget_ep_disable()
1047 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in __dwc3_gadget_ep_disable()
1089 struct dwc3 *dwc; in dwc3_gadget_ep_enable() local
1104 dwc = dep->dwc; in dwc3_gadget_ep_enable()
1106 if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, in dwc3_gadget_ep_enable()
1111 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1113 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_enable()
1121 struct dwc3 *dwc; in dwc3_gadget_ep_disable() local
1131 dwc = dep->dwc; in dwc3_gadget_ep_disable()
1133 if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), in dwc3_gadget_ep_disable()
1138 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1140 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_disable()
1243 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_one_trb() local
1244 struct usb_gadget *gadget = dwc->gadget; in dwc3_prepare_one_trb()
1248 dma = dep->dwc->bounce_addr; in dwc3_prepare_one_trb()
1329 dev_WARN(dwc->dev, "Unknown endpoint type %d\n", in dwc3_prepare_one_trb()
1572 struct dwc3 *dwc = dep->dwc; in dwc3_prepare_trbs() local
1574 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, in dwc3_prepare_trbs()
1683 static int __dwc3_gadget_get_frame(struct dwc3 *dwc) in __dwc3_gadget_get_frame() argument
1687 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_get_frame()
1704 struct dwc3 *dwc = dep->dwc; in __dwc3_stop_active_transfer() local
1721 if (ret == -ETIMEDOUT && dep->dwc->ep0state != EP0_SETUP_PHASE) { in __dwc3_stop_active_transfer()
1801 params.param0 = upper_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1802 params.param1 = lower_32_bits(dep->dwc->bounce_addr); in dwc3_gadget_start_isoc_quirk()
1858 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_start_isoc() local
1868 if (!dwc->dis_start_transfer_quirk && in __dwc3_gadget_start_isoc()
1871 if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) in __dwc3_gadget_start_isoc()
1876 dwc->gadget->speed >= USB_SPEED_HIGH) { in __dwc3_gadget_start_isoc()
1877 u32 frame = __dwc3_gadget_get_frame(dwc); in __dwc3_gadget_start_isoc()
1923 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_queue() local
1925 if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { in __dwc3_gadget_ep_queue()
1926 dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", in __dwc3_gadget_ep_queue()
1940 pm_runtime_get(dwc->dev); in __dwc3_gadget_ep_queue()
1992 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_queue() local
1998 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2000 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_queue()
2037 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_cleanup_cancelled_requests() local
2053 dev_err(dwc->dev, "request cancelled with wrong reason:%d\n", req->status); in dwc3_gadget_ep_cleanup_cancelled_requests()
2073 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_dequeue() local
2080 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2099 dwc3_ep0_reset_state(dwc); in dwc3_gadget_ep_dequeue()
2125 dev_err(dwc->dev, "request %pK was not queued to %s\n", in dwc3_gadget_ep_dequeue()
2129 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_dequeue()
2137 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep_set_halt() local
2141 dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); in __dwc3_gadget_ep_set_halt()
2156 trb = &dwc->ep0_trb[dep->trb_enqueue]; in __dwc3_gadget_ep_set_halt()
2169 dev_err(dwc->dev, "failed to set STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2197 dev_err(dwc->dev, "failed to clear STALL on %s\n", in __dwc3_gadget_ep_set_halt()
2217 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_halt() local
2223 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2225 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_halt()
2233 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_set_wedge() local
2237 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2244 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep_set_wedge()
2283 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_get_frame() local
2285 return __dwc3_gadget_get_frame(dwc); in dwc3_gadget_get_frame()
2288 static int __dwc3_gadget_wakeup(struct dwc3 *dwc) in __dwc3_gadget_wakeup() argument
2303 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2319 ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV); in __dwc3_gadget_wakeup()
2321 dev_err(dwc->dev, "failed to put link in Recovery\n"); in __dwc3_gadget_wakeup()
2328 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in __dwc3_gadget_wakeup()
2330 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in __dwc3_gadget_wakeup()
2337 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in __dwc3_gadget_wakeup()
2345 dev_err(dwc->dev, "failed to send remote wakeup\n"); in __dwc3_gadget_wakeup()
2354 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_wakeup() local
2358 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_wakeup()
2359 ret = __dwc3_gadget_wakeup(dwc); in dwc3_gadget_wakeup()
2360 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_wakeup()
2368 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_selfpowered() local
2371 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2373 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_selfpowered()
2378 static void dwc3_stop_active_transfers(struct dwc3 *dwc) in dwc3_stop_active_transfers() argument
2382 for (epnum = 2; epnum < dwc->num_eps; epnum++) { in dwc3_stop_active_transfers()
2385 dep = dwc->eps[epnum]; in dwc3_stop_active_transfers()
2389 dwc3_remove_requests(dwc, dep, -ESHUTDOWN); in dwc3_stop_active_transfers()
2393 static void __dwc3_gadget_set_ssp_rate(struct dwc3 *dwc) in __dwc3_gadget_set_ssp_rate() argument
2395 enum usb_ssp_rate ssp_rate = dwc->gadget_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2399 ssp_rate = dwc->max_ssp_rate; in __dwc3_gadget_set_ssp_rate()
2401 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_ssp_rate()
2407 else if (dwc->max_ssp_rate != USB_SSP_GEN_1x2) in __dwc3_gadget_set_ssp_rate()
2411 dwc->max_ssp_rate != USB_SSP_GEN_2x1) in __dwc3_gadget_set_ssp_rate()
2414 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_ssp_rate()
2417 static void __dwc3_gadget_set_speed(struct dwc3 *dwc) in __dwc3_gadget_set_speed() argument
2422 speed = dwc->gadget_max_speed; in __dwc3_gadget_set_speed()
2423 if (speed == USB_SPEED_UNKNOWN || speed > dwc->maximum_speed) in __dwc3_gadget_set_speed()
2424 speed = dwc->maximum_speed; in __dwc3_gadget_set_speed()
2428 __dwc3_gadget_set_ssp_rate(dwc); in __dwc3_gadget_set_speed()
2432 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_set_speed()
2449 !dwc->dis_metastability_quirk) { in __dwc3_gadget_set_speed()
2472 dev_err(dwc->dev, "invalid speed (%d)\n", speed); in __dwc3_gadget_set_speed()
2486 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_set_speed()
2489 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) in dwc3_gadget_run_stop() argument
2494 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_run_stop()
2497 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_run_stop()
2508 if (dwc->has_hibernation) in dwc3_gadget_run_stop()
2511 __dwc3_gadget_set_speed(dwc); in dwc3_gadget_run_stop()
2512 dwc->pullups_connected = true; in dwc3_gadget_run_stop()
2516 if (dwc->has_hibernation && !suspend) in dwc3_gadget_run_stop()
2519 dwc->pullups_connected = false; in dwc3_gadget_run_stop()
2522 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_run_stop()
2526 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_run_stop()
2536 static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
2537 static void __dwc3_gadget_stop(struct dwc3 *dwc);
2538 static int __dwc3_gadget_start(struct dwc3 *dwc);
2540 static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) in dwc3_gadget_soft_disconnect() argument
2545 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2546 dwc->connected = false; in dwc3_gadget_soft_disconnect()
2552 if (dwc->delayed_status) in dwc3_gadget_soft_disconnect()
2553 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_soft_disconnect()
2562 dwc3_stop_active_transfers(dwc); in dwc3_gadget_soft_disconnect()
2563 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2572 if (dwc->ep0state != EP0_SETUP_PHASE) { in dwc3_gadget_soft_disconnect()
2573 reinit_completion(&dwc->ep0_in_setup); in dwc3_gadget_soft_disconnect()
2575 ret = wait_for_completion_timeout(&dwc->ep0_in_setup, in dwc3_gadget_soft_disconnect()
2578 dev_warn(dwc->dev, "wait for SETUP phase timed out\n"); in dwc3_gadget_soft_disconnect()
2579 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2580 dwc3_ep0_reset_state(dwc); in dwc3_gadget_soft_disconnect()
2581 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2592 ret = dwc3_gadget_run_stop(dwc, false, false); in dwc3_gadget_soft_disconnect()
2600 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2601 __dwc3_gadget_stop(dwc); in dwc3_gadget_soft_disconnect()
2602 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_soft_disconnect()
2609 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_pullup() local
2610 struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc); in dwc3_gadget_pullup()
2623 pm_runtime_barrier(dwc->dev); in dwc3_gadget_pullup()
2624 if (pm_runtime_suspended(dwc->dev)) in dwc3_gadget_pullup()
2633 ret = pm_runtime_get_sync(dwc->dev); in dwc3_gadget_pullup()
2635 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2637 pm_runtime_set_suspended(dwc->dev); in dwc3_gadget_pullup()
2641 if (dwc->pullups_connected == is_on) { in dwc3_gadget_pullup()
2642 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2646 synchronize_irq(dwc->irq_gadget); in dwc3_gadget_pullup()
2649 ret = dwc3_gadget_soft_disconnect(dwc); in dwc3_gadget_pullup()
2657 ret = dwc3_core_soft_reset(dwc); in dwc3_gadget_pullup()
2661 dwc3_event_buffers_setup(dwc); in dwc3_gadget_pullup()
2662 __dwc3_gadget_start(dwc); in dwc3_gadget_pullup()
2663 ret = dwc3_gadget_run_stop(dwc, true, false); in dwc3_gadget_pullup()
2667 pm_runtime_put(dwc->dev); in dwc3_gadget_pullup()
2672 static void dwc3_gadget_enable_irq(struct dwc3 *dwc) in dwc3_gadget_enable_irq() argument
2692 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); in dwc3_gadget_enable_irq()
2695 static void dwc3_gadget_disable_irq(struct dwc3 *dwc) in dwc3_gadget_disable_irq() argument
2698 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); in dwc3_gadget_disable_irq()
2725 static void dwc3_gadget_setup_nump(struct dwc3 *dwc) in dwc3_gadget_setup_nump() argument
2732 ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_setup_nump()
2733 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_setup_nump()
2739 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_setup_nump()
2742 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_setup_nump()
2745 static int __dwc3_gadget_start(struct dwc3 *dwc) in __dwc3_gadget_start() argument
2755 if (dwc->imod_interval) { in __dwc3_gadget_start()
2756 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in __dwc3_gadget_start()
2757 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in __dwc3_gadget_start()
2758 } else if (dwc3_has_imod(dwc)) { in __dwc3_gadget_start()
2759 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), 0); in __dwc3_gadget_start()
2769 reg = dwc3_readl(dwc->regs, DWC3_GRXTHRCFG); in __dwc3_gadget_start()
2775 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); in __dwc3_gadget_start()
2777 dwc3_gadget_setup_nump(dwc); in __dwc3_gadget_start()
2786 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in __dwc3_gadget_start()
2788 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in __dwc3_gadget_start()
2793 dep = dwc->eps[0]; in __dwc3_gadget_start()
2797 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2801 dep = dwc->eps[1]; in __dwc3_gadget_start()
2805 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in __dwc3_gadget_start()
2810 dwc->ep0state = EP0_SETUP_PHASE; in __dwc3_gadget_start()
2811 dwc->ep0_bounced = false; in __dwc3_gadget_start()
2812 dwc->link_state = DWC3_LINK_STATE_SS_DIS; in __dwc3_gadget_start()
2813 dwc->delayed_status = false; in __dwc3_gadget_start()
2814 dwc3_ep0_out_start(dwc); in __dwc3_gadget_start()
2816 dwc3_gadget_enable_irq(dwc); in __dwc3_gadget_start()
2821 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_start()
2830 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_start() local
2835 irq = dwc->irq_gadget; in dwc3_gadget_start()
2837 IRQF_SHARED, "dwc3", dwc->ev_buf); in dwc3_gadget_start()
2839 dev_err(dwc->dev, "failed to request irq #%d --> %d\n", in dwc3_gadget_start()
2844 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_start()
2845 if (dwc->gadget_driver) { in dwc3_gadget_start()
2846 dev_err(dwc->dev, "%s is already bound to %s\n", in dwc3_gadget_start()
2847 dwc->gadget->name, in dwc3_gadget_start()
2848 dwc->gadget_driver->driver.name); in dwc3_gadget_start()
2853 dwc->gadget_driver = driver; in dwc3_gadget_start()
2854 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
2859 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_start()
2860 free_irq(irq, dwc); in dwc3_gadget_start()
2866 static void __dwc3_gadget_stop(struct dwc3 *dwc) in __dwc3_gadget_stop() argument
2868 dwc3_gadget_disable_irq(dwc); in __dwc3_gadget_stop()
2869 __dwc3_gadget_ep_disable(dwc->eps[0]); in __dwc3_gadget_stop()
2870 __dwc3_gadget_ep_disable(dwc->eps[1]); in __dwc3_gadget_stop()
2875 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_stop() local
2878 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_stop()
2879 dwc->gadget_driver = NULL; in dwc3_gadget_stop()
2880 dwc->max_cfg_eps = 0; in dwc3_gadget_stop()
2881 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_stop()
2883 free_irq(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_stop()
2891 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_config_params() local
2897 if (!dwc->dis_enblslpm_quirk) { in dwc3_gadget_config_params()
2908 if (dwc->is_utmi_l1_suspend) in dwc3_gadget_config_params()
2910 clamp_t(u8, dwc->hird_threshold, 2, 15); in dwc3_gadget_config_params()
2914 if (dwc->dis_u1_entry_quirk) in dwc3_gadget_config_params()
2920 if (dwc->dis_u2_entry_quirk) in dwc3_gadget_config_params()
2930 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_speed() local
2933 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_speed()
2934 dwc->gadget_max_speed = speed; in dwc3_gadget_set_speed()
2935 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_speed()
2941 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_set_ssp_rate() local
2944 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
2945 dwc->gadget_max_speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_set_ssp_rate()
2946 dwc->gadget_ssp_rate = rate; in dwc3_gadget_set_ssp_rate()
2947 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_set_ssp_rate()
2952 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_vbus_draw() local
2956 if (dwc->usb2_phy) in dwc3_gadget_vbus_draw()
2957 return usb_phy_set_power(dwc->usb2_phy, mA); in dwc3_gadget_vbus_draw()
2959 if (!dwc->usb_psy) in dwc3_gadget_vbus_draw()
2963 ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); in dwc3_gadget_vbus_draw()
2980 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_check_config() local
2986 if (!dwc->do_fifo_resize) in dwc3_gadget_check_config()
2995 if (ep_num <= dwc->max_cfg_eps) in dwc3_gadget_check_config()
2999 dwc->max_cfg_eps = ep_num; in dwc3_gadget_check_config()
3001 fifo_size = dwc3_gadget_calc_tx_fifo_size(dwc, dwc->max_cfg_eps); in dwc3_gadget_check_config()
3003 fifo_size += dwc->max_cfg_eps; in dwc3_gadget_check_config()
3006 ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7); in dwc3_gadget_check_config()
3015 struct dwc3 *dwc = gadget_to_dwc(g); in dwc3_gadget_async_callbacks() local
3018 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3019 dwc->async_callbacks = enable; in dwc3_gadget_async_callbacks()
3020 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_async_callbacks()
3042 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_control_endpoint() local
3048 dwc->gadget->ep0 = &dep->endpoint; in dwc3_gadget_init_control_endpoint()
3057 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_in_endpoint() local
3062 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_in_endpoint()
3067 size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1)); in dwc3_gadget_init_in_endpoint()
3096 &dwc->gadget->ep_list); in dwc3_gadget_init_in_endpoint()
3106 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_init_out_endpoint() local
3110 mdwidth = dwc3_mdwidth(dwc); in dwc3_gadget_init_out_endpoint()
3116 size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0)); in dwc3_gadget_init_out_endpoint()
3143 &dwc->gadget->ep_list); in dwc3_gadget_init_out_endpoint()
3151 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) in dwc3_gadget_init_endpoint() argument
3162 dep->dwc = dwc; in dwc3_gadget_init_endpoint()
3165 dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); in dwc3_gadget_init_endpoint()
3166 dwc->eps[epnum] = dep; in dwc3_gadget_init_endpoint()
3202 static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total) in dwc3_gadget_init_endpoints() argument
3206 INIT_LIST_HEAD(&dwc->gadget->ep_list); in dwc3_gadget_init_endpoints()
3211 ret = dwc3_gadget_init_endpoint(dwc, epnum); in dwc3_gadget_init_endpoints()
3219 static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) in dwc3_gadget_free_endpoints() argument
3225 dep = dwc->eps[epnum]; in dwc3_gadget_free_endpoints()
3242 debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root)); in dwc3_gadget_free_endpoints()
3291 if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && in dwc3_gadget_ep_reclaim_completed_trb()
3292 trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { in dwc3_gadget_ep_reclaim_completed_trb()
3442 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep_should_continue() local
3444 if (!dep->endpoint.desc || !dwc->pullups_connected || in dwc3_gadget_ep_should_continue()
3445 !dwc->connected) in dwc3_gadget_ep_should_continue()
3471 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_trbs_complete() local
3500 dep = dwc->eps[i]; in dwc3_gadget_endpoint_trbs_complete()
3509 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_endpoint_trbs_complete()
3510 reg |= dwc->u1u2; in dwc3_gadget_endpoint_trbs_complete()
3511 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_gadget_endpoint_trbs_complete()
3513 dwc->u1u2 = 0; in dwc3_gadget_endpoint_trbs_complete()
3593 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_command_complete() local
3597 struct usb_ep *ep0 = &dwc->eps[0]->endpoint; in dwc3_gadget_endpoint_command_complete()
3599 dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); in dwc3_gadget_endpoint_command_complete()
3600 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3606 if (dwc->delayed_status) in dwc3_gadget_endpoint_command_complete()
3607 dwc3_ep0_send_delayed_status(dwc); in dwc3_gadget_endpoint_command_complete()
3620 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_endpoint_stream_event() local
3668 dwc3_send_gadget_generic_command(dwc, cmd, dep->number); in dwc3_gadget_endpoint_stream_event()
3681 static void dwc3_endpoint_interrupt(struct dwc3 *dwc, in dwc3_endpoint_interrupt() argument
3687 dep = dwc->eps[epnum]; in dwc3_endpoint_interrupt()
3700 dwc3_ep0_interrupt(dwc, event); in dwc3_endpoint_interrupt()
3725 static void dwc3_disconnect_gadget(struct dwc3 *dwc) in dwc3_disconnect_gadget() argument
3727 if (dwc->async_callbacks && dwc->gadget_driver->disconnect) { in dwc3_disconnect_gadget()
3728 spin_unlock(&dwc->lock); in dwc3_disconnect_gadget()
3729 dwc->gadget_driver->disconnect(dwc->gadget); in dwc3_disconnect_gadget()
3730 spin_lock(&dwc->lock); in dwc3_disconnect_gadget()
3734 static void dwc3_suspend_gadget(struct dwc3 *dwc) in dwc3_suspend_gadget() argument
3736 if (dwc->async_callbacks && dwc->gadget_driver->suspend) { in dwc3_suspend_gadget()
3737 spin_unlock(&dwc->lock); in dwc3_suspend_gadget()
3738 dwc->gadget_driver->suspend(dwc->gadget); in dwc3_suspend_gadget()
3739 spin_lock(&dwc->lock); in dwc3_suspend_gadget()
3743 static void dwc3_resume_gadget(struct dwc3 *dwc) in dwc3_resume_gadget() argument
3745 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_resume_gadget()
3746 spin_unlock(&dwc->lock); in dwc3_resume_gadget()
3747 dwc->gadget_driver->resume(dwc->gadget); in dwc3_resume_gadget()
3748 spin_lock(&dwc->lock); in dwc3_resume_gadget()
3752 static void dwc3_reset_gadget(struct dwc3 *dwc) in dwc3_reset_gadget() argument
3754 if (!dwc->gadget_driver) in dwc3_reset_gadget()
3757 if (dwc->async_callbacks && dwc->gadget->speed != USB_SPEED_UNKNOWN) { in dwc3_reset_gadget()
3758 spin_unlock(&dwc->lock); in dwc3_reset_gadget()
3759 usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); in dwc3_reset_gadget()
3760 spin_lock(&dwc->lock); in dwc3_reset_gadget()
3767 struct dwc3 *dwc = dep->dwc; in dwc3_stop_active_transfer() local
3775 if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE) in dwc3_stop_active_transfer()
3792 if (dwc->ep0state != EP0_SETUP_PHASE && !dwc->delayed_status) { in dwc3_stop_active_transfer()
3832 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) in dwc3_clear_stall_all_ep() argument
3840 dep = dwc->eps[epnum]; in dwc3_clear_stall_all_ep()
3854 static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) in dwc3_gadget_disconnect_interrupt() argument
3858 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); in dwc3_gadget_disconnect_interrupt()
3860 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_disconnect_interrupt()
3863 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_disconnect_interrupt()
3865 dwc->connected = false; in dwc3_gadget_disconnect_interrupt()
3867 dwc3_disconnect_gadget(dwc); in dwc3_gadget_disconnect_interrupt()
3869 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_disconnect_interrupt()
3870 dwc->setup_packet_pending = false; in dwc3_gadget_disconnect_interrupt()
3871 usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); in dwc3_gadget_disconnect_interrupt()
3873 dwc3_ep0_reset_state(dwc); in dwc3_gadget_disconnect_interrupt()
3876 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) in dwc3_gadget_reset_interrupt() argument
3887 dwc->connected = false; in dwc3_gadget_reset_interrupt()
3916 if (dwc->setup_packet_pending) in dwc3_gadget_reset_interrupt()
3917 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_reset_interrupt()
3920 dwc3_reset_gadget(dwc); in dwc3_gadget_reset_interrupt()
3927 dwc3_ep0_reset_state(dwc); in dwc3_gadget_reset_interrupt()
3935 dwc3_stop_active_transfers(dwc); in dwc3_gadget_reset_interrupt()
3936 dwc->connected = true; in dwc3_gadget_reset_interrupt()
3938 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_reset_interrupt()
3940 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_reset_interrupt()
3941 dwc->test_mode = false; in dwc3_gadget_reset_interrupt()
3942 dwc3_clear_stall_all_ep(dwc); in dwc3_gadget_reset_interrupt()
3945 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_reset_interrupt()
3947 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_reset_interrupt()
3950 static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) in dwc3_gadget_conndone_interrupt() argument
3957 struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc); in dwc3_gadget_conndone_interrupt()
3962 reg = dwc3_readl(dwc->regs, DWC3_DSTS); in dwc3_gadget_conndone_interrupt()
3964 dwc->speed = speed; in dwc3_gadget_conndone_interrupt()
3969 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_conndone_interrupt()
3983 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
3984 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
3987 dwc->gadget->ssp_rate = USB_SSP_GEN_2x2; in dwc3_gadget_conndone_interrupt()
3989 dwc->gadget->ssp_rate = USB_SSP_GEN_2x1; in dwc3_gadget_conndone_interrupt()
4006 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_conndone_interrupt()
4009 dwc->gadget->ep0->maxpacket = 512; in dwc3_gadget_conndone_interrupt()
4010 dwc->gadget->speed = USB_SPEED_SUPER; in dwc3_gadget_conndone_interrupt()
4013 dwc->gadget->speed = USB_SPEED_SUPER_PLUS; in dwc3_gadget_conndone_interrupt()
4014 dwc->gadget->ssp_rate = USB_SSP_GEN_1x2; in dwc3_gadget_conndone_interrupt()
4019 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4020 dwc->gadget->speed = USB_SPEED_HIGH; in dwc3_gadget_conndone_interrupt()
4024 dwc->gadget->ep0->maxpacket = 64; in dwc3_gadget_conndone_interrupt()
4025 dwc->gadget->speed = USB_SPEED_FULL; in dwc3_gadget_conndone_interrupt()
4029 dwc->gadget->ep0->maxpacket = 8; in dwc3_gadget_conndone_interrupt()
4030 dwc->gadget->speed = USB_SPEED_LOW; in dwc3_gadget_conndone_interrupt()
4034 dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; in dwc3_gadget_conndone_interrupt()
4039 !dwc->usb2_gadget_lpm_disable && in dwc3_gadget_conndone_interrupt()
4042 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4044 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4046 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4049 reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold | in dwc3_gadget_conndone_interrupt()
4050 (dwc->is_utmi_l1_suspend << 4)); in dwc3_gadget_conndone_interrupt()
4058 WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum, in dwc3_gadget_conndone_interrupt()
4061 if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) in dwc3_gadget_conndone_interrupt()
4062 reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); in dwc3_gadget_conndone_interrupt()
4064 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4066 if (dwc->usb2_gadget_lpm_disable) { in dwc3_gadget_conndone_interrupt()
4067 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_gadget_conndone_interrupt()
4069 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_gadget_conndone_interrupt()
4072 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_conndone_interrupt()
4074 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_conndone_interrupt()
4077 dep = dwc->eps[0]; in dwc3_gadget_conndone_interrupt()
4080 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4084 dep = dwc->eps[1]; in dwc3_gadget_conndone_interrupt()
4087 dev_err(dwc->dev, "failed to enable %s\n", dep->name); in dwc3_gadget_conndone_interrupt()
4100 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) in dwc3_gadget_wakeup_interrupt() argument
4107 if (dwc->async_callbacks && dwc->gadget_driver->resume) { in dwc3_gadget_wakeup_interrupt()
4108 spin_unlock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4109 dwc->gadget_driver->resume(dwc->gadget); in dwc3_gadget_wakeup_interrupt()
4110 spin_lock(&dwc->lock); in dwc3_gadget_wakeup_interrupt()
4114 static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, in dwc3_gadget_linksts_change_interrupt() argument
4137 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1); in dwc3_gadget_linksts_change_interrupt()
4140 if ((dwc->link_state == DWC3_LINK_STATE_U3) && in dwc3_gadget_linksts_change_interrupt()
4169 switch (dwc->link_state) { in dwc3_gadget_linksts_change_interrupt()
4172 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_gadget_linksts_change_interrupt()
4178 if (!dwc->u1u2) in dwc3_gadget_linksts_change_interrupt()
4179 dwc->u1u2 = reg & u1u2; in dwc3_gadget_linksts_change_interrupt()
4183 dwc3_gadget_dctl_write_safe(dwc, reg); in dwc3_gadget_linksts_change_interrupt()
4194 if (dwc->speed == USB_SPEED_SUPER) in dwc3_gadget_linksts_change_interrupt()
4195 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4199 dwc3_suspend_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4202 dwc3_resume_gadget(dwc); in dwc3_gadget_linksts_change_interrupt()
4209 dwc->link_state = next; in dwc3_gadget_linksts_change_interrupt()
4212 static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, in dwc3_gadget_suspend_interrupt() argument
4217 if (dwc->link_state != next && next == DWC3_LINK_STATE_U3) in dwc3_gadget_suspend_interrupt()
4218 dwc3_suspend_gadget(dwc); in dwc3_gadget_suspend_interrupt()
4220 dwc->link_state = next; in dwc3_gadget_suspend_interrupt()
4223 static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc, in dwc3_gadget_hibernation_interrupt() argument
4241 if (is_ss ^ (dwc->speed == USB_SPEED_SUPER)) in dwc3_gadget_hibernation_interrupt()
4247 static void dwc3_gadget_interrupt(struct dwc3 *dwc, in dwc3_gadget_interrupt() argument
4252 dwc3_gadget_disconnect_interrupt(dwc); in dwc3_gadget_interrupt()
4255 dwc3_gadget_reset_interrupt(dwc); in dwc3_gadget_interrupt()
4258 dwc3_gadget_conndone_interrupt(dwc); in dwc3_gadget_interrupt()
4261 dwc3_gadget_wakeup_interrupt(dwc); in dwc3_gadget_interrupt()
4264 if (dev_WARN_ONCE(dwc->dev, !dwc->has_hibernation, in dwc3_gadget_interrupt()
4268 dwc3_gadget_hibernation_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4271 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4276 dwc3_gadget_suspend_interrupt(dwc, event->event_info); in dwc3_gadget_interrupt()
4284 dev_WARN(dwc->dev, "UNKNOWN IRQ %d\n", event->type); in dwc3_gadget_interrupt()
4288 static void dwc3_process_event_entry(struct dwc3 *dwc, in dwc3_process_event_entry() argument
4291 trace_dwc3_event(event->raw, dwc); in dwc3_process_event_entry()
4294 dwc3_endpoint_interrupt(dwc, &event->depevt); in dwc3_process_event_entry()
4296 dwc3_gadget_interrupt(dwc, &event->devt); in dwc3_process_event_entry()
4298 dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); in dwc3_process_event_entry()
4303 struct dwc3 *dwc = evt->dwc; in dwc3_process_event_buf() local
4317 dwc3_process_event_entry(dwc, &event); in dwc3_process_event_buf()
4336 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_process_event_buf()
4339 if (dwc->imod_interval) { in dwc3_process_event_buf()
4340 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), DWC3_GEVNTCOUNT_EHB); in dwc3_process_event_buf()
4341 dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); in dwc3_process_event_buf()
4353 struct dwc3 *dwc = evt->dwc; in dwc3_thread_interrupt() local
4358 spin_lock_irqsave(&dwc->lock, flags); in dwc3_thread_interrupt()
4360 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_thread_interrupt()
4368 struct dwc3 *dwc = evt->dwc; in dwc3_check_event_buf() local
4372 if (pm_runtime_suspended(dwc->dev)) { in dwc3_check_event_buf()
4373 dwc->pending_events = true; in dwc3_check_event_buf()
4379 pm_runtime_get(dwc->dev); in dwc3_check_event_buf()
4380 disable_irq_nosync(dwc->irq_gadget); in dwc3_check_event_buf()
4393 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); in dwc3_check_event_buf()
4402 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), in dwc3_check_event_buf()
4411 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); in dwc3_check_event_buf()
4423 static int dwc3_gadget_get_irq(struct dwc3 *dwc) in dwc3_gadget_get_irq() argument
4425 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); in dwc3_gadget_get_irq()
4466 int dwc3_gadget_init(struct dwc3 *dwc) in dwc3_gadget_init() argument
4472 irq = dwc3_gadget_get_irq(dwc); in dwc3_gadget_init()
4478 dwc->irq_gadget = irq; in dwc3_gadget_init()
4480 dwc->ep0_trb = dma_alloc_coherent(dwc->sysdev, in dwc3_gadget_init()
4481 sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4482 &dwc->ep0_trb_addr, GFP_KERNEL); in dwc3_gadget_init()
4483 if (!dwc->ep0_trb) { in dwc3_gadget_init()
4484 dev_err(dwc->dev, "failed to allocate ep0 trb\n"); in dwc3_gadget_init()
4489 dwc->setup_buf = kzalloc(DWC3_EP0_SETUP_SIZE, GFP_KERNEL); in dwc3_gadget_init()
4490 if (!dwc->setup_buf) { in dwc3_gadget_init()
4495 dwc->bounce = dma_alloc_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, in dwc3_gadget_init()
4496 &dwc->bounce_addr, GFP_KERNEL); in dwc3_gadget_init()
4497 if (!dwc->bounce) { in dwc3_gadget_init()
4502 init_completion(&dwc->ep0_in_setup); in dwc3_gadget_init()
4503 dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); in dwc3_gadget_init()
4504 if (!dwc->gadget) { in dwc3_gadget_init()
4510 usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); in dwc3_gadget_init()
4511 dev = &dwc->gadget->dev; in dwc3_gadget_init()
4512 dev->platform_data = dwc; in dwc3_gadget_init()
4513 dwc->gadget->ops = &dwc3_gadget_ops; in dwc3_gadget_init()
4514 dwc->gadget->speed = USB_SPEED_UNKNOWN; in dwc3_gadget_init()
4515 dwc->gadget->ssp_rate = USB_SSP_GEN_UNKNOWN; in dwc3_gadget_init()
4516 dwc->gadget->sg_supported = true; in dwc3_gadget_init()
4517 dwc->gadget->name = "dwc3-gadget"; in dwc3_gadget_init()
4518 dwc->gadget->lpm_capable = !dwc->usb2_gadget_lpm_disable; in dwc3_gadget_init()
4537 !dwc->dis_metastability_quirk) in dwc3_gadget_init()
4538 dev_info(dwc->dev, "changing max_speed on rev %08x\n", in dwc3_gadget_init()
4539 dwc->revision); in dwc3_gadget_init()
4541 dwc->gadget->max_speed = dwc->maximum_speed; in dwc3_gadget_init()
4542 dwc->gadget->max_ssp_rate = dwc->max_ssp_rate; in dwc3_gadget_init()
4549 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); in dwc3_gadget_init()
4553 ret = usb_add_gadget(dwc->gadget); in dwc3_gadget_init()
4555 dev_err(dwc->dev, "failed to add gadget\n"); in dwc3_gadget_init()
4559 if (DWC3_IP_IS(DWC32) && dwc->maximum_speed == USB_SPEED_SUPER_PLUS) in dwc3_gadget_init()
4560 dwc3_gadget_set_ssp_rate(dwc->gadget, dwc->max_ssp_rate); in dwc3_gadget_init()
4562 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); in dwc3_gadget_init()
4567 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_init()
4569 usb_put_gadget(dwc->gadget); in dwc3_gadget_init()
4570 dwc->gadget = NULL; in dwc3_gadget_init()
4572 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_init()
4573 dwc->bounce_addr); in dwc3_gadget_init()
4576 kfree(dwc->setup_buf); in dwc3_gadget_init()
4579 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_init()
4580 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_init()
4588 void dwc3_gadget_exit(struct dwc3 *dwc) in dwc3_gadget_exit() argument
4590 if (!dwc->gadget) in dwc3_gadget_exit()
4593 usb_del_gadget(dwc->gadget); in dwc3_gadget_exit()
4594 dwc3_gadget_free_endpoints(dwc); in dwc3_gadget_exit()
4595 usb_put_gadget(dwc->gadget); in dwc3_gadget_exit()
4596 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, in dwc3_gadget_exit()
4597 dwc->bounce_addr); in dwc3_gadget_exit()
4598 kfree(dwc->setup_buf); in dwc3_gadget_exit()
4599 dma_free_coherent(dwc->sysdev, sizeof(*dwc->ep0_trb) * 2, in dwc3_gadget_exit()
4600 dwc->ep0_trb, dwc->ep0_trb_addr); in dwc3_gadget_exit()
4603 int dwc3_gadget_suspend(struct dwc3 *dwc) in dwc3_gadget_suspend() argument
4607 if (!dwc->gadget_driver) in dwc3_gadget_suspend()
4610 dwc3_gadget_run_stop(dwc, false, false); in dwc3_gadget_suspend()
4612 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_suspend()
4613 dwc3_disconnect_gadget(dwc); in dwc3_gadget_suspend()
4614 __dwc3_gadget_stop(dwc); in dwc3_gadget_suspend()
4615 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_suspend()
4620 int dwc3_gadget_resume(struct dwc3 *dwc) in dwc3_gadget_resume() argument
4622 struct dwc3_vendor *vdwc = container_of(dwc, struct dwc3_vendor, dwc); in dwc3_gadget_resume()
4625 if (!dwc->gadget_driver || !vdwc->softconnect) in dwc3_gadget_resume()
4628 ret = __dwc3_gadget_start(dwc); in dwc3_gadget_resume()
4632 ret = dwc3_gadget_run_stop(dwc, true, false); in dwc3_gadget_resume()
4639 __dwc3_gadget_stop(dwc); in dwc3_gadget_resume()
4645 void dwc3_gadget_process_pending_events(struct dwc3 *dwc) in dwc3_gadget_process_pending_events() argument
4647 if (dwc->pending_events) { in dwc3_gadget_process_pending_events()
4648 dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_process_pending_events()
4649 dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf); in dwc3_gadget_process_pending_events()
4650 pm_runtime_put(dwc->dev); in dwc3_gadget_process_pending_events()
4651 dwc->pending_events = false; in dwc3_gadget_process_pending_events()
4652 enable_irq(dwc->irq_gadget); in dwc3_gadget_process_pending_events()