1 #ifndef __LINUX_FUNCTIONFS_H__ 2 #define __LINUX_FUNCTIONFS_H__ 1 3 4 5 #include <linux/types.h> 6 #include <linux/ioctl.h> 7 8 #include <linux/usb/ch9.h> 9 10 11 enum { 12 FUNCTIONFS_DESCRIPTORS_MAGIC = 1, 13 FUNCTIONFS_STRINGS_MAGIC = 2 14 }; 15 16 17 18 /* Descriptor of an non-audio endpoint */ 19 struct usb_endpoint_descriptor_no_audio { 20 __u8 bLength; 21 __u8 bDescriptorType; 22 23 __u8 bEndpointAddress; 24 __u8 bmAttributes; 25 __le16 wMaxPacketSize; 26 __u8 bInterval; 27 } __attribute__((packed)); 28 29 30 /* 31 * All numbers must be in little endian order. 32 */ 33 34 struct usb_functionfs_descs_head { 35 __le32 magic; 36 __le32 length; 37 __le32 fs_count; 38 __le32 hs_count; 39 } __attribute__((packed)); 40 41 /* 42 * Descriptors format: 43 * 44 * | off | name | type | description | 45 * |-----+-----------+--------------+--------------------------------------| 46 * | 0 | magic | LE32 | FUNCTIONFS_{FS,HS}_DESCRIPTORS_MAGIC | 47 * | 4 | length | LE32 | length of the whole data chunk | 48 * | 8 | fs_count | LE32 | number of full-speed descriptors | 49 * | 12 | hs_count | LE32 | number of high-speed descriptors | 50 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors | 51 * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 52 * 53 * descs are just valid USB descriptors and have the following format: 54 * 55 * | off | name | type | description | 56 * |-----+-----------------+------+--------------------------| 57 * | 0 | bLength | U8 | length of the descriptor | 58 * | 1 | bDescriptorType | U8 | descriptor type | 59 * | 2 | payload | | descriptor's payload | 60 */ 61 62 struct usb_functionfs_strings_head { 63 __le32 magic; 64 __le32 length; 65 __le32 str_count; 66 __le32 lang_count; 67 } __attribute__((packed)); 68 69 /* 70 * Strings format: 71 * 72 * | off | name | type | description | 73 * |-----+------------+-----------------------+----------------------------| 74 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC | 75 * | 4 | length | LE32 | length of the data chunk | 76 * | 8 | str_count | LE32 | number of strings | 77 * | 12 | lang_count | LE32 | number of languages | 78 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang | 79 * 80 * For each language there is one stringtab entry (ie. there are lang_count 81 * stringtab entires). Each StringTab has following format: 82 * 83 * | off | name | type | description | 84 * |-----+---------+-------------------+------------------------------------| 85 * | 0 | lang | LE16 | language code | 86 * | 2 | strings | String[str_count] | array of strings in given language | 87 * 88 * For each string there is one strings entry (ie. there are str_count 89 * string entries). Each String is a NUL terminated string encoded in 90 * UTF-8. 91 */ 92 93 94 95 /* 96 * Events are delivered on the ep0 file descriptor, when the user mode driver 97 * reads from this file descriptor after writing the descriptors. Don't 98 * stop polling this descriptor. 99 */ 100 101 enum usb_functionfs_event_type { 102 FUNCTIONFS_BIND, 103 FUNCTIONFS_UNBIND, 104 105 FUNCTIONFS_ENABLE, 106 FUNCTIONFS_DISABLE, 107 108 FUNCTIONFS_SETUP, 109 110 FUNCTIONFS_SUSPEND, 111 FUNCTIONFS_RESUME 112 }; 113 114 /* NOTE: this structure must stay the same size and layout on 115 * both 32-bit and 64-bit kernels. 116 */ 117 struct usb_functionfs_event { 118 union { 119 /* SETUP: packet; DATA phase i/o precedes next event 120 *(setup.bmRequestType & USB_DIR_IN) flags direction */ 121 struct usb_ctrlrequest setup; 122 } __attribute__((packed)) u; 123 124 /* enum usb_functionfs_event_type */ 125 __u8 type; 126 __u8 _pad[3]; 127 } __attribute__((packed)); 128 129 130 /* Endpoint ioctls */ 131 /* The same as in gadgetfs */ 132 133 /* IN transfers may be reported to the gadget driver as complete 134 * when the fifo is loaded, before the host reads the data; 135 * OUT transfers may be reported to the host's "client" driver as 136 * complete when they're sitting in the FIFO unread. 137 * THIS returns how many bytes are "unclaimed" in the endpoint fifo 138 * (needed for precise fault handling, when the hardware allows it) 139 */ 140 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1) 141 142 /* discards any unclaimed data in the fifo. */ 143 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2) 144 145 /* resets endpoint halt+toggle; used to implement set_interface. 146 * some hardware (like pxa2xx) can't support this. 147 */ 148 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3) 149 150 /* Specific for functionfs */ 151 152 /* 153 * Returns reverse mapping of an interface. Called on EP0. If there 154 * is no such interface returns -EDOM. If function is not active 155 * returns -ENODEV. 156 */ 157 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128) 158 159 /* 160 * Returns real bEndpointAddress of an endpoint. If function is not 161 * active returns -ENODEV. 162 */ 163 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129) 164 165 166 167 #endif 168