1 /*	$NetBSD: magmareg.h,v 1.18 2014/11/15 19:18:19 christos Exp $	*/
2 
3 /*-
4  *  Copyright (c) 1998 Iain Hibbert
5  *  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifdef MAGMA_DEBUG
29 #define dprintf(x) printf x
30 #else
31 #define dprintf(x)
32 #endif
33 
34 /*  The mapping of minor device number -> card and port is done as
35  * follows by default:
36  *
37  *  +---+---+---+---+---+---+---+---+
38  *  | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
39  *  +---+---+---+---+---+---+---+---+
40  *    |   |   |   |   |   |   |   |
41  *    |   |   |   |   +---+---+---+---> port number
42  *    |   |   |   |
43  *    |   |   |   +-------------------> unused
44  *    |   |   |
45  *    |   |   +-----------------------> unused
46  *    |   |
47  *    +---+---------------------------> card number
48  *
49  */
50 
51 #define MAGMA_MAX_CARDS		4
52 #define MAGMA_MAX_TTY		16
53 #define MAGMA_MAX_BPP		2
54 #define MAGMA_MAX_CD1400	4
55 #define MAGMA_MAX_CD1190	2
56 
57 #define MAGMA_CARD(x)	((TTUNIT(x) >> 6) & 0x03)
58 #define MAGMA_PORT(x)	(TTUNIT(x) & 0x0f)
59 
60 #define MTTY_DIALOUT(x) TTDIALOUT(x)
61 
62 /*
63  * Supported Card Types
64  */
65 struct magma_board_info {
66 	const char *mb_sbusname;	/* sbus_attach_args.sa_name */
67 	const char *mb_name;		/* cardname to match against */
68 	const char *mb_realname;	/* english card name */
69 	int mb_nser;			/* number of serial ports */
70 	int mb_npar;			/* number of parallel ports */
71 	int mb_ncd1400;			/* number of CD1400 chips */
72 	int mb_svcackr;			/* svcackr offset */
73 	int mb_svcackt;			/* svcackt offset */
74 	int mb_svcackm;			/* svcackm offset */
75 	int mb_cd1400[MAGMA_MAX_CD1400];/* cd1400 chip register offsets */
76 	int mb_ncd1190;			/* number of CD1190 chips */
77 	int mb_cd1190[MAGMA_MAX_CD1190];/* cd1190 chip register offsets */
78 };
79 
80 /*
81  * cd1400 chip data
82  */
83 struct cd1400 {
84 	volatile u_char *cd_reg;	/* chip registers */
85 	int cd_chiprev;			/* chip revision */
86 	int cd_clock;			/* clock speed in MHz */
87 	int cd_parmode;			/* parallel mode operation */
88 };
89 
90 /*
91  * cd1190 chip data
92  */
93 struct cd1190 {
94 	volatile u_char *cd_reg;	/* chip registers */
95 	int cd_chiprev;			/* chip revision */
96 };
97 
98 /* software state for each card */
99 struct magma_softc {
100 	device_t	ms_dev;		/* required. must be first in softc */
101 	struct evcnt	ms_intrcnt;	/* statistics */
102 
103 	/* cd1400 chip info */
104 	int	ms_ncd1400;
105 	struct cd1400 ms_cd1400[MAGMA_MAX_CD1400];
106 	volatile u_char *ms_svcackr;	/* CD1400 service acknowledge receive */
107 	volatile u_char *ms_svcackt;	/* CD1400 service acknowledge transmit */
108 	volatile u_char *ms_svcackm;	/* CD1400 service acknowledge modem */
109 
110 	/* cd1190 chip info */
111 	int ms_ncd1190;
112 	struct cd1190 ms_cd1190[MAGMA_MAX_CD1190];
113 
114 	struct magma_board_info *ms_board;	/* what am I? */
115 
116 	struct mtty_softc *ms_mtty;
117 	struct mbpp_softc *ms_mbpp;
118 
119 	/* softintr(9) cookie */
120 	void	*ms_sicookie;
121 };
122 
123 #define MTTY_RBUF_SIZE		(2 * 512)
124 #define MTTY_RX_FIFO_THRESHOLD	6
125 #define MTTY_RX_DTR_THRESHOLD	9
126 
127 struct mtty_port {
128 	struct cd1400 *mp_cd1400;	/* ptr to chip */
129 	int mp_channel;			/* and channel */
130 	struct tty *mp_tty;
131 
132 	int mp_openflags;	/* default tty flags */
133 	int mp_flags;		/* port flags */
134 	int mp_carrier;		/* state of carrier */
135 
136 	u_char *mp_rbuf;	/* ring buffer start */
137 	u_char *mp_rend;	/* ring buffer end */
138 	u_char *mp_rget;	/* ring buffer read pointer */
139 	u_char *mp_rput;	/* ring buffer write pointer */
140 
141 	u_char *mp_txp;		/* transmit character pointer */
142 	int mp_txc;		/* transmit character counter */
143 };
144 
145 #define MTTYF_CARRIER_CHANGED	(1<<0)
146 #define MTTYF_SET_BREAK		(1<<1)
147 #define MTTYF_CLR_BREAK		(1<<2)
148 #define MTTYF_DONE		(1<<3)
149 #define MTTYF_STOP		(1<<4)
150 #define MTTYF_RING_OVERFLOW	(1<<5)
151 
152 struct mtty_softc {
153 	device_t ms_dev;		/* device info */
154 	int ms_nports;			/* tty ports */
155 	struct mtty_port ms_port[MAGMA_MAX_TTY];
156 };
157 
158 #define MBPP_RX_FIFO_THRESHOLD	25
159 
160 struct mbpp_port {
161 	struct cd1400 *mp_cd1400;	/* for LC2+1Sp card */
162 	struct cd1190 *mp_cd1190;	/* all the others   */
163 
164 	struct callout mp_timeout_ch;
165 	struct callout mp_start_ch;
166 
167 	int	mp_flags;
168 
169 	struct mbpp_param mp_param;
170 #define mp_burst	mp_param.bp_burst
171 #define mp_timeout	mp_param.bp_timeout
172 #define mp_delay	mp_param.bp_delay
173 
174 	u_char	*mp_ptr;		/* pointer to I/O data */
175 	int	mp_cnt;			/* count of I/O chars */
176 };
177 
178 #define MBPPF_OPEN	(1<<0)
179 #define MBPPF_TIMEOUT	(1<<1)
180 #define MBPPF_UIO	(1<<2)
181 #define MBPPF_DELAY	(1<<3)
182 #define MBPPF_WAKEUP	(1<<4)
183 
184 struct mbpp_softc {
185 	int ms_nports;			/* parallel ports */
186 	struct mbpp_port ms_port[MAGMA_MAX_BPP];
187 };
188 
189 /*
190  * useful macros
191  */
192 #define SET(t, f)	((t) |= (f))
193 #define CLR(t, f)	((t) &= ~(f))
194 #define ISSET(t, f)	((t) & (f))
195 
196 /* internal function prototypes */
197 
198 int cd1400_compute_baud(speed_t, int, int *, int *);
199 __inline void cd1400_write_ccr(struct cd1400 *, u_char);
200 __inline u_char cd1400_read_reg(struct cd1400 *, int);
201 __inline void cd1400_write_reg(struct cd1400 *, int, u_char);
202 void cd1400_enable_transmitter(struct cd1400 *, int);
203 
204 int magma_match(device_t, cfdata_t, void *);
205 void magma_attach(device_t, device_t, void *);
206 int magma_hard(void *);
207 void magma_soft(void *);
208 
209 int mtty_match(device_t, cfdata_t, void *);
210 void mtty_attach(device_t, device_t, void *);
211 int mtty_modem_control(struct mtty_port *, int, int);
212 int mtty_param(struct tty *, struct termios *);
213 void mtty_start(struct tty *);
214 
215 int mbpp_match(device_t, cfdata_t, void *);
216 void mbpp_attach(device_t, device_t, void *);
217 void mbpp_timeout(void *);
218 void mbpp_start(void *);
219 int mbpp_send(struct mbpp_port *, void *, int);
220 int mbpp_recv(struct mbpp_port *, void *, int);
221 int mbpp_hztoms(int);
222 int mbpp_mstohz(int);
223