.. | .. |
---|
4 | 4 | * |
---|
5 | 5 | * We call the USB code inside a Linux-based peripheral device a "gadget" |
---|
6 | 6 | * driver, except for the hardware-specific bus glue. One USB host can |
---|
7 | | - * master many USB gadgets, but the gadgets are only slaved to one host. |
---|
| 7 | + * talk to many USB gadgets, but the gadgets are only able to communicate |
---|
| 8 | + * to one host. |
---|
8 | 9 | * |
---|
9 | 10 | * |
---|
10 | 11 | * (C) Copyright 2002-2004 by David Brownell |
---|
.. | .. |
---|
43 | 44 | * @num_mapped_sgs: number of SG entries mapped to DMA (internal) |
---|
44 | 45 | * @length: Length of that data |
---|
45 | 46 | * @stream_id: The stream id, when USB3.0 bulk streams are being used |
---|
| 47 | + * @is_last: Indicates if this is the last request of a stream_id before |
---|
| 48 | + * switching to a different stream (required for DWC3 controllers). |
---|
46 | 49 | * @no_interrupt: If true, hints that no completion irq is needed. |
---|
47 | 50 | * Helpful sometimes with deep request queues that are handled |
---|
48 | 51 | * directly by DMA controllers. |
---|
.. | .. |
---|
76 | 79 | * Note that for writes (IN transfers) some data bytes may still |
---|
77 | 80 | * reside in a device-side FIFO when the request is reported as |
---|
78 | 81 | * complete. |
---|
79 | | - * @udc_priv: Vendor private data in usage by the UDC. |
---|
80 | 82 | * |
---|
81 | 83 | * These are allocated/freed through the endpoint they're used with. The |
---|
82 | 84 | * hardware's driver can add extra per-request data to the memory it returns, |
---|
.. | .. |
---|
106 | 108 | unsigned num_mapped_sgs; |
---|
107 | 109 | |
---|
108 | 110 | unsigned stream_id:16; |
---|
| 111 | + unsigned is_last:1; |
---|
109 | 112 | unsigned no_interrupt:1; |
---|
110 | 113 | unsigned zero:1; |
---|
111 | 114 | unsigned short_not_ok:1; |
---|
.. | .. |
---|
120 | 123 | |
---|
121 | 124 | int status; |
---|
122 | 125 | unsigned actual; |
---|
123 | | - unsigned int udc_priv; |
---|
124 | | -}; |
---|
125 | 126 | |
---|
126 | | -/* |
---|
127 | | - * @buf_base_addr: Base pointer to buffer allocated for each GSI enabled EP. |
---|
128 | | - * TRBs point to buffers that are split from this pool. The size of the |
---|
129 | | - * buffer is num_bufs times buf_len. num_bufs and buf_len are determined |
---|
130 | | - based on desired performance and aggregation size. |
---|
131 | | - * @dma: DMA address corresponding to buf_base_addr. |
---|
132 | | - * @num_bufs: Number of buffers associated with the GSI enabled EP. This |
---|
133 | | - * corresponds to the number of non-zlp TRBs allocated for the EP. |
---|
134 | | - * The value is determined based on desired performance for the EP. |
---|
135 | | - * @buf_len: Size of each individual buffer is determined based on aggregation |
---|
136 | | - * negotiated as per the protocol. In case of no aggregation supported by |
---|
137 | | - * the protocol, we use default values. |
---|
138 | | - * @db_reg_phs_addr_lsb: IPA channel doorbell register's physical address LSB |
---|
139 | | - * @mapped_db_reg_phs_addr_lsb: doorbell LSB IOVA address mapped with IOMMU |
---|
140 | | - * @db_reg_phs_addr_msb: IPA channel doorbell register's physical address MSB |
---|
141 | | - * @sgt_trb_xfer_ring: USB TRB ring related sgtable entries |
---|
142 | | - * @sgt_data_buff: Data buffer related sgtable entries |
---|
143 | | - * @dev: pointer to the DMA-capable dwc device |
---|
144 | | - */ |
---|
145 | | -struct usb_gsi_request { |
---|
146 | | - void *buf_base_addr; |
---|
147 | | - dma_addr_t dma; |
---|
148 | | - size_t num_bufs; |
---|
149 | | - size_t buf_len; |
---|
150 | | - u32 db_reg_phs_addr_lsb; |
---|
151 | | - dma_addr_t mapped_db_reg_phs_addr_lsb; |
---|
152 | | - u32 db_reg_phs_addr_msb; |
---|
153 | | - struct sg_table sgt_trb_xfer_ring; |
---|
154 | | - struct sg_table sgt_data_buff; |
---|
155 | | - struct device *dev; |
---|
156 | | -}; |
---|
157 | | - |
---|
158 | | -enum gsi_ep_op { |
---|
159 | | - GSI_EP_OP_CONFIG = 0, |
---|
160 | | - GSI_EP_OP_STARTXFER, |
---|
161 | | - GSI_EP_OP_STORE_DBL_INFO, |
---|
162 | | - GSI_EP_OP_ENABLE_GSI, |
---|
163 | | - GSI_EP_OP_UPDATEXFER, |
---|
164 | | - GSI_EP_OP_RING_DB, |
---|
165 | | - GSI_EP_OP_ENDXFER, |
---|
166 | | - GSI_EP_OP_GET_CH_INFO, |
---|
167 | | - GSI_EP_OP_GET_XFER_IDX, |
---|
168 | | - GSI_EP_OP_PREPARE_TRBS, |
---|
169 | | - GSI_EP_OP_FREE_TRBS, |
---|
170 | | - GSI_EP_OP_SET_CLR_BLOCK_DBL, |
---|
171 | | - GSI_EP_OP_CHECK_FOR_SUSPEND, |
---|
172 | | - GSI_EP_OP_DISABLE, |
---|
| 127 | + ANDROID_KABI_RESERVE(1); |
---|
173 | 128 | }; |
---|
174 | 129 | |
---|
175 | 130 | /*-------------------------------------------------------------------------*/ |
---|
.. | .. |
---|
200 | 155 | |
---|
201 | 156 | int (*fifo_status) (struct usb_ep *ep); |
---|
202 | 157 | void (*fifo_flush) (struct usb_ep *ep); |
---|
203 | | - int (*gsi_ep_op) (struct usb_ep *ep, void *op_data, |
---|
204 | | - enum gsi_ep_op op); |
---|
205 | 158 | |
---|
| 159 | + ANDROID_KABI_RESERVE(1); |
---|
206 | 160 | }; |
---|
207 | 161 | |
---|
208 | 162 | /** |
---|
.. | .. |
---|
243 | 197 | .dir_out = !!(_dir & USB_EP_CAPS_DIR_OUT), \ |
---|
244 | 198 | } |
---|
245 | 199 | |
---|
246 | | -enum ep_type { |
---|
247 | | - EP_TYPE_NORMAL = 0, |
---|
248 | | - EP_TYPE_GSI, |
---|
249 | | -}; |
---|
250 | | - |
---|
251 | 200 | /** |
---|
252 | 201 | * struct usb_ep - device side representation of USB endpoint |
---|
253 | 202 | * @name:identifier for the endpoint, such as "ep-a" or "ep9in-bulk" |
---|
.. | .. |
---|
273 | 222 | * enabled and remains valid until the endpoint is disabled. |
---|
274 | 223 | * @comp_desc: In case of SuperSpeed support, this is the endpoint companion |
---|
275 | 224 | * descriptor that is used to configure the endpoint |
---|
276 | | - * @ep_type: Used to specify type of EP eg. normal vs h/w accelerated. |
---|
277 | | - * @ep_num: Used EP number |
---|
278 | | - * @ep_intr_num: Interrupter number for EP. |
---|
279 | | - * @endless: In case where endless transfer is being initiated, this is set |
---|
280 | | - * to disable usb event interrupt for few events. |
---|
281 | | - * @transfer_type: Used to specify transfer type of EP. |
---|
282 | 225 | * |
---|
283 | 226 | * the bus controller driver lists all the general purpose endpoints in |
---|
284 | 227 | * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list, |
---|
.. | .. |
---|
302 | 245 | u8 address; |
---|
303 | 246 | const struct usb_endpoint_descriptor *desc; |
---|
304 | 247 | const struct usb_ss_ep_comp_descriptor *comp_desc; |
---|
305 | | - enum ep_type ep_type; |
---|
306 | | - u8 ep_num; |
---|
307 | | - u8 ep_intr_num; |
---|
308 | | - bool endless; |
---|
309 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
---|
310 | | - u8 transfer_type; |
---|
311 | | -#endif |
---|
| 248 | + |
---|
| 249 | + ANDROID_KABI_RESERVE(1); |
---|
312 | 250 | }; |
---|
313 | 251 | |
---|
314 | 252 | /*-------------------------------------------------------------------------*/ |
---|
.. | .. |
---|
326 | 264 | int usb_ep_set_wedge(struct usb_ep *ep); |
---|
327 | 265 | int usb_ep_fifo_status(struct usb_ep *ep); |
---|
328 | 266 | void usb_ep_fifo_flush(struct usb_ep *ep); |
---|
329 | | -int usb_gsi_ep_op(struct usb_ep *ep, |
---|
330 | | - struct usb_gsi_request *req, enum gsi_ep_op op); |
---|
331 | 267 | #else |
---|
332 | 268 | static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, |
---|
333 | 269 | unsigned maxpacket_limit) |
---|
.. | .. |
---|
357 | 293 | { return 0; } |
---|
358 | 294 | static inline void usb_ep_fifo_flush(struct usb_ep *ep) |
---|
359 | 295 | { } |
---|
360 | | - |
---|
361 | | -static inline int usb_gsi_ep_op(struct usb_ep *ep, |
---|
362 | | - struct usb_gsi_request *req, enum gsi_ep_op op) |
---|
363 | | -{ return 0; } |
---|
364 | 296 | #endif /* USB_GADGET */ |
---|
365 | 297 | |
---|
366 | 298 | /*-------------------------------------------------------------------------*/ |
---|
.. | .. |
---|
370 | 302 | #define USB_DEFAULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec */ |
---|
371 | 303 | __le16 bU2DevExitLat; /* U2 Device exit Latency */ |
---|
372 | 304 | #define USB_DEFAULT_U2_DEV_EXIT_LAT 0x1F4 /* Less then 500 microsec */ |
---|
| 305 | + __u8 besl_baseline; /* Recommended baseline BESL (0-15) */ |
---|
| 306 | + __u8 besl_deep; /* Recommended deep BESL (0-15) */ |
---|
| 307 | +#define USB_DEFAULT_BESL_UNSPECIFIED 0xFF /* No recommended value */ |
---|
373 | 308 | }; |
---|
374 | 309 | |
---|
375 | 310 | |
---|
.. | .. |
---|
383 | 318 | struct usb_gadget_ops { |
---|
384 | 319 | int (*get_frame)(struct usb_gadget *); |
---|
385 | 320 | int (*wakeup)(struct usb_gadget *); |
---|
386 | | - int (*func_wakeup)(struct usb_gadget *g, int interface_id); |
---|
387 | 321 | int (*set_selfpowered) (struct usb_gadget *, int is_selfpowered); |
---|
388 | 322 | int (*vbus_session) (struct usb_gadget *, int is_active); |
---|
389 | 323 | int (*vbus_draw) (struct usb_gadget *, unsigned mA); |
---|
390 | 324 | int (*pullup) (struct usb_gadget *, int is_on); |
---|
391 | 325 | int (*ioctl)(struct usb_gadget *, |
---|
392 | 326 | unsigned code, unsigned long param); |
---|
393 | | - void (*get_config_params)(struct usb_dcd_config_params *); |
---|
| 327 | + void (*get_config_params)(struct usb_gadget *, |
---|
| 328 | + struct usb_dcd_config_params *); |
---|
394 | 329 | int (*udc_start)(struct usb_gadget *, |
---|
395 | 330 | struct usb_gadget_driver *); |
---|
396 | 331 | int (*udc_stop)(struct usb_gadget *); |
---|
397 | 332 | void (*udc_set_speed)(struct usb_gadget *, enum usb_device_speed); |
---|
| 333 | + void (*udc_set_ssp_rate)(struct usb_gadget *gadget, |
---|
| 334 | + enum usb_ssp_rate rate); |
---|
| 335 | + void (*udc_async_callbacks)(struct usb_gadget *gadget, bool enable); |
---|
398 | 336 | struct usb_ep *(*match_ep)(struct usb_gadget *, |
---|
399 | 337 | struct usb_endpoint_descriptor *, |
---|
400 | 338 | struct usb_ss_ep_comp_descriptor *); |
---|
401 | | - int (*restart)(struct usb_gadget *g); |
---|
| 339 | + int (*check_config)(struct usb_gadget *gadget); |
---|
| 340 | + |
---|
| 341 | + ANDROID_KABI_RESERVE(1); |
---|
| 342 | + ANDROID_KABI_RESERVE(2); |
---|
| 343 | + ANDROID_KABI_RESERVE(3); |
---|
| 344 | + ANDROID_KABI_RESERVE(4); |
---|
402 | 345 | }; |
---|
403 | 346 | |
---|
404 | 347 | /** |
---|
405 | | - * struct usb_gadget - represents a usb slave device |
---|
| 348 | + * struct usb_gadget - represents a usb device |
---|
406 | 349 | * @work: (internal use) Workqueue to be used for sysfs_notify() |
---|
407 | 350 | * @udc: struct usb_udc pointer for this gadget |
---|
408 | 351 | * @ops: Function pointers used to access hardware-specific operations. |
---|
.. | .. |
---|
412 | 355 | * @speed: Speed of current connection to USB host. |
---|
413 | 356 | * @max_speed: Maximal speed the UDC can handle. UDC must support this |
---|
414 | 357 | * and all slower speeds. |
---|
| 358 | + * @ssp_rate: Current connected SuperSpeed Plus signaling rate and lane count. |
---|
| 359 | + * @max_ssp_rate: Maximum SuperSpeed Plus signaling rate and lane count the UDC |
---|
| 360 | + * can handle. The UDC must support this and all slower speeds and lower |
---|
| 361 | + * number of lanes. |
---|
415 | 362 | * @state: the state we are now (attached, suspended, configured, etc) |
---|
416 | 363 | * @name: Identifies the controller hardware type. Used in diagnostics |
---|
417 | 364 | * and sometimes configuration. |
---|
.. | .. |
---|
450 | 397 | * @connected: True if gadget is connected. |
---|
451 | 398 | * @lpm_capable: If the gadget max_speed is FULL or HIGH, this flag |
---|
452 | 399 | * indicates that it supports LPM as per the LPM ECN & errata. |
---|
453 | | - * @remote_wakeup: Indicates if the host has enabled the remote_wakeup |
---|
454 | | - * feature. |
---|
455 | | - * @uvc_enabled: True if uvc function is enabled. |
---|
| 400 | + * @irq: the interrupt number for device controller. |
---|
456 | 401 | * |
---|
457 | 402 | * Gadgets have a mostly-portable "gadget driver" implementing device |
---|
458 | 403 | * functions, handling all usb configurations and interfaces. Gadget |
---|
.. | .. |
---|
481 | 426 | struct list_head ep_list; /* of usb_ep */ |
---|
482 | 427 | enum usb_device_speed speed; |
---|
483 | 428 | enum usb_device_speed max_speed; |
---|
| 429 | + |
---|
| 430 | + /* USB SuperSpeed Plus only */ |
---|
| 431 | + enum usb_ssp_rate ssp_rate; |
---|
| 432 | + enum usb_ssp_rate max_ssp_rate; |
---|
| 433 | + |
---|
484 | 434 | enum usb_device_state state; |
---|
485 | 435 | const char *name; |
---|
486 | 436 | struct device dev; |
---|
.. | .. |
---|
507 | 457 | unsigned deactivated:1; |
---|
508 | 458 | unsigned connected:1; |
---|
509 | 459 | unsigned lpm_capable:1; |
---|
510 | | - unsigned remote_wakeup:1; |
---|
511 | | - unsigned uvc_enabled:1; |
---|
| 460 | + int irq; |
---|
512 | 461 | |
---|
513 | 462 | ANDROID_KABI_RESERVE(1); |
---|
514 | 463 | ANDROID_KABI_RESERVE(2); |
---|
.. | .. |
---|
517 | 466 | }; |
---|
518 | 467 | #define work_to_gadget(w) (container_of((w), struct usb_gadget, work)) |
---|
519 | 468 | |
---|
| 469 | +/* Interface to the device model */ |
---|
520 | 470 | static inline void set_gadget_data(struct usb_gadget *gadget, void *data) |
---|
521 | 471 | { dev_set_drvdata(&gadget->dev, data); } |
---|
522 | 472 | static inline void *get_gadget_data(struct usb_gadget *gadget) |
---|
.. | .. |
---|
525 | 475 | { |
---|
526 | 476 | return container_of(dev, struct usb_gadget, dev); |
---|
527 | 477 | } |
---|
| 478 | +static inline struct usb_gadget *usb_get_gadget(struct usb_gadget *gadget) |
---|
| 479 | +{ |
---|
| 480 | + get_device(&gadget->dev); |
---|
| 481 | + return gadget; |
---|
| 482 | +} |
---|
| 483 | +static inline void usb_put_gadget(struct usb_gadget *gadget) |
---|
| 484 | +{ |
---|
| 485 | + put_device(&gadget->dev); |
---|
| 486 | +} |
---|
| 487 | +extern void usb_initialize_gadget(struct device *parent, |
---|
| 488 | + struct usb_gadget *gadget, void (*release)(struct device *dev)); |
---|
| 489 | +extern int usb_add_gadget(struct usb_gadget *gadget); |
---|
| 490 | +extern void usb_del_gadget(struct usb_gadget *gadget); |
---|
| 491 | + |
---|
| 492 | +/* Legacy device-model interface */ |
---|
| 493 | +extern int usb_add_gadget_udc_release(struct device *parent, |
---|
| 494 | + struct usb_gadget *gadget, void (*release)(struct device *dev)); |
---|
| 495 | +extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); |
---|
| 496 | +extern void usb_del_gadget_udc(struct usb_gadget *gadget); |
---|
| 497 | +extern char *usb_get_gadget_udc_name(void); |
---|
528 | 498 | |
---|
529 | 499 | /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ |
---|
530 | 500 | #define gadget_for_each_ep(tmp, gadget) \ |
---|
.. | .. |
---|
647 | 617 | #if IS_ENABLED(CONFIG_USB_GADGET) |
---|
648 | 618 | int usb_gadget_frame_number(struct usb_gadget *gadget); |
---|
649 | 619 | int usb_gadget_wakeup(struct usb_gadget *gadget); |
---|
650 | | -int usb_gadget_func_wakeup(struct usb_gadget *gadget, int interface_id); |
---|
651 | 620 | int usb_gadget_set_selfpowered(struct usb_gadget *gadget); |
---|
652 | 621 | int usb_gadget_clear_selfpowered(struct usb_gadget *gadget); |
---|
653 | 622 | int usb_gadget_vbus_connect(struct usb_gadget *gadget); |
---|
.. | .. |
---|
657 | 626 | int usb_gadget_disconnect(struct usb_gadget *gadget); |
---|
658 | 627 | int usb_gadget_deactivate(struct usb_gadget *gadget); |
---|
659 | 628 | int usb_gadget_activate(struct usb_gadget *gadget); |
---|
| 629 | +int usb_gadget_check_config(struct usb_gadget *gadget); |
---|
660 | 630 | #else |
---|
661 | 631 | static inline int usb_gadget_frame_number(struct usb_gadget *gadget) |
---|
662 | 632 | { return 0; } |
---|
663 | 633 | static inline int usb_gadget_wakeup(struct usb_gadget *gadget) |
---|
664 | | -{ return 0; } |
---|
665 | | -static inline int usb_gadget_func_wakeup(struct usb_gadget *gadget, |
---|
666 | | - int interface_id) |
---|
667 | 634 | { return 0; } |
---|
668 | 635 | static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget) |
---|
669 | 636 | { return 0; } |
---|
.. | .. |
---|
683 | 650 | { return 0; } |
---|
684 | 651 | static inline int usb_gadget_activate(struct usb_gadget *gadget) |
---|
685 | 652 | { return 0; } |
---|
| 653 | +static inline int usb_gadget_check_config(struct usb_gadget *gadget) |
---|
| 654 | +{ return 0; } |
---|
686 | 655 | #endif /* CONFIG_USB_GADGET */ |
---|
687 | 656 | |
---|
688 | 657 | /*-------------------------------------------------------------------------*/ |
---|
689 | 658 | |
---|
690 | 659 | /** |
---|
691 | | - * struct usb_gadget_driver - driver for usb 'slave' devices |
---|
| 660 | + * struct usb_gadget_driver - driver for usb gadget devices |
---|
692 | 661 | * @function: String describing the gadget's function |
---|
693 | 662 | * @max_speed: Highest speed the driver handles. |
---|
694 | 663 | * @setup: Invoked for ep0 control requests that aren't handled by |
---|
.. | .. |
---|
816 | 785 | * it will first disconnect(). The driver is also requested |
---|
817 | 786 | * to unbind() and clean up any device state, before this procedure |
---|
818 | 787 | * finally returns. It's expected that the unbind() functions |
---|
819 | | - * will in in exit sections, so may not be linked in some kernels. |
---|
| 788 | + * will be in exit sections, so may not be linked in some kernels. |
---|
820 | 789 | */ |
---|
821 | 790 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); |
---|
822 | | - |
---|
823 | | -extern int usb_add_gadget_udc_release(struct device *parent, |
---|
824 | | - struct usb_gadget *gadget, void (*release)(struct device *dev)); |
---|
825 | | -extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); |
---|
826 | | -extern void usb_del_gadget_udc(struct usb_gadget *gadget); |
---|
827 | | -extern char *usb_get_gadget_udc_name(void); |
---|
828 | 791 | |
---|
829 | 792 | /*-------------------------------------------------------------------------*/ |
---|
830 | 793 | |
---|
.. | .. |
---|
858 | 821 | |
---|
859 | 822 | struct usb_gadget_string_container { |
---|
860 | 823 | struct list_head list; |
---|
861 | | - u8 *stash[0]; |
---|
| 824 | + u8 *stash[]; |
---|
862 | 825 | }; |
---|
863 | 826 | |
---|
864 | 827 | /* put descriptor for string with that id into buf (buflen >= 256) */ |
---|
865 | 828 | int usb_gadget_get_string(const struct usb_gadget_strings *table, int id, u8 *buf); |
---|
| 829 | + |
---|
| 830 | +/* check if the given language identifier is valid */ |
---|
| 831 | +bool usb_validate_langid(u16 langid); |
---|
866 | 832 | |
---|
867 | 833 | /*-------------------------------------------------------------------------*/ |
---|
868 | 834 | |
---|
.. | .. |
---|
901 | 867 | struct usb_gadget *gadget); |
---|
902 | 868 | int usb_otg_descriptor_init(struct usb_gadget *gadget, |
---|
903 | 869 | struct usb_descriptor_header *otg_desc); |
---|
904 | | -/*-------------------------------------------------------------------------*/ |
---|
905 | | - |
---|
906 | | -int usb_func_ep_queue(struct usb_function *func, struct usb_ep *ep, |
---|
907 | | - struct usb_request *req, gfp_t gfp_flags); |
---|
908 | | - |
---|
909 | 870 | /*-------------------------------------------------------------------------*/ |
---|
910 | 871 | |
---|
911 | 872 | /* utility to simplify map/unmap of usb_requests to/from DMA */ |
---|
.. | .. |
---|
987 | 948 | extern void usb_ep_autoconfig_release(struct usb_ep *); |
---|
988 | 949 | |
---|
989 | 950 | extern void usb_ep_autoconfig_reset(struct usb_gadget *); |
---|
990 | | -extern struct usb_ep *usb_ep_autoconfig_by_name(struct usb_gadget *gadget, |
---|
991 | | - struct usb_endpoint_descriptor *desc, |
---|
992 | | - const char *ep_name); |
---|
993 | 951 | |
---|
994 | 952 | #endif /* __LINUX_USB_GADGET_H */ |
---|