xref: /netbsd-src/sys/arch/sgimips/dev/scnvar.h (revision cbab9cadce21ae72fac13910001079fff214cc29)
1*cbab9cadSchs /*	$NetBSD: scnvar.h,v 1.2 2012/10/27 17:18:09 chs Exp $	*/
2b610ccb0Srumble 
3b610ccb0Srumble /*
4b610ccb0Srumble  * Copyright (c) 1996, 1997 Philip L. Budne.
5b610ccb0Srumble  * Copyright (c) 1993 Philip A. Nelson.
6b610ccb0Srumble  * All rights reserved.
7b610ccb0Srumble  *
8b610ccb0Srumble  * Redistribution and use in source and binary forms, with or without
9b610ccb0Srumble  * modification, are permitted provided that the following conditions
10b610ccb0Srumble  * are met:
11b610ccb0Srumble  * 1. Redistributions of source code must retain the above copyright
12b610ccb0Srumble  *    notice, this list of conditions and the following disclaimer.
13b610ccb0Srumble  * 2. Redistributions in binary form must reproduce the above copyright
14b610ccb0Srumble  *    notice, this list of conditions and the following disclaimer in the
15b610ccb0Srumble  *    documentation and/or other materials provided with the distribution.
16b610ccb0Srumble  * 3. All advertising materials mentioning features or use of this software
17b610ccb0Srumble  *    must display the following acknowledgement:
18b610ccb0Srumble  *	This product includes software developed by Philip A. Nelson.
19b610ccb0Srumble  * 4. The name of Philip A. Nelson may not be used to endorse or promote
20b610ccb0Srumble  *    products derived from this software without specific prior written
21b610ccb0Srumble  *    permission.
22b610ccb0Srumble  *
23b610ccb0Srumble  * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR
24b610ccb0Srumble  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25b610ccb0Srumble  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26b610ccb0Srumble  * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27b610ccb0Srumble  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28b610ccb0Srumble  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29b610ccb0Srumble  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30b610ccb0Srumble  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31b610ccb0Srumble  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32b610ccb0Srumble  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33b610ccb0Srumble  *
34b610ccb0Srumble  *	scnvar.h: definitions for pc532 2681/2692/26c96 duart driver
35b610ccb0Srumble  */
36b610ccb0Srumble 
37b610ccb0Srumble /* Constants. */
38b610ccb0Srumble #ifdef COMDEF_SPEED
39b610ccb0Srumble #undef  TTYDEF_SPEED
40b610ccb0Srumble #define TTYDEF_SPEED    COMDEF_SPEED	/* default baud rate */
41b610ccb0Srumble #endif
42b610ccb0Srumble 
43b610ccb0Srumble #define SCN_SIZE	         0x8	/* address space for port */
44b610ccb0Srumble 
45b610ccb0Srumble #define SCN_CONSOLE		   0	/* minor number of console */
46b610ccb0Srumble #define SCN_CONSDUART		   0
47b610ccb0Srumble #define SCN_CONSCHAN		   0
48b610ccb0Srumble 
49b610ccb0Srumble /* output port bits */
50b610ccb0Srumble #define OP_RTSA		OP_OP0
51b610ccb0Srumble #define OP_RTSB		OP_OP1
52b610ccb0Srumble #define OP_DTRA		OP_OP2
53b610ccb0Srumble #define OP_DTRB		OP_OP3
54b610ccb0Srumble /* OP4-7 not connected */
55b610ccb0Srumble 
56b610ccb0Srumble /* input port bits */
57b610ccb0Srumble #define IP_CTSA		IP_IP0
58b610ccb0Srumble #define IP_CTSB		IP_IP1
59b610ccb0Srumble #define IP_DCDB		IP_IP2
60b610ccb0Srumble #define IP_DCDA		IP_IP3
61b610ccb0Srumble /* IP4-6 not connected */
62b610ccb0Srumble 
63b610ccb0Srumble #define ACR_DELTA_CTSA	ACR_DELTA_IP0
64b610ccb0Srumble #define ACR_DELTA_CTSB	ACR_DELTA_IP1
65b610ccb0Srumble #define ACR_DELTA_DCDB	ACR_DELTA_IP2
66b610ccb0Srumble #define ACR_DELTA_DCDA	ACR_DELTA_IP3
67b610ccb0Srumble 
68b610ccb0Srumble #define IPCR_CTSA	IPCR_IP0
69b610ccb0Srumble #define IPCR_CTSB	IPCR_IP1
70b610ccb0Srumble #define IPCR_DCDB	IPCR_IP2
71b610ccb0Srumble #define IPCR_DCDA	IPCR_IP3
72b610ccb0Srumble #define IPCR_DELTA_CTSA	IPCR_DELTA_IP0
73b610ccb0Srumble #define IPCR_DELTA_CTSB	IPCR_DELTA_IP1
74b610ccb0Srumble #define IPCR_DELTA_DCDB	IPCR_DELTA_IP2
75b610ccb0Srumble #define IPCR_DELTA_DCDA	IPCR_DELTA_IP3
76b610ccb0Srumble 
77b610ccb0Srumble #define SCN_OP_BIS(SC,VAL) ((SC)->sc_duart->base[DU_OPSET] = (VAL))
78b610ccb0Srumble #define SCN_OP_BIC(SC,VAL) ((SC)->sc_duart->base[DU_OPCLR] = (VAL))
79b610ccb0Srumble 
80b610ccb0Srumble #define SCN_DCD(SC) (((SC)->sc_duart->base[DU_IP] & (SC)->sc_ip_dcd) == 0)
81b610ccb0Srumble 
82b610ccb0Srumble /* pc532 duarts are auto-sized to byte-wide */
83b610ccb0Srumble #define CH_SZ		8
84b610ccb0Srumble #define DUART_SZ	16
85b610ccb0Srumble #define SCN_REG(n)	(n << 4)		/* 15 byte pad after each reg */
86b610ccb0Srumble 
87b610ccb0Srumble /* The DUART description struct; for data common to both channels */
88b610ccb0Srumble struct duart {
89b610ccb0Srumble 	volatile u_char *base;
90b610ccb0Srumble 	struct chan {
91b610ccb0Srumble 		struct scn_softc *sc;
92b610ccb0Srumble 		struct tty *tty;
93b610ccb0Srumble 		int32_t ispeed, ospeed;
94b610ccb0Srumble 		u_char icode, ocode;
95b610ccb0Srumble 		u_char mr0;			/* MR0[7:3] */
96b610ccb0Srumble 		u_char new_mr1;		/* held changes */
97b610ccb0Srumble 		u_char new_mr2;		/* held changes */
98b610ccb0Srumble 	} chan[2];
99b610ccb0Srumble 	enum scntype { SCNUNK, SCN2681, SCN2692, SC26C92 } type;
100b610ccb0Srumble 	uint16_t counter;		/* C/T generated bps, or zero */
101b610ccb0Srumble 	uint16_t ocounter;		/* last C/T generated bps, or zero */
102b610ccb0Srumble 	u_char	mode;			/* ACR[7] + MR0[2:0] */
103b610ccb0Srumble 	u_char	acr;			/* ACR[6:0]*/
104b610ccb0Srumble 	u_char	imr;			/* IMR bits */
105b610ccb0Srumble 	u_char	opcr;			/* OPCR bits */
106b610ccb0Srumble };
107b610ccb0Srumble 
108b610ccb0Srumble #define SCN_RING_BITS	9	/* 512 byte buffers */
109b610ccb0Srumble #define SCN_RING_SIZE	(1<<SCN_RING_BITS)	/* must be a power of two */
110b610ccb0Srumble #define SCN_RING_MASK	(SCN_RING_SIZE-1)
111b610ccb0Srumble #define SCN_RING_THRESH	(SCN_RING_SIZE/2)
112b610ccb0Srumble #define SCN_RING_HIWAT  (SCN_RING_SIZE - (SCN_RING_SIZE >> 2))
113b610ccb0Srumble 
114b610ccb0Srumble /* scn channel state */
115b610ccb0Srumble struct scn_softc {
116b610ccb0Srumble 	struct tty *sc_tty;
117b610ccb0Srumble 	int     sc_unit;		/* unit number of this line (base 0) */
118b610ccb0Srumble 	int	sc_channel;
119b610ccb0Srumble 	int	sc_isconsole;
120b610ccb0Srumble 	int	sc_iskgdb;
121b610ccb0Srumble 	struct duart *sc_duart;	/* pointer to duart struct */
122b610ccb0Srumble 	volatile u_char *sc_chbase;	/* per-channel registers (CH_xxx) */
123b610ccb0Srumble 	u_char	sc_swflags;		/* from config / TIOCxFLAGS */
124b610ccb0Srumble #define SCN_SW_SOFTCAR	0x01
125b610ccb0Srumble #define SCN_SW_CLOCAL	0x02
126b610ccb0Srumble #define SCN_SW_CRTSCTS	0x04
127b610ccb0Srumble #define SCN_SW_MDMBUF	0x08		/* not implemented */
128b610ccb0Srumble 
129b610ccb0Srumble /* I wish there was a TS_DIALOUT flag! */
130b610ccb0Srumble 	u_char  sc_dialout;		/* set if open for dialout */
131b610ccb0Srumble #define SCN_DIALOUT(SCN) ((SCN)->sc_dialout)
132b610ccb0Srumble #define SCN_SETDIALOUT(SCN) (SCN)->sc_dialout = 1
133b610ccb0Srumble #define SCN_CLRDIALOUT(SCN) (SCN)->sc_dialout = 0
134b610ccb0Srumble 
135b610ccb0Srumble 	u_char	sc_heldchanges;		/* waiting for output done */
136b610ccb0Srumble 
137b610ccb0Srumble /* bits in input port register */
138b610ccb0Srumble 	u_char  sc_ip_dcd;
139b610ccb0Srumble 	u_char  sc_ip_cts;
140b610ccb0Srumble 
141b610ccb0Srumble /* bits in output port registers */
142b610ccb0Srumble 	u_char  sc_op_rts;
143b610ccb0Srumble 	u_char  sc_op_dtr;
144b610ccb0Srumble 
145b610ccb0Srumble /* interrupt mask bits */
146b610ccb0Srumble 	u_char  sc_tx_int;
147b610ccb0Srumble 	u_char  sc_rx_int;
148b610ccb0Srumble 
149b610ccb0Srumble /* counters */
150b610ccb0Srumble 	u_long	sc_framing_errors;
151b610ccb0Srumble 	u_long	sc_parity_errors;
152b610ccb0Srumble 	u_long	sc_fifo_overruns;
153b610ccb0Srumble 	u_long  sc_breaks;
154b610ccb0Srumble 
155b610ccb0Srumble /* ring buffer for rxrdy interrupt */
156b610ccb0Srumble 	u_int	sc_rbget;		/* ring buffer `get' index */
157b610ccb0Srumble 	volatile u_int sc_rbput;	/* ring buffer `put' index */
158b610ccb0Srumble 	int	sc_rbhiwat;
159b610ccb0Srumble 	short   sc_rbuf[SCN_RING_SIZE];	/* status + data */
160b610ccb0Srumble 	long	sc_fotime;		/* last fifo overrun message */
161b610ccb0Srumble 	long	sc_rotime;		/* last ring overrun message */
162b610ccb0Srumble 	u_long	sc_ring_overruns;	/* number of ring buffer overruns */
163b610ccb0Srumble 	/* Flags to communicate with scntty_softint() */
164b610ccb0Srumble 	volatile char sc_rx_blocked;	/* input block at ring */
165b610ccb0Srumble };
166