uftdireg.h revision 1.11
1/* $NetBSD: uftdireg.h,v 1.11 2019/09/13 20:50:45 ryo 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.ftdichip.com) 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@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#define FTDI_SIO_SET_BITMODE 11 /* Set FIFO/Serial mode */ 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 36enum 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 */ 81enum { 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/* 95 * BmRequestType: 0100 0000B 96 * bRequest: FTDI_SIO_SET_DATA 97 * wValue: Data characteristics (see below) 98 * wIndex: Port 99 * wLength: 0 100 * Data: No 101 * 102 * Data characteristics 103 * 104 * B0..7 Number of data bits 105 * B8..10 Parity 106 * 0 = None 107 * 1 = Odd 108 * 2 = Even 109 * 3 = Mark 110 * 4 = Space 111 * B11..13 Stop Bits 112 * 0 = 1 113 * 1 = 1.5 114 * 2 = 2 115 * B14..15 Reserved 116 * 117 */ 118/* FTDI_SIO_SET_DATA */ 119#define FTDI_SIO_SET_DATA_BITS(n) (n) 120#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 121#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 122#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 123#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 124#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 125#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 126#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 127#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 128#define FTDI_SIO_SET_BREAK (0x1 << 14) 129 130 131/* 132 * BmRequestType: 0100 0000B 133 * bRequest: FTDI_SIO_MODEM_CTRL 134 * wValue: ControlValue (see below) 135 * wIndex: Port 136 * wLength: 0 137 * Data: None 138 * 139 * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 140 * command will be IGNORED without an error being returned 141 * Also - you can not set DTR and RTS with one control message 142 * 143 * ControlValue 144 * B0 DTR state 145 * 0 = reset 146 * 1 = set 147 * B1 RTS state 148 * 0 = reset 149 * 1 = set 150 * B2..7 Reserved 151 * B8 DTR state enable 152 * 0 = ignore 153 * 1 = use DTR state 154 * B9 RTS state enable 155 * 0 = ignore 156 * 1 = use RTS state 157 * B10..15 Reserved 158 */ 159/* FTDI_SIO_MODEM_CTRL */ 160#define FTDI_SIO_SET_DTR_MASK 0x1 161#define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 162#define FTDI_SIO_SET_DTR_LOW (0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 163#define FTDI_SIO_SET_RTS_MASK 0x2 164#define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8)) 165#define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8)) 166 167 168/* 169 * BmRequestType: 0100 0000b 170 * bRequest: FTDI_SIO_SET_FLOW_CTRL 171 * wValue: Xoff/Xon 172 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 173 * wLength: 0 174 * Data: None 175 * 176 * hIndex protocol is: 177 * B0 Output handshaking using RTS/CTS 178 * 0 = disabled 179 * 1 = enabled 180 * B1 Output handshaking using DTR/DSR 181 * 0 = disabled 182 * 1 = enabled 183 * B2 Xon/Xoff handshaking 184 * 0 = disabled 185 * 1 = enabled 186 * 187 * A value of zero in the hIndex field disables handshaking 188 * 189 * If Xon/Xoff handshaking is specified, the hValue field should contain the 190 * XOFF character and the lValue field contains the XON character. 191 */ 192/* FTDI_SIO_SET_FLOW_CTRL */ 193#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 194#define FTDI_SIO_RTS_CTS_HS 0x1 195#define FTDI_SIO_DTR_DSR_HS 0x2 196#define FTDI_SIO_XON_XOFF_HS 0x4 197 198 199/* 200 * BmRequestType: 0100 0000b 201 * bRequest: FTDI_SIO_SET_EVENT_CHAR 202 * wValue: Event Char 203 * wIndex: Port 204 * wLength: 0 205 * Data: None 206 * 207 * wValue: 208 * B0..7 Event Character 209 * B8 Event Character Processing 210 * 0 = disabled 211 * 1 = enabled 212 * B9..15 Reserved 213 * 214 * FTDI_SIO_SET_EVENT_CHAR 215 * 216 * Set the special event character for the specified communications port. 217 * If the device sees this character it will immediately return the 218 * data read so far - rather than wait 40ms or until 62 bytes are read 219 * which is what normally happens. 220 */ 221 222 223 224/* 225 * BmRequestType: 0100 0000b 226 * bRequest: FTDI_SIO_SET_ERROR_CHAR 227 * wValue: Error Char 228 * wIndex: Port 229 * wLength: 0 230 * Data: None 231 * 232 * Error Char 233 * B0..7 Error Character 234 * B8 Error Character Processing 235 * 0 = disabled 236 * 1 = enabled 237 * B9..15 Reserved 238 * 239 * 240 * FTDI_SIO_SET_ERROR_CHAR 241 * Set the parity error replacement character for the specified communications 242 * port. 243 */ 244 245 246/* 247 * BmRequestType: 1100 0000b 248 * bRequest: FTDI_SIO_GET_MODEM_STATUS 249 * wValue: zero 250 * wIndex: Port 251 * wLength: 1 252 * Data: Status 253 * 254 * One byte of data is returned 255 * B0..3 0 256 * B4 CTS 257 * 0 = inactive 258 * 1 = active 259 * B5 DSR 260 * 0 = inactive 261 * 1 = active 262 * B6 Ring Indicator (RI) 263 * 0 = inactive 264 * 1 = active 265 * B7 Receive Line Signal Detect (RLSD) 266 * 0 = inactive 267 * 1 = active 268 * 269 * FTDI_SIO_GET_MODEM_STATUS 270 * Retrieve the current value of the modem status register. 271 */ 272#define FTDI_SIO_CTS_MASK 0x10 273#define FTDI_SIO_DSR_MASK 0x20 274#define FTDI_SIO_RI_MASK 0x40 275#define FTDI_SIO_RLSD_MASK 0x80 276 277 278 279/* 280 * 281 * DATA FORMAT 282 * 283 * IN Endpoint 284 * 285 * The device reserves the first two bytes of data on this endpoint to contain 286 * the current values of the modem and line status registers. In the absence of 287 * data, the device generates a message consisting of these two status bytes 288 * every 40 ms. 289 * 290 * Byte 0: Modem Status 291 * NOTE: 4 upper bits have same layout as the MSR register in a 16550 292 * 293 * Offset Description 294 * B0..3 Port 295 * B4 Clear to Send (CTS) 296 * B5 Data Set Ready (DSR) 297 * B6 Ring Indicator (RI) 298 * B7 Receive Line Signal Detect (RLSD) 299 * 300 * Byte 1: Line Status 301 * NOTE: same layout as the LSR register in a 16550 302 * 303 * Offset Description 304 * B0 Data Ready (DR) 305 * B1 Overrun Error (OE) 306 * B2 Parity Error (PE) 307 * B3 Framing Error (FE) 308 * B4 Break Interrupt (BI) 309 * B5 Transmitter Holding Register (THRE) 310 * B6 Transmitter Empty (TEMT) 311 * B7 Error in RCVR FIFO 312 * 313 * 314 * OUT Endpoint 315 * 316 * This device reserves the first bytes of data on this endpoint contain the 317 * length and port identifier of the message. For the FTDI USB Serial converter 318 * the port identifier is always 1. 319 * 320 * Byte 0: Port & length 321 * 322 * Offset Description 323 * B0..1 Port 324 * B2..7 Length of message - (not including Byte 0) 325 * 326 */ 327#define FTDI_PORT_MASK 0x0f 328#define FTDI_MSR_MASK 0xf0 329#define FTDI_GET_MSR(p) (((p)[0]) & FTDI_MSR_MASK) 330#define FTDI_GET_LSR(p) ((p)[1]) 331#define FTDI_LSR_MASK (~0x60) /* interesting bits */ 332#define FTDI_OUT_TAG(len, port) (((len) << 2) | (port)) 333 334/* 335 * BmRequestType: 0100 0000B 336 * bRequest: FTDI_SIO_SET_BITMODE 337 * wValue: Bitmode value - see below 338 * wIndex: Port 339 * wLength: 0 340 * Data: None 341 * 342 * Not all modes are available on all chips 343 */ 344/* FTDI_SIO_SET_BITMODE */ 345#define FTDI_BITMODE_RESET 0x00 /* UART mode */ 346#define FTDI_BITMODE_BITBANG 0x01 /* asynchrounous bitbang mode */ 347#define FTDI_BITMODE_MPSSE 0x02 /* MPSSE mode */ 348#define FTDI_BITMODE_SYNCBB 0x04 /* synchronous bitbang mode */ 349#define FTDI_BITMODE_MCU 0x08 /* MCU Host Bus Emulation mode */ 350#define FTDI_BITMODE_OPTO 0x10 /* Fast Opto-Isolated Serial Interface Mode */ 351#define FTDI_BITMODE_CBUS 0x20 /* Bitbang on CBUS pins */ 352#define FTDI_BITMODE_SYNCFF 0x40 /* Synchronous FIFO mode */ 353 354