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