dz_vsbus.c revision 1.13 1 /* $NetBSD: dz_vsbus.c,v 1.13 1999/06/06 19:10:49 ragge Exp $ */
2 /*
3 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed at Ludd, University of
17 * Lule}, Sweden and its contributors.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33
34
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 #include <sys/systm.h>
38 #include <sys/ioctl.h>
39 #include <sys/tty.h>
40 #include <sys/file.h>
41 #include <sys/conf.h>
42 #include <sys/device.h>
43 #include <sys/reboot.h>
44
45 #include <dev/cons.h>
46
47 #include <machine/mtpr.h>
48 #include <machine/sid.h>
49 #include <machine/uvax.h>
50 #include <machine/vsbus.h>
51 #include <machine/cpu.h>
52 #include <machine/scb.h>
53
54 #include <machine/../vax/gencons.h>
55
56 #include <dev/qbus/dzreg.h>
57 #include <dev/qbus/dzvar.h>
58
59 #include "ioconf.h"
60 #include "lkc.h"
61
62 static int dz_vsbus_match __P((struct device *, struct cfdata *, void *));
63 static void dz_vsbus_attach __P((struct device *, struct device *, void *));
64 static int dz_print __P((void *, const char *));
65
66 static vaddr_t dz_regs; /* Used for console */
67
68 struct cfattach dz_vsbus_ca = {
69 sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
70 };
71
72 #define REG(name) short name; short X##name##X;
73 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
74 REG(csr); /* 00 Csr: control/status register */
75 REG(rbuf); /* 04 Rbuf/Lpr: receive buffer/line param reg. */
76 REG(tcr); /* 08 Tcr: transmit console register */
77 REG(tdr); /* 0C Msr/Tdr: modem status reg/transmit data reg */
78 REG(lpr0); /* 10 Lpr0: */
79 REG(lpr1); /* 14 Lpr0: */
80 REG(lpr2); /* 18 Lpr0: */
81 REG(lpr3); /* 1C Lpr0: */
82 } *dz;
83 #undef REG
84
85 cons_decl(dz);
86
87 int
88 dz_print(aux, name)
89 void *aux;
90 const char *name;
91 {
92 if (name)
93 printf ("lkc at %s", name);
94 return (UNCONF);
95 }
96
97 static int
98 dz_vsbus_match(parent, cf, aux)
99 struct device *parent;
100 struct cfdata *cf;
101 void *aux;
102 {
103 struct vsbus_attach_args *va = aux;
104 struct ss_dz *dzP;
105 short i;
106
107 dzP = (struct ss_dz *)va->va_addr;
108 i = dzP->tcr;
109 dzP->csr = DZ_CSR_MSE;
110 dzP->tcr = 0;
111 DELAY(1000);
112 dzP->tcr = 1;
113 DELAY(100000);
114 dzP->tcr = i;
115 va->va_ivec = dzxint;
116
117 /* If the device doesn't exist, no interrupt has been generated */
118 return 1;
119 }
120
121 static void
122 dz_vsbus_attach(parent, self, aux)
123 struct device *parent, *self;
124 void *aux;
125 {
126 struct dz_softc *sc = (void *)self;
127 struct vsbus_attach_args *va = aux;
128
129 /*
130 * XXX - This is evil and ugly, but...
131 * due to the nature of how bus_space_* works on VAX, this will
132 * be perfectly good until everything is converted.
133 */
134 sc->sc_ioh = dz_regs;
135 sc->sc_dr.dr_csr = 0;
136 sc->sc_dr.dr_rbuf = 4;
137 sc->sc_dr.dr_dtr = 9;
138 sc->sc_dr.dr_break = 13;
139 sc->sc_dr.dr_tbuf = 12;
140 sc->sc_dr.dr_tcr = 8;
141 sc->sc_dr.dr_dcd = 13;
142 sc->sc_dr.dr_ring = 13;
143
144 sc->sc_type = DZ_DZV;
145
146 sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
147 scb_vecalloc(va->va_cvec - 4, dzrint, self->dv_unit, SCB_ISTACK);
148 printf("\n%s: 4 lines", self->dv_xname);
149
150 dzattach(sc);
151
152 if (((vax_confdata & 0x80) == 0) ||/* workstation, have lkc */
153 (vax_boardtype == VAX_BTYP_48))
154 if (cn_tab->cn_pri > CN_NORMAL) /* Passed cnsl detect */
155 config_found(self, 0, dz_print);
156 }
157
158 int
159 dzcngetc(dev)
160 dev_t dev;
161 {
162 int c = 0;
163 int mino = minor(dev);
164 u_short rbuf;
165
166 do {
167 while ((dz->csr & 0x80) == 0)
168 ; /* Wait for char */
169 rbuf = dz->rbuf;
170 if (((rbuf >> 8) & 3) != mino)
171 continue;
172 c = rbuf & 0x7f;
173 } while (c == 17 || c == 19); /* ignore XON/XOFF */
174
175 if (c == 13)
176 c = 10;
177
178 return (c);
179 }
180
181 #define DZMAJOR 1
182
183 void
184 dzcnprobe(cndev)
185 struct consdev *cndev;
186 {
187 extern vaddr_t iospace;
188 int diagcons;
189
190 switch (vax_boardtype) {
191 case VAX_BTYP_410:
192 case VAX_BTYP_420:
193 case VAX_BTYP_43:
194 diagcons = (vax_confdata & 0x20 ? 3 : 0);
195 break;
196
197 case VAX_BTYP_46:
198 case VAX_BTYP_48:
199 diagcons = (vax_confdata & 0x100 ? 3 : 0);
200 break;
201
202 case VAX_BTYP_49:
203 diagcons = 3;
204 break;
205
206 default:
207 cndev->cn_pri = CN_DEAD;
208 return;
209 }
210 if (diagcons)
211 cndev->cn_pri = CN_REMOTE;
212 else
213 cndev->cn_pri = CN_NORMAL;
214 cndev->cn_dev = makedev(DZMAJOR, diagcons);
215 dz_regs = iospace;
216 ioaccess(iospace, 0x200A0000, 1);
217 }
218
219 void
220 dzcninit(cndev)
221 struct consdev *cndev;
222 {
223 dz = (void*)dz_regs;
224
225 dz->csr = 0; /* Disable scanning until initting is done */
226 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
227 dz->csr = 0x20; /* Turn scanning back on */
228 }
229
230
231 void
232 dzcnputc(dev,ch)
233 dev_t dev;
234 int ch;
235 {
236 int timeout = 1<<15; /* don't hang the machine! */
237 int mino = minor(dev);
238 u_short tcr;
239
240 if (mfpr(PR_MAPEN) == 0)
241 return;
242
243 tcr = dz->tcr; /* remember which lines to scan */
244 dz->tcr = (1 << mino);
245
246 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
247 if (--timeout < 0)
248 break;
249 dz->tdr = ch; /* Put the character */
250 timeout = 1<<15;
251 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
252 if (--timeout < 0)
253 break;
254
255 dz->tcr = tcr;
256 }
257
258 void
259 dzcnpollc(dev, pollflag)
260 dev_t dev;
261 int pollflag;
262 {
263 static u_char mask;
264
265 if (pollflag)
266 mask = vsbus_setmask(0);
267 else
268 vsbus_setmask(mask);
269 }
270
271 #if NLKC
272 cons_decl(lkc);
273
274 void
275 lkccninit(cndev)
276 struct consdev *cndev;
277 {
278 dz = (void*)dz_regs;
279
280 dz->csr = 0; /* Disable scanning until initting is done */
281 dz->tcr = 1; /* Turn off all but line 0's xmitter */
282 dz->rbuf = 0x1c18; /* XXX */
283 dz->csr = 0x20; /* Turn scanning back on */
284 }
285
286 int
287 lkccngetc(dev)
288 dev_t dev;
289 {
290 int lkc_decode(int);
291 int c;
292 // u_char mask;
293
294
295 // mask = vsbus_setmask(0); /* save old state */
296
297 loop:
298 while ((dz->csr & 0x80) == 0)
299 ; /* Wait for char */
300
301 c = lkc_decode(dz->rbuf & 255);
302 if (c < 1)
303 goto loop;
304
305 // vsbus_clrintr(0x80); /* XXX */
306 // vsbus_setmask(mask);
307
308 return (c);
309 }
310 #endif
311