aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb/gadget.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/usb/gadget.h')
-rw-r--r--include/linux/usb/gadget.h58
1 files changed, 49 insertions, 9 deletions
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 942ef5e053bf..c3a61853cd13 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -148,6 +148,9 @@ struct usb_ep_ops {
148 * @maxpacket:The maximum packet size used on this endpoint. The initial 148 * @maxpacket:The maximum packet size used on this endpoint. The initial
149 * value can sometimes be reduced (hardware allowing), according to 149 * value can sometimes be reduced (hardware allowing), according to
150 * the endpoint descriptor used to configure the endpoint. 150 * the endpoint descriptor used to configure the endpoint.
151 * @maxpacket_limit:The maximum packet size value which can be handled by this
152 * endpoint. It's set once by UDC driver when endpoint is initialized, and
153 * should not be changed. Should not be confused with maxpacket.
151 * @max_streams: The maximum number of streams supported 154 * @max_streams: The maximum number of streams supported
152 * by this EP (0 - 16, actual number is 2^n) 155 * by this EP (0 - 16, actual number is 2^n)
153 * @mult: multiplier, 'mult' value for SS Isoc EPs 156 * @mult: multiplier, 'mult' value for SS Isoc EPs
@@ -171,6 +174,7 @@ struct usb_ep {
171 const struct usb_ep_ops *ops; 174 const struct usb_ep_ops *ops;
172 struct list_head ep_list; 175 struct list_head ep_list;
173 unsigned maxpacket:16; 176 unsigned maxpacket:16;
177 unsigned maxpacket_limit:16;
174 unsigned max_streams:16; 178 unsigned max_streams:16;
175 unsigned mult:2; 179 unsigned mult:2;
176 unsigned maxburst:5; 180 unsigned maxburst:5;
@@ -182,6 +186,21 @@ struct usb_ep {
182/*-------------------------------------------------------------------------*/ 186/*-------------------------------------------------------------------------*/
183 187
184/** 188/**
189 * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint
190 * @ep:the endpoint being configured
191 * @maxpacket_limit:value of maximum packet size limit
192 *
193 * This function shoud be used only in UDC drivers to initialize endpoint
194 * (usually in probe function).
195 */
196static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
197 unsigned maxpacket_limit)
198{
199 ep->maxpacket_limit = maxpacket_limit;
200 ep->maxpacket = maxpacket_limit;
201}
202
203/**
185 * usb_ep_enable - configure endpoint, making it usable 204 * usb_ep_enable - configure endpoint, making it usable
186 * @ep:the endpoint being configured. may not be the endpoint named "ep0". 205 * @ep:the endpoint being configured. may not be the endpoint named "ep0".
187 * drivers discover endpoints through the ep_list of a usb_gadget. 206 * drivers discover endpoints through the ep_list of a usb_gadget.
@@ -485,6 +504,11 @@ struct usb_gadget_ops {
485 * @max_speed: Maximal speed the UDC can handle. UDC must support this 504 * @max_speed: Maximal speed the UDC can handle. UDC must support this
486 * and all slower speeds. 505 * and all slower speeds.
487 * @state: the state we are now (attached, suspended, configured, etc) 506 * @state: the state we are now (attached, suspended, configured, etc)
507 * @name: Identifies the controller hardware type. Used in diagnostics
508 * and sometimes configuration.
509 * @dev: Driver model state for this abstract device.
510 * @out_epnum: last used out ep number
511 * @in_epnum: last used in ep number
488 * @sg_supported: true if we can handle scatter-gather 512 * @sg_supported: true if we can handle scatter-gather
489 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the 513 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
490 * gadget driver must provide a USB OTG descriptor. 514 * gadget driver must provide a USB OTG descriptor.
@@ -497,11 +521,8 @@ struct usb_gadget_ops {
497 * only supports HNP on a different root port. 521 * only supports HNP on a different root port.
498 * @b_hnp_enable: OTG device feature flag, indicating that the A-Host 522 * @b_hnp_enable: OTG device feature flag, indicating that the A-Host
499 * enabled HNP support. 523 * enabled HNP support.
500 * @name: Identifies the controller hardware type. Used in diagnostics 524 * @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to
501 * and sometimes configuration. 525 * MaxPacketSize.
502 * @dev: Driver model state for this abstract device.
503 * @out_epnum: last used out ep number
504 * @in_epnum: last used in ep number
505 * 526 *
506 * Gadgets have a mostly-portable "gadget driver" implementing device 527 * Gadgets have a mostly-portable "gadget driver" implementing device
507 * functions, handling all usb configurations and interfaces. Gadget 528 * functions, handling all usb configurations and interfaces. Gadget
@@ -530,16 +551,18 @@ struct usb_gadget {
530 enum usb_device_speed speed; 551 enum usb_device_speed speed;
531 enum usb_device_speed max_speed; 552 enum usb_device_speed max_speed;
532 enum usb_device_state state; 553 enum usb_device_state state;
554 const char *name;
555 struct device dev;
556 unsigned out_epnum;
557 unsigned in_epnum;
558
533 unsigned sg_supported:1; 559 unsigned sg_supported:1;
534 unsigned is_otg:1; 560 unsigned is_otg:1;
535 unsigned is_a_peripheral:1; 561 unsigned is_a_peripheral:1;
536 unsigned b_hnp_enable:1; 562 unsigned b_hnp_enable:1;
537 unsigned a_hnp_support:1; 563 unsigned a_hnp_support:1;
538 unsigned a_alt_hnp_support:1; 564 unsigned a_alt_hnp_support:1;
539 const char *name; 565 unsigned quirk_ep_out_aligned_size:1;
540 struct device dev;
541 unsigned out_epnum;
542 unsigned in_epnum;
543}; 566};
544#define work_to_gadget(w) (container_of((w), struct usb_gadget, work)) 567#define work_to_gadget(w) (container_of((w), struct usb_gadget, work))
545 568
@@ -558,6 +581,23 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
558 581
559 582
560/** 583/**
584 * usb_ep_align_maybe - returns @len aligned to ep's maxpacketsize if gadget
585 * requires quirk_ep_out_aligned_size, otherwise reguens len.
586 * @g: controller to check for quirk
587 * @ep: the endpoint whose maxpacketsize is used to align @len
588 * @len: buffer size's length to align to @ep's maxpacketsize
589 *
590 * This helper is used in case it's required for any reason to check and maybe
591 * align buffer's size to an ep's maxpacketsize.
592 */
593static inline size_t
594usb_ep_align_maybe(struct usb_gadget *g, struct usb_ep *ep, size_t len)
595{
596 return !g->quirk_ep_out_aligned_size ? len :
597 round_up(len, (size_t)ep->desc->wMaxPacketSize);
598}
599
600/**
561 * gadget_is_dualspeed - return true iff the hardware handles high speed 601 * gadget_is_dualspeed - return true iff the hardware handles high speed
562 * @g: controller that might support both high and full speeds 602 * @g: controller that might support both high and full speeds
563 */ 603 */