• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Filesystem based user-mode API to USB Gadget controller hardware
4  *
5  * Other than ep0 operations, most things are done by read() and write()
6  * on endpoint files found in one directory.  They are configured by
7  * writing descriptors, and then may be used for normal stream style
8  * i/o requests.  When ep0 is configured, the device can enumerate;
9  * when it's closed, the device disconnects from usb.  Operations on
10  * ep0 require ioctl() operations.
11  *
12  * Configuration and device descriptors get written to /dev/gadget/$CHIP,
13  * which may then be used to read usb_gadgetfs_event structs.  The driver
14  * may activate endpoints as it handles SET_CONFIGURATION setup events,
15  * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
16  * then performing data transfers by reading or writing.
17  */
18 
19 #ifndef __LINUX_USB_GADGETFS_H
20 #define __LINUX_USB_GADGETFS_H
21 
22 #include <linux/types.h>
23 #include <linux/ioctl.h>
24 
25 #include <linux/usb/ch9.h>
26 
27 /*
28  * Events are delivered on the ep0 file descriptor, when the user mode driver
29  * reads from this file descriptor after writing the descriptors.  Don't
30  * stop polling this descriptor.
31  */
32 
33 enum usb_gadgetfs_event_type {
34 	GADGETFS_NOP = 0,
35 
36 	GADGETFS_CONNECT,
37 	GADGETFS_DISCONNECT,
38 	GADGETFS_SETUP,
39 	GADGETFS_SUSPEND,
40 	/* and likely more ! */
41 };
42 
43 /* NOTE:  this structure must stay the same size and layout on
44  * both 32-bit and 64-bit kernels.
45  */
46 struct usb_gadgetfs_event {
47 	union {
48 		/* NOP, DISCONNECT, SUSPEND: nothing
49 		 * ... some hardware can't report disconnection
50 		 */
51 
52 		/* CONNECT: just the speed */
53 		enum usb_device_speed	speed;
54 
55 		/* SETUP: packet; DATA phase i/o precedes next event
56 		 *(setup.bmRequestType & USB_DIR_IN) flags direction
57 		 * ... includes SET_CONFIGURATION, SET_INTERFACE
58 		 */
59 		struct usb_ctrlrequest	setup;
60 	} u;
61 	enum usb_gadgetfs_event_type	type;
62 };
63 
64 
65 /* The 'g' code is also used by printer gadget ioctl requests.
66  * Don't add any colliding codes to either driver, and keep
67  * them in unique ranges (size 0x20 for now).
68  */
69 
70 /* endpoint ioctls */
71 
72 /* IN transfers may be reported to the gadget driver as complete
73  *	when the fifo is loaded, before the host reads the data;
74  * OUT transfers may be reported to the host's "client" driver as
75  *	complete when they're sitting in the FIFO unread.
76  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
77  * (needed for precise fault handling, when the hardware allows it)
78  */
79 #define	GADGETFS_FIFO_STATUS	_IO('g', 1)
80 
81 /* discards any unclaimed data in the fifo. */
82 #define	GADGETFS_FIFO_FLUSH	_IO('g', 2)
83 
84 /* resets endpoint halt+toggle; used to implement set_interface.
85  * some hardware (like pxa2xx) can't support this.
86  */
87 #define	GADGETFS_CLEAR_HALT	_IO('g', 3)
88 
89 #endif /* __LINUX_USB_GADGETFS_H */
90