Lines Matching refs:priv_dev
34 static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, in cdns3_ep0_run_transfer() argument
38 struct cdns3_usb_regs __iomem *regs = priv_dev->regs; in cdns3_ep0_run_transfer()
39 struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; in cdns3_ep0_run_transfer()
58 cdns3_select_ep(priv_dev, priv_dev->ep0_data_dir); in cdns3_ep0_run_transfer()
62 trace_cdns3_doorbell_ep0(priv_dev->ep0_data_dir ? "ep0in" : "ep0out", in cdns3_ep0_run_transfer()
69 __cdns3_gadget_wakeup(priv_dev); in cdns3_ep0_run_transfer()
72 writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); in cdns3_ep0_run_transfer()
83 static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev, in cdns3_ep0_delegate_req() argument
88 spin_unlock(&priv_dev->lock); in cdns3_ep0_delegate_req()
89 priv_dev->setup_pending = 1; in cdns3_ep0_delegate_req()
90 ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req); in cdns3_ep0_delegate_req()
91 priv_dev->setup_pending = 0; in cdns3_ep0_delegate_req()
92 spin_lock(&priv_dev->lock); in cdns3_ep0_delegate_req()
96 static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) in cdns3_prepare_setup_packet() argument
98 priv_dev->ep0_data_dir = 0; in cdns3_prepare_setup_packet()
99 priv_dev->ep0_stage = CDNS3_SETUP_STAGE; in cdns3_prepare_setup_packet()
100 cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, in cdns3_prepare_setup_packet()
104 static void cdns3_ep0_complete_setup(struct cdns3_device *priv_dev, in cdns3_ep0_complete_setup() argument
107 struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; in cdns3_ep0_complete_setup()
117 cdns3_select_ep(priv_dev, 0x00); in cdns3_ep0_complete_setup()
118 writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); in cdns3_ep0_complete_setup()
120 cdns3_prepare_setup_packet(priv_dev); in cdns3_ep0_complete_setup()
123 priv_dev->ep0_stage = CDNS3_SETUP_STAGE; in cdns3_ep0_complete_setup()
125 &priv_dev->regs->ep_cmd); in cdns3_ep0_complete_setup()
136 static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev, in cdns3_req_ep0_set_configuration() argument
139 enum usb_device_state device_state = priv_dev->gadget.state; in cdns3_req_ep0_set_configuration()
145 result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); in cdns3_req_ep0_set_configuration()
152 result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); in cdns3_req_ep0_set_configuration()
165 cdns3_hw_reset_eps_config(priv_dev); in cdns3_req_ep0_set_configuration()
167 usb_gadget_set_state(&priv_dev->gadget, in cdns3_req_ep0_set_configuration()
180 static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev, in cdns3_req_ep0_set_address() argument
183 enum usb_device_state device_state = priv_dev->gadget.state; in cdns3_req_ep0_set_address()
190 dev_err(priv_dev->dev, in cdns3_req_ep0_set_address()
197 dev_err(priv_dev->dev, in cdns3_req_ep0_set_address()
202 reg = readl(&priv_dev->regs->usb_cmd); in cdns3_req_ep0_set_address()
205 &priv_dev->regs->usb_cmd); in cdns3_req_ep0_set_address()
207 usb_gadget_set_state(&priv_dev->gadget, in cdns3_req_ep0_set_address()
220 static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, in cdns3_req_ep0_get_status() argument
234 if (priv_dev->is_selfpowered) in cdns3_req_ep0_get_status()
237 if (priv_dev->wake_up_flag) in cdns3_req_ep0_get_status()
240 if (priv_dev->gadget.speed != USB_SPEED_SUPER) in cdns3_req_ep0_get_status()
243 if (priv_dev->u1_allowed) in cdns3_req_ep0_get_status()
246 if (priv_dev->u2_allowed) in cdns3_req_ep0_get_status()
251 return cdns3_ep0_delegate_req(priv_dev, ctrl); in cdns3_req_ep0_get_status()
254 priv_ep = priv_dev->eps[index]; in cdns3_req_ep0_get_status()
257 cdns3_select_ep(priv_dev, le16_to_cpu(ctrl->wIndex)); in cdns3_req_ep0_get_status()
258 if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts)) || in cdns3_req_ep0_get_status()
266 response_pkt = (__le16 *)priv_dev->setup_buf; in cdns3_req_ep0_get_status()
269 cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, in cdns3_req_ep0_get_status()
274 static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, in cdns3_ep0_feature_handle_device() argument
285 state = priv_dev->gadget.state; in cdns3_ep0_feature_handle_device()
286 speed = priv_dev->gadget.speed; in cdns3_ep0_feature_handle_device()
290 priv_dev->wake_up_flag = !!set; in cdns3_ep0_feature_handle_device()
296 priv_dev->u1_allowed = !!set; in cdns3_ep0_feature_handle_device()
302 priv_dev->u2_allowed = !!set; in cdns3_ep0_feature_handle_device()
322 cdns3_set_register_bit(&priv_dev->regs->usb_cmd, in cdns3_ep0_feature_handle_device()
337 static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev, in cdns3_ep0_feature_handle_intf() argument
356 static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev, in cdns3_ep0_feature_handle_endpoint() argument
371 priv_ep = priv_dev->eps[index]; in cdns3_ep0_feature_handle_endpoint()
373 cdns3_select_ep(priv_dev, le16_to_cpu(ctrl->wIndex)); in cdns3_ep0_feature_handle_endpoint()
380 cdns3_select_ep(priv_dev, 0x00); in cdns3_ep0_feature_handle_endpoint()
395 static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev, in cdns3_req_ep0_handle_feature() argument
406 ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set); in cdns3_req_ep0_handle_feature()
409 ret = cdns3_ep0_feature_handle_intf(priv_dev, ctrl, set); in cdns3_req_ep0_handle_feature()
412 ret = cdns3_ep0_feature_handle_endpoint(priv_dev, ctrl, set); in cdns3_req_ep0_handle_feature()
428 static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev, in cdns3_req_ep0_set_sel() argument
431 if (priv_dev->gadget.state < USB_STATE_ADDRESS) in cdns3_req_ep0_set_sel()
435 dev_err(priv_dev->dev, "Set SEL should be 6 bytes, got %d\n", in cdns3_req_ep0_set_sel()
440 cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1, 0); in cdns3_req_ep0_set_sel()
452 static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev, in cdns3_req_ep0_set_isoch_delay() argument
458 priv_dev->isoch_delay = le16_to_cpu(ctrl_req->wValue); in cdns3_req_ep0_set_isoch_delay()
470 static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev, in cdns3_ep0_standard_request() argument
477 ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
480 ret = cdns3_req_ep0_set_configuration(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
483 ret = cdns3_req_ep0_get_status(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
486 ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 0); in cdns3_ep0_standard_request()
489 ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 1); in cdns3_ep0_standard_request()
492 ret = cdns3_req_ep0_set_sel(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
495 ret = cdns3_req_ep0_set_isoch_delay(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
498 ret = cdns3_ep0_delegate_req(priv_dev, ctrl_req); in cdns3_ep0_standard_request()
505 static void __pending_setup_status_handler(struct cdns3_device *priv_dev) in __pending_setup_status_handler() argument
507 struct usb_request *request = priv_dev->pending_status_request; in __pending_setup_status_handler()
509 if (priv_dev->status_completion_no_call && request && in __pending_setup_status_handler()
511 request->complete(&priv_dev->eps[0]->endpoint, request); in __pending_setup_status_handler()
512 priv_dev->status_completion_no_call = 0; in __pending_setup_status_handler()
518 struct cdns3_device *priv_dev = container_of(work, struct cdns3_device, in cdns3_pending_setup_status_handler() local
522 spin_lock_irqsave(&priv_dev->lock, flags); in cdns3_pending_setup_status_handler()
523 __pending_setup_status_handler(priv_dev); in cdns3_pending_setup_status_handler()
524 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_pending_setup_status_handler()
531 static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) in cdns3_ep0_setup_phase() argument
533 struct usb_ctrlrequest *ctrl = priv_dev->setup_buf; in cdns3_ep0_setup_phase()
534 struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; in cdns3_ep0_setup_phase()
537 priv_dev->ep0_data_dir = ctrl->bRequestType & USB_DIR_IN; in cdns3_ep0_setup_phase()
545 priv_ep->dir = priv_dev->ep0_data_dir; in cdns3_ep0_setup_phase()
551 priv_dev->ep0_stage = CDNS3_DATA_STAGE; in cdns3_ep0_setup_phase()
553 priv_dev->ep0_stage = CDNS3_STATUS_STAGE; in cdns3_ep0_setup_phase()
556 result = cdns3_ep0_standard_request(priv_dev, ctrl); in cdns3_ep0_setup_phase()
558 result = cdns3_ep0_delegate_req(priv_dev, ctrl); in cdns3_ep0_setup_phase()
564 cdns3_ep0_complete_setup(priv_dev, 1, 1); in cdns3_ep0_setup_phase()
565 else if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) in cdns3_ep0_setup_phase()
566 cdns3_ep0_complete_setup(priv_dev, 0, 1); in cdns3_ep0_setup_phase()
569 static void cdns3_transfer_completed(struct cdns3_device *priv_dev) in cdns3_transfer_completed() argument
571 struct cdns3_endpoint *priv_ep = priv_dev->eps[0]; in cdns3_transfer_completed()
582 priv_ep->dir = priv_dev->ep0_data_dir; in cdns3_transfer_completed()
586 cdns3_ep0_complete_setup(priv_dev, 0, 0); in cdns3_transfer_completed()
595 static bool cdns3_check_new_setup(struct cdns3_device *priv_dev) in cdns3_check_new_setup() argument
599 cdns3_select_ep(priv_dev, USB_DIR_OUT); in cdns3_check_new_setup()
600 ep_sts_reg = readl(&priv_dev->regs->ep_sts); in cdns3_check_new_setup()
610 void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir) in cdns3_check_ep0_interrupt_proceed() argument
614 cdns3_select_ep(priv_dev, dir); in cdns3_check_ep0_interrupt_proceed()
616 ep_sts_reg = readl(&priv_dev->regs->ep_sts); in cdns3_check_ep0_interrupt_proceed()
617 writel(ep_sts_reg, &priv_dev->regs->ep_sts); in cdns3_check_ep0_interrupt_proceed()
619 trace_cdns3_ep0_irq(priv_dev, ep_sts_reg); in cdns3_check_ep0_interrupt_proceed()
621 __pending_setup_status_handler(priv_dev); in cdns3_check_ep0_interrupt_proceed()
624 priv_dev->wait_for_setup = 1; in cdns3_check_ep0_interrupt_proceed()
626 if (priv_dev->wait_for_setup && ep_sts_reg & EP_STS_IOC) { in cdns3_check_ep0_interrupt_proceed()
627 priv_dev->wait_for_setup = 0; in cdns3_check_ep0_interrupt_proceed()
628 cdns3_ep0_setup_phase(priv_dev); in cdns3_check_ep0_interrupt_proceed()
630 priv_dev->ep0_data_dir = dir; in cdns3_check_ep0_interrupt_proceed()
631 cdns3_transfer_completed(priv_dev); in cdns3_check_ep0_interrupt_proceed()
635 if (dir == 0 && !priv_dev->setup_pending) in cdns3_check_ep0_interrupt_proceed()
636 cdns3_prepare_setup_packet(priv_dev); in cdns3_check_ep0_interrupt_proceed()
692 struct cdns3_device *priv_dev = priv_ep->cdns3_dev; in cdns3_gadget_ep0_queue() local
698 spin_lock_irqsave(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
699 trace_cdns3_ep0_queue(priv_dev, request); in cdns3_gadget_ep0_queue()
702 if (cdns3_check_new_setup(priv_dev)) { in cdns3_gadget_ep0_queue()
703 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
708 if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) { in cdns3_gadget_ep0_queue()
711 cdns3_select_ep(priv_dev, 0x00); in cdns3_gadget_ep0_queue()
717 priv_ep = priv_dev->eps[i]; in cdns3_gadget_ep0_queue()
723 cdns3_set_hw_configuration(priv_dev); in cdns3_gadget_ep0_queue()
724 cdns3_ep0_complete_setup(priv_dev, 0, 1); in cdns3_gadget_ep0_queue()
726 ret = readl_poll_timeout_atomic(&priv_dev->regs->usb_sts, val, in cdns3_gadget_ep0_queue()
729 dev_warn(priv_dev->dev, "timeout for waiting configuration set\n"); in cdns3_gadget_ep0_queue()
732 priv_dev->status_completion_no_call = true; in cdns3_gadget_ep0_queue()
733 priv_dev->pending_status_request = request; in cdns3_gadget_ep0_queue()
734 usb_gadget_set_state(&priv_dev->gadget, USB_STATE_CONFIGURED); in cdns3_gadget_ep0_queue()
735 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
742 queue_work(system_freezable_wq, &priv_dev->pending_status_wq); in cdns3_gadget_ep0_queue()
747 dev_err(priv_dev->dev, in cdns3_gadget_ep0_queue()
749 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
753 ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, in cdns3_gadget_ep0_queue()
754 priv_dev->ep0_data_dir); in cdns3_gadget_ep0_queue()
756 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
757 dev_err(priv_dev->dev, "failed to map request\n"); in cdns3_gadget_ep0_queue()
768 cdns3_ep0_run_transfer(priv_dev, request->dma, request->length, 1, zlp); in cdns3_gadget_ep0_queue()
770 spin_unlock_irqrestore(&priv_dev->lock, flags); in cdns3_gadget_ep0_queue()
784 struct cdns3_device *priv_dev = priv_ep->cdns3_dev; in cdns3_gadget_ep_set_wedge() local
786 dev_dbg(priv_dev->dev, "Wedge for %s\n", ep->name); in cdns3_gadget_ep_set_wedge()
810 void cdns3_ep0_config(struct cdns3_device *priv_dev) in cdns3_ep0_config() argument
817 regs = priv_dev->regs; in cdns3_ep0_config()
819 if (priv_dev->gadget.speed == USB_SPEED_SUPER) in cdns3_ep0_config()
822 priv_ep = priv_dev->eps[0]; in cdns3_ep0_config()
831 priv_dev->u1_allowed = 0; in cdns3_ep0_config()
832 priv_dev->u2_allowed = 0; in cdns3_ep0_config()
834 priv_dev->gadget.ep0->maxpacket = max_packet_size; in cdns3_ep0_config()
838 cdns3_select_ep(priv_dev, USB_DIR_OUT); in cdns3_ep0_config()
840 if (priv_dev->dev_ver >= DEV_VER_V3) { in cdns3_ep0_config()
841 cdns3_set_register_bit(&priv_dev->regs->dtrans, in cdns3_ep0_config()
843 cdns3_set_register_bit(&priv_dev->regs->tdl_from_trb, in cdns3_ep0_config()
856 cdns3_select_ep(priv_dev, USB_DIR_IN); in cdns3_ep0_config()
875 int cdns3_init_ep0(struct cdns3_device *priv_dev, in cdns3_init_ep0() argument
891 priv_dev->gadget.ep0 = &priv_ep->endpoint; in cdns3_init_ep0()