1/* 2 * Driver definitions for the FTDI USB Single Port Serial Converter - 3 * known as FTDI_SIO (Serial Input/Output application of the chipset) 4 * 5 * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h 6 * 7 * 8 * The example I have is known as the USC-1000 which is available from 9 * http://www.dse.co.nz - cat no XH4214 It looks similar to this: 10 * http://www.dansdata.com/usbser.htm but I can't be sure There are other 11 * USC-1000s which don't look like my device though so beware! 12 * 13 * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side, 14 * USB on the other. 15 * 16 * Thanx to FTDI (http://www.ftdichip.com) for so kindly providing details 17 * of the protocol required to talk to the device and ongoing assistence 18 * during development. 19 * 20 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the 21 * FTDI_SIO implementation. 22 * 23 */ 24 25/* Commands */ 26#define FTDI_SIO_RESET 0 /* Reset the port */ 27#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 28#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */ 29#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */ 30#define FTDI_SIO_SET_DATA 4 /* Set the data characteristics of 31 the port */ 32#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modem 33 status register */ 34#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */ 35#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */ 36#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */ 37#define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */ 38 39/* Interface indices for FT2232, FT2232H and FT4232H devices */ 40#define INTERFACE_A 1 41#define INTERFACE_B 2 42#define INTERFACE_C 3 43#define INTERFACE_D 4 44 45 46/* 47 * BmRequestType: 1100 0000b 48 * bRequest: FTDI_E2_READ 49 * wValue: 0 50 * wIndex: Address of word to read 51 * wLength: 2 52 * Data: Will return a word of data from E2Address 53 * 54 */ 55 56/* Port Identifier Table */ 57#define PIT_DEFAULT 0 /* SIOA */ 58#define PIT_SIOA 1 /* SIOA */ 59/* The device this driver is tested with one has only one port */ 60#define PIT_SIOB 2 /* SIOB */ 61#define PIT_PARALLEL 3 /* Parallel */ 62 63/* FTDI_SIO_RESET */ 64#define FTDI_SIO_RESET_REQUEST FTDI_SIO_RESET 65#define FTDI_SIO_RESET_REQUEST_TYPE 0x40 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 * BmRequestType: 0100 0000B 72 * bRequest: FTDI_SIO_RESET 73 * wValue: Control Value 74 * 0 = Reset SIO 75 * 1 = Purge RX buffer 76 * 2 = Purge TX buffer 77 * wIndex: Port 78 * wLength: 0 79 * Data: None 80 * 81 * The Reset SIO command has this effect: 82 * 83 * Sets flow control set to 'none' 84 * Event char = $0D 85 * Event trigger = disabled 86 * Purge RX buffer 87 * Purge TX buffer 88 * Clear DTR 89 * Clear RTS 90 * baud and data format not reset 91 * 92 * The Purge RX and TX buffer commands affect nothing except the buffers 93 * 94 */ 95 96/* FTDI_SIO_SET_BAUDRATE */ 97#define FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE 0x40 98#define FTDI_SIO_SET_BAUDRATE_REQUEST 3 99 100 101enum ftdi_chip_type { 102 SIO = 1, 103 FT8U232AM = 2, 104 FT232BM = 3, 105 FT2232C = 4, 106 FT232RL = 5, 107 FT2232H = 6, 108 FT4232H = 7 109}; 110 111enum ftdi_sio_baudrate { 112 ftdi_sio_b300 = 0, 113 ftdi_sio_b600 = 1, 114 ftdi_sio_b1200 = 2, 115 ftdi_sio_b2400 = 3, 116 ftdi_sio_b4800 = 4, 117 ftdi_sio_b9600 = 5, 118 ftdi_sio_b19200 = 6, 119 ftdi_sio_b38400 = 7, 120 ftdi_sio_b57600 = 8, 121 ftdi_sio_b115200 = 9 122}; 123 124/* 125 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor 126 * values are calculated internally. 127 */ 128#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA 129#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40 130#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 131#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 132#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 133#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 134#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 135#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 136#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 137#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 138#define FTDI_SIO_SET_BREAK (0x1 << 14) 139/* FTDI_SIO_SET_DATA */ 140 141/* 142 * BmRequestType: 0100 0000B 143 * bRequest: FTDI_SIO_SET_DATA 144 * wValue: Data characteristics (see below) 145 * wIndex: Port 146 * wLength: 0 147 * Data: No 148 * 149 * Data characteristics 150 * 151 * B0..7 Number of data bits 152 * B8..10 Parity 153 * 0 = None 154 * 1 = Odd 155 * 2 = Even 156 * 3 = Mark 157 * 4 = Space 158 * B11..13 Stop Bits 159 * 0 = 1 160 * 1 = 1.5 161 * 2 = 2 162 * B14 163 * 1 = TX ON (break) 164 * 0 = TX OFF (normal state) 165 * B15 Reserved 166 * 167 */ 168 169 170 171/* FTDI_SIO_MODEM_CTRL */ 172#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40 173#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL 174 175/* 176 * BmRequestType: 0100 0000B 177 * bRequest: FTDI_SIO_MODEM_CTRL 178 * wValue: ControlValue (see below) 179 * wIndex: Port 180 * wLength: 0 181 * Data: None 182 * 183 * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 184 * command will be IGNORED without an error being returned 185 * Also - you can not set DTR and RTS with one control message 186 */ 187 188#define FTDI_SIO_SET_DTR_MASK 0x1 189#define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK << 8)) 190#define FTDI_SIO_SET_DTR_LOW (0 | (FTDI_SIO_SET_DTR_MASK << 8)) 191#define FTDI_SIO_SET_RTS_MASK 0x2 192#define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8)) 193#define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8)) 194 195/* 196 * ControlValue 197 * B0 DTR state 198 * 0 = reset 199 * 1 = set 200 * B1 RTS state 201 * 0 = reset 202 * 1 = set 203 * B2..7 Reserved 204 * B8 DTR state enable 205 * 0 = ignore 206 * 1 = use DTR state 207 * B9 RTS state enable 208 * 0 = ignore 209 * 1 = use RTS state 210 * B10..15 Reserved 211 */ 212 213/* FTDI_SIO_SET_FLOW_CTRL */ 214#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40 215#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL 216#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 217#define FTDI_SIO_RTS_CTS_HS (0x1 << 8) 218#define FTDI_SIO_DTR_DSR_HS (0x2 << 8) 219#define FTDI_SIO_XON_XOFF_HS (0x4 << 8) 220/* 221 * BmRequestType: 0100 0000b 222 * bRequest: FTDI_SIO_SET_FLOW_CTRL 223 * wValue: Xoff/Xon 224 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 225 * wLength: 0 226 * Data: None 227 * 228 * hIndex protocol is: 229 * B0 Output handshaking using RTS/CTS 230 * 0 = disabled 231 * 1 = enabled 232 * B1 Output handshaking using DTR/DSR 233 * 0 = disabled 234 * 1 = enabled 235 * B2 Xon/Xoff handshaking 236 * 0 = disabled 237 * 1 = enabled 238 * 239 * A value of zero in the hIndex field disables handshaking 240 * 241 * If Xon/Xoff handshaking is specified, the hValue field should contain the 242 * XOFF character and the lValue field contains the XON character. 243 */ 244 245/* 246 * FTDI_SIO_GET_LATENCY_TIMER 247 * 248 * Set the timeout interval. The FTDI collects data from the slave 249 * device, transmitting it to the host when either A) 62 bytes are 250 * received, or B) the timeout interval has elapsed and the buffer 251 * contains at least 1 byte. Setting this value to a small number 252 * can dramatically improve performance for applications which send 253 * small packets, since the default value is 16ms. 254 */ 255#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER 256#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0 257 258/* 259 * BmRequestType: 1100 0000b 260 * bRequest: FTDI_SIO_GET_LATENCY_TIMER 261 * wValue: 0 262 * wIndex: Port 263 * wLength: 0 264 * Data: latency (on return) 265 */ 266 267/* 268 * FTDI_SIO_SET_LATENCY_TIMER 269 * 270 * Set the timeout interval. The FTDI collects data from the slave 271 * device, transmitting it to the host when either A) 62 bytes are 272 * received, or B) the timeout interval has elapsed and the buffer 273 * contains at least 1 byte. Setting this value to a small number 274 * can dramatically improve performance for applications which send 275 * small packets, since the default value is 16ms. 276 */ 277#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER 278#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40 279 280/* 281 * BmRequestType: 0100 0000b 282 * bRequest: FTDI_SIO_SET_LATENCY_TIMER 283 * wValue: Latency (milliseconds) 284 * wIndex: Port 285 * wLength: 0 286 * Data: None 287 * 288 * wValue: 289 * B0..7 Latency timer 290 * B8..15 0 291 * 292 */ 293 294/* 295 * FTDI_SIO_SET_EVENT_CHAR 296 * 297 * Set the special event character for the specified communications port. 298 * If the device sees this character it will immediately return the 299 * data read so far - rather than wait 40ms or until 62 bytes are read 300 * which is what normally happens. 301 */ 302 303 304#define FTDI_SIO_SET_EVENT_CHAR_REQUEST FTDI_SIO_SET_EVENT_CHAR 305#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40 306 307 308/* 309 * BmRequestType: 0100 0000b 310 * bRequest: FTDI_SIO_SET_EVENT_CHAR 311 * wValue: EventChar 312 * wIndex: Port 313 * wLength: 0 314 * Data: None 315 * 316 * wValue: 317 * B0..7 Event Character 318 * B8 Event Character Processing 319 * 0 = disabled 320 * 1 = enabled 321 * B9..15 Reserved 322 * 323 */ 324 325/* FTDI_SIO_SET_ERROR_CHAR */ 326 327/* 328 * Set the parity error replacement character for the specified communications 329 * port 330 */ 331 332/* 333 * BmRequestType: 0100 0000b 334 * bRequest: FTDI_SIO_SET_EVENT_CHAR 335 * wValue: Error Char 336 * wIndex: Port 337 * wLength: 0 338 * Data: None 339 * 340 *Error Char 341 * B0..7 Error Character 342 * B8 Error Character Processing 343 * 0 = disabled 344 * 1 = enabled 345 * B9..15 Reserved 346 * 347 */ 348 349/* FTDI_SIO_GET_MODEM_STATUS */ 350/* Retrieve the current value of the modem status register */ 351 352#define FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE 0xc0 353#define FTDI_SIO_GET_MODEM_STATUS_REQUEST FTDI_SIO_GET_MODEM_STATUS 354#define FTDI_SIO_CTS_MASK 0x10 355#define FTDI_SIO_DSR_MASK 0x20 356#define FTDI_SIO_RI_MASK 0x40 357#define FTDI_SIO_RLSD_MASK 0x80 358/* 359 * BmRequestType: 1100 0000b 360 * bRequest: FTDI_SIO_GET_MODEM_STATUS 361 * wValue: zero 362 * wIndex: Port 363 * wLength: 1 364 * Data: Status 365 * 366 * One byte of data is returned 367 * B0..3 0 368 * B4 CTS 369 * 0 = inactive 370 * 1 = active 371 * B5 DSR 372 * 0 = inactive 373 * 1 = active 374 * B6 Ring Indicator (RI) 375 * 0 = inactive 376 * 1 = active 377 * B7 Receive Line Signal Detect (RLSD) 378 * 0 = inactive 379 * 1 = active 380 */ 381 382 383 384/* Descriptors returned by the device 385 * 386 * Device Descriptor 387 * 388 * Offset Field Size Value Description 389 * 0 bLength 1 0x12 Size of descriptor in bytes 390 * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type 391 * 2 bcdUSB 2 0x0110 USB Spec Release Number 392 * 4 bDeviceClass 1 0x00 Class Code 393 * 5 bDeviceSubClass 1 0x00 SubClass Code 394 * 6 bDeviceProtocol 1 0x00 Protocol Code 395 * 7 bMaxPacketSize0 1 0x08 Maximum packet size for endpoint 0 396 * 8 idVendor 2 0x0403 Vendor ID 397 * 10 idProduct 2 0x8372 Product ID (FTDI_SIO_PID) 398 * 12 bcdDevice 2 0x0001 Device release number 399 * 14 iManufacturer 1 0x01 Index of man. string desc 400 * 15 iProduct 1 0x02 Index of prod string desc 401 * 16 iSerialNumber 1 0x02 Index of serial nmr string desc 402 * 17 bNumConfigurations 1 0x01 Number of possible configurations 403 * 404 * Configuration Descriptor 405 * 406 * Offset Field Size Value 407 * 0 bLength 1 0x09 Size of descriptor in bytes 408 * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type 409 * 2 wTotalLength 2 0x0020 Total length of data 410 * 4 bNumInterfaces 1 0x01 Number of interfaces supported 411 * 5 bConfigurationValue 1 0x01 Argument for SetCOnfiguration() req 412 * 6 iConfiguration 1 0x02 Index of config string descriptor 413 * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup 414 * 8 MaxPower 1 0x1E Max power consumption 415 * 416 * Interface Descriptor 417 * 418 * Offset Field Size Value 419 * 0 bLength 1 0x09 Size of descriptor in bytes 420 * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type 421 * 2 bInterfaceNumber 1 0x00 Number of interface 422 * 3 bAlternateSetting 1 0x00 Value used to select alternate 423 * 4 bNumEndpoints 1 0x02 Number of endpoints 424 * 5 bInterfaceClass 1 0xFF Class Code 425 * 6 bInterfaceSubClass 1 0xFF Subclass Code 426 * 7 bInterfaceProtocol 1 0xFF Protocol Code 427 * 8 iInterface 1 0x02 Index of interface string description 428 * 429 * IN Endpoint Descriptor 430 * 431 * Offset Field Size Value 432 * 0 bLength 1 0x07 Size of descriptor in bytes 433 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 434 * 2 bEndpointAddress 1 0x82 Address of endpoint 435 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 436 * 4 bNumEndpoints 2 0x0040 maximum packet size 437 * 5 bInterval 1 0x00 Interval for polling endpoint 438 * 439 * OUT Endpoint Descriptor 440 * 441 * Offset Field Size Value 442 * 0 bLength 1 0x07 Size of descriptor in bytes 443 * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 444 * 2 bEndpointAddress 1 0x02 Address of endpoint 445 * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 446 * 4 bNumEndpoints 2 0x0040 maximum packet size 447 * 5 bInterval 1 0x00 Interval for polling endpoint 448 * 449 * DATA FORMAT 450 * 451 * IN Endpoint 452 * 453 * The device reserves the first two bytes of data on this endpoint to contain 454 * the current values of the modem and line status registers. In the absence of 455 * data, the device generates a message consisting of these two status bytes 456 * every 40 ms 457 * 458 * Byte 0: Modem Status 459 * 460 * Offset Description 461 * B0 Reserved - must be 1 462 * B1 Reserved - must be 0 463 * B2 Reserved - must be 0 464 * B3 Reserved - must be 0 465 * B4 Clear to Send (CTS) 466 * B5 Data Set Ready (DSR) 467 * B6 Ring Indicator (RI) 468 * B7 Receive Line Signal Detect (RLSD) 469 * 470 * Byte 1: Line Status 471 * 472 * Offset Description 473 * B0 Data Ready (DR) 474 * B1 Overrun Error (OE) 475 * B2 Parity Error (PE) 476 * B3 Framing Error (FE) 477 * B4 Break Interrupt (BI) 478 * B5 Transmitter Holding Register (THRE) 479 * B6 Transmitter Empty (TEMT) 480 * B7 Error in RCVR FIFO 481 * 482 */ 483#define FTDI_RS0_CTS (1 << 4) 484#define FTDI_RS0_DSR (1 << 5) 485#define FTDI_RS0_RI (1 << 6) 486#define FTDI_RS0_RLSD (1 << 7) 487 488#define FTDI_RS_DR 1 489#define FTDI_RS_OE (1<<1) 490#define FTDI_RS_PE (1<<2) 491#define FTDI_RS_FE (1<<3) 492#define FTDI_RS_BI (1<<4) 493#define FTDI_RS_THRE (1<<5) 494#define FTDI_RS_TEMT (1<<6) 495#define FTDI_RS_FIFO (1<<7) 496 497/* 498 * OUT Endpoint 499 * 500 * This device reserves the first bytes of data on this endpoint contain the 501 * length and port identifier of the message. For the FTDI USB Serial converter 502 * the port identifier is always 1. 503 * 504 * Byte 0: Line Status 505 * 506 * Offset Description 507 * B0 Reserved - must be 1 508 * B1 Reserved - must be 0 509 * B2..7 Length of message - (not including Byte 0) 510 * 511 */ 512