diff options
Diffstat (limited to 'include/linux/usb/composite.h')
-rw-r--r-- | include/linux/usb/composite.h | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index b09c37e04a91..8860594d6364 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h | |||
@@ -60,7 +60,7 @@ struct usb_configuration; | |||
60 | * @name: For diagnostics, identifies the function. | 60 | * @name: For diagnostics, identifies the function. |
61 | * @strings: tables of strings, keyed by identifiers assigned during bind() | 61 | * @strings: tables of strings, keyed by identifiers assigned during bind() |
62 | * and by language IDs provided in control requests | 62 | * and by language IDs provided in control requests |
63 | * @descriptors: Table of full (or low) speed descriptors, using interface and | 63 | * @fs_descriptors: Table of full (or low) speed descriptors, using interface and |
64 | * string identifiers assigned during @bind(). If this pointer is null, | 64 | * string identifiers assigned during @bind(). If this pointer is null, |
65 | * the function will not be available at full speed (or at low speed). | 65 | * the function will not be available at full speed (or at low speed). |
66 | * @hs_descriptors: Table of high speed descriptors, using interface and | 66 | * @hs_descriptors: Table of high speed descriptors, using interface and |
@@ -77,6 +77,8 @@ struct usb_configuration; | |||
77 | * in interface or class descriptors; endpoints; I/O buffers; and so on. | 77 | * in interface or class descriptors; endpoints; I/O buffers; and so on. |
78 | * @unbind: Reverses @bind; called as a side effect of unregistering the | 78 | * @unbind: Reverses @bind; called as a side effect of unregistering the |
79 | * driver which added this function. | 79 | * driver which added this function. |
80 | * @free_func: free the struct usb_function. | ||
81 | * @mod: (internal) points to the module that created this structure. | ||
80 | * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may | 82 | * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may |
81 | * initialize usb_ep.driver data at this time (when it is used). | 83 | * initialize usb_ep.driver data at this time (when it is used). |
82 | * Note that setting an interface to its current altsetting resets | 84 | * Note that setting an interface to its current altsetting resets |
@@ -116,6 +118,7 @@ struct usb_configuration; | |||
116 | * two or more distinct instances within the same configuration, providing | 118 | * two or more distinct instances within the same configuration, providing |
117 | * several independent logical data links to a USB host. | 119 | * several independent logical data links to a USB host. |
118 | */ | 120 | */ |
121 | |||
119 | struct usb_function { | 122 | struct usb_function { |
120 | const char *name; | 123 | const char *name; |
121 | struct usb_gadget_strings **strings; | 124 | struct usb_gadget_strings **strings; |
@@ -136,6 +139,8 @@ struct usb_function { | |||
136 | struct usb_function *); | 139 | struct usb_function *); |
137 | void (*unbind)(struct usb_configuration *, | 140 | void (*unbind)(struct usb_configuration *, |
138 | struct usb_function *); | 141 | struct usb_function *); |
142 | void (*free_func)(struct usb_function *f); | ||
143 | struct module *mod; | ||
139 | 144 | ||
140 | /* runtime state management */ | 145 | /* runtime state management */ |
141 | int (*set_alt)(struct usb_function *, | 146 | int (*set_alt)(struct usb_function *, |
@@ -156,6 +161,7 @@ struct usb_function { | |||
156 | /* internals */ | 161 | /* internals */ |
157 | struct list_head list; | 162 | struct list_head list; |
158 | DECLARE_BITMAP(endpoints, 32); | 163 | DECLARE_BITMAP(endpoints, 32); |
164 | const struct usb_function_instance *fi; | ||
159 | }; | 165 | }; |
160 | 166 | ||
161 | int usb_add_function(struct usb_configuration *, struct usb_function *); | 167 | int usb_add_function(struct usb_configuration *, struct usb_function *); |
@@ -184,7 +190,8 @@ int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, | |||
184 | * @bConfigurationValue: Copied into configuration descriptor. | 190 | * @bConfigurationValue: Copied into configuration descriptor. |
185 | * @iConfiguration: Copied into configuration descriptor. | 191 | * @iConfiguration: Copied into configuration descriptor. |
186 | * @bmAttributes: Copied into configuration descriptor. | 192 | * @bmAttributes: Copied into configuration descriptor. |
187 | * @bMaxPower: Copied into configuration descriptor. | 193 | * @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the |
194 | * configuration descriptor after considering the bus speed. | ||
188 | * @cdev: assigned by @usb_add_config() before calling @bind(); this is | 195 | * @cdev: assigned by @usb_add_config() before calling @bind(); this is |
189 | * the device associated with this configuration. | 196 | * the device associated with this configuration. |
190 | * | 197 | * |
@@ -230,7 +237,7 @@ struct usb_configuration { | |||
230 | u8 bConfigurationValue; | 237 | u8 bConfigurationValue; |
231 | u8 iConfiguration; | 238 | u8 iConfiguration; |
232 | u8 bmAttributes; | 239 | u8 bmAttributes; |
233 | u8 bMaxPower; | 240 | u16 MaxPower; |
234 | 241 | ||
235 | struct usb_composite_dev *cdev; | 242 | struct usb_composite_dev *cdev; |
236 | 243 | ||
@@ -283,6 +290,7 @@ enum { | |||
283 | * after function notifications | 290 | * after function notifications |
284 | * @resume: Notifies configuration when the host restarts USB traffic, | 291 | * @resume: Notifies configuration when the host restarts USB traffic, |
285 | * before function notifications | 292 | * before function notifications |
293 | * @gadget_driver: Gadget driver controlling this driver | ||
286 | * | 294 | * |
287 | * Devices default to reporting self powered operation. Devices which rely | 295 | * Devices default to reporting self powered operation. Devices which rely |
288 | * on bus powered operation should report this in their @bind method. | 296 | * on bus powered operation should report this in their @bind method. |
@@ -316,7 +324,15 @@ struct usb_composite_driver { | |||
316 | extern int usb_composite_probe(struct usb_composite_driver *driver); | 324 | extern int usb_composite_probe(struct usb_composite_driver *driver); |
317 | extern void usb_composite_unregister(struct usb_composite_driver *driver); | 325 | extern void usb_composite_unregister(struct usb_composite_driver *driver); |
318 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); | 326 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); |
327 | extern int composite_dev_prepare(struct usb_composite_driver *composite, | ||
328 | struct usb_composite_dev *cdev); | ||
329 | void composite_dev_cleanup(struct usb_composite_dev *cdev); | ||
319 | 330 | ||
331 | static inline struct usb_composite_driver *to_cdriver( | ||
332 | struct usb_gadget_driver *gdrv) | ||
333 | { | ||
334 | return container_of(gdrv, struct usb_composite_driver, gadget_driver); | ||
335 | } | ||
320 | 336 | ||
321 | /** | 337 | /** |
322 | * struct usb_composite_device - represents one composite usb gadget | 338 | * struct usb_composite_device - represents one composite usb gadget |
@@ -360,6 +376,7 @@ struct usb_composite_dev { | |||
360 | unsigned int suspended:1; | 376 | unsigned int suspended:1; |
361 | struct usb_device_descriptor desc; | 377 | struct usb_device_descriptor desc; |
362 | struct list_head configs; | 378 | struct list_head configs; |
379 | struct list_head gstrings; | ||
363 | struct usb_composite_driver *driver; | 380 | struct usb_composite_driver *driver; |
364 | u8 next_string_id; | 381 | u8 next_string_id; |
365 | char *def_manufacturer; | 382 | char *def_manufacturer; |
@@ -381,8 +398,15 @@ struct usb_composite_dev { | |||
381 | extern int usb_string_id(struct usb_composite_dev *c); | 398 | extern int usb_string_id(struct usb_composite_dev *c); |
382 | extern int usb_string_ids_tab(struct usb_composite_dev *c, | 399 | extern int usb_string_ids_tab(struct usb_composite_dev *c, |
383 | struct usb_string *str); | 400 | struct usb_string *str); |
401 | extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev, | ||
402 | struct usb_gadget_strings **sp, unsigned n_strings); | ||
403 | |||
384 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); | 404 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); |
385 | 405 | ||
406 | extern void composite_disconnect(struct usb_gadget *gadget); | ||
407 | extern int composite_setup(struct usb_gadget *gadget, | ||
408 | const struct usb_ctrlrequest *ctrl); | ||
409 | |||
386 | /* | 410 | /* |
387 | * Some systems will need runtime overrides for the product identifiers | 411 | * Some systems will need runtime overrides for the product identifiers |
388 | * published in the device descriptor, either numbers or strings or both. | 412 | * published in the device descriptor, either numbers or strings or both. |
@@ -431,6 +455,54 @@ static inline u16 get_default_bcdDevice(void) | |||
431 | return bcdDevice; | 455 | return bcdDevice; |
432 | } | 456 | } |
433 | 457 | ||
458 | struct usb_function_driver { | ||
459 | const char *name; | ||
460 | struct module *mod; | ||
461 | struct list_head list; | ||
462 | struct usb_function_instance *(*alloc_inst)(void); | ||
463 | struct usb_function *(*alloc_func)(struct usb_function_instance *inst); | ||
464 | }; | ||
465 | |||
466 | struct usb_function_instance { | ||
467 | struct usb_function_driver *fd; | ||
468 | void (*free_func_inst)(struct usb_function_instance *inst); | ||
469 | }; | ||
470 | |||
471 | void usb_function_unregister(struct usb_function_driver *f); | ||
472 | int usb_function_register(struct usb_function_driver *newf); | ||
473 | void usb_put_function_instance(struct usb_function_instance *fi); | ||
474 | void usb_put_function(struct usb_function *f); | ||
475 | struct usb_function_instance *usb_get_function_instance(const char *name); | ||
476 | struct usb_function *usb_get_function(struct usb_function_instance *fi); | ||
477 | |||
478 | struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, | ||
479 | int val); | ||
480 | int usb_add_config_only(struct usb_composite_dev *cdev, | ||
481 | struct usb_configuration *config); | ||
482 | void usb_remove_function(struct usb_configuration *c, struct usb_function *f); | ||
483 | |||
484 | #define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ | ||
485 | static struct usb_function_driver _name ## usb_func = { \ | ||
486 | .name = __stringify(_name), \ | ||
487 | .mod = THIS_MODULE, \ | ||
488 | .alloc_inst = _inst_alloc, \ | ||
489 | .alloc_func = _func_alloc, \ | ||
490 | }; \ | ||
491 | MODULE_ALIAS("usbfunc:"__stringify(_name)); | ||
492 | |||
493 | #define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \ | ||
494 | DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \ | ||
495 | static int __init _name ## mod_init(void) \ | ||
496 | { \ | ||
497 | return usb_function_register(&_name ## usb_func); \ | ||
498 | } \ | ||
499 | static void __exit _name ## mod_exit(void) \ | ||
500 | { \ | ||
501 | usb_function_unregister(&_name ## usb_func); \ | ||
502 | } \ | ||
503 | module_init(_name ## mod_init); \ | ||
504 | module_exit(_name ## mod_exit) | ||
505 | |||
434 | /* messaging utils */ | 506 | /* messaging utils */ |
435 | #define DBG(d, fmt, args...) \ | 507 | #define DBG(d, fmt, args...) \ |
436 | dev_dbg(&(d)->gadget->dev , fmt , ## args) | 508 | dev_dbg(&(d)->gadget->dev , fmt , ## args) |