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