aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2012-09-10 03:16:07 -0400
committerFelipe Balbi <balbi@ti.com>2012-09-10 09:43:24 -0400
commited9cbda63d45638b69ce62412e3a3c7b00644835 (patch)
tree37db67a0df54bb9d9fb26b9e8c043b21551a3830
parent9c6d196d5aa35e07482f23c3e37755e7a82140e0 (diff)
usb: gadget: remove usb_gadget_controller_number()
The bcdDevice field is defined as |Device release number in binary-coded decimal in the USB 2.0 specification. We use this field to distinguish the UDCs from each other. In theory this could be used on the host side to apply certain quirks if the "special" UDC in combination with this gadget is used. This hasn't been done as far as I am aware. In practice it would be better to fix the UDC driver before shipping since a later release might not need this quirk anymore. There are some driver in tree (on the host side) which use the bcdDevice field to figure out special workarounds for a given firmware revision. This seems to make sense. Therefore this patch converts all gadgets (except a few) to use the kernel version instead a random 2 or 3 plus the UDC number. The few that don't report kernel's version are: - webcam This one reports always a version 0x10 so allow it to do so in future. - nokia This one reports always 0x211. The comment says that this gadget works only if the UDC supports altsettings so I added a check for this. - serial This one reports 0x2400 + UDC number. Since the gadget version is 2.4 this could make sense. Therefore bcdDevice is 0x2400 here. I also remove various gadget_is_<name> macros which are unused. The remaining few macros should be moved to feature / bug bitfield. Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--drivers/usb/gadget/Makefile2
-rw-r--r--drivers/usb/gadget/acm_ms.c13
-rw-r--r--drivers/usb/gadget/audio.c12
-rw-r--r--drivers/usb/gadget/cdc2.c16
-rw-r--r--drivers/usb/gadget/composite.c2
-rw-r--r--drivers/usb/gadget/ether.c17
-rw-r--r--drivers/usb/gadget/f_mass_storage.c15
-rw-r--r--drivers/usb/gadget/file_storage.c14
-rw-r--r--drivers/usb/gadget/gadget_chips.c94
-rw-r--r--drivers/usb/gadget/gadget_chips.h23
-rw-r--r--drivers/usb/gadget/gmidi.c16
-rw-r--r--drivers/usb/gadget/hid.c8
-rw-r--r--drivers/usb/gadget/multi.c11
-rw-r--r--drivers/usb/gadget/ncm.c17
-rw-r--r--drivers/usb/gadget/nokia.c14
-rw-r--r--drivers/usb/gadget/printer.c11
-rw-r--r--drivers/usb/gadget/serial.c22
-rw-r--r--drivers/usb/gadget/zero.c17
-rw-r--r--include/linux/usb/composite.h11
19 files changed, 24 insertions, 311 deletions
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 5c4a1330b49..307be5fa824 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
6obj-$(CONFIG_USB_GADGET) += udc-core.o 6obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
8libcomposite-y := usbstring.o config.o epautoconf.o 8libcomposite-y := usbstring.o config.o epautoconf.o
9libcomposite-y += gadget_chips.o composite.o 9libcomposite-y += composite.o
10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
11obj-$(CONFIG_USB_NET2272) += net2272.o 11obj-$(CONFIG_USB_NET2272) += net2272.o
12obj-$(CONFIG_USB_NET2280) += net2280.o 12obj-$(CONFIG_USB_NET2280) += net2280.o
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index b0abc2518b3..5a7f289805f 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -148,7 +148,6 @@ static struct usb_configuration acm_ms_config_driver = {
148 148
149static int __init acm_ms_bind(struct usb_composite_dev *cdev) 149static int __init acm_ms_bind(struct usb_composite_dev *cdev)
150{ 150{
151 int gcnum;
152 struct usb_gadget *gadget = cdev->gadget; 151 struct usb_gadget *gadget = cdev->gadget;
153 int status; 152 int status;
154 void *retp; 153 void *retp;
@@ -165,18 +164,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
165 goto fail0; 164 goto fail0;
166 } 165 }
167 166
168 /* set bcdDevice */
169 gcnum = usb_gadget_controller_number(gadget);
170 if (gcnum >= 0) {
171 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
172 } else {
173 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
174 gadget->name,
175 acm_ms_config_driver.label);
176 device_desc.bcdDevice =
177 cpu_to_le16(0x0300 | 0x0099);
178 }
179
180 /* 167 /*
181 * Allocate string descriptor numbers ... note that string 168 * Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue. 169 * contents can be overridden by the composite_dev glue.
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 1b9dee91d68..231b0efe8fd 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -135,20 +135,8 @@ static struct usb_configuration audio_config_driver = {
135 135
136static int __init audio_bind(struct usb_composite_dev *cdev) 136static int __init audio_bind(struct usb_composite_dev *cdev)
137{ 137{
138 int gcnum;
139 int status; 138 int status;
140 139
141 gcnum = usb_gadget_controller_number(cdev->gadget);
142 if (gcnum >= 0)
143 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
144 else {
145 ERROR(cdev, "controller '%s' not recognized; trying %s\n",
146 cdev->gadget->name,
147 audio_config_driver.label);
148 device_desc.bcdDevice =
149 __constant_cpu_to_le16(0x0300 | 0x0099);
150 }
151
152 status = usb_string_ids_tab(cdev, strings_dev); 140 status = usb_string_ids_tab(cdev, strings_dev);
153 if (status < 0) 141 if (status < 0)
154 goto fail; 142 goto fail;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index ba38d2a4372..1e4bb77f00b 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -143,7 +143,6 @@ static struct usb_configuration cdc_config_driver = {
143 143
144static int __init cdc_bind(struct usb_composite_dev *cdev) 144static int __init cdc_bind(struct usb_composite_dev *cdev)
145{ 145{
146 int gcnum;
147 struct usb_gadget *gadget = cdev->gadget; 146 struct usb_gadget *gadget = cdev->gadget;
148 int status; 147 int status;
149 148
@@ -163,21 +162,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
163 if (status < 0) 162 if (status < 0)
164 goto fail0; 163 goto fail0;
165 164
166 gcnum = usb_gadget_controller_number(gadget);
167 if (gcnum >= 0)
168 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
169 else {
170 /* We assume that can_support_ecm() tells the truth;
171 * but if the controller isn't recognized at all then
172 * that assumption is a bit more likely to be wrong.
173 */
174 WARNING(cdev, "controller '%s' not recognized; trying %s\n",
175 gadget->name,
176 cdc_config_driver.label);
177 device_desc.bcdDevice =
178 cpu_to_le16(0x0300 | 0x0099);
179 }
180
181 /* Allocate string descriptor numbers ... note that string 165 /* Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue. 166 * contents can be overridden by the composite_dev glue.
183 */ 167 */
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index cacb273ba70..957f973dd96 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1389,6 +1389,8 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
1389 new->idProduct = idProduct; 1389 new->idProduct = idProduct;
1390 if (bcdDevice) 1390 if (bcdDevice)
1391 new->bcdDevice = bcdDevice; 1391 new->bcdDevice = bcdDevice;
1392 else
1393 new->bcdDevice = cpu_to_le16(get_default_bcdDevice());
1392 if (iSerialNumber) 1394 if (iSerialNumber)
1393 new->iSerialNumber = iSerialNumber; 1395 new->iSerialNumber = iSerialNumber;
1394 if (iManufacturer) 1396 if (iManufacturer)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index d7ec87e0bfc..18c3f423706 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -275,7 +275,6 @@ static struct usb_configuration eth_config_driver = {
275 275
276static int __init eth_bind(struct usb_composite_dev *cdev) 276static int __init eth_bind(struct usb_composite_dev *cdev)
277{ 277{
278 int gcnum;
279 struct usb_gadget *gadget = cdev->gadget; 278 struct usb_gadget *gadget = cdev->gadget;
280 int status; 279 int status;
281 280
@@ -310,22 +309,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
310 device_desc.bNumConfigurations = 2; 309 device_desc.bNumConfigurations = 2;
311 } 310 }
312 311
313 gcnum = usb_gadget_controller_number(gadget);
314 if (gcnum >= 0)
315 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
316 else {
317 /* We assume that can_support_ecm() tells the truth;
318 * but if the controller isn't recognized at all then
319 * that assumption is a bit more likely to be wrong.
320 */
321 dev_warn(&gadget->dev,
322 "controller '%s' not recognized; trying %s\n",
323 gadget->name,
324 eth_config_driver.label);
325 device_desc.bcdDevice =
326 cpu_to_le16(0x0300 | 0x0099);
327 }
328
329 /* Allocate string descriptor numbers ... note that string 312 /* Allocate string descriptor numbers ... note that string
330 * contents can be overridden by the composite_dev glue. 313 * contents can be overridden by the composite_dev glue.
331 */ 314 */
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 11150960d88..3a7668bde3e 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -348,7 +348,6 @@ struct fsg_config {
348 348
349 const char *vendor_name; /* 8 characters or less */ 349 const char *vendor_name; /* 8 characters or less */
350 const char *product_name; /* 16 characters or less */ 350 const char *product_name; /* 16 characters or less */
351 u16 release;
352 351
353 char can_stall; 352 char can_stall;
354}; 353};
@@ -2772,18 +2771,7 @@ buffhds_first_it:
2772 bh->next = common->buffhds; 2771 bh->next = common->buffhds;
2773 2772
2774 /* Prepare inquiryString */ 2773 /* Prepare inquiryString */
2775 if (cfg->release != 0xffff) { 2774 i = get_default_bcdDevice();
2776 i = cfg->release;
2777 } else {
2778 i = usb_gadget_controller_number(gadget);
2779 if (i >= 0) {
2780 i = 0x0300 + i;
2781 } else {
2782 WARNING(common, "controller '%s' not recognized\n",
2783 gadget->name);
2784 i = 0x0399;
2785 }
2786 }
2787 snprintf(common->inquiry_string, sizeof common->inquiry_string, 2775 snprintf(common->inquiry_string, sizeof common->inquiry_string,
2788 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2776 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
2789 /* Assume product name dependent on the first LUN */ 2777 /* Assume product name dependent on the first LUN */
@@ -3109,7 +3097,6 @@ fsg_config_from_params(struct fsg_config *cfg,
3109 /* Let MSF use defaults */ 3097 /* Let MSF use defaults */
3110 cfg->vendor_name = 0; 3098 cfg->vendor_name = 0;
3111 cfg->product_name = 0; 3099 cfg->product_name = 0;
3112 cfg->release = 0xffff;
3113 3100
3114 cfg->ops = NULL; 3101 cfg->ops = NULL;
3115 cfg->private_data = NULL; 3102 cfg->private_data = NULL;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index ce362f7e39d..3f7d640b675 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -251,6 +251,7 @@
251#include <linux/freezer.h> 251#include <linux/freezer.h>
252#include <linux/utsname.h> 252#include <linux/utsname.h>
253 253
254#include <linux/usb/composite.h>
254#include <linux/usb/ch9.h> 255#include <linux/usb/ch9.h>
255#include <linux/usb/gadget.h> 256#include <linux/usb/gadget.h>
256 257
@@ -3198,7 +3199,6 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3198static int __init check_parameters(struct fsg_dev *fsg) 3199static int __init check_parameters(struct fsg_dev *fsg)
3199{ 3200{
3200 int prot; 3201 int prot;
3201 int gcnum;
3202 3202
3203 /* Store the default values */ 3203 /* Store the default values */
3204 mod_data.transport_type = USB_PR_BULK; 3204 mod_data.transport_type = USB_PR_BULK;
@@ -3213,16 +3213,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
3213 if (gadget_is_at91(fsg->gadget)) 3213 if (gadget_is_at91(fsg->gadget))
3214 mod_data.can_stall = 0; 3214 mod_data.can_stall = 0;
3215 3215
3216 if (mod_data.release == 0xffff) { // Parameter wasn't set 3216 if (mod_data.release == 0xffff)
3217 gcnum = usb_gadget_controller_number(fsg->gadget); 3217 mod_data.release = get_default_bcdDevice();
3218 if (gcnum >= 0)
3219 mod_data.release = 0x0300 + gcnum;
3220 else {
3221 WARNING(fsg, "controller '%s' not recognized\n",
3222 fsg->gadget->name);
3223 mod_data.release = 0x0399;
3224 }
3225 }
3226 3218
3227 prot = simple_strtol(mod_data.protocol_parm, NULL, 0); 3219 prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
3228 3220
diff --git a/drivers/usb/gadget/gadget_chips.c b/drivers/usb/gadget/gadget_chips.c
deleted file mode 100644
index 6387d43d3f8..00000000000
--- a/drivers/usb/gadget/gadget_chips.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/*
2 * USB device controllers have lots of quirks. Use these macros in
3 * gadget drivers or other code that needs to deal with them, and which
4 * autoconfigures instead of using early binding to the hardware.
5 *
6 * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
7 * some config file that gets updated as new hardware is supported.
8 * (And avoiding all runtime comparisons in typical one-choice configs!)
9 *
10 * NOTE: some of these controller drivers may not be available yet.
11 * Some are available on 2.4 kernels; several are available, but not
12 * yet pushed in the 2.6 mainline tree.
13 */
14
15#include <linux/usb/gadget.h>
16#include <linux/module.h>
17
18#include "gadget_chips.h"
19
20/**
21 * usb_gadget_controller_number - support bcdDevice id convention
22 * @gadget: the controller being driven
23 *
24 * Return a 2-digit BCD value associated with the peripheral controller,
25 * suitable for use as part of a bcdDevice value, or a negative error code.
26 *
27 * NOTE: this convention is purely optional, and has no meaning in terms of
28 * any USB specification. If you want to use a different convention in your
29 * gadget driver firmware -- maybe a more formal revision ID -- feel free.
30 *
31 * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
32 * to change their behavior accordingly. For example it might help avoiding
33 * some chip bug.
34 */
35int usb_gadget_controller_number(struct usb_gadget *gadget)
36{
37 if (gadget_is_net2280(gadget))
38 return 0x01;
39 else if (gadget_is_dummy(gadget))
40 return 0x02;
41 else if (gadget_is_pxa(gadget))
42 return 0x03;
43 else if (gadget_is_goku(gadget))
44 return 0x06;
45 else if (gadget_is_omap(gadget))
46 return 0x08;
47 else if (gadget_is_pxa27x(gadget))
48 return 0x11;
49 else if (gadget_is_s3c2410(gadget))
50 return 0x12;
51 else if (gadget_is_at91(gadget))
52 return 0x13;
53 else if (gadget_is_imx(gadget))
54 return 0x14;
55 else if (gadget_is_musbhdrc(gadget))
56 return 0x16;
57 else if (gadget_is_atmel_usba(gadget))
58 return 0x18;
59 else if (gadget_is_fsl_usb2(gadget))
60 return 0x19;
61 else if (gadget_is_amd5536udc(gadget))
62 return 0x20;
63 else if (gadget_is_m66592(gadget))
64 return 0x21;
65 else if (gadget_is_fsl_qe(gadget))
66 return 0x22;
67 else if (gadget_is_ci13xxx_pci(gadget))
68 return 0x23;
69 else if (gadget_is_langwell(gadget))
70 return 0x24;
71 else if (gadget_is_r8a66597(gadget))
72 return 0x25;
73 else if (gadget_is_s3c_hsotg(gadget))
74 return 0x26;
75 else if (gadget_is_pch(gadget))
76 return 0x27;
77 else if (gadget_is_ci13xxx_msm(gadget))
78 return 0x28;
79 else if (gadget_is_renesas_usbhs(gadget))
80 return 0x29;
81 else if (gadget_is_s3c_hsudc(gadget))
82 return 0x30;
83 else if (gadget_is_net2272(gadget))
84 return 0x31;
85 else if (gadget_is_dwc3(gadget))
86 return 0x32;
87 else if (gadget_is_lpc32xx(gadget))
88 return 0x33;
89 else if (gadget_is_bcm63xx(gadget))
90 return 0x34;
91
92 return -ENOENT;
93}
94EXPORT_SYMBOL_GPL(usb_gadget_controller_number);
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index c7055cd1e92..bcd04bc66b9 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -27,35 +27,12 @@
27 * If you have forgotten the alphabetical order let VIM/EMACS 27 * If you have forgotten the alphabetical order let VIM/EMACS
28 * do that for you. 28 * do that for you.
29 */ 29 */
30#define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name))
31#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name)) 30#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name))
32#define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name))
33#define gadget_is_bcm63xx(g) (!strcmp("bcm63xx_udc", (g)->name))
34#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
35#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
36#define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name))
37#define gadget_is_dwc3(g) (!strcmp("dwc3-gadget", (g)->name))
38#define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name))
39#define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name))
40#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) 31#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name))
41#define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name))
42#define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
43#define gadget_is_lpc32xx(g) (!strcmp("lpc32xx_udc", (g)->name))
44#define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name))
45#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name)) 32#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name))
46#define gadget_is_net2272(g) (!strcmp("net2272", (g)->name))
47#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name)) 33#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name))
48#define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name))
49#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
50#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name)) 34#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name))
51#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name)) 35#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name))
52#define gadget_is_r8a66597(g) (!strcmp("r8a66597_udc", (g)->name))
53#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
54#define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name))
55#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
56#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))
57
58int usb_gadget_controller_number(struct usb_gadget *gadget);
59 36
60/** 37/**
61 * gadget_supports_altsettings - return true if altsettings work 38 * gadget_supports_altsettings - return true if altsettings work
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 4181524d1c4..881aab86ae9 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -137,8 +137,7 @@ static int __init midi_bind_config(struct usb_configuration *c)
137 137
138static int __init midi_bind(struct usb_composite_dev *cdev) 138static int __init midi_bind(struct usb_composite_dev *cdev)
139{ 139{
140 struct usb_gadget *gadget = cdev->gadget; 140 int status;
141 int gcnum, status;
142 141
143 status = usb_string_ids_tab(cdev, strings_dev); 142 status = usb_string_ids_tab(cdev, strings_dev);
144 if (status < 0) 143 if (status < 0)
@@ -147,19 +146,6 @@ static int __init midi_bind(struct usb_composite_dev *cdev)
147 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 146 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
148 midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id; 147 midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
149 148
150 gcnum = usb_gadget_controller_number(gadget);
151 if (gcnum < 0) {
152 /* gmidi is so simple (no altsettings) that
153 * it SHOULD NOT have problems with bulk-capable hardware.
154 * so warn about unrecognized controllers, don't panic.
155 */
156 pr_warning("%s: controller '%s' not recognized\n",
157 __func__, gadget->name);
158 device_desc.bcdDevice = cpu_to_le16(0x9999);
159 } else {
160 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
161 }
162
163 status = usb_add_config(cdev, &midi_config, midi_bind_config); 149 status = usb_add_config(cdev, &midi_config, midi_bind_config);
164 if (status < 0) 150 if (status < 0)
165 return status; 151 return status;
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 5fa1bfa8c6c..74130f6c12c 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -143,7 +143,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
143{ 143{
144 struct usb_gadget *gadget = cdev->gadget; 144 struct usb_gadget *gadget = cdev->gadget;
145 struct list_head *tmp; 145 struct list_head *tmp;
146 int status, gcnum, funcs = 0; 146 int status, funcs = 0;
147 147
148 list_for_each(tmp, &hidg_func_list) 148 list_for_each(tmp, &hidg_func_list)
149 funcs++; 149 funcs++;
@@ -156,12 +156,6 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
156 if (status < 0) 156 if (status < 0)
157 return status; 157 return status;
158 158
159 gcnum = usb_gadget_controller_number(gadget);
160 if (gcnum >= 0)
161 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
162 else
163 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
164
165 /* Allocate string descriptor numbers ... note that string 159 /* Allocate string descriptor numbers ... note that string
166 * contents can be overridden by the composite_dev glue. 160 * contents can be overridden by the composite_dev glue.
167 */ 161 */
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 9d2e75c017d..88472bf7dbb 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -247,7 +247,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
247static int __ref multi_bind(struct usb_composite_dev *cdev) 247static int __ref multi_bind(struct usb_composite_dev *cdev)
248{ 248{
249 struct usb_gadget *gadget = cdev->gadget; 249 struct usb_gadget *gadget = cdev->gadget;
250 int status, gcnum; 250 int status;
251 251
252 if (!can_support_ecm(cdev->gadget)) { 252 if (!can_support_ecm(cdev->gadget)) {
253 dev_err(&gadget->dev, "controller '%s' not usable\n", 253 dev_err(&gadget->dev, "controller '%s' not usable\n",
@@ -275,15 +275,6 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
275 } 275 }
276 } 276 }
277 277
278 /* set bcdDevice */
279 gcnum = usb_gadget_controller_number(gadget);
280 if (gcnum >= 0) {
281 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
282 } else {
283 WARNING(cdev, "controller '%s' not recognized\n", gadget->name);
284 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
285 }
286
287 /* allocate string IDs */ 278 /* allocate string IDs */
288 status = usb_string_ids_tab(cdev, strings_dev); 279 status = usb_string_ids_tab(cdev, strings_dev);
289 if (unlikely(status < 0)) 280 if (unlikely(status < 0))
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index b21ec269b8f..a22ad9af056 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -139,7 +139,6 @@ static struct usb_configuration ncm_config_driver = {
139 139
140static int __init gncm_bind(struct usb_composite_dev *cdev) 140static int __init gncm_bind(struct usb_composite_dev *cdev)
141{ 141{
142 int gcnum;
143 struct usb_gadget *gadget = cdev->gadget; 142 struct usb_gadget *gadget = cdev->gadget;
144 int status; 143 int status;
145 144
@@ -148,22 +147,6 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
148 if (status < 0) 147 if (status < 0)
149 return status; 148 return status;
150 149
151 gcnum = usb_gadget_controller_number(gadget);
152 if (gcnum >= 0)
153 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
154 else {
155 /* We assume that can_support_ecm() tells the truth;
156 * but if the controller isn't recognized at all then
157 * that assumption is a bit more likely to be wrong.
158 */
159 dev_warn(&gadget->dev,
160 "controller '%s' not recognized; trying %s\n",
161 gadget->name,
162 ncm_config_driver.label);
163 device_desc.bcdDevice =
164 cpu_to_le16(0x0300 | 0x0099);
165 }
166
167 /* Allocate string descriptor numbers ... note that string 150 /* Allocate string descriptor numbers ... note that string
168 * contents can be overridden by the composite_dev glue. 151 * contents can be overridden by the composite_dev glue.
169 */ 152 */
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index ad0cc347307..661600abace 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -84,6 +84,7 @@ static struct usb_device_descriptor device_desc = {
84 .bDeviceClass = USB_CLASS_COMM, 84 .bDeviceClass = USB_CLASS_COMM,
85 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID), 85 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
86 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID), 86 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
87 .bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM),
87 /* .iManufacturer = DYNAMIC */ 88 /* .iManufacturer = DYNAMIC */
88 /* .iProduct = DYNAMIC */ 89 /* .iProduct = DYNAMIC */
89 .bNumConfigurations = 1, 90 .bNumConfigurations = 1,
@@ -145,7 +146,6 @@ static struct usb_configuration nokia_config_100ma_driver = {
145 146
146static int __init nokia_bind(struct usb_composite_dev *cdev) 147static int __init nokia_bind(struct usb_composite_dev *cdev)
147{ 148{
148 int gcnum;
149 struct usb_gadget *gadget = cdev->gadget; 149 struct usb_gadget *gadget = cdev->gadget;
150 int status; 150 int status;
151 151
@@ -170,18 +170,8 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
170 nokia_config_500ma_driver.iConfiguration = status; 170 nokia_config_500ma_driver.iConfiguration = status;
171 nokia_config_100ma_driver.iConfiguration = status; 171 nokia_config_100ma_driver.iConfiguration = status;
172 172
173 /* set up other descriptors */ 173 if (!gadget_supports_altsettings(gadget))
174 gcnum = usb_gadget_controller_number(gadget);
175 if (gcnum >= 0)
176 device_desc.bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM);
177 else {
178 /* this should only work with hw that supports altsettings
179 * and several endpoints, anything else, panic.
180 */
181 pr_err("nokia_bind: controller '%s' not recognized\n",
182 gadget->name);
183 goto err_usb; 174 goto err_usb;
184 }
185 175
186 /* finally register the configuration */ 176 /* finally register the configuration */
187 status = usb_add_config(cdev, &nokia_config_500ma_driver, 177 status = usb_add_config(cdev, &nokia_config_500ma_driver,
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index e394050afd0..e156e3f2672 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -1101,7 +1101,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
1101 struct usb_gadget *gadget = c->cdev->gadget; 1101 struct usb_gadget *gadget = c->cdev->gadget;
1102 struct printer_dev *dev; 1102 struct printer_dev *dev;
1103 int status = -ENOMEM; 1103 int status = -ENOMEM;
1104 int gcnum;
1105 size_t len; 1104 size_t len;
1106 u32 i; 1105 u32 i;
1107 struct usb_request *req; 1106 struct usb_request *req;
@@ -1143,16 +1142,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
1143 goto fail; 1142 goto fail;
1144 } 1143 }
1145 1144
1146 gcnum = usb_gadget_controller_number(gadget);
1147 if (gcnum >= 0) {
1148 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1149 } else {
1150 dev_warn(&gadget->dev, "controller '%s' not recognized\n",
1151 gadget->name);
1152 /* unrecognized, but safe unless bulk is REALLY quirky */
1153 device_desc.bcdDevice =
1154 cpu_to_le16(0xFFFF);
1155 }
1156 if (iPNPstring) 1145 if (iPNPstring)
1157 strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2); 1146 strlcpy(&pnp_string[2], iPNPstring, (sizeof pnp_string)-2);
1158 1147
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f17d4626af5..942067327d8 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -86,7 +86,7 @@ static struct usb_device_descriptor device_desc = {
86 /* .bMaxPacketSize0 = f(hardware) */ 86 /* .bMaxPacketSize0 = f(hardware) */
87 .idVendor = cpu_to_le16(GS_VENDOR_ID), 87 .idVendor = cpu_to_le16(GS_VENDOR_ID),
88 /* .idProduct = f(use_acm) */ 88 /* .idProduct = f(use_acm) */
89 /* .bcdDevice = f(hardware) */ 89 .bcdDevice = cpu_to_le16(GS_VERSION_NUM << 16),
90 /* .iManufacturer = DYNAMIC */ 90 /* .iManufacturer = DYNAMIC */
91 /* .iProduct = DYNAMIC */ 91 /* .iProduct = DYNAMIC */
92 .bNumConfigurations = 1, 92 .bNumConfigurations = 1,
@@ -154,8 +154,6 @@ static struct usb_configuration serial_config_driver = {
154 154
155static int __init gs_bind(struct usb_composite_dev *cdev) 155static int __init gs_bind(struct usb_composite_dev *cdev)
156{ 156{
157 int gcnum;
158 struct usb_gadget *gadget = cdev->gadget;
159 int status; 157 int status;
160 158
161 status = gserial_setup(cdev->gadget, n_ports); 159 status = gserial_setup(cdev->gadget, n_ports);
@@ -174,24 +172,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
174 status = strings_dev[STRING_DESCRIPTION_IDX].id; 172 status = strings_dev[STRING_DESCRIPTION_IDX].id;
175 serial_config_driver.iConfiguration = status; 173 serial_config_driver.iConfiguration = status;
176 174
177 /* set up other descriptors */
178 gcnum = usb_gadget_controller_number(gadget);
179 if (gcnum >= 0)
180 device_desc.bcdDevice = cpu_to_le16(GS_VERSION_NUM | gcnum);
181 else {
182 /* this is so simple (for now, no altsettings) that it
183 * SHOULD NOT have problems with bulk-capable hardware.
184 * so warn about unrcognized controllers -- don't panic.
185 *
186 * things like configuration and altsetting numbering
187 * can need hardware-specific attention though.
188 */
189 pr_warning("gs_bind: controller '%s' not recognized\n",
190 gadget->name);
191 device_desc.bcdDevice =
192 cpu_to_le16(GS_VERSION_NUM | 0x0099);
193 }
194
195 if (gadget_is_otg(cdev->gadget)) { 175 if (gadget_is_otg(cdev->gadget)) {
196 serial_config_driver.descriptors = otg_desc; 176 serial_config_driver.descriptors = otg_desc;
197 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 177 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 0dabffa5f49..6bf4c061136 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -253,8 +253,6 @@ static void zero_resume(struct usb_composite_dev *cdev)
253 253
254static int __init zero_bind(struct usb_composite_dev *cdev) 254static int __init zero_bind(struct usb_composite_dev *cdev)
255{ 255{
256 int gcnum;
257 struct usb_gadget *gadget = cdev->gadget;
258 int status; 256 int status;
259 257
260 /* Allocate string descriptor numbers ... note that string 258 /* Allocate string descriptor numbers ... note that string
@@ -281,21 +279,6 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
281 loopback_add(cdev, autoresume != 0); 279 loopback_add(cdev, autoresume != 0);
282 } 280 }
283 281
284 gcnum = usb_gadget_controller_number(gadget);
285 if (gcnum >= 0)
286 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
287 else {
288 /* gadget zero is so simple (for now, no altsettings) that
289 * it SHOULD NOT have problems with bulk-capable hardware.
290 * so just warn about unrcognized controllers -- don't panic.
291 *
292 * things like configuration and altsetting numbering
293 * can need hardware-specific attention though.
294 */
295 pr_warning("%s: controller '%s' not recognized\n",
296 longname, gadget->name);
297 device_desc.bcdDevice = cpu_to_le16(0x9999);
298 }
299 usb_composite_overwrite_options(cdev, &coverwrite); 282 usb_composite_overwrite_options(cdev, &coverwrite);
300 283
301 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); 284 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname);
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 65ae0a3feb5..f8dda062180 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -34,6 +34,8 @@
34 * the composite model the host can use both functions at the same time. 34 * the composite model the host can use both functions at the same time.
35 */ 35 */
36 36
37#include <linux/bcd.h>
38#include <linux/version.h>
37#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
38#include <linux/usb/gadget.h> 40#include <linux/usb/gadget.h>
39 41
@@ -418,6 +420,15 @@ struct usb_composite_overwrite {
418void usb_composite_overwrite_options(struct usb_composite_dev *cdev, 420void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
419 struct usb_composite_overwrite *covr); 421 struct usb_composite_overwrite *covr);
420 422
423static inline u16 get_default_bcdDevice(void)
424{
425 u16 bcdDevice;
426
427 bcdDevice = bin2bcd((LINUX_VERSION_CODE >> 16 & 0xff)) << 8;
428 bcdDevice |= bin2bcd((LINUX_VERSION_CODE >> 8 & 0xff));
429 return bcdDevice;
430}
431
421/* messaging utils */ 432/* messaging utils */
422#define DBG(d, fmt, args...) \ 433#define DBG(d, fmt, args...) \
423 dev_dbg(&(d)->gadget->dev , fmt , ## args) 434 dev_dbg(&(d)->gadget->dev , fmt , ## args)