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