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
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
1129 dev_err(pdev->dev, in cdnsp_gadget_ep_dequeue()
1139 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1141 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1149 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_halt() local
1154 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1165 ret = cdnsp_halt_endpoint(pdev, pep, value); in cdnsp_gadget_ep_set_halt()
1168 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1175 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_wedge() local
1179 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1181 ret = cdnsp_halt_endpoint(pdev, pep, 1); in cdnsp_gadget_ep_set_wedge()
1182 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1213 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_giveback() local
1220 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_gadget_giveback()
1225 if (preq != &pdev->ep0_preq) { in cdnsp_gadget_giveback()
1226 spin_unlock(&pdev->lock); in cdnsp_gadget_giveback()
1228 spin_lock(&pdev->lock); in cdnsp_gadget_giveback()
1238 static int cdnsp_run(struct cdnsp_device *pdev, in cdnsp_run() argument
1245 temp = readl(&pdev->ir_set->irq_control); in cdnsp_run()
1248 writel(temp, &pdev->ir_set->irq_control); in cdnsp_run()
1250 temp = readl(&pdev->port3x_regs->mode_addr); in cdnsp_run()
1265 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdnsp_run()
1275 writel(temp, &pdev->port3x_regs->mode_addr); in cdnsp_run()
1276 cdnsp_set_link_state(pdev, &pdev->usb3_port.regs->portsc, in cdnsp_run()
1279 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_run()
1282 cdnsp_set_link_state(pdev, &pdev->usb2_port.regs->portsc, in cdnsp_run()
1287 writel(PORT_REG6_L1_L0_HW_EN | fs_speed, &pdev->port20_regs->port_reg6); in cdnsp_run()
1289 ret = cdnsp_start(pdev); in cdnsp_run()
1295 temp = readl(&pdev->op_regs->command); in cdnsp_run()
1297 writel(temp, &pdev->op_regs->command); in cdnsp_run()
1299 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_run()
1300 writel(IMAN_IE_SET(temp), &pdev->ir_set->irq_pending); in cdnsp_run()
1305 cdnsp_halt(pdev); in cdnsp_run()
1313 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_start() local
1317 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1318 pdev->gadget_driver = driver; in cdnsp_gadget_udc_start()
1322 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_udc_start()
1324 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1334 void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, in cdnsp_update_erst_dequeue() argument
1341 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1344 if (event_ring_deq != pdev->event_ring->dequeue) { in cdnsp_update_erst_dequeue()
1345 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_update_erst_dequeue()
1346 pdev->event_ring->dequeue); in cdnsp_update_erst_dequeue()
1357 cdnsp_write_64(temp_64, &pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1360 static void cdnsp_clear_cmd_ring(struct cdnsp_device *pdev) in cdnsp_clear_cmd_ring() argument
1366 cdnsp_initialize_ring_info(pdev->cmd_ring); in cdnsp_clear_cmd_ring()
1368 seg = pdev->cmd_ring->first_seg; in cdnsp_clear_cmd_ring()
1369 for (i = 0; i < pdev->cmd_ring->num_segs; i++) { in cdnsp_clear_cmd_ring()
1376 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1378 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_clear_cmd_ring()
1379 pdev->cmd_ring->cycle_state; in cdnsp_clear_cmd_ring()
1380 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1383 static void cdnsp_consume_all_events(struct cdnsp_device *pdev) in cdnsp_consume_all_events() argument
1390 event_ring_deq = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1391 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_consume_all_events()
1392 event = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1399 if (cycle_bit != pdev->event_ring->cycle_state) in cdnsp_consume_all_events()
1402 cdnsp_inc_deq(pdev, pdev->event_ring); in cdnsp_consume_all_events()
1409 if (cdnsp_last_trb_on_ring(pdev->event_ring, event_deq_seg, in cdnsp_consume_all_events()
1417 cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); in cdnsp_consume_all_events()
1420 static void cdnsp_stop(struct cdnsp_device *pdev) in cdnsp_stop() argument
1424 cdnsp_cmd_flush_ep(pdev, &pdev->eps[0]); in cdnsp_stop()
1427 if (!list_empty(&pdev->eps[0].pending_list)) { in cdnsp_stop()
1430 req = next_request(&pdev->eps[0].pending_list); in cdnsp_stop()
1431 if (req == &pdev->ep0_preq) in cdnsp_stop()
1432 cdnsp_ep_dequeue(&pdev->eps[0], req); in cdnsp_stop()
1435 cdnsp_disable_port(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1436 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1437 cdnsp_disable_slot(pdev); in cdnsp_stop()
1438 cdnsp_halt(pdev); in cdnsp_stop()
1440 temp = readl(&pdev->op_regs->status); in cdnsp_stop()
1441 writel((temp & ~0x1fff) | STS_EINT, &pdev->op_regs->status); in cdnsp_stop()
1442 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1443 writel(IMAN_IE_CLEAR(temp), &pdev->ir_set->irq_pending); in cdnsp_stop()
1445 cdnsp_clear_port_change_bit(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1446 cdnsp_clear_port_change_bit(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1449 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1451 writel(temp, &pdev->ir_set->irq_pending); in cdnsp_stop()
1453 cdnsp_consume_all_events(pdev); in cdnsp_stop()
1454 cdnsp_clear_cmd_ring(pdev); in cdnsp_stop()
1466 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_stop() local
1469 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1470 cdnsp_stop(pdev); in cdnsp_gadget_udc_stop()
1471 pdev->gadget_driver = NULL; in cdnsp_gadget_udc_stop()
1472 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1479 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_get_frame() local
1481 return cdnsp_get_frame(pdev); in cdnsp_gadget_get_frame()
1484 static void __cdnsp_gadget_wakeup(struct cdnsp_device *pdev) in __cdnsp_gadget_wakeup() argument
1489 port_regs = pdev->active_port->regs; in __cdnsp_gadget_wakeup()
1493 if (pdev->gadget.speed < USB_SPEED_SUPER && portsc == XDEV_U2) { in __cdnsp_gadget_wakeup()
1500 if (portsc == XDEV_U3 && !pdev->may_wakeup) in __cdnsp_gadget_wakeup()
1503 cdnsp_set_link_state(pdev, &port_regs->portsc, XDEV_U0); in __cdnsp_gadget_wakeup()
1505 pdev->cdnsp_state |= CDNSP_WAKEUP_PENDING; in __cdnsp_gadget_wakeup()
1510 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_wakeup() local
1513 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1514 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_wakeup()
1515 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1523 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_set_selfpowered() local
1526 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1528 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1535 struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); in cdnsp_gadget_pullup() local
1536 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_gadget_pullup()
1546 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_pullup()
1549 cdnsp_reset_device(pdev); in cdnsp_gadget_pullup()
1555 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_pullup()
1570 static void cdnsp_get_ep_buffering(struct cdnsp_device *pdev, in cdnsp_get_ep_buffering() argument
1573 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_ep_buffering()
1586 endpoints = HCS_ENDPOINTS(pdev->hcs_params1) / 2; in cdnsp_get_ep_buffering()
1597 static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_init_endpoints() argument
1599 int max_streams = HCC_MAX_PSA(pdev->hcc_params); in cdnsp_gadget_init_endpoints()
1603 INIT_LIST_HEAD(&pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1606 dev_err(pdev->dev, "Stream size %d not supported\n", in cdnsp_gadget_init_endpoints()
1617 if (!CDNSP_IF_EP_EXIST(pdev, epnum, direction)) in cdnsp_gadget_init_endpoints()
1620 pep = &pdev->eps[i]; in cdnsp_gadget_init_endpoints()
1621 pep->pdev = pdev; in cdnsp_gadget_init_endpoints()
1643 pdev->ep0_preq.epnum = pep->number; in cdnsp_gadget_init_endpoints()
1644 pdev->ep0_preq.pep = pep; in cdnsp_gadget_init_endpoints()
1645 pdev->gadget.ep0 = &pep->endpoint; in cdnsp_gadget_init_endpoints()
1656 &pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1667 pep->in_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1668 pep->out_ctx = cdnsp_get_ep_ctx(&pdev->out_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1669 cdnsp_get_ep_buffering(pdev, pep); in cdnsp_gadget_init_endpoints()
1671 dev_dbg(pdev->dev, "Init %s, MPS: %04x SupType: " in cdnsp_gadget_init_endpoints()
1688 static void cdnsp_gadget_free_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_free_endpoints() argument
1694 pep = &pdev->eps[i]; in cdnsp_gadget_free_endpoints()
1700 void cdnsp_disconnect_gadget(struct cdnsp_device *pdev) in cdnsp_disconnect_gadget() argument
1702 pdev->cdnsp_state |= CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1704 if (pdev->gadget_driver && pdev->gadget_driver->disconnect) { in cdnsp_disconnect_gadget()
1705 spin_unlock(&pdev->lock); in cdnsp_disconnect_gadget()
1706 pdev->gadget_driver->disconnect(&pdev->gadget); in cdnsp_disconnect_gadget()
1707 spin_lock(&pdev->lock); in cdnsp_disconnect_gadget()
1710 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdnsp_disconnect_gadget()
1711 usb_gadget_set_state(&pdev->gadget, USB_STATE_NOTATTACHED); in cdnsp_disconnect_gadget()
1713 pdev->cdnsp_state &= ~CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1716 void cdnsp_suspend_gadget(struct cdnsp_device *pdev) in cdnsp_suspend_gadget() argument
1718 if (pdev->gadget_driver && pdev->gadget_driver->suspend) { in cdnsp_suspend_gadget()
1719 spin_unlock(&pdev->lock); in cdnsp_suspend_gadget()
1720 pdev->gadget_driver->suspend(&pdev->gadget); in cdnsp_suspend_gadget()
1721 spin_lock(&pdev->lock); in cdnsp_suspend_gadget()
1725 void cdnsp_resume_gadget(struct cdnsp_device *pdev) in cdnsp_resume_gadget() argument
1727 if (pdev->gadget_driver && pdev->gadget_driver->resume) { in cdnsp_resume_gadget()
1728 spin_unlock(&pdev->lock); in cdnsp_resume_gadget()
1729 pdev->gadget_driver->resume(&pdev->gadget); in cdnsp_resume_gadget()
1730 spin_lock(&pdev->lock); in cdnsp_resume_gadget()
1734 void cdnsp_irq_reset(struct cdnsp_device *pdev) in cdnsp_irq_reset() argument
1738 cdnsp_reset_device(pdev); in cdnsp_irq_reset()
1740 port_regs = pdev->active_port->regs; in cdnsp_irq_reset()
1741 pdev->gadget.speed = cdnsp_port_speed(readl(port_regs)); in cdnsp_irq_reset()
1743 spin_unlock(&pdev->lock); in cdnsp_irq_reset()
1744 usb_gadget_udc_reset(&pdev->gadget, pdev->gadget_driver); in cdnsp_irq_reset()
1745 spin_lock(&pdev->lock); in cdnsp_irq_reset()
1747 switch (pdev->gadget.speed) { in cdnsp_irq_reset()
1751 pdev->gadget.ep0->maxpacket = 512; in cdnsp_irq_reset()
1756 pdev->gadget.ep0->maxpacket = 64; in cdnsp_irq_reset()
1760 dev_err(pdev->dev, "Unknown device speed\n"); in cdnsp_irq_reset()
1764 cdnsp_clear_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_irq_reset()
1765 cdnsp_setup_device(pdev, SETUP_CONTEXT_ONLY); in cdnsp_irq_reset()
1766 usb_gadget_set_state(&pdev->gadget, USB_STATE_DEFAULT); in cdnsp_irq_reset()
1769 static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) in cdnsp_get_rev_cap() argument
1771 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_rev_cap()
1774 pdev->rev_cap = reg; in cdnsp_get_rev_cap()
1776 dev_info(pdev->dev, "Rev: %08x/%08x, eps: %08x, buff: %08x/%08x\n", in cdnsp_get_rev_cap()
1777 readl(&pdev->rev_cap->ctrl_revision), in cdnsp_get_rev_cap()
1778 readl(&pdev->rev_cap->rtl_revision), in cdnsp_get_rev_cap()
1779 readl(&pdev->rev_cap->ep_supported), in cdnsp_get_rev_cap()
1780 readl(&pdev->rev_cap->rx_buff_size), in cdnsp_get_rev_cap()
1781 readl(&pdev->rev_cap->tx_buff_size)); in cdnsp_get_rev_cap()
1784 static int cdnsp_gen_setup(struct cdnsp_device *pdev) in cdnsp_gen_setup() argument
1789 pdev->cap_regs = pdev->regs; in cdnsp_gen_setup()
1790 pdev->op_regs = pdev->regs + in cdnsp_gen_setup()
1791 HC_LENGTH(readl(&pdev->cap_regs->hc_capbase)); in cdnsp_gen_setup()
1792 pdev->run_regs = pdev->regs + in cdnsp_gen_setup()
1793 (readl(&pdev->cap_regs->run_regs_off) & RTSOFF_MASK); in cdnsp_gen_setup()
1796 pdev->hcs_params1 = readl(&pdev->cap_regs->hcs_params1); in cdnsp_gen_setup()
1797 pdev->hcc_params = readl(&pdev->cap_regs->hc_capbase); in cdnsp_gen_setup()
1798 pdev->hci_version = HC_VERSION(pdev->hcc_params); in cdnsp_gen_setup()
1799 pdev->hcc_params = readl(&pdev->cap_regs->hcc_params); in cdnsp_gen_setup()
1801 cdnsp_get_rev_cap(pdev); in cdnsp_gen_setup()
1804 ret = cdnsp_halt(pdev); in cdnsp_gen_setup()
1809 ret = cdnsp_reset(pdev); in cdnsp_gen_setup()
1817 if (HCC_64BIT_ADDR(pdev->hcc_params) && in cdnsp_gen_setup()
1818 !dma_set_mask(pdev->dev, DMA_BIT_MASK(64))) { in cdnsp_gen_setup()
1819 dev_dbg(pdev->dev, "Enabling 64-bit DMA addresses.\n"); in cdnsp_gen_setup()
1820 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(64)); in cdnsp_gen_setup()
1826 ret = dma_set_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1830 dev_dbg(pdev->dev, "Enabling 32-bit DMA addresses.\n"); in cdnsp_gen_setup()
1831 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1834 spin_lock_init(&pdev->lock); in cdnsp_gen_setup()
1836 ret = cdnsp_mem_init(pdev); in cdnsp_gen_setup()
1845 reg = readl(&pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1847 writel(reg, &pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1854 struct cdnsp_device *pdev; in __cdnsp_gadget_init() local
1860 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); in __cdnsp_gadget_init()
1861 if (!pdev) in __cdnsp_gadget_init()
1866 cdns->gadget_dev = pdev; in __cdnsp_gadget_init()
1867 pdev->dev = cdns->dev; in __cdnsp_gadget_init()
1868 pdev->regs = cdns->dev_regs; in __cdnsp_gadget_init()
1886 pdev->gadget.ops = &cdnsp_gadget_ops; in __cdnsp_gadget_init()
1887 pdev->gadget.name = "cdnsp-gadget"; in __cdnsp_gadget_init()
1888 pdev->gadget.speed = USB_SPEED_UNKNOWN; in __cdnsp_gadget_init()
1889 pdev->gadget.sg_supported = 1; in __cdnsp_gadget_init()
1890 pdev->gadget.max_speed = max_speed; in __cdnsp_gadget_init()
1891 pdev->gadget.lpm_capable = 1; in __cdnsp_gadget_init()
1893 pdev->setup_buf = kzalloc(CDNSP_EP0_SETUP_SIZE, GFP_KERNEL); in __cdnsp_gadget_init()
1894 if (!pdev->setup_buf) in __cdnsp_gadget_init()
1901 pdev->gadget.quirk_ep_out_aligned_size = true; in __cdnsp_gadget_init()
1903 ret = cdnsp_gen_setup(pdev); in __cdnsp_gadget_init()
1905 dev_err(pdev->dev, "Generic initialization failed %d\n", ret); in __cdnsp_gadget_init()
1909 ret = cdnsp_gadget_init_endpoints(pdev); in __cdnsp_gadget_init()
1911 dev_err(pdev->dev, "failed to initialize endpoints\n"); in __cdnsp_gadget_init()
1915 ret = usb_add_gadget_udc(pdev->dev, &pdev->gadget); in __cdnsp_gadget_init()
1917 dev_err(pdev->dev, "failed to register udc\n"); in __cdnsp_gadget_init()
1921 ret = devm_request_threaded_irq(pdev->dev, cdns->dev_irq, in __cdnsp_gadget_init()
1924 dev_name(pdev->dev), pdev); in __cdnsp_gadget_init()
1931 usb_del_gadget_udc(&pdev->gadget); in __cdnsp_gadget_init()
1933 cdnsp_gadget_free_endpoints(pdev); in __cdnsp_gadget_init()
1935 cdnsp_halt(pdev); in __cdnsp_gadget_init()
1936 cdnsp_reset(pdev); in __cdnsp_gadget_init()
1937 cdnsp_mem_cleanup(pdev); in __cdnsp_gadget_init()
1939 kfree(pdev->setup_buf); in __cdnsp_gadget_init()
1941 kfree(pdev); in __cdnsp_gadget_init()
1948 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_exit() local
1950 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); in cdnsp_gadget_exit()
1953 usb_del_gadget_udc(&pdev->gadget); in cdnsp_gadget_exit()
1954 cdnsp_gadget_free_endpoints(pdev); in cdnsp_gadget_exit()
1955 cdnsp_mem_cleanup(pdev); in cdnsp_gadget_exit()
1956 kfree(pdev); in cdnsp_gadget_exit()
1963 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_suspend() local
1966 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_suspend()
1969 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_suspend()
1970 cdnsp_disconnect_gadget(pdev); in cdnsp_gadget_suspend()
1971 cdnsp_stop(pdev); in cdnsp_gadget_suspend()
1972 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_suspend()
1979 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_resume() local
1984 if (!pdev->gadget_driver) in cdnsp_gadget_resume()
1987 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_resume()
1988 max_speed = pdev->gadget_driver->max_speed; in cdnsp_gadget_resume()
1991 max_speed = min(max_speed, pdev->gadget.max_speed); in cdnsp_gadget_resume()
1993 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_resume()
1995 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_resume()
1996 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_resume()
1998 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_resume()