dz_vsbus.c revision 1.5 1 /* $NetBSD: dz_vsbus.c,v 1.5 1998/06/07 20:19:12 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;
156 u_char mask;
157
158 mask = vs_cpu->vc_intmsk; /* save old state */
159 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
160
161 do {
162 while ((dz->csr & 0x80) == 0)
163 ; /* Wait for char */
164 c = dz->rbuf & 0x7f;
165 } while (c == 17 || c == 19); /* ignore XON/XOFF */
166
167 if (c == 13)
168 c = 10;
169
170 vs_cpu->vc_intclr = 0x80; /* clear te interrupt request */
171 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
172
173 return (c);
174 }
175
176 #define DZMAJOR 1
177
178 void
179 dzcnprobe(cndev)
180 struct consdev *cndev;
181 {
182
183 switch (vax_boardtype) {
184 case VAX_BTYP_410:
185 case VAX_BTYP_420:
186 case VAX_BTYP_43:
187 cndev->cn_dev = makedev(DZMAJOR, 3);
188 cndev->cn_pri = CN_NORMAL;
189 break;
190
191 default:
192 cndev->cn_pri = CN_DEAD;
193 break;
194 }
195
196 return;
197 }
198
199 void
200 dzcninit(cndev)
201 struct consdev *cndev;
202 {
203 dz = (void*)dz_regs;
204
205 dz->csr = 0; /* Disable scanning until initting is done */
206 dz->tcr = 8; /* Turn off all but line 3's xmitter */
207 dz->csr = 0x20; /* Turn scanning back on */
208 }
209
210
211 void
212 dzcnputc(dev,ch)
213 dev_t dev;
214 int ch;
215 {
216 int timeout = 1<<15; /* don't hang the machine! */
217 u_short tcr;
218 u_char mask;
219
220 if (mfpr(PR_MAPEN) == 0)
221 return;
222
223 mask = vs_cpu->vc_intmsk; /* save old state */
224 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
225 tcr = dz->tcr; /* remember which lines to scan */
226 dz->tcr = 8; /* XXX */
227
228 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
229 if (--timeout < 0)
230 break;
231 dz->tdr = ch; /* Put the character */
232
233 dz->tcr = tcr;
234 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
235 }
236
237 void
238 dzcnpollc(dev, pollflag)
239 dev_t dev;
240 int pollflag;
241 {
242 }
243
244 #if NLKC
245 cons_decl(lkc);
246
247 void
248 lkccninit(cndev)
249 struct consdev *cndev;
250 {
251 dz = (void*)dz_regs;
252
253 dz->csr = 0; /* Disable scanning until initting is done */
254 dz->tcr = 1; /* Turn off all but line 0's xmitter */
255 dz->rbuf = 0x1c18; /* XXX */
256 dz->csr = 0x20; /* Turn scanning back on */
257 }
258
259 int
260 lkccngetc(dev)
261 dev_t dev;
262 {
263 int lkc_decode(int);
264 int c;
265 u_char mask;
266
267 mask = vs_cpu->vc_intmsk; /* save old state */
268 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
269
270 loop:
271 while ((dz->csr & 0x80) == 0)
272 ; /* Wait for char */
273
274 c = lkc_decode(dz->rbuf & 255);
275 if (c < 1)
276 goto loop;
277
278 vs_cpu->vc_intclr = 0x80; /* clear te interrupt request */
279 vs_cpu->vc_intmsk = mask; /* restore interrupt mask */
280
281 return (c);
282 }
283 #endif
284