Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * epautoconf.c -- endpoint autoconfiguration for usb gadget drivers |
| 3 | * |
| 4 | * Copyright (C) 2004 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
Sebastian Andrzej Siewior | dc995fc | 2012-09-06 20:11:12 +0200 | [diff] [blame] | 13 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/device.h> |
| 17 | |
| 18 | #include <linux/ctype.h> |
| 19 | #include <linux/string.h> |
| 20 | |
David Brownell | 5f84813 | 2006-12-16 15:34:53 -0800 | [diff] [blame] | 21 | #include <linux/usb/ch9.h> |
David Brownell | 9454a57 | 2007-10-04 18:05:17 -0700 | [diff] [blame] | 22 | #include <linux/usb/gadget.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include "gadget_chips.h" |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* |
| 27 | * This should work with endpoints from controller drivers sharing the |
| 28 | * same endpoint naming convention. By example: |
| 29 | * |
| 30 | * - ep1, ep2, ... address is fixed, not direction or type |
| 31 | * - ep1in, ep2out, ... address and direction are fixed, not type |
| 32 | * - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction |
| 33 | * - ep1in-bulk, ep2out-iso, ... all three are fixed |
| 34 | * - ep-* ... no functionality restrictions |
| 35 | * |
| 36 | * Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal. |
| 37 | * Less common restrictions are implied by gadget_is_*(). |
| 38 | * |
| 39 | * NOTE: each endpoint is unidirectional, as specified by its USB |
| 40 | * descriptor; and isn't specific to a configuration or altsetting. |
| 41 | */ |
Michal Nazarewicz | 28824b1 | 2010-05-05 12:53:13 +0200 | [diff] [blame] | 42 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | ep_matches ( |
| 44 | struct usb_gadget *gadget, |
| 45 | struct usb_ep *ep, |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 46 | struct usb_endpoint_descriptor *desc, |
| 47 | struct usb_ss_ep_comp_descriptor *ep_comp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | ) |
| 49 | { |
| 50 | u8 type; |
| 51 | const char *tmp; |
| 52 | u16 max; |
| 53 | |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 54 | int num_req_streams = 0; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* endpoint already claimed? */ |
David Brownell | a947522 | 2007-07-30 12:31:07 -0700 | [diff] [blame] | 57 | if (NULL != ep->driver_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return 0; |
David Brownell | a353678 | 2006-07-06 15:48:53 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* only support ep0 for portable CONTROL traffic */ |
| 61 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
| 62 | if (USB_ENDPOINT_XFER_CONTROL == type) |
| 63 | return 0; |
| 64 | |
| 65 | /* some other naming convention */ |
| 66 | if ('e' != ep->name[0]) |
| 67 | return 0; |
| 68 | |
| 69 | /* type-restriction: "-iso", "-bulk", or "-int". |
| 70 | * direction-restriction: "in", "out". |
| 71 | */ |
| 72 | if ('-' != ep->name[2]) { |
| 73 | tmp = strrchr (ep->name, '-'); |
| 74 | if (tmp) { |
| 75 | switch (type) { |
| 76 | case USB_ENDPOINT_XFER_INT: |
| 77 | /* bulk endpoints handle interrupt transfers, |
| 78 | * except the toggle-quirky iso-synch kind |
| 79 | */ |
| 80 | if ('s' == tmp[2]) // == "-iso" |
| 81 | return 0; |
| 82 | /* for now, avoid PXA "interrupt-in"; |
| 83 | * it's documented as never using DATA1. |
| 84 | */ |
| 85 | if (gadget_is_pxa (gadget) |
| 86 | && 'i' == tmp [1]) |
| 87 | return 0; |
| 88 | break; |
| 89 | case USB_ENDPOINT_XFER_BULK: |
| 90 | if ('b' != tmp[1]) // != "-bulk" |
| 91 | return 0; |
| 92 | break; |
| 93 | case USB_ENDPOINT_XFER_ISOC: |
| 94 | if ('s' != tmp[2]) // != "-iso" |
| 95 | return 0; |
| 96 | } |
| 97 | } else { |
| 98 | tmp = ep->name + strlen (ep->name); |
| 99 | } |
| 100 | |
| 101 | /* direction-restriction: "..in-..", "out-.." */ |
| 102 | tmp--; |
| 103 | if (!isdigit (*tmp)) { |
| 104 | if (desc->bEndpointAddress & USB_DIR_IN) { |
| 105 | if ('n' != *tmp) |
| 106 | return 0; |
| 107 | } else { |
| 108 | if ('t' != *tmp) |
| 109 | return 0; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
Jassi Brar | 553fbcd | 2011-01-14 11:55:53 +0900 | [diff] [blame] | 114 | /* |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 115 | * Get the number of required streams from the EP companion |
| 116 | * descriptor and see if the EP matches it |
| 117 | */ |
| 118 | if (usb_endpoint_xfer_bulk(desc)) { |
Sebastian Andrzej Siewior | c74c930 | 2012-01-11 21:42:44 +0100 | [diff] [blame] | 119 | if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) { |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 120 | num_req_streams = ep_comp->bmAttributes & 0x1f; |
| 121 | if (num_req_streams > ep->max_streams) |
| 122 | return 0; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | } |
| 126 | |
| 127 | /* |
Jassi Brar | 553fbcd | 2011-01-14 11:55:53 +0900 | [diff] [blame] | 128 | * If the protocol driver hasn't yet decided on wMaxPacketSize |
| 129 | * and wants to know the maximum possible, provide the info. |
| 130 | */ |
| 131 | if (desc->wMaxPacketSize == 0) |
| 132 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket); |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* endpoint maxpacket size is an input parameter, except for bulk |
| 135 | * where it's an output parameter representing the full speed limit. |
| 136 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. |
| 137 | */ |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 138 | max = 0x7ff & usb_endpoint_maxp(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | switch (type) { |
| 140 | case USB_ENDPOINT_XFER_INT: |
Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 141 | /* INT: limit 64 bytes full speed, 1024 high/super speed */ |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 142 | if (!gadget_is_dualspeed(gadget) && max > 64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | /* FALLTHROUGH */ |
| 145 | |
| 146 | case USB_ENDPOINT_XFER_ISOC: |
Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 147 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | if (ep->maxpacket < max) |
| 149 | return 0; |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 150 | if (!gadget_is_dualspeed(gadget) && max > 1023) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | |
| 153 | /* BOTH: "high bandwidth" works only at high speed */ |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 154 | if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) { |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 155 | if (!gadget_is_dualspeed(gadget)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return 0; |
| 157 | /* configure your hardware with enough buffering!! */ |
| 158 | } |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | /* MATCH!! */ |
| 163 | |
| 164 | /* report address */ |
David Brownell | a4c39c4 | 2008-06-19 17:52:25 -0700 | [diff] [blame] | 165 | desc->bEndpointAddress &= USB_DIR_IN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | if (isdigit (ep->name [2])) { |
Julia Lawall | bb9496c | 2008-11-25 14:15:19 +0100 | [diff] [blame] | 167 | u8 num = simple_strtoul (&ep->name [2], NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | desc->bEndpointAddress |= num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } else if (desc->bEndpointAddress & USB_DIR_IN) { |
Sebastian Andrzej Siewior | e87bb71 | 2012-09-06 20:11:11 +0200 | [diff] [blame] | 170 | if (++gadget->in_epnum > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return 0; |
Sebastian Andrzej Siewior | e87bb71 | 2012-09-06 20:11:11 +0200 | [diff] [blame] | 172 | desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } else { |
Sebastian Andrzej Siewior | e87bb71 | 2012-09-06 20:11:11 +0200 | [diff] [blame] | 174 | if (++gadget->out_epnum > 15) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | return 0; |
Sebastian Andrzej Siewior | e87bb71 | 2012-09-06 20:11:11 +0200 | [diff] [blame] | 176 | desc->bEndpointAddress |= gadget->out_epnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* report (variable) full speed bulk maxpacket */ |
Tatyana Brokhman | bdb64d7 | 2011-06-29 16:41:50 +0300 | [diff] [blame] | 180 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | int size = ep->maxpacket; |
| 182 | |
| 183 | /* min() doesn't work on bitfields with gcc-3.5 */ |
| 184 | if (size > 64) |
| 185 | size = 64; |
| 186 | desc->wMaxPacketSize = cpu_to_le16(size); |
| 187 | } |
Tatyana Brokhman | 48767a4 | 2011-06-28 16:33:49 +0300 | [diff] [blame] | 188 | ep->address = desc->bEndpointAddress; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return 1; |
| 190 | } |
| 191 | |
Michal Nazarewicz | 28824b1 | 2010-05-05 12:53:13 +0200 | [diff] [blame] | 192 | static struct usb_ep * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | find_ep (struct usb_gadget *gadget, const char *name) |
| 194 | { |
| 195 | struct usb_ep *ep; |
| 196 | |
| 197 | list_for_each_entry (ep, &gadget->ep_list, ep_list) { |
| 198 | if (0 == strcmp (ep->name, name)) |
| 199 | return ep; |
| 200 | } |
| 201 | return NULL; |
| 202 | } |
| 203 | |
| 204 | /** |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 205 | * usb_ep_autoconfig_ss() - choose an endpoint matching the ep |
| 206 | * descriptor and ep companion descriptor |
| 207 | * @gadget: The device to which the endpoint must belong. |
| 208 | * @desc: Endpoint descriptor, with endpoint direction and transfer mode |
| 209 | * initialized. For periodic transfers, the maximum packet |
| 210 | * size must also be initialized. This is modified on |
| 211 | * success. |
| 212 | * @ep_comp: Endpoint companion descriptor, with the required |
| 213 | * number of streams. Will be modified when the chosen EP |
| 214 | * supports a different number of streams. |
| 215 | * |
| 216 | * This routine replaces the usb_ep_autoconfig when needed |
| 217 | * superspeed enhancments. If such enhancemnets are required, |
| 218 | * the FD should call usb_ep_autoconfig_ss directly and provide |
| 219 | * the additional ep_comp parameter. |
| 220 | * |
| 221 | * By choosing an endpoint to use with the specified descriptor, |
| 222 | * this routine simplifies writing gadget drivers that work with |
| 223 | * multiple USB device controllers. The endpoint would be |
| 224 | * passed later to usb_ep_enable(), along with some descriptor. |
| 225 | * |
| 226 | * That second descriptor won't always be the same as the first one. |
| 227 | * For example, isochronous endpoints can be autoconfigured for high |
| 228 | * bandwidth, and then used in several lower bandwidth altsettings. |
| 229 | * Also, high and full speed descriptors will be different. |
| 230 | * |
| 231 | * Be sure to examine and test the results of autoconfiguration |
| 232 | * on your hardware. This code may not make the best choices |
| 233 | * about how to use the USB controller, and it can't know all |
| 234 | * the restrictions that may apply. Some combinations of driver |
| 235 | * and hardware won't be able to autoconfigure. |
| 236 | * |
| 237 | * On success, this returns an un-claimed usb_ep, and modifies the endpoint |
| 238 | * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value |
| 239 | * is initialized as if the endpoint were used at full speed and |
| 240 | * the bmAttribute field in the ep companion descriptor is |
| 241 | * updated with the assigned number of streams if it is |
| 242 | * different from the original value. To prevent the endpoint |
| 243 | * from being returned by a later autoconfig call, claim it by |
| 244 | * assigning ep->driver_data to some non-null value. |
| 245 | * |
| 246 | * On failure, this returns a null endpoint descriptor. |
| 247 | */ |
| 248 | struct usb_ep *usb_ep_autoconfig_ss( |
| 249 | struct usb_gadget *gadget, |
| 250 | struct usb_endpoint_descriptor *desc, |
| 251 | struct usb_ss_ep_comp_descriptor *ep_comp |
| 252 | ) |
| 253 | { |
| 254 | struct usb_ep *ep; |
| 255 | u8 type; |
| 256 | |
| 257 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
| 258 | |
| 259 | /* First, apply chip-specific "best usage" knowledge. |
| 260 | * This might make a good usb_gadget_ops hook ... |
| 261 | */ |
| 262 | if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { |
| 263 | /* ep-e, ep-f are PIO with only 64 byte fifos */ |
| 264 | ep = find_ep (gadget, "ep-e"); |
| 265 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 266 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 267 | ep = find_ep (gadget, "ep-f"); |
| 268 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 269 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 270 | |
| 271 | } else if (gadget_is_goku (gadget)) { |
| 272 | if (USB_ENDPOINT_XFER_INT == type) { |
| 273 | /* single buffering is enough */ |
| 274 | ep = find_ep(gadget, "ep3-bulk"); |
| 275 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 276 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 277 | } else if (USB_ENDPOINT_XFER_BULK == type |
| 278 | && (USB_DIR_IN & desc->bEndpointAddress)) { |
| 279 | /* DMA may be available */ |
| 280 | ep = find_ep(gadget, "ep2-bulk"); |
| 281 | if (ep && ep_matches(gadget, ep, desc, |
| 282 | ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 283 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | #ifdef CONFIG_BLACKFIN |
| 287 | } else if (gadget_is_musbhdrc(gadget)) { |
| 288 | if ((USB_ENDPOINT_XFER_BULK == type) || |
| 289 | (USB_ENDPOINT_XFER_ISOC == type)) { |
| 290 | if (USB_DIR_IN & desc->bEndpointAddress) |
| 291 | ep = find_ep (gadget, "ep5in"); |
| 292 | else |
| 293 | ep = find_ep (gadget, "ep6out"); |
| 294 | } else if (USB_ENDPOINT_XFER_INT == type) { |
| 295 | if (USB_DIR_IN & desc->bEndpointAddress) |
| 296 | ep = find_ep(gadget, "ep1in"); |
| 297 | else |
| 298 | ep = find_ep(gadget, "ep2out"); |
| 299 | } else |
| 300 | ep = NULL; |
| 301 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 302 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 303 | #endif |
| 304 | } |
| 305 | |
| 306 | /* Second, look at endpoints until an unclaimed one looks usable */ |
| 307 | list_for_each_entry (ep, &gadget->ep_list, ep_list) { |
| 308 | if (ep_matches(gadget, ep, desc, ep_comp)) |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 309 | goto found_ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* Fail */ |
| 313 | return NULL; |
Sebastian Andrzej Siewior | 609ca22 | 2012-02-06 18:46:35 +0100 | [diff] [blame] | 314 | found_ep: |
| 315 | ep->desc = NULL; |
| 316 | ep->comp_desc = NULL; |
| 317 | return ep; |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 318 | } |
Sebastian Andrzej Siewior | dc995fc | 2012-09-06 20:11:12 +0200 | [diff] [blame] | 319 | EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss); |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 320 | |
| 321 | /** |
| 322 | * usb_ep_autoconfig() - choose an endpoint matching the |
| 323 | * descriptor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * @gadget: The device to which the endpoint must belong. |
| 325 | * @desc: Endpoint descriptor, with endpoint direction and transfer mode |
| 326 | * initialized. For periodic transfers, the maximum packet |
| 327 | * size must also be initialized. This is modified on success. |
| 328 | * |
| 329 | * By choosing an endpoint to use with the specified descriptor, this |
| 330 | * routine simplifies writing gadget drivers that work with multiple |
| 331 | * USB device controllers. The endpoint would be passed later to |
| 332 | * usb_ep_enable(), along with some descriptor. |
| 333 | * |
| 334 | * That second descriptor won't always be the same as the first one. |
| 335 | * For example, isochronous endpoints can be autoconfigured for high |
| 336 | * bandwidth, and then used in several lower bandwidth altsettings. |
| 337 | * Also, high and full speed descriptors will be different. |
| 338 | * |
| 339 | * Be sure to examine and test the results of autoconfiguration on your |
| 340 | * hardware. This code may not make the best choices about how to use the |
| 341 | * USB controller, and it can't know all the restrictions that may apply. |
| 342 | * Some combinations of driver and hardware won't be able to autoconfigure. |
| 343 | * |
| 344 | * On success, this returns an un-claimed usb_ep, and modifies the endpoint |
| 345 | * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value |
| 346 | * is initialized as if the endpoint were used at full speed. To prevent |
| 347 | * the endpoint from being returned by a later autoconfig call, claim it |
| 348 | * by assigning ep->driver_data to some non-null value. |
| 349 | * |
| 350 | * On failure, this returns a null endpoint descriptor. |
| 351 | */ |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 352 | struct usb_ep *usb_ep_autoconfig( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | struct usb_gadget *gadget, |
| 354 | struct usb_endpoint_descriptor *desc |
| 355 | ) |
| 356 | { |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 357 | return usb_ep_autoconfig_ss(gadget, desc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
Sebastian Andrzej Siewior | dc995fc | 2012-09-06 20:11:12 +0200 | [diff] [blame] | 359 | EXPORT_SYMBOL_GPL(usb_ep_autoconfig); |
Tatyana Brokhman | a59d6b9 | 2011-06-28 16:33:53 +0300 | [diff] [blame] | 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | /** |
| 362 | * usb_ep_autoconfig_reset - reset endpoint autoconfig state |
| 363 | * @gadget: device for which autoconfig state will be reset |
| 364 | * |
| 365 | * Use this for devices where one configuration may need to assign |
| 366 | * endpoint resources very differently from the next one. It clears |
| 367 | * state such as ep->driver_data and the record of assigned endpoints |
| 368 | * used by usb_ep_autoconfig(). |
| 369 | */ |
Michal Nazarewicz | 28824b1 | 2010-05-05 12:53:13 +0200 | [diff] [blame] | 370 | void usb_ep_autoconfig_reset (struct usb_gadget *gadget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | struct usb_ep *ep; |
| 373 | |
| 374 | list_for_each_entry (ep, &gadget->ep_list, ep_list) { |
| 375 | ep->driver_data = NULL; |
| 376 | } |
Sebastian Andrzej Siewior | e87bb71 | 2012-09-06 20:11:11 +0200 | [diff] [blame] | 377 | gadget->in_epnum = 0; |
| 378 | gadget->out_epnum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
Sebastian Andrzej Siewior | dc995fc | 2012-09-06 20:11:12 +0200 | [diff] [blame] | 380 | EXPORT_SYMBOL_GPL(usb_ep_autoconfig_reset); |