Skip to content

Commit

Permalink
usb: gadget: remove global variable composite in composite.c
Browse files Browse the repository at this point in the history
This patch removes the global variable composite in composite.c.
The private data which was saved there is now passed via an additional
argument to the bind() function in struct usb_gadget_driver.

Only the "old-style" UDC drivers have to be touched here, new style are
doing it right because this change is made in udc-core.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Sep 10, 2012
1 parent e220ff7 commit ffe0b33
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 63 deletions.
3 changes: 2 additions & 1 deletion drivers/staging/ccg/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,8 @@ static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
return *desc;
}

static int composite_bind(struct usb_gadget *gadget)
static int composite_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
struct usb_composite_dev *cdev;
int status = -ENOMEM;
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/amd5536udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ static int udc_wakeup(struct usb_gadget *gadget)
}

static int amd5536_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int amd5536_stop(struct usb_gadget_driver *driver);
/* gadget operations */
static const struct usb_gadget_ops udc_ops = {
Expand Down Expand Up @@ -1914,7 +1914,7 @@ static int setup_ep0(struct udc *dev)

/* Called by gadget driver to register itself */
static int amd5536_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct udc *dev = udc;
int retval;
Expand All @@ -1932,7 +1932,7 @@ static int amd5536_start(struct usb_gadget_driver *driver,
dev->driver = driver;
dev->gadget.dev.driver = &driver->driver;

retval = bind(&dev->gadget);
retval = bind(&dev->gadget, driver);

/* Some gadget drivers use both ep0 directions.
* NOTE: to gadget driver, ep0 is just one endpoint...
Expand Down
52 changes: 30 additions & 22 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
/* big enough to hold our biggest descriptor */
#define USB_BUFSIZ 1024

static struct usb_composite_driver *composite;

/* Some systems will need runtime overrides for the product identifiers
* published in the device descriptor, either numbers or strings or both.
* String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
Expand Down Expand Up @@ -889,6 +887,7 @@ static int lookup_string(
static int get_string(struct usb_composite_dev *cdev,
void *buf, u16 language, int id)
{
struct usb_composite_driver *composite = cdev->driver;
struct usb_configuration *c;
struct usb_function *f;
int len;
Expand Down Expand Up @@ -1359,8 +1358,8 @@ static void composite_disconnect(struct usb_gadget *gadget)
spin_lock_irqsave(&cdev->lock, flags);
if (cdev->config)
reset_config(cdev);
if (composite->disconnect)
composite->disconnect(cdev);
if (cdev->driver->disconnect)
cdev->driver->disconnect(cdev);
spin_unlock_irqrestore(&cdev->lock, flags);
}

Expand Down Expand Up @@ -1396,8 +1395,8 @@ composite_unbind(struct usb_gadget *gadget)
struct usb_configuration, list);
remove_config(cdev, c);
}
if (composite->unbind)
composite->unbind(cdev);
if (cdev->driver->unbind)
cdev->driver->unbind(cdev);

if (cdev->req) {
kfree(cdev->req->buf);
Expand All @@ -1406,7 +1405,6 @@ composite_unbind(struct usb_gadget *gadget)
device_remove_file(&gadget->dev, &dev_attr_suspended);
kfree(cdev);
set_gadget_data(gadget, NULL);
composite = NULL;
}

static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
Expand All @@ -1422,9 +1420,16 @@ static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
return *desc;
}

static int composite_bind(struct usb_gadget *gadget)
static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv)
{
return container_of(gdrv, struct usb_composite_driver, gadget_driver);
}

static int composite_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *gdriver)
{
struct usb_composite_dev *cdev;
struct usb_composite_driver *composite = to_cdriver(gdriver);
int status = -ENOMEM;

cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
Expand Down Expand Up @@ -1546,8 +1551,8 @@ composite_suspend(struct usb_gadget *gadget)
f->suspend(f);
}
}
if (composite->suspend)
composite->suspend(cdev);
if (cdev->driver->suspend)
cdev->driver->suspend(cdev);

cdev->suspended = 1;

Expand All @@ -1565,8 +1570,8 @@ composite_resume(struct usb_gadget *gadget)
* suspend/resume callbacks?
*/
DBG(cdev, "resume\n");
if (composite->resume)
composite->resume(cdev);
if (cdev->driver->resume)
cdev->driver->resume(cdev);
if (cdev->config) {
list_for_each_entry(f, &cdev->config->functions, list) {
if (f->resume)
Expand All @@ -1584,7 +1589,7 @@ composite_resume(struct usb_gadget *gadget)

/*-------------------------------------------------------------------------*/

static struct usb_gadget_driver composite_driver = {
static const struct usb_gadget_driver composite_driver_template = {
.bind = composite_bind,
.unbind = composite_unbind,

Expand Down Expand Up @@ -1620,19 +1625,24 @@ static struct usb_gadget_driver composite_driver = {
*/
int usb_composite_probe(struct usb_composite_driver *driver)
{
if (!driver || !driver->dev || composite || !driver->bind)
struct usb_gadget_driver *gadget_driver;

if (!driver || !driver->dev || !driver->bind)
return -EINVAL;

if (!driver->name)
driver->name = "composite";
if (!driver->iProduct)
driver->iProduct = driver->name;
composite_driver.function = (char *) driver->name;
composite_driver.driver.name = driver->name;
composite_driver.max_speed = driver->max_speed;
composite = driver;

return usb_gadget_probe_driver(&composite_driver);
driver->gadget_driver = composite_driver_template;
gadget_driver = &driver->gadget_driver;

gadget_driver->function = (char *) driver->name;
gadget_driver->driver.name = driver->name;
gadget_driver->max_speed = driver->max_speed;

return usb_gadget_probe_driver(gadget_driver);
}

/**
Expand All @@ -1644,9 +1654,7 @@ int usb_composite_probe(struct usb_composite_driver *driver)
*/
void usb_composite_unregister(struct usb_composite_driver *driver)
{
if (composite != driver)
return;
usb_gadget_unregister_driver(&composite_driver);
usb_gadget_unregister_driver(&driver->gadget_driver);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/dbgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
return -ENODEV;
}

static int __init dbgp_bind(struct usb_gadget *gadget)
static int __init dbgp_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
int err, stp;

Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/file_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
}


static int __init fsg_bind(struct usb_gadget *gadget)
static int __init fsg_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
struct fsg_dev *fsg = the_fsg;
int rc;
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/fsl_udc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
}

static int fsl_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int fsl_stop(struct usb_gadget_driver *driver);
/* defined in gadget.h */
static struct usb_gadget_ops fsl_gadget_ops = {
Expand Down Expand Up @@ -1951,7 +1951,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
* Called by initialization code of gadget drivers
*----------------------------------------------------------------*/
static int fsl_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
int retval = -ENODEV;
unsigned long flags = 0;
Expand All @@ -1976,7 +1976,7 @@ static int fsl_start(struct usb_gadget_driver *driver,
spin_unlock_irqrestore(&udc_controller->lock, flags);

/* bind udc driver to gadget driver */
retval = bind(&udc_controller->gadget);
retval = bind(&udc_controller->gadget, driver);
if (retval) {
VDBG("bind to %s --> %d", driver->driver.name, retval);
udc_controller->gadget.dev.driver = NULL;
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/gadget/fusb300_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ static void init_controller(struct fusb300 *fusb300)
static struct fusb300 *the_controller;

static int fusb300_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct fusb300 *fusb300 = the_controller;
int retval;
Expand Down Expand Up @@ -1339,7 +1339,7 @@ static int fusb300_udc_start(struct usb_gadget_driver *driver,
goto error;
}

retval = bind(&fusb300->gadget);
retval = bind(&fusb300->gadget, driver);
if (retval) {
pr_err("bind to driver error (%d)\n", retval);
device_del(&fusb300->gadget.dev);
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/goku_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ static int goku_get_frame(struct usb_gadget *_gadget)
}

static int goku_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int goku_stop(struct usb_gadget_driver *driver);

static const struct usb_gadget_ops goku_ops = {
Expand Down Expand Up @@ -1348,7 +1348,7 @@ static struct goku_udc *the_controller;
* the driver might get unbound.
*/
static int goku_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct goku_udc *dev = the_controller;
int retval;
Expand All @@ -1368,7 +1368,7 @@ static int goku_start(struct usb_gadget_driver *driver,
driver->driver.bus = NULL;
dev->driver = driver;
dev->gadget.dev.driver = &driver->driver;
retval = bind(&dev->gadget);
retval = bind(&dev->gadget, driver);
if (retval) {
DBG(dev, "bind to driver %s --> error %d\n",
driver->driver.name, retval);
Expand Down
7 changes: 4 additions & 3 deletions drivers/usb/gadget/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,8 +1679,8 @@ gadgetfs_unbind (struct usb_gadget *gadget)

static struct dev_data *the_device;

static int
gadgetfs_bind (struct usb_gadget *gadget)
static int gadgetfs_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
struct dev_data *dev = the_device;

Expand Down Expand Up @@ -1773,7 +1773,8 @@ static struct usb_gadget_driver gadgetfs_driver = {

static void gadgetfs_nop(struct usb_gadget *arg) { }

static int gadgetfs_probe (struct usb_gadget *gadget)
static int gadgetfs_probe(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
CHIP = gadget->name;
return -EISNAM;
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/gadget/m66592-udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ static struct usb_ep_ops m66592_ep_ops = {
static struct m66592 *the_controller;

static int m66592_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct m66592 *m66592 = the_controller;
int retval;
Expand All @@ -1492,7 +1492,7 @@ static int m66592_start(struct usb_gadget_driver *driver,
goto error;
}

retval = bind(&m66592->gadget);
retval = bind(&m66592->gadget, driver);
if (retval) {
pr_err("bind to driver error (%d)\n", retval);
device_del(&m66592->gadget.dev);
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/mv_udc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)
}

static int mv_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int mv_udc_stop(struct usb_gadget_driver *driver);
/* device controller usb_gadget_ops structure */
static const struct usb_gadget_ops mv_ops = {
Expand Down Expand Up @@ -1374,7 +1374,7 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver)
}

static int mv_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct mv_udc *udc = the_controller;
int retval = 0;
Expand All @@ -1399,7 +1399,7 @@ static int mv_udc_start(struct usb_gadget_driver *driver,

spin_unlock_irqrestore(&udc->lock, flags);

retval = bind(&udc->gadget);
retval = bind(&udc->gadget, driver);
if (retval) {
dev_err(&udc->dev->dev, "bind to driver %s --> %d\n",
driver->driver.name, retval);
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/omap_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on)
}

static int omap_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int omap_udc_stop(struct usb_gadget_driver *driver);

static struct usb_gadget_ops omap_gadget_ops = {
Expand Down Expand Up @@ -2040,7 +2040,7 @@ static inline int machine_without_vbus_sense(void)
}

static int omap_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
int status = -ENODEV;
struct omap_ep *ep;
Expand Down Expand Up @@ -2082,7 +2082,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
if (udc->dc_clk != NULL)
omap_udc_enable_clock(1);

status = bind(&udc->gadget);
status = bind(&udc->gadget, driver);
if (status) {
DBG("bind to %s --> %d\n", driver->driver.name, status);
udc->gadget.dev.driver = NULL;
Expand Down
6 changes: 3 additions & 3 deletions drivers/usb/gadget/pch_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
}

static int pch_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int pch_udc_stop(struct usb_gadget_driver *driver);
static const struct usb_gadget_ops pch_udc_ops = {
.get_frame = pch_udc_pcd_get_frame,
Expand Down Expand Up @@ -2982,7 +2982,7 @@ static int init_dma_pools(struct pch_udc_dev *dev)
}

static int pch_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct pch_udc_dev *dev = pch_udc;
int retval;
Expand All @@ -3006,7 +3006,7 @@ static int pch_udc_start(struct usb_gadget_driver *driver,
dev->gadget.dev.driver = &driver->driver;

/* Invoke the bind routine of the gadget driver */
retval = bind(&dev->gadget);
retval = bind(&dev->gadget, driver);

if (retval) {
dev_err(&dev->pdev->dev, "%s: binding to %s returning %d\n",
Expand Down
Loading

0 comments on commit ffe0b33

Please sign in to comment.