mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-16 09:56:46 +00:00
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: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
75a14b1434
commit
63eed2b524
@ -1801,90 +1801,95 @@ void musb_gadget_cleanup(struct musb *musb)
|
|||||||
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
|
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
|
||||||
int (*bind)(struct usb_gadget *))
|
int (*bind)(struct usb_gadget *))
|
||||||
{
|
{
|
||||||
int retval;
|
struct musb *musb = the_gadget;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct musb *musb = the_gadget;
|
int retval = -EINVAL;
|
||||||
|
|
||||||
if (!driver
|
if (!driver
|
||||||
|| driver->speed != USB_SPEED_HIGH
|
|| driver->speed != USB_SPEED_HIGH
|
||||||
|| !bind || !driver->setup)
|
|| !bind || !driver->setup)
|
||||||
return -EINVAL;
|
goto err0;
|
||||||
|
|
||||||
/* driver must be initialized to support peripheral mode */
|
/* driver must be initialized to support peripheral mode */
|
||||||
if (!musb) {
|
if (!musb) {
|
||||||
DBG(1, "%s, no dev??\n", __func__);
|
DBG(1, "%s, no dev??\n", __func__);
|
||||||
return -ENODEV;
|
retval = -ENODEV;
|
||||||
|
goto err0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG(3, "registering driver %s\n", driver->function);
|
DBG(3, "registering driver %s\n", driver->function);
|
||||||
spin_lock_irqsave(&musb->lock, flags);
|
|
||||||
|
|
||||||
if (musb->gadget_driver) {
|
if (musb->gadget_driver) {
|
||||||
DBG(1, "%s is already bound to %s\n",
|
DBG(1, "%s is already bound to %s\n",
|
||||||
musb_driver_name,
|
musb_driver_name,
|
||||||
musb->gadget_driver->driver.name);
|
musb->gadget_driver->driver.name);
|
||||||
retval = -EBUSY;
|
retval = -EBUSY;
|
||||||
} else {
|
goto err0;
|
||||||
musb->gadget_driver = driver;
|
|
||||||
musb->g.dev.driver = &driver->driver;
|
|
||||||
driver->driver.bus = NULL;
|
|
||||||
musb->softconnect = 1;
|
|
||||||
retval = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spin_lock_irqsave(&musb->lock, flags);
|
||||||
|
musb->gadget_driver = driver;
|
||||||
|
musb->g.dev.driver = &driver->driver;
|
||||||
|
driver->driver.bus = NULL;
|
||||||
|
musb->softconnect = 1;
|
||||||
|
spin_unlock_irqrestore(&musb->lock, flags);
|
||||||
|
|
||||||
|
retval = bind(&musb->g);
|
||||||
|
if (retval) {
|
||||||
|
DBG(3, "bind to driver %s failed --> %d\n",
|
||||||
|
driver->driver.name, retval);
|
||||||
|
goto err1;
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_lock_irqsave(&musb->lock, flags);
|
||||||
|
|
||||||
|
otg_set_peripheral(musb->xceiv, &musb->g);
|
||||||
|
musb->xceiv->state = OTG_STATE_B_IDLE;
|
||||||
|
musb->is_active = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!is_otg_enabled(musb))
|
||||||
|
musb_start(musb);
|
||||||
|
|
||||||
|
otg_set_peripheral(musb->xceiv, &musb->g);
|
||||||
|
|
||||||
spin_unlock_irqrestore(&musb->lock, flags);
|
spin_unlock_irqrestore(&musb->lock, flags);
|
||||||
|
|
||||||
if (retval == 0) {
|
if (is_otg_enabled(musb)) {
|
||||||
retval = bind(&musb->g);
|
struct usb_hcd *hcd = musb_to_hcd(musb);
|
||||||
if (retval != 0) {
|
|
||||||
DBG(3, "bind to driver %s failed --> %d\n",
|
|
||||||
driver->driver.name, retval);
|
|
||||||
musb->gadget_driver = NULL;
|
|
||||||
musb->g.dev.driver = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&musb->lock, flags);
|
DBG(3, "OTG startup...\n");
|
||||||
|
|
||||||
otg_set_peripheral(musb->xceiv, &musb->g);
|
/* REVISIT: funcall to other code, which also
|
||||||
musb->xceiv->state = OTG_STATE_B_IDLE;
|
* handles power budgeting ... this way also
|
||||||
musb->is_active = 1;
|
* ensures HdrcStart is indirectly called.
|
||||||
|
|
||||||
/* 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.
|
|
||||||
*/
|
*/
|
||||||
|
retval = usb_add_hcd(musb_to_hcd(musb), -1, 0);
|
||||||
if (!is_otg_enabled(musb))
|
if (retval < 0) {
|
||||||
musb_start(musb);
|
DBG(1, "add_hcd failed, %d\n", retval);
|
||||||
|
goto err2;
|
||||||
otg_set_peripheral(musb->xceiv, &musb->g);
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&musb->lock, flags);
|
|
||||||
|
|
||||||
if (is_otg_enabled(musb)) {
|
|
||||||
struct usb_hcd *hcd = musb_to_hcd(musb);
|
|
||||||
|
|
||||||
DBG(3, "OTG startup...\n");
|
|
||||||
|
|
||||||
/* REVISIT: funcall to other code, which also
|
|
||||||
* handles power budgeting ... this way also
|
|
||||||
* ensures HdrcStart is indirectly called.
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return retval;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(usb_gadget_probe_driver);
|
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)
|
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
|
||||||
int retval = 0;
|
|
||||||
struct musb *musb = the_gadget;
|
struct musb *musb = the_gadget;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
if (!driver || !driver->unbind || !musb)
|
if (!driver || !driver->unbind || !musb)
|
||||||
return -EINVAL;
|
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.
|
* this needs to shut down the OTG engine.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1956,29 +1964,26 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
|
|||||||
musb_hnp_stop(musb);
|
musb_hnp_stop(musb);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (musb->gadget_driver == driver) {
|
(void) musb_gadget_vbus_draw(&musb->g, 0);
|
||||||
|
|
||||||
(void) musb_gadget_vbus_draw(&musb->g, 0);
|
musb->xceiv->state = OTG_STATE_UNDEFINED;
|
||||||
|
stop_activity(musb, driver);
|
||||||
|
otg_set_peripheral(musb->xceiv, NULL);
|
||||||
|
|
||||||
musb->xceiv->state = OTG_STATE_UNDEFINED;
|
DBG(3, "unregistering driver %s\n", driver->function);
|
||||||
stop_activity(musb, driver);
|
|
||||||
otg_set_peripheral(musb->xceiv, NULL);
|
|
||||||
|
|
||||||
DBG(3, "unregistering driver %s\n", driver->function);
|
spin_unlock_irqrestore(&musb->lock, flags);
|
||||||
spin_unlock_irqrestore(&musb->lock, flags);
|
driver->unbind(&musb->g);
|
||||||
driver->unbind(&musb->g);
|
spin_lock_irqsave(&musb->lock, flags);
|
||||||
spin_lock_irqsave(&musb->lock, flags);
|
|
||||||
|
|
||||||
musb->gadget_driver = NULL;
|
musb->gadget_driver = NULL;
|
||||||
musb->g.dev.driver = NULL;
|
musb->g.dev.driver = NULL;
|
||||||
|
|
||||||
musb->is_active = 0;
|
musb->is_active = 0;
|
||||||
musb_platform_try_idle(musb, 0);
|
musb_platform_try_idle(musb, 0);
|
||||||
} else
|
|
||||||
retval = -EINVAL;
|
|
||||||
spin_unlock_irqrestore(&musb->lock, flags);
|
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));
|
usb_remove_hcd(musb_to_hcd(musb));
|
||||||
/* FIXME we need to be able to register another
|
/* FIXME we need to be able to register another
|
||||||
* gadget driver here and have everything work;
|
* 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);
|
EXPORT_SYMBOL(usb_gadget_unregister_driver);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user