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_JTAG_IFACE(i) (1 << i) /* Flag interface as jtag */ 44 #define UFTDI_JTAG_IFACES_MAX 8 /* Allow up to 8 jtag intfs */ 45 #define UFTDI_JTAG_CHECK_STRING 0xff /* Check product names table */ 46 #define UFTDI_JTAG_MASK 0xff 47 48 /* 49 * BmRequestType: 0100 0000B 50 * bRequest: FTDI_SIO_RESET 51 * wValue: Control Value 52 * 0 = Reset SIO 53 * 1 = Purge RX buffer 54 * 2 = Purge TX buffer 55 * wIndex: Port 56 * wLength: 0 57 * Data: None 58 * 59 * The Reset SIO command has this effect: 60 * 61 * Sets flow control set to 'none' 62 * Event char = 0x0d 63 * Event trigger = disabled 64 * Purge RX buffer 65 * Purge TX buffer 66 * Clear DTR 67 * Clear RTS 68 * baud and data format not reset 69 * 70 * The Purge RX and TX buffer commands affect nothing except the buffers 71 */ 72 /* FTDI_SIO_RESET */ 73 #define FTDI_SIO_RESET_SIO 0 74 #define FTDI_SIO_RESET_PURGE_RX 1 75 #define FTDI_SIO_RESET_PURGE_TX 2 76 77 /* 78 * BmRequestType: 0100 0000B 79 * bRequest: FTDI_SIO_SET_BAUDRATE 80 * wValue: BaudRate low bits 81 * wIndex: Port and BaudRate high bits 82 * wLength: 0 83 * Data: None 84 */ 85 /* FTDI_SIO_SET_BAUDRATE */ 86 87 /* 88 * BmRequestType: 0100 0000B 89 * bRequest: FTDI_SIO_SET_DATA 90 * wValue: Data characteristics (see below) 91 * wIndex: Port 92 * wLength: 0 93 * Data: No 94 * 95 * Data characteristics 96 * 97 * B0..7 Number of data bits 98 * B8..10 Parity 99 * 0 = None 100 * 1 = Odd 101 * 2 = Even 102 * 3 = Mark 103 * 4 = Space 104 * B11..13 Stop Bits 105 * 0 = 1 106 * 1 = 1.5 107 * 2 = 2 108 * B14..15 Reserved 109 * 110 */ 111 /* FTDI_SIO_SET_DATA */ 112 #define FTDI_SIO_SET_DATA_BITS(n) (n) 113 #define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 114 #define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 115 #define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 116 #define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 117 #define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 118 #define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 119 #define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 120 #define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 121 #define FTDI_SIO_SET_BREAK (0x1 << 14) 122 123 /* 124 * BmRequestType: 0100 0000B 125 * bRequest: FTDI_SIO_MODEM_CTRL 126 * wValue: ControlValue (see below) 127 * wIndex: Port 128 * wLength: 0 129 * Data: None 130 * 131 * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 132 * command will be IGNORED without an error being returned 133 * Also - you can not set DTR and RTS with one control message 134 * 135 * ControlValue 136 * B0 DTR state 137 * 0 = reset 138 * 1 = set 139 * B1 RTS state 140 * 0 = reset 141 * 1 = set 142 * B2..7 Reserved 143 * B8 DTR state enable 144 * 0 = ignore 145 * 1 = use DTR state 146 * B9 RTS state enable 147 * 0 = ignore 148 * 1 = use RTS state 149 * B10..15 Reserved 150 */ 151 /* FTDI_SIO_MODEM_CTRL */ 152 #define FTDI_SIO_SET_DTR_MASK 0x1 153 #define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK << 8)) 154 #define FTDI_SIO_SET_DTR_LOW (0 | ( FTDI_SIO_SET_DTR_MASK << 8)) 155 #define FTDI_SIO_SET_RTS_MASK 0x2 156 #define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8)) 157 #define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8)) 158 159 /* 160 * BmRequestType: 0100 0000b 161 * bRequest: FTDI_SIO_SET_FLOW_CTRL 162 * wValue: Xoff/Xon 163 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 164 * wLength: 0 165 * Data: None 166 * 167 * hIndex protocol is: 168 * B0 Output handshaking using RTS/CTS 169 * 0 = disabled 170 * 1 = enabled 171 * B1 Output handshaking using DTR/DSR 172 * 0 = disabled 173 * 1 = enabled 174 * B2 Xon/Xoff handshaking 175 * 0 = disabled 176 * 1 = enabled 177 * 178 * A value of zero in the hIndex field disables handshaking 179 * 180 * If Xon/Xoff handshaking is specified, the hValue field should contain the 181 * XOFF character and the lValue field contains the XON character. 182 */ 183 /* FTDI_SIO_SET_FLOW_CTRL */ 184 #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 185 #define FTDI_SIO_RTS_CTS_HS 0x1 186 #define FTDI_SIO_DTR_DSR_HS 0x2 187 #define FTDI_SIO_XON_XOFF_HS 0x4 188 189 /* 190 * BmRequestType: 0100 0000b 191 * bRequest: FTDI_SIO_SET_EVENT_CHAR 192 * wValue: Event Char 193 * wIndex: Port 194 * wLength: 0 195 * Data: None 196 * 197 * wValue: 198 * B0..7 Event Character 199 * B8 Event Character Processing 200 * 0 = disabled 201 * 1 = enabled 202 * B9..15 Reserved 203 * 204 * FTDI_SIO_SET_EVENT_CHAR 205 * 206 * Set the special event character for the specified communications port. 207 * If the device sees this character it will immediately return the 208 * data read so far - rather than wait 40ms or until 62 bytes are read 209 * which is what normally happens. 210 */ 211 212 /* 213 * BmRequestType: 0100 0000b 214 * bRequest: FTDI_SIO_SET_ERROR_CHAR 215 * wValue: Error Char 216 * wIndex: Port 217 * wLength: 0 218 * Data: None 219 * 220 * Error Char 221 * B0..7 Error Character 222 * B8 Error Character Processing 223 * 0 = disabled 224 * 1 = enabled 225 * B9..15 Reserved 226 * FTDI_SIO_SET_ERROR_CHAR 227 * Set the parity error replacement character for the specified communications 228 * port. 229 */ 230 231 /* 232 * BmRequestType: 1100 0000b 233 * bRequest: FTDI_SIO_GET_MODEM_STATUS 234 * wValue: zero 235 * wIndex: Port 236 * wLength: 1 237 * Data: Status 238 * 239 * One byte of data is returned 240 * B0..3 0 241 * B4 CTS 242 * 0 = inactive 243 * 1 = active 244 * B5 DSR 245 * 0 = inactive 246 * 1 = active 247 * B6 Ring Indicator (RI) 248 * 0 = inactive 249 * 1 = active 250 * B7 Receive Line Signal Detect (RLSD) 251 * 0 = inactive 252 * 1 = active 253 * 254 * FTDI_SIO_GET_MODEM_STATUS 255 * Retrieve the current value of the modem status register. 256 */ 257 #define FTDI_SIO_CTS_MASK 0x10 258 #define FTDI_SIO_DSR_MASK 0x20 259 #define FTDI_SIO_RI_MASK 0x40 260 #define FTDI_SIO_RLSD_MASK 0x80 261 262 /* 263 * DATA FORMAT 264 * 265 * IN Endpoint 266 * 267 * The device reserves the first two bytes of data on this endpoint to contain 268 * the current values of the modem and line status registers. In the absence of 269 * data, the device generates a message consisting of these two status bytes 270 * every 40 ms. 271 * 272 * Byte 0: Modem Status 273 * NOTE: 4 upper bits have same layout as the MSR register in a 16550 274 * 275 * Offset Description 276 * B0..3 Port 277 * B4 Clear to Send (CTS) 278 * B5 Data Set Ready (DSR) 279 * B6 Ring Indicator (RI) 280 * B7 Receive Line Signal Detect (RLSD) 281 * 282 * Byte 1: Line Status 283 * NOTE: same layout as the LSR register in a 16550 284 * 285 * Offset Description 286 * B0 Data Ready (DR) 287 * B1 Overrun Error (OE) 288 * B2 Parity Error (PE) 289 * B3 Framing Error (FE) 290 * B4 Break Interrupt (BI) 291 * B5 Transmitter Holding Register (THRE) 292 * B6 Transmitter Empty (TEMT) 293 * B7 Error in RCVR FIFO 294 * OUT Endpoint 295 * 296 * This device reserves the first bytes of data on this endpoint contain the 297 * length and port identifier of the message. For the FTDI USB Serial converter 298 * the port identifier is always 1. 299 * 300 * Byte 0: Port & length 301 * 302 * Offset Description 303 * B0..1 Port 304 * B2..7 Length of message - (not including Byte 0) 305 */ 306 #define FTDI_PORT_MASK 0x0f 307 #define FTDI_MSR_MASK 0xf0 308 #define FTDI_GET_MSR(p) (((p)[0]) & FTDI_MSR_MASK) 309 #define FTDI_GET_LSR(p) ((p)[1]) 310 #define FTDI_LSR_MASK (~0x60) /* interesting bits */ 311 #define FTDI_OUT_TAG(len, port) (((len) << 2) | (port)) 312