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_prepare(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
604 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()
620 cdnsp_queue_reset_ep(pdev, pep->idx); in cdnsp_halt_endpoint()
621 cdnsp_ring_cmd_db(pdev); in cdnsp_halt_endpoint()
622 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_halt_endpoint()
631 cdnsp_ring_doorbell_for_active_rings(pdev, pep); in cdnsp_halt_endpoint()
639 static int cdnsp_update_eps_configuration(struct cdnsp_device *pdev, in cdnsp_update_eps_configuration() argument
648 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
659 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
663 if ((pdev->eps[i - 1].ring && !(ctrl_ctx->drop_flags & le32)) || in cdnsp_update_eps_configuration()
676 ret = cdnsp_configure_endpoint(pdev); in cdnsp_update_eps_configuration()
678 trace_cdnsp_configure_endpoint(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_update_eps_configuration()
681 cdnsp_zero_in_ctx(pdev); in cdnsp_update_eps_configuration()
692 int cdnsp_reset_device(struct cdnsp_device *pdev) in cdnsp_reset_device() argument
698 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_reset_device()
700 pdev->device_address = 0; in cdnsp_reset_device()
703 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_reset_device()
708 pdev->eps[0].ep_state & EP_HALTED) { in cdnsp_reset_device()
709 cdnsp_halt_endpoint(pdev, &pdev->eps[0], 0); in cdnsp_reset_device()
716 pdev->eps[0].ep_state &= ~(EP_STOPPED | EP_HALTED); in cdnsp_reset_device()
717 pdev->eps[0].ep_state |= EP_ENABLED; in cdnsp_reset_device()
722 cdnsp_queue_reset_device(pdev); in cdnsp_reset_device()
723 cdnsp_ring_cmd_db(pdev); in cdnsp_reset_device()
724 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_reset_device()
731 pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED; in cdnsp_reset_device()
736 dev_err(pdev->dev, "Reset device failed with error code %d", in cdnsp_reset_device()
746 static void cdnsp_setup_streams_ep_input_ctx(struct cdnsp_device *pdev, in cdnsp_setup_streams_ep_input_ctx() argument
769 int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_alloc_streams() argument
793 ret = cdnsp_alloc_stream_info(pdev, pep, num_stream_ctxs, num_streams); in cdnsp_alloc_streams()
797 cdnsp_setup_streams_ep_input_ctx(pdev, pep->in_ctx, &pep->stream_info); in cdnsp_alloc_streams()
807 int cdnsp_disable_slot(struct cdnsp_device *pdev) in cdnsp_disable_slot() argument
811 cdnsp_queue_slot_control(pdev, TRB_DISABLE_SLOT); in cdnsp_disable_slot()
812 cdnsp_ring_cmd_db(pdev); in cdnsp_disable_slot()
813 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_disable_slot()
815 pdev->slot_id = 0; in cdnsp_disable_slot()
816 pdev->active_port = NULL; in cdnsp_disable_slot()
818 trace_cdnsp_handle_cmd_disable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_disable_slot()
820 memset(pdev->in_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
821 memset(pdev->out_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
826 int cdnsp_enable_slot(struct cdnsp_device *pdev) in cdnsp_enable_slot() argument
833 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_enable_slot()
839 cdnsp_queue_slot_control(pdev, TRB_ENABLE_SLOT); in cdnsp_enable_slot()
840 cdnsp_ring_cmd_db(pdev); in cdnsp_enable_slot()
841 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_enable_slot()
845 pdev->slot_id = 1; in cdnsp_enable_slot()
848 trace_cdnsp_handle_cmd_enable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_enable_slot()
857 int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup) in cdnsp_setup_device() argument
864 if (!pdev->slot_id) { in cdnsp_setup_device()
869 if (!pdev->active_port->port_num) in cdnsp_setup_device()
872 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_setup_device()
880 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_setup_device()
881 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_setup_device()
884 ret = cdnsp_setup_addressable_priv_dev(pdev); in cdnsp_setup_device()
889 cdnsp_copy_ep0_dequeue_into_input_ctx(pdev); in cdnsp_setup_device()
896 cdnsp_queue_address_device(pdev, pdev->in_ctx.dma, setup); in cdnsp_setup_device()
897 cdnsp_ring_cmd_db(pdev); in cdnsp_setup_device()
898 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_setup_device()
900 trace_cdnsp_handle_cmd_addr_dev(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_setup_device()
909 void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *pdev, in cdnsp_set_usb2_hardware_lpm() argument
913 if (pdev->active_port != &pdev->usb2_port || !pdev->gadget.lpm_capable) in cdnsp_set_usb2_hardware_lpm()
920 &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
922 writel(PORT_L1S_NYET, &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
925 static int cdnsp_get_frame(struct cdnsp_device *pdev) in cdnsp_get_frame() argument
927 return readl(&pdev->run_regs->microframe_index) >> 3; in cdnsp_get_frame()
934 struct cdnsp_device *pdev; in cdnsp_gadget_ep_enable() local
945 pdev = pep->pdev; in cdnsp_gadget_ep_enable()
948 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, in cdnsp_gadget_ep_enable()
952 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
956 dev_err(pdev->dev, "ERROR: Bad endpoint number\n"); in cdnsp_gadget_ep_enable()
963 if (pdev->gadget.speed == USB_SPEED_FULL) { in cdnsp_gadget_ep_enable()
972 dev_err(pdev->dev, "bInterval %d not supported\n", in cdnsp_gadget_ep_enable()
977 cdnsp_set_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_gadget_ep_enable()
980 ret = cdnsp_endpoint_init(pdev, pep, GFP_ATOMIC); in cdnsp_gadget_ep_enable()
984 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_enable()
988 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_enable()
990 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_enable()
999 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
1008 struct cdnsp_device *pdev; in cdnsp_gadget_ep_disable() local
1018 pdev = pep->pdev; in cdnsp_gadget_ep_disable()
1020 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1023 dev_err(pdev->dev, "%s is already disabled\n", pep->name); in cdnsp_gadget_ep_disable()
1032 cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_gadget_ep_disable()
1033 cdnsp_cmd_flush_ep(pdev, pep); in cdnsp_gadget_ep_disable()
1042 cdnsp_invalidate_ep_events(pdev, pep); in cdnsp_gadget_ep_disable()
1046 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_disable()
1050 cdnsp_endpoint_zero(pdev, pep); in cdnsp_gadget_ep_disable()
1053 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_disable()
1055 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_disable()
1062 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1099 struct cdnsp_device *pdev; in cdnsp_gadget_ep_queue() local
1108 pdev = pep->pdev; in cdnsp_gadget_ep_queue()
1111 dev_err(pdev->dev, "%s: can't queue to disabled endpoint\n", in cdnsp_gadget_ep_queue()
1117 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1119 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1128 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_dequeue() local
1133 dev_err(pdev->dev, in cdnsp_gadget_ep_dequeue()
1143 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1145 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1153 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_halt() local
1158 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1169 ret = cdnsp_halt_endpoint(pdev, pep, value); in cdnsp_gadget_ep_set_halt()
1172 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1179 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_wedge() local
1183 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1185 ret = cdnsp_halt_endpoint(pdev, pep, 1); in cdnsp_gadget_ep_set_wedge()
1186 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1217 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_giveback() local
1224 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_gadget_giveback()
1229 if (preq != &pdev->ep0_preq) { in cdnsp_gadget_giveback()
1230 spin_unlock(&pdev->lock); in cdnsp_gadget_giveback()
1232 spin_lock(&pdev->lock); in cdnsp_gadget_giveback()
1242 static int cdnsp_run(struct cdnsp_device *pdev, in cdnsp_run() argument
1250 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_run()
1252 temp = readl(&pdev->ir_set->irq_control); in cdnsp_run()
1255 writel(temp, &pdev->ir_set->irq_control); in cdnsp_run()
1257 temp = readl(&pdev->port3x_regs->mode_addr); in cdnsp_run()
1272 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdnsp_run()
1282 writel(temp, &pdev->port3x_regs->mode_addr); in cdnsp_run()
1283 cdnsp_set_link_state(pdev, &pdev->usb3_port.regs->portsc, in cdnsp_run()
1286 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_run()
1289 cdnsp_set_link_state(pdev, &pdev->usb2_port.regs->portsc, in cdnsp_run()
1294 writel(PORT_REG6_L1_L0_HW_EN | fs_speed, &pdev->port20_regs->port_reg6); in cdnsp_run()
1296 ret = cdnsp_start(pdev); in cdnsp_run()
1302 temp = readl(&pdev->op_regs->command); in cdnsp_run()
1304 writel(temp, &pdev->op_regs->command); in cdnsp_run()
1306 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_run()
1307 writel(IMAN_IE_SET(temp), &pdev->ir_set->irq_pending); in cdnsp_run()
1312 cdnsp_halt(pdev); in cdnsp_run()
1320 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_start() local
1324 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1325 pdev->gadget_driver = driver; in cdnsp_gadget_udc_start()
1329 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_udc_start()
1331 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1341 void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, in cdnsp_update_erst_dequeue() argument
1348 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1351 if (event_ring_deq != pdev->event_ring->dequeue) { in cdnsp_update_erst_dequeue()
1352 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_update_erst_dequeue()
1353 pdev->event_ring->dequeue); in cdnsp_update_erst_dequeue()
1364 cdnsp_write_64(temp_64, &pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1367 static void cdnsp_clear_cmd_ring(struct cdnsp_device *pdev) in cdnsp_clear_cmd_ring() argument
1373 cdnsp_initialize_ring_info(pdev->cmd_ring); in cdnsp_clear_cmd_ring()
1375 seg = pdev->cmd_ring->first_seg; in cdnsp_clear_cmd_ring()
1376 for (i = 0; i < pdev->cmd_ring->num_segs; i++) { in cdnsp_clear_cmd_ring()
1383 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1385 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_clear_cmd_ring()
1386 pdev->cmd_ring->cycle_state; in cdnsp_clear_cmd_ring()
1387 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1390 static void cdnsp_consume_all_events(struct cdnsp_device *pdev) in cdnsp_consume_all_events() argument
1397 event_ring_deq = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1398 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_consume_all_events()
1399 event = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1406 if (cycle_bit != pdev->event_ring->cycle_state) in cdnsp_consume_all_events()
1409 cdnsp_inc_deq(pdev, pdev->event_ring); in cdnsp_consume_all_events()
1416 if (cdnsp_last_trb_on_ring(pdev->event_ring, event_deq_seg, in cdnsp_consume_all_events()
1424 cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); in cdnsp_consume_all_events()
1427 static void cdnsp_stop(struct cdnsp_device *pdev) in cdnsp_stop() argument
1431 cdnsp_cmd_flush_ep(pdev, &pdev->eps[0]); in cdnsp_stop()
1434 if (!list_empty(&pdev->eps[0].pending_list)) { in cdnsp_stop()
1437 req = next_request(&pdev->eps[0].pending_list); in cdnsp_stop()
1438 if (req == &pdev->ep0_preq) in cdnsp_stop()
1439 cdnsp_ep_dequeue(&pdev->eps[0], req); in cdnsp_stop()
1442 cdnsp_disable_port(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1443 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1444 cdnsp_disable_slot(pdev); in cdnsp_stop()
1445 cdnsp_halt(pdev); in cdnsp_stop()
1447 temp = readl(&pdev->op_regs->status); in cdnsp_stop()
1448 writel((temp & ~0x1fff) | STS_EINT, &pdev->op_regs->status); in cdnsp_stop()
1449 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1450 writel(IMAN_IE_CLEAR(temp), &pdev->ir_set->irq_pending); in cdnsp_stop()
1452 cdnsp_clear_port_change_bit(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1453 cdnsp_clear_port_change_bit(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1456 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1458 writel(temp, &pdev->ir_set->irq_pending); in cdnsp_stop()
1460 cdnsp_consume_all_events(pdev); in cdnsp_stop()
1461 cdnsp_clear_cmd_ring(pdev); in cdnsp_stop()
1473 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_stop() local
1476 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1477 cdnsp_stop(pdev); in cdnsp_gadget_udc_stop()
1478 pdev->gadget_driver = NULL; in cdnsp_gadget_udc_stop()
1479 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1486 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_get_frame() local
1488 return cdnsp_get_frame(pdev); in cdnsp_gadget_get_frame()
1491 static void __cdnsp_gadget_wakeup(struct cdnsp_device *pdev) in __cdnsp_gadget_wakeup() argument
1496 port_regs = pdev->active_port->regs; in __cdnsp_gadget_wakeup()
1500 if (pdev->gadget.speed < USB_SPEED_SUPER && portsc == XDEV_U2) { in __cdnsp_gadget_wakeup()
1507 if (portsc == XDEV_U3 && !pdev->may_wakeup) in __cdnsp_gadget_wakeup()
1510 cdnsp_set_link_state(pdev, &port_regs->portsc, XDEV_U0); in __cdnsp_gadget_wakeup()
1512 pdev->cdnsp_state |= CDNSP_WAKEUP_PENDING; in __cdnsp_gadget_wakeup()
1517 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_wakeup() local
1520 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1521 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_wakeup()
1522 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1530 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_set_selfpowered() local
1533 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1535 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1542 struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); in cdnsp_gadget_pullup() local
1543 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_gadget_pullup()
1553 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_pullup()
1556 cdnsp_reset_device(pdev); in cdnsp_gadget_pullup()
1562 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_pullup()
1577 static void cdnsp_get_ep_buffering(struct cdnsp_device *pdev, in cdnsp_get_ep_buffering() argument
1580 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_ep_buffering()
1593 endpoints = HCS_ENDPOINTS(pdev->hcs_params1) / 2; in cdnsp_get_ep_buffering()
1604 static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_init_endpoints() argument
1606 int max_streams = HCC_MAX_PSA(pdev->hcc_params); in cdnsp_gadget_init_endpoints()
1610 INIT_LIST_HEAD(&pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1613 dev_err(pdev->dev, "Stream size %d not supported\n", in cdnsp_gadget_init_endpoints()
1624 if (!CDNSP_IF_EP_EXIST(pdev, epnum, direction)) in cdnsp_gadget_init_endpoints()
1627 pep = &pdev->eps[i]; in cdnsp_gadget_init_endpoints()
1628 pep->pdev = pdev; in cdnsp_gadget_init_endpoints()
1650 pdev->ep0_preq.epnum = pep->number; in cdnsp_gadget_init_endpoints()
1651 pdev->ep0_preq.pep = pep; in cdnsp_gadget_init_endpoints()
1652 pdev->gadget.ep0 = &pep->endpoint; in cdnsp_gadget_init_endpoints()
1663 &pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1674 pep->in_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1675 pep->out_ctx = cdnsp_get_ep_ctx(&pdev->out_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1676 cdnsp_get_ep_buffering(pdev, pep); in cdnsp_gadget_init_endpoints()
1678 dev_dbg(pdev->dev, "Init %s, MPS: %04x SupType: " in cdnsp_gadget_init_endpoints()
1695 static void cdnsp_gadget_free_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_free_endpoints() argument
1701 pep = &pdev->eps[i]; in cdnsp_gadget_free_endpoints()
1707 void cdnsp_disconnect_gadget(struct cdnsp_device *pdev) in cdnsp_disconnect_gadget() argument
1709 pdev->cdnsp_state |= CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1711 if (pdev->gadget_driver && pdev->gadget_driver->disconnect) { in cdnsp_disconnect_gadget()
1712 spin_unlock(&pdev->lock); in cdnsp_disconnect_gadget()
1713 pdev->gadget_driver->disconnect(&pdev->gadget); in cdnsp_disconnect_gadget()
1714 spin_lock(&pdev->lock); in cdnsp_disconnect_gadget()
1717 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdnsp_disconnect_gadget()
1718 usb_gadget_set_state(&pdev->gadget, USB_STATE_NOTATTACHED); in cdnsp_disconnect_gadget()
1720 pdev->cdnsp_state &= ~CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1723 void cdnsp_suspend_gadget(struct cdnsp_device *pdev) in cdnsp_suspend_gadget() argument
1725 if (pdev->gadget_driver && pdev->gadget_driver->suspend) { in cdnsp_suspend_gadget()
1726 spin_unlock(&pdev->lock); in cdnsp_suspend_gadget()
1727 pdev->gadget_driver->suspend(&pdev->gadget); in cdnsp_suspend_gadget()
1728 spin_lock(&pdev->lock); in cdnsp_suspend_gadget()
1732 void cdnsp_resume_gadget(struct cdnsp_device *pdev) in cdnsp_resume_gadget() argument
1734 if (pdev->gadget_driver && pdev->gadget_driver->resume) { in cdnsp_resume_gadget()
1735 spin_unlock(&pdev->lock); in cdnsp_resume_gadget()
1736 pdev->gadget_driver->resume(&pdev->gadget); in cdnsp_resume_gadget()
1737 spin_lock(&pdev->lock); in cdnsp_resume_gadget()
1741 void cdnsp_irq_reset(struct cdnsp_device *pdev) in cdnsp_irq_reset() argument
1745 cdnsp_reset_device(pdev); in cdnsp_irq_reset()
1747 port_regs = pdev->active_port->regs; in cdnsp_irq_reset()
1748 pdev->gadget.speed = cdnsp_port_speed(readl(port_regs)); in cdnsp_irq_reset()
1750 spin_unlock(&pdev->lock); in cdnsp_irq_reset()
1751 usb_gadget_udc_reset(&pdev->gadget, pdev->gadget_driver); in cdnsp_irq_reset()
1752 spin_lock(&pdev->lock); in cdnsp_irq_reset()
1754 switch (pdev->gadget.speed) { in cdnsp_irq_reset()
1758 pdev->gadget.ep0->maxpacket = 512; in cdnsp_irq_reset()
1763 pdev->gadget.ep0->maxpacket = 64; in cdnsp_irq_reset()
1767 dev_err(pdev->dev, "Unknown device speed\n"); in cdnsp_irq_reset()
1771 cdnsp_clear_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_irq_reset()
1772 cdnsp_setup_device(pdev, SETUP_CONTEXT_ONLY); in cdnsp_irq_reset()
1773 usb_gadget_set_state(&pdev->gadget, USB_STATE_DEFAULT); in cdnsp_irq_reset()
1776 static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) in cdnsp_get_rev_cap() argument
1778 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_rev_cap()
1781 pdev->rev_cap = reg; in cdnsp_get_rev_cap()
1783 dev_info(pdev->dev, "Rev: %08x/%08x, eps: %08x, buff: %08x/%08x\n", in cdnsp_get_rev_cap()
1784 readl(&pdev->rev_cap->ctrl_revision), in cdnsp_get_rev_cap()
1785 readl(&pdev->rev_cap->rtl_revision), in cdnsp_get_rev_cap()
1786 readl(&pdev->rev_cap->ep_supported), in cdnsp_get_rev_cap()
1787 readl(&pdev->rev_cap->rx_buff_size), in cdnsp_get_rev_cap()
1788 readl(&pdev->rev_cap->tx_buff_size)); in cdnsp_get_rev_cap()
1791 static int cdnsp_gen_setup(struct cdnsp_device *pdev) in cdnsp_gen_setup() argument
1796 pdev->cap_regs = pdev->regs; in cdnsp_gen_setup()
1797 pdev->op_regs = pdev->regs + in cdnsp_gen_setup()
1798 HC_LENGTH(readl(&pdev->cap_regs->hc_capbase)); in cdnsp_gen_setup()
1799 pdev->run_regs = pdev->regs + in cdnsp_gen_setup()
1800 (readl(&pdev->cap_regs->run_regs_off) & RTSOFF_MASK); in cdnsp_gen_setup()
1803 pdev->hcs_params1 = readl(&pdev->cap_regs->hcs_params1); in cdnsp_gen_setup()
1804 pdev->hcc_params = readl(&pdev->cap_regs->hc_capbase); in cdnsp_gen_setup()
1805 pdev->hci_version = HC_VERSION(pdev->hcc_params); in cdnsp_gen_setup()
1806 pdev->hcc_params = readl(&pdev->cap_regs->hcc_params); in cdnsp_gen_setup()
1808 cdnsp_get_rev_cap(pdev); in cdnsp_gen_setup()
1811 ret = cdnsp_halt(pdev); in cdnsp_gen_setup()
1816 ret = cdnsp_reset(pdev); in cdnsp_gen_setup()
1824 if (HCC_64BIT_ADDR(pdev->hcc_params) && in cdnsp_gen_setup()
1825 !dma_set_mask(pdev->dev, DMA_BIT_MASK(64))) { in cdnsp_gen_setup()
1826 dev_dbg(pdev->dev, "Enabling 64-bit DMA addresses.\n"); in cdnsp_gen_setup()
1827 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(64)); in cdnsp_gen_setup()
1833 ret = dma_set_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1837 dev_dbg(pdev->dev, "Enabling 32-bit DMA addresses.\n"); in cdnsp_gen_setup()
1838 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1841 spin_lock_init(&pdev->lock); in cdnsp_gen_setup()
1843 ret = cdnsp_mem_init(pdev); in cdnsp_gen_setup()
1852 reg = readl(&pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1854 writel(reg, &pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1861 struct cdnsp_device *pdev; in __cdnsp_gadget_init() local
1867 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); in __cdnsp_gadget_init()
1868 if (!pdev) in __cdnsp_gadget_init()
1873 cdns->gadget_dev = pdev; in __cdnsp_gadget_init()
1874 pdev->dev = cdns->dev; in __cdnsp_gadget_init()
1875 pdev->regs = cdns->dev_regs; in __cdnsp_gadget_init()
1893 pdev->gadget.ops = &cdnsp_gadget_ops; in __cdnsp_gadget_init()
1894 pdev->gadget.name = "cdnsp-gadget"; in __cdnsp_gadget_init()
1895 pdev->gadget.speed = USB_SPEED_UNKNOWN; in __cdnsp_gadget_init()
1896 pdev->gadget.sg_supported = 1; in __cdnsp_gadget_init()
1897 pdev->gadget.max_speed = max_speed; in __cdnsp_gadget_init()
1898 pdev->gadget.lpm_capable = 1; in __cdnsp_gadget_init()
1900 pdev->setup_buf = kzalloc(CDNSP_EP0_SETUP_SIZE, GFP_KERNEL); in __cdnsp_gadget_init()
1901 if (!pdev->setup_buf) in __cdnsp_gadget_init()
1908 pdev->gadget.quirk_ep_out_aligned_size = true; in __cdnsp_gadget_init()
1910 ret = cdnsp_gen_setup(pdev); in __cdnsp_gadget_init()
1912 dev_err(pdev->dev, "Generic initialization failed %d\n", ret); in __cdnsp_gadget_init()
1916 ret = cdnsp_gadget_init_endpoints(pdev); in __cdnsp_gadget_init()
1918 dev_err(pdev->dev, "failed to initialize endpoints\n"); in __cdnsp_gadget_init()
1922 ret = usb_add_gadget_udc(pdev->dev, &pdev->gadget); in __cdnsp_gadget_init()
1924 dev_err(pdev->dev, "failed to register udc\n"); in __cdnsp_gadget_init()
1928 ret = devm_request_threaded_irq(pdev->dev, cdns->dev_irq, in __cdnsp_gadget_init()
1931 dev_name(pdev->dev), pdev); in __cdnsp_gadget_init()
1938 usb_del_gadget_udc(&pdev->gadget); in __cdnsp_gadget_init()
1940 cdnsp_gadget_free_endpoints(pdev); in __cdnsp_gadget_init()
1942 cdnsp_halt(pdev); in __cdnsp_gadget_init()
1943 cdnsp_reset(pdev); in __cdnsp_gadget_init()
1944 cdnsp_mem_cleanup(pdev); in __cdnsp_gadget_init()
1946 kfree(pdev->setup_buf); in __cdnsp_gadget_init()
1948 kfree(pdev); in __cdnsp_gadget_init()
1955 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_exit() local
1957 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); in cdnsp_gadget_exit()
1960 usb_del_gadget_udc(&pdev->gadget); in cdnsp_gadget_exit()
1961 cdnsp_gadget_free_endpoints(pdev); in cdnsp_gadget_exit()
1962 cdnsp_mem_cleanup(pdev); in cdnsp_gadget_exit()
1963 kfree(pdev); in cdnsp_gadget_exit()
1970 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_suspend() local
1973 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_suspend()
1976 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_suspend()
1977 cdnsp_disconnect_gadget(pdev); in cdnsp_gadget_suspend()
1978 cdnsp_stop(pdev); in cdnsp_gadget_suspend()
1979 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_suspend()
1986 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_resume() local
1991 if (!pdev->gadget_driver) in cdnsp_gadget_resume()
1994 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_resume()
1995 max_speed = pdev->gadget_driver->max_speed; in cdnsp_gadget_resume()
1998 max_speed = min(max_speed, pdev->gadget.max_speed); in cdnsp_gadget_resume()
2000 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_resume()
2002 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_resume()
2003 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_resume()
2005 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_resume()