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