Commit d7be2952 authored by Felipe Balbi's avatar Felipe Balbi

usb: dwc3: gadget: re-factor ->udc_start and ->udc_stop

we will be re-using it for suspend/resume, so
instead of duplicating code, let's just re-factor
the functions so they can be re-used.
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 5185c913
...@@ -1616,37 +1616,12 @@ static void dwc3_gadget_disable_irq(struct dwc3 *dwc) ...@@ -1616,37 +1616,12 @@ static void dwc3_gadget_disable_irq(struct dwc3 *dwc)
static irqreturn_t dwc3_interrupt(int irq, void *_dwc); static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc); static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
static int dwc3_gadget_start(struct usb_gadget *g, static int __dwc3_gadget_start(struct dwc3 *dwc)
struct usb_gadget_driver *driver)
{ {
struct dwc3 *dwc = gadget_to_dwc(g);
struct dwc3_ep *dep; struct dwc3_ep *dep;
unsigned long flags;
int ret = 0; int ret = 0;
int irq;
u32 reg; u32 reg;
irq = platform_get_irq(to_platform_device(dwc->dev), 0);
ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
IRQF_SHARED, "dwc3", dwc->ev_buf);
if (ret) {
dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
irq, ret);
goto err0;
}
spin_lock_irqsave(&dwc->lock, flags);
if (dwc->gadget_driver) {
dev_err(dwc->dev, "%s is already bound to %s\n",
dwc->gadget.name,
dwc->gadget_driver->driver.name);
ret = -EBUSY;
goto err1;
}
dwc->gadget_driver = driver;
reg = dwc3_readl(dwc->regs, DWC3_DCFG); reg = dwc3_readl(dwc->regs, DWC3_DCFG);
reg &= ~(DWC3_DCFG_SPEED_MASK); reg &= ~(DWC3_DCFG_SPEED_MASK);
...@@ -1709,7 +1684,7 @@ static int dwc3_gadget_start(struct usb_gadget *g, ...@@ -1709,7 +1684,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
false); false);
if (ret) { if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name); dev_err(dwc->dev, "failed to enable %s\n", dep->name);
goto err2; goto err0;
} }
dep = dwc->eps[1]; dep = dwc->eps[1];
...@@ -1717,7 +1692,7 @@ static int dwc3_gadget_start(struct usb_gadget *g, ...@@ -1717,7 +1692,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
false); false);
if (ret) { if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name); dev_err(dwc->dev, "failed to enable %s\n", dep->name);
goto err3; goto err1;
} }
/* begin to receive SETUP packets */ /* begin to receive SETUP packets */
...@@ -1726,39 +1701,72 @@ static int dwc3_gadget_start(struct usb_gadget *g, ...@@ -1726,39 +1701,72 @@ static int dwc3_gadget_start(struct usb_gadget *g,
dwc3_gadget_enable_irq(dwc); dwc3_gadget_enable_irq(dwc);
spin_unlock_irqrestore(&dwc->lock, flags);
return 0; return 0;
err3:
__dwc3_gadget_ep_disable(dwc->eps[0]);
err2:
dwc->gadget_driver = NULL;
err1: err1:
spin_unlock_irqrestore(&dwc->lock, flags); __dwc3_gadget_ep_disable(dwc->eps[0]);
free_irq(irq, dwc->ev_buf);
err0: err0:
return ret; return ret;
} }
static int dwc3_gadget_stop(struct usb_gadget *g) static int dwc3_gadget_start(struct usb_gadget *g,
struct usb_gadget_driver *driver)
{ {
struct dwc3 *dwc = gadget_to_dwc(g); struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long flags; unsigned long flags;
int ret = 0;
int irq; int irq;
irq = platform_get_irq(to_platform_device(dwc->dev), 0);
ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
IRQF_SHARED, "dwc3", dwc->ev_buf);
if (ret) {
dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
irq, ret);
goto err0;
}
spin_lock_irqsave(&dwc->lock, flags); spin_lock_irqsave(&dwc->lock, flags);
if (dwc->gadget_driver) {
dev_err(dwc->dev, "%s is already bound to %s\n",
dwc->gadget.name,
dwc->gadget_driver->driver.name);
ret = -EBUSY;
goto err1;
}
dwc->gadget_driver = driver;
__dwc3_gadget_start(dwc);
spin_unlock_irqrestore(&dwc->lock, flags);
return 0;
err1:
spin_unlock_irqrestore(&dwc->lock, flags);
free_irq(irq, dwc);
err0:
return ret;
}
static void __dwc3_gadget_stop(struct dwc3 *dwc)
{
dwc3_gadget_disable_irq(dwc); dwc3_gadget_disable_irq(dwc);
__dwc3_gadget_ep_disable(dwc->eps[0]); __dwc3_gadget_ep_disable(dwc->eps[0]);
__dwc3_gadget_ep_disable(dwc->eps[1]); __dwc3_gadget_ep_disable(dwc->eps[1]);
}
dwc->gadget_driver = NULL; static int dwc3_gadget_stop(struct usb_gadget *g)
{
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long flags;
int irq;
spin_lock_irqsave(&dwc->lock, flags);
__dwc3_gadget_stop(dwc);
dwc->gadget_driver = NULL;
spin_unlock_irqrestore(&dwc->lock, flags); spin_unlock_irqrestore(&dwc->lock, flags);
irq = platform_get_irq(to_platform_device(dwc->dev), 0); irq = platform_get_irq(to_platform_device(dwc->dev), 0);
......
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