aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2013-01-25 04:28:19 -0500
committerFelipe Balbi <balbi@ti.com>2013-03-18 05:17:13 -0400
commitfdba5aa54cfca795b73e50d45f617a0498a29af7 (patch)
treed501be94dcc5f904c684c3e09f22d049c882670f /drivers/usb/dwc3
parent14cd592f72ea1ce1a25d7a576a5ed6aa761456bc (diff)
usb: dwc3: remove our homebrew state mechanism
We can reuse the generic implementation via our struct usb_gadget. Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3')
-rw-r--r--drivers/usb/dwc3/core.h7
-rw-r--r--drivers/usb/dwc3/ep0.c34
2 files changed, 17 insertions, 24 deletions
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index cdd70cb78aa4..d8c36fccce96 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -494,12 +494,6 @@ enum dwc3_link_state {
494 DWC3_LINK_STATE_MASK = 0x0f, 494 DWC3_LINK_STATE_MASK = 0x0f,
495}; 495};
496 496
497enum dwc3_device_state {
498 DWC3_DEFAULT_STATE,
499 DWC3_ADDRESS_STATE,
500 DWC3_CONFIGURED_STATE,
501};
502
503/* TRB Length, PCM and Status */ 497/* TRB Length, PCM and Status */
504#define DWC3_TRB_SIZE_MASK (0x00ffffff) 498#define DWC3_TRB_SIZE_MASK (0x00ffffff)
505#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) 499#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
@@ -721,7 +715,6 @@ struct dwc3 {
721 enum dwc3_ep0_next ep0_next_event; 715 enum dwc3_ep0_next ep0_next_event;
722 enum dwc3_ep0_state ep0state; 716 enum dwc3_ep0_state ep0state;
723 enum dwc3_link_state link_state; 717 enum dwc3_link_state link_state;
724 enum dwc3_device_state dev_state;
725 718
726 u16 isoch_delay; 719 u16 isoch_delay;
727 u16 u2sel; 720 u16 u2sel;
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 2a82b7145052..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 }
@@ -512,13 +516,10 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
512 reg |= DWC3_DCFG_DEVADDR(addr); 516 reg |= DWC3_DCFG_DEVADDR(addr);
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;
517 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); 520 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
518 } else { 521 else
519 dwc->dev_state = DWC3_DEFAULT_STATE;
520 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); 522 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
521 }
522 523
523 return 0; 524 return 0;
524} 525}
@@ -535,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
535 536
536static 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)
537{ 538{
539 enum usb_device_state state = dwc->gadget.state;
538 u32 cfg; 540 u32 cfg;
539 int ret; 541 int ret;
540 u32 reg; 542 u32 reg;
@@ -542,16 +544,15 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
542 dwc->start_config_issued = false; 544 dwc->start_config_issued = false;
543 cfg = le16_to_cpu(ctrl->wValue); 545 cfg = le16_to_cpu(ctrl->wValue);
544 546
545 switch (dwc->dev_state) { 547 switch (state) {
546 case DWC3_DEFAULT_STATE: 548 case USB_STATE_DEFAULT:
547 return -EINVAL; 549 return -EINVAL;
548 break; 550 break;
549 551
550 case DWC3_ADDRESS_STATE: 552 case USB_STATE_ADDRESS:
551 ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 ret = dwc3_ep0_delegate_req(dwc, ctrl);
552 /* if the cfg matches and the cfg is non zero */ 554 /* if the cfg matches and the cfg is non zero */
553 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 555 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
554 dwc->dev_state = DWC3_CONFIGURED_STATE;
555 usb_gadget_set_state(&dwc->gadget, 556 usb_gadget_set_state(&dwc->gadget,
556 USB_STATE_CONFIGURED); 557 USB_STATE_CONFIGURED);
557 558
@@ -568,13 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
568 } 569 }
569 break; 570 break;
570 571
571 case DWC3_CONFIGURED_STATE: 572 case USB_STATE_CONFIGURED:
572 ret = dwc3_ep0_delegate_req(dwc, ctrl); 573 ret = dwc3_ep0_delegate_req(dwc, ctrl);
573 if (!cfg) { 574 if (!cfg)
574 dwc->dev_state = DWC3_ADDRESS_STATE;
575 usb_gadget_set_state(&dwc->gadget, 575 usb_gadget_set_state(&dwc->gadget,
576 USB_STATE_ADDRESS); 576 USB_STATE_ADDRESS);
577 }
578 break; 577 break;
579 default: 578 default:
580 ret = -EINVAL; 579 ret = -EINVAL;
@@ -629,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
629static 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)
630{ 629{
631 struct dwc3_ep *dep; 630 struct dwc3_ep *dep;
631 enum usb_device_state state = dwc->gadget.state;
632 u16 wLength; 632 u16 wLength;
633 u16 wValue; 633 u16 wValue;
634 634
635 if (dwc->dev_state == DWC3_DEFAULT_STATE) 635 if (state == USB_STATE_DEFAULT)
636 return -EINVAL; 636 return -EINVAL;
637 637
638 wValue = le16_to_cpu(ctrl->wValue); 638 wValue = le16_to_cpu(ctrl->wValue);