1c138f478Syz /*
2c138f478Syz  * CDDL HEADER START
3c138f478Syz  *
4c138f478Syz  * The contents of this file are subject to the terms of the
5e4de76aaSyz  * Common Development and Distribution License (the "License").
6e4de76aaSyz  * You may not use this file except in compliance with the License.
7c138f478Syz  *
8c138f478Syz  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c138f478Syz  * or http://www.opensolaris.org/os/licensing.
10c138f478Syz  * See the License for the specific language governing permissions
11c138f478Syz  * and limitations under the License.
12c138f478Syz  *
13c138f478Syz  * When distributing Covered Code, include this CDDL HEADER in each
14c138f478Syz  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c138f478Syz  * If applicable, add the following below this CDDL HEADER, with the
16c138f478Syz  * fields enclosed by brackets "[]" replaced with your own identifying
17c138f478Syz  * information: Portions Copyright [yyyy] [name of copyright owner]
18c138f478Syz  *
19c138f478Syz  * CDDL HEADER END
20c138f478Syz  */
21c138f478Syz 
22c138f478Syz /*
23*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24c138f478Syz  * Use is subject to license terms.
25c138f478Syz  */
26c138f478Syz 
27c138f478Syz 
28c138f478Syz #ifndef _SYS_USB_USBSER_KEYSPAN_USA49MSG_H
29c138f478Syz #define	_SYS_USB_USBSER_KEYSPAN_USA49MSG_H
30c138f478Syz 
31c138f478Syz typedef struct keyspan_usa49_port_ctrl_msg keyspan_usa49_port_ctrl_msg_t;
32c138f478Syz typedef struct keyspan_usa49_port_status_msg keyspan_usa49_port_status_msg_t;
33c138f478Syz 
34c138f478Syz /*
35c138f478Syz  * usa49msg.h
36c138f478Syz  *
37c138f478Syz  * Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
38c138f478Syz  *
39c138f478Syz  * Keyspan USB Async Message Formats for the USA49W
40c138f478Syz  *
41c138f478Syz  *
42c138f478Syz  * Buffer formats for RX/TX data messages are not defined by
43c138f478Syz  * a structure, but are described here:
44c138f478Syz  *
45c138f478Syz  * USB OUT (host -> USAxx, transmit) messages contain a
46c138f478Syz  * REQUEST_ACK indicator (set to 0xff to request an ACK at the
47c138f478Syz  * completion of transmit; 0x00 otherwise), followed by data:
48c138f478Syz  *
49c138f478Syz  *	RQSTACK DAT DAT DAT ...
50c138f478Syz  *
51c138f478Syz  * with a total data length of 63.
52c138f478Syz  *
53c138f478Syz  * USB IN (USAxx -> host, receive) messages begin with a status
54c138f478Syz  * byte in which the 0x80 bit is either:
55c138f478Syz  *
56c138f478Syz  * (a)	0x80 bit clear
57c138f478Syz  *		indicates that the bytes following it are all data
58c138f478Syz  *		bytes:
59c138f478Syz  *
60c138f478Syz  *			STAT DATA DATA DATA DATA DATA ...
61c138f478Syz  *
62c138f478Syz  *		for a total of up to 63 DATA bytes,
63c138f478Syz  *
64c138f478Syz  * or:
65c138f478Syz  *
66c138f478Syz  *	(b)	0x80 bit set
67c138f478Syz  *		indiates that the bytes following alternate data and
68c138f478Syz  *		status bytes:
69c138f478Syz  *
70c138f478Syz  *			STAT DATA STAT DATA STAT DATA STAT DATA ...
71c138f478Syz  *
72c138f478Syz  *		for a total of up to 32 DATA bytes.
73c138f478Syz  *
74c138f478Syz  * The valid bits in the STAT bytes are:
75c138f478Syz  *
76c138f478Syz  *	OVERRUN	0x02
77c138f478Syz  *	PARITY	0x04
78c138f478Syz  *	FRAMING	0x08
79c138f478Syz  *	BREAK	0x10
80c138f478Syz  *
81c138f478Syz  * Notes:
82c138f478Syz  *
83c138f478Syz  * (1) The OVERRUN bit can appear in either (a) or (b) format
84c138f478Syz  *	messages, but the but the PARITY/FRAMING/BREAK bits
85c138f478Syz  *	only appear in (b) format messages.
86c138f478Syz  * (2) For the host to determine the exact point at which the
87c138f478Syz  *	overrun occurred (to identify the point in the data
88c138f478Syz  *	stream at which the data was lost), it needs to count
89c138f478Syz  *	128 characters, starting at the first character of the
90c138f478Syz  *	message in which OVERRUN was reported; the lost character(s)
91c138f478Syz  *	would have been received between the 128th and 129th
92c138f478Syz  *	characters.
93c138f478Syz  * (3)	An RX data message in which the first byte has 0x80 clear
94c138f478Syz  *	serves as a "break off" indicator.
95c138f478Syz  * (4)	a control message specifying disablePort will be answered
96c138f478Syz  *	with a status message, but no further status will be sent
97c138f478Syz  *	until a control messages with enablePort is sent
98c138f478Syz  *
99c138f478Syz  */
100c138f478Syz 
101c138f478Syz /*
102c138f478Syz  * Host->device messages sent on the global control endpoint:
103c138f478Syz  *
104c138f478Syz  * portNumber	message
105c138f478Syz  * ----------	--------------------
106c138f478Syz  * 0,1,2,3	portControlMessage
107c138f478Syz  * 0x80		globalControlMessage
108c138f478Syz  */
109c138f478Syz 
110c138f478Syz struct keyspan_usa49_port_ctrl_msg {
111c138f478Syz 	/*
112c138f478Syz 	 * 0.	0/1/2/3 	port control message follows
113c138f478Syz 	 * 0x80 set	non-port control message follows
114c138f478Syz 	 */
115c138f478Syz 	uint8_t portNumber;
116c138f478Syz 
117c138f478Syz 	/*
118c138f478Syz 	 * there are three types of "commands" sent in the control message:
119c138f478Syz 	 *
120c138f478Syz 	 * 1. configuration changes which must be requested by setting
121c138f478Syz 	 * the corresponding "set" flag (and should only be requested
122c138f478Syz 	 * when necessary, to reduce overhead on the USA26):
123c138f478Syz 	 */
124c138f478Syz 	uint8_t setClocking;	/* host requests baud rate be set */
125c138f478Syz 	uint8_t baudLo;		/* host does baud divisor calculation */
126c138f478Syz 
127c138f478Syz 	/* baudHi is only used for first port (gives lower rates) */
128c138f478Syz 	uint8_t baudHi;
129c138f478Syz 	uint8_t prescaler;	/* specified as N/8; values 8-ff are valid */
130c138f478Syz 	/* must be set any time internal baud rate is set; */
131c138f478Syz 	uint8_t txClocking;	/* 0=internal, 1=external/DSR */
132c138f478Syz 	uint8_t rxClocking;	/* 0=internal, 1=external/DSR */
133c138f478Syz 
134c138f478Syz 	uint8_t setLcr;		/* host requests lcr be set */
135c138f478Syz 	uint8_t lcr;		/* use PARITY, STOPBITS, DATABITS below */
136c138f478Syz 
137c138f478Syz 	uint8_t setFlowControl;	/* host requests flow control be set */
138c138f478Syz 	uint8_t ctsFlowControl;	/* 1=use CTS flow control, 0=don't */
139c138f478Syz 	uint8_t xonFlowControl;	/* 1=use XON/XOFF flow control, 0=don't */
140c138f478Syz 	uint8_t xonChar;	/* specified in current character format */
141c138f478Syz 	uint8_t xoffChar;	/* specified in current character format */
142c138f478Syz 
143c138f478Syz 	uint8_t setRts;		/* host requests RTS output be set */
144c138f478Syz 	uint8_t rts;		/* 1=active, 0=inactive */
145c138f478Syz 
146c138f478Syz 	uint8_t setDtr;		/* host requests DTR output be set */
147c138f478Syz 	uint8_t dtr;		/* 1=on, 0=off */
148c138f478Syz 
149c138f478Syz 	/*
150c138f478Syz 	 * 3. configuration data which is simply used as is (no overhead,
151c138f478Syz 	 * but must be specified correctly in every host message).
152c138f478Syz 	 */
153c138f478Syz 
154c138f478Syz 	/* forward when this number of chars available */
155c138f478Syz 	uint8_t forwardingLength;
156c138f478Syz 	uint8_t dsrFlowControl;	/* 1=use DSR flow control, 0=don't */
157c138f478Syz 
158c138f478Syz 	/* 0=not allowed, 1=normal, 2-255 deliver ACK faster */
159c138f478Syz 	uint8_t txAckThreshold;
160c138f478Syz 	uint8_t loopbackMode;	/* 0=no loopback, 1=loopback enabled */
161c138f478Syz 
162c138f478Syz 	/*
163c138f478Syz 	 * 4.	commands which are flags only; these are processed in order
164c138f478Syz 	 * (so that, e.g., if both _txOn and _txOff flags are set, the
165c138f478Syz 	 * port ends in a TX_OFF state); any non-zero value is respected
166c138f478Syz 	 */
167c138f478Syz 
168c138f478Syz 	/* enable transmitting (and continue if there's data) */
169c138f478Syz 	uint8_t _txOn;
170c138f478Syz 	uint8_t _txOff;		/* stop transmitting */
171c138f478Syz 	uint8_t txFlush;	/* toss outbound data */
172c138f478Syz 	uint8_t txBreak;	/* turn on break (cleared by _txOn) */
173c138f478Syz 	uint8_t rxOn;		/* turn on receiver */
174c138f478Syz 	uint8_t rxOff;		/* turn off receiver */
175c138f478Syz 	uint8_t rxFlush;	/* toss inbound data */
176c138f478Syz 
177c138f478Syz 	/* forward all inbound data, NOW (as if fwdLen==1) */
178c138f478Syz 	uint8_t rxForward;
179c138f478Syz 
180c138f478Syz 	/* return current status (even if it hasn't changed) */
181c138f478Syz 	uint8_t returnStatus;
182c138f478Syz 	uint8_t resetDataToggle;	/* reset data toggle state to DATA0 */
183c138f478Syz 
184c138f478Syz 	/* start servicing port (move data, check status) */
185c138f478Syz 	uint8_t enablePort;
186c138f478Syz 
187c138f478Syz 	/* stop servicing port (does implicit tx/rx flush/off) */
188c138f478Syz 	uint8_t disablePort;
189c138f478Syz 
190c138f478Syz };
191c138f478Syz 
192c138f478Syz /* defines for bits in lcr */
193c138f478Syz #define	USA_DATABITS_5		0x00
194c138f478Syz #define	USA_DATABITS_6		0x01
195c138f478Syz #define	USA_DATABITS_7		0x02
196c138f478Syz #define	USA_DATABITS_8		0x03
197c138f478Syz #define	STOPBITS_5678_1		0x00	/* 1 stop bit for all byte sizes */
198c138f478Syz #define	STOPBITS_5_1p5		0x04	/* 1.5 stop bits for 5-bit byte */
199c138f478Syz #define	STOPBITS_678_2		0x04	/* 2 stop bits for 6/7/8-bit byte */
200c138f478Syz #define	USA_PARITY_NONE		0x00
201c138f478Syz #define	USA_PARITY_ODD		0x08
202c138f478Syz #define	USA_PARITY_EVEN		0x18
203c138f478Syz #define	PARITY_1			0x28
204c138f478Syz #define	PARITY_0			0x38
205c138f478Syz 
206c138f478Syz /*
207c138f478Syz  * during normal operation, status messages are returned
208c138f478Syz  * to the host whenever the board detects changes.  In some
209c138f478Syz  * circumstances (e.g. Windows), status messages from the
210c138f478Syz  * device cause problems; to shut them off, the host issues
211c138f478Syz  * a control message with the disableStatusMessages flags
212c138f478Syz  * set (to any non-zero value).  The device will respond to
213c138f478Syz  * this message, and then suppress further status messages;
214c138f478Syz  * it will resume sending status messages any time the host
215c138f478Syz  * sends any control message (either global or port-specific).
216c138f478Syz  */
217c138f478Syz 
218c138f478Syz struct keyspan_usa49_globalControlMessage {
219c138f478Syz 	uint8_t portNumber;	/* 0x80 */
220c138f478Syz 
221c138f478Syz 	/* 1/2=number of status responses requested */
222c138f478Syz 	uint8_t sendGlobalStatus;
223c138f478Syz 	uint8_t resetStatusToggle;	/* 1=reset global status toggle */
224c138f478Syz 	uint8_t resetStatusCount;	/* a cycling value */
225c138f478Syz 	uint8_t remoteWakeupEnable;	/* 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4 */
226c138f478Syz 	uint8_t disableStatusMessages;	/* 1=send no status until host talks */
227c138f478Syz };
228c138f478Syz 
229c138f478Syz /*
230c138f478Syz  * Device->host messages send on the global status endpoint
231c138f478Syz  *
232c138f478Syz  * portNumber			message
233c138f478Syz  * ----------			--------------------
234c138f478Syz  * 0x00,0x01,0x02,0x03		portStatusMessage
235c138f478Syz  * 0x80				globalStatusMessage
236c138f478Syz  * 0x81				globalDebugMessage
237c138f478Syz  */
238c138f478Syz 
239c138f478Syz struct keyspan_usa49_port_status_msg {	/* one for each port */
240c138f478Syz 	uint8_t portNumber;	/* 0,1,2,3 */
241c138f478Syz 	uint8_t cts;		/* reports CTS pin */
242c138f478Syz 	uint8_t dcd;		/* reports DCD pin */
243c138f478Syz 	uint8_t dsr;		/* reports DSR pin */
244c138f478Syz 	uint8_t ri;		/* reports RI pin */
245c138f478Syz 	uint8_t _txOff;		/* transmit has been disabled (by host) */
246c138f478Syz 
247c138f478Syz 	/* transmit is in XOFF state (either host or RX XOFF) */
248c138f478Syz 	uint8_t _txXoff;
249c138f478Syz 	uint8_t rxEnabled;	/* as configured by rxOn/rxOff 1=on, 0=off */
250c138f478Syz 
251c138f478Syz 	/* 1=a control message has been processed */
252c138f478Syz 	uint8_t controlResponse;
253c138f478Syz 	uint8_t txAck;		/* ACK (data TX complete) */
254c138f478Syz 	uint8_t rs232valid;	/* RS-232 signal valid */
255c138f478Syz };
256c138f478Syz 
257c138f478Syz /* bits in RX data message when STAT byte is included */
258c138f478Syz #define	RXERROR_OVERRUN	0x02
259c138f478Syz #define	RXERROR_PARITY	0x04
260c138f478Syz #define	RXERROR_FRAMING	0x08
261c138f478Syz #define	RXERROR_BREAK	0x10
262c138f478Syz 
263c138f478Syz struct keyspan_usa49_globalStatusMessage {
264c138f478Syz 	uint8_t portNumber;	/* 0x80=globalStatusMessage */
265c138f478Syz 	uint8_t sendGlobalStatus;	/* from request, decremented */
266c138f478Syz 	uint8_t resetStatusCount;	/* as in request */
267c138f478Syz };
268c138f478Syz 
269c138f478Syz struct keyspan_usa49_globalDebugMessage {
270c138f478Syz 	uint8_t portNumber;	/* 0x81=globalDebugMessage */
271c138f478Syz 	uint8_t n;		/* typically a count/status byte */
272c138f478Syz 	uint8_t b;		/* typically a data byte */
273c138f478Syz };
274c138f478Syz 
275c138f478Syz /* ie: the maximum length of an EZUSB endpoint buffer */
276c138f478Syz #define	MAX_DATA_LEN			64
277c138f478Syz 
278c138f478Syz /* update status approx. 60 times a second (16.6666 ms) */
279c138f478Syz #define	STATUS_UPDATE_INTERVAL	16
280c138f478Syz 
281c138f478Syz /* status rationing tuning value (each port gets checked each n ms) */
282c138f478Syz #define	STATUS_RATION	10
283c138f478Syz 
284c138f478Syz #endif /* _SYS_USB_USBSER_KEYSPAN_USA49MSG_H */
285