xref: /OK3568_Linux_fs/kernel/drivers/usb/serial/keyspan_usa49msg.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: BSD-3-Clause */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun 	usa49msg.h
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun 	Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
6*4882a593Smuzhiyun 	This file is available under a BSD-style copyright
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun 	Keyspan USB Async Message Formats for the USA49W
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun 	Redistribution and use in source and binary forms, with or without
11*4882a593Smuzhiyun 	modification, are permitted provided that the following conditions are
12*4882a593Smuzhiyun 	met:
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun 	1. Redistributions of source code must retain this licence text
15*4882a593Smuzhiyun    	without modification, this list of conditions, and the following
16*4882a593Smuzhiyun    	disclaimer.  The following copyright notice must appear immediately at
17*4882a593Smuzhiyun    	the beginning of all source files:
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun         	Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun         	This file is available under a BSD-style copyright
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	2. The name of InnoSys Incorporated may not be used to endorse or promote
24*4882a593Smuzhiyun    	products derived from this software without specific prior written
25*4882a593Smuzhiyun    	permission.
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 	THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR
28*4882a593Smuzhiyun 	IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29*4882a593Smuzhiyun 	OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30*4882a593Smuzhiyun 	NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31*4882a593Smuzhiyun 	INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32*4882a593Smuzhiyun 	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33*4882a593Smuzhiyun 	SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34*4882a593Smuzhiyun 	CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35*4882a593Smuzhiyun 	LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36*4882a593Smuzhiyun 	OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37*4882a593Smuzhiyun 	SUCH DAMAGE.
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	4th revision: USA49W version
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	Buffer formats for RX/TX data messages are not defined by
42*4882a593Smuzhiyun 	a structure, but are described here:
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	USB OUT (host -> USAxx, transmit) messages contain a
45*4882a593Smuzhiyun 	REQUEST_ACK indicator (set to 0xff to request an ACK at the
46*4882a593Smuzhiyun 	completion of transmit; 0x00 otherwise), followed by data:
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 		RQSTACK DAT DAT DAT ...
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	with a total data length of 63.
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	USB IN (USAxx -> host, receive) messages begin with a status
53*4882a593Smuzhiyun 	byte in which the 0x80 bit is either:
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 		(a)	0x80 bit clear
56*4882a593Smuzhiyun 			indicates that the bytes following it are all data
57*4882a593Smuzhiyun 			bytes:
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 				STAT DATA DATA DATA DATA DATA ...
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 			for a total of up to 63 DATA bytes,
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	or:
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 		(b)	0x80 bit set
66*4882a593Smuzhiyun 			indiates that the bytes following alternate data and
67*4882a593Smuzhiyun 			status bytes:
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 				STAT DATA STAT DATA STAT DATA STAT DATA ...
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 			for a total of up to 32 DATA bytes.
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	The valid bits in the STAT bytes are:
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 		OVERRUN	0x02
76*4882a593Smuzhiyun 		PARITY	0x04
77*4882a593Smuzhiyun 		FRAMING	0x08
78*4882a593Smuzhiyun 		BREAK	0x10
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	Notes:
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	(1) The OVERRUN bit can appear in either (a) or (b) format
83*4882a593Smuzhiyun 		messages, but the but the PARITY/FRAMING/BREAK bits
84*4882a593Smuzhiyun 		only appear in (b) format messages.
85*4882a593Smuzhiyun 	(2) For the host to determine the exact point at which the
86*4882a593Smuzhiyun 		overrun occurred (to identify the point in the data
87*4882a593Smuzhiyun 		stream at which the data was lost), it needs to count
88*4882a593Smuzhiyun 		128 characters, starting at the first character of the
89*4882a593Smuzhiyun 		message in which OVERRUN was reported; the lost character(s)
90*4882a593Smuzhiyun 		would have been received between the 128th and 129th
91*4882a593Smuzhiyun 		characters.
92*4882a593Smuzhiyun 	(3)	An RX data message in which the first byte has 0x80 clear
93*4882a593Smuzhiyun 		serves as a "break off" indicator.
94*4882a593Smuzhiyun 	(4)	a control message specifying disablePort will be answered
95*4882a593Smuzhiyun 		with a status message, but no further status will be sent
96*4882a593Smuzhiyun 		until a control messages with enablePort is sent
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	revision history:
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun 	1999feb10	add reportHskiaChanges to allow us to ignore them
101*4882a593Smuzhiyun 	1999feb10	add txAckThreshold for fast+loose throughput enhancement
102*4882a593Smuzhiyun 	1999mar30	beef up support for RX error reporting
103*4882a593Smuzhiyun 	1999apr14	add resetDataToggle to control message
104*4882a593Smuzhiyun 	2000jan04	merge with usa17msg.h
105*4882a593Smuzhiyun 	2000mar08	clone from usa26msg.h -> usa49msg.h
106*4882a593Smuzhiyun 	2000mar09	change to support 4 ports
107*4882a593Smuzhiyun 	2000may03	change external clocking to match USA-49W hardware
108*4882a593Smuzhiyun 	2000jun01	add extended BSD-style copyright text
109*4882a593Smuzhiyun 	2001jul05	change message format to improve OVERRUN case
110*4882a593Smuzhiyun */
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #ifndef	__USA49MSG__
113*4882a593Smuzhiyun #define	__USA49MSG__
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /*
117*4882a593Smuzhiyun 	Host->device messages sent on the global control endpoint:
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	portNumber	message
120*4882a593Smuzhiyun 	----------	--------------------
121*4882a593Smuzhiyun 	0,1,2,3		portControlMessage
122*4882a593Smuzhiyun 	0x80		globalControlMessage
123*4882a593Smuzhiyun */
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun struct keyspan_usa49_portControlMessage
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	/*
128*4882a593Smuzhiyun 		0.	0/1/2/3 	port control message follows
129*4882a593Smuzhiyun 			0x80 set	non-port control message follows
130*4882a593Smuzhiyun 	*/
131*4882a593Smuzhiyun 	u8	portNumber,
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	/*
134*4882a593Smuzhiyun 		there are three types of "commands" sent in the control message:
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 		1.	configuration changes which must be requested by setting
137*4882a593Smuzhiyun 			the corresponding "set" flag (and should only be requested
138*4882a593Smuzhiyun 			when necessary, to reduce overhead on the USA26):
139*4882a593Smuzhiyun 	*/
140*4882a593Smuzhiyun 		setClocking,	// host requests baud rate be set
141*4882a593Smuzhiyun 		baudLo,			// host does baud divisor calculation
142*4882a593Smuzhiyun 		baudHi,			// baudHi is only used for first port (gives lower rates)
143*4882a593Smuzhiyun 		prescaler,		// specified as N/8; values 8-ff are valid
144*4882a593Smuzhiyun 						// must be set any time internal baud rate is set;
145*4882a593Smuzhiyun 		txClocking,		// 0=internal, 1=external/DSR
146*4882a593Smuzhiyun 		rxClocking,		// 0=internal, 1=external/DSR
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 		setLcr,			// host requests lcr be set
149*4882a593Smuzhiyun 		lcr,			// use PARITY, STOPBITS, DATABITS below
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 		setFlowControl,	// host requests flow control be set
152*4882a593Smuzhiyun 		ctsFlowControl,	// 1=use CTS flow control, 0=don't
153*4882a593Smuzhiyun 		xonFlowControl,	// 1=use XON/XOFF flow control, 0=don't
154*4882a593Smuzhiyun 		xonChar,		// specified in current character format
155*4882a593Smuzhiyun 		xoffChar,		// specified in current character format
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 		setRts,			// host requests RTS output be set
158*4882a593Smuzhiyun 		rts,			// 1=active, 0=inactive
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 		setDtr,			// host requests DTR output be set
161*4882a593Smuzhiyun 		dtr;			// 1=on, 0=off
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	/*
165*4882a593Smuzhiyun 		3.	configuration data which is simply used as is (no overhead,
166*4882a593Smuzhiyun 			but must be specified correctly in every host message).
167*4882a593Smuzhiyun 	*/
168*4882a593Smuzhiyun 	u8	forwardingLength,  // forward when this number of chars available
169*4882a593Smuzhiyun 		dsrFlowControl,	// 1=use DSR flow control, 0=don't
170*4882a593Smuzhiyun 		txAckThreshold,	// 0=not allowed, 1=normal, 2-255 deliver ACK faster
171*4882a593Smuzhiyun 		loopbackMode;	// 0=no loopback, 1=loopback enabled
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	/*
174*4882a593Smuzhiyun 		4.	commands which are flags only; these are processed in order
175*4882a593Smuzhiyun 			(so that, e.g., if both _txOn and _txOff flags are set, the
176*4882a593Smuzhiyun 			port ends in a TX_OFF state); any non-zero value is respected
177*4882a593Smuzhiyun 	*/
178*4882a593Smuzhiyun 	u8	_txOn,			// enable transmitting (and continue if there's data)
179*4882a593Smuzhiyun 		_txOff,			// stop transmitting
180*4882a593Smuzhiyun 		txFlush,		// toss outbound data
181*4882a593Smuzhiyun 		txBreak,		// turn on break (cleared by _txOn)
182*4882a593Smuzhiyun 		rxOn,			// turn on receiver
183*4882a593Smuzhiyun 		rxOff,			// turn off receiver
184*4882a593Smuzhiyun 		rxFlush,		// toss inbound data
185*4882a593Smuzhiyun 		rxForward,		// forward all inbound data, NOW (as if fwdLen==1)
186*4882a593Smuzhiyun 		returnStatus,	// return current status (even if it hasn't changed)
187*4882a593Smuzhiyun 		resetDataToggle,// reset data toggle state to DATA0
188*4882a593Smuzhiyun 		enablePort,		// start servicing port (move data, check status)
189*4882a593Smuzhiyun 		disablePort;	// stop servicing port (does implicit tx/rx flush/off)
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun // defines for bits in lcr
194*4882a593Smuzhiyun #define	USA_DATABITS_5		0x00
195*4882a593Smuzhiyun #define	USA_DATABITS_6		0x01
196*4882a593Smuzhiyun #define	USA_DATABITS_7		0x02
197*4882a593Smuzhiyun #define	USA_DATABITS_8		0x03
198*4882a593Smuzhiyun #define	STOPBITS_5678_1		0x00	// 1 stop bit for all byte sizes
199*4882a593Smuzhiyun #define	STOPBITS_5_1p5		0x04	// 1.5 stop bits for 5-bit byte
200*4882a593Smuzhiyun #define	STOPBITS_678_2		0x04	// 2 stop bits for 6/7/8-bit byte
201*4882a593Smuzhiyun #define	USA_PARITY_NONE		0x00
202*4882a593Smuzhiyun #define	USA_PARITY_ODD		0x08
203*4882a593Smuzhiyun #define	USA_PARITY_EVEN		0x18
204*4882a593Smuzhiyun #define	PARITY_1			0x28
205*4882a593Smuzhiyun #define	PARITY_0			0x38
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun /*
208*4882a593Smuzhiyun 	during normal operation, status messages are returned
209*4882a593Smuzhiyun 	to the host whenever the board detects changes.  In some
210*4882a593Smuzhiyun 	circumstances (e.g. Windows), status messages from the
211*4882a593Smuzhiyun 	device cause problems; to shut them off, the host issues
212*4882a593Smuzhiyun 	a control message with the disableStatusMessages flags
213*4882a593Smuzhiyun 	set (to any non-zero value).  The device will respond to
214*4882a593Smuzhiyun 	this message, and then suppress further status messages;
215*4882a593Smuzhiyun 	it will resume sending status messages any time the host
216*4882a593Smuzhiyun 	sends any control message (either global or port-specific).
217*4882a593Smuzhiyun */
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun struct keyspan_usa49_globalControlMessage
220*4882a593Smuzhiyun {
221*4882a593Smuzhiyun 	u8	portNumber,			// 0x80
222*4882a593Smuzhiyun 		sendGlobalStatus,	// 1/2=number of status responses requested
223*4882a593Smuzhiyun 		resetStatusToggle,	// 1=reset global status toggle
224*4882a593Smuzhiyun 		resetStatusCount,	// a cycling value
225*4882a593Smuzhiyun 		remoteWakeupEnable,		// 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4
226*4882a593Smuzhiyun 		disableStatusMessages;	// 1=send no status until host talks
227*4882a593Smuzhiyun };
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun /*
230*4882a593Smuzhiyun 	Device->host messages send on the global status endpoint
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	portNumber			message
233*4882a593Smuzhiyun 	----------			--------------------
234*4882a593Smuzhiyun 	0x00,0x01,0x02,0x03	portStatusMessage
235*4882a593Smuzhiyun 	0x80				globalStatusMessage
236*4882a593Smuzhiyun 	0x81				globalDebugMessage
237*4882a593Smuzhiyun */
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun struct keyspan_usa49_portStatusMessage	// one for each port
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	u8	portNumber,		// 0,1,2,3
242*4882a593Smuzhiyun 		cts,			// reports CTS pin
243*4882a593Smuzhiyun 		dcd,			// reports DCD pin
244*4882a593Smuzhiyun 		dsr,			// reports DSR pin
245*4882a593Smuzhiyun 		ri,				// reports RI pin
246*4882a593Smuzhiyun 		_txOff,			// transmit has been disabled (by host)
247*4882a593Smuzhiyun 		_txXoff,		// transmit is in XOFF state (either host or RX XOFF)
248*4882a593Smuzhiyun 		rxEnabled,		// as configured by rxOn/rxOff 1=on, 0=off
249*4882a593Smuzhiyun 		controlResponse,// 1=a control message has been processed
250*4882a593Smuzhiyun 		txAck,			// ACK (data TX complete)
251*4882a593Smuzhiyun 		rs232valid;		// RS-232 signal valid
252*4882a593Smuzhiyun };
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun // bits in RX data message when STAT byte is included
255*4882a593Smuzhiyun #define	RXERROR_OVERRUN	0x02
256*4882a593Smuzhiyun #define	RXERROR_PARITY	0x04
257*4882a593Smuzhiyun #define	RXERROR_FRAMING	0x08
258*4882a593Smuzhiyun #define	RXERROR_BREAK	0x10
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun struct keyspan_usa49_globalStatusMessage
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun 	u8	portNumber,			// 0x80=globalStatusMessage
263*4882a593Smuzhiyun 		sendGlobalStatus,	// from request, decremented
264*4882a593Smuzhiyun 		resetStatusCount;	// as in request
265*4882a593Smuzhiyun };
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun struct keyspan_usa49_globalDebugMessage
268*4882a593Smuzhiyun {
269*4882a593Smuzhiyun 	u8	portNumber,			// 0x81=globalDebugMessage
270*4882a593Smuzhiyun 		n,					// typically a count/status byte
271*4882a593Smuzhiyun 		b;					// typically a data byte
272*4882a593Smuzhiyun };
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun // ie: the maximum length of an EZUSB endpoint buffer
275*4882a593Smuzhiyun #define	MAX_DATA_LEN			64
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun // update status approx. 60 times a second (16.6666 ms)
278*4882a593Smuzhiyun #define	STATUS_UPDATE_INTERVAL	16
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun // status rationing tuning value (each port gets checked each n ms)
281*4882a593Smuzhiyun #define	STATUS_RATION	10
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun #endif
284