diff options
Diffstat (limited to 'include/linux/usb/composite.h')
-rw-r--r-- | include/linux/usb/composite.h | 97 |
1 files changed, 75 insertions, 22 deletions
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 9d8c3b634493..f8dda0621800 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 | ||
@@ -46,6 +48,9 @@ | |||
46 | */ | 48 | */ |
47 | #define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */ | 49 | #define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */ |
48 | 50 | ||
51 | /* big enough to hold our biggest descriptor */ | ||
52 | #define USB_COMP_EP0_BUFSIZ 1024 | ||
53 | |||
49 | struct usb_configuration; | 54 | struct usb_configuration; |
50 | 55 | ||
51 | /** | 56 | /** |
@@ -245,24 +250,31 @@ int usb_add_config(struct usb_composite_dev *, | |||
245 | void usb_remove_config(struct usb_composite_dev *, | 250 | void usb_remove_config(struct usb_composite_dev *, |
246 | struct usb_configuration *); | 251 | struct usb_configuration *); |
247 | 252 | ||
253 | /* predefined index for usb_composite_driver */ | ||
254 | enum { | ||
255 | USB_GADGET_MANUFACTURER_IDX = 0, | ||
256 | USB_GADGET_PRODUCT_IDX, | ||
257 | USB_GADGET_SERIAL_IDX, | ||
258 | USB_GADGET_FIRST_AVAIL_IDX, | ||
259 | }; | ||
260 | |||
248 | /** | 261 | /** |
249 | * struct usb_composite_driver - groups configurations into a gadget | 262 | * struct usb_composite_driver - groups configurations into a gadget |
250 | * @name: For diagnostics, identifies the driver. | 263 | * @name: For diagnostics, identifies the driver. |
251 | * @iProduct: Used as iProduct override if @dev->iProduct is not set. | ||
252 | * If NULL value of @name is taken. | ||
253 | * @iManufacturer: Used as iManufacturer override if @dev->iManufacturer is | ||
254 | * not set. If NULL a default "<system> <release> with <udc>" value | ||
255 | * will be used. | ||
256 | * @iSerialNumber: Used as iSerialNumber override if @dev->iSerialNumber is | ||
257 | * not set. | ||
258 | * @dev: Template descriptor for the device, including default device | 264 | * @dev: Template descriptor for the device, including default device |
259 | * identifiers. | 265 | * identifiers. |
260 | * @strings: tables of strings, keyed by identifiers assigned during bind() | 266 | * @strings: tables of strings, keyed by identifiers assigned during @bind |
261 | * and language IDs provided in control requests | 267 | * and language IDs provided in control requests. Note: The first entries |
268 | * are predefined. The first entry that may be used is | ||
269 | * USB_GADGET_FIRST_AVAIL_IDX | ||
262 | * @max_speed: Highest speed the driver supports. | 270 | * @max_speed: Highest speed the driver supports. |
263 | * @needs_serial: set to 1 if the gadget needs userspace to provide | 271 | * @needs_serial: set to 1 if the gadget needs userspace to provide |
264 | * a serial number. If one is not provided, warning will be printed. | 272 | * a serial number. If one is not provided, warning will be printed. |
265 | * @unbind: Reverses bind; called as a side effect of unregistering | 273 | * @bind: (REQUIRED) Used to allocate resources that are shared across the |
274 | * whole device, such as string IDs, and add its configurations using | ||
275 | * @usb_add_config(). This may fail by returning a negative errno | ||
276 | * value; it should return zero on successful initialization. | ||
277 | * @unbind: Reverses @bind; called as a side effect of unregistering | ||
266 | * this driver. | 278 | * this driver. |
267 | * @disconnect: optional driver disconnect method | 279 | * @disconnect: optional driver disconnect method |
268 | * @suspend: Notifies when the host stops sending USB traffic, | 280 | * @suspend: Notifies when the host stops sending USB traffic, |
@@ -271,9 +283,9 @@ void usb_remove_config(struct usb_composite_dev *, | |||
271 | * before function notifications | 283 | * before function notifications |
272 | * | 284 | * |
273 | * Devices default to reporting self powered operation. Devices which rely | 285 | * Devices default to reporting self powered operation. Devices which rely |
274 | * on bus powered operation should report this in their @bind() method. | 286 | * on bus powered operation should report this in their @bind method. |
275 | * | 287 | * |
276 | * Before returning from bind, various fields in the template descriptor | 288 | * Before returning from @bind, various fields in the template descriptor |
277 | * may be overridden. These include the idVendor/idProduct/bcdDevice values | 289 | * may be overridden. These include the idVendor/idProduct/bcdDevice values |
278 | * normally to bind the appropriate host side driver, and the three strings | 290 | * normally to bind the appropriate host side driver, and the three strings |
279 | * (iManufacturer, iProduct, iSerialNumber) normally used to provide user | 291 | * (iManufacturer, iProduct, iSerialNumber) normally used to provide user |
@@ -283,14 +295,12 @@ void usb_remove_config(struct usb_composite_dev *, | |||
283 | */ | 295 | */ |
284 | struct usb_composite_driver { | 296 | struct usb_composite_driver { |
285 | const char *name; | 297 | const char *name; |
286 | const char *iProduct; | ||
287 | const char *iManufacturer; | ||
288 | const char *iSerialNumber; | ||
289 | const struct usb_device_descriptor *dev; | 298 | const struct usb_device_descriptor *dev; |
290 | struct usb_gadget_strings **strings; | 299 | struct usb_gadget_strings **strings; |
291 | enum usb_device_speed max_speed; | 300 | enum usb_device_speed max_speed; |
292 | unsigned needs_serial:1; | 301 | unsigned needs_serial:1; |
293 | 302 | ||
303 | int (*bind)(struct usb_composite_dev *cdev); | ||
294 | int (*unbind)(struct usb_composite_dev *); | 304 | int (*unbind)(struct usb_composite_dev *); |
295 | 305 | ||
296 | void (*disconnect)(struct usb_composite_dev *); | 306 | void (*disconnect)(struct usb_composite_dev *); |
@@ -298,10 +308,10 @@ struct usb_composite_driver { | |||
298 | /* global suspend hooks */ | 308 | /* global suspend hooks */ |
299 | void (*suspend)(struct usb_composite_dev *); | 309 | void (*suspend)(struct usb_composite_dev *); |
300 | void (*resume)(struct usb_composite_dev *); | 310 | void (*resume)(struct usb_composite_dev *); |
311 | struct usb_gadget_driver gadget_driver; | ||
301 | }; | 312 | }; |
302 | 313 | ||
303 | extern int usb_composite_probe(struct usb_composite_driver *driver, | 314 | extern int usb_composite_probe(struct usb_composite_driver *driver); |
304 | int (*bind)(struct usb_composite_dev *cdev)); | ||
305 | extern void usb_composite_unregister(struct usb_composite_driver *driver); | 315 | extern void usb_composite_unregister(struct usb_composite_driver *driver); |
306 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); | 316 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); |
307 | 317 | ||
@@ -310,7 +320,6 @@ extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); | |||
310 | * struct usb_composite_device - represents one composite usb gadget | 320 | * struct usb_composite_device - represents one composite usb gadget |
311 | * @gadget: read-only, abstracts the gadget's usb peripheral controller | 321 | * @gadget: read-only, abstracts the gadget's usb peripheral controller |
312 | * @req: used for control responses; buffer is pre-allocated | 322 | * @req: used for control responses; buffer is pre-allocated |
313 | * @bufsiz: size of buffer pre-allocated in @req | ||
314 | * @config: the currently active configuration | 323 | * @config: the currently active configuration |
315 | * | 324 | * |
316 | * One of these devices is allocated and initialized before the | 325 | * One of these devices is allocated and initialized before the |
@@ -341,7 +350,6 @@ extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); | |||
341 | struct usb_composite_dev { | 350 | struct usb_composite_dev { |
342 | struct usb_gadget *gadget; | 351 | struct usb_gadget *gadget; |
343 | struct usb_request *req; | 352 | struct usb_request *req; |
344 | unsigned bufsiz; | ||
345 | 353 | ||
346 | struct usb_configuration *config; | 354 | struct usb_configuration *config; |
347 | 355 | ||
@@ -352,9 +360,7 @@ struct usb_composite_dev { | |||
352 | struct list_head configs; | 360 | struct list_head configs; |
353 | struct usb_composite_driver *driver; | 361 | struct usb_composite_driver *driver; |
354 | u8 next_string_id; | 362 | u8 next_string_id; |
355 | u8 manufacturer_override; | 363 | char *def_manufacturer; |
356 | u8 product_override; | ||
357 | u8 serial_override; | ||
358 | 364 | ||
359 | /* the gadget driver won't enable the data pullup | 365 | /* the gadget driver won't enable the data pullup |
360 | * while the deactivation count is nonzero. | 366 | * while the deactivation count is nonzero. |
@@ -375,6 +381,53 @@ extern int usb_string_ids_tab(struct usb_composite_dev *c, | |||
375 | struct usb_string *str); | 381 | struct usb_string *str); |
376 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); | 382 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); |
377 | 383 | ||
384 | /* | ||
385 | * Some systems will need runtime overrides for the product identifiers | ||
386 | * published in the device descriptor, either numbers or strings or both. | ||
387 | * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). | ||
388 | */ | ||
389 | struct usb_composite_overwrite { | ||
390 | u16 idVendor; | ||
391 | u16 idProduct; | ||
392 | u16 bcdDevice; | ||
393 | char *serial_number; | ||
394 | char *manufacturer; | ||
395 | char *product; | ||
396 | }; | ||
397 | #define USB_GADGET_COMPOSITE_OPTIONS() \ | ||
398 | static struct usb_composite_overwrite coverwrite; \ | ||
399 | \ | ||
400 | module_param_named(idVendor, coverwrite.idVendor, ushort, S_IRUGO); \ | ||
401 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); \ | ||
402 | \ | ||
403 | module_param_named(idProduct, coverwrite.idProduct, ushort, S_IRUGO); \ | ||
404 | MODULE_PARM_DESC(idProduct, "USB Product ID"); \ | ||
405 | \ | ||
406 | module_param_named(bcdDevice, coverwrite.bcdDevice, ushort, S_IRUGO); \ | ||
407 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); \ | ||
408 | \ | ||
409 | module_param_named(iSerialNumber, coverwrite.serial_number, charp, \ | ||
410 | S_IRUGO); \ | ||
411 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); \ | ||
412 | \ | ||
413 | module_param_named(iManufacturer, coverwrite.manufacturer, charp, \ | ||
414 | S_IRUGO); \ | ||
415 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); \ | ||
416 | \ | ||
417 | module_param_named(iProduct, coverwrite.product, charp, S_IRUGO); \ | ||
418 | MODULE_PARM_DESC(iProduct, "USB Product string") | ||
419 | |||
420 | void usb_composite_overwrite_options(struct usb_composite_dev *cdev, | ||
421 | struct usb_composite_overwrite *covr); | ||
422 | |||
423 | static 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 | } | ||
378 | 431 | ||
379 | /* messaging utils */ | 432 | /* messaging utils */ |
380 | #define DBG(d, fmt, args...) \ | 433 | #define DBG(d, fmt, args...) \ |