Lines Matching +full:ring +full:- +full:disable +full:- +full:pullup
1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/dma-mapping.h>
23 #include "gadget-export.h"
25 #include "cdnsp-gadget.h"
26 #include "cdnsp-trace.h"
54 /* Save read-only status and port state. */ in cdnsp_port_state_to_neutral()
59 * cdnsp_find_next_ext_cap - Find the offset of the extended capabilities
116 if (pdev->active_port) in cdnsp_set_link_state()
117 port_num = pdev->active_port->port_num; in cdnsp_set_link_state()
147 base = &pdev->cap_regs->hc_capbase; in cdnsp_set_chicken_bits_2()
161 base = &pdev->cap_regs->hc_capbase; in cdnsp_clear_chicken_bits_2()
170 * Disable interrupts and begin the controller halting process.
180 halted = readl(&pdev->op_regs->status) & STS_HALT; in cdnsp_quiesce()
184 cmd = readl(&pdev->op_regs->command); in cdnsp_quiesce()
186 writel(cmd, &pdev->op_regs->command); in cdnsp_quiesce()
192 * Disable any IRQs and clear the run/stop bit.
205 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, val, in cdnsp_halt()
209 dev_err(pdev->dev, "ERROR: Device halt failed\n"); in cdnsp_halt()
213 pdev->cdnsp_state |= CDNSP_STATE_HALTED; in cdnsp_halt()
224 dev_err(pdev->dev, "ERROR: CDNSP controller not responding\n"); in cdnsp_died()
225 pdev->cdnsp_state |= CDNSP_STATE_DYING; in cdnsp_died()
237 temp = readl(&pdev->op_regs->command); in cdnsp_start()
239 writel(temp, &pdev->op_regs->command); in cdnsp_start()
241 pdev->cdnsp_state = 0; in cdnsp_start()
247 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, in cdnsp_start()
251 pdev->cdnsp_state = CDNSP_STATE_DYING; in cdnsp_start()
252 dev_err(pdev->dev, "ERROR: Controller run failed\n"); in cdnsp_start()
271 temp = readl(&pdev->op_regs->status); in cdnsp_reset()
274 dev_err(pdev->dev, "Device not accessible, reset failed.\n"); in cdnsp_reset()
275 return -ENODEV; in cdnsp_reset()
279 dev_err(pdev->dev, "Controller not halted, aborting reset.\n"); in cdnsp_reset()
280 return -EINVAL; in cdnsp_reset()
283 command = readl(&pdev->op_regs->command); in cdnsp_reset()
285 writel(command, &pdev->op_regs->command); in cdnsp_reset()
287 ret = readl_poll_timeout_atomic(&pdev->op_regs->command, temp, in cdnsp_reset()
291 dev_err(pdev->dev, "ERROR: Controller reset failed\n"); in cdnsp_reset()
299 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, in cdnsp_reset()
304 dev_err(pdev->dev, "ERROR: Controller not ready to work\n"); in cdnsp_reset()
308 dev_dbg(pdev->dev, "Controller ready to work"); in cdnsp_reset()
314 * cdnsp_get_endpoint_index - Find the index for an endpoint given its
317 * Index = (epnum * 2) + direction - 1,
320 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
330 return (index * 2) + (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in cdnsp_get_endpoint_index()
346 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_enqueue()
350 if (preq->epnum == 0 && !list_empty(&pep->pending_list)) { in cdnsp_ep_enqueue()
352 return -EBUSY; in cdnsp_ep_enqueue()
355 request = &preq->request; in cdnsp_ep_enqueue()
356 request->actual = 0; in cdnsp_ep_enqueue()
357 request->status = -EINPROGRESS; in cdnsp_ep_enqueue()
358 preq->direction = pep->direction; in cdnsp_ep_enqueue()
359 preq->epnum = pep->number; in cdnsp_ep_enqueue()
360 preq->td.drbl = 0; in cdnsp_ep_enqueue()
362 ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->direction); in cdnsp_ep_enqueue()
368 list_add_tail(&preq->list, &pep->pending_list); in cdnsp_ep_enqueue()
372 switch (usb_endpoint_type(pep->endpoint.desc)) { in cdnsp_ep_enqueue()
390 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_ep_enqueue()
391 pep->direction); in cdnsp_ep_enqueue()
392 list_del(&preq->list); in cdnsp_ep_enqueue()
399 * Remove the request's TD from the endpoint ring. This may cause the
402 * unless a Set Transfer Ring Dequeue Pointer is issued.
405 * from the ring. Since the ring is a contiguous structure, they can't be
409 * canceled, we simply move the ring's dequeue pointer past those TRBs
410 * using the Set Transfer Ring Dequeue Pointer command. This will be
415 * into a series of 1-TRB transfer no-op TDs. No-ops shouldn't be chained.
425 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_dequeue()
431 if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING) in cdnsp_ep_dequeue()
446 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
454 ctrl_ctx->drop_flags = 0; in cdnsp_zero_in_ctx()
455 ctrl_ctx->add_flags = 0; in cdnsp_zero_in_ctx()
456 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
457 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in cdnsp_zero_in_ctx()
460 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in cdnsp_zero_in_ctx()
462 ep_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, i); in cdnsp_zero_in_ctx()
463 ep_ctx->ep_info = 0; in cdnsp_zero_in_ctx()
464 ep_ctx->ep_info2 = 0; in cdnsp_zero_in_ctx()
465 ep_ctx->deq = 0; in cdnsp_zero_in_ctx()
466 ep_ctx->tx_info = 0; in cdnsp_zero_in_ctx()
475 cdnsp_queue_configure_endpoint(pdev, pdev->cmd.in_ctx->dma); in cdnsp_configure_endpoint()
479 dev_err(pdev->dev, in cdnsp_configure_endpoint()
481 return -EINVAL; in cdnsp_configure_endpoint()
495 event = pdev->event_ring->dequeue; in cdnsp_invalidate_ep_events()
496 segment = pdev->event_ring->deq_seg; in cdnsp_invalidate_ep_events()
497 cycle_state = pdev->event_ring->cycle_state; in cdnsp_invalidate_ep_events()
500 data = le32_to_cpu(event->trans_event.flags); in cdnsp_invalidate_ep_events()
507 TRB_TO_EP_ID(data) == (pep->idx + 1)) { in cdnsp_invalidate_ep_events()
509 event->trans_event.flags = cpu_to_le32(data); in cdnsp_invalidate_ep_events()
514 segment = pdev->event_ring->deq_seg->next; in cdnsp_invalidate_ep_events()
515 event = segment->trbs; in cdnsp_invalidate_ep_events()
533 cmd_trb = pdev->cmd.command_trb; in cdnsp_wait_for_cmd_compl()
534 pdev->cmd.status = 0; in cdnsp_wait_for_cmd_compl()
536 trace_cdnsp_cmd_wait_for_compl(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
538 ret = readl_poll_timeout_atomic(&pdev->op_regs->cmd_ring, val, in cdnsp_wait_for_cmd_compl()
542 dev_err(pdev->dev, "ERR: Timeout while waiting for command\n"); in cdnsp_wait_for_cmd_compl()
543 trace_cdnsp_cmd_timeout(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
544 pdev->cdnsp_state = CDNSP_STATE_DYING; in cdnsp_wait_for_cmd_compl()
545 return -ETIMEDOUT; in cdnsp_wait_for_cmd_compl()
548 event = pdev->event_ring->dequeue; in cdnsp_wait_for_cmd_compl()
549 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_wait_for_cmd_compl()
550 cycle_state = pdev->event_ring->cycle_state; in cdnsp_wait_for_cmd_compl()
552 cmd_deq_dma = cdnsp_trb_virt_to_dma(pdev->cmd_ring->deq_seg, cmd_trb); in cdnsp_wait_for_cmd_compl()
554 return -EINVAL; in cdnsp_wait_for_cmd_compl()
557 flags = le32_to_cpu(event->event_cmd.flags); in cdnsp_wait_for_cmd_compl()
561 return -EINVAL; in cdnsp_wait_for_cmd_compl()
563 cmd_dma = le64_to_cpu(event->event_cmd.cmd_trb); in cdnsp_wait_for_cmd_compl()
576 if (cdnsp_last_trb_on_ring(pdev->event_ring, in cdnsp_wait_for_cmd_compl()
580 event_deq_seg = event_deq_seg->next; in cdnsp_wait_for_cmd_compl()
581 event = event_deq_seg->trbs; in cdnsp_wait_for_cmd_compl()
585 trace_cdnsp_handle_command(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
587 pdev->cmd.status = GET_COMP_CODE(le32_to_cpu(event->event_cmd.status)); in cdnsp_wait_for_cmd_compl()
588 if (pdev->cmd.status == COMP_SUCCESS) in cdnsp_wait_for_cmd_compl()
591 return -pdev->cmd.status; in cdnsp_wait_for_cmd_compl()
608 if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_STOPPED) { in cdnsp_halt_endpoint()
609 cdnsp_queue_halt_endpoint(pdev, pep->idx); in cdnsp_halt_endpoint()
614 pep->ep_state |= EP_HALTED; in cdnsp_halt_endpoint()
616 cdnsp_queue_reset_ep(pdev, pep->idx); in cdnsp_halt_endpoint()
619 trace_cdnsp_handle_cmd_reset_ep(pep->out_ctx); in cdnsp_halt_endpoint()
624 pep->ep_state &= ~EP_HALTED; in cdnsp_halt_endpoint()
626 if (pep->idx != 0 && !(pep->ep_state & EP_WEDGE)) in cdnsp_halt_endpoint()
629 pep->ep_state &= ~EP_WEDGE; in cdnsp_halt_endpoint()
644 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
647 if (ctrl_ctx->add_flags == 0 && ctrl_ctx->drop_flags == 0) in cdnsp_update_eps_configuration()
650 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in cdnsp_update_eps_configuration()
651 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in cdnsp_update_eps_configuration()
652 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in cdnsp_update_eps_configuration()
655 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
656 for (i = CDNSP_ENDPOINTS_NUM; i >= 1; i--) { in cdnsp_update_eps_configuration()
659 if ((pdev->eps[i - 1].ring && !(ctrl_ctx->drop_flags & le32)) || in cdnsp_update_eps_configuration()
660 (ctrl_ctx->add_flags & le32) || i == 1) { in cdnsp_update_eps_configuration()
661 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in cdnsp_update_eps_configuration()
662 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in cdnsp_update_eps_configuration()
667 ep_sts = GET_EP_CTX_STATE(pep->out_ctx); in cdnsp_update_eps_configuration()
669 if ((ctrl_ctx->add_flags != cpu_to_le32(SLOT_FLAG) && in cdnsp_update_eps_configuration()
671 (ep_sts != EP_STATE_DISABLED && ctrl_ctx->drop_flags)) in cdnsp_update_eps_configuration()
674 trace_cdnsp_configure_endpoint(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_update_eps_configuration()
675 trace_cdnsp_handle_cmd_config_ep(pep->out_ctx); in cdnsp_update_eps_configuration()
684 * set the device address to 0, and disable all the endpoints except the default
686 * cdnsp_setup_device(), and then re-set up the configuration.
694 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_reset_device()
695 slot_ctx->dev_info = 0; in cdnsp_reset_device()
696 pdev->device_address = 0; in cdnsp_reset_device()
699 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_reset_device()
700 slot_state = GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)); in cdnsp_reset_device()
704 pdev->eps[0].ep_state & EP_HALTED) { in cdnsp_reset_device()
705 cdnsp_halt_endpoint(pdev, &pdev->eps[0], 0); in cdnsp_reset_device()
712 pdev->eps[0].ep_state &= ~(EP_STOPPED | EP_HALTED); in cdnsp_reset_device()
713 pdev->eps[0].ep_state |= EP_ENABLED; in cdnsp_reset_device()
727 pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED; in cdnsp_reset_device()
732 dev_err(pdev->dev, "Reset device failed with error code %d", in cdnsp_reset_device()
752 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in cdnsp_setup_streams_ep_input_ctx()
753 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in cdnsp_setup_streams_ep_input_ctx()
754 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in cdnsp_setup_streams_ep_input_ctx()
756 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in cdnsp_setup_streams_ep_input_ctx()
767 unsigned int num_streams = usb_ss_max_streams(pep->endpoint.comp_desc); in cdnsp_alloc_streams()
775 return -EINVAL; in cdnsp_alloc_streams()
793 cdnsp_setup_streams_ep_input_ctx(pdev, pep->in_ctx, &pep->stream_info); in cdnsp_alloc_streams()
795 pep->ep_state |= EP_HAS_STREAMS; in cdnsp_alloc_streams()
796 pep->stream_info.td_count = 0; in cdnsp_alloc_streams()
797 pep->stream_info.first_prime_det = 0; in cdnsp_alloc_streams()
800 return num_streams - 1; in cdnsp_alloc_streams()
811 pdev->slot_id = 0; in cdnsp_disable_slot()
812 pdev->active_port = NULL; in cdnsp_disable_slot()
814 trace_cdnsp_handle_cmd_disable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_disable_slot()
816 memset(pdev->in_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
817 memset(pdev->out_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
829 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_enable_slot()
830 slot_state = GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)); in cdnsp_enable_slot()
841 pdev->slot_id = 1; in cdnsp_enable_slot()
844 trace_cdnsp_handle_cmd_enable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_enable_slot()
860 if (!pdev->slot_id) { in cdnsp_setup_device()
862 return -EINVAL; in cdnsp_setup_device()
865 if (!pdev->active_port->port_num) in cdnsp_setup_device()
866 return -EINVAL; in cdnsp_setup_device()
868 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_setup_device()
869 dev_state = GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)); in cdnsp_setup_device()
876 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_setup_device()
877 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_setup_device()
879 if (!slot_ctx->dev_info || dev_state == SLOT_STATE_DEFAULT) { in cdnsp_setup_device()
887 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in cdnsp_setup_device()
888 ctrl_ctx->drop_flags = 0; in cdnsp_setup_device()
892 cdnsp_queue_address_device(pdev, pdev->in_ctx.dma, setup); in cdnsp_setup_device()
896 trace_cdnsp_handle_cmd_addr_dev(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_setup_device()
899 ctrl_ctx->add_flags = 0; in cdnsp_setup_device()
900 ctrl_ctx->drop_flags = 0; in cdnsp_setup_device()
909 if (pdev->active_port != &pdev->usb2_port || !pdev->gadget.lpm_capable) in cdnsp_set_usb2_hardware_lpm()
916 &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
918 writel(PORT_L1S_NYET, &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
923 return readl(&pdev->run_regs->microframe_index) >> 3; in cdnsp_get_frame()
936 if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT || in cdnsp_gadget_ep_enable()
937 !desc->wMaxPacketSize) in cdnsp_gadget_ep_enable()
938 return -EINVAL; in cdnsp_gadget_ep_enable()
941 pdev = pep->pdev; in cdnsp_gadget_ep_enable()
942 pep->ep_state &= ~EP_UNCONFIGURED; in cdnsp_gadget_ep_enable()
944 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, in cdnsp_gadget_ep_enable()
945 "%s is already enabled\n", pep->name)) in cdnsp_gadget_ep_enable()
948 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
952 dev_err(pdev->dev, "ERROR: Bad endpoint number\n"); in cdnsp_gadget_ep_enable()
953 ret = -EINVAL; in cdnsp_gadget_ep_enable()
957 pep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; in cdnsp_gadget_ep_enable()
959 if (pdev->gadget.speed == USB_SPEED_FULL) { in cdnsp_gadget_ep_enable()
961 pep->interval = desc->bInterval << 3; in cdnsp_gadget_ep_enable()
963 pep->interval = BIT(desc->bInterval - 1) << 3; in cdnsp_gadget_ep_enable()
967 if (pep->interval > BIT(12)) { in cdnsp_gadget_ep_enable()
968 dev_err(pdev->dev, "bInterval %d not supported\n", in cdnsp_gadget_ep_enable()
969 desc->bInterval); in cdnsp_gadget_ep_enable()
970 ret = -EINVAL; in cdnsp_gadget_ep_enable()
980 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_enable()
981 ctrl_ctx->add_flags = cpu_to_le32(added_ctxs); in cdnsp_gadget_ep_enable()
982 ctrl_ctx->drop_flags = 0; in cdnsp_gadget_ep_enable()
990 pep->ep_state |= EP_ENABLED; in cdnsp_gadget_ep_enable()
991 pep->ep_state &= ~EP_STOPPED; in cdnsp_gadget_ep_enable()
995 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
1011 return -EINVAL; in cdnsp_gadget_ep_disable()
1014 pdev = pep->pdev; in cdnsp_gadget_ep_disable()
1016 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1018 if (!(pep->ep_state & EP_ENABLED)) { in cdnsp_gadget_ep_disable()
1019 dev_err(pdev->dev, "%s is already disabled\n", pep->name); in cdnsp_gadget_ep_disable()
1020 ret = -EINVAL; in cdnsp_gadget_ep_disable()
1024 pep->ep_state |= EP_DIS_IN_RROGRESS; in cdnsp_gadget_ep_disable()
1027 if (!(pep->ep_state & EP_UNCONFIGURED)) { in cdnsp_gadget_ep_disable()
1033 while (!list_empty(&pep->pending_list)) { in cdnsp_gadget_ep_disable()
1034 preq = next_request(&pep->pending_list); in cdnsp_gadget_ep_disable()
1040 pep->ep_state &= ~EP_DIS_IN_RROGRESS; in cdnsp_gadget_ep_disable()
1041 drop_flag = cdnsp_get_endpoint_flag(pep->endpoint.desc); in cdnsp_gadget_ep_disable()
1042 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_disable()
1043 ctrl_ctx->drop_flags = cpu_to_le32(drop_flag); in cdnsp_gadget_ep_disable()
1044 ctrl_ctx->add_flags = 0; in cdnsp_gadget_ep_disable()
1048 if (!(pep->ep_state & EP_UNCONFIGURED)) in cdnsp_gadget_ep_disable()
1053 pep->ep_state &= ~(EP_ENABLED | EP_UNCONFIGURED); in cdnsp_gadget_ep_disable()
1054 pep->ep_state |= EP_STOPPED; in cdnsp_gadget_ep_disable()
1058 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1073 preq->epnum = pep->number; in cdnsp_gadget_ep_alloc_request()
1074 preq->pep = pep; in cdnsp_gadget_ep_alloc_request()
1078 return &preq->request; in cdnsp_gadget_ep_alloc_request()
1101 return -EINVAL; in cdnsp_gadget_ep_queue()
1104 pdev = pep->pdev; in cdnsp_gadget_ep_queue()
1106 if (!(pep->ep_state & EP_ENABLED)) { in cdnsp_gadget_ep_queue()
1107 dev_err(pdev->dev, "%s: can't queue to disabled endpoint\n", in cdnsp_gadget_ep_queue()
1108 pep->name); in cdnsp_gadget_ep_queue()
1109 return -EINVAL; in cdnsp_gadget_ep_queue()
1113 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1115 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1124 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_dequeue()
1128 if (request->status != -EINPROGRESS) in cdnsp_gadget_ep_dequeue()
1131 if (!pep->endpoint.desc) { in cdnsp_gadget_ep_dequeue()
1132 dev_err(pdev->dev, in cdnsp_gadget_ep_dequeue()
1134 pep->name); in cdnsp_gadget_ep_dequeue()
1135 return -ESHUTDOWN; in cdnsp_gadget_ep_dequeue()
1139 if (!(pep->ep_state & EP_ENABLED)) in cdnsp_gadget_ep_dequeue()
1142 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1144 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1152 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_halt()
1157 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1159 preq = next_request(&pep->pending_list); in cdnsp_gadget_ep_set_halt()
1163 ret = -EAGAIN; in cdnsp_gadget_ep_set_halt()
1171 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1178 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_wedge()
1182 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1183 pep->ep_state |= EP_WEDGE; in cdnsp_gadget_ep_set_wedge()
1185 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1192 .disable = cdnsp_gadget_ep_disable,
1203 .disable = cdnsp_gadget_ep_disable,
1216 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_giveback()
1218 list_del(&preq->list); in cdnsp_gadget_giveback()
1220 if (preq->request.status == -EINPROGRESS) in cdnsp_gadget_giveback()
1221 preq->request.status = status; in cdnsp_gadget_giveback()
1223 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_gadget_giveback()
1224 preq->direction); in cdnsp_gadget_giveback()
1228 if (preq != &pdev->ep0_preq) { in cdnsp_gadget_giveback()
1229 spin_unlock(&pdev->lock); in cdnsp_gadget_giveback()
1230 usb_gadget_giveback_request(&pep->endpoint, &preq->request); in cdnsp_gadget_giveback()
1231 spin_lock(&pdev->lock); in cdnsp_gadget_giveback()
1248 temp = readl(&pdev->ir_set->irq_control); in cdnsp_run()
1251 writel(temp, &pdev->ir_set->irq_control); in cdnsp_run()
1253 temp = readl(&pdev->port3x_regs->mode_addr); in cdnsp_run()
1268 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdnsp_run()
1278 writel(temp, &pdev->port3x_regs->mode_addr); in cdnsp_run()
1279 cdnsp_set_link_state(pdev, &pdev->usb3_port.regs->portsc, in cdnsp_run()
1282 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_run()
1285 cdnsp_set_link_state(pdev, &pdev->usb2_port.regs->portsc, in cdnsp_run()
1290 writel(PORT_REG6_L1_L0_HW_EN | fs_speed, &pdev->port20_regs->port_reg6); in cdnsp_run()
1294 ret = -ENODEV; in cdnsp_run()
1298 temp = readl(&pdev->op_regs->command); in cdnsp_run()
1300 writel(temp, &pdev->op_regs->command); in cdnsp_run()
1302 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_run()
1303 writel(IMAN_IE_SET(temp), &pdev->ir_set->irq_pending); in cdnsp_run()
1315 enum usb_device_speed max_speed = driver->max_speed; in cdnsp_gadget_udc_start()
1320 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1321 pdev->gadget_driver = driver; in cdnsp_gadget_udc_start()
1324 max_speed = min(driver->max_speed, g->max_speed); in cdnsp_gadget_udc_start()
1327 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1333 * Update Event Ring Dequeue Pointer:
1334 * - When all events have finished
1335 * - To avoid "Event Ring Full Error" condition
1344 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1346 /* If necessary, update the HW's version of the event ring deq ptr. */ in cdnsp_update_erst_dequeue()
1347 if (event_ring_deq != pdev->event_ring->dequeue) { in cdnsp_update_erst_dequeue()
1348 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_update_erst_dequeue()
1349 pdev->event_ring->dequeue); in cdnsp_update_erst_dequeue()
1360 cdnsp_write_64(temp_64, &pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1369 cdnsp_initialize_ring_info(pdev->cmd_ring); in cdnsp_clear_cmd_ring()
1371 seg = pdev->cmd_ring->first_seg; in cdnsp_clear_cmd_ring()
1372 for (i = 0; i < pdev->cmd_ring->num_segs; i++) { in cdnsp_clear_cmd_ring()
1373 memset(seg->trbs, 0, in cdnsp_clear_cmd_ring()
1374 sizeof(union cdnsp_trb) * (TRBS_PER_SEGMENT - 1)); in cdnsp_clear_cmd_ring()
1375 seg = seg->next; in cdnsp_clear_cmd_ring()
1378 /* Set the address in the Command Ring Control register. */ in cdnsp_clear_cmd_ring()
1379 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1381 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_clear_cmd_ring()
1382 pdev->cmd_ring->cycle_state; in cdnsp_clear_cmd_ring()
1383 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1393 event_ring_deq = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1394 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_consume_all_events()
1395 event = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1397 /* Update ring dequeue pointer. */ in cdnsp_consume_all_events()
1399 cycle_bit = (le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE); in cdnsp_consume_all_events()
1402 if (cycle_bit != pdev->event_ring->cycle_state) in cdnsp_consume_all_events()
1405 cdnsp_inc_deq(pdev, pdev->event_ring); in cdnsp_consume_all_events()
1412 if (cdnsp_last_trb_on_ring(pdev->event_ring, event_deq_seg, in cdnsp_consume_all_events()
1416 event_deq_seg = event_deq_seg->next; in cdnsp_consume_all_events()
1417 event = event_deq_seg->trbs; in cdnsp_consume_all_events()
1427 cdnsp_cmd_flush_ep(pdev, &pdev->eps[0]); in cdnsp_stop()
1430 if (!list_empty(&pdev->eps[0].pending_list)) { in cdnsp_stop()
1433 req = next_request(&pdev->eps[0].pending_list); in cdnsp_stop()
1434 if (req == &pdev->ep0_preq) in cdnsp_stop()
1435 cdnsp_ep_dequeue(&pdev->eps[0], req); in cdnsp_stop()
1438 cdnsp_disable_port(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1439 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1443 temp = readl(&pdev->op_regs->status); in cdnsp_stop()
1444 writel((temp & ~0x1fff) | STS_EINT, &pdev->op_regs->status); in cdnsp_stop()
1445 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1446 writel(IMAN_IE_CLEAR(temp), &pdev->ir_set->irq_pending); in cdnsp_stop()
1448 cdnsp_clear_port_change_bit(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1449 cdnsp_clear_port_change_bit(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1452 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1454 writel(temp, &pdev->ir_set->irq_pending); in cdnsp_stop()
1465 * Disable slot, disable IRQs, and quiesce the controller.
1472 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1474 pdev->gadget_driver = NULL; in cdnsp_gadget_udc_stop()
1475 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1492 port_regs = pdev->active_port->regs; in __cdnsp_gadget_wakeup()
1493 portsc = readl(&port_regs->portsc) & PORT_PLS_MASK; in __cdnsp_gadget_wakeup()
1496 if (pdev->gadget.speed < USB_SPEED_SUPER && portsc == XDEV_U2) { in __cdnsp_gadget_wakeup()
1497 portpm = readl(&port_regs->portpmsc); in __cdnsp_gadget_wakeup()
1503 if (portsc == XDEV_U3 && !pdev->may_wakeup) in __cdnsp_gadget_wakeup()
1506 cdnsp_set_link_state(pdev, &port_regs->portsc, XDEV_U0); in __cdnsp_gadget_wakeup()
1508 pdev->cdnsp_state |= CDNSP_WAKEUP_PENDING; in __cdnsp_gadget_wakeup()
1516 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1518 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1529 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1530 g->is_selfpowered = !!is_selfpowered; in cdnsp_gadget_set_selfpowered()
1531 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1539 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_gadget_pullup()
1545 * Disable events handling while controller is being in cdnsp_gadget_pullup()
1548 disable_irq(cdns->dev_irq); in cdnsp_gadget_pullup()
1549 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_pullup()
1558 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_pullup()
1559 enable_irq(cdns->dev_irq); in cdnsp_gadget_pullup()
1568 .pullup = cdnsp_gadget_pullup,
1576 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_ep_buffering()
1581 if (!pep->direction) { in cdnsp_get_ep_buffering()
1582 pep->buffering = readl(reg + XBUF_RX_TAG_MASK_0_OFFSET); in cdnsp_get_ep_buffering()
1583 pep->buffering_period = readl(reg + XBUF_RX_TAG_MASK_1_OFFSET); in cdnsp_get_ep_buffering()
1584 pep->buffering = (pep->buffering + 1) / 2; in cdnsp_get_ep_buffering()
1585 pep->buffering_period = (pep->buffering_period + 1) / 2; in cdnsp_get_ep_buffering()
1589 endpoints = HCS_ENDPOINTS(pdev->hcs_params1) / 2; in cdnsp_get_ep_buffering()
1594 reg += pep->number * sizeof(u32) * 2; in cdnsp_get_ep_buffering()
1596 pep->buffering = (readl(reg) + 1) / 2; in cdnsp_get_ep_buffering()
1597 pep->buffering_period = pep->buffering; in cdnsp_get_ep_buffering()
1602 int max_streams = HCC_MAX_PSA(pdev->hcc_params); in cdnsp_gadget_init_endpoints()
1606 INIT_LIST_HEAD(&pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1609 dev_err(pdev->dev, "Stream size %d not supported\n", in cdnsp_gadget_init_endpoints()
1611 return -EINVAL; in cdnsp_gadget_init_endpoints()
1623 pep = &pdev->eps[i]; in cdnsp_gadget_init_endpoints()
1624 pep->pdev = pdev; in cdnsp_gadget_init_endpoints()
1625 pep->number = epnum; in cdnsp_gadget_init_endpoints()
1626 pep->direction = direction; /* 0 for OUT, 1 for IN. */ in cdnsp_gadget_init_endpoints()
1630 * pdev->eps[0] in cdnsp_gadget_init_endpoints()
1633 snprintf(pep->name, sizeof(pep->name), "ep%d%s", in cdnsp_gadget_init_endpoints()
1636 pep->idx = 0; in cdnsp_gadget_init_endpoints()
1637 usb_ep_set_maxpacket_limit(&pep->endpoint, 512); in cdnsp_gadget_init_endpoints()
1638 pep->endpoint.maxburst = 1; in cdnsp_gadget_init_endpoints()
1639 pep->endpoint.ops = &cdnsp_gadget_ep0_ops; in cdnsp_gadget_init_endpoints()
1640 pep->endpoint.desc = &cdnsp_gadget_ep0_desc; in cdnsp_gadget_init_endpoints()
1641 pep->endpoint.comp_desc = NULL; in cdnsp_gadget_init_endpoints()
1642 pep->endpoint.caps.type_control = true; in cdnsp_gadget_init_endpoints()
1643 pep->endpoint.caps.dir_in = true; in cdnsp_gadget_init_endpoints()
1644 pep->endpoint.caps.dir_out = true; in cdnsp_gadget_init_endpoints()
1646 pdev->ep0_preq.epnum = pep->number; in cdnsp_gadget_init_endpoints()
1647 pdev->ep0_preq.pep = pep; in cdnsp_gadget_init_endpoints()
1648 pdev->gadget.ep0 = &pep->endpoint; in cdnsp_gadget_init_endpoints()
1650 snprintf(pep->name, sizeof(pep->name), "ep%d%s", in cdnsp_gadget_init_endpoints()
1651 epnum, (pep->direction) ? "in" : "out"); in cdnsp_gadget_init_endpoints()
1653 pep->idx = (epnum * 2 + (direction ? 1 : 0)) - 1; in cdnsp_gadget_init_endpoints()
1654 usb_ep_set_maxpacket_limit(&pep->endpoint, 1024); in cdnsp_gadget_init_endpoints()
1656 pep->endpoint.max_streams = max_streams; in cdnsp_gadget_init_endpoints()
1657 pep->endpoint.ops = &cdnsp_gadget_ep_ops; in cdnsp_gadget_init_endpoints()
1658 list_add_tail(&pep->endpoint.ep_list, in cdnsp_gadget_init_endpoints()
1659 &pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1661 pep->endpoint.caps.type_iso = true; in cdnsp_gadget_init_endpoints()
1662 pep->endpoint.caps.type_bulk = true; in cdnsp_gadget_init_endpoints()
1663 pep->endpoint.caps.type_int = true; in cdnsp_gadget_init_endpoints()
1665 pep->endpoint.caps.dir_in = direction; in cdnsp_gadget_init_endpoints()
1666 pep->endpoint.caps.dir_out = !direction; in cdnsp_gadget_init_endpoints()
1669 pep->endpoint.name = pep->name; in cdnsp_gadget_init_endpoints()
1670 pep->in_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1671 pep->out_ctx = cdnsp_get_ep_ctx(&pdev->out_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1674 dev_dbg(pdev->dev, "Init %s, MPS: %04x SupType: " in cdnsp_gadget_init_endpoints()
1677 pep->name, 1024, in cdnsp_gadget_init_endpoints()
1678 (pep->endpoint.caps.type_control) ? "yes" : "no", in cdnsp_gadget_init_endpoints()
1679 (pep->endpoint.caps.type_int) ? "yes" : "no", in cdnsp_gadget_init_endpoints()
1680 (pep->endpoint.caps.type_bulk) ? "yes" : "no", in cdnsp_gadget_init_endpoints()
1681 (pep->endpoint.caps.type_iso) ? "yes" : "no", in cdnsp_gadget_init_endpoints()
1682 (pep->endpoint.caps.dir_in) ? "yes" : "no", in cdnsp_gadget_init_endpoints()
1683 (pep->endpoint.caps.dir_out) ? "yes" : "no"); in cdnsp_gadget_init_endpoints()
1685 INIT_LIST_HEAD(&pep->pending_list); in cdnsp_gadget_init_endpoints()
1697 pep = &pdev->eps[i]; in cdnsp_gadget_free_endpoints()
1698 if (pep->number != 0 && pep->out_ctx) in cdnsp_gadget_free_endpoints()
1699 list_del(&pep->endpoint.ep_list); in cdnsp_gadget_free_endpoints()
1705 pdev->cdnsp_state |= CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1707 if (pdev->gadget_driver && pdev->gadget_driver->disconnect) { in cdnsp_disconnect_gadget()
1708 spin_unlock(&pdev->lock); in cdnsp_disconnect_gadget()
1709 pdev->gadget_driver->disconnect(&pdev->gadget); in cdnsp_disconnect_gadget()
1710 spin_lock(&pdev->lock); in cdnsp_disconnect_gadget()
1713 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdnsp_disconnect_gadget()
1714 usb_gadget_set_state(&pdev->gadget, USB_STATE_NOTATTACHED); in cdnsp_disconnect_gadget()
1716 pdev->cdnsp_state &= ~CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1721 if (pdev->gadget_driver && pdev->gadget_driver->suspend) { in cdnsp_suspend_gadget()
1722 spin_unlock(&pdev->lock); in cdnsp_suspend_gadget()
1723 pdev->gadget_driver->suspend(&pdev->gadget); in cdnsp_suspend_gadget()
1724 spin_lock(&pdev->lock); in cdnsp_suspend_gadget()
1730 if (pdev->gadget_driver && pdev->gadget_driver->resume) { in cdnsp_resume_gadget()
1731 spin_unlock(&pdev->lock); in cdnsp_resume_gadget()
1732 pdev->gadget_driver->resume(&pdev->gadget); in cdnsp_resume_gadget()
1733 spin_lock(&pdev->lock); in cdnsp_resume_gadget()
1743 port_regs = pdev->active_port->regs; in cdnsp_irq_reset()
1744 pdev->gadget.speed = cdnsp_port_speed(readl(port_regs)); in cdnsp_irq_reset()
1746 spin_unlock(&pdev->lock); in cdnsp_irq_reset()
1747 usb_gadget_udc_reset(&pdev->gadget, pdev->gadget_driver); in cdnsp_irq_reset()
1748 spin_lock(&pdev->lock); in cdnsp_irq_reset()
1750 switch (pdev->gadget.speed) { in cdnsp_irq_reset()
1754 pdev->gadget.ep0->maxpacket = 512; in cdnsp_irq_reset()
1759 pdev->gadget.ep0->maxpacket = 64; in cdnsp_irq_reset()
1763 dev_err(pdev->dev, "Unknown device speed\n"); in cdnsp_irq_reset()
1769 usb_gadget_set_state(&pdev->gadget, USB_STATE_DEFAULT); in cdnsp_irq_reset()
1774 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_rev_cap()
1777 pdev->rev_cap = reg; in cdnsp_get_rev_cap()
1779 dev_info(pdev->dev, "Rev: %08x/%08x, eps: %08x, buff: %08x/%08x\n", in cdnsp_get_rev_cap()
1780 readl(&pdev->rev_cap->ctrl_revision), in cdnsp_get_rev_cap()
1781 readl(&pdev->rev_cap->rtl_revision), in cdnsp_get_rev_cap()
1782 readl(&pdev->rev_cap->ep_supported), in cdnsp_get_rev_cap()
1783 readl(&pdev->rev_cap->rx_buff_size), in cdnsp_get_rev_cap()
1784 readl(&pdev->rev_cap->tx_buff_size)); in cdnsp_get_rev_cap()
1792 pdev->cap_regs = pdev->regs; in cdnsp_gen_setup()
1793 pdev->op_regs = pdev->regs + in cdnsp_gen_setup()
1794 HC_LENGTH(readl(&pdev->cap_regs->hc_capbase)); in cdnsp_gen_setup()
1795 pdev->run_regs = pdev->regs + in cdnsp_gen_setup()
1796 (readl(&pdev->cap_regs->run_regs_off) & RTSOFF_MASK); in cdnsp_gen_setup()
1798 /* Cache read-only capability registers */ in cdnsp_gen_setup()
1799 pdev->hcs_params1 = readl(&pdev->cap_regs->hcs_params1); in cdnsp_gen_setup()
1800 pdev->hcc_params = readl(&pdev->cap_regs->hc_capbase); in cdnsp_gen_setup()
1801 pdev->hci_version = HC_VERSION(pdev->hcc_params); in cdnsp_gen_setup()
1802 pdev->hcc_params = readl(&pdev->cap_regs->hcc_params); in cdnsp_gen_setup()
1817 * Set dma_mask and coherent_dma_mask to 64-bits, in cdnsp_gen_setup()
1818 * if controller supports 64-bit addressing. in cdnsp_gen_setup()
1820 if (HCC_64BIT_ADDR(pdev->hcc_params) && in cdnsp_gen_setup()
1821 !dma_set_mask(pdev->dev, DMA_BIT_MASK(64))) { in cdnsp_gen_setup()
1822 dev_dbg(pdev->dev, "Enabling 64-bit DMA addresses.\n"); in cdnsp_gen_setup()
1823 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(64)); in cdnsp_gen_setup()
1826 * This is to avoid error in cases where a 32-bit USB in cdnsp_gen_setup()
1827 * controller is used on a 64-bit capable system. in cdnsp_gen_setup()
1829 ret = dma_set_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1833 dev_dbg(pdev->dev, "Enabling 32-bit DMA addresses.\n"); in cdnsp_gen_setup()
1834 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1837 spin_lock_init(&pdev->lock); in cdnsp_gen_setup()
1848 reg = readl(&pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1850 writel(reg, &pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1859 int ret = -ENOMEM; in __cdnsp_gadget_init()
1865 return -ENOMEM; in __cdnsp_gadget_init()
1867 pm_runtime_get_sync(cdns->dev); in __cdnsp_gadget_init()
1869 cdns->gadget_dev = pdev; in __cdnsp_gadget_init()
1870 pdev->dev = cdns->dev; in __cdnsp_gadget_init()
1871 pdev->regs = cdns->dev_regs; in __cdnsp_gadget_init()
1872 max_speed = usb_get_maximum_speed(cdns->dev); in __cdnsp_gadget_init()
1881 dev_err(cdns->dev, "invalid speed parameter %d\n", max_speed); in __cdnsp_gadget_init()
1889 pdev->gadget.ops = &cdnsp_gadget_ops; in __cdnsp_gadget_init()
1890 pdev->gadget.name = "cdnsp-gadget"; in __cdnsp_gadget_init()
1891 pdev->gadget.speed = USB_SPEED_UNKNOWN; in __cdnsp_gadget_init()
1892 pdev->gadget.sg_supported = 1; in __cdnsp_gadget_init()
1893 pdev->gadget.max_speed = max_speed; in __cdnsp_gadget_init()
1894 pdev->gadget.lpm_capable = 1; in __cdnsp_gadget_init()
1896 pdev->setup_buf = kzalloc(CDNSP_EP0_SETUP_SIZE, GFP_KERNEL); in __cdnsp_gadget_init()
1897 if (!pdev->setup_buf) in __cdnsp_gadget_init()
1904 pdev->gadget.quirk_ep_out_aligned_size = true; in __cdnsp_gadget_init()
1908 dev_err(pdev->dev, "Generic initialization failed %d\n", ret); in __cdnsp_gadget_init()
1914 dev_err(pdev->dev, "failed to initialize endpoints\n"); in __cdnsp_gadget_init()
1918 ret = usb_add_gadget_udc(pdev->dev, &pdev->gadget); in __cdnsp_gadget_init()
1920 dev_err(pdev->dev, "failed to register udc\n"); in __cdnsp_gadget_init()
1924 ret = devm_request_threaded_irq(pdev->dev, cdns->dev_irq, in __cdnsp_gadget_init()
1927 dev_name(pdev->dev), pdev); in __cdnsp_gadget_init()
1934 usb_del_gadget_udc(&pdev->gadget); in __cdnsp_gadget_init()
1942 kfree(pdev->setup_buf); in __cdnsp_gadget_init()
1951 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_exit()
1953 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); in cdnsp_gadget_exit()
1954 pm_runtime_mark_last_busy(cdns->dev); in cdnsp_gadget_exit()
1955 pm_runtime_put_autosuspend(cdns->dev); in cdnsp_gadget_exit()
1956 usb_del_gadget_udc(&pdev->gadget); in cdnsp_gadget_exit()
1960 cdns->gadget_dev = NULL; in cdnsp_gadget_exit()
1966 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_suspend()
1969 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_suspend()
1972 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_suspend()
1975 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_suspend()
1982 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_resume()
1987 if (!pdev->gadget_driver) in cdnsp_gadget_resume()
1990 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_resume()
1991 max_speed = pdev->gadget_driver->max_speed; in cdnsp_gadget_resume()
1994 max_speed = min(max_speed, pdev->gadget.max_speed); in cdnsp_gadget_resume()
1998 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_resume()
2001 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_resume()
2007 * cdnsp_gadget_init - initialize device structure
2016 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); in cdnsp_gadget_init()
2018 return -ENOMEM; in cdnsp_gadget_init()
2020 rdrv->start = __cdnsp_gadget_init; in cdnsp_gadget_init()
2021 rdrv->stop = cdnsp_gadget_exit; in cdnsp_gadget_init()
2022 rdrv->suspend = cdnsp_gadget_suspend; in cdnsp_gadget_init()
2023 rdrv->resume = cdnsp_gadget_resume; in cdnsp_gadget_init()
2024 rdrv->state = CDNS_ROLE_STATE_INACTIVE; in cdnsp_gadget_init()
2025 rdrv->name = "gadget"; in cdnsp_gadget_init()
2026 cdns->roles[USB_ROLE_DEVICE] = rdrv; in cdnsp_gadget_init()