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