Lines Matching refs:pdev

101 void cdnsp_set_link_state(struct cdnsp_device *pdev,  in cdnsp_set_link_state()  argument
116 if (pdev->active_port) in cdnsp_set_link_state()
117 port_num = pdev->active_port->port_num; in cdnsp_set_link_state()
124 static void cdnsp_disable_port(struct cdnsp_device *pdev, in cdnsp_disable_port() argument
132 static void cdnsp_clear_port_change_bit(struct cdnsp_device *pdev, in cdnsp_clear_port_change_bit() argument
141 static void cdnsp_set_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) in cdnsp_set_chicken_bits_2() argument
147 base = &pdev->cap_regs->hc_capbase; in cdnsp_set_chicken_bits_2()
155 static void cdnsp_clear_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) in cdnsp_clear_chicken_bits_2() argument
161 base = &pdev->cap_regs->hc_capbase; in cdnsp_clear_chicken_bits_2()
172 static void cdnsp_quiesce(struct cdnsp_device *pdev) in cdnsp_quiesce() argument
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()
198 int cdnsp_halt(struct cdnsp_device *pdev) in cdnsp_halt() argument
203 cdnsp_quiesce(pdev); in cdnsp_halt()
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()
222 void cdnsp_died(struct cdnsp_device *pdev) in cdnsp_died() argument
224 dev_err(pdev->dev, "ERROR: CDNSP controller not responding\n"); in cdnsp_died()
225 pdev->cdnsp_state |= CDNSP_STATE_DYING; in cdnsp_died()
226 cdnsp_halt(pdev); in cdnsp_died()
232 static int cdnsp_start(struct cdnsp_device *pdev) in cdnsp_start() argument
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()
265 int cdnsp_reset(struct cdnsp_device *pdev) in cdnsp_reset() argument
271 temp = readl(&pdev->op_regs->status); in cdnsp_reset()
274 dev_err(pdev->dev, "Device not accessible, reset failed.\n"); in cdnsp_reset()
279 dev_err(pdev->dev, "Controller not halted, aborting reset.\n"); 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()
346 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_enqueue() local
362 ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->direction); in cdnsp_ep_enqueue()
374 ret = cdnsp_queue_ctrl_tx(pdev, preq); in cdnsp_ep_enqueue()
378 ret = cdnsp_queue_bulk_tx(pdev, preq); in cdnsp_ep_enqueue()
381 ret = cdnsp_queue_isoc_tx(pdev, preq); in cdnsp_ep_enqueue()
390 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_ep_enqueue()
425 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_dequeue() local
432 ret_stop = cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_ep_dequeue()
434 ret_rem = cdnsp_remove_request(pdev, preq, pep); in cdnsp_ep_dequeue()
439 static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev) in cdnsp_zero_in_ctx() argument
446 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
456 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
462 ep_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, i); in cdnsp_zero_in_ctx()
471 static int cdnsp_configure_endpoint(struct cdnsp_device *pdev) in cdnsp_configure_endpoint() argument
475 cdnsp_queue_configure_endpoint(pdev, pdev->cmd.in_ctx->dma); in cdnsp_configure_endpoint()
476 cdnsp_ring_cmd_db(pdev); in cdnsp_configure_endpoint()
477 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_configure_endpoint()
479 dev_err(pdev->dev, in cdnsp_configure_endpoint()
487 static void cdnsp_invalidate_ep_events(struct cdnsp_device *pdev, in cdnsp_invalidate_ep_events() argument
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()
514 segment = pdev->event_ring->deq_seg->next; in cdnsp_invalidate_ep_events()
522 int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev) in cdnsp_wait_for_cmd_compl() argument
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()
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()
576 if (cdnsp_last_trb_on_ring(pdev->event_ring, 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()
595 int cdnsp_halt_endpoint(struct cdnsp_device *pdev, in cdnsp_halt_endpoint() argument
603 ret = cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_halt_endpoint()
609 cdnsp_queue_halt_endpoint(pdev, pep->idx); in cdnsp_halt_endpoint()
610 cdnsp_ring_cmd_db(pdev); in cdnsp_halt_endpoint()
611 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_halt_endpoint()
616 cdnsp_queue_reset_ep(pdev, pep->idx); in cdnsp_halt_endpoint()
617 cdnsp_ring_cmd_db(pdev); in cdnsp_halt_endpoint()
618 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_halt_endpoint()
627 cdnsp_ring_doorbell_for_active_rings(pdev, pep); in cdnsp_halt_endpoint()
635 static int cdnsp_update_eps_configuration(struct cdnsp_device *pdev, in cdnsp_update_eps_configuration() argument
644 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
655 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
659 if ((pdev->eps[i - 1].ring && !(ctrl_ctx->drop_flags & le32)) || in cdnsp_update_eps_configuration()
672 ret = cdnsp_configure_endpoint(pdev); in cdnsp_update_eps_configuration()
674 trace_cdnsp_configure_endpoint(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_update_eps_configuration()
677 cdnsp_zero_in_ctx(pdev); in cdnsp_update_eps_configuration()
688 int cdnsp_reset_device(struct cdnsp_device *pdev) in cdnsp_reset_device() argument
694 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); 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()
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()
718 cdnsp_queue_reset_device(pdev); in cdnsp_reset_device()
719 cdnsp_ring_cmd_db(pdev); in cdnsp_reset_device()
720 ret = cdnsp_wait_for_cmd_compl(pdev); 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()
742 static void cdnsp_setup_streams_ep_input_ctx(struct cdnsp_device *pdev, in cdnsp_setup_streams_ep_input_ctx() argument
765 int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_alloc_streams() argument
789 ret = cdnsp_alloc_stream_info(pdev, pep, num_stream_ctxs, num_streams); in cdnsp_alloc_streams()
793 cdnsp_setup_streams_ep_input_ctx(pdev, pep->in_ctx, &pep->stream_info); in cdnsp_alloc_streams()
803 int cdnsp_disable_slot(struct cdnsp_device *pdev) in cdnsp_disable_slot() argument
807 cdnsp_queue_slot_control(pdev, TRB_DISABLE_SLOT); in cdnsp_disable_slot()
808 cdnsp_ring_cmd_db(pdev); in cdnsp_disable_slot()
809 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_disable_slot()
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()
822 int cdnsp_enable_slot(struct cdnsp_device *pdev) in cdnsp_enable_slot() argument
829 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_enable_slot()
835 cdnsp_queue_slot_control(pdev, TRB_ENABLE_SLOT); in cdnsp_enable_slot()
836 cdnsp_ring_cmd_db(pdev); in cdnsp_enable_slot()
837 ret = cdnsp_wait_for_cmd_compl(pdev); 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()
853 int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup) in cdnsp_setup_device() argument
860 if (!pdev->slot_id) { in cdnsp_setup_device()
865 if (!pdev->active_port->port_num) in cdnsp_setup_device()
868 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); 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()
880 ret = cdnsp_setup_addressable_priv_dev(pdev); in cdnsp_setup_device()
885 cdnsp_copy_ep0_dequeue_into_input_ctx(pdev); in cdnsp_setup_device()
892 cdnsp_queue_address_device(pdev, pdev->in_ctx.dma, setup); in cdnsp_setup_device()
893 cdnsp_ring_cmd_db(pdev); in cdnsp_setup_device()
894 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_setup_device()
896 trace_cdnsp_handle_cmd_addr_dev(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_setup_device()
905 void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *pdev, in cdnsp_set_usb2_hardware_lpm() argument
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()
921 static int cdnsp_get_frame(struct cdnsp_device *pdev) in cdnsp_get_frame() argument
923 return readl(&pdev->run_regs->microframe_index) >> 3; in cdnsp_get_frame()
930 struct cdnsp_device *pdev; in cdnsp_gadget_ep_enable() local
941 pdev = pep->pdev; in cdnsp_gadget_ep_enable()
944 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, 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()
959 if (pdev->gadget.speed == USB_SPEED_FULL) { in cdnsp_gadget_ep_enable()
968 dev_err(pdev->dev, "bInterval %d not supported\n", in cdnsp_gadget_ep_enable()
973 cdnsp_set_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_gadget_ep_enable()
976 ret = cdnsp_endpoint_init(pdev, pep, GFP_ATOMIC); in cdnsp_gadget_ep_enable()
980 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_enable()
984 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_enable()
986 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_enable()
995 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
1004 struct cdnsp_device *pdev; in cdnsp_gadget_ep_disable() local
1014 pdev = pep->pdev; in cdnsp_gadget_ep_disable()
1016 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1019 dev_err(pdev->dev, "%s is already disabled\n", pep->name); in cdnsp_gadget_ep_disable()
1028 cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_gadget_ep_disable()
1029 cdnsp_cmd_flush_ep(pdev, pep); in cdnsp_gadget_ep_disable()
1038 cdnsp_invalidate_ep_events(pdev, pep); in cdnsp_gadget_ep_disable()
1042 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_disable()
1046 cdnsp_endpoint_zero(pdev, pep); in cdnsp_gadget_ep_disable()
1049 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_disable()
1051 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_disable()
1058 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1095 struct cdnsp_device *pdev; in cdnsp_gadget_ep_queue() local
1104 pdev = pep->pdev; in cdnsp_gadget_ep_queue()
1107 dev_err(pdev->dev, "%s: can't queue to disabled endpoint\n", 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() local
1132 dev_err(pdev->dev, 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() local
1157 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1168 ret = cdnsp_halt_endpoint(pdev, pep, value); 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() local
1182 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1184 ret = cdnsp_halt_endpoint(pdev, pep, 1); in cdnsp_gadget_ep_set_wedge()
1185 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1216 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_giveback() local
1223 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_gadget_giveback()
1228 if (preq != &pdev->ep0_preq) { in cdnsp_gadget_giveback()
1229 spin_unlock(&pdev->lock); in cdnsp_gadget_giveback()
1231 spin_lock(&pdev->lock); in cdnsp_gadget_giveback()
1241 static int cdnsp_run(struct cdnsp_device *pdev, in cdnsp_run() argument
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()
1292 ret = cdnsp_start(pdev); 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()
1308 cdnsp_halt(pdev); in cdnsp_run()
1316 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_start() local
1320 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1321 pdev->gadget_driver = driver; in cdnsp_gadget_udc_start()
1325 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_udc_start()
1327 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1337 void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, in cdnsp_update_erst_dequeue() argument
1344 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); 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()
1363 static void cdnsp_clear_cmd_ring(struct cdnsp_device *pdev) in cdnsp_clear_cmd_ring() argument
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()
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()
1386 static void cdnsp_consume_all_events(struct cdnsp_device *pdev) in cdnsp_consume_all_events() argument
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()
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()
1420 cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); in cdnsp_consume_all_events()
1423 static void cdnsp_stop(struct cdnsp_device *pdev) in cdnsp_stop() argument
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()
1440 cdnsp_disable_slot(pdev); in cdnsp_stop()
1441 cdnsp_halt(pdev); 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()
1456 cdnsp_consume_all_events(pdev); in cdnsp_stop()
1457 cdnsp_clear_cmd_ring(pdev); in cdnsp_stop()
1469 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_stop() local
1472 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1473 cdnsp_stop(pdev); 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()
1482 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_get_frame() local
1484 return cdnsp_get_frame(pdev); in cdnsp_gadget_get_frame()
1487 static void __cdnsp_gadget_wakeup(struct cdnsp_device *pdev) in __cdnsp_gadget_wakeup() argument
1492 port_regs = pdev->active_port->regs; in __cdnsp_gadget_wakeup()
1496 if (pdev->gadget.speed < USB_SPEED_SUPER && portsc == XDEV_U2) { 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()
1513 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_wakeup() local
1516 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1517 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_wakeup()
1518 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1526 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_set_selfpowered() local
1529 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1531 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1538 struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); in cdnsp_gadget_pullup() local
1539 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_gadget_pullup()
1549 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_pullup()
1552 cdnsp_reset_device(pdev); in cdnsp_gadget_pullup()
1558 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_pullup()
1573 static void cdnsp_get_ep_buffering(struct cdnsp_device *pdev, in cdnsp_get_ep_buffering() argument
1576 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_ep_buffering()
1589 endpoints = HCS_ENDPOINTS(pdev->hcs_params1) / 2; in cdnsp_get_ep_buffering()
1600 static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_init_endpoints() argument
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()
1620 if (!CDNSP_IF_EP_EXIST(pdev, epnum, direction)) in cdnsp_gadget_init_endpoints()
1623 pep = &pdev->eps[i]; in cdnsp_gadget_init_endpoints()
1624 pep->pdev = pdev; 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()
1659 &pdev->gadget.ep_list); 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()
1672 cdnsp_get_ep_buffering(pdev, pep); in cdnsp_gadget_init_endpoints()
1674 dev_dbg(pdev->dev, "Init %s, MPS: %04x SupType: " in cdnsp_gadget_init_endpoints()
1691 static void cdnsp_gadget_free_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_free_endpoints() argument
1697 pep = &pdev->eps[i]; in cdnsp_gadget_free_endpoints()
1703 void cdnsp_disconnect_gadget(struct cdnsp_device *pdev) in cdnsp_disconnect_gadget() argument
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()
1719 void cdnsp_suspend_gadget(struct cdnsp_device *pdev) in cdnsp_suspend_gadget() argument
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()
1728 void cdnsp_resume_gadget(struct cdnsp_device *pdev) in cdnsp_resume_gadget() argument
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()
1737 void cdnsp_irq_reset(struct cdnsp_device *pdev) in cdnsp_irq_reset() argument
1741 cdnsp_reset_device(pdev); in cdnsp_irq_reset()
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()
1767 cdnsp_clear_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_irq_reset()
1768 cdnsp_setup_device(pdev, SETUP_CONTEXT_ONLY); in cdnsp_irq_reset()
1769 usb_gadget_set_state(&pdev->gadget, USB_STATE_DEFAULT); in cdnsp_irq_reset()
1772 static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) in cdnsp_get_rev_cap() argument
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()
1787 static int cdnsp_gen_setup(struct cdnsp_device *pdev) in cdnsp_gen_setup() argument
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()
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()
1804 cdnsp_get_rev_cap(pdev); in cdnsp_gen_setup()
1807 ret = cdnsp_halt(pdev); in cdnsp_gen_setup()
1812 ret = cdnsp_reset(pdev); 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()
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()
1839 ret = cdnsp_mem_init(pdev); 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()
1857 struct cdnsp_device *pdev; in __cdnsp_gadget_init() local
1863 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); in __cdnsp_gadget_init()
1864 if (!pdev) 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()
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()
1906 ret = cdnsp_gen_setup(pdev); in __cdnsp_gadget_init()
1908 dev_err(pdev->dev, "Generic initialization failed %d\n", ret); in __cdnsp_gadget_init()
1912 ret = cdnsp_gadget_init_endpoints(pdev); 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()
1936 cdnsp_gadget_free_endpoints(pdev); in __cdnsp_gadget_init()
1938 cdnsp_halt(pdev); in __cdnsp_gadget_init()
1939 cdnsp_reset(pdev); in __cdnsp_gadget_init()
1940 cdnsp_mem_cleanup(pdev); in __cdnsp_gadget_init()
1942 kfree(pdev->setup_buf); in __cdnsp_gadget_init()
1944 kfree(pdev); in __cdnsp_gadget_init()
1951 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_exit() local
1953 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); in cdnsp_gadget_exit()
1956 usb_del_gadget_udc(&pdev->gadget); in cdnsp_gadget_exit()
1957 cdnsp_gadget_free_endpoints(pdev); in cdnsp_gadget_exit()
1958 cdnsp_mem_cleanup(pdev); in cdnsp_gadget_exit()
1959 kfree(pdev); in cdnsp_gadget_exit()
1966 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_suspend() local
1969 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_suspend()
1972 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_suspend()
1973 cdnsp_disconnect_gadget(pdev); in cdnsp_gadget_suspend()
1974 cdnsp_stop(pdev); 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() local
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()
1996 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_resume()
1998 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_resume()
1999 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_resume()
2001 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_resume()