Merge commit 'v2.6.34-rc5' into oprofile/core
[pandora-kernel.git] / drivers / usb / serial / ftdi_sio.h
1 /*
2  * Driver definitions for the FTDI USB Single Port Serial Converter -
3  * known as FTDI_SIO (Serial Input/Output application of the chipset)
4  *
5  * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h
6  *
7  *
8  * The example I have is known as the USC-1000 which is available from
9  * http://www.dse.co.nz - cat no XH4214 It looks similar to this:
10  * http://www.dansdata.com/usbser.htm but I can't be sure There are other
11  * USC-1000s which don't look like my device though so beware!
12  *
13  * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
14  * USB on the other.
15  *
16  * Thanx to FTDI (http://www.ftdichip.com) for so kindly providing details
17  * of the protocol required to talk to the device and ongoing assistence
18  * during development.
19  *
20  * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the
21  * FTDI_SIO implementation.
22  *
23  */
24
25 /* Commands */
26 #define FTDI_SIO_RESET          0 /* Reset the port */
27 #define FTDI_SIO_MODEM_CTRL     1 /* Set the modem control register */
28 #define FTDI_SIO_SET_FLOW_CTRL  2 /* Set flow control register */
29 #define FTDI_SIO_SET_BAUD_RATE  3 /* Set baud rate */
30 #define FTDI_SIO_SET_DATA       4 /* Set the data characteristics of the port */
31 #define FTDI_SIO_GET_MODEM_STATUS       5 /* Retrieve current value of modem status register */
32 #define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
33 #define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
34 #define FTDI_SIO_SET_LATENCY_TIMER      9 /* Set the latency timer */
35 #define FTDI_SIO_GET_LATENCY_TIMER      10 /* Get the latency timer */
36
37 /* Interface indices for FT2232, FT2232H and FT4232H devices */
38 #define INTERFACE_A             1
39 #define INTERFACE_B             2
40 #define INTERFACE_C             3
41 #define INTERFACE_D             4
42
43
44 /*
45  *   BmRequestType:  1100 0000b
46  *   bRequest:       FTDI_E2_READ
47  *   wValue:         0
48  *   wIndex:         Address of word to read
49  *   wLength:        2
50  *   Data:           Will return a word of data from E2Address
51  *
52  */
53
54 /* Port Identifier Table */
55 #define PIT_DEFAULT             0 /* SIOA */
56 #define PIT_SIOA                1 /* SIOA */
57 /* The device this driver is tested with one has only one port */
58 #define PIT_SIOB                2 /* SIOB */
59 #define PIT_PARALLEL            3 /* Parallel */
60
61 /* FTDI_SIO_RESET */
62 #define FTDI_SIO_RESET_REQUEST FTDI_SIO_RESET
63 #define FTDI_SIO_RESET_REQUEST_TYPE 0x40
64 #define FTDI_SIO_RESET_SIO 0
65 #define FTDI_SIO_RESET_PURGE_RX 1
66 #define FTDI_SIO_RESET_PURGE_TX 2
67
68 /*
69  * BmRequestType:  0100 0000B
70  * bRequest:       FTDI_SIO_RESET
71  * wValue:         Control Value
72  *                   0 = Reset SIO
73  *                   1 = Purge RX buffer
74  *                   2 = Purge TX buffer
75  * wIndex:         Port
76  * wLength:        0
77  * Data:           None
78  *
79  * The Reset SIO command has this effect:
80  *
81  *    Sets flow control set to 'none'
82  *    Event char = $0D
83  *    Event trigger = disabled
84  *    Purge RX buffer
85  *    Purge TX buffer
86  *    Clear DTR
87  *    Clear RTS
88  *    baud and data format not reset
89  *
90  * The Purge RX and TX buffer commands affect nothing except the buffers
91  *
92    */
93
94 /* FTDI_SIO_SET_BAUDRATE */
95 #define FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE 0x40
96 #define FTDI_SIO_SET_BAUDRATE_REQUEST 3
97
98 /*
99  * BmRequestType:  0100 0000B
100  * bRequest:       FTDI_SIO_SET_BAUDRATE
101  * wValue:         BaudDivisor value - see below
102  * wIndex:         Port
103  * wLength:        0
104  * Data:           None
105  * The BaudDivisor values are calculated as follows:
106  * - BaseClock is either 12000000 or 48000000 depending on the device. FIXME: I wish
107  *   I knew how to detect old chips to select proper base clock!
108  * - BaudDivisor is a fixed point number encoded in a funny way.
109  *   (--WRONG WAY OF THINKING--)
110  *   BaudDivisor is a fixed point number encoded with following bit weighs:
111  *   (-2)(-1)(13..0). It is a radical with a denominator of 4, so values
112  *   end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...).
113  *   (--THE REALITY--)
114  *   The both-bits-set has quite different meaning from 0.75 - the chip designers
115  *   have decided it to mean 0.125 instead of 0.75.
116  *   This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates
117  *   and Flow Control Consideration for USB to RS232".
118  * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should
119  *   automagically re-encode the resulting value to take fractions into consideration.
120  * As all values are integers, some bit twiddling is in order:
121  *   BaudDivisor = (BaseClock / 16 / BaudRate) |
122  *   (((BaseClock / 2 / BaudRate) & 4) ? 0x4000    // 0.5
123  *    : ((BaseClock / 2 / BaudRate) & 2) ? 0x8000  // 0.25
124  *    : ((BaseClock / 2 / BaudRate) & 1) ? 0xc000  // 0.125
125  *    : 0)
126  *
127  * For the FT232BM, a 17th divisor bit was introduced to encode the multiples
128  * of 0.125 missing from the FT8U232AM.  Bits 16 to 14 are coded as follows
129  * (the first four codes are the same as for the FT8U232AM, where bit 16 is
130  * always 0):
131  *   000 - add .000 to divisor
132  *   001 - add .500 to divisor
133  *   010 - add .250 to divisor
134  *   011 - add .125 to divisor
135  *   100 - add .375 to divisor
136  *   101 - add .625 to divisor
137  *   110 - add .750 to divisor
138  *   111 - add .875 to divisor
139  * Bits 15 to 0 of the 17-bit divisor are placed in the urb value.  Bit 16 is
140  * placed in bit 0 of the urb index.
141  *
142  * Note that there are a couple of special cases to support the highest baud
143  * rates.  If the calculated divisor value is 1, this needs to be replaced with
144  * 0.  Additionally for the FT232BM, if the calculated divisor value is 0x4001
145  * (1.5), this needs to be replaced with 0x0001 (1) (but this divisor value is
146  * not supported by the FT8U232AM).
147  */
148
149 typedef enum {
150         SIO = 1,
151         FT8U232AM = 2,
152         FT232BM = 3,
153         FT2232C = 4,
154         FT232RL = 5,
155         FT2232H = 6,
156         FT4232H = 7
157 } ftdi_chip_type_t;
158
159 typedef enum {
160  ftdi_sio_b300 = 0,
161  ftdi_sio_b600 = 1,
162  ftdi_sio_b1200 = 2,
163  ftdi_sio_b2400 = 3,
164  ftdi_sio_b4800 = 4,
165  ftdi_sio_b9600 = 5,
166  ftdi_sio_b19200 = 6,
167  ftdi_sio_b38400 = 7,
168  ftdi_sio_b57600 = 8,
169  ftdi_sio_b115200 = 9
170 } FTDI_SIO_baudrate_t;
171
172 /*
173  * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values
174  * are calculated internally.
175  */
176
177 #define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA
178 #define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
179 #define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
180 #define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
181 #define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
182 #define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
183 #define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
184 #define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
185 #define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
186 #define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
187 #define FTDI_SIO_SET_BREAK (0x1 << 14)
188 /* FTDI_SIO_SET_DATA */
189
190 /*
191  * BmRequestType:  0100 0000B
192  * bRequest:       FTDI_SIO_SET_DATA
193  * wValue:         Data characteristics (see below)
194  * wIndex:         Port
195  * wLength:        0
196  * Data:           No
197  *
198  * Data characteristics
199  *
200  *   B0..7   Number of data bits
201  *   B8..10  Parity
202  *           0 = None
203  *           1 = Odd
204  *           2 = Even
205  *           3 = Mark
206  *           4 = Space
207  *   B11..13 Stop Bits
208  *           0 = 1
209  *           1 = 1.5
210  *           2 = 2
211  *   B14
212  *           1 = TX ON (break)
213  *           0 = TX OFF (normal state)
214  *   B15 Reserved
215  *
216  */
217
218
219
220 /* FTDI_SIO_MODEM_CTRL */
221 #define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40
222 #define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL
223
224 /*
225  * BmRequestType:   0100 0000B
226  * bRequest:        FTDI_SIO_MODEM_CTRL
227  * wValue:          ControlValue (see below)
228  * wIndex:          Port
229  * wLength:         0
230  * Data:            None
231  *
232  * NOTE: If the device is in RTS/CTS flow control, the RTS set by this
233  * command will be IGNORED without an error being returned
234  * Also - you can not set DTR and RTS with one control message
235  */
236
237 #define FTDI_SIO_SET_DTR_MASK 0x1
238 #define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK  << 8))
239 #define FTDI_SIO_SET_DTR_LOW  (0 | (FTDI_SIO_SET_DTR_MASK  << 8))
240 #define FTDI_SIO_SET_RTS_MASK 0x2
241 #define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8))
242 #define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8))
243
244 /*
245  * ControlValue
246  * B0    DTR state
247  *          0 = reset
248  *          1 = set
249  * B1    RTS state
250  *          0 = reset
251  *          1 = set
252  * B2..7 Reserved
253  * B8    DTR state enable
254  *          0 = ignore
255  *          1 = use DTR state
256  * B9    RTS state enable
257  *          0 = ignore
258  *          1 = use RTS state
259  * B10..15 Reserved
260  */
261
262 /* FTDI_SIO_SET_FLOW_CTRL */
263 #define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40
264 #define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL
265 #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
266 #define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
267 #define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
268 #define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
269 /*
270  *   BmRequestType:  0100 0000b
271  *   bRequest:       FTDI_SIO_SET_FLOW_CTRL
272  *   wValue:         Xoff/Xon
273  *   wIndex:         Protocol/Port - hIndex is protocol / lIndex is port
274  *   wLength:        0
275  *   Data:           None
276  *
277  * hIndex protocol is:
278  *   B0 Output handshaking using RTS/CTS
279  *       0 = disabled
280  *       1 = enabled
281  *   B1 Output handshaking using DTR/DSR
282  *       0 = disabled
283  *       1 = enabled
284  *   B2 Xon/Xoff handshaking
285  *       0 = disabled
286  *       1 = enabled
287  *
288  * A value of zero in the hIndex field disables handshaking
289  *
290  * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character
291  * and the lValue field contains the XON character.
292  */
293
294 /*
295  * FTDI_SIO_GET_LATENCY_TIMER
296  *
297  * Set the timeout interval. The FTDI collects data from the slave
298  * device, transmitting it to the host when either A) 62 bytes are
299  * received, or B) the timeout interval has elapsed and the buffer
300  * contains at least 1 byte.  Setting this value to a small number
301  * can dramatically improve performance for applications which send
302  * small packets, since the default value is 16ms.
303  */
304 #define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER
305 #define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0
306
307 /*
308  *  BmRequestType:   1100 0000b
309  *  bRequest:        FTDI_SIO_GET_LATENCY_TIMER
310  *  wValue:          0
311  *  wIndex:          Port
312  *  wLength:         0
313  *  Data:            latency (on return)
314  */
315
316 /*
317  * FTDI_SIO_SET_LATENCY_TIMER
318  *
319  * Set the timeout interval. The FTDI collects data from the slave
320  * device, transmitting it to the host when either A) 62 bytes are
321  * received, or B) the timeout interval has elapsed and the buffer
322  * contains at least 1 byte.  Setting this value to a small number
323  * can dramatically improve performance for applications which send
324  * small packets, since the default value is 16ms.
325  */
326 #define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER
327 #define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40
328
329 /*
330  *  BmRequestType:   0100 0000b
331  *  bRequest:        FTDI_SIO_SET_LATENCY_TIMER
332  *  wValue:          Latency (milliseconds)
333  *  wIndex:          Port
334  *  wLength:         0
335  *  Data:            None
336  *
337  * wValue:
338  *   B0..7   Latency timer
339  *   B8..15  0
340  *
341  */
342
343 /*
344  * FTDI_SIO_SET_EVENT_CHAR
345  *
346  * Set the special event character for the specified communications port.
347  * If the device sees this character it will immediately return the
348  * data read so far - rather than wait 40ms or until 62 bytes are read
349  * which is what normally happens.
350  */
351
352
353 #define  FTDI_SIO_SET_EVENT_CHAR_REQUEST FTDI_SIO_SET_EVENT_CHAR
354 #define  FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40
355
356
357 /*
358  *  BmRequestType:   0100 0000b
359  *  bRequest:        FTDI_SIO_SET_EVENT_CHAR
360  *  wValue:          EventChar
361  *  wIndex:          Port
362  *  wLength:         0
363  *  Data:            None
364  *
365  * wValue:
366  *   B0..7   Event Character
367  *   B8      Event Character Processing
368  *             0 = disabled
369  *             1 = enabled
370  *   B9..15  Reserved
371  *
372  */
373
374 /* FTDI_SIO_SET_ERROR_CHAR */
375
376 /* Set the parity error replacement character for the specified communications port */
377
378 /*
379  *  BmRequestType:  0100 0000b
380  *  bRequest:       FTDI_SIO_SET_EVENT_CHAR
381  *  wValue:         Error Char
382  *  wIndex:         Port
383  *  wLength:        0
384  *  Data:           None
385  *
386  *Error Char
387  *  B0..7  Error Character
388  *  B8     Error Character Processing
389  *           0 = disabled
390  *           1 = enabled
391  *  B9..15 Reserved
392  *
393  */
394
395 /* FTDI_SIO_GET_MODEM_STATUS */
396 /* Retrieve the current value of the modem status register */
397
398 #define FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE 0xc0
399 #define FTDI_SIO_GET_MODEM_STATUS_REQUEST FTDI_SIO_GET_MODEM_STATUS
400 #define FTDI_SIO_CTS_MASK 0x10
401 #define FTDI_SIO_DSR_MASK 0x20
402 #define FTDI_SIO_RI_MASK  0x40
403 #define FTDI_SIO_RLSD_MASK 0x80
404 /*
405  *   BmRequestType:   1100 0000b
406  *   bRequest:        FTDI_SIO_GET_MODEM_STATUS
407  *   wValue:          zero
408  *   wIndex:          Port
409  *   wLength:         1
410  *   Data:            Status
411  *
412  * One byte of data is returned
413  * B0..3 0
414  * B4    CTS
415  *         0 = inactive
416  *         1 = active
417  * B5    DSR
418  *         0 = inactive
419  *         1 = active
420  * B6    Ring Indicator (RI)
421  *         0 = inactive
422  *         1 = active
423  * B7    Receive Line Signal Detect (RLSD)
424  *         0 = inactive
425  *         1 = active
426  */
427
428
429
430 /* Descriptors returned by the device
431  *
432  *  Device Descriptor
433  *
434  * Offset       Field           Size    Value   Description
435  * 0    bLength         1       0x12    Size of descriptor in bytes
436  * 1    bDescriptorType 1       0x01    DEVICE Descriptor Type
437  * 2    bcdUSB          2       0x0110  USB Spec Release Number
438  * 4    bDeviceClass    1       0x00    Class Code
439  * 5    bDeviceSubClass 1       0x00    SubClass Code
440  * 6    bDeviceProtocol 1       0x00    Protocol Code
441  * 7    bMaxPacketSize0 1       0x08    Maximum packet size for endpoint 0
442  * 8    idVendor        2       0x0403  Vendor ID
443  * 10   idProduct       2       0x8372  Product ID (FTDI_SIO_PID)
444  * 12   bcdDevice       2       0x0001  Device release number
445  * 14   iManufacturer   1       0x01    Index of man. string desc
446  * 15   iProduct        1       0x02    Index of prod string desc
447  * 16   iSerialNumber   1       0x02    Index of serial nmr string desc
448  * 17   bNumConfigurations 1    0x01    Number of possible configurations
449  *
450  * Configuration Descriptor
451  *
452  * Offset       Field                   Size    Value
453  * 0    bLength                 1       0x09    Size of descriptor in bytes
454  * 1    bDescriptorType         1       0x02    CONFIGURATION Descriptor Type
455  * 2    wTotalLength            2       0x0020  Total length of data
456  * 4    bNumInterfaces          1       0x01    Number of interfaces supported
457  * 5    bConfigurationValue     1       0x01    Argument for SetCOnfiguration() req
458  * 6    iConfiguration          1       0x02    Index of config string descriptor
459  * 7    bmAttributes            1       0x20    Config characteristics Remote Wakeup
460  * 8    MaxPower                1       0x1E    Max power consumption
461  *
462  * Interface Descriptor
463  *
464  * Offset       Field                   Size    Value
465  * 0    bLength                 1       0x09    Size of descriptor in bytes
466  * 1    bDescriptorType         1       0x04    INTERFACE Descriptor Type
467  * 2    bInterfaceNumber        1       0x00    Number of interface
468  * 3    bAlternateSetting       1       0x00    Value used to select alternate
469  * 4    bNumEndpoints           1       0x02    Number of endpoints
470  * 5    bInterfaceClass         1       0xFF    Class Code
471  * 6    bInterfaceSubClass      1       0xFF    Subclass Code
472  * 7    bInterfaceProtocol      1       0xFF    Protocol Code
473  * 8    iInterface              1       0x02    Index of interface string description
474  *
475  * IN Endpoint Descriptor
476  *
477  * Offset       Field                   Size    Value
478  * 0    bLength                 1       0x07    Size of descriptor in bytes
479  * 1    bDescriptorType         1       0x05    ENDPOINT descriptor type
480  * 2    bEndpointAddress        1       0x82    Address of endpoint
481  * 3    bmAttributes            1       0x02    Endpoint attributes - Bulk
482  * 4    bNumEndpoints           2       0x0040  maximum packet size
483  * 5    bInterval               1       0x00    Interval for polling endpoint
484  *
485  * OUT Endpoint Descriptor
486  *
487  * Offset       Field                   Size    Value
488  * 0    bLength                 1       0x07    Size of descriptor in bytes
489  * 1    bDescriptorType         1       0x05    ENDPOINT descriptor type
490  * 2    bEndpointAddress        1       0x02    Address of endpoint
491  * 3    bmAttributes            1       0x02    Endpoint attributes - Bulk
492  * 4    bNumEndpoints           2       0x0040  maximum packet size
493  * 5    bInterval               1       0x00    Interval for polling endpoint
494  *
495  * DATA FORMAT
496  *
497  * IN Endpoint
498  *
499  * The device reserves the first two bytes of data on this endpoint to contain the current
500  * values of the modem and line status registers. In the absence of data, the device 
501  * generates a message consisting of these two status bytes every 40 ms
502  *
503  * Byte 0: Modem Status
504  *
505  * Offset       Description
506  * B0   Reserved - must be 1
507  * B1   Reserved - must be 0
508  * B2   Reserved - must be 0
509  * B3   Reserved - must be 0
510  * B4   Clear to Send (CTS)
511  * B5   Data Set Ready (DSR)
512  * B6   Ring Indicator (RI)
513  * B7   Receive Line Signal Detect (RLSD)
514  *
515  * Byte 1: Line Status
516  *
517  * Offset       Description
518  * B0   Data Ready (DR)
519  * B1   Overrun Error (OE)
520  * B2   Parity Error (PE)
521  * B3   Framing Error (FE)
522  * B4   Break Interrupt (BI)
523  * B5   Transmitter Holding Register (THRE)
524  * B6   Transmitter Empty (TEMT)
525  * B7   Error in RCVR FIFO
526  *
527  */
528 #define FTDI_RS0_CTS    (1 << 4)
529 #define FTDI_RS0_DSR    (1 << 5)
530 #define FTDI_RS0_RI     (1 << 6)
531 #define FTDI_RS0_RLSD   (1 << 7)
532
533 #define FTDI_RS_DR  1
534 #define FTDI_RS_OE (1<<1)
535 #define FTDI_RS_PE (1<<2)
536 #define FTDI_RS_FE (1<<3)
537 #define FTDI_RS_BI (1<<4)
538 #define FTDI_RS_THRE (1<<5)
539 #define FTDI_RS_TEMT (1<<6)
540 #define FTDI_RS_FIFO  (1<<7)
541
542 /*
543  * OUT Endpoint
544  *
545  * This device reserves the first bytes of data on this endpoint contain the length
546  * and port identifier of the message. For the FTDI USB Serial converter the port 
547  * identifier is always 1.
548  *
549  * Byte 0: Line Status
550  *
551  * Offset       Description
552  * B0   Reserved - must be 1
553  * B1   Reserved - must be 0
554  * B2..7        Length of message - (not including Byte 0)
555  *
556  */