usb: gadget: push VID/PID/USB BCD module option into gadgets
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Mon, 10 Sep 2012 13:01:53 +0000 (15:01 +0200)
committerFelipe Balbi <balbi@ti.com>
Mon, 10 Sep 2012 13:12:59 +0000 (16:12 +0300)
This patch moves the module options idVendor, idProduct and bcdDevice
from composite.c into each gadgets. This ensures compatibility with
current gadgets and removes the global variable which brings me step
closer towards composite.c in libcomposite

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
18 files changed:
drivers/usb/gadget/acm_ms.c
drivers/usb/gadget/audio.c
drivers/usb/gadget/cdc2.c
drivers/usb/gadget/composite.c
drivers/usb/gadget/ether.c
drivers/usb/gadget/g_ffs.c
drivers/usb/gadget/gmidi.c
drivers/usb/gadget/hid.c
drivers/usb/gadget/mass_storage.c
drivers/usb/gadget/multi.c
drivers/usb/gadget/ncm.c
drivers/usb/gadget/nokia.c
drivers/usb/gadget/printer.c
drivers/usb/gadget/serial.c
drivers/usb/gadget/tcm_usb_gadget.c
drivers/usb/gadget/webcam.c
drivers/usb/gadget/zero.c
include/linux/usb/composite.h

index ea349bab7f15b45d49c0def74bebcdcb8d39ccc4..7bd6b71af5d30c6836346446351a276570877303 100644 (file)
@@ -47,6 +47,7 @@
 #include "f_mass_storage.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static struct usb_device_descriptor device_desc = {
        .bLength =              sizeof device_desc,
@@ -203,6 +204,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto fail1;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
                        DRIVER_DESC);
        fsg_common_put(&fsg_common);
index 5702ce3777fbadfc4d7d363301e8b2d588b53fe4..55b593c5a9c8b91cf2e168808e179af642490478 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <linux/kernel.h>
 #include <linux/utsname.h>
+#include <linux/usb/composite.h>
 
 #include "gadget_chips.h"
 #define DRIVER_DESC            "Linux USB Audio Gadget"
@@ -28,6 +29,7 @@
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
 #include "composite.c"
+USB_GADGET_COMPOSITE_OPTIONS();
 
 /* string IDs are assigned dynamically */
 
@@ -174,6 +176,7 @@ static int __init audio_bind(struct usb_composite_dev *cdev)
        status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
        if (status < 0)
                goto fail;
+       usb_composite_overwrite_options(cdev, &coverwrite);
 
        INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
        return 0;
index 3b89fe2bd0b834cb56ced8250b9a70eb056bf1ff..93a75809b4deb4118c436c42434126e47c4c9a06 100644 (file)
@@ -34,6 +34,7 @@
 #define CDC_PRODUCT_NUM                0xa4aa  /* CDC Composite: ECM + ACM */
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 /*
  * Kbuild is not very cooperative with respect to linking separately
@@ -204,6 +205,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto fail1;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
                        DRIVER_DESC);
 
index 8d81a5ccfa0317e726396aad9aed47b3b8a65dc8..317a5ece3bd2eacdc698a34b1bef647267952cf3 100644 (file)
  * published in the device descriptor, either numbers or strings or both.
  * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
  */
-
-static ushort idVendor;
-module_param(idVendor, ushort, S_IRUGO);
-MODULE_PARM_DESC(idVendor, "USB Vendor ID");
-
-static ushort idProduct;
-module_param(idProduct, ushort, S_IRUGO);
-MODULE_PARM_DESC(idProduct, "USB Product ID");
-
-static ushort bcdDevice;
-module_param(bcdDevice, ushort, S_IRUGO);
-MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
-
 static char *iManufacturer;
 module_param(iManufacturer, charp, S_IRUGO);
 MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
@@ -1418,6 +1405,30 @@ static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
        return *desc;
 }
 
