18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Driver definitions for the FTDI USB Single Port Serial Converter -
48c2ecf20Sopenharmony_ci * known as FTDI_SIO (Serial Input/Output application of the chipset)
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * The example I have is known as the USC-1000 which is available from
108c2ecf20Sopenharmony_ci * http://www.dse.co.nz - cat no XH4214 It looks similar to this:
118c2ecf20Sopenharmony_ci * http://www.dansdata.com/usbser.htm but I can't be sure There are other
128c2ecf20Sopenharmony_ci * USC-1000s which don't look like my device though so beware!
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
158c2ecf20Sopenharmony_ci * USB on the other.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * Thanx to FTDI (http://www.ftdichip.com) for so kindly providing details
188c2ecf20Sopenharmony_ci * of the protocol required to talk to the device and ongoing assistence
198c2ecf20Sopenharmony_ci * during development.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the
228c2ecf20Sopenharmony_ci * FTDI_SIO implementation.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Commands */
278c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET			0 /* Reset the port */
288c2ecf20Sopenharmony_ci#define FTDI_SIO_MODEM_CTRL		1 /* Set the modem control register */
298c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL		2 /* Set flow control register */
308c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BAUD_RATE		3 /* Set baud rate */
318c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA		4 /* Set the data characteristics of
328c2ecf20Sopenharmony_ci					     the port */
338c2ecf20Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS	5 /* Retrieve current value of modem
348c2ecf20Sopenharmony_ci					     status register */
358c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_EVENT_CHAR		6 /* Set the event character */
368c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_ERROR_CHAR		7 /* Set the error character */
378c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_LATENCY_TIMER	9 /* Set the latency timer */
388c2ecf20Sopenharmony_ci#define FTDI_SIO_GET_LATENCY_TIMER	0x0a /* Get the latency timer */
398c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BITMODE		0x0b /* Set bitbang mode */
408c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_PINS		0x0c /* Read immediate value of pins */
418c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_EEPROM		0x90 /* Read EEPROM */
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* Interface indices for FT2232, FT2232H and FT4232H devices */
448c2ecf20Sopenharmony_ci#define INTERFACE_A		1
458c2ecf20Sopenharmony_ci#define INTERFACE_B		2
468c2ecf20Sopenharmony_ci#define INTERFACE_C		3
478c2ecf20Sopenharmony_ci#define INTERFACE_D		4
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci *   BmRequestType:  1100 0000b
528c2ecf20Sopenharmony_ci *   bRequest:       FTDI_E2_READ
538c2ecf20Sopenharmony_ci *   wValue:         0
548c2ecf20Sopenharmony_ci *   wIndex:         Address of word to read
558c2ecf20Sopenharmony_ci *   wLength:        2
568c2ecf20Sopenharmony_ci *   Data:           Will return a word of data from E2Address
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Port Identifier Table */
618c2ecf20Sopenharmony_ci#define PIT_DEFAULT		0 /* SIOA */
628c2ecf20Sopenharmony_ci#define PIT_SIOA		1 /* SIOA */
638c2ecf20Sopenharmony_ci/* The device this driver is tested with one has only one port */
648c2ecf20Sopenharmony_ci#define PIT_SIOB		2 /* SIOB */
658c2ecf20Sopenharmony_ci#define PIT_PARALLEL		3 /* Parallel */
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* FTDI_SIO_RESET */
688c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET_REQUEST FTDI_SIO_RESET
698c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET_REQUEST_TYPE 0x40
708c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET_SIO 0
718c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET_PURGE_RX 1
728c2ecf20Sopenharmony_ci#define FTDI_SIO_RESET_PURGE_TX 2
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/*
758c2ecf20Sopenharmony_ci * BmRequestType:  0100 0000B
768c2ecf20Sopenharmony_ci * bRequest:       FTDI_SIO_RESET
778c2ecf20Sopenharmony_ci * wValue:         Control Value
788c2ecf20Sopenharmony_ci *                   0 = Reset SIO
798c2ecf20Sopenharmony_ci *                   1 = Purge RX buffer
808c2ecf20Sopenharmony_ci *                   2 = Purge TX buffer
818c2ecf20Sopenharmony_ci * wIndex:         Port
828c2ecf20Sopenharmony_ci * wLength:        0
838c2ecf20Sopenharmony_ci * Data:           None
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci * The Reset SIO command has this effect:
868c2ecf20Sopenharmony_ci *
878c2ecf20Sopenharmony_ci *    Sets flow control set to 'none'
888c2ecf20Sopenharmony_ci *    Event char = $0D
898c2ecf20Sopenharmony_ci *    Event trigger = disabled
908c2ecf20Sopenharmony_ci *    Purge RX buffer
918c2ecf20Sopenharmony_ci *    Purge TX buffer
928c2ecf20Sopenharmony_ci *    Clear DTR
938c2ecf20Sopenharmony_ci *    Clear RTS
948c2ecf20Sopenharmony_ci *    baud and data format not reset
958c2ecf20Sopenharmony_ci *
968c2ecf20Sopenharmony_ci * The Purge RX and TX buffer commands affect nothing except the buffers
978c2ecf20Sopenharmony_ci *
988c2ecf20Sopenharmony_ci   */
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* FTDI_SIO_SET_BAUDRATE */
1018c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE 0x40
1028c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BAUDRATE_REQUEST 3
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/*
1058c2ecf20Sopenharmony_ci * BmRequestType:  0100 0000B
1068c2ecf20Sopenharmony_ci * bRequest:       FTDI_SIO_SET_BAUDRATE
1078c2ecf20Sopenharmony_ci * wValue:         BaudDivisor value - see below
1088c2ecf20Sopenharmony_ci * wIndex:         Port
1098c2ecf20Sopenharmony_ci * wLength:        0
1108c2ecf20Sopenharmony_ci * Data:           None
1118c2ecf20Sopenharmony_ci * The BaudDivisor values are calculated as follows:
1128c2ecf20Sopenharmony_ci * - BaseClock is either 12000000 or 48000000 depending on the device.
1138c2ecf20Sopenharmony_ci *   FIXME: I wish I knew how to detect old chips to select proper base clock!
1148c2ecf20Sopenharmony_ci * - BaudDivisor is a fixed point number encoded in a funny way.
1158c2ecf20Sopenharmony_ci *   (--WRONG WAY OF THINKING--)
1168c2ecf20Sopenharmony_ci *   BaudDivisor is a fixed point number encoded with following bit weighs:
1178c2ecf20Sopenharmony_ci *   (-2)(-1)(13..0). It is a radical with a denominator of 4, so values
1188c2ecf20Sopenharmony_ci *   end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...).
1198c2ecf20Sopenharmony_ci *   (--THE REALITY--)
1208c2ecf20Sopenharmony_ci *   The both-bits-set has quite different meaning from 0.75 - the chip
1218c2ecf20Sopenharmony_ci *   designers have decided it to mean 0.125 instead of 0.75.
1228c2ecf20Sopenharmony_ci *   This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates
1238c2ecf20Sopenharmony_ci *   and Flow Control Consideration for USB to RS232".
1248c2ecf20Sopenharmony_ci * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should
1258c2ecf20Sopenharmony_ci *   automagically re-encode the resulting value to take fractions into
1268c2ecf20Sopenharmony_ci *   consideration.
1278c2ecf20Sopenharmony_ci * As all values are integers, some bit twiddling is in order:
1288c2ecf20Sopenharmony_ci *   BaudDivisor = (BaseClock / 16 / BaudRate) |
1298c2ecf20Sopenharmony_ci *   (((BaseClock / 2 / BaudRate) & 4) ? 0x4000    // 0.5
1308c2ecf20Sopenharmony_ci *    : ((BaseClock / 2 / BaudRate) & 2) ? 0x8000  // 0.25
1318c2ecf20Sopenharmony_ci *    : ((BaseClock / 2 / BaudRate) & 1) ? 0xc000  // 0.125
1328c2ecf20Sopenharmony_ci *    : 0)
1338c2ecf20Sopenharmony_ci *
1348c2ecf20Sopenharmony_ci * For the FT232BM, a 17th divisor bit was introduced to encode the multiples
1358c2ecf20Sopenharmony_ci * of 0.125 missing from the FT8U232AM.  Bits 16 to 14 are coded as follows
1368c2ecf20Sopenharmony_ci * (the first four codes are the same as for the FT8U232AM, where bit 16 is
1378c2ecf20Sopenharmony_ci * always 0):
1388c2ecf20Sopenharmony_ci *   000 - add .000 to divisor
1398c2ecf20Sopenharmony_ci *   001 - add .500 to divisor
1408c2ecf20Sopenharmony_ci *   010 - add .250 to divisor
1418c2ecf20Sopenharmony_ci *   011 - add .125 to divisor
1428c2ecf20Sopenharmony_ci *   100 - add .375 to divisor
1438c2ecf20Sopenharmony_ci *   101 - add .625 to divisor
1448c2ecf20Sopenharmony_ci *   110 - add .750 to divisor
1458c2ecf20Sopenharmony_ci *   111 - add .875 to divisor
1468c2ecf20Sopenharmony_ci * Bits 15 to 0 of the 17-bit divisor are placed in the urb value.  Bit 16 is
1478c2ecf20Sopenharmony_ci * placed in bit 0 of the urb index.
1488c2ecf20Sopenharmony_ci *
1498c2ecf20Sopenharmony_ci * Note that there are a couple of special cases to support the highest baud
1508c2ecf20Sopenharmony_ci * rates.  If the calculated divisor value is 1, this needs to be replaced with
1518c2ecf20Sopenharmony_ci * 0.  Additionally for the FT232BM, if the calculated divisor value is 0x4001
1528c2ecf20Sopenharmony_ci * (1.5), this needs to be replaced with 0x0001 (1) (but this divisor value is
1538c2ecf20Sopenharmony_ci * not supported by the FT8U232AM).
1548c2ecf20Sopenharmony_ci */
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cienum ftdi_chip_type {
1578c2ecf20Sopenharmony_ci	SIO = 1,
1588c2ecf20Sopenharmony_ci	FT8U232AM = 2,
1598c2ecf20Sopenharmony_ci	FT232BM = 3,
1608c2ecf20Sopenharmony_ci	FT2232C = 4,
1618c2ecf20Sopenharmony_ci	FT232RL = 5,
1628c2ecf20Sopenharmony_ci	FT2232H = 6,
1638c2ecf20Sopenharmony_ci	FT4232H = 7,
1648c2ecf20Sopenharmony_ci	FT232H  = 8,
1658c2ecf20Sopenharmony_ci	FTX     = 9,
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cienum ftdi_sio_baudrate {
1698c2ecf20Sopenharmony_ci	ftdi_sio_b300 = 0,
1708c2ecf20Sopenharmony_ci	ftdi_sio_b600 = 1,
1718c2ecf20Sopenharmony_ci	ftdi_sio_b1200 = 2,
1728c2ecf20Sopenharmony_ci	ftdi_sio_b2400 = 3,
1738c2ecf20Sopenharmony_ci	ftdi_sio_b4800 = 4,
1748c2ecf20Sopenharmony_ci	ftdi_sio_b9600 = 5,
1758c2ecf20Sopenharmony_ci	ftdi_sio_b19200 = 6,
1768c2ecf20Sopenharmony_ci	ftdi_sio_b38400 = 7,
1778c2ecf20Sopenharmony_ci	ftdi_sio_b57600 = 8,
1788c2ecf20Sopenharmony_ci	ftdi_sio_b115200 = 9
1798c2ecf20Sopenharmony_ci};
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/*
1828c2ecf20Sopenharmony_ci * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor
1838c2ecf20Sopenharmony_ci * values are calculated internally.
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_REQUEST	FTDI_SIO_SET_DATA
1868c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_REQUEST_TYPE	0x40
1878c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_NONE	(0x0 << 8)
1888c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_ODD	(0x1 << 8)
1898c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_EVEN	(0x2 << 8)
1908c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_MARK	(0x3 << 8)
1918c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_PARITY_SPACE	(0x4 << 8)
1928c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_1	(0x0 << 11)
1938c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_15	(0x1 << 11)
1948c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DATA_STOP_BITS_2	(0x2 << 11)
1958c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BREAK		(0x1 << 14)
1968c2ecf20Sopenharmony_ci/* FTDI_SIO_SET_DATA */
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/*
1998c2ecf20Sopenharmony_ci * BmRequestType:  0100 0000B
2008c2ecf20Sopenharmony_ci * bRequest:       FTDI_SIO_SET_DATA
2018c2ecf20Sopenharmony_ci * wValue:         Data characteristics (see below)
2028c2ecf20Sopenharmony_ci * wIndex:         Port
2038c2ecf20Sopenharmony_ci * wLength:        0
2048c2ecf20Sopenharmony_ci * Data:           No
2058c2ecf20Sopenharmony_ci *
2068c2ecf20Sopenharmony_ci * Data characteristics
2078c2ecf20Sopenharmony_ci *
2088c2ecf20Sopenharmony_ci *   B0..7   Number of data bits
2098c2ecf20Sopenharmony_ci *   B8..10  Parity
2108c2ecf20Sopenharmony_ci *           0 = None
2118c2ecf20Sopenharmony_ci *           1 = Odd
2128c2ecf20Sopenharmony_ci *           2 = Even
2138c2ecf20Sopenharmony_ci *           3 = Mark
2148c2ecf20Sopenharmony_ci *           4 = Space
2158c2ecf20Sopenharmony_ci *   B11..13 Stop Bits
2168c2ecf20Sopenharmony_ci *           0 = 1
2178c2ecf20Sopenharmony_ci *           1 = 1.5
2188c2ecf20Sopenharmony_ci *           2 = 2
2198c2ecf20Sopenharmony_ci *   B14
2208c2ecf20Sopenharmony_ci *           1 = TX ON (break)
2218c2ecf20Sopenharmony_ci *           0 = TX OFF (normal state)
2228c2ecf20Sopenharmony_ci *   B15 Reserved
2238c2ecf20Sopenharmony_ci *
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* FTDI_SIO_MODEM_CTRL */
2298c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40
2308c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/*
2338c2ecf20Sopenharmony_ci * BmRequestType:   0100 0000B
2348c2ecf20Sopenharmony_ci * bRequest:        FTDI_SIO_MODEM_CTRL
2358c2ecf20Sopenharmony_ci * wValue:          ControlValue (see below)
2368c2ecf20Sopenharmony_ci * wIndex:          Port
2378c2ecf20Sopenharmony_ci * wLength:         0
2388c2ecf20Sopenharmony_ci * Data:            None
2398c2ecf20Sopenharmony_ci *
2408c2ecf20Sopenharmony_ci * NOTE: If the device is in RTS/CTS flow control, the RTS set by this
2418c2ecf20Sopenharmony_ci * command will be IGNORED without an error being returned
2428c2ecf20Sopenharmony_ci * Also - you can not set DTR and RTS with one control message
2438c2ecf20Sopenharmony_ci */
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DTR_MASK 0x1
2468c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DTR_HIGH ((FTDI_SIO_SET_DTR_MASK  << 8) | 1)
2478c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_DTR_LOW  ((FTDI_SIO_SET_DTR_MASK  << 8) | 0)
2488c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_RTS_MASK 0x2
2498c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_RTS_HIGH ((FTDI_SIO_SET_RTS_MASK << 8) | 2)
2508c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_RTS_LOW  ((FTDI_SIO_SET_RTS_MASK << 8) | 0)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/*
2538c2ecf20Sopenharmony_ci * ControlValue
2548c2ecf20Sopenharmony_ci * B0    DTR state
2558c2ecf20Sopenharmony_ci *          0 = reset
2568c2ecf20Sopenharmony_ci *          1 = set
2578c2ecf20Sopenharmony_ci * B1    RTS state
2588c2ecf20Sopenharmony_ci *          0 = reset
2598c2ecf20Sopenharmony_ci *          1 = set
2608c2ecf20Sopenharmony_ci * B2..7 Reserved
2618c2ecf20Sopenharmony_ci * B8    DTR state enable
2628c2ecf20Sopenharmony_ci *          0 = ignore
2638c2ecf20Sopenharmony_ci *          1 = use DTR state
2648c2ecf20Sopenharmony_ci * B9    RTS state enable
2658c2ecf20Sopenharmony_ci *          0 = ignore
2668c2ecf20Sopenharmony_ci *          1 = use RTS state
2678c2ecf20Sopenharmony_ci * B10..15 Reserved
2688c2ecf20Sopenharmony_ci */
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci/* FTDI_SIO_SET_FLOW_CTRL */
2718c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40
2728c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL
2738c2ecf20Sopenharmony_ci#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
2748c2ecf20Sopenharmony_ci#define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
2758c2ecf20Sopenharmony_ci#define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
2768c2ecf20Sopenharmony_ci#define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
2778c2ecf20Sopenharmony_ci/*
2788c2ecf20Sopenharmony_ci *   BmRequestType:  0100 0000b
2798c2ecf20Sopenharmony_ci *   bRequest:       FTDI_SIO_SET_FLOW_CTRL
2808c2ecf20Sopenharmony_ci *   wValue:         Xoff/Xon
2818c2ecf20Sopenharmony_ci *   wIndex:         Protocol/Port - hIndex is protocol / lIndex is port
2828c2ecf20Sopenharmony_ci *   wLength:        0
2838c2ecf20Sopenharmony_ci *   Data:           None
2848c2ecf20Sopenharmony_ci *
2858c2ecf20Sopenharmony_ci * hIndex protocol is:
2868c2ecf20Sopenharmony_ci *   B0 Output handshaking using RTS/CTS
2878c2ecf20Sopenharmony_ci *       0 = disabled
2888c2ecf20Sopenharmony_ci *       1 = enabled
2898c2ecf20Sopenharmony_ci *   B1 Output handshaking using DTR/DSR
2908c2ecf20Sopenharmony_ci *       0 = disabled
2918c2ecf20Sopenharmony_ci *       1 = enabled
2928c2ecf20Sopenharmony_ci *   B2 Xon/Xoff handshaking
2938c2ecf20Sopenharmony_ci *       0 = disabled
2948c2ecf20Sopenharmony_ci *       1 = enabled
2958c2ecf20Sopenharmony_ci *
2968c2ecf20Sopenharmony_ci * A value of zero in the hIndex field disables handshaking
2978c2ecf20Sopenharmony_ci *
2988c2ecf20Sopenharmony_ci * If Xon/Xoff handshaking is specified, the hValue field should contain the
2998c2ecf20Sopenharmony_ci * XOFF character and the lValue field contains the XON character.
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci/*
3038c2ecf20Sopenharmony_ci * FTDI_SIO_GET_LATENCY_TIMER
3048c2ecf20Sopenharmony_ci *
3058c2ecf20Sopenharmony_ci * Set the timeout interval. The FTDI collects data from the
3068c2ecf20Sopenharmony_ci * device, transmitting it to the host when either A) 62 bytes are
3078c2ecf20Sopenharmony_ci * received, or B) the timeout interval has elapsed and the buffer
3088c2ecf20Sopenharmony_ci * contains at least 1 byte.  Setting this value to a small number
3098c2ecf20Sopenharmony_ci * can dramatically improve performance for applications which send
3108c2ecf20Sopenharmony_ci * small packets, since the default value is 16ms.
3118c2ecf20Sopenharmony_ci */
3128c2ecf20Sopenharmony_ci#define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER
3138c2ecf20Sopenharmony_ci#define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/*
3168c2ecf20Sopenharmony_ci *  BmRequestType:   1100 0000b
3178c2ecf20Sopenharmony_ci *  bRequest:        FTDI_SIO_GET_LATENCY_TIMER
3188c2ecf20Sopenharmony_ci *  wValue:          0
3198c2ecf20Sopenharmony_ci *  wIndex:          Port
3208c2ecf20Sopenharmony_ci *  wLength:         0
3218c2ecf20Sopenharmony_ci *  Data:            latency (on return)
3228c2ecf20Sopenharmony_ci */
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci/*
3258c2ecf20Sopenharmony_ci * FTDI_SIO_SET_LATENCY_TIMER
3268c2ecf20Sopenharmony_ci *
3278c2ecf20Sopenharmony_ci * Set the timeout interval. The FTDI collects data from the
3288c2ecf20Sopenharmony_ci * device, transmitting it to the host when either A) 62 bytes are
3298c2ecf20Sopenharmony_ci * received, or B) the timeout interval has elapsed and the buffer
3308c2ecf20Sopenharmony_ci * contains at least 1 byte.  Setting this value to a small number
3318c2ecf20Sopenharmony_ci * can dramatically improve performance for applications which send
3328c2ecf20Sopenharmony_ci * small packets, since the default value is 16ms.
3338c2ecf20Sopenharmony_ci */
3348c2ecf20Sopenharmony_ci#define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER
3358c2ecf20Sopenharmony_ci#define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/*
3388c2ecf20Sopenharmony_ci *  BmRequestType:   0100 0000b
3398c2ecf20Sopenharmony_ci *  bRequest:        FTDI_SIO_SET_LATENCY_TIMER
3408c2ecf20Sopenharmony_ci *  wValue:          Latency (milliseconds)
3418c2ecf20Sopenharmony_ci *  wIndex:          Port
3428c2ecf20Sopenharmony_ci *  wLength:         0
3438c2ecf20Sopenharmony_ci *  Data:            None
3448c2ecf20Sopenharmony_ci *
3458c2ecf20Sopenharmony_ci * wValue:
3468c2ecf20Sopenharmony_ci *   B0..7   Latency timer
3478c2ecf20Sopenharmony_ci *   B8..15  0
3488c2ecf20Sopenharmony_ci *
3498c2ecf20Sopenharmony_ci */
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/*
3528c2ecf20Sopenharmony_ci * FTDI_SIO_SET_EVENT_CHAR
3538c2ecf20Sopenharmony_ci *
3548c2ecf20Sopenharmony_ci * Set the special event character for the specified communications port.
3558c2ecf20Sopenharmony_ci * If the device sees this character it will immediately return the
3568c2ecf20Sopenharmony_ci * data read so far - rather than wait 40ms or until 62 bytes are read
3578c2ecf20Sopenharmony_ci * which is what normally happens.
3588c2ecf20Sopenharmony_ci */
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci#define  FTDI_SIO_SET_EVENT_CHAR_REQUEST FTDI_SIO_SET_EVENT_CHAR
3628c2ecf20Sopenharmony_ci#define  FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci/*
3668c2ecf20Sopenharmony_ci *  BmRequestType:   0100 0000b
3678c2ecf20Sopenharmony_ci *  bRequest:        FTDI_SIO_SET_EVENT_CHAR
3688c2ecf20Sopenharmony_ci *  wValue:          EventChar
3698c2ecf20Sopenharmony_ci *  wIndex:          Port
3708c2ecf20Sopenharmony_ci *  wLength:         0
3718c2ecf20Sopenharmony_ci *  Data:            None
3728c2ecf20Sopenharmony_ci *
3738c2ecf20Sopenharmony_ci * wValue:
3748c2ecf20Sopenharmony_ci *   B0..7   Event Character
3758c2ecf20Sopenharmony_ci *   B8      Event Character Processing
3768c2ecf20Sopenharmony_ci *             0 = disabled
3778c2ecf20Sopenharmony_ci *             1 = enabled
3788c2ecf20Sopenharmony_ci *   B9..15  Reserved
3798c2ecf20Sopenharmony_ci *
3808c2ecf20Sopenharmony_ci */
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci/* FTDI_SIO_SET_ERROR_CHAR */
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci/*
3858c2ecf20Sopenharmony_ci * Set the parity error replacement character for the specified communications
3868c2ecf20Sopenharmony_ci * port
3878c2ecf20Sopenharmony_ci */
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/*
3908c2ecf20Sopenharmony_ci *  BmRequestType:  0100 0000b
3918c2ecf20Sopenharmony_ci *  bRequest:       FTDI_SIO_SET_EVENT_CHAR
3928c2ecf20Sopenharmony_ci *  wValue:         Error Char
3938c2ecf20Sopenharmony_ci *  wIndex:         Port
3948c2ecf20Sopenharmony_ci *  wLength:        0
3958c2ecf20Sopenharmony_ci *  Data:           None
3968c2ecf20Sopenharmony_ci *
3978c2ecf20Sopenharmony_ci *Error Char
3988c2ecf20Sopenharmony_ci *  B0..7  Error Character
3998c2ecf20Sopenharmony_ci *  B8     Error Character Processing
4008c2ecf20Sopenharmony_ci *           0 = disabled
4018c2ecf20Sopenharmony_ci *           1 = enabled
4028c2ecf20Sopenharmony_ci *  B9..15 Reserved
4038c2ecf20Sopenharmony_ci *
4048c2ecf20Sopenharmony_ci */
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/* FTDI_SIO_GET_MODEM_STATUS */
4078c2ecf20Sopenharmony_ci/* Retrieve the current value of the modem status register */
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE 0xc0
4108c2ecf20Sopenharmony_ci#define FTDI_SIO_GET_MODEM_STATUS_REQUEST FTDI_SIO_GET_MODEM_STATUS
4118c2ecf20Sopenharmony_ci#define FTDI_SIO_CTS_MASK 0x10
4128c2ecf20Sopenharmony_ci#define FTDI_SIO_DSR_MASK 0x20
4138c2ecf20Sopenharmony_ci#define FTDI_SIO_RI_MASK  0x40
4148c2ecf20Sopenharmony_ci#define FTDI_SIO_RLSD_MASK 0x80
4158c2ecf20Sopenharmony_ci/*
4168c2ecf20Sopenharmony_ci *   BmRequestType:   1100 0000b
4178c2ecf20Sopenharmony_ci *   bRequest:        FTDI_SIO_GET_MODEM_STATUS
4188c2ecf20Sopenharmony_ci *   wValue:          zero
4198c2ecf20Sopenharmony_ci *   wIndex:          Port
4208c2ecf20Sopenharmony_ci *   wLength:         1
4218c2ecf20Sopenharmony_ci *   Data:            Status
4228c2ecf20Sopenharmony_ci *
4238c2ecf20Sopenharmony_ci * One byte of data is returned
4248c2ecf20Sopenharmony_ci * B0..3 0
4258c2ecf20Sopenharmony_ci * B4    CTS
4268c2ecf20Sopenharmony_ci *         0 = inactive
4278c2ecf20Sopenharmony_ci *         1 = active
4288c2ecf20Sopenharmony_ci * B5    DSR
4298c2ecf20Sopenharmony_ci *         0 = inactive
4308c2ecf20Sopenharmony_ci *         1 = active
4318c2ecf20Sopenharmony_ci * B6    Ring Indicator (RI)
4328c2ecf20Sopenharmony_ci *         0 = inactive
4338c2ecf20Sopenharmony_ci *         1 = active
4348c2ecf20Sopenharmony_ci * B7    Receive Line Signal Detect (RLSD)
4358c2ecf20Sopenharmony_ci *         0 = inactive
4368c2ecf20Sopenharmony_ci *         1 = active
4378c2ecf20Sopenharmony_ci */
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci/* FTDI_SIO_SET_BITMODE */
4408c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BITMODE_REQUEST_TYPE 0x40
4418c2ecf20Sopenharmony_ci#define FTDI_SIO_SET_BITMODE_REQUEST FTDI_SIO_SET_BITMODE
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci/* Possible bitmodes for FTDI_SIO_SET_BITMODE_REQUEST */
4448c2ecf20Sopenharmony_ci#define FTDI_SIO_BITMODE_RESET		0x00
4458c2ecf20Sopenharmony_ci#define FTDI_SIO_BITMODE_CBUS		0x20
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/* FTDI_SIO_READ_PINS */
4488c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_PINS_REQUEST_TYPE 0xc0
4498c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_PINS_REQUEST FTDI_SIO_READ_PINS
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci/*
4528c2ecf20Sopenharmony_ci * FTDI_SIO_READ_EEPROM
4538c2ecf20Sopenharmony_ci *
4548c2ecf20Sopenharmony_ci * EEPROM format found in FTDI AN_201, "FT-X MTP memory Configuration",
4558c2ecf20Sopenharmony_ci * http://www.ftdichip.com/Support/Documents/AppNotes/AN_201_FT-X%20MTP%20Memory%20Configuration.pdf
4568c2ecf20Sopenharmony_ci */
4578c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0
4588c2ecf20Sopenharmony_ci#define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci#define FTDI_FTX_CBUS_MUX_GPIO		0x8
4618c2ecf20Sopenharmony_ci#define FTDI_FT232R_CBUS_MUX_GPIO	0xa
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci/* Descriptors returned by the device
4658c2ecf20Sopenharmony_ci *
4668c2ecf20Sopenharmony_ci *  Device Descriptor
4678c2ecf20Sopenharmony_ci *
4688c2ecf20Sopenharmony_ci * Offset	Field		Size	Value	Description
4698c2ecf20Sopenharmony_ci * 0	bLength		1	0x12	Size of descriptor in bytes
4708c2ecf20Sopenharmony_ci * 1	bDescriptorType	1	0x01	DEVICE Descriptor Type
4718c2ecf20Sopenharmony_ci * 2	bcdUSB		2	0x0110	USB Spec Release Number
4728c2ecf20Sopenharmony_ci * 4	bDeviceClass	1	0x00	Class Code
4738c2ecf20Sopenharmony_ci * 5	bDeviceSubClass	1	0x00	SubClass Code
4748c2ecf20Sopenharmony_ci * 6	bDeviceProtocol	1	0x00	Protocol Code
4758c2ecf20Sopenharmony_ci * 7	bMaxPacketSize0 1	0x08	Maximum packet size for endpoint 0
4768c2ecf20Sopenharmony_ci * 8	idVendor	2	0x0403	Vendor ID
4778c2ecf20Sopenharmony_ci * 10	idProduct	2	0x8372	Product ID (FTDI_SIO_PID)
4788c2ecf20Sopenharmony_ci * 12	bcdDevice	2	0x0001	Device release number
4798c2ecf20Sopenharmony_ci * 14	iManufacturer	1	0x01	Index of man. string desc
4808c2ecf20Sopenharmony_ci * 15	iProduct	1	0x02	Index of prod string desc
4818c2ecf20Sopenharmony_ci * 16	iSerialNumber	1	0x02	Index of serial nmr string desc
4828c2ecf20Sopenharmony_ci * 17	bNumConfigurations 1    0x01	Number of possible configurations
4838c2ecf20Sopenharmony_ci *
4848c2ecf20Sopenharmony_ci * Configuration Descriptor
4858c2ecf20Sopenharmony_ci *
4868c2ecf20Sopenharmony_ci * Offset	Field			Size	Value
4878c2ecf20Sopenharmony_ci * 0	bLength			1	0x09	Size of descriptor in bytes
4888c2ecf20Sopenharmony_ci * 1	bDescriptorType		1	0x02	CONFIGURATION Descriptor Type
4898c2ecf20Sopenharmony_ci * 2	wTotalLength		2	0x0020	Total length of data
4908c2ecf20Sopenharmony_ci * 4	bNumInterfaces		1	0x01	Number of interfaces supported
4918c2ecf20Sopenharmony_ci * 5	bConfigurationValue	1	0x01	Argument for SetCOnfiguration() req
4928c2ecf20Sopenharmony_ci * 6	iConfiguration		1	0x02	Index of config string descriptor
4938c2ecf20Sopenharmony_ci * 7	bmAttributes		1	0x20	Config characteristics Remote Wakeup
4948c2ecf20Sopenharmony_ci * 8	MaxPower		1	0x1E	Max power consumption
4958c2ecf20Sopenharmony_ci *
4968c2ecf20Sopenharmony_ci * Interface Descriptor
4978c2ecf20Sopenharmony_ci *
4988c2ecf20Sopenharmony_ci * Offset	Field			Size	Value
4998c2ecf20Sopenharmony_ci * 0	bLength			1	0x09	Size of descriptor in bytes
5008c2ecf20Sopenharmony_ci * 1	bDescriptorType		1	0x04	INTERFACE Descriptor Type
5018c2ecf20Sopenharmony_ci * 2	bInterfaceNumber	1	0x00	Number of interface
5028c2ecf20Sopenharmony_ci * 3	bAlternateSetting	1	0x00	Value used to select alternate
5038c2ecf20Sopenharmony_ci * 4	bNumEndpoints		1	0x02	Number of endpoints
5048c2ecf20Sopenharmony_ci * 5	bInterfaceClass		1	0xFF	Class Code
5058c2ecf20Sopenharmony_ci * 6	bInterfaceSubClass	1	0xFF	Subclass Code
5068c2ecf20Sopenharmony_ci * 7	bInterfaceProtocol	1	0xFF	Protocol Code
5078c2ecf20Sopenharmony_ci * 8	iInterface		1	0x02	Index of interface string description
5088c2ecf20Sopenharmony_ci *
5098c2ecf20Sopenharmony_ci * IN Endpoint Descriptor
5108c2ecf20Sopenharmony_ci *
5118c2ecf20Sopenharmony_ci * Offset	Field			Size	Value
5128c2ecf20Sopenharmony_ci * 0	bLength			1	0x07	Size of descriptor in bytes
5138c2ecf20Sopenharmony_ci * 1	bDescriptorType		1	0x05	ENDPOINT descriptor type
5148c2ecf20Sopenharmony_ci * 2	bEndpointAddress	1	0x82	Address of endpoint
5158c2ecf20Sopenharmony_ci * 3	bmAttributes		1	0x02	Endpoint attributes - Bulk
5168c2ecf20Sopenharmony_ci * 4	bNumEndpoints		2	0x0040	maximum packet size
5178c2ecf20Sopenharmony_ci * 5	bInterval		1	0x00	Interval for polling endpoint
5188c2ecf20Sopenharmony_ci *
5198c2ecf20Sopenharmony_ci * OUT Endpoint Descriptor
5208c2ecf20Sopenharmony_ci *
5218c2ecf20Sopenharmony_ci * Offset	Field			Size	Value
5228c2ecf20Sopenharmony_ci * 0	bLength			1	0x07	Size of descriptor in bytes
5238c2ecf20Sopenharmony_ci * 1	bDescriptorType		1	0x05	ENDPOINT descriptor type
5248c2ecf20Sopenharmony_ci * 2	bEndpointAddress	1	0x02	Address of endpoint
5258c2ecf20Sopenharmony_ci * 3	bmAttributes		1	0x02	Endpoint attributes - Bulk
5268c2ecf20Sopenharmony_ci * 4	bNumEndpoints		2	0x0040	maximum packet size
5278c2ecf20Sopenharmony_ci * 5	bInterval		1	0x00	Interval for polling endpoint
5288c2ecf20Sopenharmony_ci *
5298c2ecf20Sopenharmony_ci * DATA FORMAT
5308c2ecf20Sopenharmony_ci *
5318c2ecf20Sopenharmony_ci * IN Endpoint
5328c2ecf20Sopenharmony_ci *
5338c2ecf20Sopenharmony_ci * The device reserves the first two bytes of data on this endpoint to contain
5348c2ecf20Sopenharmony_ci * the current values of the modem and line status registers. In the absence of
5358c2ecf20Sopenharmony_ci * data, the device generates a message consisting of these two status bytes
5368c2ecf20Sopenharmony_ci * every 40 ms
5378c2ecf20Sopenharmony_ci *
5388c2ecf20Sopenharmony_ci * Byte 0: Modem Status
5398c2ecf20Sopenharmony_ci *
5408c2ecf20Sopenharmony_ci * Offset	Description
5418c2ecf20Sopenharmony_ci * B0	Reserved - must be 1
5428c2ecf20Sopenharmony_ci * B1	Reserved - must be 0
5438c2ecf20Sopenharmony_ci * B2	Reserved - must be 0
5448c2ecf20Sopenharmony_ci * B3	Reserved - must be 0
5458c2ecf20Sopenharmony_ci * B4	Clear to Send (CTS)
5468c2ecf20Sopenharmony_ci * B5	Data Set Ready (DSR)
5478c2ecf20Sopenharmony_ci * B6	Ring Indicator (RI)
5488c2ecf20Sopenharmony_ci * B7	Receive Line Signal Detect (RLSD)
5498c2ecf20Sopenharmony_ci *
5508c2ecf20Sopenharmony_ci * Byte 1: Line Status
5518c2ecf20Sopenharmony_ci *
5528c2ecf20Sopenharmony_ci * Offset	Description
5538c2ecf20Sopenharmony_ci * B0	Data Ready (DR)
5548c2ecf20Sopenharmony_ci * B1	Overrun Error (OE)
5558c2ecf20Sopenharmony_ci * B2	Parity Error (PE)
5568c2ecf20Sopenharmony_ci * B3	Framing Error (FE)
5578c2ecf20Sopenharmony_ci * B4	Break Interrupt (BI)
5588c2ecf20Sopenharmony_ci * B5	Transmitter Holding Register (THRE)
5598c2ecf20Sopenharmony_ci * B6	Transmitter Empty (TEMT)
5608c2ecf20Sopenharmony_ci * B7	Error in RCVR FIFO
5618c2ecf20Sopenharmony_ci *
5628c2ecf20Sopenharmony_ci */
5638c2ecf20Sopenharmony_ci#define FTDI_RS0_CTS	(1 << 4)
5648c2ecf20Sopenharmony_ci#define FTDI_RS0_DSR	(1 << 5)
5658c2ecf20Sopenharmony_ci#define FTDI_RS0_RI	(1 << 6)
5668c2ecf20Sopenharmony_ci#define FTDI_RS0_RLSD	(1 << 7)
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci#define FTDI_RS_DR	1
5698c2ecf20Sopenharmony_ci#define FTDI_RS_OE	(1<<1)
5708c2ecf20Sopenharmony_ci#define FTDI_RS_PE	(1<<2)
5718c2ecf20Sopenharmony_ci#define FTDI_RS_FE	(1<<3)
5728c2ecf20Sopenharmony_ci#define FTDI_RS_BI	(1<<4)
5738c2ecf20Sopenharmony_ci#define FTDI_RS_THRE	(1<<5)
5748c2ecf20Sopenharmony_ci#define FTDI_RS_TEMT	(1<<6)
5758c2ecf20Sopenharmony_ci#define FTDI_RS_FIFO	(1<<7)
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci/*
5788c2ecf20Sopenharmony_ci * OUT Endpoint
5798c2ecf20Sopenharmony_ci *
5808c2ecf20Sopenharmony_ci * This device reserves the first bytes of data on this endpoint contain the
5818c2ecf20Sopenharmony_ci * length and port identifier of the message. For the FTDI USB Serial converter
5828c2ecf20Sopenharmony_ci * the port identifier is always 1.
5838c2ecf20Sopenharmony_ci *
5848c2ecf20Sopenharmony_ci * Byte 0: Line Status
5858c2ecf20Sopenharmony_ci *
5868c2ecf20Sopenharmony_ci * Offset	Description
5878c2ecf20Sopenharmony_ci * B0	Reserved - must be 1
5888c2ecf20Sopenharmony_ci * B1	Reserved - must be 0
5898c2ecf20Sopenharmony_ci * B2..7	Length of message - (not including Byte 0)
5908c2ecf20Sopenharmony_ci *
5918c2ecf20Sopenharmony_ci */
592