Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: push VID/PID/USB BCD module option into gadgets

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>

authored by

Sebastian Andrzej Siewior and committed by
Felipe Balbi
7d16e8d3 3b4a3fc0

+103 -28
+2
drivers/usb/gadget/acm_ms.c
··· 47 47 #include "f_mass_storage.c" 48 48 49 49 /*-------------------------------------------------------------------------*/ 50 + USB_GADGET_COMPOSITE_OPTIONS(); 50 51 51 52 static struct usb_device_descriptor device_desc = { 52 53 .bLength = sizeof device_desc, ··· 204 203 if (status < 0) 205 204 goto fail1; 206 205 206 + usb_composite_overwrite_options(cdev, &coverwrite); 207 207 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 208 208 DRIVER_DESC); 209 209 fsg_common_put(&fsg_common);
+3
drivers/usb/gadget/audio.c
··· 13 13 14 14 #include <linux/kernel.h> 15 15 #include <linux/utsname.h> 16 + #include <linux/usb/composite.h> 16 17 17 18 #include "gadget_chips.h" 18 19 #define DRIVER_DESC "Linux USB Audio Gadget" ··· 29 28 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 30 29 */ 31 30 #include "composite.c" 31 + USB_GADGET_COMPOSITE_OPTIONS(); 32 32 33 33 /* string IDs are assigned dynamically */ 34 34 ··· 176 174 status = usb_add_config(cdev, &audio_config_driver, audio_do_config); 177 175 if (status < 0) 178 176 goto fail; 177 + usb_composite_overwrite_options(cdev, &coverwrite); 179 178 180 179 INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION); 181 180 return 0;
+2
drivers/usb/gadget/cdc2.c
··· 34 34 #define CDC_PRODUCT_NUM 0xa4aa /* CDC Composite: ECM + ACM */ 35 35 36 36 /*-------------------------------------------------------------------------*/ 37 + USB_GADGET_COMPOSITE_OPTIONS(); 37 38 38 39 /* 39 40 * Kbuild is not very cooperative with respect to linking separately ··· 205 204 if (status < 0) 206 205 goto fail1; 207 206 207 + usb_composite_overwrite_options(cdev, &coverwrite); 208 208 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 209 209 DRIVER_DESC); 210 210
+39 -24
drivers/usb/gadget/composite.c
··· 32 32 * published in the device descriptor, either numbers or strings or both. 33 33 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 34 34 */ 35 - 36 - static ushort idVendor; 37 - module_param(idVendor, ushort, S_IRUGO); 38 - MODULE_PARM_DESC(idVendor, "USB Vendor ID"); 39 - 40 - static ushort idProduct; 41 - module_param(idProduct, ushort, S_IRUGO); 42 - MODULE_PARM_DESC(idProduct, "USB Product ID"); 43 - 44 - static ushort bcdDevice; 45 - module_param(bcdDevice, ushort, S_IRUGO); 46 - MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); 47 - 48 35 static char *iManufacturer; 49 36 module_param(iManufacturer, charp, S_IRUGO); 50 37 MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); ··· 1405 1418 return *desc; 1406 1419 } 1407 1420 1421 + static void update_unchanged_dev_desc(struct usb_device_descriptor *new, 1422 + const struct usb_device_descriptor *old) 1423 + { 1424 + __le16 idVendor; 1425 + __le16 idProduct; 1426 + __le16 bcdDevice; 1427 + 1428 + /* 1429 + * these variables may have been set in 1430 + * usb_composite_overwrite_options() 1431 + */ 1432 + idVendor = new->idVendor; 1433 + idProduct = new->idProduct; 1434 + bcdDevice = new->bcdDevice; 1435 + 1436 + *new = *old; 1437 + if (idVendor) 1438 + new->idVendor = idVendor; 1439 + if (idProduct) 1440 + new->idProduct = idProduct; 1441 + if (bcdDevice) 1442 + new->bcdDevice = bcdDevice; 1443 + } 1444 + 1408 1445 static struct usb_composite_driver *to_cdriver(struct usb_gadget_driver *gdrv) 1409 1446 { 1410 1447 return container_of(gdrv, struct usb_composite_driver, gadget_driver); ··· 1484 1473 if (status < 0) 1485 1474 goto fail; 1486 1475 1487 - cdev->desc = *composite->dev; 1488 - 1489 - /* standardized runtime overrides for device ID data */ 1490 - if (idVendor) 1491 - cdev->desc.idVendor = cpu_to_le16(idVendor); 1492 - 1493 - if (idProduct) 1494 - cdev->desc.idProduct = cpu_to_le16(idProduct); 1495 - 1496 - if (bcdDevice) 1497 - cdev->desc.bcdDevice = cpu_to_le16(bcdDevice); 1476 + update_unchanged_dev_desc(&cdev->desc, composite->dev); 1498 1477 1499 1478 /* string overrides */ 1500 1479 if (iManufacturer || !cdev->desc.iManufacturer) { ··· 1687 1686 spin_unlock_irqrestore(&cdev->lock, flags); 1688 1687 } 1689 1688 1689 + void usb_composite_overwrite_options(struct usb_composite_dev *cdev, 1690 + struct usb_composite_overwrite *covr) 1691 + { 1692 + struct usb_device_descriptor *desc = &cdev->desc; 1693 + 1694 + if (covr->idVendor) 1695 + desc->idVendor = cpu_to_le16(covr->idVendor); 1696 + 1697 + if (covr->idProduct) 1698 + desc->idProduct = cpu_to_le16(covr->idProduct); 1699 + 1700 + if (covr->bcdDevice) 1701 + desc->bcdDevice = cpu_to_le16(covr->bcdDevice); 1702 + }
+2
drivers/usb/gadget/ether.c
··· 114 114 #include "u_ether.c" 115 115 116 116 /*-------------------------------------------------------------------------*/ 117 + USB_GADGET_COMPOSITE_OPTIONS(); 117 118 118 119 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 119 120 * Instead: allocate your own, using normal USB-IF procedures. ··· 364 363 if (status < 0) 365 364 goto fail; 366 365 366 + usb_composite_overwrite_options(cdev, &coverwrite); 367 367 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 368 368 DRIVER_DESC); 369 369
+3 -1
drivers/usb/gadget/g_ffs.c
··· 73 73 struct ffs_data *ffs_data; 74 74 }; 75 75 76 + USB_GADGET_COMPOSITE_OPTIONS(); 77 + 76 78 static struct usb_device_descriptor gfs_dev_desc = { 77 79 .bLength = sizeof gfs_dev_desc, 78 80 .bDescriptorType = USB_DT_DEVICE, ··· 379 377 if (unlikely(ret < 0)) 380 378 goto error_unbind; 381 379 } 382 - 380 + usb_composite_overwrite_options(cdev, &coverwrite); 383 381 return 0; 384 382 385 383 error_unbind:
+3 -1
drivers/usb/gadget/gmidi.c
··· 48 48 static const char shortname[] = "g_midi"; 49 49 static const char longname[] = "MIDI Gadget"; 50 50 51 + USB_GADGET_COMPOSITE_OPTIONS(); 52 + 51 53 static int index = SNDRV_DEFAULT_IDX1; 52 54 module_param(index, int, S_IRUGO); 53 55 MODULE_PARM_DESC(index, "Index value for the USB MIDI Gadget adapter."); ··· 165 163 status = usb_add_config(cdev, &midi_config, midi_bind_config); 166 164 if (status < 0) 167 165 return status; 168 - 166 + usb_composite_overwrite_options(cdev, &coverwrite); 169 167 pr_info("%s\n", longname); 170 168 return 0; 171 169 }
+2
drivers/usb/gadget/hid.c
··· 48 48 static LIST_HEAD(hidg_func_list); 49 49 50 50 /*-------------------------------------------------------------------------*/ 51 + USB_GADGET_COMPOSITE_OPTIONS(); 51 52 52 53 static struct usb_device_descriptor device_desc = { 53 54 .bLength = sizeof device_desc, ··· 189 188 if (status < 0) 190 189 return status; 191 190 191 + usb_composite_overwrite_options(cdev, &coverwrite); 192 192 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 193 193 194 194 return 0;
+2 -1
drivers/usb/gadget/mass_storage.c
··· 52 52 #include "f_mass_storage.c" 53 53 54 54 /*-------------------------------------------------------------------------*/ 55 + USB_GADGET_COMPOSITE_OPTIONS(); 55 56 56 57 static struct usb_device_descriptor msg_device_desc = { 57 58 .bLength = sizeof msg_device_desc, ··· 144 143 status = usb_add_config(cdev, &msg_config_driver, msg_do_config); 145 144 if (status < 0) 146 145 return status; 147 - 146 + usb_composite_overwrite_options(cdev, &coverwrite); 148 147 dev_info(&cdev->gadget->dev, 149 148 DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 150 149 set_bit(0, &msg_registered);
+2 -1
drivers/usb/gadget/multi.c
··· 58 58 #endif 59 59 #include "u_ether.c" 60 60 61 - 61 + USB_GADGET_COMPOSITE_OPTIONS(); 62 62 63 63 /***************************** Device Descriptor ****************************/ 64 64 ··· 307 307 status = cdc_config_register(cdev); 308 308 if (unlikely(status < 0)) 309 309 goto fail2; 310 + usb_composite_overwrite_options(cdev, &coverwrite); 310 311 311 312 /* we're done */ 312 313 dev_info(&gadget->dev, DRIVER_DESC "\n");
+2
drivers/usb/gadget/ncm.c
··· 54 54 #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ 55 55 56 56 /*-------------------------------------------------------------------------*/ 57 + USB_GADGET_COMPOSITE_OPTIONS(); 57 58 58 59 static struct usb_device_descriptor device_desc = { 59 60 .bLength = sizeof device_desc, ··· 192 191 if (status < 0) 193 192 goto fail; 194 193 194 + usb_composite_overwrite_options(cdev, &coverwrite); 195 195 dev_info(&gadget->dev, "%s\n", DRIVER_DESC); 196 196 197 197 return 0;
+2
drivers/usb/gadget/nokia.c
··· 49 49 #include "u_ether.c" 50 50 51 51 /*-------------------------------------------------------------------------*/ 52 + USB_GADGET_COMPOSITE_OPTIONS(); 52 53 53 54 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */ 54 55 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */ ··· 198 197 if (status < 0) 199 198 goto err_usb; 200 199 200 + usb_composite_overwrite_options(cdev, &coverwrite); 201 201 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); 202 202 203 203 return 0;
+4
drivers/usb/gadget/printer.c
··· 54 54 #include "composite.c" 55 55 56 56 /*-------------------------------------------------------------------------*/ 57 + USB_GADGET_COMPOSITE_OPTIONS(); 57 58 58 59 #define DRIVER_DESC "Printer Gadget" 59 60 #define DRIVER_VERSION "2007 OCT 06" ··· 1266 1265 device_desc.iSerialNumber = strings[STRING_SERIALNUM].id; 1267 1266 1268 1267 ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); 1268 + if (ret) 1269 + return ret; 1270 + usb_composite_overwrite_options(cdev, &coverwrite); 1269 1271 return ret; 1270 1272 } 1271 1273
+2
drivers/usb/gadget/serial.c
··· 45 45 #include "u_serial.c" 46 46 47 47 /*-------------------------------------------------------------------------*/ 48 + USB_GADGET_COMPOSITE_OPTIONS(); 48 49 49 50 /* Thanks to NetChip Technologies for donating this product ID. 50 51 * ··· 213 212 if (status < 0) 214 213 goto fail; 215 214 215 + usb_composite_overwrite_options(cdev, &coverwrite); 216 216 INFO(cdev, "%s\n", GS_VERSION_NAME); 217 217 218 218 return 0;
+5
drivers/usb/gadget/tcm_usb_gadget.c
··· 29 29 30 30 #include "tcm_usb_gadget.h" 31 31 32 + USB_GADGET_COMPOSITE_OPTIONS(); 33 + 32 34 static struct target_fabric_configfs *usbg_fabric_configfs; 33 35 34 36 static inline struct f_uas *to_f_uas(struct usb_function *f) ··· 2439 2437 2440 2438 ret = usb_add_config(cdev, &usbg_config_driver, 2441 2439 usbg_cfg_bind); 2440 + if (ret) 2441 + return ret; 2442 + usb_composite_overwrite_options(cdev, &coverwrite); 2442 2443 return 0; 2443 2444 } 2444 2445
+2
drivers/usb/gadget/webcam.c
··· 30 30 #include "uvc_v4l2.c" 31 31 #include "f_uvc.c" 32 32 33 + USB_GADGET_COMPOSITE_OPTIONS(); 33 34 /* -------------------------------------------------------------------------- 34 35 * Device descriptor 35 36 */ ··· 371 370 webcam_config_bind)) < 0) 372 371 goto error; 373 372 373 + usb_composite_overwrite_options(cdev, &coverwrite); 374 374 INFO(cdev, "Webcam Video Gadget\n"); 375 375 return 0; 376 376
+2
drivers/usb/gadget/zero.c
··· 64 64 #include "f_loopback.c" 65 65 66 66 /*-------------------------------------------------------------------------*/ 67 + USB_GADGET_COMPOSITE_OPTIONS(); 67 68 68 69 #define DRIVER_VERSION "Cinco de Mayo 2008" 69 70 ··· 306 305 longname, gadget->name); 307 306 device_desc.bcdDevice = cpu_to_le16(0x9999); 308 307 } 308 + usb_composite_overwrite_options(cdev, &coverwrite); 309 309 310 310 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); 311 311
+24
include/linux/usb/composite.h
··· 381 381 struct usb_string *str); 382 382 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 383 383 384 + /* 385 + * Some systems will need runtime overrides for the product identifiers 386 + * published in the device descriptor, either numbers or strings or both. 387 + * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 388 + */ 389 + struct usb_composite_overwrite { 390 + u16 idVendor; 391 + u16 idProduct; 392 + u16 bcdDevice; 393 + }; 394 + #define USB_GADGET_COMPOSITE_OPTIONS() \ 395 + static struct usb_composite_overwrite coverwrite; \ 396 + \ 397 + module_param_named(idVendor, coverwrite.idVendor, ushort, S_IRUGO); \ 398 + MODULE_PARM_DESC(idVendor, "USB Vendor ID"); \ 399 + \ 400 + module_param_named(idProduct, coverwrite.idProduct, ushort, S_IRUGO); \ 401 + MODULE_PARM_DESC(idProduct, "USB Product ID"); \ 402 + \ 403 + module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \ 404 + MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)") 405 + 406 + void usb_composite_overwrite_options(struct usb_composite_dev *cdev, 407 + struct usb_composite_overwrite *covr); 384 408 385 409 /* messaging utils */ 386 410 #define DBG(d, fmt, args...) \