aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb/composite.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/usb/composite.h')
-rw-r--r--include/linux/usb/composite.h75
1 files changed, 73 insertions, 2 deletions
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index b09c37e04a91..3c671c1b37f6 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -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
119struct usb_function { 122struct 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
161int usb_add_function(struct usb_configuration *, struct usb_function *); 167int 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
@@ -316,7 +323,15 @@ struct usb_composite_driver {
316extern int usb_composite_probe(struct usb_composite_driver *driver); 323extern int usb_composite_probe(struct usb_composite_driver *driver);
317extern void usb_composite_unregister(struct usb_composite_driver *driver); 324extern void usb_composite_unregister(struct usb_composite_driver *driver);
318extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); 325extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
326extern int composite_dev_prepare(struct usb_composite_driver *composite,
327 struct usb_composite_dev *cdev);
328void composite_dev_cleanup(struct usb_composite_dev *cdev);
319 329
330static inline struct usb_composite_driver *to_cdriver(
331 struct usb_gadget_driver *gdrv)
332{
333 return container_of(gdrv, struct usb_composite_driver, gadget_driver);
334}
320 335
321/** 336/**
322 * struct usb_composite_device - represents one composite usb gadget 337 * struct usb_composite_device - represents one composite usb gadget
@@ -360,6 +375,7 @@ struct usb_composite_dev {
360 unsigned int suspended:1; 375 unsigned int suspended:1;
361 struct usb_device_descriptor desc; 376 struct usb_device_descriptor desc;
362 struct list_head configs; 377 struct list_head configs;
378 struct list_head gstrings;
363 struct usb_composite_driver *driver; 379 struct usb_composite_driver *driver;
364 u8 next_string_id; 380 u8 next_string_id;
365 char *def_manufacturer; 381 char *def_manufacturer;
@@ -381,8 +397,15 @@ struct usb_composite_dev {
381extern int usb_string_id(struct usb_composite_dev *c); 397extern int usb_string_id(struct usb_composite_dev *c);
382extern int usb_string_ids_tab(struct usb_composite_dev *c, 398extern int usb_string_ids_tab(struct usb_composite_dev *c,
383 struct usb_string *str); 399 struct usb_string *str);
400extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev,
401 struct usb_gadget_strings **sp, unsigned n_strings);
402
384extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 403extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
385 404
405extern void composite_disconnect(struct usb_gadget *gadget);
406extern int composite_setup(struct usb_gadget *gadget,
407 const struct usb_ctrlrequest *ctrl);
408
386/* 409/*
387 * Some systems will need runtime overrides for the product identifiers 410 * Some systems will need runtime overrides for the product identifiers
388 * published in the device descriptor, either numbers or strings or both. 411 * published in the device descriptor, either numbers or strings or both.
@@ -431,6 +454,54 @@ static inline u16 get_default_bcdDevice(void)
431 return bcdDevice; 454 return bcdDevice;
432} 455}
433 456
457struct usb_function_driver {
458 const char *name;
459 struct module *mod;
460 struct list_head list;
461 struct usb_function_instance *(*alloc_inst)(void);
462 struct usb_function *(*alloc_func)(struct usb_function_instance *inst);
463};
464
465struct usb_function_instance {
466 struct usb_function_driver *fd;
467 void (*free_func_inst)(struct usb_function_instance *inst);
468};
469
470void usb_function_unregister(struct usb_function_driver *f);
471int usb_function_register(struct usb_function_driver *newf);
472void usb_put_function_instance(struct usb_function_instance *fi);
473void usb_put_function(struct usb_function *f);
474struct usb_function_instance *usb_get_function_instance(const char *name);
475struct usb_function *usb_get_function(struct usb_function_instance *fi);
476
477struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev,
478 int val);
479int usb_add_config_only(struct usb_composite_dev *cdev,
480 struct usb_configuration *config);
481void usb_remove_function(struct usb_configuration *c, struct usb_function *f);
482
483#define DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \
484 static struct usb_function_driver _name ## usb_func = { \
485 .name = __stringify(_name), \
486 .mod = THIS_MODULE, \
487 .alloc_inst = _inst_alloc, \
488 .alloc_func = _func_alloc, \
489 }; \
490 MODULE_ALIAS("usbfunc:"__stringify(_name));
491
492#define DECLARE_USB_FUNCTION_INIT(_name, _inst_alloc, _func_alloc) \
493 DECLARE_USB_FUNCTION(_name, _inst_alloc, _func_alloc) \
494 static int __init _name ## mod_init(void) \
495 { \
496 return usb_function_register(&_name ## usb_func); \
497 } \
498 static void __exit _name ## mod_exit(void) \
499 { \
500 usb_function_unregister(&_name ## usb_func); \
501 } \
502 module_init(_name ## mod_init); \
503 module_exit(_name ## mod_exit)
504
434/* messaging utils */ 505/* messaging utils */
435#define DBG(d, fmt, args...) \ 506#define DBG(d, fmt, args...) \
436 dev_dbg(&(d)->gadget->dev , fmt , ## args) 507 dev_dbg(&(d)->gadget->dev , fmt , ## args)