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