Home | History | Annotate | Line # | Download | only in usb
uftdireg.h revision 1.1
      1 /*
      2  * Definitions for the FTDI USB Single Port Serial Converter -
      3  * known as FTDI_SIO (Serial Input/Output application of the chipset)
      4  *
      5  * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
      6  * USB on the other.
      7  *
      8  * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details
      9  * of the protocol required to talk to the device and ongoing assistence
     10  * during development.
     11  *
     12  * Bill Ryder - bryder (at) sgi.com of Silicon Graphics, Inc. is the original
     13  * author of this file.
     14  */
     15 /* Modified by Lennart Augustsson */
     16 
     17 /* Vendor Request Interface */
     18 #define FTDI_SIO_RESET 		0 /* Reset the port */
     19 #define FTDI_SIO_MODEM_CTRL 	1 /* Set the modem control register */
     20 #define FTDI_SIO_SET_FLOW_CTRL	2 /* Set flow control register */
     21 #define FTDI_SIO_SET_BAUD_RATE	3 /* Set baud rate */
     22 #define FTDI_SIO_SET_DATA	4 /* Set the data characteristics of the port */
     23 #define FTDI_SIO_GET_STATUS	5 /* Retrieve current value of status reg */
     24 #define FTDI_SIO_SET_EVENT_CHAR	6 /* Set the event character */
     25 #define FTDI_SIO_SET_ERROR_CHAR	7 /* Set the error character */
     26 
     27 /* Port Identifier Table */
     28 #define FTDI_PIT_DEFAULT 	0 /* SIOA */
     29 #define FTDI_PIT_SIOA		1 /* SIOA */
     30 #define FTDI_PIT_SIOB		2 /* SIOB */
     31 #define FTDI_PIT_PARALLEL	3 /* Parallel */
     32 
     33 /*
     34  * BmRequestType:  0100 0000B
     35  * bRequest:       FTDI_SIO_RESET
     36  * wValue:         Control Value
     37  *                   0 = Reset SIO
     38  *                   1 = Purge RX buffer
     39  *                   2 = Purge TX buffer
     40  * wIndex:         Port
     41  * wLength:        0
     42  * Data:           None
     43  *
     44  * The Reset SIO command has this effect:
     45  *
     46  *    Sets flow control set to 'none'
     47  *    Event char = 0x0d
     48  *    Event trigger = disabled
     49  *    Purge RX buffer
     50  *    Purge TX buffer
     51  *    Clear DTR
     52  *    Clear RTS
     53  *    baud and data format not reset
     54  *
     55  * The Purge RX and TX buffer commands affect nothing except the buffers
     56  *
     57  */
     58 /* FTDI_SIO_RESET */
     59 #define FTDI_SIO_RESET_SIO 0
     60 #define FTDI_SIO_RESET_PURGE_RX 1
     61 #define FTDI_SIO_RESET_PURGE_TX 2
     62 
     63 
     64 /*
     65  * BmRequestType:  0100 0000B
     66  * bRequest:       FTDI_SIO_SET_BAUDRATE
     67  * wValue:         BaudRate value - see below
     68  * wIndex:         Port
     69  * wLength:        0
     70  * Data:           None
     71  */
     72 /* FTDI_SIO_SET_BAUDRATE */
     73 enum {
     74 	ftdi_sio_b300 = 0,
     75 	ftdi_sio_b600 = 1,
     76 	ftdi_sio_b1200 = 2,
     77 	ftdi_sio_b2400 = 3,
     78 	ftdi_sio_b4800 = 4,
     79 	ftdi_sio_b9600 = 5,
     80 	ftdi_sio_b19200 = 6,
     81 	ftdi_sio_b38400 = 7,
     82 	ftdi_sio_b57600 = 8,
     83 	ftdi_sio_b115200 = 9
     84 };
     85 
     86 
     87 /*
     88  * BmRequestType:  0100 0000B
     89  * bRequest:       FTDI_SIO_SET_DATA
     90  * wValue:         Data characteristics (see below)
     91  * wIndex:         Port
     92  * wLength:        0
     93  * Data:           No
     94  *
     95  * Data characteristics
     96  *
     97  *   B0..7   Number of data bits
     98  *   B8..10  Parity
     99  *           0 = None
    100  *           1 = Odd
    101  *           2 = Even
    102  *           3 = Mark
    103  *           4 = Space
    104  *   B11..13 Stop Bits
    105  *           0 = 1
    106  *           1 = 1.5
    107  *           2 = 2
    108  *   B14..15 Reserved
    109  *
    110  */
    111 /* FTDI_SIO_SET_DATA */
    112 #define FTDI_SIO_SET_DATA_BITS(n) (n)
    113 #define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
    114 #define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
    115 #define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
    116 #define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
    117 #define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
    118 #define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
    119 #define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
    120 #define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
    121 
    122 
    123 /*
    124  * BmRequestType:   0100 0000B
    125  * bRequest:        FTDI_SIO_MODEM_CTRL
    126  * wValue:          ControlValue (see below)
    127  * wIndex:          Port
    128  * wLength:         0
    129  * Data:            None
    130  *
    131  * NOTE: If the device is in RTS/CTS flow control, the RTS set by this
    132  * command will be IGNORED without an error being returned
    133  * Also - you can not set DTR and RTS with one control message
    134  *
    135  * ControlValue
    136  * B0    DTR state
    137  *          0 = reset
    138  *          1 = set
    139  * B1    RTS state
    140  *          0 = reset
    141  *          1 = set
    142  * B2..7 Reserved
    143  * B8    DTR state enable
    144  *          0 = ignore
    145  *          1 = use DTR state
    146  * B9    RTS state enable
    147  *          0 = ignore
    148  *          1 = use RTS state
    149  * B10..15 Reserved
    150  */
    151 /* FTDI_SIO_MODEM_CTRL */
    152 #define FTDI_SIO_SET_DTR_MASK 0x1
    153 #define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK  << 8))
    154 #define FTDI_SIO_SET_DTR_LOW  (0 | ( FTDI_SIO_SET_DTR_MASK  << 8))
    155 #define FTDI_SIO_SET_RTS_MASK 0x2
    156 #define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8))
    157 #define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8))
    158 
    159 
    160 /*
    161  *   BmRequestType:  0100 0000b
    162  *   bRequest:       FTDI_SIO_SET_FLOW_CTRL
    163  *   wValue:         Xoff/Xon
    164  *   wIndex:         Protocol/Port - hIndex is protocl / lIndex is port
    165  *   wLength:        0
    166  *   Data:           None
    167  *
    168  * hIndex protocol is:
    169  *   B0 Output handshaking using RTS/CTS
    170  *       0 = disabled
    171  *       1 = enabled
    172  *   B1 Output handshaking using DTR/DSR
    173  *       0 = disabled
    174  *       1 = enabled
    175  *   B2 Xon/Xoff handshaking
    176  *       0 = disabled
    177  *       1 = enabled
    178  *
    179  * A value of zero in the hIndex field disables handshaking
    180  *
    181  * If Xon/Xoff handshaking is specified, the hValue field should contain the
    182  * XOFF character and the lValue field contains the XON character.
    183  */
    184 /* FTDI_SIO_SET_FLOW_CTRL */
    185 #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
    186 #define FTDI_SIO_RTS_CTS_HS 0x1
    187 #define FTDI_SIO_DTR_DSR_HS 0x2
    188 #define FTDI_SIO_XON_XOFF_HS 0x4
    189 
    190 
    191 /*
    192  *  BmRequestType:   0100 0000b
    193  *  bRequest:        FTDI_SIO_SET_EVENT_CHAR
    194  *  wValue:          Event Char
    195  *  wIndex:          Port
    196  *  wLength:         0
    197  *  Data:            None
    198  *
    199  * wValue:
    200  *   B0..7   Event Character
    201  *   B8      Event Character Processing
    202  *             0 = disabled
    203  *             1 = enabled
    204  *   B9..15  Reserved
    205  *
    206  * FTDI_SIO_SET_EVENT_CHAR
    207  *
    208  * Set the special event character for the specified communications port.
    209  * If the device sees this character it will immediately return the
    210  * data read so far - rather than wait 40ms or until 62 bytes are read
    211  * which is what normally happens.
    212  */
    213 
    214 
    215 
    216 /*
    217  *  BmRequestType:  0100 0000b
    218  *  bRequest:       FTDI_SIO_SET_ERROR_CHAR
    219  *  wValue:         Error Char
    220  *  wIndex:         Port
    221  *  wLength:        0
    222  *  Data:           None
    223  *
    224  *  Error Char
    225  *  B0..7  Error Character
    226  *  B8     Error Character Processing
    227  *           0 = disabled
    228  *           1 = enabled
    229  *  B9..15 Reserved
    230  *
    231  *
    232  * FTDI_SIO_SET_ERROR_CHAR
    233  * Set the parity error replacement character for the specified communications
    234  * port.
    235  */
    236 
    237 
    238 /*
    239  *   BmRequestType:   1100 0000b
    240  *   bRequest:        FTDI_SIO_GET_MODEM_STATUS
    241  *   wValue:          zero
    242  *   wIndex:          Port
    243  *   wLength:         1
    244  *   Data:            Status
    245  *
    246  * One byte of data is returned
    247  * B0..3 0
    248  * B4    CTS
    249  *         0 = inactive
    250  *         1 = active
    251  * B5    DSR
    252  *         0 = inactive
    253  *         1 = active
    254  * B6    Ring Indicator (RI)
    255  *         0 = inactive
    256  *         1 = active
    257  * B7    Receive Line Signal Detect (RLSD)
    258  *         0 = inactive
    259  *         1 = active
    260  *
    261  * FTDI_SIO_GET_MODEM_STATUS
    262  * Retreive the current value of the modem status register.
    263  */
    264 #define FTDI_SIO_CTS_MASK 0x10
    265 #define FTDI_SIO_DSR_MASK 0x20
    266 #define FTDI_SIO_RI_MASK  0x40
    267 #define FTDI_SIO_RLSD_MASK 0x80
    268 
    269 
    270 
    271 /*
    272  *
    273  * DATA FORMAT
    274  *
    275  * IN Endpoint
    276  *
    277  * The device reserves the first two bytes of data on this endpoint to contain
    278  * the current values of the modem and line status registers. In the absence of
    279  * data, the device generates a message consisting of these two status bytes
    280  * every 40 ms.
    281  *
    282  * Byte 0: Modem Status
    283  *   NOTE: 4 upper bits have same layout as the MSR register in a 16550
    284  *
    285  * Offset	Description
    286  * B0..3	Port
    287  * B4		Clear to Send (CTS)
    288  * B5		Data Set Ready (DSR)
    289  * B6		Ring Indicator (RI)
    290  * B7		Receive Line Signal Detect (RLSD)
    291  *
    292  * Byte 1: Line Status
    293  *   NOTE: same layout as the LSR register in a 16550
    294  *
    295  * Offset	Description
    296  * B0	Data Ready (DR)
    297  * B1	Overrun Error (OE)
    298  * B2	Parity Error (PE)
    299  * B3	Framing Error (FE)
    300  * B4	Break Interrupt (BI)
    301  * B5	Transmitter Holding Register (THRE)
    302  * B6	Transmitter Empty (TEMT)
    303  * B7	Error in RCVR FIFO
    304  *
    305  *
    306  * OUT Endpoint
    307  *
    308  * This device reserves the first bytes of data on this endpoint contain the
    309  * length and port identifier of the message. For the FTDI USB Serial converter
    310  * the port identifier is always 1.
    311  *
    312  * Byte 0: Port & length
    313  *
    314  * Offset	Description
    315  * B0..1	Port
    316  * B2..7	Length of message - (not including Byte 0)
    317  *
    318  */
    319 #define FTDI_PORT_MASK 0x0f
    320 #define FTDI_MSR_MASK 0xf0
    321 #define FTDI_GET_MSR(p) (((p)[0]) & FTDI_MSR_MASK)
    322 #define FTDI_GET_LSR(p) ((p)[1])
    323 #define FTDI_LSR_MASK (~0x60) /* interesting bits */
    324 #define FTDI_OUT_TAG(len, port) (((len) << 2) | (port))
    325