162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Driver definitions for the FTDI USB Single Port Serial Converter - 462306a36Sopenharmony_ci * known as FTDI_SIO (Serial Input/Output application of the chipset) 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * The example I have is known as the USC-1000 which is available from 1062306a36Sopenharmony_ci * http://www.dse.co.nz - cat no XH4214 It looks similar to this: 1162306a36Sopenharmony_ci * http://www.dansdata.com/usbser.htm but I can't be sure There are other 1262306a36Sopenharmony_ci * USC-1000s which don't look like my device though so beware! 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side, 1562306a36Sopenharmony_ci * USB on the other. 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * Thanx to FTDI (http://www.ftdichip.com) for so kindly providing details 1862306a36Sopenharmony_ci * of the protocol required to talk to the device and ongoing assistence 1962306a36Sopenharmony_ci * during development. 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the 2262306a36Sopenharmony_ci * FTDI_SIO implementation. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* Commands */ 2762306a36Sopenharmony_ci#define FTDI_SIO_RESET 0 /* Reset the port */ 2862306a36Sopenharmony_ci#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 2962306a36Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */ 3062306a36Sopenharmony_ci#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */ 3162306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA 4 /* Set the data characteristics of 3262306a36Sopenharmony_ci the port */ 3362306a36Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modem 3462306a36Sopenharmony_ci status register */ 3562306a36Sopenharmony_ci#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */ 3662306a36Sopenharmony_ci#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */ 3762306a36Sopenharmony_ci#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */ 3862306a36Sopenharmony_ci#define FTDI_SIO_GET_LATENCY_TIMER 0x0a /* Get the latency timer */ 3962306a36Sopenharmony_ci#define FTDI_SIO_SET_BITMODE 0x0b /* Set bitbang mode */ 4062306a36Sopenharmony_ci#define FTDI_SIO_READ_PINS 0x0c /* Read immediate value of pins */ 4162306a36Sopenharmony_ci#define FTDI_SIO_READ_EEPROM 0x90 /* Read EEPROM */ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* Channel indices for FT2232, FT2232H and FT4232H devices */ 4462306a36Sopenharmony_ci#define CHANNEL_A 1 4562306a36Sopenharmony_ci#define CHANNEL_B 2 4662306a36Sopenharmony_ci#define CHANNEL_C 3 4762306a36Sopenharmony_ci#define CHANNEL_D 4 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* 5162306a36Sopenharmony_ci * BmRequestType: 1100 0000b 5262306a36Sopenharmony_ci * bRequest: FTDI_E2_READ 5362306a36Sopenharmony_ci * wValue: 0 5462306a36Sopenharmony_ci * wIndex: Address of word to read 5562306a36Sopenharmony_ci * wLength: 2 5662306a36Sopenharmony_ci * Data: Will return a word of data from E2Address 5762306a36Sopenharmony_ci * 5862306a36Sopenharmony_ci */ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* Port Identifier Table */ 6162306a36Sopenharmony_ci#define PIT_DEFAULT 0 /* SIOA */ 6262306a36Sopenharmony_ci#define PIT_SIOA 1 /* SIOA */ 6362306a36Sopenharmony_ci/* The device this driver is tested with one has only one port */ 6462306a36Sopenharmony_ci#define PIT_SIOB 2 /* SIOB */ 6562306a36Sopenharmony_ci#define PIT_PARALLEL 3 /* Parallel */ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/* FTDI_SIO_RESET */ 6862306a36Sopenharmony_ci#define FTDI_SIO_RESET_REQUEST FTDI_SIO_RESET 6962306a36Sopenharmony_ci#define FTDI_SIO_RESET_REQUEST_TYPE 0x40 7062306a36Sopenharmony_ci#define FTDI_SIO_RESET_SIO 0 7162306a36Sopenharmony_ci#define FTDI_SIO_RESET_PURGE_RX 1 7262306a36Sopenharmony_ci#define FTDI_SIO_RESET_PURGE_TX 2 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* 7562306a36Sopenharmony_ci * BmRequestType: 0100 0000B 7662306a36Sopenharmony_ci * bRequest: FTDI_SIO_RESET 7762306a36Sopenharmony_ci * wValue: Control Value 7862306a36Sopenharmony_ci * 0 = Reset SIO 7962306a36Sopenharmony_ci * 1 = Purge RX buffer 8062306a36Sopenharmony_ci * 2 = Purge TX buffer 8162306a36Sopenharmony_ci * wIndex: Port 8262306a36Sopenharmony_ci * wLength: 0 8362306a36Sopenharmony_ci * Data: None 8462306a36Sopenharmony_ci * 8562306a36Sopenharmony_ci * The Reset SIO command has this effect: 8662306a36Sopenharmony_ci * 8762306a36Sopenharmony_ci * Sets flow control set to 'none' 8862306a36Sopenharmony_ci * Event char = $0D 8962306a36Sopenharmony_ci * Event trigger = disabled 9062306a36Sopenharmony_ci * Purge RX buffer 9162306a36Sopenharmony_ci * Purge TX buffer 9262306a36Sopenharmony_ci * Clear DTR 9362306a36Sopenharmony_ci * Clear RTS 9462306a36Sopenharmony_ci * baud and data format not reset 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci * The Purge RX and TX buffer commands affect nothing except the buffers 9762306a36Sopenharmony_ci * 9862306a36Sopenharmony_ci */ 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* FTDI_SIO_SET_BAUDRATE */ 10162306a36Sopenharmony_ci#define FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE 0x40 10262306a36Sopenharmony_ci#define FTDI_SIO_SET_BAUDRATE_REQUEST 3 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/* 10562306a36Sopenharmony_ci * BmRequestType: 0100 0000B 10662306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_BAUDRATE 10762306a36Sopenharmony_ci * wValue: BaudDivisor value - see below 10862306a36Sopenharmony_ci * wIndex: Port 10962306a36Sopenharmony_ci * wLength: 0 11062306a36Sopenharmony_ci * Data: None 11162306a36Sopenharmony_ci * The BaudDivisor values are calculated as follows: 11262306a36Sopenharmony_ci * - BaseClock is either 12000000 or 48000000 depending on the device. 11362306a36Sopenharmony_ci * FIXME: I wish I knew how to detect old chips to select proper base clock! 11462306a36Sopenharmony_ci * - BaudDivisor is a fixed point number encoded in a funny way. 11562306a36Sopenharmony_ci * (--WRONG WAY OF THINKING--) 11662306a36Sopenharmony_ci * BaudDivisor is a fixed point number encoded with following bit weighs: 11762306a36Sopenharmony_ci * (-2)(-1)(13..0). It is a radical with a denominator of 4, so values 11862306a36Sopenharmony_ci * end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...). 11962306a36Sopenharmony_ci * (--THE REALITY--) 12062306a36Sopenharmony_ci * The both-bits-set has quite different meaning from 0.75 - the chip 12162306a36Sopenharmony_ci * designers have decided it to mean 0.125 instead of 0.75. 12262306a36Sopenharmony_ci * This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates 12362306a36Sopenharmony_ci * and Flow Control Consideration for USB to RS232". 12462306a36Sopenharmony_ci * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should 12562306a36Sopenharmony_ci * automagically re-encode the resulting value to take fractions into 12662306a36Sopenharmony_ci * consideration. 12762306a36Sopenharmony_ci * As all values are integers, some bit twiddling is in order: 12862306a36Sopenharmony_ci * BaudDivisor = (BaseClock / 16 / BaudRate) | 12962306a36Sopenharmony_ci * (((BaseClock / 2 / BaudRate) & 4) ? 0x4000 // 0.5 13062306a36Sopenharmony_ci * : ((BaseClock / 2 / BaudRate) & 2) ? 0x8000 // 0.25 13162306a36Sopenharmony_ci * : ((BaseClock / 2 / BaudRate) & 1) ? 0xc000 // 0.125 13262306a36Sopenharmony_ci * : 0) 13362306a36Sopenharmony_ci * 13462306a36Sopenharmony_ci * For the FT232BM, a 17th divisor bit was introduced to encode the multiples 13562306a36Sopenharmony_ci * of 0.125 missing from the FT8U232AM. Bits 16 to 14 are coded as follows 13662306a36Sopenharmony_ci * (the first four codes are the same as for the FT8U232AM, where bit 16 is 13762306a36Sopenharmony_ci * always 0): 13862306a36Sopenharmony_ci * 000 - add .000 to divisor 13962306a36Sopenharmony_ci * 001 - add .500 to divisor 14062306a36Sopenharmony_ci * 010 - add .250 to divisor 14162306a36Sopenharmony_ci * 011 - add .125 to divisor 14262306a36Sopenharmony_ci * 100 - add .375 to divisor 14362306a36Sopenharmony_ci * 101 - add .625 to divisor 14462306a36Sopenharmony_ci * 110 - add .750 to divisor 14562306a36Sopenharmony_ci * 111 - add .875 to divisor 14662306a36Sopenharmony_ci * Bits 15 to 0 of the 17-bit divisor are placed in the urb value. Bit 16 is 14762306a36Sopenharmony_ci * placed in bit 0 of the urb index. 14862306a36Sopenharmony_ci * 14962306a36Sopenharmony_ci * Note that there are a couple of special cases to support the highest baud 15062306a36Sopenharmony_ci * rates. If the calculated divisor value is 1, this needs to be replaced with 15162306a36Sopenharmony_ci * 0. Additionally for the FT232BM, if the calculated divisor value is 0x4001 15262306a36Sopenharmony_ci * (1.5), this needs to be replaced with 0x0001 (1) (but this divisor value is 15362306a36Sopenharmony_ci * not supported by the FT8U232AM). 15462306a36Sopenharmony_ci */ 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cienum ftdi_sio_baudrate { 15762306a36Sopenharmony_ci ftdi_sio_b300 = 0, 15862306a36Sopenharmony_ci ftdi_sio_b600 = 1, 15962306a36Sopenharmony_ci ftdi_sio_b1200 = 2, 16062306a36Sopenharmony_ci ftdi_sio_b2400 = 3, 16162306a36Sopenharmony_ci ftdi_sio_b4800 = 4, 16262306a36Sopenharmony_ci ftdi_sio_b9600 = 5, 16362306a36Sopenharmony_ci ftdi_sio_b19200 = 6, 16462306a36Sopenharmony_ci ftdi_sio_b38400 = 7, 16562306a36Sopenharmony_ci ftdi_sio_b57600 = 8, 16662306a36Sopenharmony_ci ftdi_sio_b115200 = 9 16762306a36Sopenharmony_ci}; 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* 17062306a36Sopenharmony_ci * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor 17162306a36Sopenharmony_ci * values are calculated internally. 17262306a36Sopenharmony_ci */ 17362306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA 17462306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40 17562306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 17662306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 17762306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 17862306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 17962306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 18062306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 18162306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 18262306a36Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 18362306a36Sopenharmony_ci#define FTDI_SIO_SET_BREAK (0x1 << 14) 18462306a36Sopenharmony_ci/* FTDI_SIO_SET_DATA */ 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci/* 18762306a36Sopenharmony_ci * BmRequestType: 0100 0000B 18862306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_DATA 18962306a36Sopenharmony_ci * wValue: Data characteristics (see below) 19062306a36Sopenharmony_ci * wIndex: Port 19162306a36Sopenharmony_ci * wLength: 0 19262306a36Sopenharmony_ci * Data: No 19362306a36Sopenharmony_ci * 19462306a36Sopenharmony_ci * Data characteristics 19562306a36Sopenharmony_ci * 19662306a36Sopenharmony_ci * B0..7 Number of data bits 19762306a36Sopenharmony_ci * B8..10 Parity 19862306a36Sopenharmony_ci * 0 = None 19962306a36Sopenharmony_ci * 1 = Odd 20062306a36Sopenharmony_ci * 2 = Even 20162306a36Sopenharmony_ci * 3 = Mark 20262306a36Sopenharmony_ci * 4 = Space 20362306a36Sopenharmony_ci * B11..13 Stop Bits 20462306a36Sopenharmony_ci * 0 = 1 20562306a36Sopenharmony_ci * 1 = 1.5 20662306a36Sopenharmony_ci * 2 = 2 20762306a36Sopenharmony_ci * B14 20862306a36Sopenharmony_ci * 1 = TX ON (break) 20962306a36Sopenharmony_ci * 0 = TX OFF (normal state) 21062306a36Sopenharmony_ci * B15 Reserved 21162306a36Sopenharmony_ci * 21262306a36Sopenharmony_ci */ 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ci/* FTDI_SIO_MODEM_CTRL */ 21762306a36Sopenharmony_ci#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40 21862306a36Sopenharmony_ci#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci/* 22162306a36Sopenharmony_ci * BmRequestType: 0100 0000B 22262306a36Sopenharmony_ci * bRequest: FTDI_SIO_MODEM_CTRL 22362306a36Sopenharmony_ci * wValue: ControlValue (see below) 22462306a36Sopenharmony_ci * wIndex: Port 22562306a36Sopenharmony_ci * wLength: 0 22662306a36Sopenharmony_ci * Data: None 22762306a36Sopenharmony_ci * 22862306a36Sopenharmony_ci * NOTE: If the device is in RTS/CTS flow control, the RTS set by this 22962306a36Sopenharmony_ci * command will be IGNORED without an error being returned 23062306a36Sopenharmony_ci * Also - you can not set DTR and RTS with one control message 23162306a36Sopenharmony_ci */ 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci#define FTDI_SIO_SET_DTR_MASK 0x1 23462306a36Sopenharmony_ci#define FTDI_SIO_SET_DTR_HIGH ((FTDI_SIO_SET_DTR_MASK << 8) | 1) 23562306a36Sopenharmony_ci#define FTDI_SIO_SET_DTR_LOW ((FTDI_SIO_SET_DTR_MASK << 8) | 0) 23662306a36Sopenharmony_ci#define FTDI_SIO_SET_RTS_MASK 0x2 23762306a36Sopenharmony_ci#define FTDI_SIO_SET_RTS_HIGH ((FTDI_SIO_SET_RTS_MASK << 8) | 2) 23862306a36Sopenharmony_ci#define FTDI_SIO_SET_RTS_LOW ((FTDI_SIO_SET_RTS_MASK << 8) | 0) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci/* 24162306a36Sopenharmony_ci * ControlValue 24262306a36Sopenharmony_ci * B0 DTR state 24362306a36Sopenharmony_ci * 0 = reset 24462306a36Sopenharmony_ci * 1 = set 24562306a36Sopenharmony_ci * B1 RTS state 24662306a36Sopenharmony_ci * 0 = reset 24762306a36Sopenharmony_ci * 1 = set 24862306a36Sopenharmony_ci * B2..7 Reserved 24962306a36Sopenharmony_ci * B8 DTR state enable 25062306a36Sopenharmony_ci * 0 = ignore 25162306a36Sopenharmony_ci * 1 = use DTR state 25262306a36Sopenharmony_ci * B9 RTS state enable 25362306a36Sopenharmony_ci * 0 = ignore 25462306a36Sopenharmony_ci * 1 = use RTS state 25562306a36Sopenharmony_ci * B10..15 Reserved 25662306a36Sopenharmony_ci */ 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci/* FTDI_SIO_SET_FLOW_CTRL */ 25962306a36Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40 26062306a36Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL 26162306a36Sopenharmony_ci#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 26262306a36Sopenharmony_ci#define FTDI_SIO_RTS_CTS_HS (0x1 << 8) 26362306a36Sopenharmony_ci#define FTDI_SIO_DTR_DSR_HS (0x2 << 8) 26462306a36Sopenharmony_ci#define FTDI_SIO_XON_XOFF_HS (0x4 << 8) 26562306a36Sopenharmony_ci/* 26662306a36Sopenharmony_ci * BmRequestType: 0100 0000b 26762306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_FLOW_CTRL 26862306a36Sopenharmony_ci * wValue: Xoff/Xon 26962306a36Sopenharmony_ci * wIndex: Protocol/Port - hIndex is protocol / lIndex is port 27062306a36Sopenharmony_ci * wLength: 0 27162306a36Sopenharmony_ci * Data: None 27262306a36Sopenharmony_ci * 27362306a36Sopenharmony_ci * hIndex protocol is: 27462306a36Sopenharmony_ci * B0 Output handshaking using RTS/CTS 27562306a36Sopenharmony_ci * 0 = disabled 27662306a36Sopenharmony_ci * 1 = enabled 27762306a36Sopenharmony_ci * B1 Output handshaking using DTR/DSR 27862306a36Sopenharmony_ci * 0 = disabled 27962306a36Sopenharmony_ci * 1 = enabled 28062306a36Sopenharmony_ci * B2 Xon/Xoff handshaking 28162306a36Sopenharmony_ci * 0 = disabled 28262306a36Sopenharmony_ci * 1 = enabled 28362306a36Sopenharmony_ci * 28462306a36Sopenharmony_ci * A value of zero in the hIndex field disables handshaking 28562306a36Sopenharmony_ci * 28662306a36Sopenharmony_ci * If Xon/Xoff handshaking is specified, the hValue field should contain the 28762306a36Sopenharmony_ci * XOFF character and the lValue field contains the XON character. 28862306a36Sopenharmony_ci */ 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci/* 29162306a36Sopenharmony_ci * FTDI_SIO_GET_LATENCY_TIMER 29262306a36Sopenharmony_ci * 29362306a36Sopenharmony_ci * Set the timeout interval. The FTDI collects data from the 29462306a36Sopenharmony_ci * device, transmitting it to the host when either A) 62 bytes are 29562306a36Sopenharmony_ci * received, or B) the timeout interval has elapsed and the buffer 29662306a36Sopenharmony_ci * contains at least 1 byte. Setting this value to a small number 29762306a36Sopenharmony_ci * can dramatically improve performance for applications which send 29862306a36Sopenharmony_ci * small packets, since the default value is 16ms. 29962306a36Sopenharmony_ci */ 30062306a36Sopenharmony_ci#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER 30162306a36Sopenharmony_ci#define FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci/* 30462306a36Sopenharmony_ci * BmRequestType: 1100 0000b 30562306a36Sopenharmony_ci * bRequest: FTDI_SIO_GET_LATENCY_TIMER 30662306a36Sopenharmony_ci * wValue: 0 30762306a36Sopenharmony_ci * wIndex: Port 30862306a36Sopenharmony_ci * wLength: 0 30962306a36Sopenharmony_ci * Data: latency (on return) 31062306a36Sopenharmony_ci */ 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci/* 31362306a36Sopenharmony_ci * FTDI_SIO_SET_LATENCY_TIMER 31462306a36Sopenharmony_ci * 31562306a36Sopenharmony_ci * Set the timeout interval. The FTDI collects data from the 31662306a36Sopenharmony_ci * device, transmitting it to the host when either A) 62 bytes are 31762306a36Sopenharmony_ci * received, or B) the timeout interval has elapsed and the buffer 31862306a36Sopenharmony_ci * contains at least 1 byte. Setting this value to a small number 31962306a36Sopenharmony_ci * can dramatically improve performance for applications which send 32062306a36Sopenharmony_ci * small packets, since the default value is 16ms. 32162306a36Sopenharmony_ci */ 32262306a36Sopenharmony_ci#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER 32362306a36Sopenharmony_ci#define FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci/* 32662306a36Sopenharmony_ci * BmRequestType: 0100 0000b 32762306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_LATENCY_TIMER 32862306a36Sopenharmony_ci * wValue: Latency (milliseconds) 32962306a36Sopenharmony_ci * wIndex: Port 33062306a36Sopenharmony_ci * wLength: 0 33162306a36Sopenharmony_ci * Data: None 33262306a36Sopenharmony_ci * 33362306a36Sopenharmony_ci * wValue: 33462306a36Sopenharmony_ci * B0..7 Latency timer 33562306a36Sopenharmony_ci * B8..15 0 33662306a36Sopenharmony_ci * 33762306a36Sopenharmony_ci */ 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci/* 34062306a36Sopenharmony_ci * FTDI_SIO_SET_EVENT_CHAR 34162306a36Sopenharmony_ci * 34262306a36Sopenharmony_ci * Set the special event character for the specified communications port. 34362306a36Sopenharmony_ci * If the device sees this character it will immediately return the 34462306a36Sopenharmony_ci * data read so far - rather than wait 40ms or until 62 bytes are read 34562306a36Sopenharmony_ci * which is what normally happens. 34662306a36Sopenharmony_ci */ 34762306a36Sopenharmony_ci 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci#define FTDI_SIO_SET_EVENT_CHAR_REQUEST FTDI_SIO_SET_EVENT_CHAR 35062306a36Sopenharmony_ci#define FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci/* 35462306a36Sopenharmony_ci * BmRequestType: 0100 0000b 35562306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_EVENT_CHAR 35662306a36Sopenharmony_ci * wValue: EventChar 35762306a36Sopenharmony_ci * wIndex: Port 35862306a36Sopenharmony_ci * wLength: 0 35962306a36Sopenharmony_ci * Data: None 36062306a36Sopenharmony_ci * 36162306a36Sopenharmony_ci * wValue: 36262306a36Sopenharmony_ci * B0..7 Event Character 36362306a36Sopenharmony_ci * B8 Event Character Processing 36462306a36Sopenharmony_ci * 0 = disabled 36562306a36Sopenharmony_ci * 1 = enabled 36662306a36Sopenharmony_ci * B9..15 Reserved 36762306a36Sopenharmony_ci * 36862306a36Sopenharmony_ci */ 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci/* FTDI_SIO_SET_ERROR_CHAR */ 37162306a36Sopenharmony_ci 37262306a36Sopenharmony_ci/* 37362306a36Sopenharmony_ci * Set the parity error replacement character for the specified communications 37462306a36Sopenharmony_ci * port 37562306a36Sopenharmony_ci */ 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci/* 37862306a36Sopenharmony_ci * BmRequestType: 0100 0000b 37962306a36Sopenharmony_ci * bRequest: FTDI_SIO_SET_EVENT_CHAR 38062306a36Sopenharmony_ci * wValue: Error Char 38162306a36Sopenharmony_ci * wIndex: Port 38262306a36Sopenharmony_ci * wLength: 0 38362306a36Sopenharmony_ci * Data: None 38462306a36Sopenharmony_ci * 38562306a36Sopenharmony_ci *Error Char 38662306a36Sopenharmony_ci * B0..7 Error Character 38762306a36Sopenharmony_ci * B8 Error Character Processing 38862306a36Sopenharmony_ci * 0 = disabled 38962306a36Sopenharmony_ci * 1 = enabled 39062306a36Sopenharmony_ci * B9..15 Reserved 39162306a36Sopenharmony_ci * 39262306a36Sopenharmony_ci */ 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci/* FTDI_SIO_GET_MODEM_STATUS */ 39562306a36Sopenharmony_ci/* Retrieve the current value of the modem status register */ 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE 0xc0 39862306a36Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS_REQUEST FTDI_SIO_GET_MODEM_STATUS 39962306a36Sopenharmony_ci#define FTDI_SIO_CTS_MASK 0x10 40062306a36Sopenharmony_ci#define FTDI_SIO_DSR_MASK 0x20 40162306a36Sopenharmony_ci#define FTDI_SIO_RI_MASK 0x40 40262306a36Sopenharmony_ci#define FTDI_SIO_RLSD_MASK 0x80 40362306a36Sopenharmony_ci/* 40462306a36Sopenharmony_ci * BmRequestType: 1100 0000b 40562306a36Sopenharmony_ci * bRequest: FTDI_SIO_GET_MODEM_STATUS 40662306a36Sopenharmony_ci * wValue: zero 40762306a36Sopenharmony_ci * wIndex: Port 40862306a36Sopenharmony_ci * wLength: 1 40962306a36Sopenharmony_ci * Data: Status 41062306a36Sopenharmony_ci * 41162306a36Sopenharmony_ci * One byte of data is returned 41262306a36Sopenharmony_ci * B0..3 0 41362306a36Sopenharmony_ci * B4 CTS 41462306a36Sopenharmony_ci * 0 = inactive 41562306a36Sopenharmony_ci * 1 = active 41662306a36Sopenharmony_ci * B5 DSR 41762306a36Sopenharmony_ci * 0 = inactive 41862306a36Sopenharmony_ci * 1 = active 41962306a36Sopenharmony_ci * B6 Ring Indicator (RI) 42062306a36Sopenharmony_ci * 0 = inactive 42162306a36Sopenharmony_ci * 1 = active 42262306a36Sopenharmony_ci * B7 Receive Line Signal Detect (RLSD) 42362306a36Sopenharmony_ci * 0 = inactive 42462306a36Sopenharmony_ci * 1 = active 42562306a36Sopenharmony_ci */ 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci/* FTDI_SIO_SET_BITMODE */ 42862306a36Sopenharmony_ci#define FTDI_SIO_SET_BITMODE_REQUEST_TYPE 0x40 42962306a36Sopenharmony_ci#define FTDI_SIO_SET_BITMODE_REQUEST FTDI_SIO_SET_BITMODE 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci/* Possible bitmodes for FTDI_SIO_SET_BITMODE_REQUEST */ 43262306a36Sopenharmony_ci#define FTDI_SIO_BITMODE_RESET 0x00 43362306a36Sopenharmony_ci#define FTDI_SIO_BITMODE_CBUS 0x20 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci/* FTDI_SIO_READ_PINS */ 43662306a36Sopenharmony_ci#define FTDI_SIO_READ_PINS_REQUEST_TYPE 0xc0 43762306a36Sopenharmony_ci#define FTDI_SIO_READ_PINS_REQUEST FTDI_SIO_READ_PINS 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci/* 44062306a36Sopenharmony_ci * FTDI_SIO_READ_EEPROM 44162306a36Sopenharmony_ci * 44262306a36Sopenharmony_ci * EEPROM format found in FTDI AN_201, "FT-X MTP memory Configuration", 44362306a36Sopenharmony_ci * http://www.ftdichip.com/Support/Documents/AppNotes/AN_201_FT-X%20MTP%20Memory%20Configuration.pdf 44462306a36Sopenharmony_ci */ 44562306a36Sopenharmony_ci#define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0 44662306a36Sopenharmony_ci#define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci#define FTDI_FTX_CBUS_MUX_GPIO 0x8 44962306a36Sopenharmony_ci#define FTDI_FT232R_CBUS_MUX_GPIO 0xa 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci/* Descriptors returned by the device 45362306a36Sopenharmony_ci * 45462306a36Sopenharmony_ci * Device Descriptor 45562306a36Sopenharmony_ci * 45662306a36Sopenharmony_ci * Offset Field Size Value Description 45762306a36Sopenharmony_ci * 0 bLength 1 0x12 Size of descriptor in bytes 45862306a36Sopenharmony_ci * 1 bDescriptorType 1 0x01 DEVICE Descriptor Type 45962306a36Sopenharmony_ci * 2 bcdUSB 2 0x0110 USB Spec Release Number 46062306a36Sopenharmony_ci * 4 bDeviceClass 1 0x00 Class Code 46162306a36Sopenharmony_ci * 5 bDeviceSubClass 1 0x00 SubClass Code 46262306a36Sopenharmony_ci * 6 bDeviceProtocol 1 0x00 Protocol Code 46362306a36Sopenharmony_ci * 7 bMaxPacketSize0 1 0x08 Maximum packet size for endpoint 0 46462306a36Sopenharmony_ci * 8 idVendor 2 0x0403 Vendor ID 46562306a36Sopenharmony_ci * 10 idProduct 2 0x8372 Product ID (FTDI_SIO_PID) 46662306a36Sopenharmony_ci * 12 bcdDevice 2 0x0001 Device release number 46762306a36Sopenharmony_ci * 14 iManufacturer 1 0x01 Index of man. string desc 46862306a36Sopenharmony_ci * 15 iProduct 1 0x02 Index of prod string desc 46962306a36Sopenharmony_ci * 16 iSerialNumber 1 0x02 Index of serial nmr string desc 47062306a36Sopenharmony_ci * 17 bNumConfigurations 1 0x01 Number of possible configurations 47162306a36Sopenharmony_ci * 47262306a36Sopenharmony_ci * Configuration Descriptor 47362306a36Sopenharmony_ci * 47462306a36Sopenharmony_ci * Offset Field Size Value 47562306a36Sopenharmony_ci * 0 bLength 1 0x09 Size of descriptor in bytes 47662306a36Sopenharmony_ci * 1 bDescriptorType 1 0x02 CONFIGURATION Descriptor Type 47762306a36Sopenharmony_ci * 2 wTotalLength 2 0x0020 Total length of data 47862306a36Sopenharmony_ci * 4 bNumInterfaces 1 0x01 Number of interfaces supported 47962306a36Sopenharmony_ci * 5 bConfigurationValue 1 0x01 Argument for SetCOnfiguration() req 48062306a36Sopenharmony_ci * 6 iConfiguration 1 0x02 Index of config string descriptor 48162306a36Sopenharmony_ci * 7 bmAttributes 1 0x20 Config characteristics Remote Wakeup 48262306a36Sopenharmony_ci * 8 MaxPower 1 0x1E Max power consumption 48362306a36Sopenharmony_ci * 48462306a36Sopenharmony_ci * Interface Descriptor 48562306a36Sopenharmony_ci * 48662306a36Sopenharmony_ci * Offset Field Size Value 48762306a36Sopenharmony_ci * 0 bLength 1 0x09 Size of descriptor in bytes 48862306a36Sopenharmony_ci * 1 bDescriptorType 1 0x04 INTERFACE Descriptor Type 48962306a36Sopenharmony_ci * 2 bInterfaceNumber 1 0x00 Number of interface 49062306a36Sopenharmony_ci * 3 bAlternateSetting 1 0x00 Value used to select alternate 49162306a36Sopenharmony_ci * 4 bNumEndpoints 1 0x02 Number of endpoints 49262306a36Sopenharmony_ci * 5 bInterfaceClass 1 0xFF Class Code 49362306a36Sopenharmony_ci * 6 bInterfaceSubClass 1 0xFF Subclass Code 49462306a36Sopenharmony_ci * 7 bInterfaceProtocol 1 0xFF Protocol Code 49562306a36Sopenharmony_ci * 8 iInterface 1 0x02 Index of interface string description 49662306a36Sopenharmony_ci * 49762306a36Sopenharmony_ci * IN Endpoint Descriptor 49862306a36Sopenharmony_ci * 49962306a36Sopenharmony_ci * Offset Field Size Value 50062306a36Sopenharmony_ci * 0 bLength 1 0x07 Size of descriptor in bytes 50162306a36Sopenharmony_ci * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 50262306a36Sopenharmony_ci * 2 bEndpointAddress 1 0x82 Address of endpoint 50362306a36Sopenharmony_ci * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 50462306a36Sopenharmony_ci * 4 bNumEndpoints 2 0x0040 maximum packet size 50562306a36Sopenharmony_ci * 5 bInterval 1 0x00 Interval for polling endpoint 50662306a36Sopenharmony_ci * 50762306a36Sopenharmony_ci * OUT Endpoint Descriptor 50862306a36Sopenharmony_ci * 50962306a36Sopenharmony_ci * Offset Field Size Value 51062306a36Sopenharmony_ci * 0 bLength 1 0x07 Size of descriptor in bytes 51162306a36Sopenharmony_ci * 1 bDescriptorType 1 0x05 ENDPOINT descriptor type 51262306a36Sopenharmony_ci * 2 bEndpointAddress 1 0x02 Address of endpoint 51362306a36Sopenharmony_ci * 3 bmAttributes 1 0x02 Endpoint attributes - Bulk 51462306a36Sopenharmony_ci * 4 bNumEndpoints 2 0x0040 maximum packet size 51562306a36Sopenharmony_ci * 5 bInterval 1 0x00 Interval for polling endpoint 51662306a36Sopenharmony_ci * 51762306a36Sopenharmony_ci * DATA FORMAT 51862306a36Sopenharmony_ci * 51962306a36Sopenharmony_ci * IN Endpoint 52062306a36Sopenharmony_ci * 52162306a36Sopenharmony_ci * The device reserves the first two bytes of data on this endpoint to contain 52262306a36Sopenharmony_ci * the current values of the modem and line status registers. In the absence of 52362306a36Sopenharmony_ci * data, the device generates a message consisting of these two status bytes 52462306a36Sopenharmony_ci * every 40 ms 52562306a36Sopenharmony_ci * 52662306a36Sopenharmony_ci * Byte 0: Modem Status 52762306a36Sopenharmony_ci * 52862306a36Sopenharmony_ci * Offset Description 52962306a36Sopenharmony_ci * B0 Reserved - must be 1 53062306a36Sopenharmony_ci * B1 Reserved - must be 0 53162306a36Sopenharmony_ci * B2 Reserved - must be 0 53262306a36Sopenharmony_ci * B3 Reserved - must be 0 53362306a36Sopenharmony_ci * B4 Clear to Send (CTS) 53462306a36Sopenharmony_ci * B5 Data Set Ready (DSR) 53562306a36Sopenharmony_ci * B6 Ring Indicator (RI) 53662306a36Sopenharmony_ci * B7 Receive Line Signal Detect (RLSD) 53762306a36Sopenharmony_ci * 53862306a36Sopenharmony_ci * Byte 1: Line Status 53962306a36Sopenharmony_ci * 54062306a36Sopenharmony_ci * Offset Description 54162306a36Sopenharmony_ci * B0 Data Ready (DR) 54262306a36Sopenharmony_ci * B1 Overrun Error (OE) 54362306a36Sopenharmony_ci * B2 Parity Error (PE) 54462306a36Sopenharmony_ci * B3 Framing Error (FE) 54562306a36Sopenharmony_ci * B4 Break Interrupt (BI) 54662306a36Sopenharmony_ci * B5 Transmitter Holding Register (THRE) 54762306a36Sopenharmony_ci * B6 Transmitter Empty (TEMT) 54862306a36Sopenharmony_ci * B7 Error in RCVR FIFO 54962306a36Sopenharmony_ci * 55062306a36Sopenharmony_ci */ 55162306a36Sopenharmony_ci#define FTDI_RS0_CTS (1 << 4) 55262306a36Sopenharmony_ci#define FTDI_RS0_DSR (1 << 5) 55362306a36Sopenharmony_ci#define FTDI_RS0_RI (1 << 6) 55462306a36Sopenharmony_ci#define FTDI_RS0_RLSD (1 << 7) 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ci#define FTDI_RS_DR 1 55762306a36Sopenharmony_ci#define FTDI_RS_OE (1<<1) 55862306a36Sopenharmony_ci#define FTDI_RS_PE (1<<2) 55962306a36Sopenharmony_ci#define FTDI_RS_FE (1<<3) 56062306a36Sopenharmony_ci#define FTDI_RS_BI (1<<4) 56162306a36Sopenharmony_ci#define FTDI_RS_THRE (1<<5) 56262306a36Sopenharmony_ci#define FTDI_RS_TEMT (1<<6) 56362306a36Sopenharmony_ci#define FTDI_RS_FIFO (1<<7) 56462306a36Sopenharmony_ci 56562306a36Sopenharmony_ci/* 56662306a36Sopenharmony_ci * OUT Endpoint 56762306a36Sopenharmony_ci * 56862306a36Sopenharmony_ci * This device reserves the first bytes of data on this endpoint contain the 56962306a36Sopenharmony_ci * length and port identifier of the message. For the FTDI USB Serial converter 57062306a36Sopenharmony_ci * the port identifier is always 1. 57162306a36Sopenharmony_ci * 57262306a36Sopenharmony_ci * Byte 0: Line Status 57362306a36Sopenharmony_ci * 57462306a36Sopenharmony_ci * Offset Description 57562306a36Sopenharmony_ci * B0 Reserved - must be 1 57662306a36Sopenharmony_ci * B1 Reserved - must be 0 57762306a36Sopenharmony_ci * B2..7 Length of message - (not including Byte 0) 57862306a36Sopenharmony_ci * 57962306a36Sopenharmony_ci */ 580