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