1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Filesystem based user-mode API to USB Gadget controller hardware
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.
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.
19 #ifndef __LINUX_USB_GADGETFS_H
20 #define __LINUX_USB_GADGETFS_H
22 #include <linux/types.h>
23 #include <linux/ioctl.h>
25 #include <linux/usb/ch9.h>
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.
33 enum usb_gadgetfs_event_type
{
40 /* and likely more ! */
43 /* NOTE: this structure must stay the same size and layout on
44 * both 32-bit and 64-bit kernels.
46 struct usb_gadgetfs_event
{
48 /* NOP, DISCONNECT, SUSPEND: nothing
49 * ... some hardware can't report disconnection
52 /* CONNECT: just the speed */
53 enum usb_device_speed speed
;
55 /* SETUP: packet; DATA phase i/o precedes next event
56 *(setup.bmRequestType & USB_DIR_IN) flags direction
57 * ... includes SET_CONFIGURATION, SET_INTERFACE
59 struct usb_ctrlrequest setup
;
61 enum usb_gadgetfs_event_type type
;
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).
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)
79 #define GADGETFS_FIFO_STATUS _IO('g', 1)
81 /* discards any unclaimed data in the fifo. */
82 #define GADGETFS_FIFO_FLUSH _IO('g', 2)
84 /* resets endpoint halt+toggle; used to implement set_interface.
85 * some hardware (like pxa2xx) can't support this.
87 #define GADGETFS_CLEAR_HALT _IO('g', 3)
89 #endif /* __LINUX_USB_GADGETFS_H */