usb: gadget: g_ffs: Allow to set bmAttributes of configuration
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / char / ts0710.h
1 /*
2  * File: ts0710.h
3  *
4  * Portions derived from rfcomm.c, original header as follows:
5  *
6  * Copyright (C) 2000, 2001  Axis Communications AB
7  *
8  * Author: Mats Friden <mats.friden@axis.com>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  *
24  * Exceptionally, Axis Communications AB grants discretionary and
25  * conditional permissions for additional use of the text contained
26  * in the company's release of the AXIS OpenBT Stack under the
27  * provisions set forth hereunder.
28  *
29  * Provided that, if you use the AXIS OpenBT Stack with other files,
30  * that do not implement functionality as specified in the Bluetooth
31  * System specification, to produce an executable, this does not by
32  * itself cause the resulting executable to be covered by the GNU
33  * General Public License. Your use of that executable is in no way
34  * restricted on account of using the AXIS OpenBT Stack code with it.
35  *
36  * This exception does not however invalidate any other reasons why
37  * the executable file might be covered by the provisions of the GNU
38  * General Public License.
39  *
40  */
41 /*
42  * Copyright (C) 2002  Motorola
43  *
44  *  07/28/2002  Initial version based on rfcomm.c
45  *  11/18/2002  Modified
46  */
47
48 #include <linux/configfs.h>
49 #include <linux/module.h>
50
51 #include <linux/errno.h>
52 #include <linux/sched.h>
53 #include <linux/interrupt.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/fcntl.h>
57 #include <linux/string.h>
58 #include <linux/major.h>
59 #include <linux/mm.h>
60 #include <linux/init.h>
61 //#include <linux/devfs_fs_kernel.h>
62
63 #include <asm/uaccess.h>
64 #include <asm/system.h>
65 #include <asm/bitops.h>
66
67 #include <asm/byteorder.h>
68 #include <asm/types.h>
69
70 #define TS0710_MAX_CHN  33
71
72 #define SET_PF(ctr) ((ctr) | (1 << 4))
73 #define CLR_PF(ctr) ((ctr) & 0xef)
74 #define GET_PF(ctr) (((ctr) >> 4) & 0x1)
75
76 #define GET_PN_MSG_FRAME_SIZE(pn) ( ((pn)->frame_sizeh << 8) | ((pn)->frame_sizel))
77 #define SET_PN_MSG_FRAME_SIZE(pn, size) ({ (pn)->frame_sizel = (size) & 0xff; \
78                                            (pn)->frame_sizeh = (size) >> 8; })
79
80 #define GET_LONG_LENGTH(a) ( ((a).h_len << 7) | ((a).l_len) )
81 #define SET_LONG_LENGTH(a, length) ({ (a).ea = 0; \
82                                       (a).l_len = length & 0x7F; \
83                                       (a).h_len = (length >> 7) & 0xFF; })
84
85 #define SHORT_CRC_CHECK 3
86 #define LONG_CRC_CHECK 4
87
88 /* FIXME: Should this one be define here? */
89 #define SHORT_PAYLOAD_SIZE 127
90
91 #define EA 1
92 #define FCS_SIZE 1
93 #define FLAG_SIZE 2
94
95 #define TS0710_MAX_HDR_SIZE 5
96 #define DEF_TS0710_MTU 1600
97
98 #define TS0710_BASIC_FLAG 0xF9
99 /* the control field */
100 #define SABM 0x2f
101 #define SABM_SIZE 4
102 #define UA 0x63
103 #define UA_SIZE 4
104 #define DM 0x0f
105 #define DISC 0x43
106 #define UIH 0xef
107
108 /* the type field in a multiplexer command packet */
109 #define TEST 0x8
110 #define FCON 0x28
111 #define FCOFF 0x18
112 #define MSC 0x38
113 #define RPN 0x24
114 #define RLS 0x14
115 #define PN 0x20
116 #define NSC 0x4
117
118 /* V.24 modem control signals */
119 #define FC 0x2
120 #define RTC 0x4
121 #define RTR 0x8
122 #define IC 0x40
123 #define DV 0x80
124
125 #define CTRL_CHAN 0             /* The control channel is defined as DLCI 0 */
126 #define MCC_CMD 1               /* Multiplexer command cr */
127 #define MCC_RSP 0               /* Multiplexer response cr */
128
129 #ifdef __LITTLE_ENDIAN_BITFIELD
130
131 typedef struct {
132         __u8 ea:1;
133         __u8 cr:1;
134         __u8 d:1;
135         __u8 server_chn:5;
136 } __attribute__ ((packed)) address_field;
137
138 typedef struct {
139         __u8 ea:1;
140         __u8 len:7;
141 } __attribute__ ((packed)) short_length;
142
143 typedef struct {
144         __u8 ea:1;
145         __u8 l_len:7;
146         __u8 h_len;
147 } __attribute__ ((packed)) long_length;
148
149 typedef struct {
150         address_field addr;
151         __u8 control;
152         short_length length;
153 } __attribute__ ((packed)) short_frame_head;
154
155 typedef struct {
156         short_frame_head h;
157         __u8 data[0];
158 } __attribute__ ((packed)) short_frame;
159
160 typedef struct {
161         address_field addr;
162         __u8 control;
163         long_length length;
164         __u8 data[0];
165 } __attribute__ ((packed)) long_frame_head;
166
167 typedef struct {
168         long_frame_head h;
169         __u8 data[0];
170 } __attribute__ ((packed)) long_frame;
171
172 /* Typedefinitions for structures used for the multiplexer commands */
173 typedef struct {
174         __u8 ea:1;
175         __u8 cr:1;
176         __u8 type:6;
177 } __attribute__ ((packed)) mcc_type;
178
179 typedef struct {
180         mcc_type type;
181         short_length length;
182         __u8 value[0];
183 } __attribute__ ((packed)) mcc_short_frame_head;
184
185 typedef struct {
186         mcc_short_frame_head h;
187         __u8 value[0];
188 } __attribute__ ((packed)) mcc_short_frame;
189
190 typedef struct {
191         mcc_type type;
192         long_length length;
193         __u8 value[0];
194 } __attribute__ ((packed)) mcc_long_frame_head;
195
196 typedef struct {
197         mcc_long_frame_head h;
198         __u8 value[0];
199 } __attribute__ ((packed)) mcc_long_frame;
200
201 /* MSC-command */
202 typedef struct {
203         __u8 ea:1;
204         __u8 fc:1;
205         __u8 rtc:1;
206         __u8 rtr:1;
207         __u8 reserved:2;
208         __u8 ic:1;
209         __u8 dv:1;
210 } __attribute__ ((packed)) v24_sigs;
211
212 typedef struct {
213         __u8 ea:1;
214         __u8 b1:1;
215         __u8 b2:1;
216         __u8 b3:1;
217         __u8 len:4;
218 } __attribute__ ((packed)) brk_sigs;
219
220 typedef struct {
221         short_frame_head s_head;
222         mcc_short_frame_head mcc_s_head;
223         address_field dlci;
224         __u8 v24_sigs;
225         //brk_sigs break_signals;
226         __u8 fcs;
227 } __attribute__ ((packed)) msc_msg;
228
229 #if 0
230 /* conflict with termios.h */
231 /* RPN command */
232 #define B2400 0
233 #define B4800 1
234 #define B7200 2
235 #define B9600 3
236 #define B19200 4
237 #define B38400 5
238 #define B57600 6
239 #define B115200 7
240 #define D230400 8
241 #endif
242
243 /*
244 typedef struct{
245   __u8 bit_rate:1;
246   __u8 data_bits:1;
247   __u8 stop_bit:1;
248   __u8 parity:1;
249   __u8 parity_type:1;
250   __u8 xon_u8:1;
251   __u8 xoff_u8:1;
252   __u8 res1:1;
253   __u8 xon_input:1;
254   __u8 xon_output:1;
255   __u8 rtr_input:1;
256   __u8 rtr_output:1;
257   __u8 rtc_input:1;
258   __u8 rtc_output:1;
259   __u8 res2:2;
260 } __attribute__((packed)) parameter_mask;
261
262 typedef struct{
263   __u8 bit_rate;
264   __u8 data_bits:2;
265   __u8 stop_bit:1;
266   __u8 parity:1;
267   __u8 parity_type:2;
268   __u8 res1:2;
269   __u8 xon_input:1;
270   __u8 xon_output:1;
271   __u8 rtr_input:1;
272   __u8 rtr_output:1;
273   __u8 rtc_input:1;
274   __u8 rtc_output:1;
275   __u8 res2:2;
276   __u8 xon_u8;
277   __u8 xoff_u8;
278   parameter_mask pm;
279 } __attribute__((packed)) rpn_values;
280
281 typedef struct{
282   short_frame_head s_head;
283   mcc_short_frame_head mcc_s_head;
284   address_field dlci;
285   rpn_values rpn_val;
286   __u8 fcs;
287 } __attribute__((packed)) rpn_msg;
288 */
289
290 /* RLS-command */
291 /*
292 typedef struct{
293   short_frame_head s_head;
294   mcc_short_frame_head mcc_s_head;
295   address_field dlci;
296   __u8 error:4;
297   __u8 res:4;
298   __u8 fcs;
299 } __attribute__((packed)) rls_msg;
300 */
301
302 /* PN-command */
303 typedef struct {
304         short_frame_head s_head;
305         mcc_short_frame_head mcc_s_head;
306         __u8 dlci:6;
307         __u8 res1:2;
308         __u8 frame_type:4;
309         __u8 credit_flow:4;
310         __u8 prior:6;
311         __u8 res2:2;
312         __u8 ack_timer;
313         __u8 frame_sizel;
314         __u8 frame_sizeh;
315         __u8 max_nbrof_retrans;
316         __u8 credits;
317         __u8 fcs;
318 } __attribute__ ((packed)) pn_msg;
319
320 /* NSC-command */
321 typedef struct {
322         short_frame_head s_head;
323         mcc_short_frame_head mcc_s_head;
324         mcc_type command_type;
325         __u8 fcs;
326 } __attribute__ ((packed)) nsc_msg;
327
328 #else
329 #error Only littel-endianess supported now!
330 #endif
331
332 enum {
333         REJECTED = 0,
334         DISCONNECTED,
335         CONNECTING,
336         NEGOTIATING,
337         CONNECTED,
338         DISCONNECTING,
339         FLOW_STOPPED
340 };
341
342 enum ts0710_events {
343         CONNECT_IND,
344         CONNECT_CFM,
345         DISCONN_CFM
346 };
347
348 typedef struct {
349         volatile __u8 state;
350         volatile __u8 flow_control;
351         volatile __u8 initiated;
352         volatile __u8 initiator;
353         volatile __u16 mtu;
354         wait_queue_head_t open_wait;
355         wait_queue_head_t close_wait;
356 } dlci_struct;
357
358 /* user space interfaces */
359 typedef struct {
360         volatile __u8 initiator;
361         volatile __u8 c_dlci;
362         volatile __u16 mtu;
363         volatile __u8 be_testing;
364         volatile __u32 test_errs;
365         void *user_data;
366         wait_queue_head_t test_wait;
367
368         dlci_struct dlci[TS0710_MAX_CHN];
369 } ts0710_con;