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