aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/composite.c
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2012-09-07 03:53:17 -0400
committerFelipe Balbi <balbi@ti.com>2012-09-10 08:35:41 -0400
commitffe0b335062505a98d7296dae2c2a197713f87e0 (patch)
treec2fe75a9711026ee65409034dd71579bad64a801 /drivers/usb/gadget/composite.c
parente220ff75db3c1195814c2ad5ada11f71b011d000 (diff)
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: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/composite.c')
-rw-r--r--drivers/usb/gadget/composite.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 2a345f28b9ae..0b6ee2012af1 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -31,8 +31,6 @@
31/* big enough to hold our biggest descriptor */ 31/* big enough to hold our biggest descriptor */
32#define USB_BUFSIZ 1024 32#define USB_BUFSIZ 1024
33 33
34static struct usb_composite_driver *composite;
35
36/* Some systems will need runtime overrides for the product identifiers 34/* Some systems will need runtime overrides for the product identifiers
37 * published in the device descriptor, either numbers or strings or both. 35 * published in the device descriptor, either numbers or strings or both.
38 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 36 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
@@ -889,6 +887,7 @@ static int lookup_string(
889static int get_string(struct usb_composite_dev *cdev, 887static int get_string(struct usb_composite_dev *cdev,
890 void *buf, u16 language, int id) 888 void *buf, u16 language, int id)
891{ 889{
890 struct usb_composite_driver *composite = cdev->driver;
892 struct usb_configuration *c; 891 struct usb_configuration *c;
893 struct usb_function *f; 892 struct usb_function *f;
894 int len; 893 int len;
@@ -1359,8 +1358,8 @@ static void composite_disconnect(struct usb_gadget *gadget)
1359 spin_lock_irqsave(&cdev->lock, flags); 1358 spin_lock_irqsave(&cdev->lock, flags);
1360 if (cdev->config) 1359 if (cdev->config)
1361 reset_config(cdev); 1360 reset_config(cdev);
1362 if (composite->disconnect) 1361 if (cdev->driver->disconnect)
1363 composite->disconnect(cdev); 1362 cdev->driver->disconnect(cdev);
1364 spin_unlock_irqrestore(&cdev->lock, flags); 1363 spin_unlock_irqrestore(&cdev->lock, flags);
1365} 1364}
1366 1365
@@ -1396,8 +1395,8 @@ composite_unbind(struct usb_gadget *gadget)
1396 struct usb_configuration, list); 1395 struct usb_configuration, list);
1397 remove_config(cdev, c); 1396 remove_config(cdev, c);
1398 } 1397 }
1399 if (composite->unbind) 1398 if (cdev->driver->unbind)
1400 composite->unbind(cdev); 1399 cdev->driver->unbind(cdev);
1401 1400
1402 if (cdev->req) { 1401 if (cdev->req) {
1403 kfree(cdev->req->buf); 1402 kfree(cdev->req->buf);
@@ -1406,7 +1405,6 @@ composite_unbind(struct usb_gadget *gadget)
1406 device_remove_file(&gadget->dev, &dev_attr_suspended); 1405 device_remove_file(&gadget->dev, &dev_attr_suspended);
1407 kfree(cdev); 1406 kfree(cdev);
1408 set_gadget_data(gadget, NULL); 1407 set_gadget_data(gadget, NULL);
1409 composite = NULL;
1410} 1408}
1411 1409
1412static u8 override_id(struct usb_composite_dev *cdev, u8 *desc) 1410static 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)
1422 return *desc; 1420 return *desc;
1423} 1421}
1424 1422
1425static int composite_bind(struct usb_gadget *gadget) 1423static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv)
1424{
1425 return container_of(gdrv, struct usb_composite_driver, gadget_driver);
1426}
1427
1428static int composite_bind(struct usb_gadget *gadget,
1429 struct usb_gadget_driver *gdriver)
1426{ 1430{
1427 struct usb_composite_dev *cdev; 1431 struct usb_composite_dev *cdev;
1432 struct usb_composite_driver *composite = to_cdriver(gdriver);
1428 int status = -ENOMEM; 1433 int status = -ENOMEM;
1429 1434
1430 cdev = kzalloc(sizeof *cdev, GFP_KERNEL); 1435 cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
@@ -1546,8 +1551,8 @@ composite_suspend(struct usb_gadget *gadget)
1546 f->suspend(f); 1551 f->suspend(f);
1547 } 1552 }
1548 } 1553 }
1549 if (composite->suspend) 1554 if (cdev->driver->suspend)
1550 composite->suspend(cdev); 1555 cdev->driver->suspend(cdev);
1551 1556
1552 cdev->suspended = 1; 1557 cdev->suspended = 1;
1553 1558
@@ -1565,8 +1570,8 @@ composite_resume(struct usb_gadget *gadget)
1565 * suspend/resume callbacks? 1570 * suspend/resume callbacks?
1566 */ 1571 */
1567 DBG(cdev, "resume\n"); 1572 DBG(cdev, "resume\n");
1568 if (composite->resume) 1573 if (cdev->driver->resume)
1569 composite->resume(cdev); 1574 cdev->driver->resume(cdev);
1570 if (cdev->config) { 1575 if (cdev->config) {
1571 list_for_each_entry(f, &cdev->config->functions, list) { 1576 list_for_each_entry(f, &cdev->config->functions, list) {
1572 if (f->resume) 1577 if (f->resume)
@@ -1584,7 +1589,7 @@ composite_resume(struct usb_gadget *gadget)
1584 1589
1585/*-------------------------------------------------------------------------*/ 1590/*-------------------------------------------------------------------------*/
1586 1591
1587static struct usb_gadget_driver composite_driver = { 1592static const struct usb_gadget_driver composite_driver_template = {
1588 .bind = composite_bind, 1593 .bind = composite_bind,
1589 .unbind = composite_unbind, 1594 .unbind = composite_unbind,
1590 1595
@@ -1620,19 +1625,24 @@ static struct usb_gadget_driver composite_driver = {
1620 */ 1625 */
1621int usb_composite_probe(struct usb_composite_driver *driver) 1626int usb_composite_probe(struct usb_composite_driver *driver)
1622{ 1627{
1623 if (!driver || !driver->dev || composite || !driver->bind) 1628 struct usb_gadget_driver *gadget_driver;
1629
1630 if (!driver || !driver->dev || !driver->bind)
1624 return -EINVAL; 1631 return -EINVAL;
1625 1632
1626 if (!driver->name) 1633 if (!driver->name)
1627 driver->name = "composite"; 1634 driver->name = "composite";
1628 if (!driver->iProduct) 1635 if (!driver->iProduct)
1629 driver->iProduct = driver->name; 1636 driver->iProduct = driver->name;
1630 composite_driver.function = (char *) driver->name;
1631 composite_driver.driver.name = driver->name;
1632 composite_driver.max_speed = driver->max_speed;
1633 composite = driver;
1634 1637
1635 return usb_gadget_probe_driver(&composite_driver); 1638 driver->gadget_driver = composite_driver_template;
1639 gadget_driver = &driver->gadget_driver;
1640
1641 gadget_driver->function = (char *) driver->name;
1642 gadget_driver->driver.name = driver->name;
1643 gadget_driver->max_speed = driver->max_speed;
1644
1645 return usb_gadget_probe_driver(gadget_driver);
1636} 1646}
1637 1647
1638/** 1648/**
@@ -1644,9 +1654,7 @@ int usb_composite_probe(struct usb_composite_driver *driver)
1644 */ 1654 */
1645void usb_composite_unregister(struct usb_composite_driver *driver) 1655void usb_composite_unregister(struct usb_composite_driver *driver)
1646{ 1656{
1647 if (composite != driver) 1657 usb_gadget_unregister_driver(&driver->gadget_driver);
1648 return;
1649 usb_gadget_unregister_driver(&composite_driver);
1650} 1658}
1651 1659
1652/** 1660/**