Commit ffe0b335 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi

usb: gadget: remove global variable composite in composite.c

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: default avatarMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent e220ff75
......@@ -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;
......
......@@ -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 = {
......@@ -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;
......@@ -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...
......
......@@ -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).
......@@ -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;
......@@ -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);
}
......@@ -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);
......@@ -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)
......@@ -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);
......@@ -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;
......@@ -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)
......@@ -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,
......@@ -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);
}
/**
......@@ -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);
}
/**
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 = {
......@@ -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;
......@@ -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;
......
......@@ -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;
......@@ -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);
......
......@@ -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 = {
......@@ -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;
......@@ -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);
......
......@@ -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;
......@@ -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;
......
......@@ -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;
......@@ -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);
......
......@@ -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 = {
......@@ -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;
......@@ -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);
......
......@@ -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 = {
......@@ -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;
......@@ -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;
......
......@@ -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,
......@@ -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;
......@@ -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",
......
......@@ -999,7 +999,7 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
}
static int pxa25x_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int pxa25x_stop(struct usb_gadget_driver *driver);
static const struct usb_gadget_ops pxa25x_udc_ops = {
......@@ -1257,7 +1257,7 @@ static void udc_enable (struct pxa25x_udc *dev)
* the driver might get unbound.
*/
static int pxa25x_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct pxa25x_udc *dev = the_controller;
int retval;
......@@ -1285,7 +1285,7 @@ static int pxa25x_start(struct usb_gadget_driver *driver,
dev->gadget.dev.driver = NULL;
return retval;
}
retval = bind(&dev->gadget);
retval = bind(&dev->gadget, driver);
if (retval) {
DMSG("bind to driver %s --> error %d\n",
driver->driver.name, retval);
......
......@@ -1672,7 +1672,7 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
}
static int pxa27x_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int pxa27x_udc_stop(struct usb_gadget_driver *driver);
static const struct usb_gadget_ops pxa_udc_ops = {
......@@ -1803,7 +1803,7 @@ 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 *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct pxa_udc *udc = the_controller;
int retval;
......@@ -1826,7 +1826,7 @@ static int pxa27x_udc_start(struct usb_gadget_driver *driver,
dev_err(udc->dev, "device_add error %d\n", retval);
goto add_fail;
}
retval = bind(&udc->gadget);
retval = bind(&udc->gadget, driver);
if (retval) {
dev_err(udc->dev, "bind to driver %s --> error %d\n",
driver->driver.name, retval);
......
......@@ -1539,7 +1539,7 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
}
static int s3c2410_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
static int s3c2410_udc_stop(struct usb_gadget_driver *driver);
static const struct usb_gadget_ops s3c2410_ops = {
......@@ -1665,7 +1665,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev)
}
static int s3c2410_udc_start(struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
struct s3c2410_udc *udc = the_controller;
int retval;
......@@ -1705,7 +1705,7 @@ static int s3c2410_udc_start(struct usb_gadget_driver *driver,
dprintk(DEBUG_NORMAL, "binding gadget driver '%s'\n",
driver->driver.name);
retval = bind(&udc->gadget);
retval = bind(&udc->gadget, driver);
if (retval) {
device_del(&udc->gadget.dev);
goto register_error;
......
......@@ -118,7 +118,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
*/
static inline int usb_gadget_start(struct usb_gadget *gadget,
struct usb_gadget_driver *driver,
int (*bind)(struct usb_gadget *))
int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
{
return gadget->ops->start(driver, bind);
}
......@@ -338,7 +338,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
udc->dev.driver = &driver->driver;
if (udc_is_newstyle(udc)) {
ret = driver->bind(udc->gadget);
ret = driver->bind(udc->gadget, driver);
if (ret)
goto err1;
ret = usb_gadget_udc_start(udc->gadget, driver);
......
......@@ -303,6 +303,7 @@ struct usb_composite_driver {
/* global suspend hooks */
void (*suspend)(struct usb_composite_dev *);
void (*resume)(struct usb_composite_dev *);
struct usb_gadget_driver gadget_driver;
};
extern int usb_composite_probe(struct usb_composite_driver *driver);
......
......@@ -474,7 +474,8 @@ struct usb_gadget_ops {
/* Those two are deprecated */
int (*start)(struct usb_gadget_driver *,
int (*bind)(struct usb_gadget *));
int (*bind)(struct usb_gadget *,
struct usb_gadget_driver *driver));
int (*stop)(struct usb_gadget_driver *);
};
......@@ -821,7 +822,8 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
struct usb_gadget_driver {
char *function;
enum usb_device_speed max_speed;
int (*bind)(struct usb_gadget *gadget);
int (*bind)(struct usb_gadget *gadget,
struct usb_gadget_driver *driver);
void (*unbind)(struct usb_gadget *);
int (*setup)(struct usb_gadget *,
const struct usb_ctrlrequest *);
......
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