| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 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 |  | 
| Roger Quadros | 1b9ba00 | 2011-05-09 13:08:06 +0300 | [diff] [blame] | 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 */ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | struct usb_configuration; | 
|  | 50 |  | 
|  | 51 | /** | 
|  | 52 | * struct usb_function - describes one function of a configuration | 
|  | 53 | * @name: For diagnostics, identifies the function. | 
|  | 54 | * @strings: tables of strings, keyed by identifiers assigned during bind() | 
|  | 55 | *	and by language IDs provided in control requests | 
|  | 56 | * @descriptors: Table of full (or low) speed descriptors, using interface and | 
|  | 57 | *	string identifiers assigned during @bind().  If this pointer is null, | 
|  | 58 | *	the function will not be available at full speed (or at low speed). | 
|  | 59 | * @hs_descriptors: Table of high speed descriptors, using interface and | 
|  | 60 | *	string identifiers assigned during @bind().  If this pointer is null, | 
|  | 61 | *	the function will not be available at high speed. | 
| Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 62 | * @ss_descriptors: Table of super speed descriptors, using interface and | 
|  | 63 | *	string identifiers assigned during @bind(). If this | 
|  | 64 | *	pointer is null after initiation, the function will not | 
|  | 65 | *	be available at super speed. | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 66 | * @config: assigned when @usb_add_function() is called; this is the | 
|  | 67 | *	configuration with which this function is associated. | 
|  | 68 | * @bind: Before the gadget can register, all of its functions bind() to the | 
|  | 69 | *	available resources including string and interface identifiers used | 
|  | 70 | *	in interface or class descriptors; endpoints; I/O buffers; and so on. | 
|  | 71 | * @unbind: Reverses @bind; called as a side effect of unregistering the | 
|  | 72 | *	driver which added this function. | 
|  | 73 | * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may | 
|  | 74 | *	initialize usb_ep.driver data at this time (when it is used). | 
|  | 75 | *	Note that setting an interface to its current altsetting resets | 
|  | 76 | *	interface state, and that all interfaces have a disabled state. | 
|  | 77 | * @get_alt: Returns the active altsetting.  If this is not provided, | 
|  | 78 | *	then only altsetting zero is supported. | 
|  | 79 | * @disable: (REQUIRED) Indicates the function should be disabled.  Reasons | 
|  | 80 | *	include host resetting or reconfiguring the gadget, and disconnection. | 
|  | 81 | * @setup: Used for interface-specific control requests. | 
|  | 82 | * @suspend: Notifies functions when the host stops sending USB traffic. | 
|  | 83 | * @resume: Notifies functions when the host restarts USB traffic. | 
| Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 84 | * @get_status: Returns function status as a reply to | 
|  | 85 | *	GetStatus() request when the recepient is Interface. | 
|  | 86 | * @func_suspend: callback to be called when | 
|  | 87 | *	SetFeature(FUNCTION_SUSPEND) is reseived | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 88 | * | 
|  | 89 | * A single USB function uses one or more interfaces, and should in most | 
|  | 90 | * cases support operation at both full and high speeds.  Each function is | 
|  | 91 | * associated by @usb_add_function() with a one configuration; that function | 
|  | 92 | * causes @bind() to be called so resources can be allocated as part of | 
|  | 93 | * setting up a gadget driver.  Those resources include endpoints, which | 
|  | 94 | * should be allocated using @usb_ep_autoconfig(). | 
|  | 95 | * | 
|  | 96 | * To support dual speed operation, a function driver provides descriptors | 
|  | 97 | * for both high and full speed operation.  Except in rare cases that don't | 
|  | 98 | * involve bulk endpoints, each speed needs different endpoint descriptors. | 
|  | 99 | * | 
|  | 100 | * Function drivers choose their own strategies for managing instance data. | 
|  | 101 | * The simplest strategy just declares it "static', which means the function | 
|  | 102 | * can only be activated once.  If the function needs to be exposed in more | 
|  | 103 | * than one configuration at a given speed, it needs to support multiple | 
|  | 104 | * usb_function structures (one for each configuration). | 
|  | 105 | * | 
|  | 106 | * A more complex strategy might encapsulate a @usb_function structure inside | 
|  | 107 | * a driver-specific instance structure to allows multiple activations.  An | 
|  | 108 | * example of multiple activations might be a CDC ACM function that supports | 
|  | 109 | * two or more distinct instances within the same configuration, providing | 
|  | 110 | * several independent logical data links to a USB host. | 
|  | 111 | */ | 
|  | 112 | struct usb_function { | 
|  | 113 | const char			*name; | 
|  | 114 | struct usb_gadget_strings	**strings; | 
|  | 115 | struct usb_descriptor_header	**descriptors; | 
|  | 116 | struct usb_descriptor_header	**hs_descriptors; | 
| Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 117 | struct usb_descriptor_header	**ss_descriptors; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | struct usb_configuration	*config; | 
|  | 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 */ | 
|  | 128 | int			(*bind)(struct usb_configuration *, | 
|  | 129 | struct usb_function *); | 
|  | 130 | void			(*unbind)(struct usb_configuration *, | 
|  | 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 |  | 
| Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 144 | /* USB 3.0 additions */ | 
|  | 145 | int			(*get_status)(struct usb_function *); | 
|  | 146 | int			(*func_suspend)(struct usb_function *, | 
|  | 147 | u8 suspend_opt); | 
| Randy Dunlap | cac85a8 | 2009-04-29 21:04:19 -0700 | [diff] [blame] | 148 | /* private: */ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 149 | /* internals */ | 
|  | 150 | struct list_head		list; | 
| Laurent Pinchart | 5242658 | 2009-10-21 00:03:38 +0200 | [diff] [blame] | 151 | DECLARE_BITMAP(endpoints, 32); | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 152 | }; | 
|  | 153 |  | 
|  | 154 | int usb_add_function(struct usb_configuration *, struct usb_function *); | 
|  | 155 |  | 
| David Brownell | 60beed9 | 2008-08-18 17:38:22 -0700 | [diff] [blame] | 156 | int usb_function_deactivate(struct usb_function *); | 
|  | 157 | int usb_function_activate(struct usb_function *); | 
|  | 158 |  | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 159 | int usb_interface_id(struct usb_configuration *, struct usb_function *); | 
|  | 160 |  | 
| Tatyana Brokhman | 48767a4 | 2011-06-28 16:33:49 +0300 | [diff] [blame] | 161 | int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, | 
|  | 162 | struct usb_ep *_ep); | 
|  | 163 |  | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 164 | #define	MAX_CONFIG_INTERFACES		16	/* arbitrary; max 255 */ | 
|  | 165 |  | 
|  | 166 | /** | 
|  | 167 | * struct usb_configuration - represents one gadget configuration | 
|  | 168 | * @label: For diagnostics, describes the configuration. | 
|  | 169 | * @strings: Tables of strings, keyed by identifiers assigned during @bind() | 
|  | 170 | *	and by language IDs provided in control requests. | 
|  | 171 | * @descriptors: Table of descriptors preceding all function descriptors. | 
|  | 172 | *	Examples include OTG and vendor-specific descriptors. | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 173 | * @unbind: Reverses @bind; called as a side effect of unregistering the | 
|  | 174 | *	driver which added this configuration. | 
|  | 175 | * @setup: Used to delegate control requests that aren't handled by standard | 
|  | 176 | *	device infrastructure or directed at a specific interface. | 
|  | 177 | * @bConfigurationValue: Copied into configuration descriptor. | 
|  | 178 | * @iConfiguration: Copied into configuration descriptor. | 
|  | 179 | * @bmAttributes: Copied into configuration descriptor. | 
|  | 180 | * @bMaxPower: Copied into configuration descriptor. | 
|  | 181 | * @cdev: assigned by @usb_add_config() before calling @bind(); this is | 
|  | 182 | *	the device associated with this configuration. | 
|  | 183 | * | 
|  | 184 | * Configurations are building blocks for gadget drivers structured around | 
|  | 185 | * function drivers.  Simple USB gadgets require only one function and one | 
|  | 186 | * configuration, and handle dual-speed hardware by always providing the same | 
|  | 187 | * functionality.  Slightly more complex gadgets may have more than one | 
|  | 188 | * single-function configuration at a given speed; or have configurations | 
|  | 189 | * that only work at one speed. | 
|  | 190 | * | 
|  | 191 | * Composite devices are, by definition, ones with configurations which | 
|  | 192 | * include more than one function. | 
|  | 193 | * | 
|  | 194 | * The lifecycle of a usb_configuration includes allocation, initialization | 
|  | 195 | * of the fields described above, and calling @usb_add_config() to set up | 
|  | 196 | * internal data and bind it to a specific device.  The configuration's | 
|  | 197 | * @bind() method is then used to initialize all the functions and then | 
|  | 198 | * call @usb_add_function() for them. | 
|  | 199 | * | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 200 | * Those functions would normally be independent of each other, but that's | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 201 | * not mandatory.  CDC WMC devices are an example where functions often | 
|  | 202 | * depend on other functions, with some functions subsidiary to others. | 
|  | 203 | * Such interdependency may be managed in any way, so long as all of the | 
|  | 204 | * descriptors complete by the time the composite driver returns from | 
|  | 205 | * its bind() routine. | 
|  | 206 | */ | 
|  | 207 | struct usb_configuration { | 
|  | 208 | const char			*label; | 
|  | 209 | struct usb_gadget_strings	**strings; | 
|  | 210 | const struct usb_descriptor_header **descriptors; | 
|  | 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 |  | 
| Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 217 | /* configuration management: unbind/setup */ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 218 | void			(*unbind)(struct usb_configuration *); | 
|  | 219 | int			(*setup)(struct usb_configuration *, | 
|  | 220 | const struct usb_ctrlrequest *); | 
|  | 221 |  | 
|  | 222 | /* fields in the config descriptor */ | 
|  | 223 | u8			bConfigurationValue; | 
|  | 224 | u8			iConfiguration; | 
|  | 225 | u8			bmAttributes; | 
|  | 226 | u8			bMaxPower; | 
|  | 227 |  | 
|  | 228 | struct usb_composite_dev	*cdev; | 
|  | 229 |  | 
| Randy Dunlap | cac85a8 | 2009-04-29 21:04:19 -0700 | [diff] [blame] | 230 | /* private: */ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 231 | /* internals */ | 
|  | 232 | struct list_head	list; | 
|  | 233 | struct list_head	functions; | 
|  | 234 | u8			next_interface_id; | 
| Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 235 | unsigned		superspeed:1; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 236 | unsigned		highspeed:1; | 
|  | 237 | unsigned		fullspeed:1; | 
|  | 238 | struct usb_function	*interface[MAX_CONFIG_INTERFACES]; | 
|  | 239 | }; | 
|  | 240 |  | 
|  | 241 | int usb_add_config(struct usb_composite_dev *, | 
| Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 242 | struct usb_configuration *, | 
|  | 243 | int (*)(struct usb_configuration *)); | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 244 |  | 
| Benoit Goby | 51cce6f | 2012-05-10 10:07:57 +0200 | [diff] [blame] | 245 | void usb_remove_config(struct usb_composite_dev *, | 
|  | 246 | struct usb_configuration *); | 
|  | 247 |  | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 248 | /** | 
|  | 249 | * struct usb_composite_driver - groups configurations into a gadget | 
|  | 250 | * @name: For diagnostics, identifies the driver. | 
| Michal Nazarewicz | ad1a810 | 2010-08-12 17:43:46 +0200 | [diff] [blame] | 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. | 
| Andrzej Pietrasiewicz | cad4cd8 | 2012-05-10 10:08:00 +0200 | [diff] [blame] | 256 | * @iSerialNumber: Used as iSerialNumber override if @dev->iSerialNumber is | 
|  | 257 | *	not set. | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 258 | * @dev: Template descriptor for the device, including default device | 
|  | 259 | *	identifiers. | 
|  | 260 | * @strings: tables of strings, keyed by identifiers assigned during bind() | 
|  | 261 | *	and language IDs provided in control requests | 
| Tatyana Brokhman | 35a0e0b | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 262 | * @max_speed: Highest speed the driver supports. | 
| Michal Nazarewicz | ad1a810 | 2010-08-12 17:43:46 +0200 | [diff] [blame] | 263 | * @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. | 
| Michal Nazarewicz | 07a18bd | 2010-08-12 17:43:54 +0200 | [diff] [blame] | 265 | * @unbind: Reverses bind; called as a side effect of unregistering | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 266 | *	this driver. | 
| Randy Dunlap | d187abb | 2010-08-11 12:07:13 -0700 | [diff] [blame] | 267 | * @disconnect: optional driver disconnect method | 
| David Brownell | 8942939 | 2009-03-19 14:14:17 -0700 | [diff] [blame] | 268 | * @suspend: Notifies when the host stops sending USB traffic, | 
|  | 269 | *	after function notifications | 
|  | 270 | * @resume: Notifies configuration when the host restarts USB traffic, | 
|  | 271 | *	before function notifications | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 272 | * | 
|  | 273 | * Devices default to reporting self powered operation.  Devices which rely | 
|  | 274 | * on bus powered operation should report this in their @bind() method. | 
|  | 275 | * | 
| Michal Nazarewicz | 07a18bd | 2010-08-12 17:43:54 +0200 | [diff] [blame] | 276 | * Before returning from bind, various fields in the template descriptor | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 277 | * may be overridden.  These include the idVendor/idProduct/bcdDevice values | 
|  | 278 | * normally to bind the appropriate host side driver, and the three strings | 
|  | 279 | * (iManufacturer, iProduct, iSerialNumber) normally used to provide user | 
|  | 280 | * meaningful device identifiers.  (The strings will not be defined unless | 
|  | 281 | * they are defined in @dev and @strings.)  The correct ep0 maxpacket size | 
|  | 282 | * is also reported, as defined by the underlying controller driver. | 
|  | 283 | */ | 
|  | 284 | struct usb_composite_driver { | 
|  | 285 | const char				*name; | 
| Michal Nazarewicz | ad1a810 | 2010-08-12 17:43:46 +0200 | [diff] [blame] | 286 | const char				*iProduct; | 
|  | 287 | const char				*iManufacturer; | 
| Andrzej Pietrasiewicz | cad4cd8 | 2012-05-10 10:08:00 +0200 | [diff] [blame] | 288 | const char				*iSerialNumber; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 289 | const struct usb_device_descriptor	*dev; | 
|  | 290 | struct usb_gadget_strings		**strings; | 
| Tatyana Brokhman | 35a0e0b | 2011-06-29 16:41:49 +0300 | [diff] [blame] | 291 | enum usb_device_speed			max_speed; | 
| Michal Nazarewicz | ad1a810 | 2010-08-12 17:43:46 +0200 | [diff] [blame] | 292 | unsigned		needs_serial:1; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 293 |  | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 294 | int			(*unbind)(struct usb_composite_dev *); | 
| David Brownell | 8942939 | 2009-03-19 14:14:17 -0700 | [diff] [blame] | 295 |  | 
| Michal Nazarewicz | 3f3e12d | 2010-06-21 13:57:08 +0200 | [diff] [blame] | 296 | void			(*disconnect)(struct usb_composite_dev *); | 
|  | 297 |  | 
| David Brownell | 8942939 | 2009-03-19 14:14:17 -0700 | [diff] [blame] | 298 | /* global suspend hooks */ | 
|  | 299 | void			(*suspend)(struct usb_composite_dev *); | 
|  | 300 | void			(*resume)(struct usb_composite_dev *); | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 301 | }; | 
|  | 302 |  | 
| Michal Nazarewicz | 07a18bd | 2010-08-12 17:43:54 +0200 | [diff] [blame] | 303 | 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); | 
| Roger Quadros | 1b9ba00 | 2011-05-09 13:08:06 +0300 | [diff] [blame] | 306 | extern void usb_composite_setup_continue(struct usb_composite_dev *cdev); | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 307 |  | 
|  | 308 |  | 
|  | 309 | /** | 
|  | 310 | * struct usb_composite_device - represents one composite usb gadget | 
|  | 311 | * @gadget: read-only, abstracts the gadget's usb peripheral controller | 
|  | 312 | * @req: used for control responses; buffer is pre-allocated | 
|  | 313 | * @bufsiz: size of buffer pre-allocated in @req | 
|  | 314 | * @config: the currently active configuration | 
|  | 315 | * | 
|  | 316 | * One of these devices is allocated and initialized before the | 
|  | 317 | * associated device driver's bind() is called. | 
|  | 318 | * | 
|  | 319 | * OPEN ISSUE:  it appears that some WUSB devices will need to be | 
|  | 320 | * built by combining a normal (wired) gadget with a wireless one. | 
|  | 321 | * This revision of the gadget framework should probably try to make | 
|  | 322 | * sure doing that won't hurt too much. | 
|  | 323 | * | 
|  | 324 | * One notion for how to handle Wireless USB devices involves: | 
|  | 325 | * (a) a second gadget here, discovery mechanism TBD, but likely | 
|  | 326 | *     needing separate "register/unregister WUSB gadget" calls; | 
|  | 327 | * (b) updates to usb_gadget to include flags "is it wireless", | 
|  | 328 | *     "is it wired", plus (presumably in a wrapper structure) | 
|  | 329 | *     bandgroup and PHY info; | 
|  | 330 | * (c) presumably a wireless_ep wrapping a usb_ep, and reporting | 
|  | 331 | *     wireless-specific parameters like maxburst and maxsequence; | 
|  | 332 | * (d) configurations that are specific to wireless links; | 
|  | 333 | * (e) function drivers that understand wireless configs and will | 
|  | 334 | *     support wireless for (additional) function instances; | 
|  | 335 | * (f) a function to support association setup (like CBAF), not | 
|  | 336 | *     necessarily requiring a wireless adapter; | 
|  | 337 | * (g) composite device setup that can create one or more wireless | 
|  | 338 | *     configs, including appropriate association setup support; | 
|  | 339 | * (h) more, TBD. | 
|  | 340 | */ | 
|  | 341 | struct usb_composite_dev { | 
|  | 342 | struct usb_gadget		*gadget; | 
|  | 343 | struct usb_request		*req; | 
|  | 344 | unsigned			bufsiz; | 
|  | 345 |  | 
|  | 346 | struct usb_configuration	*config; | 
|  | 347 |  | 
| Randy Dunlap | cac85a8 | 2009-04-29 21:04:19 -0700 | [diff] [blame] | 348 | /* private: */ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 349 | /* internals */ | 
| Fabien Chouteau | f48cf80 | 2010-04-23 14:21:26 +0200 | [diff] [blame] | 350 | unsigned int			suspended:1; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 351 | struct usb_device_descriptor	desc; | 
|  | 352 | struct list_head		configs; | 
|  | 353 | struct usb_composite_driver	*driver; | 
|  | 354 | u8				next_string_id; | 
| Michal Nazarewicz | ad1a810 | 2010-08-12 17:43:46 +0200 | [diff] [blame] | 355 | u8				manufacturer_override; | 
|  | 356 | u8				product_override; | 
|  | 357 | u8				serial_override; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 358 |  | 
| David Brownell | 60beed9 | 2008-08-18 17:38:22 -0700 | [diff] [blame] | 359 | /* the gadget driver won't enable the data pullup | 
|  | 360 | * while the deactivation count is nonzero. | 
|  | 361 | */ | 
|  | 362 | unsigned			deactivations; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 363 |  | 
| Roger Quadros | 1b9ba00 | 2011-05-09 13:08:06 +0300 | [diff] [blame] | 364 | /* the composite driver won't complete the control transfer's | 
|  | 365 | * data/status stages till delayed_status is zero. | 
|  | 366 | */ | 
|  | 367 | int				delayed_status; | 
|  | 368 |  | 
|  | 369 | /* protects deactivations and delayed_status counts*/ | 
| David Brownell | 60beed9 | 2008-08-18 17:38:22 -0700 | [diff] [blame] | 370 | spinlock_t			lock; | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 371 | }; | 
|  | 372 |  | 
|  | 373 | extern int usb_string_id(struct usb_composite_dev *c); | 
| Michal Nazarewicz | f2adc4f | 2010-06-16 12:07:59 +0200 | [diff] [blame] | 374 | extern int usb_string_ids_tab(struct usb_composite_dev *c, | 
|  | 375 | struct usb_string *str); | 
|  | 376 | extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); | 
|  | 377 |  | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 378 |  | 
|  | 379 | /* messaging utils */ | 
|  | 380 | #define DBG(d, fmt, args...) \ | 
|  | 381 | dev_dbg(&(d)->gadget->dev , fmt , ## args) | 
|  | 382 | #define VDBG(d, fmt, args...) \ | 
|  | 383 | dev_vdbg(&(d)->gadget->dev , fmt , ## args) | 
|  | 384 | #define ERROR(d, fmt, args...) \ | 
|  | 385 | dev_err(&(d)->gadget->dev , fmt , ## args) | 
| Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 386 | #define WARNING(d, fmt, args...) \ | 
| David Brownell | 40982be | 2008-06-19 17:52:58 -0700 | [diff] [blame] | 387 | dev_warn(&(d)->gadget->dev , fmt , ## args) | 
|  | 388 | #define INFO(d, fmt, args...) \ | 
|  | 389 | dev_info(&(d)->gadget->dev , fmt , ## args) | 
|  | 390 |  | 
|  | 391 | #endif	/* __LINUX_USB_COMPOSITE_H */ |