[PATCH 9/9] usb/gadget: push VID/PID/USB BCD module option into gadgets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
 drivers/usb/gadget/acm_ms.c         |    3 ++-
 drivers/usb/gadget/audio.c          |    3 ++-
 drivers/usb/gadget/cdc2.c           |    3 ++-
 drivers/usb/gadget/composite.c      |   23 -----------------------
 drivers/usb/gadget/ether.c          |    3 ++-
 drivers/usb/gadget/g_ffs.c          |    4 +++-
 drivers/usb/gadget/gmidi.c          |    3 ++-
 drivers/usb/gadget/hid.c            |    2 ++
 drivers/usb/gadget/mass_storage.c   |    3 ++-
 drivers/usb/gadget/multi.c          |    3 ++-
 drivers/usb/gadget/ncm.c            |    2 ++
 drivers/usb/gadget/nokia.c          |    2 ++
 drivers/usb/gadget/printer.c        |    9 ++++++++-
 drivers/usb/gadget/serial.c         |    2 ++
 drivers/usb/gadget/tcm_usb_gadget.c |    4 ++++
 drivers/usb/gadget/webcam.c         |    2 ++
 drivers/usb/gadget/zero.c           |    2 ++
 include/linux/usb/composite.h       |   28 ++++++++++++++++++++++++++++
 18 files changed, 69 insertions(+), 32 deletions(-)

diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 5db661d..bef987a 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -151,7 +151,7 @@ static struct usb_configuration acm_ms_config_driver = {
 };
 
 /*-------------------------------------------------------------------------*/
-
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init acm_ms_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -209,6 +209,7 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto fail1;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
 			DRIVER_DESC);
 	fsg_common_put(&fsg_common);
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 689d142..2d05734 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -144,7 +144,7 @@ static struct usb_configuration audio_config_driver = {
 };
 
 /*-------------------------------------------------------------------------*/
-
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init audio_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -180,6 +180,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_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 
 	INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
 	return 0;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 8e386cf..8878414 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -146,7 +146,7 @@ static struct usb_configuration cdc_config_driver = {
 };
 
 /*-------------------------------------------------------------------------*/
-
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init cdc_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -210,6 +210,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto fail1;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
 			DRIVER_DESC);
 
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 153efc4..aac450e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -32,19 +32,6 @@
  * 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");
@@ -1475,16 +1462,6 @@ static int composite_bind(struct usb_gadget *gadget,
 
 	cdev->desc = *cdriver->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);
