dz_vsbus.c revision 1.10 1 /* $NetBSD: dz_vsbus.c,v 1.10 1999/03/26 22:04:07 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 <vax/uba/dzreg.h>
57 #include <vax/uba/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 sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
130 sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
131 sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
132 sc->sc_dr.dr_break = (void *)(dz_regs + 13);
133 sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
134 sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
135 sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
136 sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
137
138 sc->sc_type = DZ_DZV;
139
140 sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
141 scb_vecalloc(va->va_cvec - 4, dzrint, self->dv_unit, SCB_ISTACK);
142 printf("\n%s: 4 lines", self->dv_xname);
143
144 dzattach(sc);
145
146 if (((vax_confdata & 0x80) == 0) ||/* workstation, have lkc */
147 (vax_boardtype == VAX_BTYP_48))
148 config_found(self, 0, dz_print);
149 }
150
151 int
152 dzcngetc(dev)
153 dev_t dev;
154 {
155 int c = 0;
156 int mino = minor(dev);
157 u_short rbuf;
158
159 do {
160 while ((dz->csr & 0x80) == 0)
161 ; /* Wait for char */
162 rbuf = dz->rbuf;
163 if (((rbuf >> 8) & 3) != mino)
164 continue;
165 c = rbuf & 0x7f;
166 } while (c == 17 || c == 19); /* ignore XON/XOFF */
167
168 if (c == 13)
169 c = 10;
170
171 return (c);
172 }
173
174 #define DZMAJOR 1
175
176 void
177 dzcnprobe(cndev)
178 struct consdev *cndev;
179 {
180 extern vaddr_t iospace;
181 int pri = CN_NORMAL, min = 0;
182
183 switch (vax_boardtype) {
184 case VAX_BTYP_410:
185 case VAX_BTYP_420:
186 case VAX_BTYP_43:
187 if (vax_confdata & 0x20) {
188 min = 3;
189 pri = CN_REMOTE;
190 }
191 break;
192
193 case VAX_BTYP_46:
194 /* if (vax_confdata & 0x100) */
195 min = 3;
196 break;
197
198 case VAX_BTYP_49:
199 case VAX_BTYP_48:
200 min = 3;
201 break;
202
203 default:
204 pri = CN_DEAD;
205 break;
206 }
207 cndev->cn_pri = pri;
208 if (pri != CN_DEAD) {
209 cndev->cn_dev = makedev(DZMAJOR, min);
210 dz_regs = iospace;
211 ioaccess(iospace, 0x200A0000, 1);
212 }
213 }
214
215 void
216 dzcninit(cndev)
217 struct consdev *cndev;
218 {
219 dz = (void*)dz_regs;
220
221 dz->csr = 0; /* Disable scanning until initting is done */
222 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
223 dz->csr = 0x20; /* Turn scanning back on */
224 }
225
226
227 void
228 dzcnputc(dev,ch)
229 dev_t dev;
230 int ch;
231 {
232 int timeout = 1<<15; /* don't hang the machine! */
233 int mino = minor(dev);
234 u_short tcr;
235
236 if (mfpr(PR_MAPEN) == 0)
237 return;
238
239 tcr = dz->tcr; /* remember which lines to scan */
240 dz->tcr = (1 << mino);
241
242 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
243 if (--timeout < 0)
244 break;
245 dz->tdr = ch; /* Put the character */
246 timeout = 1<<15;
247 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
248 if (--timeout < 0)
249 break;
250
251 dz->tcr = tcr;
252 }
253
254 void
255 dzcnpollc(dev, pollflag)
256 dev_t dev;
257 int pollflag;
258 {
259 static u_char mask;
260
261 if (pollflag)
262 mask = vsbus_setmask(0);
263 else
264 vsbus_setmask(mask);
265 }
266
267 #if NLKC
268 cons_decl(lkc);
269
270 void
271 lkccninit(cndev)
272 struct consdev *cndev;
273 {
274 dz = (void*)dz_regs;
275
276 dz->csr = 0; /* Disable scanning until initting is done */
277 dz->tcr = 1; /* Turn off all but line 0's xmitter */
278 dz->rbuf = 0x1c18; /* XXX */
279 dz->csr = 0x20; /* Turn scanning back on */
280 }
281
282 int
283 lkccngetc(dev)
284 dev_t dev;
285 {
286 int lkc_decode(int);
287 int c;
288 // u_char mask;
289
290
291 // mask = vsbus_setmask(0); /* save old state */
292
293 loop:
294 while ((dz->csr & 0x80) == 0)
295 ; /* Wait for char */
296
297 c = lkc_decode(dz->rbuf & 255);
298 if (c < 1)
299 goto loop;
300
301 // vsbus_clrintr(0x80); /* XXX */
302 // vsbus_setmask(mask);
303
304 return (c);
305 }
306 #endif
307