xref: /haiku/src/add-ons/kernel/drivers/ports/usb_serial/FTDIRegs.h (revision 8195a5a835117ab2da405e0d477153570b75d921)
1 /*	$NetBSD: uftdireg.h,v 1.6 2002/07/11 21:14:28 augustss Exp $ */
2 /*	$FreeBSD: src/sys/dev/usb/uftdireg.h,v 1.1 2002/08/11 23:32:33 joe Exp $	*/
3 
4 /*
5  * Definitions for the FTDI USB Single Port Serial Converter -
6  * known as FTDI_SIO (Serial Input/Output application of the chipset)
7  *
8  * The device is based on the FTDI FT8U100AX chip. It has a DB25 on one side,
9  * USB on the other.
10  *
11  * Thanx to FTDI (http://www.ftdi.co.uk) for so kindly providing details
12  * of the protocol required to talk to the device and ongoing assistence
13  * during development.
14  *
15  * Bill Ryder - bryder@sgi.com of Silicon Graphics, Inc. is the original
16  * author of this file.
17  */
18 /* Modified by Lennart Augustsson */
19 
20 /*
21  * Added to BeOS USB Serial Driver project by Siarzhuk Zharski
22  *
23  * $Source: /cvsroot/sis4be/usb_serial/uftdireg.h,v $
24  * $Author: zharik $
25  * $Revision: 1.1 $
26  * $Date: 2003/05/29 18:55:43 $
27  *
28  */
29 
30 /* Vendor Request Interface */
31 #define FTDI_SIO_RESET			0 /* Reset the port */
32 #define FTDI_SIO_MODEM_CTRL		1 /* Set the modem control register */
33 #define FTDI_SIO_SET_FLOW_CTRL	2 /* Set flow control register */
34 #define FTDI_SIO_SET_BAUD_RATE	3 /* Set baud rate */
35 #define FTDI_SIO_SET_DATA		4 /* Set the data characteristics of the port */
36 #define FTDI_SIO_GET_STATUS		5 /* Retrieve current value of status reg */
37 #define FTDI_SIO_SET_EVENT_CHAR	6 /* Set the event character */
38 #define FTDI_SIO_SET_ERROR_CHAR	7 /* Set the error character */
39 
40 /* Port Identifier Table */
41 #define FTDI_PIT_DEFAULT	0 /* SIOA */
42 #define FTDI_PIT_SIOA		1 /* SIOA */
43 #define FTDI_PIT_SIOB		2 /* SIOB */
44 #define FTDI_PIT_PARALLEL	3 /* Parallel */
45 
46 enum uftdi_type {
47 	UFTDI_TYPE_SIO,
48 	UFTDI_TYPE_8U232AM
49 };
50 
51 /*
52  * BmRequestType:  0100 0000B
53  * bRequest:       FTDI_SIO_RESET
54  * wValue:         Control Value
55  *                   0 = Reset SIO
56  *                   1 = Purge RX buffer
57  *                   2 = Purge TX buffer
58  * wIndex:         Port
59  * wLength:        0
60  * Data:           None
61  *
62  * The Reset SIO command has this effect:
63  *
64  *    Sets flow control set to 'none'
65  *    Event char = 0x0d
66  *    Event trigger = disabled
67  *    Purge RX buffer
68  *    Purge TX buffer
69  *    Clear DTR
70  *    Clear RTS
71  *    baud and data format not reset
72  *
73  * The Purge RX and TX buffer commands affect nothing except the buffers
74  *
75  */
76 /* FTDI_SIO_RESET */
77 #define FTDI_SIO_RESET_SIO		0
78 #define FTDI_SIO_RESET_PURGE_RX	1
79 #define FTDI_SIO_RESET_PURGE_TX	2
80 
81 
82 /*
83  * BmRequestType:  0100 0000B
84  * bRequest:       FTDI_SIO_SET_BAUDRATE
85  * wValue:         BaudRate value - see below
86  * wIndex:         Port
87  * wLength:        0
88  * Data:           None
89  */
90 /* FTDI_SIO_SET_BAUDRATE */
91 enum {
92 	ftdi_sio_b300 = 0,
93 	ftdi_sio_b600 = 1,
94 	ftdi_sio_b1200 = 2,
95 	ftdi_sio_b2400 = 3,
96 	ftdi_sio_b4800 = 4,
97 	ftdi_sio_b9600 = 5,
98 	ftdi_sio_b19200 = 6,
99 	ftdi_sio_b38400 = 7,
100 	ftdi_sio_b57600 = 8,
101 	ftdi_sio_b115200 = 9
102 };
103 
104 enum {
105 	ftdi_8u232am_b300 = 0x2710,
106 	ftdi_8u232am_b600 = 0x1388,
107 	ftdi_8u232am_b1200 = 0x09c4,
108 	ftdi_8u232am_b2400 = 0x04e2,
109 	ftdi_8u232am_b4800 = 0x0271,
110 	ftdi_8u232am_b9600 = 0x4138,
111 	ftdi_8u232am_b19200 = 0x809c,
112 	ftdi_8u232am_b38400 = 0xc04e,
113 	ftdi_8u232am_b57600 = 0x0034,
114 	ftdi_8u232am_b115200 = 0x001a,
115 	ftdi_8u232am_b230400 = 0x000d,
116 	ftdi_8u232am_b460800 = 0x4006,
117 	ftdi_8u232am_b921600 = 0x8003
118 };
119 
120 /*
121  * BmRequestType:  0100 0000B
122  * bRequest:       FTDI_SIO_SET_DATA
123  * wValue:         Data characteristics (see below)
124  * wIndex:         Port
125  * wLength:        0
126  * Data:           No
127  *
128  * Data characteristics
129  *
130  *   B0..7   Number of data bits
131  *   B8..10  Parity
132  *           0 = None
133  *           1 = Odd
134  *           2 = Even
135  *           3 = Mark
136  *           4 = Space
137  *   B11..13 Stop Bits
138  *           0 = 1
139  *           1 = 1.5
140  *           2 = 2
141  *   B14..15 Reserved
142  *
143  */
144 /* FTDI_SIO_SET_DATA */
145 #define FTDI_SIO_SET_DATA_BITS(n)		(n)
146 #define FTDI_SIO_SET_DATA_PARITY_NONE	(0x0 << 8)
147 #define FTDI_SIO_SET_DATA_PARITY_ODD	(0x1 << 8)
148 #define FTDI_SIO_SET_DATA_PARITY_EVEN	(0x2 << 8)
149 #define FTDI_SIO_SET_DATA_PARITY_MARK	(0x3 << 8)
150 #define FTDI_SIO_SET_DATA_PARITY_SPACE	(0x4 << 8)
151 #define FTDI_SIO_SET_DATA_STOP_BITS_1	(0x0 << 11)
152 #define FTDI_SIO_SET_DATA_STOP_BITS_15	(0x1 << 11)
153 #define FTDI_SIO_SET_DATA_STOP_BITS_2	(0x2 << 11)
154 #define FTDI_SIO_SET_BREAK				(0x1 << 14)
155 
156 
157 /*
158  * BmRequestType:   0100 0000B
159  * bRequest:        FTDI_SIO_MODEM_CTRL
160  * wValue:          ControlValue (see below)
161  * wIndex:          Port
162  * wLength:         0
163  * Data:            None
164  *
165  * NOTE: If the device is in RTS/CTS flow control, the RTS set by this
166  * command will be IGNORED without an error being returned
167  * Also - you can not set DTR and RTS with one control message
168  *
169  * ControlValue
170  * B0    DTR state
171  *          0 = reset
172  *          1 = set
173  * B1    RTS state
174  *          0 = reset
175  *          1 = set
176  * B2..7 Reserved
177  * B8    DTR state enable
178  *          0 = ignore
179  *          1 = use DTR state
180  * B9    RTS state enable
181  *          0 = ignore
182  *          1 = use RTS state
183  * B10..15 Reserved
184  */
185 /* FTDI_SIO_MODEM_CTRL */
186 #define FTDI_SIO_SET_DTR_MASK	0x1
187 #define FTDI_SIO_SET_DTR_HIGH	(1 | ( FTDI_SIO_SET_DTR_MASK  << 8))
188 #define FTDI_SIO_SET_DTR_LOW	(0 | ( FTDI_SIO_SET_DTR_MASK  << 8))
189 #define FTDI_SIO_SET_RTS_MASK	0x2
190 #define FTDI_SIO_SET_RTS_HIGH	(2 | ( FTDI_SIO_SET_RTS_MASK << 8))
191 #define FTDI_SIO_SET_RTS_LOW	(0 | ( FTDI_SIO_SET_RTS_MASK << 8))
192 
193 
194 /*
195  *   BmRequestType:  0100 0000b
196  *   bRequest:       FTDI_SIO_SET_FLOW_CTRL
197  *   wValue:         Xoff/Xon
198  *   wIndex:         Protocol/Port - hIndex is protocl / lIndex is port
199  *   wLength:        0
200  *   Data:           None
201  *
202  * hIndex protocol is:
203  *   B0 Output handshaking using RTS/CTS
204  *       0 = disabled
205  *       1 = enabled
206  *   B1 Output handshaking using DTR/DSR
207  *       0 = disabled
208  *       1 = enabled
209  *   B2 Xon/Xoff handshaking
210  *       0 = disabled
211  *       1 = enabled
212  *
213  * A value of zero in the hIndex field disables handshaking
214  *
215  * If Xon/Xoff handshaking is specified, the hValue field should contain the
216  * XOFF character and the lValue field contains the XON character.
217  */
218 /* FTDI_SIO_SET_FLOW_CTRL */
219 #define FTDI_SIO_DISABLE_FLOW_CTRL	0x0
220 #define FTDI_SIO_RTS_CTS_HS			0x1
221 #define FTDI_SIO_DTR_DSR_HS			0x2
222 #define FTDI_SIO_XON_XOFF_HS		0x4
223 
224 
225 /*
226  *  BmRequestType:   0100 0000b
227  *  bRequest:        FTDI_SIO_SET_EVENT_CHAR
228  *  wValue:          Event Char
229  *  wIndex:          Port
230  *  wLength:         0
231  *  Data:            None
232  *
233  * wValue:
234  *   B0..7   Event Character
235  *   B8      Event Character Processing
236  *             0 = disabled
237  *             1 = enabled
238  *   B9..15  Reserved
239  *
240  * FTDI_SIO_SET_EVENT_CHAR
241  *
242  * Set the special event character for the specified communications port.
243  * If the device sees this character it will immediately return the
244  * data read so far - rather than wait 40ms or until 62 bytes are read
245  * which is what normally happens.
246  */
247 
248 
249 
250 /*
251  *  BmRequestType:  0100 0000b
252  *  bRequest:       FTDI_SIO_SET_ERROR_CHAR
253  *  wValue:         Error Char
254  *  wIndex:         Port
255  *  wLength:        0
256  *  Data:           None
257  *
258  *  Error Char
259  *  B0..7  Error Character
260  *  B8     Error Character Processing
261  *           0 = disabled
262  *           1 = enabled
263  *  B9..15 Reserved
264  *
265  *
266  * FTDI_SIO_SET_ERROR_CHAR
267  * Set the parity error replacement character for the specified communications
268  * port.
269  */
270 
271 
272 /*
273  *   BmRequestType:   1100 0000b
274  *   bRequest:        FTDI_SIO_GET_MODEM_STATUS
275  *   wValue:          zero
276  *   wIndex:          Port
277  *   wLength:         1
278  *   Data:            Status
279  *
280  * One byte of data is returned
281  * B0..3 0
282  * B4    CTS
283  *         0 = inactive
284  *         1 = active
285  * B5    DSR
286  *         0 = inactive
287  *         1 = active
288  * B6    Ring Indicator (RI)
289  *         0 = inactive
290  *         1 = active
291  * B7    Receive Line Signal Detect (RLSD)
292  *         0 = inactive
293  *         1 = active
294  *
295  * FTDI_SIO_GET_MODEM_STATUS
296  * Retrieve the current value of the modem status register.
297  */
298 #define FTDI_SIO_CTS_MASK	0x10
299 #define FTDI_SIO_DSR_MASK	0x20
300 #define FTDI_SIO_RI_MASK	0x40
301 #define FTDI_SIO_RLSD_MASK	0x80
302 
303 
304 
305 /*
306  *
307  * DATA FORMAT
308  *
309  * IN Endpoint
310  *
311  * The device reserves the first two bytes of data on this endpoint to contain
312  * the current values of the modem and line status registers. In the absence of
313  * data, the device generates a message consisting of these two status bytes
314  * every 40 ms.
315  *
316  * Byte 0: Modem Status
317  *   NOTE: 4 upper bits have same layout as the MSR register in a 16550
318  *
319  * Offset	Description
320  * B0..3	Port
321  * B4		Clear to Send (CTS)
322  * B5		Data Set Ready (DSR)
323  * B6		Ring Indicator (RI)
324  * B7		Receive Line Signal Detect (RLSD)
325  *
326  * Byte 1: Line Status
327  *   NOTE: same layout as the LSR register in a 16550
328  *
329  * Offset	Description
330  * B0	Data Ready (DR)
331  * B1	Overrun Error (OE)
332  * B2	Parity Error (PE)
333  * B3	Framing Error (FE)
334  * B4	Break Interrupt (BI)
335  * B5	Transmitter Holding Register (THRE)
336  * B6	Transmitter Empty (TEMT)
337  * B7	Error in RCVR FIFO
338  *
339  *
340  * OUT Endpoint
341  *
342  * This device reserves the first bytes of data on this endpoint contain the
343  * length and port identifier of the message. For the FTDI USB Serial converter
344  * the port identifier is always 1.
345  *
346  * Byte 0: Port & length
347  *
348  * Offset	Description
349  * B0..1	Port
350  * B2..7	Length of message - (not including Byte 0)
351  *
352  */
353 #define FTDI_PORT_MASK			0x0f
354 #define FTDI_MSR_MASK			0xf0
355 #define FTDI_GET_MSR(p)			(((p)[0]) & FTDI_MSR_MASK)
356 #define FTDI_GET_LSR(p)			((p)[1])
357 #define FTDI_LSR_MASK			(~0x60) /* interesting bits */
358 #define FTDI_OUT_TAG(len, port)	(((len) << 2) | (port))
359