aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3/ep0.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc3/ep0.c')
-rw-r--r--drivers/usb/dwc3/ep0.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1d139ca05ef1..5acbb948b704 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
394 u32 wIndex; 394 u32 wIndex;
395 u32 reg; 395 u32 reg;
396 int ret; 396 int ret;
397 enum usb_device_state state;
397 398
398 wValue = le16_to_cpu(ctrl->wValue); 399 wValue = le16_to_cpu(ctrl->wValue);
399 wIndex = le16_to_cpu(ctrl->wIndex); 400 wIndex = le16_to_cpu(ctrl->wIndex);
400 recip = ctrl->bRequestType & USB_RECIP_MASK; 401 recip = ctrl->bRequestType & USB_RECIP_MASK;
402 state = dwc->gadget.state;
403
401 switch (recip) { 404 switch (recip) {
402 case USB_RECIP_DEVICE: 405 case USB_RECIP_DEVICE:
403 406
@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
409 * default control pipe 412 * default control pipe
410 */ 413 */
411 case USB_DEVICE_U1_ENABLE: 414 case USB_DEVICE_U1_ENABLE:
412 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 415 if (state != USB_STATE_CONFIGURED)
413 return -EINVAL; 416 return -EINVAL;
414 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 417 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
415 return -EINVAL; 418 return -EINVAL;
@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
423 break; 426 break;
424 427
425 case USB_DEVICE_U2_ENABLE: 428 case USB_DEVICE_U2_ENABLE:
426 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 429 if (state != USB_STATE_CONFIGURED)
427 return -EINVAL; 430 return -EINVAL;
428 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 431 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
429 return -EINVAL; 432 return -EINVAL;
@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
493 496
494static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 497static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
495{ 498{
499 enum usb_device_state state = dwc->gadget.state;
496 u32 addr; 500 u32 addr;
497 u32 reg; 501 u32 reg;
498 502
@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
502 return -EINVAL; 506 return -EINVAL;
503 } 507 }
504 508
505 if (dwc->dev_state == DWC3_CONFIGURED_STATE) { 509 if (state == USB_STATE_CONFIGURED) {
506 dev_dbg(dwc->dev, "trying to set address when configured\n"); 510 dev_dbg(dwc->dev, "trying to set address when configured\n");
507 return -EINVAL; 511 return -EINVAL;
508 } 512 }
@@ -513,9 +517,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
513 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 517 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
514 518
515 if (addr) 519 if (addr)
516 dwc->dev_state = DWC3_ADDRESS_STATE; 520 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
517 else 521 else
518 dwc->dev_state = DWC3_DEFAULT_STATE; 522 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
519 523
520 return 0; 524 return 0;
521} 525}
@@ -532,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
532 536
533static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 537static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
534{ 538{
539 enum usb_device_state state = dwc->gadget.state;
535 u32 cfg; 540 u32 cfg;
536 int ret; 541 int ret;
537 u32 reg; 542 u32 reg;
@@ -539,16 +544,18 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
539 dwc->start_config_issued = false; 544 dwc->start_config_issued = false;
540 cfg = le16_to_cpu(ctrl->wValue); 545 cfg = le16_to_cpu(ctrl->wValue);
541 546
542 switch (dwc->dev_state) { 547 switch (state) {
543 case DWC3_DEFAULT_STATE: 548 case USB_STATE_DEFAULT:
544 return -EINVAL; 549 return -EINVAL;
545 break; 550 break;
546 551
547 case DWC3_ADDRESS_STATE: 552 case USB_STATE_ADDRESS:
548 ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 ret = dwc3_ep0_delegate_req(dwc, ctrl);
549 /* if the cfg matches and the cfg is non zero */ 554 /* if the cfg matches and the cfg is non zero */
550 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 555 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
551 dwc->dev_state = DWC3_CONFIGURED_STATE; 556 usb_gadget_set_state(&dwc->gadget,
557 USB_STATE_CONFIGURED);
558
552 /* 559 /*
553 * Enable transition to U1/U2 state when 560 * Enable transition to U1/U2 state when
554 * nothing is pending from application. 561 * nothing is pending from application.
@@ -562,10 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
562 } 569 }
563 break; 570 break;
564 571
565 case DWC3_CONFIGURED_STATE: 572 case USB_STATE_CONFIGURED:
566 ret = dwc3_ep0_delegate_req(dwc, ctrl); 573 ret = dwc3_ep0_delegate_req(dwc, ctrl);
567 if (!cfg) 574 if (!cfg)
568 dwc->dev_state = DWC3_ADDRESS_STATE; 575 usb_gadget_set_state(&dwc->gadget,
576 USB_STATE_ADDRESS);
569 break; 577 break;
570 default: 578 default:
571 ret = -EINVAL; 579 ret = -EINVAL;
@@ -620,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
620static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 628static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
621{ 629{
622 struct dwc3_ep *dep; 630 struct dwc3_ep *dep;
631 enum usb_device_state state = dwc->gadget.state;
623 u16 wLength; 632 u16 wLength;
624 u16 wValue; 633 u16 wValue;
625 634
626 if (dwc->dev_state == DWC3_DEFAULT_STATE) 635 if (state == USB_STATE_DEFAULT)
627 return -EINVAL; 636 return -EINVAL;
628 637
629 wValue = le16_to_cpu(ctrl->wValue); 638 wValue = le16_to_cpu(ctrl->wValue);