Commit 63eed2b5 authored by Felipe Balbi's avatar Felipe Balbi

usb: musb: gadget: beautify usb_gadget_probe_driver()/usb_gadget_unregister_driver

Just a few cosmetic fixes to usb_gadget_probe_driver()
and usb_gadget_unregister_driver().

Decreased a few indentation levels with goto statements.

While at that, also add the missing call to musb_stop().
If we don't have OTG, there's no point of leaving
MUSB prepared for operation if a gadget driver fails
to probe. The same is valid for usb_gadget_unregister_driver(),
since we are removing the gadget driver and we don't have
OTG, we can completely unconfigure MUSB.
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 75a14b14
......@@ -1801,46 +1801,44 @@ void musb_gadget_cleanup(struct musb *musb)
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
{
int retval;
unsigned long flags;
struct musb *musb = the_gadget;
unsigned long flags;
int retval = -EINVAL;
if (!driver
|| driver->speed != USB_SPEED_HIGH
|| !bind || !driver->setup)
return -EINVAL;
goto err0;
/* driver must be initialized to support peripheral mode */
if (!musb) {
DBG(1, "%s, no dev??\n", __func__);
return -ENODEV;
retval = -ENODEV;
goto err0;
}
DBG(3, "registering driver %s\n", driver->function);
spin_lock_irqsave(&musb->lock, flags);
if (musb->gadget_driver) {
DBG(1, "%s is already bound to %s\n",
musb_driver_name,
musb->gadget_driver->driver.name);
retval = -EBUSY;
} else {
goto err0;
}
spin_lock_irqsave(&musb->lock, flags);
musb->gadget_driver = driver;
musb->g.dev.driver = &driver->driver;
driver->driver.bus = NULL;
musb->softconnect = 1;
retval = 0;
}
spin_unlock_irqrestore(&musb->lock, flags);
if (retval == 0) {
retval = bind(&musb->g);
if (retval != 0) {
if (retval) {
DBG(3, "bind to driver %s failed --> %d\n",
driver->driver.name, retval);
musb->gadget_driver = NULL;
musb->g.dev.driver = NULL;
goto err1;
}
spin_lock_irqsave(&musb->lock, flags);
......@@ -1849,7 +1847,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
musb->xceiv->state = OTG_STATE_B_IDLE;
musb->is_active = 1;
/* FIXME this ignores the softconnect flag. Drivers are
/*
* FIXME this ignores the softconnect flag. Drivers are
* allowed hold the peripheral inactive until for example
* userspace hooks up printer hardware or DSP codecs, so
* hosts only see fully functional devices.
......@@ -1874,17 +1873,23 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
retval = usb_add_hcd(musb_to_hcd(musb), -1, 0);
if (retval < 0) {
DBG(1, "add_hcd failed, %d\n", retval);
spin_lock_irqsave(&musb->lock, flags);
otg_set_peripheral(musb->xceiv, NULL);
musb->gadget_driver = NULL;
musb->g.dev.driver = NULL;
spin_unlock_irqrestore(&musb->lock, flags);
} else {
hcd->self.uses_pio_for_control = 1;
}
goto err2;
}
hcd->self.uses_pio_for_control = 1;
}
return 0;
err2:
if (!is_otg_enabled(musb))
musb_stop(musb);
err1:
musb->gadget_driver = NULL;
musb->g.dev.driver = NULL;
err0:
return retval;
}
EXPORT_SYMBOL(usb_gadget_probe_driver);
......@@ -1939,14 +1944,17 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
*/
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
{
unsigned long flags;
int retval = 0;
struct musb *musb = the_gadget;
unsigned long flags;
if (!driver || !driver->unbind || !musb)
return -EINVAL;
/* REVISIT always use otg_set_peripheral() here too;
if (!musb->gadget_driver)
return -EINVAL;
/*
* REVISIT always use otg_set_peripheral() here too;
* this needs to shut down the OTG engine.
*/
......@@ -1956,8 +1964,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
musb_hnp_stop(musb);
#endif
if (musb->gadget_driver == driver) {
(void) musb_gadget_vbus_draw(&musb->g, 0);
musb->xceiv->state = OTG_STATE_UNDEFINED;
......@@ -1965,6 +1971,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
otg_set_peripheral(musb->xceiv, NULL);
DBG(3, "unregistering driver %s\n", driver->function);
spin_unlock_irqrestore(&musb->lock, flags);
driver->unbind(&musb->g);
spin_lock_irqsave(&musb->lock, flags);
......@@ -1974,11 +1981,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
musb->is_active = 0;
musb_platform_try_idle(musb, 0);
} else
retval = -EINVAL;
spin_unlock_irqrestore(&musb->lock, flags);
if (is_otg_enabled(musb) && retval == 0) {
if (is_otg_enabled(musb)) {
usb_remove_hcd(musb_to_hcd(musb));
/* FIXME we need to be able to register another
* gadget driver here and have everything work;
......@@ -1986,7 +1991,10 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
*/
}
return retval;
if (!is_otg_enabled(musb))
musb_stop(musb);
return 0;
}
EXPORT_SYMBOL(usb_gadget_unregister_driver);
......
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