dz_vsbus.c revision 1.1 1 /* $NetBSD: dz_vsbus.c,v 1.1 1998/05/17 18:52:34 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
58 static int dz_vsbus_match __P((struct device *, struct cfdata *, void *));
59 static void dz_vsbus_attach __P((struct device *, struct device *, void *));
60 static void txon __P((void));
61 static void rxon __P((void));
62
63 struct cfattach dz_vsbus_ca = {
64 sizeof(struct dz_softc), dz_vsbus_match, dz_vsbus_attach
65 };
66
67 static void
68 rxon()
69 {
70 vsbus_intr_enable(INR_SR);
71 }
72
73 static void
74 txon()
75 {
76 vsbus_intr_enable(INR_ST);
77 }
78
79 static int
80 dz_vsbus_match(parent, cf, aux)
81 struct device *parent;
82 struct cfdata *cf;
83 void *aux;
84 {
85 struct vsbus_attach_args *va = aux;
86 if (va->va_type == INR_SR)
87 return 1;
88 return 0;
89 }
90
91 static void
92 dz_vsbus_attach(parent, self, aux)
93 struct device *parent, *self;
94 void *aux;
95 {
96 struct dz_softc *sc = (void *)self;
97
98 sc->sc_dr.dr_csr = (void *)(dz_regs + 0);
99 sc->sc_dr.dr_rbuf = (void *)(dz_regs + 4);
100 sc->sc_dr.dr_dtr = (void *)(dz_regs + 9);
101 sc->sc_dr.dr_break = (void *)(dz_regs + 13);
102 sc->sc_dr.dr_tbuf = (void *)(dz_regs + 12);
103 sc->sc_dr.dr_tcr = (void *)(dz_regs + 8);
104 sc->sc_dr.dr_dcd = (void *)(dz_regs + 13);
105 sc->sc_dr.dr_ring = (void *)(dz_regs + 13);
106
107 sc->sc_type = DZ_DZV;
108
109 sc->sc_txon = txon;
110 sc->sc_rxon = rxon;
111 sc->sc_dsr = 0x0d; /* XXX check if VS has modem ctrl bits */
112 vsbus_intr_attach(INR_SR, dzrint, 0);
113 vsbus_intr_attach(INR_ST, dzxint, 0);
114 printf(": DC367");
115
116 dzattach(sc);
117 }
118
119 /*----------------------------------------------------------------------*/
120
121 #define REG(name) short name; short X##name##X;
122 static volatile struct {/* base address of DZ-controller: 0x200A0000 */
123 REG(csr); /* 00 Csr: control/status register */
124 REG(rbuf); /* 04 Rbuf/Lpr: receive buffer/line param reg. */
125 REG(tcr); /* 08 Tcr: transmit console register */
126 REG(tdr); /* 0C Msr/Tdr: modem status reg/transmit data reg */
127 REG(lpr0); /* 10 Lpr0: */
128 REG(lpr1); /* 14 Lpr0: */
129 REG(lpr2); /* 18 Lpr0: */
130 REG(lpr3); /* 1C Lpr0: */
131 } *dz = (void*)0x200A0000;
132 #undef REG
133
134 cons_decl(dz);
135
136 int
137 dzcngetc(dev)
138 dev_t dev;
139 {
140 int c;
141
142 do {
143 while ((dz->csr & 0x80) == 0)
144 ; /* Wait for char */
145 c = dz->rbuf & 0x7f;
146 } while (c == 17 || c == 19); /* ignore XON/XOFF */
147
148 if (c == 13)
149 c = 10;
150 return (c);
151 }
152
153 #define DZMAJOR 1
154
155 void
156 dzcnprobe(cndev)
157 struct consdev *cndev;
158 {
159
160 switch (vax_boardtype) {
161 case VAX_BTYP_410:
162 case VAX_BTYP_420:
163 case VAX_BTYP_43:
164 cndev->cn_dev = makedev(DZMAJOR, 3);
165 cndev->cn_pri = CN_NORMAL;
166 break;
167
168 default:
169 cndev->cn_pri = CN_DEAD;
170 break;
171 }
172
173 return;
174 }
175
176 void
177 dzcninit(cndev)
178 struct consdev *cndev;
179 {
180 dz = (void*)dz_regs;
181
182 dz->csr = 0; /* Disable scanning until initting is done */
183 dz->rbuf = 0; /* Turn off line 0's receiver */
184 dz->rbuf = 1; /* Turn off line 1's receiver */
185 dz->rbuf = 2; /* Turn off line 2's receiver */
186 /* Leave line 3 alone */
187 dz->tcr = 8; /* Turn off all but line 3's xmitter */
188 dz->csr = 0x20; /* Turn scanning back on */
189 }
190
191
192 void
193 dzcnputc(dev,ch)
194 dev_t dev;
195 int ch;
196 {
197 int timeout = 1<<15; /* don't hang the machine! */
198
199 if (mfpr(PR_MAPEN) == 0)
200 return;
201
202 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
203 if (--timeout < 0)
204 break;
205 dz->tdr = ch; /* Put the character */
206 }
207