summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-02-09 09:38:26 -0500
committerColin Cross <ccross@android.com>2011-06-14 09:09:53 -0700
commitaecca43f09d029eb98bec88b6da3b3c6897e42f5 (patch)
tree10e0615a2b05f5444cafcbebd18f359713c7ab24
parent6bb1acf2eba2dd5200bd935286b3d9f130b71c3b (diff)
USB: gadget: android: Support switching vendor ID when configuration changes
Based on the list of enabled USB functions, we can now switch the vendor ID as well as the product ID. Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--drivers/usb/gadget/android.c32
-rw-r--r--include/linux/usb/android_composite.h7
2 files changed, 31 insertions, 8 deletions
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c
index 3d3fc795c4c..e49ef2c470d 100644
--- a/drivers/usb/gadget/android.c
+++ b/drivers/usb/gadget/android.c
@@ -65,6 +65,7 @@ struct android_dev {
int num_functions;
char **functions;
+ int vendor_id;
int product_id;
int version;
};
@@ -254,6 +255,22 @@ static int product_matches_functions(struct android_usb_product *p)
return 1;
}
+static int get_vendor_id(struct android_dev *dev)
+{
+ struct android_usb_product *p = dev->products;
+ int count = dev->num_products;
+ int i;
+
+ if (p) {
+ for (i = 0; i < count; i++, p++) {
+ if (p->vendor_id && product_matches_functions(p))
+ return p->vendor_id;
+ }
+ }
+ /* use default vendor ID */
+ return dev->vendor_id;
+}
+
static int get_product_id(struct android_dev *dev)
{
struct android_usb_product *p = dev->products;
@@ -274,7 +291,7 @@ static int android_bind(struct usb_composite_dev *cdev)
{
struct android_dev *dev = _android_dev;
struct usb_gadget *gadget = cdev->gadget;
- int gcnum, id, product_id, ret;
+ int gcnum, id, ret;
printk(KERN_INFO "android_bind\n");
@@ -324,8 +341,8 @@ static int android_bind(struct usb_composite_dev *cdev)
usb_gadget_set_selfpowered(gadget);
dev->cdev = cdev;
- product_id = get_product_id(dev);
- device_desc.idProduct = __constant_cpu_to_le16(product_id);
+ device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev));
+ device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev));
cdev->desc.idProduct = device_desc.idProduct;
return 0;
@@ -394,7 +411,6 @@ void android_enable_function(struct usb_function *f, int enable)
{
struct android_dev *dev = _android_dev;
int disable = !enable;
- int product_id;
if (!!f->disabled != disable) {
usb_function_set_enabled(f, !disable);
@@ -416,8 +432,8 @@ void android_enable_function(struct usb_function *f, int enable)
update_dev_desc(dev);
- product_id = get_product_id(dev);
- device_desc.idProduct = __constant_cpu_to_le16(product_id);
+ device_desc.idVendor = __constant_cpu_to_le16(get_vendor_id(dev));
+ device_desc.idProduct = __constant_cpu_to_le16(get_product_id(dev));
if (dev->cdev)
dev->cdev->desc.idProduct = device_desc.idProduct;
usb_composite_force_reset(dev->cdev);
@@ -436,9 +452,11 @@ static int android_probe(struct platform_device *pdev)
dev->num_products = pdata->num_products;
dev->functions = pdata->functions;
dev->num_functions = pdata->num_functions;
- if (pdata->vendor_id)
+ if (pdata->vendor_id) {
+ dev->vendor_id = pdata->vendor_id;
device_desc.idVendor =
__constant_cpu_to_le16(pdata->vendor_id);
+ }
if (pdata->product_id) {
dev->product_id = pdata->product_id;
device_desc.idProduct =
diff --git a/include/linux/usb/android_composite.h b/include/linux/usb/android_composite.h
index 62e72e3bd2b..7f9000711f4 100644
--- a/include/linux/usb/android_composite.h
+++ b/include/linux/usb/android_composite.h
@@ -27,7 +27,12 @@ struct android_usb_function {
};
struct android_usb_product {
- /* Default product ID. */
+ /* Vendor ID for this set of functions.
+ * Default vendor_id in platform data will be used if this is zero.
+ */
+ __u16 vendor_id;
+
+ /* Product ID for this set of functions. */
__u16 product_id;
/* List of function names associated with this product.