Commit fdba5aa5 authored by Felipe Balbi's avatar Felipe Balbi

usb: dwc3: remove our homebrew state mechanism

We can reuse the generic implementation via
our struct usb_gadget.
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 14cd592f
...@@ -494,12 +494,6 @@ enum dwc3_link_state { ...@@ -494,12 +494,6 @@ enum dwc3_link_state {
DWC3_LINK_STATE_MASK = 0x0f, DWC3_LINK_STATE_MASK = 0x0f,
}; };
enum dwc3_device_state {
DWC3_DEFAULT_STATE,
DWC3_ADDRESS_STATE,
DWC3_CONFIGURED_STATE,
};
/* TRB Length, PCM and Status */ /* TRB Length, PCM and Status */
#define DWC3_TRB_SIZE_MASK (0x00ffffff) #define DWC3_TRB_SIZE_MASK (0x00ffffff)
#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) #define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
...@@ -721,7 +715,6 @@ struct dwc3 { ...@@ -721,7 +715,6 @@ struct dwc3 {
enum dwc3_ep0_next ep0_next_event; enum dwc3_ep0_next ep0_next_event;
enum dwc3_ep0_state ep0state; enum dwc3_ep0_state ep0state;
enum dwc3_link_state link_state; enum dwc3_link_state link_state;
enum dwc3_device_state dev_state;
u16 isoch_delay; u16 isoch_delay;
u16 u2sel; u16 u2sel;
......
...@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, ...@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
u32 wIndex; u32 wIndex;
u32 reg; u32 reg;
int ret; int ret;
enum usb_device_state state;
wValue = le16_to_cpu(ctrl->wValue); wValue = le16_to_cpu(ctrl->wValue);
wIndex = le16_to_cpu(ctrl->wIndex); wIndex = le16_to_cpu(ctrl->wIndex);
recip = ctrl->bRequestType & USB_RECIP_MASK; recip = ctrl->bRequestType & USB_RECIP_MASK;
state = dwc->gadget.state;
switch (recip) { switch (recip) {
case USB_RECIP_DEVICE: case USB_RECIP_DEVICE:
...@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, ...@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
* default control pipe * default control pipe
*/ */
case USB_DEVICE_U1_ENABLE: case USB_DEVICE_U1_ENABLE:
if (dwc->dev_state != DWC3_CONFIGURED_STATE) if (state != USB_STATE_CONFIGURED)
return -EINVAL; return -EINVAL;
if (dwc->speed != DWC3_DSTS_SUPERSPEED) if (dwc->speed != DWC3_DSTS_SUPERSPEED)
return -EINVAL; return -EINVAL;
...@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, ...@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
break; break;
case USB_DEVICE_U2_ENABLE: case USB_DEVICE_U2_ENABLE:
if (dwc->dev_state != DWC3_CONFIGURED_STATE) if (state != USB_STATE_CONFIGURED)
return -EINVAL; return -EINVAL;
if (dwc->speed != DWC3_DSTS_SUPERSPEED) if (dwc->speed != DWC3_DSTS_SUPERSPEED)
return -EINVAL; return -EINVAL;
...@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc, ...@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
{ {
enum usb_device_state state = dwc->gadget.state;
u32 addr; u32 addr;
u32 reg; u32 reg;
...@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) ...@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
return -EINVAL; return -EINVAL;
} }
if (dwc->dev_state == DWC3_CONFIGURED_STATE) { if (state == USB_STATE_CONFIGURED) {
dev_dbg(dwc->dev, "trying to set address when configured\n"); dev_dbg(dwc->dev, "trying to set address when configured\n");
return -EINVAL; return -EINVAL;
} }
...@@ -512,13 +516,10 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) ...@@ -512,13 +516,10 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
reg |= DWC3_DCFG_DEVADDR(addr); reg |= DWC3_DCFG_DEVADDR(addr);
dwc3_writel(dwc->regs, DWC3_DCFG, reg); dwc3_writel(dwc->regs, DWC3_DCFG, reg);
if (addr) { if (addr)
dwc->dev_state = DWC3_ADDRESS_STATE;
usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
} else { else
dwc->dev_state = DWC3_DEFAULT_STATE;
usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
}
return 0; return 0;
} }
...@@ -535,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) ...@@ -535,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
{ {
enum usb_device_state state = dwc->gadget.state;
u32 cfg; u32 cfg;
int ret; int ret;
u32 reg; u32 reg;
...@@ -542,16 +544,15 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) ...@@ -542,16 +544,15 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
dwc->start_config_issued = false; dwc->start_config_issued = false;
cfg = le16_to_cpu(ctrl->wValue); cfg = le16_to_cpu(ctrl->wValue);
switch (dwc->dev_state) { switch (state) {
case DWC3_DEFAULT_STATE: case USB_STATE_DEFAULT:
return -EINVAL; return -EINVAL;
break; break;
case DWC3_ADDRESS_STATE: case USB_STATE_ADDRESS:
ret = dwc3_ep0_delegate_req(dwc, ctrl); ret = dwc3_ep0_delegate_req(dwc, ctrl);
/* if the cfg matches and the cfg is non zero */ /* if the cfg matches and the cfg is non zero */
if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
dwc->dev_state = DWC3_CONFIGURED_STATE;
usb_gadget_set_state(&dwc->gadget, usb_gadget_set_state(&dwc->gadget,
USB_STATE_CONFIGURED); USB_STATE_CONFIGURED);
...@@ -568,13 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) ...@@ -568,13 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
} }
break; break;
case DWC3_CONFIGURED_STATE: case USB_STATE_CONFIGURED:
ret = dwc3_ep0_delegate_req(dwc, ctrl); ret = dwc3_ep0_delegate_req(dwc, ctrl);
if (!cfg) { if (!cfg)
dwc->dev_state = DWC3_ADDRESS_STATE;
usb_gadget_set_state(&dwc->gadget, usb_gadget_set_state(&dwc->gadget,
USB_STATE_ADDRESS); USB_STATE_ADDRESS);
}
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -629,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req) ...@@ -629,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
{ {
struct dwc3_ep *dep; struct dwc3_ep *dep;
enum usb_device_state state = dwc->gadget.state;
u16 wLength; u16 wLength;
u16 wValue; u16 wValue;
if (dwc->dev_state == DWC3_DEFAULT_STATE) if (state == USB_STATE_DEFAULT)
return -EINVAL; return -EINVAL;
wValue = le16_to_cpu(ctrl->wValue); wValue = le16_to_cpu(ctrl->wValue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment