diff options
Diffstat (limited to 'drivers/usb/gadget/ncm.c')
-rw-r--r-- | drivers/usb/gadget/ncm.c | 62 |
1 files changed, 13 insertions, 49 deletions
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 89530034dff1..a22ad9af0565 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c | |||
@@ -20,8 +20,8 @@ | |||
20 | /* #define VERBOSE_DEBUG */ | 20 | /* #define VERBOSE_DEBUG */ |
21 | 21 | ||
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/utsname.h> | 23 | #include <linux/module.h> |
24 | 24 | #include <linux/usb/composite.h> | |
25 | 25 | ||
26 | #include "u_ether.h" | 26 | #include "u_ether.h" |
27 | 27 | ||
@@ -36,11 +36,6 @@ | |||
36 | * the runtime footprint, and giving us at least some parts of what | 36 | * the runtime footprint, and giving us at least some parts of what |
37 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | 37 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
38 | */ | 38 | */ |
39 | #include "composite.c" | ||
40 | #include "usbstring.c" | ||
41 | #include "config.c" | ||
42 | #include "epautoconf.c" | ||
43 | |||
44 | #include "f_ncm.c" | 39 | #include "f_ncm.c" |
45 | #include "u_ether.c" | 40 | #include "u_ether.c" |
46 | 41 | ||
@@ -57,6 +52,7 @@ | |||
57 | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ | 52 | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ |
58 | 53 | ||
59 | /*-------------------------------------------------------------------------*/ | 54 | /*-------------------------------------------------------------------------*/ |
55 | USB_GADGET_COMPOSITE_OPTIONS(); | ||
60 | 56 | ||
61 | static struct usb_device_descriptor device_desc = { | 57 | static struct usb_device_descriptor device_desc = { |
62 | .bLength = sizeof device_desc, | 58 | .bLength = sizeof device_desc, |
@@ -97,17 +93,11 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
97 | NULL, | 93 | NULL, |
98 | }; | 94 | }; |
99 | 95 | ||
100 | |||
101 | /* string IDs are assigned dynamically */ | 96 | /* string IDs are assigned dynamically */ |
102 | |||
103 | #define STRING_MANUFACTURER_IDX 0 | ||
104 | #define STRING_PRODUCT_IDX 1 | ||
105 | |||
106 | static char manufacturer[50]; | ||
107 | |||
108 | static struct usb_string strings_dev[] = { | 97 | static struct usb_string strings_dev[] = { |
109 | [STRING_MANUFACTURER_IDX].s = manufacturer, | 98 | [USB_GADGET_MANUFACTURER_IDX].s = "", |
110 | [STRING_PRODUCT_IDX].s = DRIVER_DESC, | 99 | [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC, |
100 | [USB_GADGET_SERIAL_IDX].s = "", | ||
111 | { } /* end of list */ | 101 | { } /* end of list */ |
112 | }; | 102 | }; |
113 | 103 | ||
@@ -149,7 +139,6 @@ static struct usb_configuration ncm_config_driver = { | |||
149 | 139 | ||
150 | static int __init gncm_bind(struct usb_composite_dev *cdev) | 140 | static int __init gncm_bind(struct usb_composite_dev *cdev) |
151 | { | 141 | { |
152 | int gcnum; | ||
153 | struct usb_gadget *gadget = cdev->gadget; | 142 | struct usb_gadget *gadget = cdev->gadget; |
154 | int status; | 143 | int status; |
155 | 144 | ||
@@ -158,48 +147,22 @@ static int __init gncm_bind(struct usb_composite_dev *cdev) | |||
158 | if (status < 0) | 147 | if (status < 0) |
159 | return status; | 148 | return status; |
160 | 149 | ||
161 | gcnum = usb_gadget_controller_number(gadget); | ||
162 | if (gcnum >= 0) | ||
163 | device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); | ||
164 | else { | ||
165 | /* We assume that can_support_ecm() tells the truth; | ||
166 | * but if the controller isn't recognized at all then | ||
167 | * that assumption is a bit more likely to be wrong. | ||
168 | */ | ||
169 | dev_warn(&gadget->dev, | ||
170 | "controller '%s' not recognized; trying %s\n", | ||
171 | gadget->name, | ||
172 | ncm_config_driver.label); | ||
173 | device_desc.bcdDevice = | ||
174 | cpu_to_le16(0x0300 | 0x0099); | ||
175 | } | ||
176 | |||
177 | |||
178 | /* Allocate string descriptor numbers ... note that string | 150 | /* Allocate string descriptor numbers ... note that string |
179 | * contents can be overridden by the composite_dev glue. | 151 | * contents can be overridden by the composite_dev glue. |
180 | */ | 152 | */ |
181 | 153 | ||
182 | /* device descriptor strings: manufacturer, product */ | 154 | status = usb_string_ids_tab(cdev, strings_dev); |
183 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", | ||
184 | init_utsname()->sysname, init_utsname()->release, | ||
185 | gadget->name); | ||
186 | status = usb_string_id(cdev); | ||
187 | if (status < 0) | ||
188 | goto fail; | ||
189 | strings_dev[STRING_MANUFACTURER_IDX].id = status; | ||
190 | device_desc.iManufacturer = status; | ||
191 | |||
192 | status = usb_string_id(cdev); | ||
193 | if (status < 0) | 155 | if (status < 0) |
194 | goto fail; | 156 | goto fail; |
195 | strings_dev[STRING_PRODUCT_IDX].id = status; | 157 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
196 | device_desc.iProduct = status; | 158 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
197 | 159 | ||
198 | status = usb_add_config(cdev, &ncm_config_driver, | 160 | status = usb_add_config(cdev, &ncm_config_driver, |
199 | ncm_do_config); | 161 | ncm_do_config); |
200 | if (status < 0) | 162 | if (status < 0) |
201 | goto fail; | 163 | goto fail; |
202 | 164 | ||
165 | usb_composite_overwrite_options(cdev, &coverwrite); | ||
203 | dev_info(&gadget->dev, "%s\n", DRIVER_DESC); | 166 | dev_info(&gadget->dev, "%s\n", DRIVER_DESC); |
204 | 167 | ||
205 | return 0; | 168 | return 0; |
@@ -215,11 +178,12 @@ static int __exit gncm_unbind(struct usb_composite_dev *cdev) | |||
215 | return 0; | 178 | return 0; |
216 | } | 179 | } |
217 | 180 | ||
218 | static struct usb_composite_driver ncm_driver = { | 181 | static __refdata struct usb_composite_driver ncm_driver = { |
219 | .name = "g_ncm", | 182 | .name = "g_ncm", |
220 | .dev = &device_desc, | 183 | .dev = &device_desc, |
221 | .strings = dev_strings, | 184 | .strings = dev_strings, |
222 | .max_speed = USB_SPEED_HIGH, | 185 | .max_speed = USB_SPEED_HIGH, |
186 | .bind = gncm_bind, | ||
223 | .unbind = __exit_p(gncm_unbind), | 187 | .unbind = __exit_p(gncm_unbind), |
224 | }; | 188 | }; |
225 | 189 | ||
@@ -229,7 +193,7 @@ MODULE_LICENSE("GPL"); | |||
229 | 193 | ||
230 | static int __init init(void) | 194 | static int __init init(void) |
231 | { | 195 | { |
232 | return usb_composite_probe(&ncm_driver, gncm_bind); | 196 | return usb_composite_probe(&ncm_driver); |
233 | } | 197 | } |
234 | module_init(init); | 198 | module_init(init); |
235 | 199 | ||