Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d16e8d3 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi
Browse files

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: 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 3b4a3fc0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
+3 −0
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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);

+39 −24
Original line number Diff line number Diff line
@@ -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");
@@ -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);
}
+2 −0
Original line number Diff line number Diff line
@@ -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);

Loading