Lines Matching refs:pdev
103 void cdnsp_set_link_state(struct cdnsp_device *pdev, in cdnsp_set_link_state() argument
118 if (pdev->active_port) in cdnsp_set_link_state()
119 port_num = pdev->active_port->port_num; in cdnsp_set_link_state()
126 static void cdnsp_disable_port(struct cdnsp_device *pdev, in cdnsp_disable_port() argument
134 static void cdnsp_clear_port_change_bit(struct cdnsp_device *pdev, in cdnsp_clear_port_change_bit() argument
143 static void cdnsp_set_apb_timeout_value(struct cdnsp_device *pdev) in cdnsp_set_apb_timeout_value() argument
145 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_set_apb_timeout_value()
154 base = &pdev->cap_regs->hc_capbase; in cdnsp_set_apb_timeout_value()
163 static void cdnsp_set_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) in cdnsp_set_chicken_bits_2() argument
169 base = &pdev->cap_regs->hc_capbase; in cdnsp_set_chicken_bits_2()
177 static void cdnsp_clear_chicken_bits_2(struct cdnsp_device *pdev, u32 bit) in cdnsp_clear_chicken_bits_2() argument
183 base = &pdev->cap_regs->hc_capbase; in cdnsp_clear_chicken_bits_2()
194 static void cdnsp_quiesce(struct cdnsp_device *pdev) in cdnsp_quiesce() argument
202 halted = readl(&pdev->op_regs->status) & STS_HALT; in cdnsp_quiesce()
206 cmd = readl(&pdev->op_regs->command); in cdnsp_quiesce()
208 writel(cmd, &pdev->op_regs->command); in cdnsp_quiesce()
220 int cdnsp_halt(struct cdnsp_device *pdev) in cdnsp_halt() argument
225 cdnsp_quiesce(pdev); in cdnsp_halt()
227 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, val, in cdnsp_halt()
231 dev_err(pdev->dev, "ERROR: Device halt failed\n"); in cdnsp_halt()
235 pdev->cdnsp_state |= CDNSP_STATE_HALTED; in cdnsp_halt()
244 void cdnsp_died(struct cdnsp_device *pdev) in cdnsp_died() argument
246 dev_err(pdev->dev, "ERROR: CDNSP controller not responding\n"); in cdnsp_died()
247 pdev->cdnsp_state |= CDNSP_STATE_DYING; in cdnsp_died()
248 cdnsp_halt(pdev); in cdnsp_died()
254 static int cdnsp_start(struct cdnsp_device *pdev) in cdnsp_start() argument
259 temp = readl(&pdev->op_regs->command); in cdnsp_start()
261 writel(temp, &pdev->op_regs->command); in cdnsp_start()
263 pdev->cdnsp_state = 0; in cdnsp_start()
269 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, in cdnsp_start()
273 pdev->cdnsp_state = CDNSP_STATE_DYING; in cdnsp_start()
274 dev_err(pdev->dev, "ERROR: Controller run failed\n"); in cdnsp_start()
287 int cdnsp_reset(struct cdnsp_device *pdev) in cdnsp_reset() argument
293 temp = readl(&pdev->op_regs->status); in cdnsp_reset()
296 dev_err(pdev->dev, "Device not accessible, reset failed.\n"); in cdnsp_reset()
301 dev_err(pdev->dev, "Controller not halted, aborting reset.\n"); in cdnsp_reset()
305 command = readl(&pdev->op_regs->command); in cdnsp_reset()
307 writel(command, &pdev->op_regs->command); in cdnsp_reset()
309 ret = readl_poll_timeout_atomic(&pdev->op_regs->command, temp, in cdnsp_reset()
313 dev_err(pdev->dev, "ERROR: Controller reset failed\n"); in cdnsp_reset()
321 ret = readl_poll_timeout_atomic(&pdev->op_regs->status, temp, in cdnsp_reset()
326 dev_err(pdev->dev, "ERROR: Controller not ready to work\n"); in cdnsp_reset()
330 dev_dbg(pdev->dev, "Controller ready to work"); in cdnsp_reset()
368 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_enqueue() local
384 ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->direction); in cdnsp_ep_enqueue()
396 ret = cdnsp_queue_ctrl_tx(pdev, preq); in cdnsp_ep_enqueue()
400 ret = cdnsp_queue_bulk_tx(pdev, preq); in cdnsp_ep_enqueue()
403 ret = cdnsp_queue_isoc_tx(pdev, preq); in cdnsp_ep_enqueue()
412 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_ep_enqueue()
447 struct cdnsp_device *pdev = pep->pdev; in cdnsp_ep_dequeue() local
454 ret_stop = cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_ep_dequeue()
456 ret_rem = cdnsp_remove_request(pdev, preq, pep); in cdnsp_ep_dequeue()
461 static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev) in cdnsp_zero_in_ctx() argument
468 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
478 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_zero_in_ctx()
484 ep_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, i); in cdnsp_zero_in_ctx()
493 static int cdnsp_configure_endpoint(struct cdnsp_device *pdev) in cdnsp_configure_endpoint() argument
497 cdnsp_queue_configure_endpoint(pdev, pdev->cmd.in_ctx->dma); in cdnsp_configure_endpoint()
498 cdnsp_ring_cmd_db(pdev); in cdnsp_configure_endpoint()
499 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_configure_endpoint()
501 dev_err(pdev->dev, in cdnsp_configure_endpoint()
509 static void cdnsp_invalidate_ep_events(struct cdnsp_device *pdev, in cdnsp_invalidate_ep_events() argument
517 event = pdev->event_ring->dequeue; in cdnsp_invalidate_ep_events()
518 segment = pdev->event_ring->deq_seg; in cdnsp_invalidate_ep_events()
519 cycle_state = pdev->event_ring->cycle_state; in cdnsp_invalidate_ep_events()
536 segment = pdev->event_ring->deq_seg->next; in cdnsp_invalidate_ep_events()
544 int cdnsp_wait_for_cmd_compl(struct cdnsp_device *pdev) in cdnsp_wait_for_cmd_compl() argument
556 cmd_trb = pdev->cmd.command_trb; in cdnsp_wait_for_cmd_compl()
557 pdev->cmd.status = 0; in cdnsp_wait_for_cmd_compl()
559 trace_cdnsp_cmd_wait_for_compl(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
561 ret = readl_poll_timeout_atomic(&pdev->op_regs->cmd_ring, val, in cdnsp_wait_for_cmd_compl()
565 dev_err(pdev->dev, "ERR: Timeout while waiting for command\n"); in cdnsp_wait_for_cmd_compl()
566 trace_cdnsp_cmd_timeout(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
567 pdev->cdnsp_state = CDNSP_STATE_DYING; in cdnsp_wait_for_cmd_compl()
571 event = pdev->event_ring->dequeue; in cdnsp_wait_for_cmd_compl()
572 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_wait_for_cmd_compl()
573 cycle_state = pdev->event_ring->cycle_state; in cdnsp_wait_for_cmd_compl()
575 cmd_deq_dma = cdnsp_trb_virt_to_dma(pdev->cmd_ring->deq_seg, cmd_trb); in cdnsp_wait_for_cmd_compl()
614 if (cdnsp_last_trb_on_ring(pdev->event_ring, in cdnsp_wait_for_cmd_compl()
623 trace_cdnsp_handle_command(pdev->cmd_ring, &cmd_trb->generic); in cdnsp_wait_for_cmd_compl()
625 pdev->cmd.status = GET_COMP_CODE(le32_to_cpu(event->event_cmd.status)); in cdnsp_wait_for_cmd_compl()
626 if (pdev->cmd.status == COMP_SUCCESS) in cdnsp_wait_for_cmd_compl()
629 return -pdev->cmd.status; in cdnsp_wait_for_cmd_compl()
633 int cdnsp_halt_endpoint(struct cdnsp_device *pdev, in cdnsp_halt_endpoint() argument
641 ret = cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_halt_endpoint()
647 cdnsp_queue_halt_endpoint(pdev, pep->idx); in cdnsp_halt_endpoint()
648 cdnsp_ring_cmd_db(pdev); in cdnsp_halt_endpoint()
649 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_halt_endpoint()
654 cdnsp_queue_reset_ep(pdev, pep->idx); in cdnsp_halt_endpoint()
655 cdnsp_ring_cmd_db(pdev); in cdnsp_halt_endpoint()
656 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_halt_endpoint()
665 cdnsp_ring_doorbell_for_active_rings(pdev, pep); in cdnsp_halt_endpoint()
673 static int cdnsp_update_eps_configuration(struct cdnsp_device *pdev, in cdnsp_update_eps_configuration() argument
682 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
693 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_update_eps_configuration()
697 if ((pdev->eps[i - 1].ring && !(ctrl_ctx->drop_flags & le32)) || in cdnsp_update_eps_configuration()
710 ret = cdnsp_configure_endpoint(pdev); in cdnsp_update_eps_configuration()
712 trace_cdnsp_configure_endpoint(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_update_eps_configuration()
715 cdnsp_zero_in_ctx(pdev); in cdnsp_update_eps_configuration()
726 int cdnsp_reset_device(struct cdnsp_device *pdev) in cdnsp_reset_device() argument
732 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_reset_device()
734 pdev->device_address = 0; in cdnsp_reset_device()
737 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_reset_device()
742 pdev->eps[0].ep_state & EP_HALTED) { in cdnsp_reset_device()
743 cdnsp_halt_endpoint(pdev, &pdev->eps[0], 0); in cdnsp_reset_device()
750 pdev->eps[0].ep_state &= ~(EP_STOPPED | EP_HALTED); in cdnsp_reset_device()
751 pdev->eps[0].ep_state |= EP_ENABLED; in cdnsp_reset_device()
756 cdnsp_queue_reset_device(pdev); in cdnsp_reset_device()
757 cdnsp_ring_cmd_db(pdev); in cdnsp_reset_device()
758 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_reset_device()
765 pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED; in cdnsp_reset_device()
770 dev_err(pdev->dev, "Reset device failed with error code %d", in cdnsp_reset_device()
780 static void cdnsp_setup_streams_ep_input_ctx(struct cdnsp_device *pdev, in cdnsp_setup_streams_ep_input_ctx() argument
803 int cdnsp_alloc_streams(struct cdnsp_device *pdev, struct cdnsp_ep *pep) in cdnsp_alloc_streams() argument
827 ret = cdnsp_alloc_stream_info(pdev, pep, num_stream_ctxs, num_streams); in cdnsp_alloc_streams()
831 cdnsp_setup_streams_ep_input_ctx(pdev, pep->in_ctx, &pep->stream_info); in cdnsp_alloc_streams()
841 int cdnsp_disable_slot(struct cdnsp_device *pdev) in cdnsp_disable_slot() argument
845 cdnsp_queue_slot_control(pdev, TRB_DISABLE_SLOT); in cdnsp_disable_slot()
846 cdnsp_ring_cmd_db(pdev); in cdnsp_disable_slot()
847 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_disable_slot()
849 pdev->slot_id = 0; in cdnsp_disable_slot()
850 pdev->active_port = NULL; in cdnsp_disable_slot()
852 trace_cdnsp_handle_cmd_disable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_disable_slot()
854 memset(pdev->in_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
855 memset(pdev->out_ctx.bytes, 0, CDNSP_CTX_SIZE); in cdnsp_disable_slot()
860 int cdnsp_enable_slot(struct cdnsp_device *pdev) in cdnsp_enable_slot() argument
867 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_enable_slot()
873 cdnsp_queue_slot_control(pdev, TRB_ENABLE_SLOT); in cdnsp_enable_slot()
874 cdnsp_ring_cmd_db(pdev); in cdnsp_enable_slot()
875 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_enable_slot()
879 pdev->slot_id = 1; in cdnsp_enable_slot()
882 trace_cdnsp_handle_cmd_enable_slot(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_enable_slot()
891 int cdnsp_setup_device(struct cdnsp_device *pdev, enum cdnsp_setup_dev setup) in cdnsp_setup_device() argument
898 if (!pdev->slot_id) { in cdnsp_setup_device()
903 if (!pdev->active_port->port_num) in cdnsp_setup_device()
906 slot_ctx = cdnsp_get_slot_ctx(&pdev->out_ctx); in cdnsp_setup_device()
914 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_setup_device()
915 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_setup_device()
918 ret = cdnsp_setup_addressable_priv_dev(pdev); in cdnsp_setup_device()
923 cdnsp_copy_ep0_dequeue_into_input_ctx(pdev); in cdnsp_setup_device()
930 cdnsp_queue_address_device(pdev, pdev->in_ctx.dma, setup); in cdnsp_setup_device()
931 cdnsp_ring_cmd_db(pdev); in cdnsp_setup_device()
932 ret = cdnsp_wait_for_cmd_compl(pdev); in cdnsp_setup_device()
934 trace_cdnsp_handle_cmd_addr_dev(cdnsp_get_slot_ctx(&pdev->out_ctx)); in cdnsp_setup_device()
943 void cdnsp_set_usb2_hardware_lpm(struct cdnsp_device *pdev, in cdnsp_set_usb2_hardware_lpm() argument
947 if (pdev->active_port != &pdev->usb2_port || !pdev->gadget.lpm_capable) in cdnsp_set_usb2_hardware_lpm()
954 &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
956 writel(PORT_L1S_NYET, &pdev->active_port->regs->portpmsc); in cdnsp_set_usb2_hardware_lpm()
959 static int cdnsp_get_frame(struct cdnsp_device *pdev) in cdnsp_get_frame() argument
961 return readl(&pdev->run_regs->microframe_index) >> 3; in cdnsp_get_frame()
968 struct cdnsp_device *pdev; in cdnsp_gadget_ep_enable() local
979 pdev = pep->pdev; in cdnsp_gadget_ep_enable()
982 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, in cdnsp_gadget_ep_enable()
986 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
990 dev_err(pdev->dev, "ERROR: Bad endpoint number\n"); in cdnsp_gadget_ep_enable()
997 if (pdev->gadget.speed == USB_SPEED_FULL) { in cdnsp_gadget_ep_enable()
1006 dev_err(pdev->dev, "bInterval %d not supported\n", in cdnsp_gadget_ep_enable()
1011 cdnsp_set_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_gadget_ep_enable()
1014 ret = cdnsp_endpoint_init(pdev, pep, GFP_ATOMIC); in cdnsp_gadget_ep_enable()
1018 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_enable()
1022 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_enable()
1024 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_enable()
1033 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_enable()
1042 struct cdnsp_device *pdev; in cdnsp_gadget_ep_disable() local
1052 pdev = pep->pdev; in cdnsp_gadget_ep_disable()
1054 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1057 dev_err(pdev->dev, "%s is already disabled\n", pep->name); in cdnsp_gadget_ep_disable()
1066 cdnsp_cmd_stop_ep(pdev, pep); in cdnsp_gadget_ep_disable()
1074 cdnsp_invalidate_ep_events(pdev, pep); in cdnsp_gadget_ep_disable()
1078 ctrl_ctx = cdnsp_get_input_control_ctx(&pdev->in_ctx); in cdnsp_gadget_ep_disable()
1082 cdnsp_endpoint_zero(pdev, pep); in cdnsp_gadget_ep_disable()
1085 ret = cdnsp_update_eps_configuration(pdev, pep); in cdnsp_gadget_ep_disable()
1087 cdnsp_free_endpoint_rings(pdev, pep); in cdnsp_gadget_ep_disable()
1094 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_disable()
1131 struct cdnsp_device *pdev; in cdnsp_gadget_ep_queue() local
1140 pdev = pep->pdev; in cdnsp_gadget_ep_queue()
1143 dev_err(pdev->dev, "%s: can't queue to disabled endpoint\n", in cdnsp_gadget_ep_queue()
1149 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1151 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_queue()
1160 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_dequeue() local
1168 dev_err(pdev->dev, in cdnsp_gadget_ep_dequeue()
1178 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1180 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_dequeue()
1188 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_halt() local
1193 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1204 ret = cdnsp_halt_endpoint(pdev, pep, value); in cdnsp_gadget_ep_set_halt()
1207 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_halt()
1214 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_ep_set_wedge() local
1218 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1220 ret = cdnsp_halt_endpoint(pdev, pep, 1); in cdnsp_gadget_ep_set_wedge()
1221 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_ep_set_wedge()
1252 struct cdnsp_device *pdev = pep->pdev; in cdnsp_gadget_giveback() local
1259 usb_gadget_unmap_request_by_dev(pdev->dev, &preq->request, in cdnsp_gadget_giveback()
1264 if (preq != &pdev->ep0_preq) { in cdnsp_gadget_giveback()
1265 spin_unlock(&pdev->lock); in cdnsp_gadget_giveback()
1267 spin_lock(&pdev->lock); in cdnsp_gadget_giveback()
1277 static int cdnsp_run(struct cdnsp_device *pdev, in cdnsp_run() argument
1284 temp = readl(&pdev->ir_set->irq_control); in cdnsp_run()
1287 writel(temp, &pdev->ir_set->irq_control); in cdnsp_run()
1289 temp = readl(&pdev->port3x_regs->mode_addr); in cdnsp_run()
1304 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdnsp_run()
1314 writel(temp, &pdev->port3x_regs->mode_addr); in cdnsp_run()
1315 cdnsp_set_link_state(pdev, &pdev->usb3_port.regs->portsc, in cdnsp_run()
1318 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_run()
1321 cdnsp_set_link_state(pdev, &pdev->usb2_port.regs->portsc, in cdnsp_run()
1326 writel(PORT_REG6_L1_L0_HW_EN | fs_speed, &pdev->port20_regs->port_reg6); in cdnsp_run()
1328 ret = cdnsp_start(pdev); in cdnsp_run()
1334 temp = readl(&pdev->op_regs->command); in cdnsp_run()
1336 writel(temp, &pdev->op_regs->command); in cdnsp_run()
1338 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_run()
1339 writel(IMAN_IE_SET(temp), &pdev->ir_set->irq_pending); in cdnsp_run()
1344 cdnsp_halt(pdev); in cdnsp_run()
1352 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_start() local
1356 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1357 pdev->gadget_driver = driver; in cdnsp_gadget_udc_start()
1361 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_udc_start()
1363 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_start()
1373 void cdnsp_update_erst_dequeue(struct cdnsp_device *pdev, in cdnsp_update_erst_dequeue() argument
1380 temp_64 = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1383 if (event_ring_deq != pdev->event_ring->dequeue) { in cdnsp_update_erst_dequeue()
1384 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_update_erst_dequeue()
1385 pdev->event_ring->dequeue); in cdnsp_update_erst_dequeue()
1396 cdnsp_write_64(temp_64, &pdev->ir_set->erst_dequeue); in cdnsp_update_erst_dequeue()
1399 static void cdnsp_clear_cmd_ring(struct cdnsp_device *pdev) in cdnsp_clear_cmd_ring() argument
1405 cdnsp_initialize_ring_info(pdev->cmd_ring); in cdnsp_clear_cmd_ring()
1407 seg = pdev->cmd_ring->first_seg; in cdnsp_clear_cmd_ring()
1408 for (i = 0; i < pdev->cmd_ring->num_segs; i++) { in cdnsp_clear_cmd_ring()
1415 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1417 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_clear_cmd_ring()
1418 pdev->cmd_ring->cycle_state; in cdnsp_clear_cmd_ring()
1419 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_clear_cmd_ring()
1422 static void cdnsp_consume_all_events(struct cdnsp_device *pdev) in cdnsp_consume_all_events() argument
1429 event_ring_deq = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1430 event_deq_seg = pdev->event_ring->deq_seg; in cdnsp_consume_all_events()
1431 event = pdev->event_ring->dequeue; in cdnsp_consume_all_events()
1438 if (cycle_bit != pdev->event_ring->cycle_state) in cdnsp_consume_all_events()
1441 cdnsp_inc_deq(pdev, pdev->event_ring); in cdnsp_consume_all_events()
1448 if (cdnsp_last_trb_on_ring(pdev->event_ring, event_deq_seg, in cdnsp_consume_all_events()
1456 cdnsp_update_erst_dequeue(pdev, event_ring_deq, 1); in cdnsp_consume_all_events()
1459 static void cdnsp_stop(struct cdnsp_device *pdev) in cdnsp_stop() argument
1464 if (!list_empty(&pdev->eps[0].pending_list)) { in cdnsp_stop()
1467 req = next_request(&pdev->eps[0].pending_list); in cdnsp_stop()
1468 if (req == &pdev->ep0_preq) in cdnsp_stop()
1469 cdnsp_ep_dequeue(&pdev->eps[0], req); in cdnsp_stop()
1472 cdnsp_disable_port(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1473 cdnsp_disable_port(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1474 cdnsp_disable_slot(pdev); in cdnsp_stop()
1475 cdnsp_halt(pdev); in cdnsp_stop()
1477 temp = readl(&pdev->op_regs->status); in cdnsp_stop()
1478 writel((temp & ~0x1fff) | STS_EINT, &pdev->op_regs->status); in cdnsp_stop()
1479 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1480 writel(IMAN_IE_CLEAR(temp), &pdev->ir_set->irq_pending); in cdnsp_stop()
1482 cdnsp_clear_port_change_bit(pdev, &pdev->usb2_port.regs->portsc); in cdnsp_stop()
1483 cdnsp_clear_port_change_bit(pdev, &pdev->usb3_port.regs->portsc); in cdnsp_stop()
1486 temp = readl(&pdev->ir_set->irq_pending); in cdnsp_stop()
1488 writel(temp, &pdev->ir_set->irq_pending); in cdnsp_stop()
1490 cdnsp_consume_all_events(pdev); in cdnsp_stop()
1491 cdnsp_clear_cmd_ring(pdev); in cdnsp_stop()
1503 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_udc_stop() local
1506 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1507 cdnsp_stop(pdev); in cdnsp_gadget_udc_stop()
1508 pdev->gadget_driver = NULL; in cdnsp_gadget_udc_stop()
1509 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_udc_stop()
1516 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_get_frame() local
1518 return cdnsp_get_frame(pdev); in cdnsp_gadget_get_frame()
1521 static void __cdnsp_gadget_wakeup(struct cdnsp_device *pdev) in __cdnsp_gadget_wakeup() argument
1526 port_regs = pdev->active_port->regs; in __cdnsp_gadget_wakeup()
1530 if (pdev->gadget.speed < USB_SPEED_SUPER && portsc == XDEV_U2) { in __cdnsp_gadget_wakeup()
1537 if (portsc == XDEV_U3 && !pdev->may_wakeup) in __cdnsp_gadget_wakeup()
1540 cdnsp_set_link_state(pdev, &port_regs->portsc, XDEV_U0); in __cdnsp_gadget_wakeup()
1542 pdev->cdnsp_state |= CDNSP_WAKEUP_PENDING; in __cdnsp_gadget_wakeup()
1547 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_wakeup() local
1550 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1551 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_wakeup()
1552 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_wakeup()
1560 struct cdnsp_device *pdev = gadget_to_cdnsp(g); in cdnsp_gadget_set_selfpowered() local
1563 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1565 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_set_selfpowered()
1572 struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); in cdnsp_gadget_pullup() local
1573 struct cdns *cdns = dev_get_drvdata(pdev->dev); in cdnsp_gadget_pullup()
1583 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_pullup()
1586 cdnsp_reset_device(pdev); in cdnsp_gadget_pullup()
1592 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_pullup()
1607 static void cdnsp_get_ep_buffering(struct cdnsp_device *pdev, in cdnsp_get_ep_buffering() argument
1610 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_ep_buffering()
1623 endpoints = HCS_ENDPOINTS(pdev->hcs_params1) / 2; in cdnsp_get_ep_buffering()
1634 static int cdnsp_gadget_init_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_init_endpoints() argument
1636 int max_streams = HCC_MAX_PSA(pdev->hcc_params); in cdnsp_gadget_init_endpoints()
1640 INIT_LIST_HEAD(&pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1643 dev_err(pdev->dev, "Stream size %d not supported\n", in cdnsp_gadget_init_endpoints()
1654 if (!CDNSP_IF_EP_EXIST(pdev, epnum, direction)) in cdnsp_gadget_init_endpoints()
1657 pep = &pdev->eps[i]; in cdnsp_gadget_init_endpoints()
1658 pep->pdev = pdev; in cdnsp_gadget_init_endpoints()
1680 pdev->ep0_preq.epnum = pep->number; in cdnsp_gadget_init_endpoints()
1681 pdev->ep0_preq.pep = pep; in cdnsp_gadget_init_endpoints()
1682 pdev->gadget.ep0 = &pep->endpoint; in cdnsp_gadget_init_endpoints()
1693 &pdev->gadget.ep_list); in cdnsp_gadget_init_endpoints()
1704 pep->in_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1705 pep->out_ctx = cdnsp_get_ep_ctx(&pdev->out_ctx, pep->idx); in cdnsp_gadget_init_endpoints()
1706 cdnsp_get_ep_buffering(pdev, pep); in cdnsp_gadget_init_endpoints()
1708 dev_dbg(pdev->dev, "Init %s, MPS: %04x SupType: " in cdnsp_gadget_init_endpoints()
1725 static void cdnsp_gadget_free_endpoints(struct cdnsp_device *pdev) in cdnsp_gadget_free_endpoints() argument
1731 pep = &pdev->eps[i]; in cdnsp_gadget_free_endpoints()
1737 void cdnsp_disconnect_gadget(struct cdnsp_device *pdev) in cdnsp_disconnect_gadget() argument
1739 pdev->cdnsp_state |= CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1741 if (pdev->gadget_driver && pdev->gadget_driver->disconnect) { in cdnsp_disconnect_gadget()
1742 spin_unlock(&pdev->lock); in cdnsp_disconnect_gadget()
1743 pdev->gadget_driver->disconnect(&pdev->gadget); in cdnsp_disconnect_gadget()
1744 spin_lock(&pdev->lock); in cdnsp_disconnect_gadget()
1747 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdnsp_disconnect_gadget()
1748 usb_gadget_set_state(&pdev->gadget, USB_STATE_NOTATTACHED); in cdnsp_disconnect_gadget()
1750 pdev->cdnsp_state &= ~CDNSP_STATE_DISCONNECT_PENDING; in cdnsp_disconnect_gadget()
1753 void cdnsp_suspend_gadget(struct cdnsp_device *pdev) in cdnsp_suspend_gadget() argument
1755 if (pdev->gadget_driver && pdev->gadget_driver->suspend) { in cdnsp_suspend_gadget()
1756 spin_unlock(&pdev->lock); in cdnsp_suspend_gadget()
1757 pdev->gadget_driver->suspend(&pdev->gadget); in cdnsp_suspend_gadget()
1758 spin_lock(&pdev->lock); in cdnsp_suspend_gadget()
1762 void cdnsp_resume_gadget(struct cdnsp_device *pdev) in cdnsp_resume_gadget() argument
1764 if (pdev->gadget_driver && pdev->gadget_driver->resume) { in cdnsp_resume_gadget()
1765 spin_unlock(&pdev->lock); in cdnsp_resume_gadget()
1766 pdev->gadget_driver->resume(&pdev->gadget); in cdnsp_resume_gadget()
1767 spin_lock(&pdev->lock); in cdnsp_resume_gadget()
1771 void cdnsp_irq_reset(struct cdnsp_device *pdev) in cdnsp_irq_reset() argument
1775 cdnsp_reset_device(pdev); in cdnsp_irq_reset()
1777 port_regs = pdev->active_port->regs; in cdnsp_irq_reset()
1778 pdev->gadget.speed = cdnsp_port_speed(readl(port_regs)); in cdnsp_irq_reset()
1780 spin_unlock(&pdev->lock); in cdnsp_irq_reset()
1781 usb_gadget_udc_reset(&pdev->gadget, pdev->gadget_driver); in cdnsp_irq_reset()
1782 spin_lock(&pdev->lock); in cdnsp_irq_reset()
1784 switch (pdev->gadget.speed) { in cdnsp_irq_reset()
1788 pdev->gadget.ep0->maxpacket = 512; in cdnsp_irq_reset()
1793 pdev->gadget.ep0->maxpacket = 64; in cdnsp_irq_reset()
1797 dev_err(pdev->dev, "Unknown device speed\n"); in cdnsp_irq_reset()
1801 cdnsp_clear_chicken_bits_2(pdev, CHICKEN_XDMA_2_TP_CACHE_DIS); in cdnsp_irq_reset()
1802 cdnsp_setup_device(pdev, SETUP_CONTEXT_ONLY); in cdnsp_irq_reset()
1803 usb_gadget_set_state(&pdev->gadget, USB_STATE_DEFAULT); in cdnsp_irq_reset()
1806 static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) in cdnsp_get_rev_cap() argument
1808 void __iomem *reg = &pdev->cap_regs->hc_capbase; in cdnsp_get_rev_cap()
1811 pdev->rev_cap = reg; in cdnsp_get_rev_cap()
1813 pdev->rtl_revision = readl(&pdev->rev_cap->rtl_revision); in cdnsp_get_rev_cap()
1815 dev_info(pdev->dev, "Rev: %08x/%08x, eps: %08x, buff: %08x/%08x\n", in cdnsp_get_rev_cap()
1816 readl(&pdev->rev_cap->ctrl_revision), in cdnsp_get_rev_cap()
1817 readl(&pdev->rev_cap->rtl_revision), in cdnsp_get_rev_cap()
1818 readl(&pdev->rev_cap->ep_supported), in cdnsp_get_rev_cap()
1819 readl(&pdev->rev_cap->rx_buff_size), in cdnsp_get_rev_cap()
1820 readl(&pdev->rev_cap->tx_buff_size)); in cdnsp_get_rev_cap()
1823 static int cdnsp_gen_setup(struct cdnsp_device *pdev) in cdnsp_gen_setup() argument
1828 pdev->cap_regs = pdev->regs; in cdnsp_gen_setup()
1829 pdev->op_regs = pdev->regs + in cdnsp_gen_setup()
1830 HC_LENGTH(readl(&pdev->cap_regs->hc_capbase)); in cdnsp_gen_setup()
1831 pdev->run_regs = pdev->regs + in cdnsp_gen_setup()
1832 (readl(&pdev->cap_regs->run_regs_off) & RTSOFF_MASK); in cdnsp_gen_setup()
1835 pdev->hcs_params1 = readl(&pdev->cap_regs->hcs_params1); in cdnsp_gen_setup()
1836 pdev->hcc_params = readl(&pdev->cap_regs->hc_capbase); in cdnsp_gen_setup()
1837 pdev->hci_version = HC_VERSION(pdev->hcc_params); in cdnsp_gen_setup()
1838 pdev->hcc_params = readl(&pdev->cap_regs->hcc_params); in cdnsp_gen_setup()
1847 cdnsp_set_apb_timeout_value(pdev); in cdnsp_gen_setup()
1849 cdnsp_get_rev_cap(pdev); in cdnsp_gen_setup()
1852 ret = cdnsp_halt(pdev); in cdnsp_gen_setup()
1857 ret = cdnsp_reset(pdev); in cdnsp_gen_setup()
1865 if (HCC_64BIT_ADDR(pdev->hcc_params) && in cdnsp_gen_setup()
1866 !dma_set_mask(pdev->dev, DMA_BIT_MASK(64))) { in cdnsp_gen_setup()
1867 dev_dbg(pdev->dev, "Enabling 64-bit DMA addresses.\n"); in cdnsp_gen_setup()
1868 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(64)); in cdnsp_gen_setup()
1874 ret = dma_set_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1878 dev_dbg(pdev->dev, "Enabling 32-bit DMA addresses.\n"); in cdnsp_gen_setup()
1879 dma_set_coherent_mask(pdev->dev, DMA_BIT_MASK(32)); in cdnsp_gen_setup()
1882 spin_lock_init(&pdev->lock); in cdnsp_gen_setup()
1884 ret = cdnsp_mem_init(pdev); in cdnsp_gen_setup()
1893 reg = readl(&pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1895 writel(reg, &pdev->port3x_regs->mode_2); in cdnsp_gen_setup()
1902 struct cdnsp_device *pdev; in __cdnsp_gadget_init() local
1908 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); in __cdnsp_gadget_init()
1909 if (!pdev) in __cdnsp_gadget_init()
1914 cdns->gadget_dev = pdev; in __cdnsp_gadget_init()
1915 pdev->dev = cdns->dev; in __cdnsp_gadget_init()
1916 pdev->regs = cdns->dev_regs; in __cdnsp_gadget_init()
1934 pdev->gadget.ops = &cdnsp_gadget_ops; in __cdnsp_gadget_init()
1935 pdev->gadget.name = "cdnsp-gadget"; in __cdnsp_gadget_init()
1936 pdev->gadget.speed = USB_SPEED_UNKNOWN; in __cdnsp_gadget_init()
1937 pdev->gadget.sg_supported = 1; in __cdnsp_gadget_init()
1938 pdev->gadget.max_speed = max_speed; in __cdnsp_gadget_init()
1939 pdev->gadget.lpm_capable = 1; in __cdnsp_gadget_init()
1941 pdev->setup_buf = kzalloc(CDNSP_EP0_SETUP_SIZE, GFP_KERNEL); in __cdnsp_gadget_init()
1942 if (!pdev->setup_buf) in __cdnsp_gadget_init()
1949 pdev->gadget.quirk_ep_out_aligned_size = true; in __cdnsp_gadget_init()
1951 ret = cdnsp_gen_setup(pdev); in __cdnsp_gadget_init()
1953 dev_err(pdev->dev, "Generic initialization failed %d\n", ret); in __cdnsp_gadget_init()
1957 ret = cdnsp_gadget_init_endpoints(pdev); in __cdnsp_gadget_init()
1959 dev_err(pdev->dev, "failed to initialize endpoints\n"); in __cdnsp_gadget_init()
1963 ret = usb_add_gadget_udc(pdev->dev, &pdev->gadget); in __cdnsp_gadget_init()
1965 dev_err(pdev->dev, "failed to register udc\n"); in __cdnsp_gadget_init()
1969 ret = devm_request_threaded_irq(pdev->dev, cdns->dev_irq, in __cdnsp_gadget_init()
1972 dev_name(pdev->dev), pdev); in __cdnsp_gadget_init()
1979 usb_del_gadget_udc(&pdev->gadget); in __cdnsp_gadget_init()
1981 cdnsp_gadget_free_endpoints(pdev); in __cdnsp_gadget_init()
1983 cdnsp_halt(pdev); in __cdnsp_gadget_init()
1984 cdnsp_reset(pdev); in __cdnsp_gadget_init()
1985 cdnsp_mem_cleanup(pdev); in __cdnsp_gadget_init()
1987 kfree(pdev->setup_buf); in __cdnsp_gadget_init()
1989 kfree(pdev); in __cdnsp_gadget_init()
1996 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_exit() local
1998 devm_free_irq(pdev->dev, cdns->dev_irq, pdev); in cdnsp_gadget_exit()
2001 usb_del_gadget_udc(&pdev->gadget); in cdnsp_gadget_exit()
2002 cdnsp_gadget_free_endpoints(pdev); in cdnsp_gadget_exit()
2003 cdnsp_mem_cleanup(pdev); in cdnsp_gadget_exit()
2004 kfree(pdev); in cdnsp_gadget_exit()
2011 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_suspend() local
2014 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_suspend()
2017 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_suspend()
2018 cdnsp_disconnect_gadget(pdev); in cdnsp_gadget_suspend()
2019 cdnsp_stop(pdev); in cdnsp_gadget_suspend()
2020 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_suspend()
2027 struct cdnsp_device *pdev = cdns->gadget_dev; in cdnsp_gadget_resume() local
2032 if (!pdev->gadget_driver) in cdnsp_gadget_resume()
2035 spin_lock_irqsave(&pdev->lock, flags); in cdnsp_gadget_resume()
2036 max_speed = pdev->gadget_driver->max_speed; in cdnsp_gadget_resume()
2039 max_speed = min(max_speed, pdev->gadget.max_speed); in cdnsp_gadget_resume()
2041 ret = cdnsp_run(pdev, max_speed); in cdnsp_gadget_resume()
2043 if (pdev->link_state == XDEV_U3) in cdnsp_gadget_resume()
2044 __cdnsp_gadget_wakeup(pdev); in cdnsp_gadget_resume()
2046 spin_unlock_irqrestore(&pdev->lock, flags); in cdnsp_gadget_resume()