1/* $NetBSD: uftdireg.h,v 1.6 2002/07/11 21:14:28 augustss Exp $ */ 2/* $FreeBSD$ */ 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 * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details 12 * of the protocol required to talk to the device and ongoing assistence 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 26 * port */ 27#define FTDI_SIO_GET_STATUS 5 /* Retrieve current value of status 28 * reg */ 29#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */ 30#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */ 31#define FTDI_SIO_SET_LATENCY 9 /* Set the latency timer */ 32#define FTDI_SIO_GET_LATENCY 10 /* Read the latency timer */ 33#define FTDI_SIO_SET_BITMODE 11 /* Set the bit bang I/O mode */ 34#define FTDI_SIO_GET_BITMODE 12 /* Read pin states in bit bang mode */ 35 36/* Port Identifier Table */ 37#define FTDI_PIT_DEFAULT 0 /* SIOA */ 38#define FTDI_PIT_SIOA 1 /* SIOA */ 39#define FTDI_PIT_SIOB 2 /* SIOB */ 40#define FTDI_PIT_PARALLEL 3 /* Parallel */ 41 42/* Values for driver_info */ 43#define UFTDI_TYPE_MASK 0x000000ff 44#define UFTDI_TYPE_SIO 0x00000001 45#define UFTDI_TYPE_8U232AM 0x00000002 46#define UFTDI_TYPE_AUTO (UFTDI_TYPE_SIO | UFTDI_TYPE_8U232AM) 47#define UFTDI_FLAG_MASK 0x0000ff00 48#define UFTDI_FLAG_JTAG 0x00000100 49 50/* 51 * BmRequestType: 0100 0000B 52 * bRequest: FTDI_SIO_RESET 53 * wValue: Control Value 54 * 0 = Reset SIO 55 * 1 = Purge RX buffer 56 * 2 = Purge TX buffer 57 * wIndex: Port 58 * wLength: 0 59 * Data: None 60 * 61 * The Reset SIO command has this effect: 62 * 63 * Sets flow control set to 'none' 64 * Event char = 0x0d 65 * Event trigger = disabled 66 * Purge RX buffer 67 * Purge TX buffer 68 * Clear DTR 69 * Clear RTS 70 * baud and data format not reset 71 * 72 * The Purge RX and TX buffer commands affect nothing except the buffers 73 */ 74/* FTDI_SIO_RESET */ 75#define FTDI_SIO_RESET_SIO 0 76#define FTDI_SIO_RESET_PURGE_RX 1 77#define FTDI_SIO_RESET_PURGE_TX 2 78 79/* 80 * BmRequestType: 0100 0000B 81 * bRequest: FTDI_SIO_SET_BAUDRATE 82 * wValue: BaudRate low bits 83 * wIndex: Port and BaudRate high bits 84 * wLength: 0 85 * Data: None 86 */ 87/* FTDI_SIO_SET_BAUDRATE */ 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 * BmRequestType: 0100 0000B 127 * bRequest: FTDI_SIO_MODEM_CTRL 128 * wValue: ControlValue (see below) 129 * wIndex: Port 130 * wLength: 0 131 * Data: None 132 * 133 * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 134 * command will be IGNORED without an error being returned 135 * Also - you can not set DTR and RTS with one control message 136 * 137 * ControlValue 138 * B0 DTR state 139 * 0 = reset 140 * 1 = set 141 * B1 RTS state 142 * 0 = reset 143 * 1 = set 144 * B2..7 Reserved 145 * B8 DTR state enable 146 * 0 = ignore 147 * 1 = use DTR state 148 * B9 RTS state enable 149 * 0 = ignore 150 * 1 = use RTS state 151 * B10..15 Reserved 152 */ 153/* FTDI_SIO_MODEM_CTRL */ 154#define FTDI_SIO_SET_DTR_MASK 0x1 155#define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 156#define FTDI_SIO_SET_DTR_LOW (0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 157#define FTDI_SIO_SET_RTS_MASK 0x2 158#define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8)) 159#define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8)) 160 161/* 162 * BmRequestType: 0100 0000b 163 * bRequest: FTDI_SIO_SET_FLOW_CTRL 164 * wValue: Xoff/Xon 165 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 166 * wLength: 0 167 * Data: None 168 * 169 * hIndex protocol is: 170 * B0 Output handshaking using RTS/CTS 171 * 0 = disabled 172 * 1 = enabled 173 * B1 Output handshaking using DTR/DSR 174 * 0 = disabled 175 * 1 = enabled 176 * B2 Xon/Xoff handshaking 177 * 0 = disabled 178 * 1 = enabled 179 * 180 * A value of zero in the hIndex field disables handshaking 181 * 182 * If Xon/Xoff handshaking is specified, the hValue field should contain the 183 * XOFF character and the lValue field contains the XON character. 184 */ 185/* FTDI_SIO_SET_FLOW_CTRL */ 186#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 187#define FTDI_SIO_RTS_CTS_HS 0x1 188#define FTDI_SIO_DTR_DSR_HS 0x2 189#define FTDI_SIO_XON_XOFF_HS 0x4 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 * BmRequestType: 0100 0000b 216 * bRequest: FTDI_SIO_SET_ERROR_CHAR 217 * wValue: Error Char 218 * wIndex: Port 219 * wLength: 0 220 * Data: None 221 * 222 * Error Char 223 * B0..7 Error Character 224 * B8 Error Character Processing 225 * 0 = disabled 226 * 1 = enabled 227 * B9..15 Reserved 228 * FTDI_SIO_SET_ERROR_CHAR 229 * Set the parity error replacement character for the specified communications 230 * port. 231 */ 232 233/* 234 * BmRequestType: 1100 0000b 235 * bRequest: FTDI_SIO_GET_MODEM_STATUS 236 * wValue: zero 237 * wIndex: Port 238 * wLength: 1 239 * Data: Status 240 * 241 * One byte of data is returned 242 * B0..3 0 243 * B4 CTS 244 * 0 = inactive 245 * 1 = active 246 * B5 DSR 247 * 0 = inactive 248 * 1 = active 249 * B6 Ring Indicator (RI) 250 * 0 = inactive 251 * 1 = active 252 * B7 Receive Line Signal Detect (RLSD) 253 * 0 = inactive 254 * 1 = active 255 * 256 * FTDI_SIO_GET_MODEM_STATUS 257 * Retrieve the current value of the modem status register. 258 */ 259#define FTDI_SIO_CTS_MASK 0x10 260#define FTDI_SIO_DSR_MASK 0x20 261#define FTDI_SIO_RI_MASK 0x40 262#define FTDI_SIO_RLSD_MASK 0x80 263 264/* 265 * DATA FORMAT 266 * 267 * IN Endpoint 268 * 269 * The device reserves the first two bytes of data on this endpoint to contain 270 * the current values of the modem and line status registers. In the absence of 271 * data, the device generates a message consisting of these two status bytes 272 * every 40 ms. 273 * 274 * Byte 0: Modem Status 275 * NOTE: 4 upper bits have same layout as the MSR register in a 16550 276 * 277 * Offset Description 278 * B0..3 Port 279 * B4 Clear to Send (CTS) 280 * B5 Data Set Ready (DSR) 281 * B6 Ring Indicator (RI) 282 * B7 Receive Line Signal Detect (RLSD) 283 * 284 * Byte 1: Line Status 285 * NOTE: same layout as the LSR register in a 16550 286 * 287 * Offset Description 288 * B0 Data Ready (DR) 289 * B1 Overrun Error (OE) 290 * B2 Parity Error (PE) 291 * B3 Framing Error (FE) 292 * B4 Break Interrupt (BI) 293 * B5 Transmitter Holding Register (THRE) 294 * B6 Transmitter Empty (TEMT) 295 * B7 Error in RCVR FIFO 296 * OUT Endpoint 297 * 298 * This device reserves the first bytes of data on this endpoint contain the 299 * length and port identifier of the message. For the FTDI USB Serial converter 300 * the port identifier is always 1. 301 * 302 * Byte 0: Port & length 303 * 304 * Offset Description 305 * B0..1 Port 306 * B2..7 Length of message - (not including Byte 0) 307 */ 308#define FTDI_PORT_MASK 0x0f 309#define FTDI_MSR_MASK 0xf0 310#define FTDI_GET_MSR(p) (((p)[0]) & FTDI_MSR_MASK) 311#define FTDI_GET_LSR(p) ((p)[1]) 312#define FTDI_LSR_MASK (~0x60) /* interesting bits */ 313#define FTDI_OUT_TAG(len, port) (((len) << 2) | (port)) 314