Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
composite.h
Go to the documentation of this file.
1 /*
2  * composite.h -- framework for usb gadgets which are composite devices
3  *
4  * Copyright (C) 2006-2008 David Brownell
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef __LINUX_USB_COMPOSITE_H
22 #define __LINUX_USB_COMPOSITE_H
23 
24 /*
25  * This framework is an optional layer on top of the USB Gadget interface,
26  * making it easier to build (a) Composite devices, supporting multiple
27  * functions within any single configuration, and (b) Multi-configuration
28  * devices, also supporting multiple functions but without necessarily
29  * having more than one function per configuration.
30  *
31  * Example: a device with a single configuration supporting both network
32  * link and mass storage functions is a composite device. Those functions
33  * might alternatively be packaged in individual configurations, but in
34  * the composite model the host can use both functions at the same time.
35  */
36 
37 #include <linux/usb/ch9.h>
38 #include <linux/usb/gadget.h>
39 
40 /*
41  * USB function drivers should return USB_GADGET_DELAYED_STATUS if they
42  * wish to delay the data/status stages of the control transfer till they
43  * are ready. The control transfer will then be kept from completing till
44  * all the function drivers that requested for USB_GADGET_DELAYED_STAUS
45  * invoke usb_composite_setup_continue().
46  */
47 #define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */
48 
49 struct usb_configuration;
50 
112 struct usb_function {
113  const char *name;
118 
120 
121  /* REVISIT: bind() functions can be marked __init, which
122  * makes trouble for section mismatch analysis. See if
123  * we can't restructure things to avoid mismatching.
124  * Related: unbind() may kfree() but bind() won't...
125  */
126 
127  /* configuration management: bind/unbind */
129  struct usb_function *);
131  struct usb_function *);
132 
133  /* runtime state management */
134  int (*set_alt)(struct usb_function *,
135  unsigned interface, unsigned alt);
136  int (*get_alt)(struct usb_function *,
137  unsigned interface);
138  void (*disable)(struct usb_function *);
139  int (*setup)(struct usb_function *,
140  const struct usb_ctrlrequest *);
141  void (*suspend)(struct usb_function *);
142  void (*resume)(struct usb_function *);
143 
144  /* USB 3.0 additions */
147  u8 suspend_opt);
148  /* private: */
149  /* internals */
150  struct list_head list;
152 };
153 
154 int usb_add_function(struct usb_configuration *, struct usb_function *);
155 
157 int usb_function_activate(struct usb_function *);
158 
159 int usb_interface_id(struct usb_configuration *, struct usb_function *);
160 
161 int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
162  struct usb_ep *_ep);
163 
164 #define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
165 
208  const char *label;
211 
212  /* REVISIT: bind() functions can be marked __init, which
213  * makes trouble for section mismatch analysis. See if
214  * we can't restructure things to avoid mismatching...
215  */
216 
217  /* configuration management: unbind/setup */
220  const struct usb_ctrlrequest *);
221 
222  /* fields in the config descriptor */
227 
229 
230  /* private: */
231  /* internals */
232  struct list_head list;
235  unsigned superspeed:1;
236  unsigned highspeed:1;
237  unsigned fullspeed:1;
239 };
240 
241 int usb_add_config(struct usb_composite_dev *,
242  struct usb_configuration *,
243  int (*)(struct usb_configuration *));
244 
246  struct usb_configuration *);
247 
289  const char *name;
290  const char *iProduct;
291  const char *iManufacturer;
292  const char *iSerialNumber;
293  const struct usb_device_descriptor *dev;
296  unsigned needs_serial:1;
297 
300 
302 
303  /* global suspend hooks */
306 };
307 
311 
312 
347  struct usb_request *req;
348  unsigned bufsiz;
349 
351 
352  /* private: */
353  /* internals */
354  unsigned int suspended:1;
362 
363  /* the gadget driver won't enable the data pullup
364  * while the deactivation count is nonzero.
365  */
366  unsigned deactivations;
367 
368  /* the composite driver won't complete the control transfer's
369  * data/status stages till delayed_status is zero.
370  */
372 
373  /* protects deactivations and delayed_status counts*/
375 };
376 
377 extern int usb_string_id(struct usb_composite_dev *c);
378 extern int usb_string_ids_tab(struct usb_composite_dev *c,
379  struct usb_string *str);
380 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
381 
382 
383 /* messaging utils */
384 #define DBG(d, fmt, args...) \
385  dev_dbg(&(d)->gadget->dev , fmt , ## args)
386 #define VDBG(d, fmt, args...) \
387  dev_vdbg(&(d)->gadget->dev , fmt , ## args)
388 #define ERROR(d, fmt, args...) \
389  dev_err(&(d)->gadget->dev , fmt , ## args)
390 #define WARNING(d, fmt, args...) \
391  dev_warn(&(d)->gadget->dev , fmt , ## args)
392 #define INFO(d, fmt, args...) \
393  dev_info(&(d)->gadget->dev , fmt , ## args)
394 
395 #endif /* __LINUX_USB_COMPOSITE_H */