dz_vsbus.c revision 1.12 1 /* $NetBSD: dz_vsbus.c,v 1.12 1999/05/20 23:00:58 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 if (cn_tab->cn_pri > CN_NORMAL) /* Passed cnsl detect */
149 config_found(self, 0, dz_print);
150 }
151
152 int
153 dzcngetc(dev)
154 dev_t dev;
155 {
156 int c = 0;
157 int mino = minor(dev);
158 u_short rbuf;
159
160 do {
161 while ((dz->csr & 0x80) == 0)
162 ; /* Wait for char */
163 rbuf = dz->rbuf;
164 if (((rbuf >> 8) & 3) != mino)
165 continue;
166 c = rbuf & 0x7f;
167 } while (c == 17 || c == 19); /* ignore XON/XOFF */
168
169 if (c == 13)
170 c = 10;
171
172 return (c);
173 }
174
175 #define DZMAJOR 1
176
177 void
178 dzcnprobe(cndev)
179 struct consdev *cndev;
180 {
181 extern vaddr_t iospace;
182 int diagcons;
183
184 switch (vax_boardtype) {
185 case VAX_BTYP_410:
186 case VAX_BTYP_420:
187 case VAX_BTYP_43:
188 diagcons = (vax_confdata & 0x20 ? 3 : 0);
189 break;
190
191 case VAX_BTYP_46:
192 case VAX_BTYP_48:
193 diagcons = (vax_confdata & 0x100 ? 3 : 0);
194 break;
195
196 case VAX_BTYP_49:
197 diagcons = 3;
198 break;
199
200 default:
201 cndev->cn_pri = CN_DEAD;
202 return;
203 }
204 if (diagcons)
205 cndev->cn_pri = CN_REMOTE;
206 else
207 cndev->cn_pri = CN_NORMAL;
208 cndev->cn_dev = makedev(DZMAJOR, diagcons);
209 dz_regs = iospace;
210 ioaccess(iospace, 0x200A0000, 1);
211 }
212
213 void
214 dzcninit(cndev)
215 struct consdev *cndev;
216 {
217 dz = (void*)dz_regs;
218
219 dz->csr = 0; /* Disable scanning until initting is done */
220 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
221 dz->csr = 0x20; /* Turn scanning back on */
222 }
223
224
225 void
226 dzcnputc(dev,ch)
227 dev_t dev;
228 int ch;
229 {
230 int timeout = 1<<15; /* don't hang the machine! */
231 int mino = minor(dev);
232 u_short tcr;
233
234 if (mfpr(PR_MAPEN) == 0)
235 return;
236
237 tcr = dz->tcr; /* remember which lines to scan */
238 dz->tcr = (1 << mino);
239
240 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
241 if (--timeout < 0)
242 break;
243 dz->tdr = ch; /* Put the character */
244 timeout = 1<<15;
245 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
246 if (--timeout < 0)
247 break;
248
249 dz->tcr = tcr;
250 }
251
252 void
253 dzcnpollc(dev, pollflag)
254 dev_t dev;
255 int pollflag;
256 {
257 static u_char mask;
258
259 if (pollflag)
260 mask = vsbus_setmask(0);
261 else
262 vsbus_setmask(mask);
263 }
264
265 #if NLKC
266 cons_decl(lkc);
267
268 void
269 lkccninit(cndev)
270 struct consdev *cndev;
271 {
272 dz = (void*)dz_regs;
273
274 dz->csr = 0; /* Disable scanning until initting is done */
275 dz->tcr = 1; /* Turn off all but line 0's xmitter */
276 dz->rbuf = 0x1c18; /* XXX */
277 dz->csr = 0x20; /* Turn scanning back on */
278 }
279
280 int
281 lkccngetc(dev)
282 dev_t dev;
283 {
284 int lkc_decode(int);
285 int c;
286 // u_char mask;
287
288
289 // mask = vsbus_setmask(0); /* save old state */
290
291 loop:
292 while ((dz->csr & 0x80) == 0)
293 ; /* Wait for char */
294
295 c = lkc_decode(dz->rbuf & 255);
296 if (c < 1)
297 goto loop;
298
299 // vsbus_clrintr(0x80); /* XXX */
300 // vsbus_setmask(mask);
301
302 return (c);
303 }
304 #endif
305