usb: dwc3: gadget: implement gadget state tracking
authorFelipe Balbi <balbi@ti.com>
Mon, 19 Dec 2011 11:01:52 +0000 (13:01 +0200)
committerFelipe Balbi <balbi@ti.com>
Mon, 18 Mar 2013 09:17:12 +0000 (11:17 +0200)
make use of the previously introduced gadget->state
field.

Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/dwc3/ep0.c
drivers/usb/dwc3/gadget.c

index 1d139ca05ef17bdd56cdfa3ba9027ea70c337d88..2a82b7145052d65c0d959431a0c2a2f7eb4f02d2 100644 (file)
@@ -512,10 +512,13 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
        reg |= DWC3_DCFG_DEVADDR(addr);
        dwc3_writel(dwc->regs, DWC3_DCFG, reg);
 
-       if (addr)
+       if (addr) {
                dwc->dev_state = DWC3_ADDRESS_STATE;
-       else
+               usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
+       } else {
                dwc->dev_state = DWC3_DEFAULT_STATE;
+               usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
+       }
 
        return 0;
 }
@@ -549,6 +552,9 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
                /* if the cfg matches and the cfg is non zero */
                if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
                        dwc->dev_state = DWC3_CONFIGURED_STATE;
+                       usb_gadget_set_state(&dwc->gadget,
+                                       USB_STATE_CONFIGURED);
+
                        /*
                         * Enable transition to U1/U2 state when
                         * nothing is pending from application.
@@ -564,8 +570,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
 
        case DWC3_CONFIGURED_STATE:
                ret = dwc3_ep0_delegate_req(dwc, ctrl);
-               if (!cfg)
+               if (!cfg) {
                        dwc->dev_state = DWC3_ADDRESS_STATE;
+                       usb_gadget_set_state(&dwc->gadget,
+                                       USB_STATE_ADDRESS);
+               }
                break;
        default:
                ret = -EINVAL;
index 742eb8268e9aefa1a1cf53fcf1bdb8cbd308a0b3..2686bf26ccafb3ec6662bcbee60a83806a62a439 100644 (file)
@@ -2137,7 +2137,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
        }
 
        /* after reset -> Default State */
-       dwc->dev_state = DWC3_DEFAULT_STATE;
+       usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
 
        /* Recent versions support automatic phy suspend and don't need this */
        if (dwc->revision < DWC3_REVISION_194A) {