+static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
+               const struct usb_device_descriptor *old)
+{
+       __le16 idVendor;
+       __le16 idProduct;
+       __le16 bcdDevice;
+
+       /*
+        * these variables may have been set in
+        * usb_composite_overwrite_options()
+        */
+       idVendor = new->idVendor;
+       idProduct = new->idProduct;
+       bcdDevice = new->bcdDevice;
+
+       *new = *old;
+       if (idVendor)
+               new->idVendor = idVendor;
+       if (idProduct)
+               new->idProduct = idProduct;
+       if (bcdDevice)
+               new->bcdDevice = bcdDevice;
+}
+
 static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv)
 {
        return container_of(gdrv, struct usb_composite_driver, gadget_driver);
@@ -1473,17 +1484,7 @@ static int composite_bind(struct usb_gadget *gadget,
        if (status < 0)
                goto fail;
 
-       cdev->desc = *composite->dev;
-
-       /* standardized runtime overrides for device ID data */
-       if (idVendor)
-               cdev->desc.idVendor = cpu_to_le16(idVendor);
-
-       if (idProduct)
-               cdev->desc.idProduct = cpu_to_le16(idProduct);
-
-       if (bcdDevice)
-               cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
+       update_unchanged_dev_desc(&cdev->desc, composite->dev);
 
        /* string overrides */
        if (iManufacturer || !cdev->desc.iManufacturer) {
@@ -1686,3 +1687,17 @@ void usb_composite_setup_continue(struct usb_composite_dev *cdev)
        spin_unlock_irqrestore(&cdev->lock, flags);
 }
 
+void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
+               struct usb_composite_overwrite *covr)
+{
+       struct usb_device_descriptor    *desc = &cdev->desc;
+
+       if (covr->idVendor)
+               desc->idVendor = cpu_to_le16(covr->idVendor);
+
+       if (covr->idProduct)
+               desc->idProduct = cpu_to_le16(covr->idProduct);
+
+       if (covr->bcdDevice)
+               desc->bcdDevice = cpu_to_le16(covr->bcdDevice);
+}
index 004c6ed79e3b8c47b592b8f75476e559b1e3557f..709ef22655966764ee49350f39a3603cd6c41973 100644 (file)
@@ -114,6 +114,7 @@ static inline bool has_rndis(void)
 #include "u_ether.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!!  Ever!!
  * Instead:  allocate your own, using normal USB-IF procedures.
@@ -363,6 +364,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto fail;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
                        DRIVER_DESC);
 
index c3a583ea9938e92e586cbe95917213f0d7690463..a44ed661c16be421566d1b1bc9d68b81949e49ef 100644 (file)
@@ -73,6 +73,8 @@ struct gfs_ffs_obj {
        struct ffs_data *ffs_data;
 };
 
+USB_GADGET_COMPOSITE_OPTIONS();
+
 static struct usb_device_descriptor gfs_dev_desc = {
        .bLength                = sizeof gfs_dev_desc,
        .bDescriptorType        = USB_DT_DEVICE,
@@ -377,7 +379,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
                if (unlikely(ret < 0))
                        goto error_unbind;
        }
-
+       usb_composite_overwrite_options(cdev, &coverwrite);
        return 0;
 
 error_unbind:
index 68f8c032ba6b253fd5a569ab7271c4c48e4800b7..01b31e2d03afac803a3afb4e6643cae16c6df6ab 100644 (file)
@@ -48,6 +48,8 @@ MODULE_LICENSE("GPL v2");
 static const char shortname[] = "g_midi";
 static const char longname[] = "MIDI Gadget";
 
+USB_GADGET_COMPOSITE_OPTIONS();
+
 static int index = SNDRV_DEFAULT_IDX1;
 module_param(index, int, S_IRUGO);
 MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter.");
@@ -163,7 +165,7 @@ static int __init midi_bind(struct usb_composite_dev *cdev)
        status = usb_add_config(cdev, &midi_config, midi_bind_config);
        if (status < 0)
                return status;
-
+       usb_composite_overwrite_options(cdev, &coverwrite);
        pr_info("%s\n", longname);
        return 0;
 }
index 1e3f03be94dfa06e4206a4fe9271e39c4a51a063..59fe7eef00da043cb0c9b58c9bcf7e663161931b 100644 (file)
@@ -48,6 +48,7 @@ struct hidg_func_node {
 static LIST_HEAD(hidg_func_list);
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static struct usb_device_descriptor device_desc = {
        .bLength =              sizeof device_desc,
@@ -188,6 +189,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                return status;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
 
        return 0;
index 0b0f008427ed6c712fe337252729a25842afb156..8ffbade383f22d2f7b8de32394ece97e76ca167f 100644 (file)
@@ -52,6 +52,7 @@
 #include "f_mass_storage.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static struct usb_device_descriptor msg_device_desc = {
        .bLength =              sizeof msg_device_desc,
@@ -143,7 +144,7 @@ static int __init msg_bind(struct usb_composite_dev *cdev)
        status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
        if (status < 0)
                return status;
-
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&cdev->gadget->dev,
                 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
        set_bit(0, &msg_registered);
index 72fb30141ff4784c5d0de1704558f0237e24b227..60168877330a6d83fafa95e786977fc1ab0111f1 100644 (file)
@@ -58,7 +58,7 @@ MODULE_LICENSE("GPL");
 #endif
 #include "u_ether.c"
 
-
+USB_GADGET_COMPOSITE_OPTIONS();
 
 /***************************** Device Descriptor ****************************/
 
@@ -307,6 +307,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
        status = cdc_config_register(cdev);
        if (unlikely(status < 0))
                goto fail2;
+       usb_composite_overwrite_options(cdev, &coverwrite);
 
        /* we're done */
        dev_info(&gadget->dev, DRIVER_DESC "\n");
index 6c7e159845353565b5a90e141943abb5cf942481..8537cd9c6affffcc6ab1e38a84c7bfddefc038e2 100644 (file)
@@ -54,6 +54,7 @@
 #define CDC_PRODUCT_NUM                0xa4a1  /* Linux-USB Ethernet Gadget */
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static struct usb_device_descriptor device_desc = {
        .bLength =              sizeof device_desc,
@@ -191,6 +192,7 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto fail;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, "%s\n", DRIVER_DESC);
 
        return 0;
index b0893136a05db011c71108ab954a7f7b100756bf..5ed927b16c0e3d7dd0a84f840f7b2e5abd1be136 100644 (file)
@@ -49,6 +49,7 @@
 #include "u_ether.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 #define NOKIA_VENDOR_ID                        0x0421  /* Nokia */
 #define NOKIA_PRODUCT_ID               0x01c8  /* Nokia Gadget */
@@ -197,6 +198,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto err_usb;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
 
        return 0;
index 51b6e7bf413eb6377b8b7940d5ee56c67f27a976..3fa4d80629cc657217b4c209af0b25c7dc74cbee 100644 (file)
@@ -54,6 +54,7 @@
 #include "composite.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 #define DRIVER_DESC            "Printer Gadget"
 #define DRIVER_VERSION         "2007 OCT 06"
@@ -1265,6 +1266,9 @@ static int __init printer_bind(struct usb_composite_dev *cdev)
        device_desc.iSerialNumber = strings[STRING_SERIALNUM].id;
 
        ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config);
+       if (ret)
+               return ret;
+       usb_composite_overwrite_options(cdev, &coverwrite);
        return ret;
 }
 
