dz_vsbus.c revision 1.6 1 /* $NetBSD: dz_vsbus.c,v 1.6 1998/08/10 14:47:16 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/../vax/gencons.h>
52
53 #include <vax/uba/dzreg.h>
54 #include <vax/uba/dzvar.h>
55
56 #include "ioconf.h"
57 #include "lkc.h"
58
59 static int dz_vsbus_match __P((struct device *, struct cfdata *, void *));
60 static void dz_vsbus_attach __P((struct device *, struct device *, void *));
61 static int dz_print __P((void *, const char *));
62 static void txon __P((void));
63 static void rxon __P((void));
64
65 struct cfattach dz_vsbus_ca = {
66 sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
67 };
68
69 static void
70 rxon()
71 {
72 vsbus_intr_enable(inr_sr);
73 }
74
75 static void
76 txon()
77 {
78 vsbus_intr_enable(inr_st);
79 }
80
81 int
82 dz_print(aux, name)
83 void *aux;
84 const char *name;
85 {
86 if (name)
87 printf ("lkc at %s", name);
88 return (UNCONF);
89 }
90
91 static int
92 dz_vsbus_match(parent, cf, aux)
93 struct device *parent;
94 struct cfdata *cf;
95 void *aux;
96 {
97 struct vsbus_attach_args *va = aux;
98 if (va->va_type == inr_sr)
99 return 1;
100 return 0;
101 }
102
103 static void
104 dz_vsbus_attach(parent, self, aux)
105 struct device *parent, *self;
106 void *aux;
107 {
108 struct dz_softc *sc = (void *)self;
109
110 sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
111 sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
112 sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
113 sc->sc_dr.dr_break = (void *)(dz_regs + 13);
114 sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
115 sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
116 sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
117 sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
118
119 sc->sc_type = DZ_DZV;
120
121 sc->sc_txon = txon;
122 sc->sc_rxon = rxon;
123 sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
124 vsbus_intr_attach(inr_sr, dzrint, 0);
125 vsbus_intr_attach(inr_st, dzxint, 0);
126 printf(": DC367");
127
128 dzattach(sc);
129
130 if ((vax_confdata & 0x80) == 0) /* workstation, have lkc */
131 config_found(self, 0, dz_print);
132 }
133
134 /*----------------------------------------------------------------------*/
135
136 #define REG(name) short name; short X##name##X;
137 static volatile struct {/* base address of DZ-controller: 0x200A0000 */
138 REG(csr); /* 00 Csr: control/status register */
139 REG(rbuf); /* 04 Rbuf/Lpr: receive buffer/line param reg. */
140 REG(tcr); /* 08 Tcr: transmit console register */
141 REG(tdr); /* 0C Msr/Tdr: modem status reg/transmit data reg */
142 REG(lpr0); /* 10 Lpr0: */
143 REG(lpr1); /* 14 Lpr0: */
144 REG(lpr2); /* 18 Lpr0: */
145 REG(lpr3); /* 1C Lpr0: */
146 } *dz = (void*)0x200A0000;
147 #undef REG
148
149 cons_decl(dz);
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 u_char mask;
159
160 mask = vs_cpu->vc_intmsk; /* save old state */
161 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
162
163 do {
164 while ((dz->csr & 0x80) == 0)
165 ; /* Wait for char */
166 rbuf = dz->rbuf;
167 if (((rbuf >> 8) & 3) != mino)
168 continue;
169 c = rbuf & 0x7f;
170 } while (c == 17 || c == 19); /* ignore XON/XOFF */
171
172 if (c == 13)
173 c = 10;
174
175 vs_cpu->vc_intclr = 0x80; /* clear te interrupt request */
176 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
177
178 return (c);
179 }
180
181 #define DZMAJOR 1
182
183 void
184 dzcnprobe(cndev)
185 struct consdev *cndev;
186 {
187
188 switch (vax_boardtype) {
189 case VAX_BTYP_410:
190 case VAX_BTYP_420:
191 case VAX_BTYP_43:
192 case VAX_BTYP_46:
193 cndev->cn_dev = makedev(DZMAJOR, 3);
194 cndev->cn_pri = CN_NORMAL;
195 break;
196
197 default:
198 cndev->cn_pri = CN_DEAD;
199 break;
200 }
201
202 return;
203 }
204
205 void
206 dzcninit(cndev)
207 struct consdev *cndev;
208 {
209 dz = (void*)dz_regs;
210
211 dz->csr = 0; /* Disable scanning until initting is done */
212 dz->tcr = 8; /* Turn off all but line 3's xmitter */
213 dz->csr = 0x20; /* Turn scanning back on */
214 }
215
216
217 void
218 dzcnputc(dev,ch)
219 dev_t dev;
220 int ch;
221 {
222 int timeout = 1<<15; /* don't hang the machine! */
223 int mino = minor(dev);
224 u_short tcr;
225 u_char mask;
226
227 if (mfpr(PR_MAPEN) == 0)
228 return;
229
230 mask = vs_cpu->vc_intmsk; /* save old state */
231 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
232 tcr = dz->tcr; /* remember which lines to scan */
233 dz->tcr = (1 << mino);
234
235 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
236 if (--timeout < 0)
237 break;
238 dz->tdr = ch; /* Put the character */
239
240 dz->tcr = tcr;
241 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
242 }
243
244 void
245 dzcnpollc(dev, pollflag)
246 dev_t dev;
247 int pollflag;
248 {
249 }
250
251 #if NLKC
252 cons_decl(lkc);
253
254 void
255 lkccninit(cndev)
256 struct consdev *cndev;
257 {
258 dz = (void*)dz_regs;
259
260 dz->csr = 0; /* Disable scanning until initting is done */
261 dz->tcr = 1; /* Turn off all but line 0's xmitter */
262 dz->rbuf = 0x1c18; /* XXX */
263 dz->csr = 0x20; /* Turn scanning back on */
264 }
265
266 int
267 lkccngetc(dev)
268 dev_t dev;
269 {
270 int lkc_decode(int);
271 int c;
272 u_char mask;
273
274 mask = vs_cpu->vc_intmsk; /* save old state */
275 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
276
277 loop:
278 while ((dz->csr & 0x80) == 0)
279 ; /* Wait for char */
280
281 c = lkc_decode(dz->rbuf & 255);
282 if (c < 1)
283 goto loop;
284
285 vs_cpu->vc_intclr = 0x80; /* clear te interrupt request */
286 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
287
288 return (c);
289 }
290 #endif
291