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