]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/serial/uftdi_reg.h
Merge r262907 from ^/projects/release-embedded:
[FreeBSD/FreeBSD.git] / sys / dev / usb / serial / uftdi_reg.h
1 /*      $NetBSD: uftdireg.h,v 1.6 2002/07/11 21:14:28 augustss Exp $ */
2 /*      $FreeBSD$       */
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 /* Vendor Request Interface */
21 #define FTDI_SIO_RESET          0       /* Reset the port */
22 #define FTDI_SIO_MODEM_CTRL     1       /* Set the modem control register */
23 #define FTDI_SIO_SET_FLOW_CTRL  2       /* Set flow control register */
24 #define FTDI_SIO_SET_BAUD_RATE  3       /* Set baud rate */
25 #define FTDI_SIO_SET_DATA       4       /* Set the data characteristics of the
26                                          * port */
27 #define FTDI_SIO_GET_STATUS     5       /* Retrieve current value of status
28                                          * reg */
29 #define FTDI_SIO_SET_EVENT_CHAR 6       /* Set the event character */
30 #define FTDI_SIO_SET_ERROR_CHAR 7       /* Set the error character */
31
32 /* Port Identifier Table */
33 #define FTDI_PIT_DEFAULT        0       /* SIOA */
34 #define FTDI_PIT_SIOA           1       /* SIOA */
35 #define FTDI_PIT_SIOB           2       /* SIOB */
36 #define FTDI_PIT_PARALLEL       3       /* Parallel */
37
38 /* Values for driver_info */
39 #define UFTDI_TYPE_MASK         0x000000ff
40 #define UFTDI_TYPE_SIO          0x00000001
41 #define UFTDI_TYPE_8U232AM      0x00000002
42 #define UFTDI_TYPE_AUTO         (UFTDI_TYPE_SIO | UFTDI_TYPE_8U232AM)
43 #define UFTDI_FLAG_MASK         0x0000ff00
44 #define UFTDI_FLAG_JTAG         0x00000100
45
46 /*
47  * BmRequestType:  0100 0000B
48  * bRequest:       FTDI_SIO_RESET
49  * wValue:         Control Value
50  *                   0 = Reset SIO
51  *                   1 = Purge RX buffer
52  *                   2 = Purge TX buffer
53  * wIndex:         Port
54  * wLength:        0
55  * Data:           None
56  *
57  * The Reset SIO command has this effect:
58  *
59  *    Sets flow control set to 'none'
60  *    Event char = 0x0d
61  *    Event trigger = disabled
62  *    Purge RX buffer
63  *    Purge TX buffer
64  *    Clear DTR
65  *    Clear RTS
66  *    baud and data format not reset
67  *
68  * The Purge RX and TX buffer commands affect nothing except the buffers
69  */
70 /* FTDI_SIO_RESET */
71 #define FTDI_SIO_RESET_SIO 0
72 #define FTDI_SIO_RESET_PURGE_RX 1
73 #define FTDI_SIO_RESET_PURGE_TX 2
74
75 /*
76  * BmRequestType:  0100 0000B
77  * bRequest:       FTDI_SIO_SET_BAUDRATE
78  * wValue:         BaudRate low bits
79  * wIndex:         Port and BaudRate high bits 
80  * wLength:        0
81  * Data:           None
82  */
83 /* FTDI_SIO_SET_BAUDRATE */
84
85 /*
86  * BmRequestType:  0100 0000B
87  * bRequest:       FTDI_SIO_SET_DATA
88  * wValue:         Data characteristics (see below)
89  * wIndex:         Port
90  * wLength:        0
91  * Data:           No
92  *
93  * Data characteristics
94  *
95  *   B0..7   Number of data bits
96  *   B8..10  Parity
97  *           0 = None
98  *           1 = Odd
99  *           2 = Even
100  *           3 = Mark
101  *           4 = Space
102  *   B11..13 Stop Bits
103  *           0 = 1
104  *           1 = 1.5
105  *           2 = 2
106  *   B14..15 Reserved
107  *
108  */
109 /* FTDI_SIO_SET_DATA */
110 #define FTDI_SIO_SET_DATA_BITS(n) (n)
111 #define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
112 #define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
113 #define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
114 #define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
115 #define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
116 #define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
117 #define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
118 #define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
119 #define FTDI_SIO_SET_BREAK (0x1 << 14)
120
121 /*
122  * BmRequestType:   0100 0000B
123  * bRequest:        FTDI_SIO_MODEM_CTRL
124  * wValue:          ControlValue (see below)
125  * wIndex:          Port
126  * wLength:         0
127  * Data:            None
128  *
129  * NOTE: If the device is in RTS/CTS flow control, the RTS set by this
130  * command will be IGNORED without an error being returned
131  * Also - you can not set DTR and RTS with one control message
132  *
133  * ControlValue
134  * B0    DTR state
135  *          0 = reset
136  *          1 = set
137  * B1    RTS state
138  *          0 = reset
139  *          1 = set
140  * B2..7 Reserved
141  * B8    DTR state enable
142  *          0 = ignore
143  *          1 = use DTR state
144  * B9    RTS state enable
145  *          0 = ignore
146  *          1 = use RTS state
147  * B10..15 Reserved
148  */
149 /* FTDI_SIO_MODEM_CTRL */
150 #define FTDI_SIO_SET_DTR_MASK 0x1
151 #define FTDI_SIO_SET_DTR_HIGH (1 | ( FTDI_SIO_SET_DTR_MASK  << 8))
152 #define FTDI_SIO_SET_DTR_LOW  (0 | ( FTDI_SIO_SET_DTR_MASK  << 8))
153 #define FTDI_SIO_SET_RTS_MASK 0x2
154 #define FTDI_SIO_SET_RTS_HIGH (2 | ( FTDI_SIO_SET_RTS_MASK << 8))
155 #define FTDI_SIO_SET_RTS_LOW (0 | ( FTDI_SIO_SET_RTS_MASK << 8))
156
157 /*
158  *   BmRequestType:  0100 0000b
159  *   bRequest:       FTDI_SIO_SET_FLOW_CTRL
160  *   wValue:         Xoff/Xon
161  *   wIndex:         Protocol/Port - hIndex is protocol / lIndex is port
162  *   wLength:        0
163  *   Data:           None
164  *
165  * hIndex protocol is:
166  *   B0 Output handshaking using RTS/CTS
167  *       0 = disabled
168  *       1 = enabled
169  *   B1 Output handshaking using DTR/DSR
170  *       0 = disabled
171  *       1 = enabled
172  *   B2 Xon/Xoff handshaking
173  *       0 = disabled
174  *       1 = enabled
175  *
176  * A value of zero in the hIndex field disables handshaking
177  *
178  * If Xon/Xoff handshaking is specified, the hValue field should contain the
179  * XOFF character and the lValue field contains the XON character.
180  */
181 /* FTDI_SIO_SET_FLOW_CTRL */
182 #define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
183 #define FTDI_SIO_RTS_CTS_HS 0x1
184 #define FTDI_SIO_DTR_DSR_HS 0x2
185 #define FTDI_SIO_XON_XOFF_HS 0x4
186
187 /*
188  *  BmRequestType:   0100 0000b
189  *  bRequest:        FTDI_SIO_SET_EVENT_CHAR
190  *  wValue:          Event Char
191  *  wIndex:          Port
192  *  wLength:         0
193  *  Data:            None
194  *
195  * wValue:
196  *   B0..7   Event Character
197  *   B8      Event Character Processing
198  *             0 = disabled
199  *             1 = enabled
200  *   B9..15  Reserved
201  *
202  * FTDI_SIO_SET_EVENT_CHAR
203  *
204  * Set the special event character for the specified communications port.
205  * If the device sees this character it will immediately return the
206  * data read so far - rather than wait 40ms or until 62 bytes are read
207  * which is what normally happens.
208  */
209
210 /*
211  *  BmRequestType:  0100 0000b
212  *  bRequest:       FTDI_SIO_SET_ERROR_CHAR
213  *  wValue:         Error Char
214  *  wIndex:         Port
215  *  wLength:        0
216  *  Data:           None
217  *
218  *  Error Char
219  *  B0..7  Error Character
220  *  B8     Error Character Processing
221  *           0 = disabled
222  *           1 = enabled
223  *  B9..15 Reserved
224  * FTDI_SIO_SET_ERROR_CHAR
225  * Set the parity error replacement character for the specified communications
226  * port.
227  */
228
229 /*
230  *   BmRequestType:   1100 0000b
231  *   bRequest:        FTDI_SIO_GET_MODEM_STATUS
232  *   wValue:          zero
233  *   wIndex:          Port
234  *   wLength:         1
235  *   Data:            Status
236  *
237  * One byte of data is returned
238  * B0..3 0
239  * B4    CTS
240  *         0 = inactive
241  *         1 = active
242  * B5    DSR
243  *         0 = inactive
244  *         1 = active
245  * B6    Ring Indicator (RI)
246  *         0 = inactive
247  *         1 = active
248  * B7    Receive Line Signal Detect (RLSD)
249  *         0 = inactive
250  *         1 = active
251  *
252  * FTDI_SIO_GET_MODEM_STATUS
253  * Retrieve the current value of the modem status register.
254  */
255 #define FTDI_SIO_CTS_MASK 0x10
256 #define FTDI_SIO_DSR_MASK 0x20
257 #define FTDI_SIO_RI_MASK  0x40
258 #define FTDI_SIO_RLSD_MASK 0x80
259
260 /*
261  * DATA FORMAT
262  *
263  * IN Endpoint
264  *
265  * The device reserves the first two bytes of data on this endpoint to contain
266  * the current values of the modem and line status registers. In the absence of
267  * data, the device generates a message consisting of these two status bytes
268  * every 40 ms.
269  *
270  * Byte 0: Modem Status
271  *   NOTE: 4 upper bits have same layout as the MSR register in a 16550
272  *
273  * Offset       Description
274  * B0..3        Port
275  * B4           Clear to Send (CTS)
276  * B5           Data Set Ready (DSR)
277  * B6           Ring Indicator (RI)
278  * B7           Receive Line Signal Detect (RLSD)
279  *
280  * Byte 1: Line Status
281  *   NOTE: same layout as the LSR register in a 16550
282  *
283  * Offset       Description
284  * B0   Data Ready (DR)
285  * B1   Overrun Error (OE)
286  * B2   Parity Error (PE)
287  * B3   Framing Error (FE)
288  * B4   Break Interrupt (BI)
289  * B5   Transmitter Holding Register (THRE)
290  * B6   Transmitter Empty (TEMT)
291  * B7   Error in RCVR FIFO
292  * OUT Endpoint
293  *
294  * This device reserves the first bytes of data on this endpoint contain the
295  * length and port identifier of the message. For the FTDI USB Serial converter
296  * the port identifier is always 1.
297  *
298  * Byte 0: Port & length
299  *
300  * Offset       Description
301  * B0..1        Port
302  * B2..7        Length of message - (not including Byte 0)
303  */
304 #define FTDI_PORT_MASK 0x0f
305 #define FTDI_MSR_MASK 0xf0
306 #define FTDI_GET_MSR(p) (((p)[0]) & FTDI_MSR_MASK)
307 #define FTDI_GET_LSR(p) ((p)[1])
308 #define FTDI_LSR_MASK (~0x60)           /* interesting bits */
309 #define FTDI_OUT_TAG(len, port) (((len) << 2) | (port))