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 32 /* Port Identifier Table */ 33 #define FTDI_PIT_DEFAULT 0 /* SIOA */ 34 #define FTDI_PIT_SIOA 1 /* SIOA */ 35 #define FTDI_PIT_SIOB 2 /* SIOB */ 36 #define FTDI_PIT_PARALLEL 3 /* Parallel */ 37 38 /* Values for driver_info */ 39 #define UFTDI_TYPE_MASK 0x000000ff 40 #define UFTDI_TYPE_SIO 0x00000001 41 #define UFTDI_TYPE_8U232AM 0x00000002 42 #define UFTDI_TYPE_AUTO (UFTDI_TYPE_SIO | UFTDI_TYPE_8U232AM) 43 #define UFTDI_FLAG_MASK 0x0000ff00 44 #define UFTDI_FLAG_JTAG 0x00000100 45 46 /* 47 * BmRequestType: 0100 0000B 48 * bRequest: FTDI_SIO_RESET 49 * wValue: Control Value 50 * 0 = Reset SIO 51 * 1 = Purge RX buffer 52 * 2 = Purge TX buffer 53 * wIndex: Port 54 * wLength: 0 55 * Data: None 56 * 57 * The Reset SIO command has this effect: 58 * 59 * Sets flow control set to 'none' 60 * Event char = 0x0d 61 * Event trigger = disabled 62 * Purge RX buffer 63 * Purge TX buffer 64 * Clear DTR 65 * Clear RTS 66 * baud and data format not reset 67 * 68 * The Purge RX and TX buffer commands affect nothing except the buffers 69 */ 70 /* FTDI_SIO_RESET */ 71 #define FTDI_SIO_RESET_SIO 0 72 #define FTDI_SIO_RESET_PURGE_RX 1 73 #define FTDI_SIO_RESET_PURGE_TX 2 74 75 /* 76 * BmRequestType: 0100 0000B 77 * bRequest: FTDI_SIO_SET_BAUDRATE 78 * wValue: BaudRate value - see below 79 * wIndex: Port 80 * wLength: 0 81 * Data: None 82 */ 83 /* FTDI_SIO_SET_BAUDRATE */ 84 enum { 85 ftdi_sio_b300 = 0, 86 ftdi_sio_b600 = 1, 87 ftdi_sio_b1200 = 2, 88 ftdi_sio_b2400 = 3, 89 ftdi_sio_b4800 = 4, 90 ftdi_sio_b9600 = 5, 91 ftdi_sio_b19200 = 6, 92 ftdi_sio_b38400 = 7, 93 ftdi_sio_b57600 = 8, 94 ftdi_sio_b115200 = 9 95 }; 96 97 #define FTDI_8U232AM_FREQ 3000000 98 99 /* Bounds for normal divisors as 4-bit fixed precision ints. */ 100 #define FTDI_8U232AM_MIN_DIV 0x20 101 #define FTDI_8U232AM_MAX_DIV 0x3fff8 102 103 /* 104 * BmRequestType: 0100 0000B 105 * bRequest: FTDI_SIO_SET_DATA 106 * wValue: Data characteristics (see below) 107 * wIndex: Port 108 * wLength: 0 109 * Data: No 110 * 111 * Data characteristics 112 * 113 * B0..7 Number of data bits 114 * B8..10 Parity 115 * 0 = None 116 * 1 = Odd 117 * 2 = Even 118 * 3 = Mark 119 * 4 = Space 120 * B11..13 Stop Bits 121 * 0 = 1 122 * 1 = 1.5 123 * 2 = 2 124 * B14..15 Reserved 125 * 126 */ 127 /* FTDI_SIO_SET_DATA */ 128 #define FTDI_SIO_SET_DATA_BITS(n) (n) 129 #define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 130 #define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 131 #define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 132 #define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 133 #define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 134 #define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 135 #define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 136 #define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 137 #define FTDI_SIO_SET_BREAK (0x1 << 14) 138 139 /* 140 * BmRequestType: 0100 0000B 141 * bRequest: FTDI_SIO_MODEM_CTRL 142 * wValue: ControlValue (see below) 143 * wIndex: Port 144 * wLength: 0 145 * Data: None 146 * 147 * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 148 * command will be IGNORED without an error being returned 149 * Also - you can not set DTR and RTS with one control message 150 * 151 * ControlValue 152 * B0 DTR state 153 * 0 = reset 154 * 1 = set 155 * B1 RTS state 156 * 0 = reset 157 * 1 = set 158 * B2..7 Reserved 159 * B8 DTR state enable 160 * 0 = ignore 161 * 1 = use DTR state 162 * B9 RTS state enable 163 * 0 = ignore 164 * 1 = use RTS state 165 * B10..15 Reserved 166 */ 167 /* FTDI_SIO_MODEM_CTRL */ 168 #define FTDI_SIO_SET_DTR_MASK 0x1 169 #define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 170 #define FTDI_SIO_SET_DTR_LOW (0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 171 #define FTDI_SIO_SET_RTS_MASK 0x2 172 #define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8)) 173 #define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8)) 174 175 /* 176 * BmRequestType: 0100 0000b 177 * bRequest: FTDI_SIO_SET_FLOW_CTRL 178 * wValue: Xoff/Xon 179 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 180 * wLength: 0 181 * Data: None 182 * 183 * hIndex protocol is: 184 * B0 Output handshaking using RTS/CTS 185 * 0 = disabled 186 * 1 = enabled 187 * B1 Output handshaking using DTR/DSR 188 * 0 = disabled 189 * 1 = enabled 190 * B2 Xon/Xoff handshaking 191 * 0 = disabled 192 * 1 = enabled 193 * 194 * A value of zero in the hIndex field disables handshaking 195 * 196 * If Xon/Xoff handshaking is specified, the hValue field should contain the 197 * XOFF character and the lValue field contains the XON character. 198 */ 199 /* FTDI_SIO_SET_FLOW_CTRL */ 200 #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 201 #define FTDI_SIO_RTS_CTS_HS 0x1 202 #define FTDI_SIO_DTR_DSR_HS 0x2 203 #define FTDI_SIO_XON_XOFF_HS 0x4 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 * BmRequestType: 0100 0000b 230 * bRequest: FTDI_SIO_SET_ERROR_CHAR 231 * wValue: Error Char 232 * wIndex: Port 233 * wLength: 0 234 * Data: None 235 * 236 * Error Char 237 * B0..7 Error Character 238 * B8 Error Character Processing 239 * 0 = disabled 240 * 1 = enabled 241 * B9..15 Reserved 242 * FTDI_SIO_SET_ERROR_CHAR 243 * Set the parity error replacement character for the specified communications 244 * port. 245 */ 246 247 /* 248 * BmRequestType: 1100 0000b 249 * bRequest: FTDI_SIO_GET_MODEM_STATUS 250 * wValue: zero 251 * wIndex: Port 252 * wLength: 1 253 * Data: Status 254 * 255 * One byte of data is returned 256 * B0..3 0 257 * B4 CTS 258 * 0 = inactive 259 * 1 = active 260 * B5 DSR 261 * 0 = inactive 262 * 1 = active 263 * B6 Ring Indicator (RI) 264 * 0 = inactive 265 * 1 = active 266 * B7 Receive Line Signal Detect (RLSD) 267 * 0 = inactive 268 * 1 = active 269 * 270 * FTDI_SIO_GET_MODEM_STATUS 271 * Retrieve the current value of the modem status register. 272 */ 273 #define FTDI_SIO_CTS_MASK 0x10 274 #define FTDI_SIO_DSR_MASK 0x20 275 #define FTDI_SIO_RI_MASK 0x40 276 #define FTDI_SIO_RLSD_MASK 0x80 277 278 /* 279 * DATA FORMAT 280 * 281 * IN Endpoint 282 * 283 * The device reserves the first two bytes of data on this endpoint to contain 284 * the current values of the modem and line status registers. In the absence of 285 * data, the device generates a message consisting of these two status bytes 286 * every 40 ms. 287 * 288 * Byte 0: Modem Status 289 * NOTE: 4 upper bits have same layout as the MSR register in a 16550 290 * 291 * Offset Description 292 * B0..3 Port 293 * B4 Clear to Send (CTS) 294 * B5 Data Set Ready (DSR) 295 * B6 Ring Indicator (RI) 296 * B7 Receive Line Signal Detect (RLSD) 297 * 298 * Byte 1: Line Status 299 * NOTE: same layout as the LSR register in a 16550 300 * 301 * Offset Description 302 * B0 Data Ready (DR) 303 * B1 Overrun Error (OE) 304 * B2 Parity Error (PE) 305 * B3 Framing Error (FE) 306 * B4 Break Interrupt (BI) 307 * B5 Transmitter Holding Register (THRE) 308 * B6 Transmitter Empty (TEMT) 309 * B7 Error in RCVR FIFO 310 * OUT Endpoint 311 * 312 * This device reserves the first bytes of data on this endpoint contain the 313 * length and port identifier of the message. For the FTDI USB Serial converter 314 * the port identifier is always 1. 315 * 316 * Byte 0: Port & length 317 * 318 * Offset Description 319 * B0..1 Port 320 * B2..7 Length of message - (not including Byte 0) 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