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