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