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