dz_vsbus.c revision 1.22.2.1 1 /* $NetBSD: dz_vsbus.c,v 1.22.2.1 2002/05/19 07:56:32 gehenna 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 <arch/vax/vax/gencons.h>
55
56 #include <dev/dec/dzreg.h>
57 #include <dev/dec/dzvar.h>
58
59 #include "ioconf.h"
60 #include "dzkbd.h"
61 #include "dzms.h"
62 #include "opt_cputype.h"
63
64 #if NDZKBD > 0 || NDZMS > 0
65 #include <dev/dec/dzkbdvar.h>
66
67 #if 0
68 static struct dz_linestate dz_conslinestate = { NULL, -1, NULL, NULL, NULL };
69 #endif
70 #endif
71
72 static int dz_vsbus_match(struct device *, struct cfdata *, void *);
73 static void dz_vsbus_attach(struct device *, struct device *, void *);
74
75 static vaddr_t dz_regs; /* Used for console */
76
77 struct cfattach dz_vsbus_ca = {
78 sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
79 };
80
81 #define REG(name) short name; short X##name##X;
82 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
83 REG(csr); /* 00 Csr: control/status register */
84 REG(rbuf); /* 04 Rbuf/Lpr: receive buffer/line param reg. */
85 REG(tcr); /* 08 Tcr: transmit console register */
86 REG(tdr); /* 0C Msr/Tdr: modem status reg/transmit data reg */
87 REG(lpr0); /* 10 Lpr0: */
88 REG(lpr1); /* 14 Lpr0: */
89 REG(lpr2); /* 18 Lpr0: */
90 REG(lpr3); /* 1C Lpr0: */
91 } *dz;
92 #undef REG
93
94 cons_decl(dz);
95
96 #if NDZKBD > 0 || NDZMS > 0
97 static int
98 dz_print(void *aux, const char *name)
99 {
100 #if 0
101 #if NDZKBD > 0 || NDZMS > 0
102 struct dz_attach_args *dz_args = aux;
103 if (name == NULL) {
104 printf (" line %d", dz_args->line);
105 if (dz_args->hwflags & DZ_HWFLAG_CONSOLE)
106 printf (" (console)");
107 }
108 return (QUIET);
109 #else
110 if (name)
111 printf ("lkc at %s", name);
112 return (UNCONF);
113 #endif
114 #endif
115 return (UNCONF);
116 }
117 #endif
118
119 static int
120 dz_vsbus_match(struct device *parent, struct cfdata *cf, void *aux)
121 {
122 struct vsbus_attach_args *va = aux;
123 struct ss_dz *dzP;
124 short i;
125
126 #if VAX53 || VAX49 || VAXANY
127 if (vax_boardtype == VAX_BTYP_53 || vax_boardtype == VAX_BTYP_49)
128 if (cf->cf_loc[0] != 0x25000000)
129 return 0; /* Ugly */
130 #endif
131
132 dzP = (struct ss_dz *)va->va_addr;
133 i = dzP->tcr;
134 dzP->csr = DZ_CSR_MSE|DZ_CSR_TXIE;
135 dzP->tcr = 0;
136 DELAY(1000);
137 dzP->tcr = 1;
138 DELAY(100000);
139 dzP->tcr = i;
140
141 /* If the device doesn't exist, no interrupt has been generated */
142 return 1;
143 }
144
145 static void
146 dz_vsbus_attach(struct device *parent, struct device *self, void *aux)
147 {
148 struct dz_softc *sc = (void *)self;
149 struct vsbus_attach_args *va = aux;
150 #if NDZKBD > 0
151 extern const struct cdevsw dz_cdevsw;
152 #endif
153 #if NDZKBD > 0 || NDZMS > 0
154 struct dzkm_attach_args daa;
155 #endif
156 int s;
157
158 /*
159 * XXX - This is evil and ugly, but...
160 * due to the nature of how bus_space_* works on VAX, this will
161 * be perfectly good until everything is converted.
162 */
163 if (dz_regs == 0) /* This isn't console */
164 dz_regs = vax_map_physmem(va->va_paddr, 1);
165 sc->sc_ioh = dz_regs;
166 sc->sc_dr.dr_csr = 0;
167 sc->sc_dr.dr_rbuf = 4;
168 sc->sc_dr.dr_dtr = 9;
169 sc->sc_dr.dr_break = 13;
170 sc->sc_dr.dr_tbuf = 12;
171 sc->sc_dr.dr_tcr = 8;
172 sc->sc_dr.dr_dcd = 13;
173 sc->sc_dr.dr_ring = 13;
174
175 sc->sc_type = DZ_DZV;
176
177 sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
178
179 scb_vecalloc(va->va_cvec, dzxint, sc, SCB_ISTACK, &sc->sc_tintrcnt);
180 scb_vecalloc(va->va_cvec - 4, dzrint, sc, SCB_ISTACK, &sc->sc_rintrcnt);
181
182 printf("\n%s: 4 lines", self->dv_xname);
183
184 dzattach(sc, NULL);
185 DELAY(10000);
186
187 #if NDZKBD > 0
188 /* Don't change speed if this is the console */
189 if (cn_tab->cn_dev != makedev(cdevsw_lookup_major(&dz_cdevsw), 0))
190 dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8)
191 | DZ_LPR_8_BIT_CHAR;
192 daa.daa_line = 0;
193 daa.daa_flags = (cn_tab->cn_pri == CN_INTERNAL ? DZKBD_CONSOLE : 0);
194 config_found(self, &daa, dz_print);
195 #endif
196 #if NDZMS > 0
197 dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) | DZ_LPR_7_BIT_CHAR \
198 | DZ_LPR_PARENB | DZ_LPR_OPAR | 1 /* line */;
199 daa.daa_line = 1;
200 daa.daa_flags = 0;
201 config_found(self, &daa, dz_print);
202 #endif
203 s = spltty();
204 dzrint(sc);
205 dzxint(sc);
206 splx(s);
207 }
208
209 int
210 dzcngetc(dev_t dev)
211 {
212 int c = 0;
213 int mino = minor(dev);
214 u_short rbuf;
215
216 do {
217 while ((dz->csr & 0x80) == 0)
218 ; /* Wait for char */
219 rbuf = dz->rbuf;
220 if (((rbuf >> 8) & 3) != mino)
221 continue;
222 c = rbuf & 0x7f;
223 } while (c == 17 || c == 19); /* ignore XON/XOFF */
224
225 if (c == 13)
226 c = 10;
227
228 return (c);
229 }
230
231 void
232 dzcnprobe(struct consdev *cndev)
233 {
234 extern vaddr_t iospace;
235 int diagcons;
236 paddr_t ioaddr = 0x200A0000;
237 extern const struct cdevsw dz_cdevsw;
238
239 switch (vax_boardtype) {
240 case VAX_BTYP_410:
241 case VAX_BTYP_420:
242 case VAX_BTYP_43:
243 diagcons = (vax_confdata & 0x20 ? 3 : 0);
244 break;
245
246 case VAX_BTYP_46:
247 case VAX_BTYP_48:
248 diagcons = (vax_confdata & 0x100 ? 3 : 0);
249 break;
250
251 case VAX_BTYP_49:
252 case VAX_BTYP_53:
253 ioaddr = 0x25000000;
254 diagcons = 3;
255 break;
256
257 default:
258 cndev->cn_pri = CN_DEAD;
259 return;
260 }
261 if (diagcons)
262 cndev->cn_pri = CN_REMOTE;
263 else
264 cndev->cn_pri = CN_NORMAL;
265 cndev->cn_dev = makedev(cdevsw_lookup_major(&dz_cdevsw), diagcons);
266 (vaddr_t)dz = dz_regs = iospace;
267 ioaccess(iospace, ioaddr, 1);
268 }
269
270 void
271 dzcninit(struct consdev *cndev)
272 {
273 dz = (void*)dz_regs;
274
275 dz->csr = 0; /* Disable scanning until initting is done */
276 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
277 dz->csr = 0x20; /* Turn scanning back on */
278 }
279
280
281 void
282 dzcnputc(dev_t dev, int ch)
283 {
284 int timeout = 1<<15; /* don't hang the machine! */
285 int mino = minor(dev);
286 u_short tcr;
287
288 if (mfpr(PR_MAPEN) == 0)
289 return;
290
291 tcr = dz->tcr; /* remember which lines to scan */
292 dz->tcr = (1 << mino);
293
294 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
295 if (--timeout < 0)
296 break;
297 dz->tdr = ch; /* Put the character */
298 timeout = 1<<15;
299 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
300 if (--timeout < 0)
301 break;
302
303 dz->tcr = tcr;
304 }
305
306 void
307 dzcnpollc(dev_t dev, int pollflag)
308 {
309 static u_char mask;
310
311 if (pollflag)
312 mask = vsbus_setmask(0);
313 else
314 vsbus_setmask(mask);
315 }
316
317 #if NDZKBD > 0 || NDZMS > 0
318 int
319 dzgetc(struct dz_linestate *ls)
320 {
321 int line = ls->dz_line;
322 u_short rbuf;
323
324 for (;;) {
325 for(; (dz->csr & DZ_CSR_RX_DONE) == 0;);
326 rbuf = dz->rbuf;
327 if (((rbuf >> 8) & 3) == line)
328 return (rbuf & 0xff);
329 }
330 }
331
332 void
333 dzputc(struct dz_linestate *ls, int ch)
334 {
335 int line = 0; /* = ls->dz_line; */
336 u_short tcr;
337 int s;
338 extern const struct cdevsw dz_cdevsw;
339
340 /* if the dz has already been attached, the MI
341 driver will do the transmitting: */
342 if (ls && ls->dz_sc) {
343 s = spltty();
344 putc(ch, &ls->dz_sc->sc_dz[line].dz_tty->t_outq);
345 tcr = dz->tcr;
346 if (!(tcr & (1 << line)))
347 dz->tcr = tcr | (1 << line);
348 dzxint(ls->dz_sc);
349 splx(s);
350 return;
351 }
352
353 /* use dzcnputc to do the transmitting: */
354 dzcnputc(makedev(cdevsw_lookup_major(&dz_cdevsw), line), ch);
355 }
356 #endif /* NDZKBD > 0 || NDZMS > 0 */
357