-
 	/* string overrides */
 	if (iManufacturer || !cdev->desc.iManufacturer) {
 		if (!iManufacturer && !cdriver->iManufacturer &&
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 39eb718..512a4f8 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -282,7 +282,7 @@ static struct usb_configuration eth_config_driver = {
 };
 
 /*-------------------------------------------------------------------------*/
-
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init eth_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -369,6 +369,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto fail;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
 			DRIVER_DESC);
 
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index c3a583e..9d04451 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -338,6 +338,8 @@ static void functionfs_release_dev_callback(struct ffs_data *ffs_data)
 /*
  * It is assumed that gfs_bind is called from a context where gfs_lock is held
  */
+USB_GADGET_COMPOSITE_OPTIONS();
+
 static int gfs_bind(struct usb_composite_dev *cdev)
 {
 	int ret, i;
@@ -377,7 +379,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
 		if (unlikely(ret < 0))
 			goto error_unbind;
 	}
-
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(gfs_dev_desc);
 	return 0;
 
 error_unbind:
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 0c70708..c804c03 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -135,6 +135,7 @@ static int __init midi_bind_config(struct usb_configuration *c)
 				  buflen, qlen);
 }
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init midi_bind(struct usb_composite_dev *cdev)
 {
 	struct usb_gadget *gadget = cdev->gadget;
@@ -176,7 +177,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_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	pr_info("%s\n", longname);
 	return 0;
 }
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 4880cdd..6b9346c 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -143,6 +143,7 @@ static struct usb_configuration config_driver = {
 };
 
 /****************************** Gadget Bind ******************************/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static int __init hid_bind(struct usb_composite_dev *cdev)
 {
@@ -193,6 +194,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		return status;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
 
 	return 0;
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 0b0f008..4a20743 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -135,6 +135,7 @@ static struct usb_configuration msg_config_driver = {
 
 
 /****************************** Gadget Bind ******************************/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static int __init msg_bind(struct usb_composite_dev *cdev)
 {
@@ -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_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(msg_device_desc);
 	dev_info(&cdev->gadget->dev,
 		 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
 	set_bit(0, &msg_registered);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 72fb301..437285f 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -252,7 +252,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
 
 
 /****************************** Gadget Bind ******************************/
-
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static int __ref multi_bind(struct usb_composite_dev *cdev)
 {
@@ -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_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 
 	/* we're done */
 	dev_info(&gadget->dev, DRIVER_DESC "\n");
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index 69b660b..0bab8f2 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -143,6 +143,7 @@ static struct usb_configuration ncm_config_driver = {
 };
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static int __init gncm_bind(struct usb_composite_dev *cdev)
 {
@@ -197,6 +198,7 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto fail;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, "%s\n", DRIVER_DESC);
 
 	return 0;
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 6834c62..775f637 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -146,6 +146,7 @@ static struct usb_configuration nokia_config_100ma_driver = {
 	.bMaxPower	= 50, /* 100 mA */
 };
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init nokia_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -211,6 +212,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto err_usb;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
 
 	return 0;
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 3d3d20d..3edbff6 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -1261,9 +1261,16 @@ static int printer_unbind(struct usb_composite_dev *cdev)
 	return 0;
 }
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init printer_bind(struct usb_composite_dev *cdev)
 {
-	return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config);
+	int ret;
+
+	ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config);
+	if (ret)
+		return ret;
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
+	return 0;
 }
 
 static __refdata struct usb_composite_driver printer_driver = {
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 098c3d0..02b9327 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -157,6 +157,7 @@ static struct usb_configuration serial_config_driver = {
 	.bmAttributes	= USB_CONFIG_ATT_SELFPOWER,
 };
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init gs_bind(struct usb_composite_dev *cdev)
 {
 	int			gcnum;
@@ -226,6 +227,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
 	if (status < 0)
 		goto fail;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 	INFO(cdev, "%s\n", GS_VERSION_NAME);
 
 	return 0;
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c
index e64a759..1561374 100644
--- a/drivers/usb/gadget/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/tcm_usb_gadget.c
@@ -2424,12 +2424,16 @@ err:
 	return ret;
 }
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int usb_target_bind(struct usb_composite_dev *cdev)
 {
 	int ret;
 
 	ret = usb_add_config(cdev, &usbg_config_driver,
 			usbg_cfg_bind);
+	if (ret)
+		return ret;
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(usbg_device_desc);
 	return 0;
 }
 
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index 66dfca8..ac5b462 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -347,6 +347,7 @@ webcam_unbind(struct usb_composite_dev *cdev)
 	return 0;
 }
 
+USB_GADGET_COMPOSITE_OPTIONS();
 static int __init
 webcam_bind(struct usb_composite_dev *cdev)
 {
@@ -375,6 +376,7 @@ webcam_bind(struct usb_composite_dev *cdev)
 					webcam_config_bind)) < 0)
 		goto error;
 
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(webcam_device_descriptor);
 	INFO(cdev, "Webcam Video Gadget\n");
 	return 0;
 
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 9a9adee..59e40bf 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -259,6 +259,7 @@ static void zero_resume(struct usb_composite_dev *cdev)
 }
 
 /*-------------------------------------------------------------------------*/
+USB_GADGET_COMPOSITE_OPTIONS();
 
 static int __init zero_bind(struct usb_composite_dev *cdev)
 {
@@ -315,6 +316,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
 			longname, gadget->name);
 		device_desc.bcdDevice = cpu_to_le16(0x9999);
 	}
+	USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(device_desc);
 
 	INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
 
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index e970fba..bc84afc 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -381,6 +381,34 @@ 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).
+ */
+#define USB_GADGET_COMPOSITE_OPTIONS()					\
+	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)")
+
+#define USB_GADGET_COMPOSITE_OVERWRITE_VID_PID_BCD(__usb_desc)		\
+	if (idVendor)							\
+		__usb_desc.idVendor = cpu_to_le16(idVendor);		\
+									\
+	if (idProduct)							\
+		__usb_desc.idProduct = cpu_to_le16(idProduct);		\
+									\
+	if (bcdDevice)							\
+		__usb_desc.bcdDevice = cpu_to_le16(bcdDevice)
+
 
 /* messaging utils */
 #define DBG(d, fmt, args...) \
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux