dz_ibus.c revision 1.7 1 1.7 matt /* $NetBSD: dz_ibus.c,v 1.7 2008/03/15 00:57:15 matt Exp $ */
2 1.2 ad
3 1.2 ad /*-
4 1.2 ad * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 1.2 ad * All rights reserved.
6 1.2 ad *
7 1.2 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.2 ad * by Andrew Doran.
9 1.2 ad *
10 1.2 ad * Redistribution and use in source and binary forms, with or without
11 1.2 ad * modification, are permitted provided that the following conditions
12 1.2 ad * are met:
13 1.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.2 ad * notice, this list of conditions and the following disclaimer.
15 1.2 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 ad * notice, this list of conditions and the following disclaimer in the
17 1.2 ad * documentation and/or other materials provided with the distribution.
18 1.2 ad * 3. All advertising materials mentioning features or use of this software
19 1.2 ad * must display the following acknowledgement:
20 1.2 ad * This product includes software developed by the NetBSD
21 1.2 ad * Foundation, Inc. and its contributors.
22 1.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 ad * contributors may be used to endorse or promote products derived
24 1.2 ad * from this software without specific prior written permission.
25 1.2 ad *
26 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.2 ad */
38 1.2 ad
39 1.2 ad /*
40 1.2 ad * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
41 1.2 ad * All rights reserved.
42 1.2 ad *
43 1.2 ad * Redistribution and use in source and binary forms, with or without
44 1.2 ad * modification, are permitted provided that the following conditions
45 1.2 ad * are met:
46 1.2 ad * 1. Redistributions of source code must retain the above copyright
47 1.2 ad * notice, this list of conditions and the following disclaimer.
48 1.2 ad * 2. Redistributions in binary form must reproduce the above copyright
49 1.2 ad * notice, this list of conditions and the following disclaimer in the
50 1.2 ad * documentation and/or other materials provided with the distribution.
51 1.2 ad * 3. All advertising materials mentioning features or use of this software
52 1.2 ad * must display the following acknowledgement:
53 1.2 ad * This product includes software developed at Ludd, University of
54 1.2 ad * Lule}, Sweden and its contributors.
55 1.2 ad * 4. The name of the author may not be used to endorse or promote products
56 1.2 ad * derived from this software without specific prior written permission
57 1.2 ad *
58 1.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 1.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 1.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 1.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 1.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 1.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 1.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 1.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.2 ad */
69 1.2 ad
70 1.2 ad #include <sys/cdefs.h>
71 1.7 matt __KERNEL_RCSID(0, "$NetBSD: dz_ibus.c,v 1.7 2008/03/15 00:57:15 matt Exp $");
72 1.2 ad
73 1.2 ad #include "dzkbd.h"
74 1.2 ad #include "dzms.h"
75 1.2 ad
76 1.2 ad #include <sys/param.h>
77 1.2 ad #include <sys/proc.h>
78 1.2 ad #include <sys/systm.h>
79 1.2 ad #include <sys/ioctl.h>
80 1.2 ad #include <sys/tty.h>
81 1.2 ad #include <sys/file.h>
82 1.2 ad #include <sys/conf.h>
83 1.2 ad #include <sys/device.h>
84 1.2 ad #include <sys/reboot.h>
85 1.2 ad
86 1.2 ad #include <machine/bus.h>
87 1.2 ad
88 1.2 ad #include <dev/cons.h>
89 1.2 ad
90 1.2 ad #include <dev/tc/tcvar.h> /* tc_addr_t */
91 1.2 ad
92 1.2 ad #include <dev/dec/dzreg.h>
93 1.2 ad #include <dev/dec/dzvar.h>
94 1.2 ad #include <dev/dec/dzkbdvar.h>
95 1.2 ad
96 1.2 ad #include <pmax/ibus/ibusvar.h>
97 1.2 ad #include <pmax/pmax/pmaxtype.h>
98 1.2 ad #include <pmax/pmax/cons.h>
99 1.2 ad
100 1.2 ad #define DZ_LINE_KBD 0
101 1.2 ad #define DZ_LINE_MOUSE 1
102 1.2 ad #define DZ_LINE_CONSOLE 2
103 1.2 ad #define DZ_LINE_AUX 3
104 1.2 ad
105 1.7 matt int dz_ibus_match(device_t, cfdata_t, void *);
106 1.7 matt void dz_ibus_attach(device_t, device_t, void *);
107 1.2 ad int dz_ibus_intr(void *);
108 1.2 ad void dz_ibus_cnsetup(paddr_t);
109 1.2 ad int dz_ibus_cngetc(dev_t);
110 1.2 ad void dz_ibus_cnputc(dev_t, int);
111 1.2 ad void dz_ibus_cnpollc(dev_t, int);
112 1.2 ad int dz_ibus_getmajor(void);
113 1.2 ad int dz_ibus_print(void *, const char *);
114 1.2 ad
115 1.2 ad int dzgetc(struct dz_linestate *);
116 1.2 ad void dzputc(struct dz_linestate *, int);
117 1.2 ad
118 1.7 matt CFATTACH_DECL_NEW(dz_ibus, sizeof(struct dz_softc),
119 1.2 ad dz_ibus_match, dz_ibus_attach, NULL, NULL);
120 1.2 ad
121 1.2 ad struct consdev dz_ibus_consdev = {
122 1.2 ad NULL, NULL, dz_ibus_cngetc, dz_ibus_cnputc,
123 1.2 ad dz_ibus_cnpollc, NULL, NULL, NULL, NODEV, CN_NORMAL,
124 1.2 ad };
125 1.2 ad
126 1.2 ad struct dzregs {
127 1.2 ad uint16_t csr; /* 00 Csr: control/status */
128 1.2 ad uint16_t p0[3];
129 1.2 ad
130 1.2 ad uint16_t rbuf; /* 08 Rbuf/Lpr: receive buffer/line param */
131 1.2 ad uint16_t p1[3];
132 1.2 ad
133 1.2 ad uint16_t tcr; /* 10 Tcr: transmit console */
134 1.2 ad uint16_t p2[3];
135 1.2 ad
136 1.2 ad uint16_t tdr; /* 18 Msr/Tdr: modem status reg/xmit data */
137 1.2 ad uint16_t p3[3];
138 1.2 ad } volatile *dzcn;
139 1.2 ad
140 1.2 ad int dz_ibus_iscn;
141 1.2 ad int dz_ibus_consln = -1;
142 1.2 ad
143 1.2 ad int
144 1.7 matt dz_ibus_match(device_t parent, cfdata_t cf, void *aux)
145 1.2 ad {
146 1.2 ad struct ibus_attach_args *iba;
147 1.2 ad
148 1.2 ad iba = aux;
149 1.2 ad
150 1.2 ad if (strcmp(iba->ia_name, "dc") != 0 &&
151 1.2 ad strcmp(iba->ia_name, "mdc") != 0 &&
152 1.2 ad strcmp(iba->ia_name, "dc7085") != 0)
153 1.2 ad return (0);
154 1.2 ad
155 1.4 christos if (badaddr((void *)iba->ia_addr, 2))
156 1.2 ad return (0);
157 1.2 ad
158 1.2 ad return (1);
159 1.2 ad }
160 1.2 ad
161 1.2 ad void
162 1.7 matt dz_ibus_attach(device_t parent, device_t self, void *aux)
163 1.2 ad {
164 1.7 matt struct ibus_attach_args *iba = aux;
165 1.7 matt struct dz_softc *sc = device_private(self);
166 1.2 ad volatile struct dzregs *dz;
167 1.2 ad struct dzkm_attach_args daa;
168 1.2 ad int i;
169 1.2 ad
170 1.2 ad
171 1.2 ad DELAY(100000);
172 1.2 ad
173 1.2 ad /*
174 1.2 ad * XXX - This is evil and ugly, but... due to the nature of how
175 1.2 ad * bus_space_* works on pmax it will do for the time being.
176 1.2 ad */
177 1.2 ad sc->sc_ioh = (bus_space_handle_t)MIPS_PHYS_TO_KSEG1(iba->ia_addr);
178 1.2 ad
179 1.2 ad sc->sc_dr.dr_csr = 0;
180 1.2 ad sc->sc_dr.dr_rbuf = 8;
181 1.2 ad sc->sc_dr.dr_dtr = 17;
182 1.2 ad sc->sc_dr.dr_break = 25;
183 1.2 ad sc->sc_dr.dr_tbuf = 24;
184 1.2 ad sc->sc_dr.dr_tcr = 16;
185 1.2 ad sc->sc_dr.dr_dcd = 25;
186 1.2 ad sc->sc_dr.dr_ring = 24;
187 1.2 ad
188 1.2 ad sc->sc_dr.dr_firstreg = 0;
189 1.2 ad sc->sc_dr.dr_winsize = sizeof(struct dzregs);
190 1.2 ad
191 1.2 ad sc->sc_type = DZ_DZV;
192 1.2 ad
193 1.2 ad dz = (volatile struct dzregs *)sc->sc_ioh;
194 1.2 ad i = dz->tcr;
195 1.2 ad dz->csr = DZ_CSR_MSE | DZ_CSR_TXIE;
196 1.2 ad dz->tcr = 0;
197 1.2 ad wbflush();
198 1.2 ad DELAY(1000);
199 1.2 ad dz->tcr = 1;
200 1.2 ad wbflush();
201 1.2 ad DELAY(100000);
202 1.2 ad dz->tcr = i;
203 1.2 ad wbflush();
204 1.2 ad
205 1.2 ad sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
206 1.2 ad
207 1.2 ad printf(": DC-7085, 4 lines");
208 1.2 ad ibus_intr_establish(parent, (void *)iba->ia_cookie, IPL_TTY,
209 1.2 ad dz_ibus_intr, sc);
210 1.2 ad dzattach(sc, NULL, dz_ibus_consln);
211 1.2 ad DELAY(10000);
212 1.2 ad
213 1.2 ad if (systype == DS_PMAX || systype == DS_3MAX) {
214 1.2 ad #if NDZKBD > 0
215 1.2 ad if (!dz_ibus_iscn)
216 1.2 ad dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) |
217 1.2 ad DZ_LPR_8_BIT_CHAR | DZ_LINE_KBD;
218 1.2 ad daa.daa_line = DZ_LINE_KBD;
219 1.2 ad daa.daa_flags = (dz_ibus_iscn ? 0 : DZKBD_CONSOLE);
220 1.2 ad config_found(self, &daa, dz_ibus_print);
221 1.2 ad #endif
222 1.2 ad #if NDZMS > 0
223 1.2 ad dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) |
224 1.2 ad DZ_LPR_8_BIT_CHAR | DZ_LPR_PARENB | DZ_LPR_OPAR |
225 1.2 ad DZ_LINE_MOUSE;
226 1.2 ad daa.daa_line = DZ_LINE_MOUSE;
227 1.2 ad daa.daa_flags = 0;
228 1.2 ad config_found(self, &daa, dz_ibus_print);
229 1.2 ad #endif
230 1.2 ad }
231 1.2 ad }
232 1.2 ad
233 1.2 ad int
234 1.2 ad dz_ibus_getmajor(void)
235 1.2 ad {
236 1.2 ad extern const struct cdevsw dz_cdevsw;
237 1.2 ad static int cache = -1;
238 1.2 ad
239 1.2 ad if (cache != -1)
240 1.2 ad return (cache);
241 1.2 ad
242 1.2 ad return (cache = cdevsw_lookup_major(&dz_cdevsw));
243 1.2 ad }
244 1.2 ad
245 1.2 ad int
246 1.2 ad dz_ibus_intr(void *cookie)
247 1.2 ad {
248 1.2 ad struct dz_softc *sc;
249 1.2 ad volatile struct dzregs *dzr;
250 1.2 ad unsigned csr;
251 1.2 ad
252 1.2 ad sc = cookie;
253 1.2 ad dzr = (volatile struct dzregs *)sc->sc_ioh;
254 1.2 ad
255 1.2 ad while (((csr = dzr->csr) & (DZ_CSR_RX_DONE | DZ_CSR_TX_READY)) != 0) {
256 1.2 ad if ((csr & DZ_CSR_RX_DONE) != 0)
257 1.2 ad dzrint(sc);
258 1.2 ad if ((csr & DZ_CSR_TX_READY) != 0)
259 1.2 ad dzxint(sc);
260 1.2 ad }
261 1.2 ad
262 1.2 ad return (0);
263 1.2 ad }
264 1.2 ad
265 1.2 ad void
266 1.2 ad dz_ibus_cnsetup(paddr_t addr)
267 1.2 ad {
268 1.2 ad
269 1.2 ad dzcn = (void *)MIPS_PHYS_TO_KSEG1(addr);
270 1.2 ad }
271 1.2 ad
272 1.2 ad void
273 1.2 ad dz_ibus_cnattach(int line)
274 1.2 ad {
275 1.2 ad
276 1.2 ad switch (line) {
277 1.2 ad case 0:
278 1.2 ad line = DZ_LINE_KBD;
279 1.2 ad break;
280 1.2 ad case 4:
281 1.2 ad line = DZ_LINE_CONSOLE;
282 1.2 ad break;
283 1.2 ad default:
284 1.2 ad line = DZ_LINE_AUX;
285 1.2 ad break;
286 1.2 ad }
287 1.2 ad
288 1.2 ad dz_ibus_iscn = 1;
289 1.2 ad dz_ibus_consln = line;
290 1.2 ad
291 1.2 ad /* Disable scanning until init is done. */
292 1.2 ad dzcn->csr = 0;
293 1.2 ad wbflush();
294 1.5 ad DELAY(1000);
295 1.2 ad
296 1.2 ad /* Turn on transmitter for the console. */
297 1.2 ad dzcn->tcr = (1 << line);
298 1.2 ad wbflush();
299 1.5 ad DELAY(1000);
300 1.2 ad
301 1.2 ad /* Turn scanning back on. */
302 1.2 ad dzcn->csr = 0x20;
303 1.2 ad wbflush();
304 1.5 ad DELAY(1000);
305 1.2 ad
306 1.2 ad /*
307 1.2 ad * Point the console at the DZ-11.
308 1.2 ad */
309 1.2 ad cn_tab = &dz_ibus_consdev;
310 1.2 ad cn_tab->cn_pri = CN_REMOTE;
311 1.2 ad cn_tab->cn_dev = makedev(dz_ibus_getmajor(), line);
312 1.2 ad }
313 1.2 ad
314 1.2 ad int
315 1.2 ad dz_ibus_cngetc(dev_t dev)
316 1.2 ad {
317 1.2 ad int c, line, s;
318 1.2 ad uint16_t rbuf;
319 1.2 ad
320 1.2 ad c = 0;
321 1.2 ad line = minor(dev);
322 1.2 ad s = spltty();
323 1.2 ad
324 1.2 ad do {
325 1.2 ad while ((dzcn->csr & DZ_CSR_RX_DONE) == 0)
326 1.2 ad DELAY(10);
327 1.5 ad DELAY(10);
328 1.2 ad rbuf = dzcn->rbuf;
329 1.2 ad if (((rbuf >> 8) & 3) != line)
330 1.2 ad continue;
331 1.2 ad c = rbuf & 0x7f;
332 1.2 ad } while (c == 17 || c == 19); /* ignore XON/XOFF */
333 1.2 ad
334 1.2 ad splx(s);
335 1.2 ad if (c == 13)
336 1.2 ad c = 10;
337 1.2 ad return (c);
338 1.2 ad }
339 1.2 ad
340 1.2 ad void
341 1.2 ad dz_ibus_cnputc(dev_t dev, int ch)
342 1.2 ad {
343 1.2 ad int timeout, s;
344 1.2 ad uint16_t tcr;
345 1.2 ad
346 1.2 ad s = spltty();
347 1.2 ad
348 1.2 ad /* Don't hang the machine! */
349 1.2 ad timeout = 1 << 15;
350 1.2 ad
351 1.2 ad /* Remember which lines to scan */
352 1.2 ad tcr = dzcn->tcr;
353 1.2 ad dzcn->tcr = (1 << minor(dev));
354 1.2 ad wbflush();
355 1.5 ad DELAY(10);
356 1.2 ad
357 1.2 ad /* Wait until ready */
358 1.2 ad while ((dzcn->csr & 0x8000) == 0)
359 1.2 ad if (--timeout < 0)
360 1.2 ad break;
361 1.5 ad DELAY(10);
362 1.2 ad
363 1.2 ad /* Put the character */
364 1.2 ad dzcn->tdr = ch;
365 1.2 ad timeout = 1 << 15;
366 1.2 ad wbflush();
367 1.5 ad DELAY(10);
368 1.2 ad
369 1.2 ad /* Wait until ready */
370 1.2 ad while ((dzcn->csr & 0x8000) == 0)
371 1.2 ad if (--timeout < 0)
372 1.2 ad break;
373 1.2 ad
374 1.5 ad DELAY(10);
375 1.2 ad dzcn->tcr = tcr;
376 1.2 ad wbflush();
377 1.5 ad DELAY(10);
378 1.2 ad splx(s);
379 1.2 ad }
380 1.2 ad
381 1.2 ad void
382 1.2 ad dz_ibus_cnpollc(dev_t dev, int pollflag)
383 1.2 ad {
384 1.2 ad
385 1.2 ad }
386 1.2 ad
387 1.2 ad #if NDZKBD > 0 || NDZMS > 0
388 1.2 ad int
389 1.2 ad dz_ibus_print(void *aux, const char *pnp)
390 1.2 ad {
391 1.2 ad struct dzkm_attach_args *daa;
392 1.2 ad
393 1.2 ad daa = aux;
394 1.2 ad if (pnp != NULL)
395 1.2 ad printf("lkkbd/vsms at %s", pnp);
396 1.2 ad printf(" line %d", daa->daa_line);
397 1.2 ad return (UNCONF);
398 1.2 ad }
399 1.2 ad
400 1.2 ad int
401 1.2 ad dzgetc(struct dz_linestate *ls)
402 1.2 ad {
403 1.2 ad volatile struct dzregs *dzr;
404 1.2 ad int line, s;
405 1.2 ad uint16_t rbuf;
406 1.2 ad
407 1.2 ad if (ls == NULL) {
408 1.2 ad /*
409 1.2 ad * dzkbd is the only thing that should put us here.
410 1.2 ad */
411 1.2 ad line = DZ_LINE_KBD;
412 1.2 ad dzr = dzcn;
413 1.2 ad } else {
414 1.2 ad line = ls->dz_line;
415 1.2 ad dzr = (volatile struct dzregs *)ls->dz_sc->sc_ioh;
416 1.2 ad }
417 1.2 ad
418 1.2 ad s = spltty();
419 1.2 ad for (;;) {
420 1.2 ad while ((dzr->csr & DZ_CSR_RX_DONE) == 0)
421 1.2 ad DELAY(10);
422 1.5 ad DELAY(10);
423 1.2 ad rbuf = dzr->rbuf;
424 1.5 ad DELAY(10);
425 1.2 ad if (((rbuf >> 8) & 3) == line)
426 1.2 ad return (rbuf & 0xff);
427 1.2 ad }
428 1.2 ad splx(s);
429 1.2 ad }
430 1.2 ad
431 1.2 ad void
432 1.2 ad dzputc(struct dz_linestate *ls, int ch)
433 1.2 ad {
434 1.2 ad volatile struct dzregs *dzr;
435 1.2 ad int line;
436 1.2 ad uint16_t tcr;
437 1.2 ad int s;
438 1.2 ad
439 1.2 ad /*
440 1.2 ad * If the dz has already been attached, the MI driver will do the
441 1.2 ad * transmitting:
442 1.2 ad */
443 1.2 ad if (ls != NULL && ls->dz_sc != NULL) {
444 1.2 ad line = ls->dz_line;
445 1.2 ad dzr = (volatile struct dzregs *)ls->dz_sc->sc_ioh;
446 1.2 ad s = spltty();
447 1.2 ad putc(ch, &ls->dz_tty->t_outq);
448 1.2 ad tcr = dzr->tcr;
449 1.2 ad if ((tcr & (1 << line)) == 0) {
450 1.2 ad dzr->tcr = tcr | (1 << line);
451 1.2 ad wbflush();
452 1.5 ad DELAY(10);
453 1.2 ad }
454 1.2 ad dzxint(ls->dz_sc);
455 1.2 ad splx(s);
456 1.2 ad return;
457 1.2 ad }
458 1.2 ad
459 1.2 ad /* Use dzcnputc to do the transmitting. */
460 1.2 ad dz_ibus_cnputc(makedev(dz_ibus_getmajor(), DZ_LINE_KBD), ch);
461 1.2 ad }
462 1.2 ad #endif /* NDZKBD > 0 || NDZMS > 0 */
463