xref: /openbsd/sys/dev/sbus/magmareg.h (revision 799d9b3d)
1 /*	$OpenBSD: magmareg.h,v 1.11 2024/04/24 09:30:30 claudio 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  *    |   |   |   +-------------------> dialout (on tty ports)
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)	((minor(x) >> 6) & 0x03)
58 #define MAGMA_PORT(x)	(minor(x) & 0x0f)
59 
60 #define MTTY_DIALOUT(x) (minor(x) & 0x10)
61 
62 /*
63  * Supported Card Types
64  */
65 struct magma_board_info {
66 	const char *mb_sbusname;	/* sbus 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 	bus_space_handle_t cd_regh;	/* chip register handle */
85 	bus_space_tag_t cd_regt;	/* chip register tag */
86 	int cd_chiprev;			/* chip revision */
87 	int cd_clock;			/* clock speed in MHz */
88 	int cd_parmode;			/* parallel mode operation */
89 };
90 
91 /*
92  * cd1190 chip data
93  */
94 struct cd1190 {
95 	bus_space_handle_t cd_regh;	/* chip register handle */
96 	bus_space_tag_t cd_regt;	/* chip register tag */
97 	int cd_chiprev;			/* chip revision */
98 };
99 
100 /* software state for each card */
101 struct magma_softc {
102 	struct device ms_dev;		/* required. must be first in softc */
103 
104 	bus_space_tag_t sc_bustag;	/* our bus tag */
105 	bus_space_handle_t sc_iohandle;	/* whole card registers */
106 	void *sc_ih;			/* interrupt vector */
107 	void *sc_sih;			/* softintr vector */
108 
109 	/* cd1400 chip info */
110 	int ms_ncd1400;
111 	struct cd1400 ms_cd1400[MAGMA_MAX_CD1400];
112 	bus_space_handle_t sc_svcackrh;	/* CD1400 service acknowledge receive */
113 	bus_space_handle_t sc_svcackth;	/* CD1400 service acknowledge transmit */
114 	bus_space_handle_t sc_svcackmh;	/* CD1400 service acknowledge modem */
115 
116 
117 	/* cd1190 chip info */
118 	int ms_ncd1190;
119 	struct cd1190 ms_cd1190[MAGMA_MAX_CD1190];
120 
121 	const struct magma_board_info *ms_board;	/* what am I? */
122 
123 	struct mtty_softc *ms_mtty;
124 	struct mbpp_softc *ms_mbpp;
125 
126 	struct intrhand ms_hardint;	/* hard interrupt handler */
127 	struct intrhand ms_softint;	/* soft interrupt handler */
128 };
129 
130 #define MTTY_RBUF_SIZE		(2 * 512)
131 #define MTTY_RX_FIFO_THRESHOLD	6
132 #define MTTY_RX_DTR_THRESHOLD	9
133 
134 struct mtty_port {
135 	struct cd1400 *mp_cd1400;	/* ptr to chip */
136 	int mp_channel;			/* and channel */
137 	struct tty *mp_tty;
138 
139 	int mp_openflags;	/* default tty flags */
140 	int mp_flags;		/* port flags */
141 	int mp_carrier;		/* state of carrier */
142 
143 	u_char *mp_rbuf;	/* ring buffer start */
144 	u_char *mp_rend;	/* ring buffer end */
145 	u_char *mp_rget;	/* ring buffer read pointer */
146 	u_char *mp_rput;	/* ring buffer write pointer */
147 
148 	u_char *mp_txp;		/* transmit character pointer */
149 	int mp_txc;		/* transmit character counter */
150 };
151 
152 #define MTTYF_CARRIER_CHANGED	(1<<0)
153 #define MTTYF_SET_BREAK		(1<<1)
154 #define MTTYF_CLR_BREAK		(1<<2)
155 #define MTTYF_DONE		(1<<3)
156 #define MTTYF_STOP		(1<<4)
157 #define MTTYF_RING_OVERFLOW	(1<<5)
158 
159 struct mtty_softc {
160 	struct device ms_dev;		/* device info */
161 	int ms_nports;			/* tty ports */
162 	struct mtty_port ms_port[MAGMA_MAX_TTY];
163 };
164 
165 #define MBPP_RX_FIFO_THRESHOLD	25
166 
167 struct mbpp_port {
168 	struct cd1400 *mp_cd1400;	/* for LC2+1Sp card */
169 	struct cd1190 *mp_cd1190;	/* all the others   */
170 
171 	int mp_flags;
172 
173 	struct bpp_param mp_param;
174 #define mp_burst mp_param.bp_burst
175 #define mp_timeout mp_param.bp_timeout
176 #define mp_delay mp_param.bp_delay
177 
178 	u_char *mp_ptr;			/* pointer to io data */
179 	int mp_cnt;			/* count of io chars */
180 
181 	struct timeout mp_timeout_tmo;	/* for mbpp_timeout() */
182 	struct timeout mp_start_tmo;	/* for mbpp_start() */
183 };
184 
185 #define MBPPF_OPEN	(1<<0)
186 #define MBPPF_TIMEOUT	(1<<1)
187 #define MBPPF_UIO	(1<<2)
188 #define MBPPF_DELAY	(1<<3)
189 #define MBPPF_WAKEUP	(1<<4)
190 
191 struct mbpp_softc {
192 	struct device ms_dev;		/* device info */
193 	int ms_nports;			/* parallel ports */
194 	struct mbpp_port ms_port[MAGMA_MAX_BPP];
195 };
196 
197 /* internal function prototypes */
198 
199 int cd1400_compute_baud(speed_t, int, int *, int *);
200 void cd1400_enable_transmitter(struct cd1400 *, int);
201 
202 int magma_match(struct device *, void *, void *);
203 void magma_attach(struct device *, struct device *, void *);
204 int magma_hard(void *);
205 void magma_soft(void *);
206 
207 int mtty_match(struct device *, void *, void *);
208 void mtty_attach(struct device *, struct device *, void *);
209 int mtty_modem_control(struct mtty_port *, int, int);
210 int mtty_param(struct tty *, struct termios *);
211 void mtty_start(struct tty *);
212 
213 int mbpp_match(struct device *, void *, void *);
214 void mbpp_attach(struct device *, struct device *, void *);
215 int mbpp_rw(dev_t, struct uio *);
216 void mbpp_timeout(void *);
217 void mbpp_start(void *);
218 int mbpp_send(struct mbpp_port *, caddr_t, int);
219 int mbpp_recv(struct mbpp_port *, caddr_t, int);
220 
221 #define	CD1400_REGMAPSIZE	0x80
222 #define	CD1190_REGMAPSIZE	0x20
223