| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Andreas Mohr | 31844d5 | 2009-12-16 21:45:10 +0100 | [diff] [blame] | 2 |  * Driver definitions for the FTDI USB Single Port Serial Converter - | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 3 |  * known as FTDI_SIO (Serial Input/Output application of the chipset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * | 
| Andreas Mohr | 31844d5 | 2009-12-16 21:45:10 +0100 | [diff] [blame] | 5 |  * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h | 
 | 6 |  * | 
 | 7 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  * | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 13 |  * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  * USB on the other. | 
 | 15 |  * | 
| Mark Adamson | 094c2e6 | 2009-04-09 15:03:09 +0100 | [diff] [blame] | 16 |  * Thanx to FTDI (http://www.ftdichip.com) for so kindly providing details | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  * of the protocol required to talk to the device and ongoing assistence | 
 | 18 |  * during development. | 
 | 19 |  * | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 20 |  * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  * FTDI_SIO implementation. | 
 | 22 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  */ | 
 | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* Commands */ | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 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 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Andreas Mohr | 0a2a377 | 2010-01-17 11:45:47 +0100 | [diff] [blame] | 39 | /* Interface indices for FT2232, FT2232H and FT4232H devices */ | 
| Mark Adamson | 094c2e6 | 2009-04-09 15:03:09 +0100 | [diff] [blame] | 40 | #define INTERFACE_A		1 | 
 | 41 | #define INTERFACE_B		2 | 
 | 42 | #define INTERFACE_C		3 | 
 | 43 | #define INTERFACE_D		4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 |  | 
| Pawel Ludwikow | e7d7fcc | 2009-08-27 14:15:50 +0200 | [diff] [blame] | 45 |  | 
 | 46 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 57 | #define PIT_DEFAULT		0 /* SIOA */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 73 |  * wValue:         Control Value | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* | 
 | 101 |  * BmRequestType:  0100 0000B | 
 | 102 |  * bRequest:       FTDI_SIO_SET_BAUDRATE | 
 | 103 |  * wValue:         BaudDivisor value - see below | 
 | 104 |  * wIndex:         Port | 
 | 105 |  * wLength:        0 | 
 | 106 |  * Data:           None | 
 | 107 |  * The BaudDivisor values are calculated as follows: | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 108 |  * - BaseClock is either 12000000 or 48000000 depending on the device. | 
 | 109 |  *   FIXME: I wish I knew how to detect old chips to select proper base clock! | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  * - BaudDivisor is a fixed point number encoded in a funny way. | 
 | 111 |  *   (--WRONG WAY OF THINKING--) | 
 | 112 |  *   BaudDivisor is a fixed point number encoded with following bit weighs: | 
 | 113 |  *   (-2)(-1)(13..0). It is a radical with a denominator of 4, so values | 
 | 114 |  *   end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...). | 
 | 115 |  *   (--THE REALITY--) | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 116 |  *   The both-bits-set has quite different meaning from 0.75 - the chip | 
 | 117 |  *   designers have decided it to mean 0.125 instead of 0.75. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  *   This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates | 
 | 119 |  *   and Flow Control Consideration for USB to RS232". | 
 | 120 |  * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 121 |  *   automagically re-encode the resulting value to take fractions into | 
 | 122 |  *   consideration. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 |  * As all values are integers, some bit twiddling is in order: | 
 | 124 |  *   BaudDivisor = (BaseClock / 16 / BaudRate) | | 
 | 125 |  *   (((BaseClock / 2 / BaudRate) & 4) ? 0x4000    // 0.5 | 
 | 126 |  *    : ((BaseClock / 2 / BaudRate) & 2) ? 0x8000  // 0.25 | 
 | 127 |  *    : ((BaseClock / 2 / BaudRate) & 1) ? 0xc000  // 0.125 | 
 | 128 |  *    : 0) | 
 | 129 |  * | 
 | 130 |  * For the FT232BM, a 17th divisor bit was introduced to encode the multiples | 
 | 131 |  * of 0.125 missing from the FT8U232AM.  Bits 16 to 14 are coded as follows | 
 | 132 |  * (the first four codes are the same as for the FT8U232AM, where bit 16 is | 
 | 133 |  * always 0): | 
 | 134 |  *   000 - add .000 to divisor | 
 | 135 |  *   001 - add .500 to divisor | 
 | 136 |  *   010 - add .250 to divisor | 
 | 137 |  *   011 - add .125 to divisor | 
 | 138 |  *   100 - add .375 to divisor | 
 | 139 |  *   101 - add .625 to divisor | 
 | 140 |  *   110 - add .750 to divisor | 
 | 141 |  *   111 - add .875 to divisor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 142 |  * Bits 15 to 0 of the 17-bit divisor are placed in the urb value.  Bit 16 is | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  * placed in bit 0 of the urb index. | 
 | 144 |  * | 
 | 145 |  * Note that there are a couple of special cases to support the highest baud | 
 | 146 |  * rates.  If the calculated divisor value is 1, this needs to be replaced with | 
 | 147 |  * 0.  Additionally for the FT232BM, if the calculated divisor value is 0x4001 | 
 | 148 |  * (1.5), this needs to be replaced with 0x0001 (1) (but this divisor value is | 
 | 149 |  * not supported by the FT8U232AM). | 
 | 150 |  */ | 
 | 151 |  | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 152 | enum ftdi_chip_type { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | 	SIO = 1, | 
 | 154 | 	FT8U232AM = 2, | 
 | 155 | 	FT232BM = 3, | 
 | 156 | 	FT2232C = 4, | 
| Gard Spreemann | d8b2160 | 2007-03-05 00:03:26 +0100 | [diff] [blame] | 157 | 	FT232RL = 5, | 
| Mark Adamson | 094c2e6 | 2009-04-09 15:03:09 +0100 | [diff] [blame] | 158 | 	FT2232H = 6, | 
 | 159 | 	FT4232H = 7 | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 160 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 162 | enum ftdi_sio_baudrate { | 
 | 163 | 	ftdi_sio_b300 = 0, | 
 | 164 | 	ftdi_sio_b600 = 1, | 
 | 165 | 	ftdi_sio_b1200 = 2, | 
 | 166 | 	ftdi_sio_b2400 = 3, | 
 | 167 | 	ftdi_sio_b4800 = 4, | 
 | 168 | 	ftdi_sio_b9600 = 5, | 
 | 169 | 	ftdi_sio_b19200 = 6, | 
 | 170 | 	ftdi_sio_b38400 = 7, | 
 | 171 | 	ftdi_sio_b57600 = 8, | 
 | 172 | 	ftdi_sio_b115200 = 9 | 
 | 173 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 |  | 
 | 175 | /* | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 176 |  * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor | 
 | 177 |  * values are calculated internally. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 |  */ | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 179 | #define FTDI_SIO_SET_DATA_REQUEST	FTDI_SIO_SET_DATA | 
 | 180 | #define FTDI_SIO_SET_DATA_REQUEST_TYPE	0x40 | 
 | 181 | #define FTDI_SIO_SET_DATA_PARITY_NONE	(0x0 << 8) | 
 | 182 | #define FTDI_SIO_SET_DATA_PARITY_ODD	(0x1 << 8) | 
 | 183 | #define FTDI_SIO_SET_DATA_PARITY_EVEN	(0x2 << 8) | 
 | 184 | #define FTDI_SIO_SET_DATA_PARITY_MARK	(0x3 << 8) | 
 | 185 | #define FTDI_SIO_SET_DATA_PARITY_SPACE	(0x4 << 8) | 
 | 186 | #define FTDI_SIO_SET_DATA_STOP_BITS_1	(0x0 << 11) | 
 | 187 | #define FTDI_SIO_SET_DATA_STOP_BITS_15	(0x1 << 11) | 
 | 188 | #define FTDI_SIO_SET_DATA_STOP_BITS_2	(0x2 << 11) | 
 | 189 | #define FTDI_SIO_SET_BREAK		(0x1 << 14) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* FTDI_SIO_SET_DATA */ | 
 | 191 |  | 
 | 192 | /* | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 193 |  * BmRequestType:  0100 0000B | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 |  * bRequest:       FTDI_SIO_SET_DATA | 
 | 195 |  * wValue:         Data characteristics (see below) | 
 | 196 |  * wIndex:         Port | 
 | 197 |  * wLength:        0 | 
 | 198 |  * Data:           No | 
 | 199 |  * | 
 | 200 |  * Data characteristics | 
 | 201 |  * | 
 | 202 |  *   B0..7   Number of data bits | 
 | 203 |  *   B8..10  Parity | 
 | 204 |  *           0 = None | 
 | 205 |  *           1 = Odd | 
 | 206 |  *           2 = Even | 
 | 207 |  *           3 = Mark | 
 | 208 |  *           4 = Space | 
 | 209 |  *   B11..13 Stop Bits | 
 | 210 |  *           0 = 1 | 
 | 211 |  *           1 = 1.5 | 
 | 212 |  *           2 = 2 | 
 | 213 |  *   B14 | 
 | 214 |  *           1 = TX ON (break) | 
 | 215 |  *           0 = TX OFF (normal state) | 
 | 216 |  *   B15 Reserved | 
 | 217 |  * | 
 | 218 |  */ | 
 | 219 |  | 
 | 220 |  | 
 | 221 |  | 
 | 222 | /* FTDI_SIO_MODEM_CTRL */ | 
 | 223 | #define FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE 0x40 | 
 | 224 | #define FTDI_SIO_SET_MODEM_CTRL_REQUEST FTDI_SIO_MODEM_CTRL | 
 | 225 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 226 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 |  * BmRequestType:   0100 0000B | 
 | 228 |  * bRequest:        FTDI_SIO_MODEM_CTRL | 
 | 229 |  * wValue:          ControlValue (see below) | 
 | 230 |  * wIndex:          Port | 
 | 231 |  * wLength:         0 | 
 | 232 |  * Data:            None | 
 | 233 |  * | 
 | 234 |  * NOTE: If the device is in RTS/CTS flow control, the RTS set by this | 
 | 235 |  * command will be IGNORED without an error being returned | 
 | 236 |  * Also - you can not set DTR and RTS with one control message | 
 | 237 |  */ | 
 | 238 |  | 
 | 239 | #define FTDI_SIO_SET_DTR_MASK 0x1 | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 240 | #define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK  << 8)) | 
 | 241 | #define FTDI_SIO_SET_DTR_LOW  (0 | (FTDI_SIO_SET_DTR_MASK  << 8)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | #define FTDI_SIO_SET_RTS_MASK 0x2 | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 243 | #define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8)) | 
 | 244 | #define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 |  | 
 | 246 | /* | 
 | 247 |  * ControlValue | 
 | 248 |  * B0    DTR state | 
 | 249 |  *          0 = reset | 
 | 250 |  *          1 = set | 
 | 251 |  * B1    RTS state | 
 | 252 |  *          0 = reset | 
 | 253 |  *          1 = set | 
 | 254 |  * B2..7 Reserved | 
 | 255 |  * B8    DTR state enable | 
 | 256 |  *          0 = ignore | 
 | 257 |  *          1 = use DTR state | 
 | 258 |  * B9    RTS state enable | 
 | 259 |  *          0 = ignore | 
 | 260 |  *          1 = use RTS state | 
 | 261 |  * B10..15 Reserved | 
 | 262 |  */ | 
 | 263 |  | 
 | 264 | /* FTDI_SIO_SET_FLOW_CTRL */ | 
 | 265 | #define FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE 0x40 | 
 | 266 | #define FTDI_SIO_SET_FLOW_CTRL_REQUEST FTDI_SIO_SET_FLOW_CTRL | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 267 | #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | #define FTDI_SIO_RTS_CTS_HS (0x1 << 8) | 
 | 269 | #define FTDI_SIO_DTR_DSR_HS (0x2 << 8) | 
 | 270 | #define FTDI_SIO_XON_XOFF_HS (0x4 << 8) | 
 | 271 | /* | 
 | 272 |  *   BmRequestType:  0100 0000b | 
 | 273 |  *   bRequest:       FTDI_SIO_SET_FLOW_CTRL | 
 | 274 |  *   wValue:         Xoff/Xon | 
| Andreas Mohr | 0a2a377 | 2010-01-17 11:45:47 +0100 | [diff] [blame] | 275 |  *   wIndex:         Protocol/Port - hIndex is protocol / lIndex is port | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 276 |  *   wLength:        0 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 |  *   Data:           None | 
 | 278 |  * | 
 | 279 |  * hIndex protocol is: | 
 | 280 |  *   B0 Output handshaking using RTS/CTS | 
 | 281 |  *       0 = disabled | 
 | 282 |  *       1 = enabled | 
 | 283 |  *   B1 Output handshaking using DTR/DSR | 
 | 284 |  *       0 = disabled | 
 | 285 |  *       1 = enabled | 
 | 286 |  *   B2 Xon/Xoff handshaking | 
 | 287 |  *       0 = disabled | 
 | 288 |  *       1 = enabled | 
 | 289 |  * | 
 | 290 |  * A value of zero in the hIndex field disables handshaking | 
 | 291 |  * | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 292 |  * If Xon/Xoff handshaking is specified, the hValue field should contain the | 
 | 293 |  * XOFF character and the lValue field contains the XON character. | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 294 |  */ | 
 | 295 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* | 
 | 297 |  * FTDI_SIO_GET_LATENCY_TIMER | 
 | 298 |  * | 
 | 299 |  * Set the timeout interval. The FTDI collects data from the slave | 
 | 300 |  * device, transmitting it to the host when either A) 62 bytes are | 
 | 301 |  * received, or B) the timeout interval has elapsed and the buffer | 
 | 302 |  * contains at least 1 byte.  Setting this value to a small number | 
 | 303 |  * can dramatically improve performance for applications which send | 
 | 304 |  * small packets, since the default value is 16ms. | 
 | 305 |  */ | 
 | 306 | #define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST FTDI_SIO_GET_LATENCY_TIMER | 
 | 307 | #define  FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE 0xC0 | 
 | 308 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 309 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 |  *  BmRequestType:   1100 0000b | 
 | 311 |  *  bRequest:        FTDI_SIO_GET_LATENCY_TIMER | 
 | 312 |  *  wValue:          0 | 
 | 313 |  *  wIndex:          Port | 
 | 314 |  *  wLength:         0 | 
 | 315 |  *  Data:            latency (on return) | 
 | 316 |  */ | 
 | 317 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 318 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 |  * FTDI_SIO_SET_LATENCY_TIMER | 
 | 320 |  * | 
 | 321 |  * Set the timeout interval. The FTDI collects data from the slave | 
 | 322 |  * device, transmitting it to the host when either A) 62 bytes are | 
 | 323 |  * received, or B) the timeout interval has elapsed and the buffer | 
 | 324 |  * contains at least 1 byte.  Setting this value to a small number | 
 | 325 |  * can dramatically improve performance for applications which send | 
 | 326 |  * small packets, since the default value is 16ms. | 
 | 327 |  */ | 
 | 328 | #define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST FTDI_SIO_SET_LATENCY_TIMER | 
 | 329 | #define  FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE 0x40 | 
 | 330 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 331 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 |  *  BmRequestType:   0100 0000b | 
 | 333 |  *  bRequest:        FTDI_SIO_SET_LATENCY_TIMER | 
 | 334 |  *  wValue:          Latency (milliseconds) | 
 | 335 |  *  wIndex:          Port | 
 | 336 |  *  wLength:         0 | 
 | 337 |  *  Data:            None | 
 | 338 |  * | 
 | 339 |  * wValue: | 
 | 340 |  *   B0..7   Latency timer | 
 | 341 |  *   B8..15  0 | 
 | 342 |  * | 
 | 343 |  */ | 
 | 344 |  | 
 | 345 | /* | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 346 |  * FTDI_SIO_SET_EVENT_CHAR | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 |  * | 
 | 348 |  * Set the special event character for the specified communications port. | 
 | 349 |  * If the device sees this character it will immediately return the | 
 | 350 |  * data read so far - rather than wait 40ms or until 62 bytes are read | 
 | 351 |  * which is what normally happens. | 
 | 352 |  */ | 
 | 353 |  | 
 | 354 |  | 
 | 355 | #define  FTDI_SIO_SET_EVENT_CHAR_REQUEST FTDI_SIO_SET_EVENT_CHAR | 
 | 356 | #define  FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE 0x40 | 
 | 357 |  | 
 | 358 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 359 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 |  *  BmRequestType:   0100 0000b | 
 | 361 |  *  bRequest:        FTDI_SIO_SET_EVENT_CHAR | 
 | 362 |  *  wValue:          EventChar | 
 | 363 |  *  wIndex:          Port | 
 | 364 |  *  wLength:         0 | 
 | 365 |  *  Data:            None | 
 | 366 |  * | 
 | 367 |  * wValue: | 
 | 368 |  *   B0..7   Event Character | 
 | 369 |  *   B8      Event Character Processing | 
 | 370 |  *             0 = disabled | 
 | 371 |  *             1 = enabled | 
 | 372 |  *   B9..15  Reserved | 
 | 373 |  * | 
 | 374 |  */ | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 375 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* FTDI_SIO_SET_ERROR_CHAR */ | 
 | 377 |  | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 378 | /* | 
 | 379 |  * Set the parity error replacement character for the specified communications | 
 | 380 |  * port | 
 | 381 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 383 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 |  *  BmRequestType:  0100 0000b | 
 | 385 |  *  bRequest:       FTDI_SIO_SET_EVENT_CHAR | 
 | 386 |  *  wValue:         Error Char | 
 | 387 |  *  wIndex:         Port | 
 | 388 |  *  wLength:        0 | 
 | 389 |  *  Data:           None | 
 | 390 |  * | 
 | 391 |  *Error Char | 
 | 392 |  *  B0..7  Error Character | 
 | 393 |  *  B8     Error Character Processing | 
 | 394 |  *           0 = disabled | 
 | 395 |  *           1 = enabled | 
 | 396 |  *  B9..15 Reserved | 
 | 397 |  * | 
 | 398 |  */ | 
 | 399 |  | 
 | 400 | /* FTDI_SIO_GET_MODEM_STATUS */ | 
