Skip to content

Commit

Permalink
usb: gadget: pxa27x_udc: convert to udc_start/udc_stop
Browse files Browse the repository at this point in the history
Mechanical change making use of the new (can we
still call it new ?) interface for registering
UDC drivers.

Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Felipe Balbi committed Jan 24, 2013
1 parent 6166c24 commit 70189a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
61 changes: 15 additions & 46 deletions drivers/usb/gadget/pxa27x_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,18 +1671,19 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
return -EOPNOTSUPP;
}

static int pxa27x_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int pxa27x_udc_stop(struct usb_gadget_driver *driver);
static int pxa27x_udc_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
static int pxa27x_udc_stop(struct usb_gadget *g,
struct usb_gadget_driver *driver);

static const struct usb_gadget_ops pxa_udc_ops = {
.get_frame = pxa_udc_get_frame,
.wakeup = pxa_udc_wakeup,
.pullup = pxa_udc_pullup,
.vbus_session = pxa_udc_vbus_session,
.vbus_draw = pxa_udc_vbus_draw,
.start = pxa27x_udc_start,
.stop = pxa27x_udc_stop,
.udc_start = pxa27x_udc_start,
.udc_stop = pxa27x_udc_stop,
};

/**
Expand Down Expand Up @@ -1802,20 +1803,12 @@ static void udc_enable(struct pxa_udc *udc)
*
* Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
*/
static int pxa27x_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
static int pxa27x_udc_start(struct usb_gadget *g,
struct usb_gadget_driver *driver)
{
struct pxa_udc *udc = the_controller;
struct pxa_udc *udc = to_pxa(g);
int retval;

if (!driver || driver->max_speed < USB_SPEED_FULL || !bind
|| !driver->disconnect || !driver->setup)
return -EINVAL;
if (!udc)
return -ENODEV;
if (udc->driver)
return -EBUSY;

/* first hook up the driver ... */
udc->driver = driver;
udc->gadget.dev.driver = &driver->driver;
Expand All @@ -1824,36 +1817,22 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
retval = device_add(&udc->gadget.dev);
if (retval) {
dev_err(udc->dev, "device_add error %d\n", retval);
goto add_fail;
goto fail;
}
retval = bind(&udc->gadget, driver);
if (retval) {
dev_err(udc->dev, "bind to driver %s --> error %d\n",
driver->driver.name, retval);
goto bind_fail;
}
dev_dbg(udc->dev, "registered gadget driver '%s'\n",
driver->driver.name);

if (!IS_ERR_OR_NULL(udc->transceiver)) {
retval = otg_set_peripheral(udc->transceiver->otg,
&udc->gadget);
if (retval) {
dev_err(udc->dev, "can't bind to transceiver\n");
goto transceiver_fail;
goto fail;
}
}

if (should_enable_udc(udc))
udc_enable(udc);
return 0;

transceiver_fail:
if (driver->unbind)
driver->unbind(&udc->gadget);
bind_fail:
device_del(&udc->gadget.dev);
add_fail:
fail:
udc->driver = NULL;
udc->gadget.dev.driver = NULL;
return retval;
Expand All @@ -1878,9 +1857,6 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)

for (i = 0; i < NR_USB_ENDPOINTS; i++)
pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep);

if (driver)
driver->disconnect(&udc->gadget);
}

/**
Expand All @@ -1889,25 +1865,18 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
*
* Returns 0 if no error, -ENODEV, -EINVAL otherwise
*/
static int pxa27x_udc_stop(struct usb_gadget_driver *driver)
static int pxa27x_udc_stop(struct usb_gadget *g,
struct usb_gadget_driver *driver)
{
struct pxa_udc *udc = the_controller;

if (!udc)
return -ENODEV;
if (!driver || driver != udc->driver || !driver->unbind)
return -EINVAL;
struct pxa_udc *udc = to_pxa(g);

stop_activity(udc, driver);
udc_disable(udc);
dplus_pullup(udc, 0);

driver->unbind(&udc->gadget);
udc->driver = NULL;

device_del(&udc->gadget.dev);
dev_info(udc->dev, "unregistered gadget driver '%s'\n",
driver->driver.name);

if (!IS_ERR_OR_NULL(udc->transceiver))
return otg_set_peripheral(udc->transceiver->otg, NULL);
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/pxa27x_udc.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ struct pxa_udc {
struct dentry *debugfs_eps;
#endif
};
#define to_pxa(g) (container_of((g), struct pxa_udc, gadget))

static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
{
Expand Down

0 comments on commit 70189a6

Please sign in to comment.