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