index 9962504e14f1148e095093448bcd43f649bcd08f..27b5ce939bdb7b131a0d9c19e53d87a65d85d5aa 100644 (file)
@@ -45,6 +45,7 @@
 #include "u_serial.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 /* Thanks to NetChip Technologies for donating this product ID.
 *
@@ -212,6 +213,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
        if (status < 0)
                goto fail;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        INFO(cdev, "%s\n", GS_VERSION_NAME);
 
        return 0;
index 2f4980881a8089352bddf7d6b0df41a301f42d1c..fa3137ef228b8f1b3317e8af681a0fadba4e91c0 100644 (file)
@@ -29,6 +29,8 @@
 
 #include "tcm_usb_gadget.h"
 
+USB_GADGET_COMPOSITE_OPTIONS();
+
 static struct target_fabric_configfs *usbg_fabric_configfs;
 
 static inline struct f_uas *to_f_uas(struct usb_function *f)
@@ -2437,6 +2439,9 @@ static int usb_target_bind(struct usb_composite_dev *cdev)
 
        ret = usb_add_config(cdev, &usbg_config_driver,
                        usbg_cfg_bind);
+       if (ret)
+               return ret;
+       usb_composite_overwrite_options(cdev, &coverwrite);
        return 0;
 }
 
index d44a4510a65ada2529816beb6a297645a1799fdf..306006419f383ab006958de29faf1864831da722 100644 (file)
@@ -30,6 +30,7 @@
 #include "uvc_v4l2.c"
 #include "f_uvc.c"
 
+USB_GADGET_COMPOSITE_OPTIONS();
 /* --------------------------------------------------------------------------
  * Device descriptor
  */
@@ -370,6 +371,7 @@ webcam_bind(struct usb_composite_dev *cdev)
                                        webcam_config_bind)) < 0)
                goto error;
 
+       usb_composite_overwrite_options(cdev, &coverwrite);
        INFO(cdev, "Webcam Video Gadget\n");
        return 0;
 
index dbc336e3ba981fc20ff69041e237e2187d6fb2d2..2b31a4ae26b93ca6f814b4ac8e48c345b6611301 100644 (file)
@@ -64,6 +64,7 @@
 #include "f_loopback.c"
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 #define DRIVER_VERSION         "Cinco de Mayo 2008"
 
@@ -305,6 +306,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
                        longname, gadget->name);
                device_desc.bcdDevice = cpu_to_le16(0x9999);
        }
+       usb_composite_overwrite_options(cdev, &coverwrite);
 
        INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
 
index e970fba6dbbbccd9922f4baf354f5a25add2f1a2..7651e5bf74872c63f7960ad5d304cc8f470dcb15 100644 (file)
@@ -381,6 +381,30 @@ extern int usb_string_ids_tab(struct usb_composite_dev *c,
                              struct usb_string *str);
 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
 
+/*
+ * 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).
+ */
+struct usb_composite_overwrite {
+       u16     idVendor;
+       u16     idProduct;
+       u16     bcdDevice;
+};
+#define USB_GADGET_COMPOSITE_OPTIONS()                                 \
+       static struct usb_composite_overwrite coverwrite;               \
+                                                                       \
+       module_param_named(idVendor, coverwrite.idVendor, ushort, S_IRUGO); \
+       MODULE_PARM_DESC(idVendor, "USB Vendor ID");                    \
+                                                                       \
+       module_param_named(idProduct, coverwrite.idProduct, ushort, S_IRUGO); \
+       MODULE_PARM_DESC(idProduct, "USB Product ID");                  \
+                                                                       \
+       module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \
+       MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)")
+
+void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
+               struct usb_composite_overwrite *covr);
 
 /* messaging utils */
 #define DBG(d, fmt, args...) \