aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/gadget/epautoconf.c125
-rw-r--r--include/linux/usb/gadget.h13
2 files changed, 113 insertions, 25 deletions
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 0022d44060ae..91c032fbdf1c 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -63,13 +63,16 @@ static int
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
66 struct usb_endpoint_descriptor *desc 66 struct usb_endpoint_descriptor *desc,
67 struct usb_ss_ep_comp_descriptor *ep_comp
67) 68)
68{ 69{
69 u8 type; 70 u8 type;
70 const char *tmp; 71 const char *tmp;
71 u16 max; 72 u16 max;
72 73
74 int num_req_streams = 0;
75
73 /* endpoint already claimed? */ 76 /* endpoint already claimed? */
74 if (NULL != ep->driver_data) 77 if (NULL != ep->driver_data)
75 return 0; 78 return 0;
@@ -129,6 +132,22 @@ ep_matches (
129 } 132 }
130 133
131 /* 134 /*
135 * Get the number of required streams from the EP companion
136 * descriptor and see if the EP matches it
137 */
138 if (usb_endpoint_xfer_bulk(desc)) {
139 if (ep_comp) {
140 num_req_streams = ep_comp->bmAttributes & 0x1f;
141 if (num_req_streams > ep->max_streams)
142 return 0;
143 /* Update the ep_comp descriptor if needed */
144 if (num_req_streams != ep->max_streams)
145 ep_comp->bmAttributes = ep->max_streams;
146 }
147
148 }
149
150 /*
132 * If the protocol driver hasn't yet decided on wMaxPacketSize 151 * If the protocol driver hasn't yet decided on wMaxPacketSize
133 * and wants to know the maximum possible, provide the info. 152 * and wants to know the maximum possible, provide the info.
134 */ 153 */
@@ -208,38 +227,53 @@ find_ep (struct usb_gadget *gadget, const char *name)
208} 227}
209 228
210/** 229/**
211 * usb_ep_autoconfig - choose an endpoint matching the descriptor 230 * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
231 * descriptor and ep companion descriptor
212 * @gadget: The device to which the endpoint must belong. 232 * @gadget: The device to which the endpoint must belong.
213 * @desc: Endpoint descriptor, with endpoint direction and transfer mode 233 * @desc: Endpoint descriptor, with endpoint direction and transfer mode
214 * initialized. For periodic transfers, the maximum packet 234 * initialized. For periodic transfers, the maximum packet
215 * size must also be initialized. This is modified on success. 235 * size must also be initialized. This is modified on
236 * success.
237 * @ep_comp: Endpoint companion descriptor, with the required
238 * number of streams. Will be modified when the chosen EP
239 * supports a different number of streams.
216 * 240 *
217 * By choosing an endpoint to use with the specified descriptor, this 241 * This routine replaces the usb_ep_autoconfig when needed
218 * routine simplifies writing gadget drivers that work with multiple 242 * superspeed enhancments. If such enhancemnets are required,
219 * USB device controllers. The endpoint would be passed later to 243 * the FD should call usb_ep_autoconfig_ss directly and provide
220 * usb_ep_enable(), along with some descriptor. 244 * the additional ep_comp parameter.
245 *
246 * By choosing an endpoint to use with the specified descriptor,
247 * this routine simplifies writing gadget drivers that work with
248 * multiple USB device controllers. The endpoint would be
249 * passed later to usb_ep_enable(), along with some descriptor.
221 * 250 *
222 * That second descriptor won't always be the same as the first one. 251 * That second descriptor won't always be the same as the first one.
223 * For example, isochronous endpoints can be autoconfigured for high 252 * For example, isochronous endpoints can be autoconfigured for high
224 * bandwidth, and then used in several lower bandwidth altsettings. 253 * bandwidth, and then used in several lower bandwidth altsettings.
225 * Also, high and full speed descriptors will be different. 254 * Also, high and full speed descriptors will be different.
226 * 255 *
227 * Be sure to examine and test the results of autoconfiguration on your 256 * Be sure to examine and test the results of autoconfiguration
228 * hardware. This code may not make the best choices about how to use the 257 * on your hardware. This code may not make the best choices
229 * USB controller, and it can't know all the restrictions that may apply. 258 * about how to use the USB controller, and it can't know all
230 * Some combinations of driver and hardware won't be able to autoconfigure. 259 * the restrictions that may apply. Some combinations of driver
260 * and hardware won't be able to autoconfigure.
231 * 261 *
232 * On success, this returns an un-claimed usb_ep, and modifies the endpoint 262 * On success, this returns an un-claimed usb_ep, and modifies the endpoint
233 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value 263 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
234 * is initialized as if the endpoint were used at full speed. To prevent 264 * is initialized as if the endpoint were used at full speed and
235 * the endpoint from being returned by a later autoconfig call, claim it 265 * the bmAttribute field in the ep companion descriptor is
236 * by assigning ep->driver_data to some non-null value. 266 * updated with the assigned number of streams if it is
267 * different from the original value. To prevent the endpoint
268 * from being returned by a later autoconfig call, claim it by
269 * assigning ep->driver_data to some non-null value.
237 * 270 *
238 * On failure, this returns a null endpoint descriptor. 271 * On failure, this returns a null endpoint descriptor.
239 */ 272 */
240struct usb_ep *usb_ep_autoconfig ( 273struct usb_ep *usb_ep_autoconfig_ss(
241 struct usb_gadget *gadget, 274 struct usb_gadget *gadget,
242 struct usb_endpoint_descriptor *desc 275 struct usb_endpoint_descriptor *desc,
276 struct usb_ss_ep_comp_descriptor *ep_comp
243) 277)
244{ 278{
245 struct usb_ep *ep; 279 struct usb_ep *ep;
@@ -253,23 +287,24 @@ struct usb_ep *usb_ep_autoconfig (
253 if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { 287 if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) {
254 /* ep-e, ep-f are PIO with only 64 byte fifos */ 288 /* ep-e, ep-f are PIO with only 64 byte fifos */
255 ep = find_ep (gadget, "ep-e"); 289 ep = find_ep (gadget, "ep-e");
256 if (ep && ep_matches (gadget, ep, desc)) 290 if (ep && ep_matches(gadget, ep, desc, ep_comp))
257 return ep; 291 return ep;
258 ep = find_ep (gadget, "ep-f"); 292 ep = find_ep (gadget, "ep-f");
259 if (ep && ep_matches (gadget, ep, desc)) 293 if (ep && ep_matches(gadget, ep, desc, ep_comp))
260 return ep; 294 return ep;
261 295
262 } else if (gadget_is_goku (gadget)) { 296 } else if (gadget_is_goku (gadget)) {
263 if (USB_ENDPOINT_XFER_INT == type) { 297 if (USB_ENDPOINT_XFER_INT == type) {
264 /* single buffering is enough */ 298 /* single buffering is enough */
265 ep = find_ep (gadget, "ep3-bulk"); 299 ep = find_ep(gadget, "ep3-bulk");
266 if (ep && ep_matches (gadget, ep, desc)) 300 if (ep && ep_matches(gadget, ep, desc, ep_comp))
267 return ep; 301 return ep;
268 } else if (USB_ENDPOINT_XFER_BULK == type 302 } else if (USB_ENDPOINT_XFER_BULK == type
269 && (USB_DIR_IN & desc->bEndpointAddress)) { 303 && (USB_DIR_IN & desc->bEndpointAddress)) {
270 /* DMA may be available */ 304 /* DMA may be available */
271 ep = find_ep (gadget, "ep2-bulk"); 305 ep = find_ep(gadget, "ep2-bulk");
272 if (ep && ep_matches (gadget, ep, desc)) 306 if (ep && ep_matches(gadget, ep, desc,
307 ep_comp))
273 return ep; 308 return ep;
274 } 309 }
275 310
@@ -288,14 +323,14 @@ struct usb_ep *usb_ep_autoconfig (
288 ep = find_ep(gadget, "ep2out"); 323 ep = find_ep(gadget, "ep2out");
289 } else 324 } else
290 ep = NULL; 325 ep = NULL;
291 if (ep && ep_matches (gadget, ep, desc)) 326 if (ep && ep_matches(gadget, ep, desc, ep_comp))
292 return ep; 327 return ep;
293#endif 328#endif
294 } 329 }
295 330
296 /* Second, look at endpoints until an unclaimed one looks usable */ 331 /* Second, look at endpoints until an unclaimed one looks usable */
297 list_for_each_entry (ep, &gadget->ep_list, ep_list) { 332 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
298 if (ep_matches (gadget, ep, desc)) 333 if (ep_matches(gadget, ep, desc, ep_comp))
299 return ep; 334 return ep;
300 } 335 }
301 336
@@ -304,6 +339,46 @@ struct usb_ep *usb_ep_autoconfig (
304} 339}
305 340
306/** 341/**
342 * usb_ep_autoconfig() - choose an endpoint matching the
343 * descriptor
344 * @gadget: The device to which the endpoint must belong.
345 * @desc: Endpoint descriptor, with endpoint direction and transfer mode
346 * initialized. For periodic transfers, the maximum packet
347 * size must also be initialized. This is modified on success.
348 *
349 * By choosing an endpoint to use with the specified descriptor, this
350 * routine simplifies writing gadget drivers that work with multiple
351 * USB device controllers. The endpoint would be passed later to
352 * usb_ep_enable(), along with some descriptor.
353 *
354 * That second descriptor won't always be the same as the first one.
355 * For example, isochronous endpoints can be autoconfigured for high
356 * bandwidth, and then used in several lower bandwidth altsettings.
357 * Also, high and full speed descriptors will be different.
358 *
359 * Be sure to examine and test the results of autoconfiguration on your
360 * hardware. This code may not make the best choices about how to use the
361 * USB controller, and it can't know all the restrictions that may apply.
362 * Some combinations of driver and hardware won't be able to autoconfigure.
363 *
364 * On success, this returns an un-claimed usb_ep, and modifies the endpoint
365 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
366 * is initialized as if the endpoint were used at full speed. To prevent
367 * the endpoint from being returned by a later autoconfig call, claim it
368 * by assigning ep->driver_data to some non-null value.
369 *
370 * On failure, this returns a null endpoint descriptor.
371 */
372struct usb_ep *usb_ep_autoconfig(
373 struct usb_gadget *gadget,
374 struct usb_endpoint_descriptor *desc
375)
376{
377 return usb_ep_autoconfig_ss(gadget, desc, NULL);
378}
379
380
381/**
307 * usb_ep_autoconfig_reset - reset endpoint autoconfig state 382 * usb_ep_autoconfig_reset - reset endpoint autoconfig state
308 * @gadget: device for which autoconfig state will be reset 383 * @gadget: device for which autoconfig state will be reset
309 * 384 *
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d22b4a4936cb..625971292c20 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -28,6 +28,7 @@ struct usb_ep;
28 * field, and the usb controller needs one, it is responsible 28 * field, and the usb controller needs one, it is responsible
29 * for mapping and unmapping the buffer. 29 * for mapping and unmapping the buffer.
30 * @length: Length of that data 30 * @length: Length of that data
31 * @stream_id: The stream id, when USB3.0 bulk streams are being used
31 * @no_interrupt: If true, hints that no completion irq is needed. 32 * @no_interrupt: If true, hints that no completion irq is needed.
32 * Helpful sometimes with deep request queues that are handled 33 * Helpful sometimes with deep request queues that are handled
33 * directly by DMA controllers. 34 * directly by DMA controllers.
@@ -82,6 +83,7 @@ struct usb_request {
82 unsigned length; 83 unsigned length;
83 dma_addr_t dma; 84 dma_addr_t dma;
84 85
86 unsigned stream_id:16;
85 unsigned no_interrupt:1; 87 unsigned no_interrupt:1;
86 unsigned zero:1; 88 unsigned zero:1;
87 unsigned short_not_ok:1; 89 unsigned short_not_ok:1;
@@ -132,11 +134,15 @@ struct usb_ep_ops {
132 * @maxpacket:The maximum packet size used on this endpoint. The initial 134 * @maxpacket:The maximum packet size used on this endpoint. The initial
133 * value can sometimes be reduced (hardware allowing), according to 135 * value can sometimes be reduced (hardware allowing), according to
134 * the endpoint descriptor used to configure the endpoint. 136 * the endpoint descriptor used to configure the endpoint.
137 * @max_streams: The maximum number of streams supported
138 * by this EP (0 - 16, actual number is 2^n)
135 * @driver_data:for use by the gadget driver. 139 * @driver_data:for use by the gadget driver.
136 * @address: used to identify the endpoint when finding descriptor that 140 * @address: used to identify the endpoint when finding descriptor that
137 * matches connection speed 141 * matches connection speed
138 * @desc: endpoint descriptor. This pointer is set before the endpoint is 142 * @desc: endpoint descriptor. This pointer is set before the endpoint is
139 * enabled and remains valid until the endpoint is disabled. 143 * enabled and remains valid until the endpoint is disabled.
144 * @comp_desc: In case of SuperSpeed support, this is the endpoint companion
145 * descriptor that is used to configure the endpoint
140 * 146 *
141 * the bus controller driver lists all the general purpose endpoints in 147 * the bus controller driver lists all the general purpose endpoints in
142 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list, 148 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list,
@@ -149,8 +155,10 @@ struct usb_ep {
149 const struct usb_ep_ops *ops; 155 const struct usb_ep_ops *ops;
150 struct list_head ep_list; 156 struct list_head ep_list;
151 unsigned maxpacket:16; 157 unsigned maxpacket:16;
158 unsigned max_streams:16;
152 u8 address; 159 u8 address;
153 const struct usb_endpoint_descriptor *desc; 160 const struct usb_endpoint_descriptor *desc;
161 const struct usb_ss_ep_comp_descriptor *comp_desc;
154}; 162};
155 163
156/*-------------------------------------------------------------------------*/ 164/*-------------------------------------------------------------------------*/
@@ -895,6 +903,11 @@ static inline void usb_free_descriptors(struct usb_descriptor_header **v)
895extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, 903extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
896 struct usb_endpoint_descriptor *); 904 struct usb_endpoint_descriptor *);
897 905
906
907extern struct usb_ep *usb_ep_autoconfig_ss(struct usb_gadget *,
908 struct usb_endpoint_descriptor *,
909 struct usb_ss_ep_comp_descriptor *);
910
898extern void usb_ep_autoconfig_reset(struct usb_gadget *); 911extern void usb_ep_autoconfig_reset(struct usb_gadget *);
899 912
900#endif /* __LINUX_USB_GADGET_H */ 913#endif /* __LINUX_USB_GADGET_H */