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