root/dev/usb/uftdireg.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */