1 #ifndef __LINUX_FUNCTIONFS_H__
2 #define __LINUX_FUNCTIONFS_H__ 1
5 #include <linux/types.h>
6 #include <linux/ioctl.h>
8 #include <linux/usb/ch9.h>
12 FUNCTIONFS_DESCRIPTORS_MAGIC
= 1,
13 FUNCTIONFS_STRINGS_MAGIC
= 2
19 /* Descriptor of an non-audio endpoint */
20 struct usb_endpoint_descriptor_no_audio
{
24 __u8 bEndpointAddress
;
26 __le16 wMaxPacketSize
;
28 } __attribute__((packed
));
32 * All numbers must be in little endian order.
35 struct usb_functionfs_descs_head
{
40 } __attribute__((packed
));
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 |
54 * descs are just valid USB descriptors and have the following format:
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 |
63 struct usb_functionfs_strings_head
{
68 } __attribute__((packed
));
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 |
81 * For each language there is one stringtab entry (ie. there are lang_count
82 * stringtab entires). Each StringTab has following format:
84 * | off | name | type | description |
85 * |-----+---------+-------------------+------------------------------------|
86 * | 0 | lang | LE16 | language code |
87 * | 2 | strings | String[str_count] | array of strings in given language |
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
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.
103 enum usb_functionfs_event_type
{
116 /* NOTE: this structure must stay the same size and layout on
117 * both 32-bit and 64-bit kernels.
119 struct usb_functionfs_event
{
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
;
126 /* enum usb_functionfs_event_type */
129 } __attribute__((packed
));
132 /* Endpoint ioctls */
133 /* The same as in gadgetfs */
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)
142 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
144 /* discards any unclaimed data in the fifo. */
145 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
147 /* resets endpoint halt+toggle; used to implement set_interface.
148 * some hardware (like pxa2xx) can't support this.
150 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
152 /* Specific for functionfs */
155 * Returns reverse mapping of an interface. Called on EP0. If there
156 * is no such interface returns -EDOM. If function is not active
159 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
162 * Returns real bEndpointAddress of an endpoint. If function is not
163 * active returns -ENODEV.
165 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
171 struct usb_composite_dev
;
172 struct usb_configuration
;
175 static int functionfs_init(void) __attribute__((warn_unused_result
));
176 static void functionfs_cleanup(void);
178 static int functionfs_bind(struct ffs_data
*ffs
, struct usb_composite_dev
*cdev
)
179 __attribute__((warn_unused_result
, nonnull
));
180 static void functionfs_unbind(struct ffs_data
*ffs
)
181 __attribute__((nonnull
));
183 static int functionfs_bind_config(struct usb_composite_dev
*cdev
,
184 struct usb_configuration
*c
,
185 struct ffs_data
*ffs
)
186 __attribute__((warn_unused_result
, nonnull
));
189 static int functionfs_ready_callback(struct ffs_data
*ffs
)
190 __attribute__((warn_unused_result
, nonnull
));
191 static void functionfs_closed_callback(struct ffs_data
*ffs
)
192 __attribute__((nonnull
));
193 static int functionfs_check_dev_callback(const char *dev_name
)
194 __attribute__((warn_unused_result
, nonnull
));