| Matt Mackall | 4a4efbd | 2006-01-03 13:27:11 +0100 | [diff] [blame] | 401 | /* Retrieve the current value of the modem status register */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 |  | 
 | 403 | #define FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE 0xc0 | 
 | 404 | #define FTDI_SIO_GET_MODEM_STATUS_REQUEST FTDI_SIO_GET_MODEM_STATUS | 
 | 405 | #define FTDI_SIO_CTS_MASK 0x10 | 
 | 406 | #define FTDI_SIO_DSR_MASK 0x20 | 
 | 407 | #define FTDI_SIO_RI_MASK  0x40 | 
 | 408 | #define FTDI_SIO_RLSD_MASK 0x80 | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 409 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 |  *   BmRequestType:   1100 0000b | 
 | 411 |  *   bRequest:        FTDI_SIO_GET_MODEM_STATUS | 
 | 412 |  *   wValue:          zero | 
 | 413 |  *   wIndex:          Port | 
 | 414 |  *   wLength:         1 | 
 | 415 |  *   Data:            Status | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 416 |  * | 
 | 417 |  * One byte of data is returned | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 |  * B0..3 0 | 
 | 419 |  * B4    CTS | 
 | 420 |  *         0 = inactive | 
 | 421 |  *         1 = active | 
 | 422 |  * B5    DSR | 
 | 423 |  *         0 = inactive | 
 | 424 |  *         1 = active | 
 | 425 |  * B6    Ring Indicator (RI) | 
 | 426 |  *         0 = inactive | 
 | 427 |  *         1 = active | 
 | 428 |  * B7    Receive Line Signal Detect (RLSD) | 
 | 429 |  *         0 = inactive | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 430 |  *         1 = active | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 |  */ | 
 | 432 |  | 
 | 433 |  | 
 | 434 |  | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 435 | /* Descriptors returned by the device | 
 | 436 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 |  *  Device Descriptor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 438 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 |  * Offset	Field		Size	Value	Description | 
 | 440 |  * 0	bLength		1	0x12	Size of descriptor in bytes | 
 | 441 |  * 1	bDescriptorType	1	0x01	DEVICE Descriptor Type | 
 | 442 |  * 2	bcdUSB		2	0x0110	USB Spec Release Number | 
 | 443 |  * 4	bDeviceClass	1	0x00	Class Code | 
 | 444 |  * 5	bDeviceSubClass	1	0x00	SubClass Code | 
 | 445 |  * 6	bDeviceProtocol	1	0x00	Protocol Code | 
 | 446 |  * 7	bMaxPacketSize0 1	0x08	Maximum packet size for endpoint 0 | 
 | 447 |  * 8	idVendor	2	0x0403	Vendor ID | 
 | 448 |  * 10	idProduct	2	0x8372	Product ID (FTDI_SIO_PID) | 
 | 449 |  * 12	bcdDevice	2	0x0001	Device release number | 
 | 450 |  * 14	iManufacturer	1	0x01	Index of man. string desc | 
 | 451 |  * 15	iProduct	1	0x02	Index of prod string desc | 
 | 452 |  * 16	iSerialNumber	1	0x02	Index of serial nmr string desc | 
 | 453 |  * 17	bNumConfigurations 1    0x01	Number of possible configurations | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 454 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 |  * Configuration Descriptor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 456 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 |  * Offset	Field			Size	Value | 
 | 458 |  * 0	bLength			1	0x09	Size of descriptor in bytes | 
 | 459 |  * 1	bDescriptorType		1	0x02	CONFIGURATION Descriptor Type | 
 | 460 |  * 2	wTotalLength		2	0x0020	Total length of data | 
 | 461 |  * 4	bNumInterfaces		1	0x01	Number of interfaces supported | 
 | 462 |  * 5	bConfigurationValue	1	0x01	Argument for SetCOnfiguration() req | 
 | 463 |  * 6	iConfiguration		1	0x02	Index of config string descriptor | 
 | 464 |  * 7	bmAttributes		1	0x20	Config characteristics Remote Wakeup | 
 | 465 |  * 8	MaxPower		1	0x1E	Max power consumption | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 466 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 |  * Interface Descriptor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 468 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 |  * Offset	Field			Size	Value | 
 | 470 |  * 0	bLength			1	0x09	Size of descriptor in bytes | 
 | 471 |  * 1	bDescriptorType		1	0x04	INTERFACE Descriptor Type | 
 | 472 |  * 2	bInterfaceNumber	1	0x00	Number of interface | 
 | 473 |  * 3	bAlternateSetting	1	0x00	Value used to select alternate | 
 | 474 |  * 4	bNumEndpoints		1	0x02	Number of endpoints | 
 | 475 |  * 5	bInterfaceClass		1	0xFF	Class Code | 
 | 476 |  * 6	bInterfaceSubClass	1	0xFF	Subclass Code | 
 | 477 |  * 7	bInterfaceProtocol	1	0xFF	Protocol Code | 
 | 478 |  * 8	iInterface		1	0x02	Index of interface string description | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 479 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 |  * IN Endpoint Descriptor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 481 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 |  * Offset	Field			Size	Value | 
 | 483 |  * 0	bLength			1	0x07	Size of descriptor in bytes | 
 | 484 |  * 1	bDescriptorType		1	0x05	ENDPOINT descriptor type | 
 | 485 |  * 2	bEndpointAddress	1	0x82	Address of endpoint | 
 | 486 |  * 3	bmAttributes		1	0x02	Endpoint attributes - Bulk | 
 | 487 |  * 4	bNumEndpoints		2	0x0040	maximum packet size | 
 | 488 |  * 5	bInterval		1	0x00	Interval for polling endpoint | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 489 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 |  * OUT Endpoint Descriptor | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 491 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 |  * Offset	Field			Size	Value | 
 | 493 |  * 0	bLength			1	0x07	Size of descriptor in bytes | 
 | 494 |  * 1	bDescriptorType		1	0x05	ENDPOINT descriptor type | 
 | 495 |  * 2	bEndpointAddress	1	0x02	Address of endpoint | 
 | 496 |  * 3	bmAttributes		1	0x02	Endpoint attributes - Bulk | 
 | 497 |  * 4	bNumEndpoints		2	0x0040	maximum packet size | 
 | 498 |  * 5	bInterval		1	0x00	Interval for polling endpoint | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 499 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 |  * DATA FORMAT | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 501 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 |  * IN Endpoint | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 503 |  * | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 504 |  * The device reserves the first two bytes of data on this endpoint to contain | 
 | 505 |  * the current values of the modem and line status registers. In the absence of | 
 | 506 |  * data, the device generates a message consisting of these two status bytes | 
 | 507 |  * every 40 ms | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 508 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 |  * Byte 0: Modem Status | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 510 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 |  * Offset	Description | 
 | 512 |  * B0	Reserved - must be 1 | 
 | 513 |  * B1	Reserved - must be 0 | 
 | 514 |  * B2	Reserved - must be 0 | 
 | 515 |  * B3	Reserved - must be 0 | 
 | 516 |  * B4	Clear to Send (CTS) | 
 | 517 |  * B5	Data Set Ready (DSR) | 
 | 518 |  * B6	Ring Indicator (RI) | 
 | 519 |  * B7	Receive Line Signal Detect (RLSD) | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 520 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 |  * Byte 1: Line Status | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 522 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 |  * Offset	Description | 
 | 524 |  * B0	Data Ready (DR) | 
 | 525 |  * B1	Overrun Error (OE) | 
 | 526 |  * B2	Parity Error (PE) | 
 | 527 |  * B3	Framing Error (FE) | 
 | 528 |  * B4	Break Interrupt (BI) | 
 | 529 |  * B5	Transmitter Holding Register (THRE) | 
 | 530 |  * B6	Transmitter Empty (TEMT) | 
 | 531 |  * B7	Error in RCVR FIFO | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 532 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 |  */ | 
 | 534 | #define FTDI_RS0_CTS	(1 << 4) | 
 | 535 | #define FTDI_RS0_DSR	(1 << 5) | 
 | 536 | #define FTDI_RS0_RI	(1 << 6) | 
 | 537 | #define FTDI_RS0_RLSD	(1 << 7) | 
 | 538 |  | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 539 | #define FTDI_RS_DR	1 | 
 | 540 | #define FTDI_RS_OE	(1<<1) | 
 | 541 | #define FTDI_RS_PE	(1<<2) | 
 | 542 | #define FTDI_RS_FE	(1<<3) | 
 | 543 | #define FTDI_RS_BI	(1<<4) | 
 | 544 | #define FTDI_RS_THRE	(1<<5) | 
 | 545 | #define FTDI_RS_TEMT	(1<<6) | 
 | 546 | #define FTDI_RS_FIFO	(1<<7) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 |  | 
 | 548 | /* | 
 | 549 |  * OUT Endpoint | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 550 |  * | 
| Greg Kroah-Hartman | 3bb36aa | 2010-05-17 10:33:41 -0700 | [diff] [blame] | 551 |  * This device reserves the first bytes of data on this endpoint contain the | 
 | 552 |  * length and port identifier of the message. For the FTDI USB Serial converter | 
 | 553 |  * the port identifier is always 1. | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 554 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 |  * Byte 0: Line Status | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 556 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 |  * Offset	Description | 
 | 558 |  * B0	Reserved - must be 1 | 
 | 559 |  * B1	Reserved - must be 0 | 
 | 560 |  * B2..7	Length of message - (not including Byte 0) | 
| Alan Cox | 464cbb2 | 2008-07-22 11:11:23 +0100 | [diff] [blame] | 561 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |  */ |